2017-07-06 73 views
1

我想保存多边形。我想保存GeoJSON多边形

这是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

有了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从等式中删去。

相关问题