【问题标题】:Is it possible to convert pixel coordinates of an image to lat,long using GDAL in C++?是否可以在 C++ 中使用 GDAL 将图像的像素坐标转换为纬度、经度?
【发布时间】:2020-10-31 04:03:27
【问题描述】:

我拥有的图像是一个地理参考 tiff 图像,它的参考框架为 EPSG 4326。我有一组点需要转换为纬度和经度。我在我的项目中使用 Visual Studio 和 GDAL 2.3.1。我无法在 python 中获得下面的 C++ 等价物:

"trans = gdal.transformer(image, None [])
success,xyz=trans.TransformPoint(0,Posx,Posy)
lat=xyz[0]
long=xyz[1]
"

我的main里面的内容如下所示:

GDALAllRegister();
    GDALDataset* data = (GDALDataset*) GDALOpen(filename,GA_ReadOnly);
    OGRSpatialReference source,target;
    source.importFromEPSG(4326);
    target.importFromEPSG(4326);
    //setting my pixels here for pixel location(500,500)
    OGRPoint p; 
    p.setX(500); 
    p.setY(500); 
    p.assignSpatialReference(&source);
    p.transformTo(&target);
    // transformed coordinates 
    cout << p.getX() << " | " << p.getY();

我开始使用link 中的示例代码,它给了我相同的 lat,long 的结果作为我的像素位置。这怎么可能? GDAL 库中用于将像素坐标转换为 EPSG 4326 中的 Lat 和 Long 的 any 函数。感谢任何帮助。

【问题讨论】:

标签: c++ gdal


【解决方案1】:

我使用 node-gdal 库来做同样的事情。您可以按照https://github.com/naturalatlas/node-gdal/blob/master/examples/gdalinfo.js 的示例来了解他们如何将像素转换为纬度/经度坐标。

【讨论】:

  • 谢谢,但是,我正在寻找 C++ 中的东西。我添加了代码的最小可重现示例。
猜你喜欢
  • 2013-09-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多