【问题标题】:How to obtain latitude and longitude from geotiff image using Gdal C++如何使用 Gdal C++ 从 geotiff 图像中获取纬度和经度
【发布时间】:2016-09-19 03:19:37
【问题描述】:

我想使用 Gdal C++ 从 geotiff 图像中获取纬度和经度。大多数获取这些坐标的源代码和教程通常使用 C 和 Phyton。正如我们所知,这些的 Gdal 源在 C++ 中是不同的。是否有任何文档或教程如何使用 C++ 获得这种位置?或者有谁知道如何在 Gdal C++ 中获取这些坐标?

【问题讨论】:

    标签: c++ gdal


    【解决方案1】:

    像这样:

    GDALDataset *fin = (GDALDataset*)GDALOpen(filename.c_str(), GA_ReadOnly);
    if(fin==NULL)
      throw std::runtime_error("Could not open file '"+filename+"' with GDAL!");
    
    std::vector<double> geotransform(6);
    if(fin->GetGeoTransform(geotransform.data())!=CE_None)
      throw std::runtime_error("Could not get a geotransform!");
    
    //From https://www.gdal.org/gdal_datamodel.html "Affine GeoTransform"
    //    Xgeo = GT(0) + Xpixel*GT(1) + Yline*GT(2)
    //    Ygeo = GT(3) + Xpixel*GT(4) + Yline*GT(5)
    
    int x = 0;
    int y = 0;
    
    double lng=geotransform[0] + x*geotransform[1] + y*geotransform[2];
    double lat=geotransform[3] + x*geotransform[4] + y*geotransform[5];
    

    GDAL 没有 C++ 接口,因此您可以像使用 C 一样完成大部分工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多