我想保存GeoJSON多边形

时间:2017-07-06 22:50:22

标签: ruby-on-rails rails-activerecord postgis geojson rgeo

我想保存多边形。

这是Geojson enter link description here

str1 = "geojson....."
geom = RGeo::GeoJSON.decode(str1, json_parser: :json)
l = Limit.new
l.multipoligono = geom
l.save


NoMethodError: undefined methodfactory' for #RGeo::GeoJSON::FeatureCollection:0x3fc7febb7424`

这是我的rgeo.rb

RGeo::ActiveRecord::SpatialFactoryStore.instance.tap do |config|
config.default = RGeo::Geos.factory_generator
config.register(RGeo::Geographic.spherical_factory(srid: 4326), geo_type: "point")
config.register(RGeo::Geographic.spherical_factory(srid: 4326), geo_type: "multi_polygon")
config.register(RGeo::Geographic.spherical_factory(srid: 4326), geo_type: "geometry_collection")

end

1 个答案:

答案 0 :(得分:2)

有110颗星,我想this is how they do it in ruby

hash = RGeo::GeoJSON.encode(feature)
hash.to_json == str2      # => true

那就是说,我不会这样做。我也不会使用Ruby。查看PostGIS的ST_AsGeoJSON。它返回geojson的特征部分。也就是说,将RGeo从等式中删除。