题
我正在尝试使用proj.4库将纬度/经度坐标转换为OSGB36 x和y。
有没有其他人成功完成此操作?我需要填充srcPrj4String和destPrj4String变量,例如
string srcPrj4String =" + proj = longlat + ellps = WGS84 + datum = WGS84 + no_defs&quot ;;
string destPrj4String =" + proj = utm + zone = 11 + ellps = GRS80 + datum = NAD83 + units = m&quot ;;
但我无法弄清楚destPrj4String应该与OSGB36一起使用 - 我知道数据应该是+ datum = OSGB36,但我尝试的一切都不起作用
有什么想法吗?
非常感谢提前
莱迪
解决方案 2
得到了它:
string srcPrj4String = "+proj=longlat +ellps=WGS84 +towgs84=0,0,0 +no_defs";
string destPrj4String = "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894 +units=m +no_defs";
喝彩!
其他提示
谷歌搜索引起了John Stevenson博士的这个曼彻斯特大学地球科学学者 - 如果有人这样做,谁应该把它弄好。这是一个引用。
问题是去OSGB36需要一个投影和一个 基准转换。在 2007年10月之前,proj只携带 超出投影,从而产生大的偏移。你可以检查一下 如果您通过运行'proj -v'或查看您的新版本来获得新版本 epsg文件:
cat /usr/share/proj/epsg | grep -A 1 "British National Grid"
# OSGB 1936 / British National Grid
<27700> +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000
+y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs <>
新版本有+ datum = OSGB36。
如果您使用的是旧版本,则可以使用以下代码替换该行:
+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.999601 +x_0=400000 +y_0=-100000
+ellps=airy
+towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894 +units=m
+no_defs <>
一个复杂因素是OSGB36是稍微扭曲关于GPS 预测(例如WGS84和ETRS89)。这个偏差很小,而且 仅对更高精度的测量很重要。很多搜索 OSGB36偏移会显示与此相关的页面。如果你想 也弥补了这一点, 你可以下载一个nadgrid文件并使用它 。对于我的数据,这感动了 点数约1米。
在spatialreference.org上的EPSG:27700 提供了各种用于定义此字符串的字符串,包括一个对于proj4。
以下是使用proj4绑定的中的示例代码>>:
#!/usr/bin/ruby
require 'rubygems'
require 'proj4'
#Some example WGS84 lat lon coordinates to convert:
lon = -0.10322
lat = 51.52237
srcPoint = Proj4::Point.new(Math::PI * lon.to_f / 180,
Math::PI * lat.to_f / 180)
srcPrj = Proj4::Projection.new("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
destPrj = Proj4::Projection.new("+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.999601 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894 +units=m +no_defs <>")
point = srcPrj.transform(destPrj, srcPoint)
puts "http://www.openstreetmap.org/?mlat=" + lat.to_s + "&mlon=" + lon.to_s + "&zoom=16"
puts "Converts to:";
puts "http://streetmap.co.uk/grid/" + point.x.round.to_s + "_" + point.y.round.to_s + "_106"
输出:
http://www.openstreetmap.org/?mlat= 51.52237&安培; mlon = -0.10322和缩放= 16 结果
转换为:
http://streetmap.co.uk/grid/531691_182089_106
所以现在这个工作正常。最初我只是尝试'destPrj'字符串,并调用'forward'方法,但这拒绝进行基准转换,导致一切都在100米外。似乎有必要使用'srcPrj'字符串和'transform'方法来进行基准转换。
另见我的博文:用于转换到WGS84的英国军械测量坐标系的Ruby代码?,其中包含用于执行相同操作的纯ruby版本(不是proj4)