【问题标题】:Try to use Rgeo with rails尝试将 Rgeo 与 rails 一起使用
【发布时间】:2018-04-14 13:34:25
【问题描述】:

我是 Rails 新手,曾尝试使用 Rgeo 和 GeoJSON。 我想从我的数据中提取 GeoJSON 以在传单中使用。

安装GeoJSON和/或放置)的正确方法是什么。

宝石文件:

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

【问题讨论】:

  • postgis在哪里使用?
  • 在我的 RailsApp 中,它工作正常;)

标签: ruby-on-rails installation postgis geojson rgeo


【解决方案1】:

要读取 geojson 数据,您只需要在变量中捕获纯文本并解析它。

str = File.open("sample.geojson").read
shp = RGeo::GeoJSON.decode(str)

我相信 4326 是默认的 SRID,因此从技术上讲,因为您还没有重新投影它,所以从技术上讲,没有为这个实例配置任何东西。

您正在使用工厂,而我正在使用运行时默认值,但要使用工厂,您只需要在它们上调用相同的方法即可。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-08
    • 2016-03-25
    • 2013-12-25
    • 2014-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多