注意:Geojson响应包含坐标数据类型,需要将其作为几何数据类型存储在Postgres中。
我不想在Postgis中使用任何第三方软件,如Qgis或ArcGIS,或命令行工具,如geojson2psql。
使用jsonb列。
使用->
运算符查询jsonb列的特定属性很简单。例如,假设列名为“geodata”,此查询:
SELECT geodata->'geometry'->'coordinates' AS coords FROM geo_example;
...将从我从Leaflet抓取的GeoJSON示例返回[-104.99404,39.90621]:
{
"type": "Feature",
"properties": {
"name": "Coors Field",
"amenity": "Baseball Stadium",
"popupContent": "This is where the Rockies play!"
},
"geometry": {
"type": "Point",
"coordinates": [-104.99404, 39.75621]
}
};
这是一个SQL Fiddle,展示了几个例子。