I'm a newbie on rails and tried using Rgeo and GeoJSON. I want to extract GeoJSON from my data to use in leaflet.
What is the proper way to install GeoJSON (and/or place).
Gemfile :
gem 'activerecord-postgis-adapter'
gem 'rgeo-geojson'
gem 'rgeo'
gem 'rgeo-activerecord'
Is there any additional configuration needed and what's the proper way to install it (GeoJSON)
require 'rgeo/geo_json'
RGeo::ActiveRecord::SpatialFactoryStore.instance.tap do |config|
# By default, use the GEOS implementation for spatial columns.
config.default = RGeo::Geos.factory_generator
# But use a geographic implementation for point columns.
config.register(RGeo::Geographic.spherical_factory(srid: 4326),
geo_type: "point")
end
To read geojson data, you would just need to capture the plain text in a variable and parse it.
str = File.open("sample.geojson").read
shp = RGeo::GeoJSON.decode(str)
I believe 4326 is the default SRID so there isn't technically anything to configure there for this one instance seeing as you're not reprojecting it yet.
You're using factories and I'm using runtime defaults, but to use the factories you'd just need to call those same methods on them instead.