Skip to content
Permalink
Browse files

add ESRI .prj test to make sure towgs84 is ok (bug #5598), and add Qg…

…sCoordinateReferenceSystem::createFromUserInput()
  • Loading branch information
etiennesky authored and jef-n committed May 28, 2012
1 parent 59a4db6 commit ae753b87ec0de0379ad0ef5b476b18605f8def19
@@ -131,6 +131,25 @@ bool QgsCoordinateReferenceSystem::createFromString( const QString theDefinition
return result;
}

bool QgsCoordinateReferenceSystem::createFromUserInput( const QString theDefinition )
{
QString theWkt;
char *wkt = NULL;
OGRSpatialReferenceH crs = OSRNewSpatialReference( NULL );

if ( OSRSetFromUserInput( crs, theDefinition.toLocal8Bit().constData() ) == OGRERR_NONE )
{
if ( OSRExportToWkt( crs, &wkt ) == OGRERR_NONE )
{
theWkt = wkt;
OGRFree( wkt );
}
OSRDestroySpatialReference( crs );
}
QgsDebugMsg( "theDefinition: " + theDefinition + " theWkt = " + theWkt );
return createFromWkt( theWkt );
}

bool QgsCoordinateReferenceSystem::createFromOgcWmsCrs( QString theCrs )
{
QRegExp re( "(user|custom|qgis):(\\d+)", Qt::CaseInsensitive );
@@ -171,6 +171,21 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
*/
bool createFromString( const QString theDefinition );

/*! Set up this srs from a various text formats.
*
* Valid formats: WKT string, "EPSG:n", "EPSGA:n", "AUTO:proj_id,unit_id,lon0,lat0",
* "urn:ogc:def:crs:EPSG::n", PROJ.4 string, filename (with WKT, XML or PROJ.4 string),
* well known name (such as NAD27, NAD83, WGS84 or WGS72),
* ESRI::[WKT string] (directly or in a file), "IGNF:xxx"
*
* For more details on supported formats see OGRSpatialReference::SetFromUserInput()
* ( http://www.gdal.org/ogr/classOGRSpatialReference.html#aec3c6a49533fe457ddc763d699ff8796 )
* @note this function generates a WKT string using OSRSetFromUserInput() and
* passes it to createFromWkt() function.
* @param theDefinition A String containing a coordinate reference system definition.
*/
bool createFromUserInput( const QString theDefinition );

/*! Find out whether this CRS is correctly initialised and usable */
bool isValid() const;

@@ -40,6 +40,7 @@ class TestQgsCoordinateReferenceSystem: public QObject
void createFromOgcWmsCrs();
void createFromSrid();
void createFromWkt();
void createFromESRIWkt();
void createFromSrsId();
void createFromProj4();
void isValid();
@@ -72,7 +73,7 @@ void TestQgsCoordinateReferenceSystem::initTestCase()
QgsApplication::showSettings();
qDebug() << "GEOPROJ4 constant: " << GEOPROJ4;
qDebug() << "GDAL version (build): " << GDAL_RELEASE_NAME;
qDebug() << "GDAL version (runtime): " << GDALVersionInfo("RELEASE_NAME");
qDebug() << "GDAL version (runtime): " << GDALVersionInfo( "RELEASE_NAME" );
qDebug() << "PROJ.4 version: " << PJ_VERSION;
}

@@ -135,6 +136,26 @@ void TestQgsCoordinateReferenceSystem::createFromWkt()
debugPrint( myCrs );
QVERIFY( myCrs.isValid() );
}
void TestQgsCoordinateReferenceSystem::createFromESRIWkt()
{
QgsCoordinateReferenceSystem myCrs;
// this example file taken from bug #5598
QString myWKTString = "PROJCS[\"Indian_1960_UTM_Zone_48N\",GEOGCS[\"GCS_Indian_1960\",DATUM[\"D_Indian_1960\",SPHEROID[\"Everest_Adjustment_1937\",6377276.345,300.8017]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"False_Easting\",500000.0],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",105.0],PARAMETER[\"Scale_Factor\",0.9996],PARAMETER[\"Latitude_Of_Origin\",0.0],UNIT[\"Meter\",1.0]]";
#if GDAL_VERSION_NUM >= 1800
QString myProj4String = "+proj=utm +zone=48 +a=6377276.345 +b=6356075.41314024 +towgs84=198,881,317,0,0,0,0 +units=m +no_defs";
#else
// for GDAL <1.8 towgs84 is absent but we'll have to live with that...
QString myProj4String = "+proj=utm +zone=48 +a=6377276.345 +b=6356075.41314024 +units=m +no_defs";
#endif
QString myAuthId = "EPSG:3148";

// use createFromUserInput and add the ESRI:: prefix to force morphFromESRI
myCrs.createFromUserInput( "ESRI::" + myWKTString );
debugPrint( myCrs );
QVERIFY( myCrs.isValid() );
QVERIFY( myCrs.toProj4() == myProj4String );
QVERIFY( myCrs.authid() == myAuthId );
}
void TestQgsCoordinateReferenceSystem::createFromSrsId()
{
QgsCoordinateReferenceSystem myCrs;
@@ -239,10 +260,10 @@ void TestQgsCoordinateReferenceSystem::toWkt()
#else
// for GDAL <1.8
QString myStrippedWkt( "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID"
"[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],"
"AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY"
"[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY"
"[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]" );
"[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],"
"AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY"
"[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY"
"[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]" );
#endif
qDebug() << "wkt: " << myWkt;
qDebug() << "stripped: " << myStrippedWkt;

0 comments on commit ae753b8

Please sign in to comment.
You can’t perform that action at this time.