【问题标题】:RGeo: How to transform a projected coordinate to lat/lon using SRIDRGeo:如何使用 SRID 将投影坐标转换​​为纬度/经度
【发布时间】:2020-09-15 22:35:57
【问题描述】:

我想将投影坐标中的一个点转换为纬度/经度。 我读过this blog post about transformations 并想出了以下代码:

factory_25831 = RGeo::Cartesian.factory(:srid => 25831)

point_25831 = factory_25831.point(505500.421875, 4699669.4375)

factory_4326 = RGeo::Geographic.spherical_factory(:srid => 4326)

point_4326 = RGeo::Feature.cast(point_25831, :factory => factory_4326, :project => true)

这给了我:

=> #<RGeo::Geographic::SphericalPointImpl:0xe35f6c "POINT (60.421875 90.0)">

但是我应该得到类似 long: 3.0668887° / lat: 42.4493345°。

我做错了什么?

编辑:

显然我“可以”转换一个点,但只提供完整的 proj4 和 WKT 规范,这在某种程度上失去了只提供 srid 代码的好处。我的代码接收带有 srid 作为元数据的随机几何图形 - 因此我无法对规范进行硬编码。

proj4_25831 = '+proj=utm +zone=31 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs'

wkt_25831 = 'PROJCS["ETRS89 / UTM zone 31N",GEOGCS["ETRS89",DATUM["European_Terrestrial_Reference_System_1989",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6258"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4258"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",3],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","25831"]]'

factory_25831 = RGeo::Cartesian.factory(:srid => 25831,
  :proj4 => proj4_25831, :coord_sys => wkt_25831)



proj4_4326 = '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs'

wkt_4326 = <<WKT
  GEOGCS["WGS 84",
    DATUM["WGS_1984",
      SPHEROID["WGS 84",6378137,298.257223563,
        AUTHORITY["EPSG","7030"]],
      AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0,
      AUTHORITY["EPSG","8901"]],
    UNIT["degree",0.01745329251994328,
      AUTHORITY["EPSG","9122"]],
    AUTHORITY["EPSG","4326"]]
WKT


factory_4326 = RGeo::Geographic.spherical_factory(:srid => 4326,
  :proj4 => proj4_4326, :coord_sys => wkt_4326)

【问题讨论】:

    标签: ruby gis rgeo


    【解决方案1】:

    您需要告诉工厂从哪里获取投影信息。这完成了将空间参考数据库传递给工厂。有了数据库,就可以动态查找了。

    srs_database = RGeo::CoordSys::SRSDatabase::Proj4Data.new('epsg', cache: true)
    
    factory_25831 = RGeo::Cartesian.factory(srid: 25831, srs_database: srs_database)
    
    point_25831 = factory_25831.point(505500.421875, 4699669.4375)
    
    factory_4326 = RGeo::Geographic.spherical_factory(srid: 4326, srs_database: srs_database)
    
    point_4326 =  RGeo::Feature.cast(point_25831, factory: factory_4326, project: true)
    

    坐标将准确返回:

    point_4326
    => #<RGeo::Geographic::SphericalPointImpl:0x17c "POINT (3.066888712691441 42.44933441408618)">
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-07
      • 1970-01-01
      • 1970-01-01
      • 2018-02-03
      • 2010-10-11
      • 2017-07-02
      • 2017-06-29
      相关资源
      最近更新 更多