[Gdal-dev] Trapping coordinate transformation errors gracefully

Tim Sutton tim at linfiniti.com
Mon Jan 10 06:25:58 EST 2005


Hi

I am trying to compute a transform for a rectangle. Sometimes invalid data is 
being passed and I would like to be able to handle errors gracefully. 
Currently when ogr throws this error message (I include a bit of qgis stdout 
too for context):


vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
Rect inverse projection...
INPUT:
PROJCS["Alaska_Albers_Equal_Area_Conic",GEOGCS["GCS_WGS_1984",DATUM["WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Albers_Conic_Equal_Area"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["longitude_of_center",-154.0],PARAMETER["Standard_Parallel_1",55.0],PARAMETER["Standard_Parallel_2",65.0],PARAMETER["latitude_of_center",50.0],UNIT["Meter",1.0]]
OUTPUT:
GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 
84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],TOWGS84
[0,0,0,0,0,0,0],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9108"]],AXIS["Lat",NORTH],AXIS["Long",EAST],AUTHORITY["EPSG","4326"]]
INPUT RECT:
-173846,730736:255493,971426
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ERROR 1: latitude or longitude exceeded limits


As you see from the code excerpt below I do try to trap for the transform 
failing, but when the error is encountered QGIS segfaults. A backtrace is 
included at the end of this email - though I dont have gdal built with 
debugging support so I dont know how useful it is.

Many thanks for any help you may have to offer 

Regards

Tim Sutton

inline QgsRect QgsCoordinateTransform::inverseTransform(QgsRect theRect)
{
  if (mShortCircuit || !mInitialisedFlag) return theRect;
    // transform x
  double x1 = theRect.xMin(); 
  double y1 = theRect.yMin();
  double x2 = theRect.xMax(); 
  double y2 = theRect.yMax();  
#ifdef QGISDEBUG   
  
  std::cout << 
"vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv"<< 
std::endl;
  std::cout << "Rect inverse projection..." << std::endl;
  std::cout << "INPUT: " << std::endl << mSourceWKT << std::endl;
  std::cout << "OUTPUT: " << std::endl << mDestWKT  << std::endl;
  std::cout << "INPUT RECT: " << std::endl << x1 << "," << y1 << ":" << x2 << 
"," << y2 << std::endl;
  std::cout << 
"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << 
std::endl;
#endif  

  // Number of points to reproject------+
  //                                    | 
  //                                    V 
  if ( ! mDestToSourceXForm->Transform( 1, &x1, &y1 ) || ! 
mDestToSourceXForm->Transform( 1, &x2, &y2 ) )
  {
    //something bad happened....
    throw QgsCsException(QString("Coordinate inverse transform failed"));
  }
  else
  {
#ifdef QGISDEBUG 
    std::cout << "Xmin : " 
              << theRect.xMin() 
	      << "-->" << x1 
	      << ", Ymin: " 
	      << theRect.yMin() 
	      << " -->" << y1
              << "Xmax : " 
              << theRect.xMax() 
	      << "-->" << x2 
	      << ", Ymax: " 
	      << theRect.yMax() 
	      << " -->" << y2	      
	      << std::endl;
#endif        
    return QgsRect(x1, y1, x2 , y2);
  } 
}


#0  0xffffe410 in ?? ()
#1  0xbfffdcb8 in ?? ()
#2  0x00000006 in ?? ()
#3  0x4129e529 in abort () from /lib/tls/libc.so.6
#4  0x41223c25 in __cxxabiv1::__terminate () from /usr//lib/libstdc++.so.5
#5  0x41223c62 in std::terminate () from /usr//lib/libstdc++.so.5
#6  0x41223da2 in __cxa_throw () from /usr//lib/libstdc++.so.5
#7  0x080ff9b5 in QgsCoordinateTransform::inverseTransform (this=Variable 
"this" is not available.
) at qshared.h:50
#8  0x080f8d9a in QgsMapCanvas::render (this=0x83efb10, theQPaintDevice=0x0) 
at memory:271


-- 

Procrastination 
"Hard Work Often Pays Off After Time, but Laziness Always Pays Off Now." 



More information about the Gdal-dev mailing list