# [gdal-dev] Building a Mercator Image from Un-projected data..Major confusion and help requested.

Cassanova, Bill BCassanova at weather.com
Mon Nov 2 21:22:34 EST 2009

Thanks for the guidance.    The results are correct in the sense that the transformations are correct in terms of the meters values being returned.  My question is how does this convert to pixel location FROM the data set and then INTO the image.
In the below code example the bolded values are my output.  My lack of understanding comes from how do I use this information returned in Meters to navigate into my dataset and then navigate into the image?  Is it as simple of determining the meters
for the upper left and then meters for the lower right and then setting up a ratio based on the rows and columns in the input data set and corresponding output image?  This doesn't seem like a linear problem but perhaps GDAL is taking this out of the equation.
The output image will be the same number of rows and columns as the source data so no interpolation of data is needed.  My presumption is that the difference will be WHERE a particular pixel is located in the image.  Doing a straight Platte Carre
image is simple because the origin in the datasource is the same as the origin in the image.  The lowest right data element in the datasource will have the same i-j as the lowest right pixel.  My presumption and perhaps this is where I need clarification
is this will NOT be the case with Mercator or any other projection.
std::pair< double, double > upper_left = std::make_pair( -125.99, 49.7186 );

std::pair< double, double > upper_right = std::make_pair( -65.656, 49.7186 );

std::pair< double, double > lower_left = std::make_pair( -125.99, 24.0938 );

std::pair< double, double > lower_right = std::make_pair( -65.656, 24.0938 );

int my_points = 1;

int result = 0;

double x, y;

x = lower_right.first;

y = lower_right.second;

OCTTransform( my_transformation, my_points, &x, &y, NULL );

std::cout << std::fixed;

std::cout << result << " " << lower_right.first << ", " << lower_right.second << " = " << x << ", " << y << std::endl;

// 0 -65.656000, 24.093800 = -7308792.487523, 2747405.191359  --> These are correct

char *pszDstWKT = NULL;

char *pszSrcWKT = NULL;

OSRExportToWkt( mercator_proj, &pszDstWKT );

OSRExportToWkt( wgs84_proj, &pszSrcWKT );

void *hTransformArg;

hTransformArg = GDALCreateGenImgProjTransformer( NULL, pszSrcWKT, NULL, pszDstWKT, FALSE, 0, 1 );

x = upper_right.first;

y = upper_right.second;

int success;

result = GDALGenImgProjTransform(hTransformArg, FALSE, 1, &x, &y,  NULL, &success);

std::cout << result << " " << upper_right.first << ", " << upper_right.second << " = " << x << ", " << y << std::endl;

// 1 -65.656000, 49.718600 = -7308792.487523, 6365068.664114 --> This is now correct as well

x = lower_right.first;

y = lower_right.second;

result = GDALGenImgProjTransform(hTransformArg, FALSE, 1, &x, &y, NULL, &success);

std::cout << result << " " << lower_right.first << ", " << lower_right.second << " = " << x << ", " << y << std::endl;

//  1 -65.656000, 24.093800 = -7308792.487523, 2747405.191359 --> These are correct

________________________________

From: gdal-dev-bounces at lists.osgeo.org on behalf of Adam Nowacki
Sent: Mon 11/2/2009 4:49 PM
To: gdal-dev at lists.osgeo.org >> Gdal-Dev
Subject: Re: [gdal-dev] Building a Mercator Image from Un-projected data..Major confusion and help requested.

Cassanova, Bill wrote:
> result = GDALGenImgProjTransform(hTransformArg, TRUE, 1, &x, &y,
>                               NULL, &success);
> std::cout << std::fixed;
> std::cout << result << " " << lower_right.first << ", " <<
> lower_right.second << " = " << x << ", " << y << std::endl;
>
> *//** 1 -65.656000, 49.718600 = -0.000590, 0.000450***
>
> *// This is NOT Right** so apparently I am doing something wrong or not
> understanding the concept here*

2nd argument to GDALGenImgProjTransform is TRUE so you are reprojecting
from, not to mercator
_______________________________________________
gdal-dev mailing list
gdal-dev at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20091102/624838b5/attachment.html

More information about the gdal-dev mailing list