如何使用(Ruby)RGeo转换(非项目)坐标 [英] How Can I Use (Ruby) RGeo to Transform (Unproject) Coordinates

查看:107
本文介绍了如何使用(Ruby)RGeo转换(非项目)坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从>如何转换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

gis站点上的问题已得到解答,并且我能够使用PROJ命令行工具cs2cs重现正确的转换.看起来像这样:

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

现在,我进行了正确的转换,我可以使用RGeo以简单的形式尝试相同的事情:

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] 

  1. 为什么RGeo和cs2cs的结果不同?
  2. 一旦我可以使RGeo执行正确的翻译,有什么办法可以创建适当的工厂来转换完整的Geometry(而不是点)?
  3. 是否可以使用命令行工具来变通shapefile中的所有点,以便继续生活?

通常:有人可以指导我如何正确使用此库吗?

In general: Would someone please instruct me on how to properly use this library?

非常感谢您的光临.

推荐答案

由于我不知道RGeo甚至是Ruby,所以在黑暗中是一个狂野的刺,请尝试用等效于米的英尺替换您的坐标:1832244.0944819663048746863094224,640342.57048223700783128534419392 (尽管您可能不需要小数位数...)另一种可能性是交换坐标-也许RGeo做出了一些非常规的假设.

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.

如果您能够从Ruby调用可执行文件,则只需使用 ogr2ogr 来转换您的shapefile.

If you are able to call executables from Ruby, you could simply use ogr2ogr to convert your shapefiles.

这篇关于如何使用(Ruby)RGeo转换(非项目)坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆