如何转换 Shapefile 的坐标?
我正在尝试将社区数据导入我的应用程序,但我使用的数据存在问题,这些数据是从 此处。
该文件包含一个包含旧金山街区的 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 空间参考系统的纬度/经度)
预先感谢您!
I am trying to get neighborhood data into my application, and I'm having problems with the data I am using, which I got from here.
This file contains a shapefile that has the neighborhoods of San Francisco. I am running a Ruby on Rails framework, and I'm currently using GeoRuby to parse the shapefile.
The code looks like this:
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
The code is able to parse the file, but I am unable to understand the coordinates as interpreted. All of the points have values in the millions, when I would expect coordinates between -180 and 180, for valid latitude and longitude. Take a look at an example point:
<GeoRuby::SimpleFeatures::Point:0x00000104566a08 @srid=4326, @with_z=false, \
@with_m=false, @x=6015402.9999795845, @y=2114960.4999904726, @z=0.0, @m=0.0>,
What is the format of these coordinate values? How can I convert them to values that are meaningful to me? (i.e. latitude/longitude based on the SRID 4326 <=> WGS84 spatial reference system)
Thank you in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
从形状文件中获得的数据是投影地理数据。
从你的问题来看,听起来你真的只是更喜欢以纬度/经度形式显示数据。为此,您需要重新投影数据。我不是一个 ruby 爱好者,但是快速的网络搜索表明 georuby 不支持重投影 http://georuby.rubyforge.org /,但是 rgeo 可以。 http://www.daniel-azuma.com/blog/archives/28
如果您想了解有关地图投影的更多信息,请查看此处 。
顺便说一下,有一个面向 GIS(地理信息系统)专家的 stackexchange 网站,名为 http://gis.stackexchange.com
The data you have from the shape file is projected geographic data.
From your question it sounds like you would really just prefer to have your data in lat/long. To get that you need to reproject your data. I am not a ruby guy, but a quick web search reveals that georuby does not support reprojection http://georuby.rubyforge.org/, however rgeo does. http://www.daniel-azuma.com/blog/archives/28
If you would like to know more about map projections have a look here.
By the way there is a stackexchange site for GIS (geographic information systems) experts called http://gis.stackexchange.com
我注意到这仍在获取视图日志。我最终在 RGeo 中苦苦挣扎,但还有另一个解决方案。如果您能够/愿意在执行 ruby 代码之前/之外进行转换,请查看 ogr2ogr。
我在底部的评论中有更多详细信息:
如何使用 (Ruby) RGeo 进行转换(Unproject ) 坐标
I noticed this is still getting a log of views. I ended up struggling with RGeo, but there's another solution. If you are able/willing to do your conversion outside/before you execute your ruby code, check out ogr2ogr.
There are more details in my comment on the bottom here:
How Can I Use (Ruby) RGeo to Transform (Unproject) Coordinates
我遇到这个问题是因为我想将 Shapefile 中提供的点从 OSGB36 英国国家网格格式转换为 WGS84 格式(十进制)。我花了很多时间来解决这个问题,所以希望这段代码会很有用。
此代码使用 ffi-ogr gem 并需要 GDAL 库:
I came across this question as I wanted to transform points supplied in a Shapefile from OSGB36 British National Grid format to WGS84 format (decimal degrees). I spent a lot of time figuring this out so hopefully this code will prove useful.
This code uses the ffi-ogr gem and requires the GDAL library:
我遇到了同样的问题:想要将投影地理数据转换为纬度/经度值。
ogr2ogr 工具比我预想的更容易使用。
安装:
apt-get install gdal-bin
获取有关 shapefile 的信息:
ogrinfo data.shp -al -so
转换为纬度/经度和 JSON:
ogr2ogr -f GeoJSON -t_srs WGS84 data.json data.shp
I had the same problem: wanted to convert projected geodata to Lat/Long values.
The ogr2ogr tool was much easier to use than I expected.
To install:
apt-get install gdal-bin
Get info about your shapefile:
ogrinfo data.shp -al -so
Convert to Lat/Long and JSON:
ogr2ogr -f GeoJSON -t_srs WGS84 data.json data.shp