【问题标题】:Proj4rb: convert latitude/longitude to robinson projectionProj4rb:将纬度/经度转换为鲁滨逊投影
【发布时间】:2012-11-19 00:33:52
【问题描述】:

我正在使用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>

我做错了什么?

【问题讨论】:

    标签: ruby proj


    【解决方案1】:

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

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

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

    正确的是:

    source_point = Proj4::Point.new(-74.0064, 40.7142);
    

    【讨论】:

      【解决方案2】:

      问题出在您的源点(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)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-02-03
        • 1970-01-01
        • 2020-09-15
        • 2013-02-07
        • 1970-01-01
        • 1970-01-01
        • 2012-12-29
        • 2022-01-23
        相关资源
        最近更新 更多