[Gdal-dev] Coordinate transform problem

Chapman, Martin MChapman at sanz.com
Sat Oct 16 15:52:23 EDT 2004


Ok, I figured it out.  I had numerous things wrong in my code outside
this function.  I still have one problem though.  The Transform method
of the OGRCoordinateTransformation class doesn't like it when I pass in
coordinates that are outside the valid limit for certain projections
(i.e. Mercator).  My new question is, how do I calculate what the valid
limits are for a projection like mercator?  Is it a matter of
subtracting False Easting and Northing or something like that?  Any help
on understanding how to calculate these limits for a projection would be
much appreciated.
 
Thanks,
Martin

	-----Original Message-----
	From: Chapman, Martin 
	Sent: Thursday, October 14, 2004 11:42 AM
	To: gdal-dev at remotesensing.org
	Subject: [Gdal-dev] Coordinate transform problem
	
	
	I recently switched my projection support from Proj4 to OGR and
I'm having some issues when using the OGRCoordinateTransformation
object.  Basically, it looks like not all of my points are being
transformed correctly when converting from one projection to the other.
(ie. AEA to MERC).  I check for errors when converting but no errors are
being thrown.  Basically my code looks like this:
	 
	OGRCoordinateTransformation* pCT = NULL;
	  pCT = OGRCreateCoordinateTransformation(&sourceSRS,
&targetSRS);
	  if ((CPLGetLastErrorNo() != OGRERR_NONE) || (!pCT)) throw
(char*) CPLGetLastErrorMsg();
	 
	  if (pGeometry->GetGeometryTypeId() == VPWkbPolygon)
	  {
	   CVPPtr< IVPPolygon> spPolygon = (IVPPolygon*) pGeometry;
	   spPolygon->GetExteriorRing()->GetCoords(&pXCoords,
&pYCoords);
	 
	   vector< double>* pNewXCoords = new vector<
double>(*pXCoords);
	   vector< double>* pNewYCoords = new vector<
double>(*pYCoords);
	   if (pCT->Transform((int) pNewXCoords->size(),
&(*pNewXCoords)[0], &(*pNewYCoords)[0]))
	
((CVPLinearRing*)(spPolygon.p->GetExteriorRing()))->SetCoords(pNewXCoord
s, pNewYCoords);
	 
	   for (int i = 0; i < spPolygon->GetNumInteriorRing(); i++)
	   {
	    spPolygon->GetInteriorRingN(i)->GetCoords(&pXCoords,
&pYCoords);
	    vector< double>* pNewXCoords = new vector<
double>(*pXCoords);
	    vector< double>* pNewYCoords = new vector<
double>(*pYCoords);
	    if (pCT->Transform((int) pNewXCoords->size(),
&(*pNewXCoords)[0], &(*pNewYCoords)[0]))
	
((CVPLinearRing*)(spPolygon.p->GetInteriorRingN(i)))->SetCoords(pNewXCoo
rds, pNewYCoords);
	   }
	  }
	 
	  if (pCT) delete pCT;
	 
	I understand that some projections have valid lat/lon ranges
that can be less than others (ie. Merc vs. latlong), should I not be
passing points that are greater than a certain range?  I was thinking
that the proj library would wrap any longitudes if they needed wrapping.
Is this a wrong assumption?  Can anyone see what I'm doing wrong.  I've
attached a screen shot to show what the half/baked transform looks like
when converting from AEA to MERC, and the .prj files I'm using for the
projection info...I load them using importFromESRI().  Also, I'm using
GDAL 1.19.  I know you're going to say upgrade...ok, I'll get on that.
	 
	Thanks for any help!
	 
	
	Martin Chapman
	Cell 303-885-1936
	Office 303-495-6300 x326
	mchapman at sanz.com
	http://www.sanz.com <http://www.sanz.com/> 
	 
	 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20041016/7d4af8b5/attachment.html


More information about the Gdal-dev mailing list