gpt4 book ai didi

c++ - Geotiff坐标转换错误

转载 作者:行者123 更新时间:2023-12-02 10:18:20 29 4
gpt4 key购买 nike

在使用GDAL从openSUSE中运行它的GeoTiff图像中提取纬度和经度的应用程序中出现错误和崩溃,而对于我的同事来说,它在Ubuntu中运行良好。对于gdal-v3和gdal-v2版本,错误有所不同,但是似乎在OGRCreateCoordinateTransformation对象创建中存在问题:在两种情况下都返回NULL。请参阅以下详细信息:

码:

QGeoCoordinate toGeoCoordinate(double* adGeotransform, OGRSpatialReference& srcRef, int x, int y)
{
double worldX = adGeotransform[0] + x * adGeotransform[1] + y * adGeotransform[2];
double worldY = adGeotransform[3] + x * adGeotransform[4] + y * adGeotransform[5];

OGRSpatialReference dstRef;
dstRef.importFromEPSG(4326);
QScopedPointer<OGRCoordinateTransformation> coordinateTransform(
OGRCreateCoordinateTransformation(&srcRef, &dstRef));
coordinateTransform->Transform(1, &worldX, &worldY);
return QGeoCoordinate(worldY, // lat
worldX); // lon
}

QGeoRectangle extractCoordinate(const QString& path)
{
GDALAllRegister();
GDALDataset *poDataset = (GDALDataset *) GDALOpen( path.toStdString().c_str(), GA_ReadOnly );
_height = GDALGetRasterYSize(poDataset);
_width = GDALGetRasterXSize(poDataset);

double adGeotransform[6];
poDataset->GetGeoTransform(adGeotransform);
OGRSpatialReference srcRef(poDataset->GetProjectionRef());
QGeoCoordinate _topLeft = toGeoCoordinate(adGeotransform, srcRef, 0, 0);
QGeoCoordinate _bottomRight = toGeoCoordinate(adGeotransform, srcRef, _width, _height);

return QGeoRectangle(_topLeft, _bottomRight);
}

GDAL 3(openSUSE):
  • gdal-3.0.4
  • libgeotiff5-1.5.1
  • libproj19-7.0.0
  • libgeos-3.8.0

  • ERROR 1: PROJ: proj_create_from_database: Cannot find proj.db ERROR 1: PROJ: proj_create: unrecognized format / unknown name ERROR 6: Cannot find coordinate operations from PROJCRS["WGS 84 / UTM zone 10N",BASEGEOGCRS["WGS 84",DATUM["World Geodetic System 1984",ELLIPSOID["WGS 84",6378137,298.257223563,LENGTHUNIT["metre",1]]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433]],ID["EPSG",4326]],CONVERSION["UTM zone 10N",METHOD["Transverse Mercator",ID["EPSG",9807]],PARAMETER["Latitude of natural origin",0,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8801]],PARAMETER["Longitude of natural origin",-123,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8802]],PARAMETER["Scale factor at natural origin",0.9996,SCALEUNIT["unity",1],ID["EPSG",8805]],PARAMETER["False easting",500000,LENGTHUNIT["metre",1],ID["EPSG",8806]],PARAMETER["False northing",0,LENGTHUNIT["metre",1],ID["EPSG",8807]]],CS[Cartesian,2],AXIS["easting",east,ORDER[1],LENGTHUNIT["metre",1]],AXIS["northing",north,ORDER[2],LENGTHUNIT["metre",1]],ID["EPSG",32610]]' to'



    GDAL 2(openSUSE):
  • gdal2-2.4.2
  • libgeotiff5-1.5.1
  • libproj19-7.0.0
  • libgeos-3.8.0

  • ERROR 6: Unable to load PROJ.4 library (libproj.so.15), creation of OGRCoordinateTransformation failed.



    Ubuntu 18.03 LTS(正常运行):
  • libgdal-2.2.3
  • libgeotiff-1.4.2
  • libproj12-4.9.3


  • 因此,寻求可能的解决方案:
  • 错误导致的原因可能是:
  • 错误的库版本;
  • 在openSUSE上构建错误标志?
  • GeoTiff可以其他方式提取吗?
  • 最佳答案

    问题是在PROJ库版本中使用的。对于GDAL v2需要使用libproj v6。但是在openSUSE Tumbleweed中需要根据libgeotiff5(libspatialite)构建的libproj19proj v7。所以需要

  • 卸载以下所有的最新版本:libspatialitegeotifflibproj19gdal
  • 例如,从此存储库中安装libproj15 home:rogeroberholtzer
  • 自己针对已安装的libspatialitegeotiff重建src.rpmlibproj15库:
    rpmbuild --rebuild --clean libspatialite-4.3.0a-15.19.src.rpm
    rpmbuild --rebuild --clean geotiff-1.5.1-31.13.src.rpm

    例如,这些软件包可以从science存储库中获取。
  • 安装内置软件包:rpm -Uvh *
  • science存储库安装gdal2-2.4.2 rpm。

  • 和所有的作品!请享用! :)

    关于c++ - Geotiff坐标转换错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61164590/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com