If you have GeoTiff, is it possible to convert the Lat / Lon point to X, Y using GeoTransform?

I am using the GDAL library. Currently, I can take the top left point and the top right point and cut out the image from the original. Now I would like to make two WKT points and convert them to X, Y coordinates to do the same. I'm just wondering if I could do this if I knew GeoTransform and what coordinate system he used (WGS84)?

+5
source share
3 answers

I also came across this, and here is a pretty good way to transform coordinates.

Note GDAL Documentation :

, GDALDataset:: GetProjectionRef() , , GDALDataset:: GetGeoTransform().

OGRCoordinateTransformation, .

:

// Load up some dataset.
dataset = (GDALDataset *) GDALOpen( mapfile, GA_ReadOnly );

// Define Geographic coordinate system - set it to WGS84.
OGRSpatialReference *poSRS_Geog = new OGRSpatialReference();
poSRS_Geog->importFromEPSG( 4326 ); // WGS84

// Define Projected coordinate system - set to the GeoTransform.
const char *sProj = dataset->GetProjectionRef();
OGRSpatialReference *poSRS_Proj = new OGRSpatialReference( sProj );

// Set up the coordinate transform (geographic-to-projected).
OGRCoordinateTransformation *poCT_Geog2Proj;
poCT_Geog2Proj = OGRCreateCoordinateTransformation( poSRS_Geog, poSRS_Proj );

// Now everything is set up and we set transforming coordinates!
// Pass Lon/Lat coordinates to the Transform function:
double x = lon;
double y = lat;
poCT_Geog2Proj->Transform( 1, &x, &y );

// Now x and y variables will contain the X/Y pixel coordinates.

, / . , Transform() . , - x y. .

, :

// Set up the coordinate transform (projected-to-geographic).
OGRCoordinateTransformation *poCT_Proj2Geog;
poCT_Proj2Geog = OGRCreateCoordinateTransformation( poSRS_Proj, poSRS_Geog );
+5

/. , , , North Facing, geoTransform [2] geTransform [4] Lat/Lon.
< >
x = (int) Math.Abs ​​(Math.Round(( - [0])/ [1]));
y = (int) Math.Abs ​​(Math.Round(( - [3])/ [5])); >

, ( , , ):

< > // ,
pixelXSize = AbsoluteValue ((latitudeAt (Zero) - (latitudeAt (Length) -1))/imageLength);
pixelYSize = AbsoluteValue ((longitudeAt (Zero) - (LongitudeAt () -1))/imageWidth);

// x, y ,
x = AbsoluteValue ((latitudeToConvert-latitudeAt (Zero))/pixelXSize);
y = AbsoluteValue ((longitudeToConvert-longitudteAt (Zero))/pixelYSize); >

. , North Facing , . , .

0

:

void transformCoordinatesEPSG(OGRGeometry &geometry,int from, int to) {
    OGRSpatialReference srcSpatialReference;
    OGRErr error = srcSpatialReference.importFromEPSG(from);

    #ifdef __OGRTRANSFORMDEBUG
        qDebug() << "Import EPSG  " << from << "return " << error;
    #endif

    OGRSpatialReference dstSpatialReference;
    error = error | dstSpatialReference.importFromEPSG(to);

    #ifdef __OGRTRANSFORMDEBUG
    qDebug() << "Import EPSG  " << to << "return " << error;
    #endif

    OGRCoordinateTransformation* coordTrans = OGRCreateCoordinateTransformation(&srcSpatialReference, &dstSpatialReference);
    geometry.transform(coordTrans);
}

lat/long 4326.

0
source

All Articles