如何使用 (Ruby) RGeo 转换(取消投影)坐标
那里的回应让我开始走上[我认为]正确的轨道,但我仍然无法解决我的问题。
一个问题是我还没有找到正确的投影: https://gis.stackexchange.com/questions/13330/how-can-i- Correctly-transform-unproject-from-lcc
编辑:GIS 网站上的问题已得到解答,并且我能够使用 PROJ 命令行工具 cs2cs 重现正确的转换。它看起来像这样:
larry$ cs2cs -f "%.8f" +proj=lcc +lat_1=37.06666666666667 +lat_2=38.43333333333333 +lat_0=36.5 +lon_0=-120.5 +x_0=2000000 +y_0=500000.0000000002 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs +to +proj=lonlat +datum=WGS84 +ellps=WGS84
6011287.4999795845 2100857.2499904726
-122.40375492 37.74919006 0.00000000
现在,我有了正确的转换,我能够使用 RGeo 以简单的形式尝试相同的事情:
ruby-1.9.2-p180 :001 > projection_str = ' +proj=lcc +lat_1=37.06666666666667 +lat_2=38.43333333333333 +lat_0=36.5 +lon_0=-120.5 +x_0=2000000 +y_0=500000.0000000002 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs'
=> " +proj=lcc +lat_1=37.06666666666667 +lat_2=38.43333333333333 +lat_0=36.5 +lon_0=-120.5 +x_0=2000000 +y_0=500000.0000000002 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs"
ruby-1.9.2-p180 :002 > projection = RGeo::CoordSys::Proj4.new(projection_str)
=> #<RGeo::CoordSys::Proj4:0x805cba18 " +proj=lcc +lat_1=37.06666666666667 +lat_2=38.43333333333333 +lat_0=36.5 +lon_0=-120.5 +x_0=2000000 +y_0=500000.0000000002 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs +towgs84=0,0,0">
ruby-1.9.2-p180 :003 > desired_str = '+proj=lonlat +datum=WGS84 +ellps=WGS84'
=> "+proj=lonlat +datum=WGS84 +ellps=WGS84"
ruby-1.9.2-p180 :004 > desired = RGeo::CoordSys::Proj4.new(desired_str)
=> #<RGeo::CoordSys::Proj4:0x805271ac " +proj=lonlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0">
ruby-1.9.2-p180 :005 > RGeo::CoordSys::Proj4::transform_coords(projection, desired, 6011287.4999795845, 2100857.2499904726 )
=> [-140.92282523143973, 30.16981659183029]
- 为什么 RGeo 和 cs2cs 之间的结果不同?
- 一旦我可以让 RGeo 执行正确的转换,有没有办法创建适当的工厂来转换完整的几何图形而不是点?
- 是否有一个命令行工具可以用作解决方法来转换 shapefile 中的所有点,以便我可以继续我的生活?
一般来说:有人可以指导我如何正确使用这个库吗?
非常感谢您的浏览。
I started with How can I transform the coordinates of a Shapefile? .
The response there started me on [what I think is] the right track, but I still haven't been able to solve my problem.
One issue is that I haven't found the correct projection yet: https://gis.stackexchange.com/questions/13330/how-can-i-correctly-transform-unproject-from-lcc
EDIT: That question on the gis site has been answered, and I was able to reproduce a correct transformation using the PROJ command line tool cs2cs. It looks like this:
larry$ cs2cs -f "%.8f" +proj=lcc +lat_1=37.06666666666667 +lat_2=38.43333333333333 +lat_0=36.5 +lon_0=-120.5 +x_0=2000000 +y_0=500000.0000000002 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs +to +proj=lonlat +datum=WGS84 +ellps=WGS84
6011287.4999795845 2100857.2499904726
-122.40375492 37.74919006 0.00000000
Now, that I had the correct transformation, I was able to try the same thing in a simple form using RGeo:
ruby-1.9.2-p180 :001 > projection_str = ' +proj=lcc +lat_1=37.06666666666667 +lat_2=38.43333333333333 +lat_0=36.5 +lon_0=-120.5 +x_0=2000000 +y_0=500000.0000000002 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs'
=> " +proj=lcc +lat_1=37.06666666666667 +lat_2=38.43333333333333 +lat_0=36.5 +lon_0=-120.5 +x_0=2000000 +y_0=500000.0000000002 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs"
ruby-1.9.2-p180 :002 > projection = RGeo::CoordSys::Proj4.new(projection_str)
=> #<RGeo::CoordSys::Proj4:0x805cba18 " +proj=lcc +lat_1=37.06666666666667 +lat_2=38.43333333333333 +lat_0=36.5 +lon_0=-120.5 +x_0=2000000 +y_0=500000.0000000002 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs +towgs84=0,0,0">
ruby-1.9.2-p180 :003 > desired_str = '+proj=lonlat +datum=WGS84 +ellps=WGS84'
=> "+proj=lonlat +datum=WGS84 +ellps=WGS84"
ruby-1.9.2-p180 :004 > desired = RGeo::CoordSys::Proj4.new(desired_str)
=> #<RGeo::CoordSys::Proj4:0x805271ac " +proj=lonlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0">
ruby-1.9.2-p180 :005 > RGeo::CoordSys::Proj4::transform_coords(projection, desired, 6011287.4999795845, 2100857.2499904726 )
=> [-140.92282523143973, 30.16981659183029]
- Why are the results different between RGeo and cs2cs?
- Once I can make RGeo perform the correct translation, is there a way I can create the proper factory to transform a complete Geometry instead of a point?
- Is there a command-line tool I can use as a workaround to transform all of the points in my shapefile so that I can move on with my life?
In general: Would someone please instruct me on how to properly use this library?
Thank you so much for looking.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
作为在黑暗中的疯狂尝试,因为我不知道 RGeo 甚至 Ruby,请尝试将您的以英尺为单位的坐标替换为等效的米数:1832244.0944819663048746863094224、640342.57048223700783128534419392(您可能不需要那么多小数位)不过……)另一种可能性是交换坐标——也许 RGeo 做了一些非常规的假设。
如果您能够从 Ruby 调用可执行文件,则只需使用 ogr2ogr 即可转换您的 shapefile。
As a wild stab in the dark, because I don't know RGeo or even Ruby, try substituting your coordinates in feet with their metres equivalent: 1832244.0944819663048746863094224, 640342.57048223700783128534419392 (you probably won't need that number of decimal places though...) Another possibility is to swap the coordinates around - maybe RGeo makes some unconventional assumptions.
If you are able to call executables from Ruby, you could simply use ogr2ogr to convert your shapefiles.