ruby-on-rails - 如何转换 Shapefile 的坐标?

标签 ruby-on-rails ruby gis postgis shapefile

我正在尝试将邻域数据导入我的应用程序,但我在使用从 here 获得的数据时遇到了问题。

此文件包含一个包含旧金山街区的 shapefile。我正在运行 Ruby on Rails 框架,目前正在使用 GeoRuby 来解析 shapefile。

代码如下所示:

def self.run_import
  shpfile = '/path/to/realtor_neighborhoods/realtor_neighborhoods'
  ShpFile.open(shpfile) do |shp|
    shp.each do |shape|
      # This gets the first (and only) Polygon from each MultiPolygon
      polygon = shape.geometry.geometries.first 
      puts polygon.inspect
    end
  end
end

代码能够解析文件,但我无法理解所解释的坐标。对于有效的纬度和经度,当我期望坐标在 -180 到 180 之间时,所有点的值都以百万计。看一个示例点:

<GeoRuby::SimpleFeatures::Point:0x00000104566a08 @srid=4326, @with_z=false, \
   @with_m=false, @x=6015402.9999795845, @y=2114960.4999904726, @z=0.0, @m=0.0>,

这些坐标值的格式是什么?如何将它们转换为对我有意义的值? (即基于 SRID 4326 <=> WGS84 空间引用系统的纬度/经度)

提前致谢!

最佳答案

形状文件中的数据是 projected geographic data .

从您的问题来看,您似乎真的更喜欢使用纬度/经度数据。为此,您需要重新投影数据。我不是 ruby 专家,但快速网络搜索显示 georuby 不支持重投影 http://georuby.rubyforge.org/ , 然而rgeo做。 http://www.daniel-azuma.com/blog/archives/28

如果您想了解更多关于 map 投影的信息,请查看 here .

顺便说一下,有一个名为 http://gis.stackexchange.com 的 GIS(地理信息系统)专家堆栈交换站点。

关于ruby-on-rails - 如何转换 Shapefile 的坐标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6963991/

相关文章:

ruby-on-rails - 使用 Dalli 缓存 Twitter 结果

ruby-on-rails - 如何重构这个 Rails Action ?

ruby - 合并 ruby 散列添加键

ruby-on-rails - rails : control file store cache size

geolocation - GeoJSON 坐标?

snowflake-cloud-data-platform - 如何在 Snowflake 中将 MultiPoint 转换为 LineString?

ruby-on-rails - ActionCable:每个用户一个 channel

ruby-on-rails - 我怎么知道一个类是否继承自另一个类?有些方法像 is_a?

Ruby 直到循环 : undefined method `[]' for nil:NilClass (NoMethodError)

d3.js - GeoJSON 和 TopoJSON 的区别