我是rails的新手,尝试使用Rgeo和GeoJSON。我想从我的数据中提取GeoJSON,以便在传单中使用。
安装GeoJSON (和/或place)的正确方法是什么?
Gemfile:
gem 'activerecord-postgis-adapter'
gem 'rgeo-geojson'
gem 'rgeo'
gem 'rgeo-activerecord'是否需要任何额外的配置,以及安装它的适当方法(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发布于 2018-05-15 22:52:41
要读取geojson数据,只需捕获变量中的纯文本并对其进行解析。
str = File.open("sample.geojson").read
shp = RGeo::GeoJSON.decode(str)我相信4326是默认的SRID,因此在技术上没有为这个实例配置任何东西,因为您还没有重新投影它。
您使用的是工厂,我使用的是运行时默认值,但是要使用工厂,只需在它们上调用相同的方法即可。
https://stackoverflow.com/questions/49832009
复制相似问题