[Gdal-dev] Geo->local coordinate transformation
Frank Warmerdam
warmerdam at pobox.com
Wed May 16 14:59:43 EDT 2007
Kevin Bentley wrote:
> I have a project where I'm working with geographic raster images and I
> need to be able to do distance calculations between two points in the
> image.
>
> I was thinking I could create a local SRS using a corner of the raster
> as the origin, then just transform from the lat/lon coordinates to the
> local coordinates (which would just be distance from the corner in
> meters) to make my calculations the most accurate. But I'm not sure if
> this is possible with OGRSpatialReference. Can anyone tell me how I
> could create a local OGRSpatialReference object with the origin of my
> choosing? Or maybe there's an easier way to do what I'm looking for.
Kevin,
Assuming your image size is not too large (in the sense of geographic
area covered, not file size), you can define a local projected coordinate
system using perhaps the center of the image as the central meridian and
reference point. Then convert locations into this SRS and compute
cartesian distances.
I'm not really sure what the best choice of projected coordinate system
would be, but I think for a fairly small area Orthographic would be
reasonably well behaved, even if you go near the poles.
So you could create an OGRSpatialReference in C++ something like:
OGRSpatialReference oOrtho;
oOrtho.SetOS( long_center, lat_center, 0, 0 );
oOrtho.SetWellKnownGeogCS( "WGS84" );
Then you could create one for your lat/long coordinates:
OGRSpatialReference oWGS84;
oWGS84.SetWellKnownGeogCS( "WGS84" );
Then create a transformer.
OGRCoordinateTransformation *poTransformer =
OGRCreateCoordinateTransformation( &oWGS84, &oOrtho );
And transform points like:
double x = -117.0, y = 33.0, z = 0;
poTransformer->Transform( 1, &x, &y, &z );
I hope this is helpful.
Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush | President OSGeo, http://osgeo.org
More information about the Gdal-dev
mailing list