Error on geotiff coordinate transformation

a 夏天 提交于 2020-06-17 04:20:46

问题


Have error and crash in an application using GDAL for extracting latitude & longitude from GeoTiff image running it in openSUSE, while it works fine in Ubuntu for my colleagues. Errors are different for gdal-v3 and gdal-v2 versions, however seems problem is in OGRCreateCoordinateTransformation object creation: returns NULL in both cases. See details below:


Code:

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 (works fine):

  • libgdal - 2.2.3
  • libgeotiff - 1.4.2
  • libproj12 - 4.9.3

So asking for possible solutions:

  1. What the errors cause could be:
    • wrong libraries versions;
    • wrong build flags on openSUSE?
  2. GeoTiff could be extracted other way?

回答1:


Problem is in PROJ library version used. For GDAL v2 need to use libproj v6. However required libgeotiff5 and libspatialite built against libproj19 (proj v7) in openSUSE Tumbleweed. So need to

  1. Uninstall all recent versions of: libspatialite, geotiff, libproj19, gdal.
  2. Install libproj15 for example from this repo home:rogeroberholtzer
  3. Rebuild libspatialite & geotiff libraries from src.rpm against this installed libproj15 ourselves:

    rpmbuild --rebuild --clean libspatialite-4.3.0a-15.19.src.rpm
    rpmbuild --rebuild --clean geotiff-1.5.1-31.13.src.rpm
    

    These packages could be taken from science repo for example.

  4. Install built packages: rpm -Uvh *

  5. Install gdal2-2.4.2 rpm from science repo.

And all works! Enjoy! :)



来源:https://stackoverflow.com/questions/61164590/error-on-geotiff-coordinate-transformation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!