I want to save a polygon.
This is 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`
This is my 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
With 110 stars, I think this is how they do it in ruby.
hash = RGeo::GeoJSON.encode(feature)
hash.to_json == str2 # => true
That said, I wouldn't do that. I also wouldn't use Ruby. Check out PostGIS's ST_AsGeoJSON
. It returns the feature part of geojson. That is to say, cut RGeo out of the equation.