2017-07-06 32 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從等式中刪去。

相關問題