1

我正在使用Proj4rb gem 将纬度和经度坐标转换为Robinson projection中的一个点。这将用于确定在地图图像上放置图钉的位置。

我正在尝试的一个例子(对于纽约)是:

  robinson_projection = Proj4::Projection.new('+proj=robin +lon_0=0 +x_0=0 +y_0=0 +a=6371000 +b=6371000 +units=m +no_defs')

  source_point = Proj4::Point.new(40.7142, -74.0064)
  source_projection = Proj4::Projection.new("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")

  projected_point = source_projection.transform(robinson_projection, source_point)

这引发了以下异常:

#<Proj4::LatitudeOrLongitudeExceededLimitsError: latitude or longitude exceeded limits>

我究竟做错了什么?

4

2 回答 2

0

我看到两个错误,好奇是否是原因之一:

纽约有:纬度/经度:40.713956,-74.00528
第一个错误:
纽约有一个负经度坐标,你写的是 74.0064

第二:
Point.new(x,y) 中long, lat 的顺序应该是long, lat,而不是相反请检查文档!

所以正确的是:

source_point = Proj4::Point.new(-74.0064, 40.7142);
于 2012-11-30T18:58:27.457 回答
0

问题出在您的源点(lat、lng)内。尝试这个:

robinson_projection = Proj4::Projection.new('+proj=robin +lon_0=0 +x_0=0 +y_0=0 +a=6371000 +b=6371000 +units=m +no_defs')

lat = 40.7142
lon = -74.0064
source_point = Proj4::Point.new(Math::PI * lon.to_f / 180,
                                Math::PI * lat.to_f / 180)
source_projection = Proj4::Projection.new("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")

projected_point = source_projection.transform(robinson_projection, source_point)
于 2016-10-19T10:11:19.247 回答