我使用postgis将一些多边形保存在postgres中,现在我需要某种方法将此数据转换为GeoJSON文件,以便我可以在Google地图上显示它。将PostGIS中的多边形转换为GeoJSON in rails
这里是PostGIS的多边形
"POLYGON ((-40 145, -40 145, -40 145, -40 145, -40 145, -40 145))"
我怎能将它转换为在以GeoJSON相当于多边形的例子吗?
我使用postgis将一些多边形保存在postgres中,现在我需要某种方法将此数据转换为GeoJSON文件,以便我可以在Google地图上显示它。将PostGIS中的多边形转换为GeoJSON in rails
这里是PostGIS的多边形
"POLYGON ((-40 145, -40 145, -40 145, -40 145, -40 145, -40 145))"
我怎能将它转换为在以GeoJSON相当于多边形的例子吗?
我最终只是.exterior_ring.points.map{|point|{lng:point.x, lat:point.y}}
创造一些JSON并显示在谷歌地图中同样的方式,flightPlanCoordenants在示例https://developers.google.com/maps/documentation/javascript/examples/polyline-simple
https://github.com/rgeo/rgeo-geojson使用是目的的特定宝石。
你的代码看起来应该如下:
RGeo::GeoJSON.encode(<your_spatial_variable>, json_parser: :json)
的PostGIS提供了[ST_AsGeoJSON(http://postgis.net/docs/manual-dev/ST_AsGeoJSON.html)功能。 –
@DmitriGoldring你可以举一个例子,如何在rails中使用它? – Qwertie
恐怕我不是一个Rails的人,但这个[包](https://github.com/rgeo/activerecord-postgis-adapter)可能会让你开始。 –