[Geotiff] Conversion from lat/long to PCS to raster
Cassanova, Bill
BCassanova at weather.com
Fri Jan 21 08:29:16 EST 2011
If the image you have already contains the geotiff tags it is much easier to use gdal directly. If the image does not yet contain the geotiff tags you can add them using gdal_translate and then use gdal directly.
Below is an example of reading a geotiff image and extracting the lat-lon.
General instructions:
GDALDatasetH my_data_set = GDALOpen(path.c_str(), GA_ReadOnly);.
OGRSpatialReferenceH my_spatial_reference = OSRNewSpatialReference(NULL);
OSRSetWellKnownGeogCS(my_spatial_reference, "WGS84");
char *pszDstWKT = NULL;
OSRExportToWkt(my_spatial_reference, &pszDstWKT);
OSRDestroySpatialReference(my_spatial_reference);
void *my_transformer = GDALCreateGenImgProjTransformer(my_data_set,
NULL,
NULL,
pszDstWKT,
FALSE, 0.0, 0);
float original_lat = some_lat_value;
float original_lon = some_lon_value;
float lat = original_lat;
float lon = original_lon;
int result = GDALGenImgProjTransform(my_transformer, TRUE, 1, &lon, &lat,
NULL, &panSuccess);
If( result == 1 )
{
Std::cout << original_lon << " is " << lon << " in pixel space" << std::endl;
Std::cout << original_lat << " is " << lat << " in pixel space" << std::endl;
}
Hope this helps,
Bill
-----Original Message-----
From: geotiff-bounces at lists.maptools.org [mailto:geotiff-bounces at lists.maptools.org] On Behalf Of Fernando Cacciola
Sent: Friday, January 21, 2011 6:58 AM
To: geotiff at lists.maptools.org
Subject: [Geotiff] Conversion from lat/long to PCS to raster
Hi,
I plan to use libgeotiff (never used it beefore) to convert from
lat/long (GCS) to raster pixels.
IIIUC I need to convert lat/long to northings/eastings first (GCS ->
PCS), then PCS to Raster space.
I can see in libgeotiff the function GTIFPCSToImage, for PCS->Raster,
and I can also see a GTIFProj4FromLatLong(), which appears to be for
GCS to PCS, but I'm not sure how to use it.
Or rather, I can't get it to work: with a test geotiff I have,
lat/long and northings/eastings end up the same when I call
GTIFProj4FromLatLong (which of course won't give the correct raster
coordinates since this geotiff is ModelTypeProjected)
I called GTIFGetProj4Defn(&defn) FWIW.
Is this supported and I'm missing something? Or I cannot do this with
libgeotiff alone (and need GDAL instead)?
TIA
--
Fernando Cacciola
SciSoft Consulting, Founder
http://www.scisoft-consulting.com
_______________________________________________
Geotiff mailing list
Geotiff at lists.maptools.org
http://lists.maptools.org/mailman/listinfo/geotiff
More information about the Geotiff
mailing list