How can I transform the coordinates of a Shapefile?

爷,独闯天下 提交于 2019-12-05 03:46:16

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

Larry

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

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:

require 'ffi-ogr'

data = OGR.read file_name
new_spatial_ref = OGR.import_sr(4326, 'epsg')

data.layers.each do |layer|
  transformer = OGR::CoordinateTransformation.find_transformation(layer.spatial_ref, new_spatial_ref)

  layer.features.each do |feature|
    geometry = OGR::Tools.cast_geometry(feature.geometry)
    geometry.transform(transformer)

    # Do something with geometry here
  end
end

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!