23 #include <QTemporaryFile> 25 #include <QDomElement> 28 #include <QTextStream> 43 #include <ogr_srs_api.h> 44 #include <cpl_error.h> 55 , mMapUnits(
QGis::UnknownUnit )
58 , mValidationHint(
"" )
59 , mAxisInverted( false )
61 mCRS = OSRNewSpatialReference( NULL );
67 , mMapUnits(
QGis::UnknownUnit )
70 , mValidationHint(
"" )
71 , mAxisInverted( false )
73 mCRS = OSRNewSpatialReference( NULL );
81 , mMapUnits(
QGis::UnknownUnit )
84 , mValidationHint(
"" )
85 , mAxisInverted( false )
87 mCRS = OSRNewSpatialReference( NULL );
93 OSRDestroySpatialReference( mCRS );
120 QRegExp reCrsId(
"^(epsg|postgis|internal)\\:(\\d+)$", Qt::CaseInsensitive );
121 if ( reCrsId.indexIn( theDefinition ) == 0 )
123 QString authName = reCrsId.cap( 1 ).toLower();
125 if ( authName ==
"epsg" )
127 if ( authName ==
"postgis" )
129 long id = reCrsId.cap( 2 ).toLong();
134 QRegExp reCrsStr(
"^(?:(wkt|proj4)\\:)?(.+)$", Qt::CaseInsensitive );
135 if ( reCrsStr.indexIn( theDefinition ) == 0 )
137 if ( reCrsStr.cap( 1 ).toLower() ==
"proj4" )
146 QString myName = QString(
" * %1 (%2)" )
147 .arg(
QObject::tr(
"Generated CRS",
"A CRS automatically generated from layer info get this prefix for description" ) )
168 #if GDAL_VERSION_NUM >= 1900 169 if ( theDefinition.startsWith(
"ESRI::" ) )
175 if ( OSRSetFromUserInput( crs, theDefinition.toLocal8Bit().constData() ) == OGRERR_NONE )
177 if ( OSRExportToWkt( crs, &wkt ) == OGRERR_NONE )
182 OSRDestroySpatialReference( crs );
192 #if GDAL_VERSION_NUM >= 1900 193 const char* configOld = CPLGetConfigOption(
"GDAL_FIX_ESRI_WKT",
"" );
194 const char* configNew =
"GEOGCS";
196 if ( strcmp( configOld,
"" ) == 0 )
198 CPLSetConfigOption(
"GDAL_FIX_ESRI_WKT", configNew );
199 if ( strcmp( configNew, CPLGetConfigOption(
"GDAL_FIX_ESRI_WKT",
"" ) ) != 0 )
201 .arg( configNew ).arg( CPLGetConfigOption(
"GDAL_FIX_ESRI_WKT",
"" ) ) );
202 QgsDebugMsg( QString(
"set GDAL_FIX_ESRI_WKT : %1" ).arg( configNew ) );
206 QgsDebugMsg( QString(
"GDAL_FIX_ESRI_WKT was already set : %1" ).arg( configNew ) );
213 QRegExp re(
"urn:ogc:def:crs:([^:]+).+([^:]+)", Qt::CaseInsensitive );
214 if ( re.exactMatch( theCrs ) )
216 theCrs = re.cap( 1 ) +
":" + re.cap( 2 );
220 re.setPattern(
"(user|custom|qgis):(\\d+)" );
221 if ( re.exactMatch( theCrs ) &&
createFromSrsId( re.cap( 2 ).toInt() ) )
231 if ( theCrs.compare(
"CRS:27", Qt::CaseInsensitive ) == 0 ||
232 theCrs.compare(
"OGC:CRS27", Qt::CaseInsensitive ) == 0 )
239 if ( theCrs.compare(
"CRS:83", Qt::CaseInsensitive ) == 0 ||
240 theCrs.compare(
"OGC:CRS83", Qt::CaseInsensitive ) == 0 )
247 if ( theCrs.compare(
"CRS:84", Qt::CaseInsensitive ) == 0 ||
248 theCrs.compare(
"OGC:CRS84", Qt::CaseInsensitive ) == 0 )
260 mCRS = OSRNewSpatialReference( NULL );
270 mDescription = srs.mDescription;
271 mProjectionAcronym = srs.mProjectionAcronym;
272 mEllipsoidAcronym = srs.mEllipsoidAcronym;
273 mGeoFlag = srs.mGeoFlag;
274 mAxisInverted = srs.mAxisInverted;
275 mMapUnits = srs.mMapUnits;
277 mAuthId = srs.mAuthId;
278 mIsValidFlag = srs.mIsValidFlag;
279 mValidationHint = srs.mValidationHint;
284 OSRDestroySpatialReference( mCRS );
285 mCRS = OSRClone( srs.mCRS );
300 if ( mCustomSrsValidation )
301 mCustomSrsValidation( *
this );
318 "srs_id", QString::number(
id ) );
321 bool QgsCoordinateReferenceSystem::loadFromDb( QString db, QString expression, QString value )
323 QgsDebugMsgLevel(
"load CRS from " + db +
" where " + expression +
" is " + value, 3 );
324 mIsValidFlag =
false;
327 QFileInfo myInfo( db );
328 if ( !myInfo.exists() )
330 QgsDebugMsg(
"failed : " + db +
" does not exist!" );
336 sqlite3_stmt *myPreparedStatement;
339 myResult = openDb( db, &myDatabase );
340 if ( myResult != SQLITE_OK )
342 QgsDebugMsg(
"failed : " + db +
" could not be opened!" );
358 QString mySql =
"select srs_id,description,projection_acronym," 359 "ellipsoid_acronym,parameters,srid,auth_name||':'||auth_id,is_geo " 360 "from tbl_srs where " + expression +
"=" + quotedValue( value ) +
" order by deprecated";
361 myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(),
362 mySql.toUtf8().length(),
363 &myPreparedStatement, &myTail );
365 if ( myResult == SQLITE_OK && sqlite3_step( myPreparedStatement ) == SQLITE_ROW )
367 mSrsId = QString::fromUtf8((
char * )sqlite3_column_text(
368 myPreparedStatement, 0 ) ).toLong();
369 mDescription = QString::fromUtf8((
char * )sqlite3_column_text(
370 myPreparedStatement, 1 ) );
371 mProjectionAcronym = QString::fromUtf8((
char * )sqlite3_column_text( myPreparedStatement, 2 ) );
372 mEllipsoidAcronym = QString::fromUtf8((
char * )sqlite3_column_text( myPreparedStatement, 3 ) );
373 mProj4 = QString::fromUtf8((
char * )sqlite3_column_text( myPreparedStatement, 4 ) );
374 mSRID = QString::fromUtf8((
char * )sqlite3_column_text( myPreparedStatement, 5 ) ).toLong();
375 mAuthId = QString::fromUtf8((
char * )sqlite3_column_text( myPreparedStatement, 6 ) );
376 mGeoFlag = QString::fromUtf8((
char * )sqlite3_column_text( myPreparedStatement, 7 ) ).toInt() != 0;
381 mAuthId = QString(
"USER:%1" ).arg( mSrsId );
383 else if ( mAuthId.startsWith(
"EPSG:", Qt::CaseInsensitive ) )
385 OSRDestroySpatialReference( mCRS );
386 mCRS = OSRNewSpatialReference( NULL );
387 mIsValidFlag = OSRSetFromUserInput( mCRS, mAuthId.toLower().toAscii() ) == OGRERR_NONE;
393 setProj4String( mProj4 );
400 sqlite3_finalize( myPreparedStatement );
401 sqlite3_close( myDatabase );
407 if ( mAxisInverted == -1 )
409 OGRAxisOrientation orientation;
410 OSRGetAxis( mCRS, OSRIsGeographic( mCRS ) ?
"GEOGCS" :
"PROJCS", 0, &orientation );
413 if ( orientation == OAO_Other && mAuthId.startsWith(
"EPSG:", Qt::CaseInsensitive ) )
417 if ( OSRImportFromEPSGA( crs, mAuthId.mid( 5 ).toInt() ) == OGRERR_NONE )
419 OSRGetAxis( crs, OSRIsGeographic( crs ) ?
"GEOGCS" :
"PROJCS", 0, &orientation );
422 OSRDestroySpatialReference( crs );
425 mAxisInverted = orientation == OAO_North;
428 return mAxisInverted != 0;
433 mIsValidFlag =
false;
437 if ( theWkt.isEmpty() )
439 QgsDebugMsg(
"theWkt is uninitialised, operation failed" );
443 QByteArray ba = theWkt.toLatin1();
444 const char *pWkt = ba.data();
446 OGRErr myInputResult = OSRImportFromWkt( mCRS, (
char ** ) & pWkt );
448 if ( myInputResult != OGRERR_NONE )
450 QgsDebugMsg(
"\n---------------------------------------------------------------" );
451 QgsDebugMsg(
"This CRS could *** NOT *** be set from the supplied Wkt " );
453 QgsDebugMsg( QString(
"UNUSED WKT: %1" ).arg( pWkt ) );
454 QgsDebugMsg(
"---------------------------------------------------------------\n" );
458 if ( OSRAutoIdentifyEPSG( mCRS ) == OGRERR_NONE )
460 QString
authid = QString(
"%1:%2" )
461 .arg( OSRGetAuthorityName( mCRS, NULL ) )
462 .arg( OSRGetAuthorityCode( mCRS, NULL ) );
472 char *proj4src = NULL;
473 OSRExportToProj4( mCRS, &proj4src );
485 OSRExportToProj4( mCRS, &proj4src );
495 QString myName = QString(
" * %1 (%2)" )
496 .arg(
QObject::tr(
"Generated CRS",
"A CRS automatically generated from layer info get this prefix for description" ) )
522 QString myProj4String = theProj4String.trimmed();
524 mIsValidFlag =
false;
527 QRegExp myProjRegExp(
"\\+proj=(\\S+)" );
528 int myStart = myProjRegExp.indexIn( myProj4String );
531 QgsDebugMsg(
"proj string supplied has no +proj argument" );
535 mProjectionAcronym = myProjRegExp.cap( 1 );
537 QRegExp myEllipseRegExp(
"\\+ellps=(\\S+)" );
538 myStart = myEllipseRegExp.indexIn( myProj4String );
541 QgsDebugMsg(
"proj string supplied has no +ellps argument" );
542 mEllipsoidAcronym =
"";
546 mEllipsoidAcronym = myEllipseRegExp.cap( 1 );
549 QRegExp myAxisRegExp(
"\\+a=(\\S+)" );
550 myStart = myAxisRegExp.indexIn( myProj4String );
553 QgsDebugMsg(
"proj string supplied has no +a argument" );
565 QgsCoordinateReferenceSystem::RecordMap myRecord;
571 myRecord = getRecord(
"select * from tbl_srs where parameters=" + quotedValue( myProj4String ) +
" order by deprecated" );
572 if ( myRecord.empty() )
577 QRegExp myLat1RegExp(
"\\+lat_1=\\S+" );
578 QRegExp myLat2RegExp(
"\\+lat_2=\\S+" );
583 QString lat1Str =
"";
584 QString lat2Str =
"";
585 myStart1 = myLat1RegExp.indexIn( myProj4String, myStart1 );
586 myStart2 = myLat2RegExp.indexIn( myProj4String, myStart2 );
587 if ( myStart1 != -1 && myStart2 != -1 )
589 myLength1 = myLat1RegExp.matchedLength();
590 myLength2 = myLat2RegExp.matchedLength();
595 if ( lat1Str !=
"" && lat2Str !=
"" )
598 QString theProj4StringModified = myProj4String;
603 myStart2 = myLat2RegExp.indexIn( theProj4String, myStart2 );
605 QgsDebugMsg(
"trying proj4string match with swapped lat_1,lat_2" );
606 myRecord = getRecord(
"select * from tbl_srs where parameters=" + quotedValue( theProj4StringModified.trimmed() ) +
" order by deprecated" );
610 if ( myRecord.empty() )
617 QString sql =
"SELECT * FROM tbl_srs WHERE ";
624 QStringList myParams;
625 foreach ( QString param, myProj4String.split( QRegExp(
"\\s+(?=\\+)" ), QString::SkipEmptyParts ) )
627 QString arg = QString(
"' '||parameters||' ' LIKE %1" ).arg( quotedValue( QString(
"% %1 %" ).arg( param.trimmed() ) ) );
628 if ( param.startsWith(
"+datum=" ) )
636 myParams << param.trimmed();
640 if ( !datum.isEmpty() )
642 myRecord = getRecord( sql + delim + datum +
" order by deprecated" );
645 if ( myRecord.empty() )
648 myRecord = getRecord( sql +
" order by deprecated" );
651 if ( !myRecord.empty() )
654 QStringList foundParams;
655 foreach ( QString param, myRecord[
"parameters"].split( QRegExp(
"\\s+(?=\\+)" ), QString::SkipEmptyParts ) )
657 if ( !param.startsWith(
"+datum=" ) )
658 foundParams << param.trimmed();
664 if ( myParams != foundParams )
671 if ( !myRecord.empty() )
673 mySrsId = myRecord[
"srs_id"].toLong();
674 QgsDebugMsg(
"proj4string param match search for srsid returned srsid: " + QString::number( mySrsId ) );
683 QgsDebugMsg(
"globbing search for srsid from this proj string" );
684 setProj4String( myProj4String );
686 QgsDebugMsg(
"globbing search for srsid returned srsid: " + QString::number( mySrsId ) );
693 mIsValidFlag =
false;
700 QgsDebugMsg(
"Projection is not found in databases." );
702 setProj4String( myProj4String );
709 QgsCoordinateReferenceSystem::RecordMap QgsCoordinateReferenceSystem::getRecord( QString theSql )
711 QString myDatabaseFileName;
712 QgsCoordinateReferenceSystem::RecordMap myMap;
714 QString myFieldValue;
717 sqlite3_stmt *myPreparedStatement;
723 QFileInfo myInfo( myDatabaseFileName );
724 if ( !myInfo.exists() )
726 QgsDebugMsg(
"failed : " + myDatabaseFileName +
" does not exist!" );
731 myResult = openDb( myDatabaseFileName, &myDatabase );
732 if ( myResult != SQLITE_OK )
737 myResult = sqlite3_prepare( myDatabase, theSql.toUtf8(), theSql.toUtf8().length(), &myPreparedStatement, &myTail );
739 if ( myResult == SQLITE_OK && sqlite3_step( myPreparedStatement ) == SQLITE_ROW )
742 int myColumnCount = sqlite3_column_count( myPreparedStatement );
744 for (
int myColNo = 0; myColNo < myColumnCount; myColNo++ )
746 myFieldName = QString::fromUtf8((
char * )sqlite3_column_name( myPreparedStatement, myColNo ) );
747 myFieldValue = QString::fromUtf8((
char * )sqlite3_column_text( myPreparedStatement, myColNo ) );
748 myMap[myFieldName] = myFieldValue;
750 if ( sqlite3_step( myPreparedStatement ) != SQLITE_DONE )
764 sqlite3_finalize( myPreparedStatement );
765 sqlite3_close( myDatabase );
768 QFileInfo myFileInfo;
769 myFileInfo.setFile( myDatabaseFileName );
770 if ( !myFileInfo.exists() )
777 myResult = openDb( myDatabaseFileName, &myDatabase );
778 if ( myResult != SQLITE_OK )
783 myResult = sqlite3_prepare( myDatabase, theSql.toUtf8(), theSql.toUtf8().length(), &myPreparedStatement, &myTail );
785 if ( myResult == SQLITE_OK && sqlite3_step( myPreparedStatement ) == SQLITE_ROW )
787 int myColumnCount = sqlite3_column_count( myPreparedStatement );
789 for (
int myColNo = 0; myColNo < myColumnCount; myColNo++ )
791 myFieldName = QString::fromUtf8((
char * )sqlite3_column_name( myPreparedStatement, myColNo ) );
792 myFieldValue = QString::fromUtf8((
char * )sqlite3_column_text( myPreparedStatement, myColNo ) );
793 myMap[myFieldName] = myFieldValue;
796 if ( sqlite3_step( myPreparedStatement ) != SQLITE_DONE )
807 sqlite3_finalize( myPreparedStatement );
808 sqlite3_close( myDatabase );
812 RecordMap::Iterator it;
813 for ( it = myMap.begin(); it != myMap.end(); ++it )
841 if ( mDescription.isNull() )
853 if ( mProjectionAcronym.isNull() )
859 return mProjectionAcronym;
865 if ( mEllipsoidAcronym.isNull() )
871 return mEllipsoidAcronym;
880 if ( mProj4.isEmpty() )
883 char *proj4src = NULL;
884 OSRExportToProj4( mCRS, &proj4src );
889 return mProj4.trimmed();
906 void QgsCoordinateReferenceSystem::setInternalId(
long theSrsId )
910 void QgsCoordinateReferenceSystem::setAuthId( QString authId )
914 void QgsCoordinateReferenceSystem::setSrid(
long theSrid )
918 void QgsCoordinateReferenceSystem::setDescription( QString theDescription )
920 mDescription = theDescription;
922 void QgsCoordinateReferenceSystem::setProj4String( QString theProj4String )
924 mProj4 = theProj4String;
928 OSRDestroySpatialReference( mCRS );
929 mCRS = OSRNewSpatialReference( NULL );
930 mIsValidFlag = OSRImportFromProj4( mCRS, theProj4String.trimmed().toLatin1().constData() ) == OGRERR_NONE;
934 #if defined(QGISDEBUG) && QGISDEBUG>=3 938 void QgsCoordinateReferenceSystem::setGeographicFlag(
bool theGeoFlag )
940 mGeoFlag = theGeoFlag;
942 void QgsCoordinateReferenceSystem::setEpsg(
long theEpsg )
944 mAuthId = QString(
"EPSG:%1" ).arg( theEpsg );
946 void QgsCoordinateReferenceSystem::setProjectionAcronym( QString theProjectionAcronym )
948 mProjectionAcronym = theProjectionAcronym;
950 void QgsCoordinateReferenceSystem::setEllipsoidAcronym( QString theEllipsoidAcronym )
952 mEllipsoidAcronym = theEllipsoidAcronym;
955 void QgsCoordinateReferenceSystem::setMapUnits()
969 if ( OSRIsProjected( mCRS ) )
971 double toMeter = OSRGetLinearUnits( mCRS, &unitName );
972 QString unit( unitName );
979 static const double feetToMeter = 0.3048;
980 static const double smallNum = 1e-3;
982 if ( qAbs( toMeter - feetToMeter ) < smallNum )
985 QgsDebugMsg(
"Projection has linear units of " + unit );
989 else if ( unit ==
"Foot" )
999 OSRGetAngularUnits( mCRS, &unitName );
1000 QString unit( unitName );
1001 if ( unit ==
"degree" )
1005 QgsDebugMsg(
"Unsupported map units of " + unit );
1024 if ( mEllipsoidAcronym.isNull() || mProjectionAcronym.isNull()
1027 QgsDebugMsg(
"QgsCoordinateReferenceSystem::findMatchingProj will only " 1028 "work if prj acr ellipsoid acr and proj4string are set" 1029 " and the current projection is valid!" );
1035 sqlite3_stmt *myPreparedStatement;
1040 QString mySql = QString(
"select srs_id,parameters from tbl_srs where " 1041 "projection_acronym=%1 and ellipsoid_acronym=%2 order by deprecated" )
1042 .arg( quotedValue( mProjectionAcronym ) )
1043 .arg( quotedValue( mEllipsoidAcronym ) );
1048 myResult = openDb( myDatabaseFileName, &myDatabase );
1049 if ( myResult != SQLITE_OK )
1054 myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
1056 if ( myResult == SQLITE_OK )
1059 while ( sqlite3_step( myPreparedStatement ) == SQLITE_ROW )
1061 QString mySrsId = QString::fromUtf8((
char * )sqlite3_column_text( myPreparedStatement, 0 ) );
1062 QString myProj4String = QString::fromUtf8((
char * )sqlite3_column_text( myPreparedStatement, 1 ) );
1063 if (
toProj4() == myProj4String.trimmed() )
1065 QgsDebugMsg(
"-------> MATCH FOUND in srs.db srsid: " + mySrsId );
1067 sqlite3_finalize( myPreparedStatement );
1068 sqlite3_close( myDatabase );
1069 return mySrsId.toLong();
1077 QgsDebugMsg(
"no match found in srs.db, trying user db now!" );
1079 sqlite3_finalize( myPreparedStatement );
1080 sqlite3_close( myDatabase );
1087 myResult = openDb( myDatabaseFileName, &myDatabase );
1088 if ( myResult != SQLITE_OK )
1093 myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
1095 if ( myResult == SQLITE_OK )
1098 while ( sqlite3_step( myPreparedStatement ) == SQLITE_ROW )
1100 QString mySrsId = QString::fromUtf8((
char * )sqlite3_column_text( myPreparedStatement, 0 ) );
1101 QString myProj4String = QString::fromUtf8((
char * )sqlite3_column_text( myPreparedStatement, 1 ) );
1102 if (
toProj4() == myProj4String.trimmed() )
1104 QgsDebugMsg(
"-------> MATCH FOUND in user qgis.db srsid: " + mySrsId );
1106 sqlite3_finalize( myPreparedStatement );
1107 sqlite3_close( myDatabase );
1108 return mySrsId.toLong();
1119 sqlite3_finalize( myPreparedStatement );
1120 sqlite3_close( myDatabase );
1126 return ( !mIsValidFlag && !theSrs.mIsValidFlag ) ||
1127 ( mIsValidFlag && theSrs.mIsValidFlag && theSrs.
authid() ==
authid() );
1132 return !( *
this == theSrs );
1137 if ( mWkt.isEmpty() )
1140 if ( OSRExportToWkt( mCRS, &wkt ) == OGRERR_NONE )
1151 QgsDebugMsg(
"Reading Spatial Ref Sys from xml ------------------------!" );
1152 QDomNode srsNode = theNode.namedItem(
"spatialrefsys" );
1154 if ( ! srsNode.isNull() )
1156 bool initialized =
false;
1158 long srsid = srsNode.namedItem(
"srsid" ).toElement().text().toLong();
1164 myNode = srsNode.namedItem(
"authid" );
1165 if ( !myNode.isNull() )
1176 myNode = srsNode.namedItem(
"epsg" );
1177 if ( !myNode.isNull() )
1189 QgsDebugMsg(
"Ignoring authid/epsg for user crs." );
1198 myNode = srsNode.namedItem(
"proj4" );
1207 QgsDebugMsg(
"Setting from elements one by one" );
1209 myNode = srsNode.namedItem(
"proj4" );
1210 setProj4String( myNode.toElement().text() );
1212 myNode = srsNode.namedItem(
"srsid" );
1213 setInternalId( myNode.toElement().text().toLong() );
1215 myNode = srsNode.namedItem(
"srid" );
1216 setSrid( myNode.toElement().text().toLong() );
1218 myNode = srsNode.namedItem(
"authid" );
1219 setAuthId( myNode.toElement().text() );
1221 myNode = srsNode.namedItem(
"description" );
1222 setDescription( myNode.toElement().text() );
1224 myNode = srsNode.namedItem(
"projectionacronym" );
1225 setProjectionAcronym( myNode.toElement().text() );
1227 myNode = srsNode.namedItem(
"ellipsoidacronym" );
1228 setEllipsoidAcronym( myNode.toElement().text() );
1230 myNode = srsNode.namedItem(
"geographicflag" );
1231 if ( myNode.toElement().text().compare(
"true" ) )
1233 setGeographicFlag(
true );
1237 setGeographicFlag(
false );
1244 mIsValidFlag =
true;
1252 QString myName = QString(
" * %1 (%2)" )
1253 .arg(
QObject::tr(
"Generated CRS",
"A CRS automatically generated from layer info get this prefix for description" ) )
1271 QDomElement myLayerNode = theNode.toElement();
1272 QDomElement mySrsElement = theDoc.createElement(
"spatialrefsys" );
1274 QDomElement myProj4Element = theDoc.createElement(
"proj4" );
1275 myProj4Element.appendChild( theDoc.createTextNode(
toProj4() ) );
1276 mySrsElement.appendChild( myProj4Element );
1278 QDomElement mySrsIdElement = theDoc.createElement(
"srsid" );
1279 mySrsIdElement.appendChild( theDoc.createTextNode( QString::number(
srsid() ) ) );
1280 mySrsElement.appendChild( mySrsIdElement );
1282 QDomElement mySridElement = theDoc.createElement(
"srid" );
1283 mySridElement.appendChild( theDoc.createTextNode( QString::number(
postgisSrid() ) ) );
1284 mySrsElement.appendChild( mySridElement );
1286 QDomElement myEpsgElement = theDoc.createElement(
"authid" );
1287 myEpsgElement.appendChild( theDoc.createTextNode(
authid() ) );
1288 mySrsElement.appendChild( myEpsgElement );
1290 QDomElement myDescriptionElement = theDoc.createElement(
"description" );
1291 myDescriptionElement.appendChild( theDoc.createTextNode(
description() ) );
1292 mySrsElement.appendChild( myDescriptionElement );
1294 QDomElement myProjectionAcronymElement = theDoc.createElement(
"projectionacronym" );
1295 myProjectionAcronymElement.appendChild( theDoc.createTextNode(
projectionAcronym() ) );
1296 mySrsElement.appendChild( myProjectionAcronymElement );
1298 QDomElement myEllipsoidAcronymElement = theDoc.createElement(
"ellipsoidacronym" );
1299 myEllipsoidAcronymElement.appendChild( theDoc.createTextNode(
ellipsoidAcronym() ) );
1300 mySrsElement.appendChild( myEllipsoidAcronymElement );
1302 QDomElement myGeographicFlagElement = theDoc.createElement(
"geographicflag" );
1303 QString myGeoFlagText =
"false";
1306 myGeoFlagText =
"true";
1309 myGeographicFlagElement.appendChild( theDoc.createTextNode( myGeoFlagText ) );
1310 mySrsElement.appendChild( myGeographicFlagElement );
1312 myLayerNode.appendChild( mySrsElement );
1326 QString QgsCoordinateReferenceSystem::proj4FromSrsId(
const int theSrsId )
1329 QString myDatabaseFileName;
1330 QString myProjString;
1331 QString mySql = QString(
"select parameters from tbl_srs where srs_id = %1 order by deprecated" ).arg( theSrsId );
1333 QgsDebugMsg(
"mySrsId = " + QString::number( theSrsId ) );
1344 QFileInfo myFileInfo;
1345 myFileInfo.setFile( myDatabaseFileName );
1346 if ( !myFileInfo.exists() )
1360 rc = openDb( myDatabaseFileName, &db );
1367 sqlite3_stmt *ppStmt;
1369 rc = sqlite3_prepare( db, mySql.toUtf8(), mySql.toUtf8().length(), &ppStmt, &pzTail );
1372 if ( rc == SQLITE_OK )
1374 if ( sqlite3_step( ppStmt ) == SQLITE_ROW )
1376 myProjString = QString::fromUtf8((
char* )sqlite3_column_text( ppStmt, 0 ) );
1380 sqlite3_finalize( ppStmt );
1382 sqlite3_close( db );
1385 return myProjString;
1388 int QgsCoordinateReferenceSystem::openDb( QString path,
sqlite3 **db,
bool readonly )
1391 int myResult = readonly
1392 ? sqlite3_open_v2( path.toUtf8().data(), db, SQLITE_OPEN_READONLY, NULL )
1393 : sqlite3_open( path.toUtf8().data(), db );
1395 if ( myResult != SQLITE_OK )
1397 QgsDebugMsg(
"Can't open database: " + QString( sqlite3_errmsg( *db ) ) );
1404 .arg( sqlite3_errmsg( *db ) ),
QObject::tr(
"CRS" ) );
1411 mCustomSrsValidation = f;
1416 return mCustomSrsValidation;
1419 void QgsCoordinateReferenceSystem::debugPrint()
1422 QgsDebugMsg(
"* Valid : " + ( mIsValidFlag ? QString(
"true" ) : QString(
"false" ) ) );
1423 QgsDebugMsg(
"* SrsId : " + QString::number( mSrsId ) );
1443 mValidationHint = html;
1448 return mValidationHint;
1456 if ( ! mIsValidFlag )
1464 QString proj4String = mProj4;
1465 if ( proj4String.isEmpty() )
1474 if ( getRecordCount() == 0 )
1476 mySql =
"insert into tbl_srs (srs_id,description,projection_acronym,ellipsoid_acronym,parameters,is_geo) values (" 1478 +
"," + quotedValue( name )
1481 +
"," + quotedValue(
toProj4() )
1486 mySql =
"insert into tbl_srs (description,projection_acronym,ellipsoid_acronym,parameters,is_geo) values (" 1487 + quotedValue( name )
1490 +
"," + quotedValue(
toProj4() )
1495 sqlite3_stmt *myPreparedStatement;
1499 if ( myResult != SQLITE_OK )
1501 QgsDebugMsg( QString(
"Can't open or create database %1: %2" )
1503 .arg( sqlite3_errmsg( myDatabase ) ) );
1506 QgsDebugMsg( QString(
"Update or insert sql \n%1" ).arg( mySql ) );
1507 myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
1510 if ( myResult == SQLITE_OK && sqlite3_step( myPreparedStatement ) == SQLITE_DONE )
1514 return_id = sqlite3_last_insert_rowid( myDatabase );
1515 setInternalId( return_id );
1520 QStringList projectionsProj4 = settings.value(
"/UI/recentProjectionsProj4" ).toStringList();
1521 QStringList projectionsAuthId = settings.value(
"/UI/recentProjectionsAuthId" ).toStringList();
1524 projectionsProj4.append(
toProj4() );
1525 projectionsAuthId.append(
authid() );
1526 settings.setValue(
"/UI/recentProjectionsProj4", projectionsProj4 );
1527 settings.setValue(
"/UI/recentProjectionsAuthId", projectionsAuthId );
1535 long QgsCoordinateReferenceSystem::getRecordCount()
1539 sqlite3_stmt *myPreparedStatement;
1541 long myRecordCount = 0;
1544 if ( myResult != SQLITE_OK )
1546 QgsDebugMsg( QString(
"Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) );
1550 QString mySql =
"select count(*) from tbl_srs";
1551 myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(), mySql.toUtf8().length(), &myPreparedStatement, &myTail );
1553 if ( myResult == SQLITE_OK )
1555 if ( sqlite3_step( myPreparedStatement ) == SQLITE_ROW )
1557 QString myRecordCountString = QString::fromUtf8((
char * )sqlite3_column_text( myPreparedStatement, 0 ) );
1558 myRecordCount = myRecordCountString.toLong();
1562 sqlite3_finalize( myPreparedStatement );
1563 sqlite3_close( myDatabase );
1564 return myRecordCount;
1567 QString QgsCoordinateReferenceSystem::quotedValue( QString value )
1569 value.replace(
"'",
"''" );
1570 return value.prepend(
"'" ).append(
"'" );
1574 bool QgsCoordinateReferenceSystem::loadWkts( QHash<int, QString> &wkts,
const char *filename )
1576 qDebug(
"Loading %s", filename );
1577 const char *pszFilename = CPLFindFile(
"gdal", filename );
1581 QFile csv( pszFilename );
1582 if ( !csv.open( QIODevice::ReadOnly ) )
1585 QTextStream lines( &csv );
1589 QString line = lines.readLine();
1590 if ( line.isNull() )
1593 if ( line.startsWith(
'#' ) )
1597 else if ( line.startsWith(
"include " ) )
1599 if ( !loadWkts( wkts, line.mid( 8 ).toUtf8() ) )
1604 int pos = line.indexOf(
"," );
1609 int epsg = line.left( pos ).toInt( &ok );
1613 wkts.insert( epsg, line.mid( pos + 1 ) );
1622 bool QgsCoordinateReferenceSystem::loadIDs( QHash<int, QString> &wkts )
1626 foreach ( QString csv, QStringList() <<
"gcs.csv" <<
"pcs.csv" <<
"vertcs.csv" <<
"compdcs.csv" <<
"geoccs.csv" )
1628 QString filename = CPLFindFile(
"gdal", csv.toUtf8() );
1630 QFile f( filename );
1631 if ( !f.open( QIODevice::ReadOnly ) )
1634 QTextStream lines( &f );
1641 QString line = lines.readLine();
1642 if ( line.isNull() )
1645 int pos = line.indexOf(
"," );
1650 int epsg = line.left( pos ).toInt( &ok );
1655 if ( epsg == 2218 || epsg == 2221 || epsg == 2296 || epsg == 2297 || epsg == 2298 || epsg == 2299 || epsg == 2300 || epsg == 2301 || epsg == 2302 ||
1656 epsg == 2303 || epsg == 2304 || epsg == 2305 || epsg == 2306 || epsg == 2307 || epsg == 2963 || epsg == 2985 || epsg == 2986 || epsg == 3052 ||
1657 epsg == 3053 || epsg == 3139 || epsg == 3144 || epsg == 3145 || epsg == 3173 || epsg == 3295 || epsg == 3993 || epsg == 4087 || epsg == 4088 ||
1658 epsg == 5017 || epsg == 5221 || epsg == 5224 || epsg == 5225 || epsg == 5514 || epsg == 5515 || epsg == 5516 || epsg == 5819 || epsg == 5820 ||
1659 epsg == 5821 || epsg == 32600 || epsg == 32663 || epsg == 32700 )
1662 if ( OSRImportFromEPSG( crs, epsg ) != OGRERR_NONE )
1664 qDebug(
"EPSG %d: not imported", epsg );
1669 if ( OSRExportToWkt( crs, &wkt ) != OGRERR_NONE )
1671 qWarning(
"EPSG %d: not exported to WKT", epsg );
1675 wkts.insert( epsg, wkt );
1683 qDebug(
"Loaded %d/%d from %s", n, l, filename.toUtf8().constData() );
1686 OSRDestroySpatialReference( crs );
1694 syncDatumTransform( dbFilePath );
1696 int inserted = 0, updated = 0, deleted = 0, errors = 0;
1701 if ( sqlite3_open( dbFilePath.toUtf8().constData(), &database ) != SQLITE_OK )
1707 if ( sqlite3_exec( database,
"BEGIN TRANSACTION", 0, 0, 0 ) != SQLITE_OK )
1709 qCritical(
"Could not begin transaction: %s [%s]\n",
QgsApplication::srsDbFilePath().toLocal8Bit().constData(), sqlite3_errmsg( database ) );
1714 if ( sqlite3_exec( database,
"alter table tbl_srs add noupdate boolean", 0, 0, 0 ) == SQLITE_OK )
1715 ( void )sqlite3_exec( database,
"update tbl_srs set noupdate=(auth_name='EPSG' and auth_id in (5513,5514,5221,2065,102067,4156,4818))", 0, 0, 0 );
1717 ( void )sqlite3_exec( database,
"UPDATE tbl_srs SET srid=141001 WHERE srid=41001 AND auth_name='OSGEO' AND auth_id='41001'", 0, 0, 0 );
1721 sqlite3_stmt *select;
1722 char *errMsg = NULL;
1726 QHash<int, QString> wkts;
1728 loadWkts( wkts,
"epsg.wkt" );
1730 qDebug(
"%d WKTs loaded", wkts.count() );
1732 for ( QHash<int, QString>::const_iterator it = wkts.constBegin(); it != wkts.constEnd(); ++it )
1734 QByteArray ba( it.value().toUtf8() );
1735 char *psz = ba.data();
1736 OGRErr ogrErr = OSRImportFromWkt( crs, &psz );
1737 if ( ogrErr != OGRERR_NONE )
1740 if ( OSRExportToProj4( crs, &psz ) != OGRERR_NONE )
1744 proj4 = proj4.trimmed();
1748 if ( proj4.isEmpty() )
1751 sql = QString(
"SELECT parameters,noupdate FROM tbl_srs WHERE auth_name='EPSG' AND auth_id='%1'" ).arg( it.key() );
1752 if ( sqlite3_prepare( database, sql.toAscii(), sql.size(), &select, &tail ) != SQLITE_OK )
1754 qCritical(
"Could not prepare: %s [%s]\n", sql.toAscii().constData(), sqlite3_errmsg( database ) );
1759 if ( sqlite3_step( select ) == SQLITE_ROW )
1761 srsProj4 = (
const char * ) sqlite3_column_text( select, 0 );
1763 if ( QString::fromUtf8((
char * )sqlite3_column_text( select, 1 ) ).toInt() != 0 )
1767 sqlite3_finalize( select );
1769 if ( !srsProj4.isEmpty() )
1771 if ( proj4 != srsProj4 )
1774 sql = QString(
"UPDATE tbl_srs SET parameters=%1 WHERE auth_name='EPSG' AND auth_id=%2" ).arg( quotedValue( proj4 ) ).arg( it.key() );
1776 if ( sqlite3_exec( database, sql.toUtf8(), 0, 0, &errMsg ) != SQLITE_OK )
1778 qCritical(
"Could not execute: %s [%s/%s]\n",
1779 sql.toLocal8Bit().constData(),
1780 sqlite3_errmsg( database ),
1781 errMsg ? errMsg :
"(unknown error)" );
1787 QgsDebugMsgLevel( QString(
"SQL: %1\n OLD:%2\n NEW:%3" ).arg( sql ).arg( srsProj4 ).arg( proj4 ), 3 );
1793 QRegExp projRegExp(
"\\+proj=(\\S+)" );
1794 if ( projRegExp.indexIn( proj4 ) < 0 )
1796 QgsDebugMsg( QString(
"EPSG %1: no +proj argument found [%2]" ).arg( it.key() ).arg( proj4 ) );
1800 QRegExp ellipseRegExp(
"\\+ellps=(\\S+)" );
1802 if ( ellipseRegExp.indexIn( proj4 ) >= 0 )
1804 ellps = ellipseRegExp.cap( 1 );
1807 QString name( OSRIsGeographic( crs ) ? OSRGetAttrValue( crs,
"GEOCS", 0 ) : OSRGetAttrValue( crs,
"PROJCS", 0 ) );
1808 if ( name.isEmpty() )
1811 sql = QString(
"INSERT INTO tbl_srs(description,projection_acronym,ellipsoid_acronym,parameters,srid,auth_name,auth_id,is_geo,deprecated) VALUES (%1,%2,%3,%4,%5,'EPSG',%5,%6,0)" )
1812 .arg( quotedValue( name ) )
1813 .arg( quotedValue( projRegExp.cap( 1 ) ) )
1814 .arg( quotedValue( ellps ) )
1815 .arg( quotedValue( proj4 ) )
1817 .arg( OSRIsGeographic( crs ) );
1820 if ( sqlite3_exec( database, sql.toUtf8(), 0, 0, &errMsg ) == SQLITE_OK )
1826 qCritical(
"Could not execute: %s [%s/%s]\n",
1827 sql.toLocal8Bit().constData(),
1828 sqlite3_errmsg( database ),
1829 errMsg ? errMsg :
"(unknown error)" );
1833 sqlite3_free( errMsg );
1838 sql =
"DELETE FROM tbl_srs WHERE auth_name='EPSG' AND NOT auth_id IN (";
1840 foreach (
int i, wkts.keys() )
1842 sql += delim + QString::number( i );
1845 sql +=
") AND NOT noupdate";
1847 if ( sqlite3_exec( database, sql.toUtf8(), 0, 0, 0 ) == SQLITE_OK )
1849 deleted = sqlite3_changes( database );
1854 qCritical(
"Could not execute: %s [%s]\n",
1855 sql.toLocal8Bit().constData(),
1856 sqlite3_errmsg( database ) );
1859 #if !defined(PJ_VERSION) || PJ_VERSION!=470 1860 sql = QString(
"select auth_name,auth_id,parameters from tbl_srs WHERE auth_name<>'EPSG' AND NOT deprecated AND NOT noupdate" );
1861 if ( sqlite3_prepare( database, sql.toAscii(), sql.size(), &select, &tail ) == SQLITE_OK )
1863 while ( sqlite3_step( select ) == SQLITE_ROW )
1865 const char *auth_name = (
const char * ) sqlite3_column_text( select, 0 );
1866 const char *auth_id = (
const char * ) sqlite3_column_text( select, 1 );
1867 const char *params = (
const char * ) sqlite3_column_text( select, 2 );
1869 QString input = QString(
"+init=%1:%2" ).arg( QString( auth_name ).toLower() ).arg( auth_id );
1870 projPJ pj = pj_init_plus( input.toAscii() );
1873 input = QString(
"+init=%1:%2" ).arg( QString( auth_name ).toUpper() ).arg( auth_id );
1874 pj = pj_init_plus( input.toAscii() );
1879 char *def = pj_get_def( pj, 0 );
1885 input.prepend(
' ' ).append(
' ' );
1886 if ( proj4.startsWith( input ) )
1888 proj4 = proj4.mid( input.size() );
1889 proj4 = proj4.trimmed();
1892 if ( proj4 != params )
1894 sql = QString(
"UPDATE tbl_srs SET parameters=%1 WHERE auth_name=%2 AND auth_id=%3" )
1895 .arg( quotedValue( proj4 ) )
1896 .arg( quotedValue( auth_name ) )
1897 .arg( quotedValue( auth_id ) );
1899 if ( sqlite3_exec( database, sql.toUtf8(), 0, 0, &errMsg ) == SQLITE_OK )
1902 QgsDebugMsgLevel( QString(
"SQL: %1\n OLD:%2\n NEW:%3" ).arg( sql ).arg( params ).arg( proj4 ), 3 );
1906 qCritical(
"Could not execute: %s [%s/%s]\n",
1907 sql.toLocal8Bit().constData(),
1908 sqlite3_errmsg( database ),
1909 errMsg ? errMsg :
"(unknown error)" );
1916 QgsDebugMsg( QString(
"could not retrieve proj string for %1 from PROJ" ).arg( input ) );
1921 QgsDebugMsgLevel( QString(
"could not retrieve crs for %1 from PROJ" ).arg( input ), 3 );
1930 qCritical(
"Could not execute: %s [%s]\n",
1931 sql.toLocal8Bit().constData(),
1932 sqlite3_errmsg( database ) );
1936 OSRDestroySpatialReference( crs );
1938 if ( sqlite3_exec( database,
"COMMIT", 0, 0, 0 ) != SQLITE_OK )
1940 qCritical(
"Could not commit transaction: %s [%s]\n",
QgsApplication::srsDbFilePath().toLocal8Bit().constData(), sqlite3_errmsg( database ) );
1944 sqlite3_close( database );
1946 qWarning(
"CRS update (inserted:%d updated:%d deleted:%d errors:%d)", inserted, updated, deleted, errors );
1951 return updated + inserted;
1954 bool QgsCoordinateReferenceSystem::syncDatumTransform(
const QString& dbPath )
1956 const char *filename = CSVFilename(
"datum_shift.csv" );
1957 FILE *fp = VSIFOpen( filename,
"rb" );
1963 char **fieldnames = CSVReadParseLine( fp );
1975 {
"SOURCE_CRS_CODE",
"source_crs_code", -1 },
1976 {
"TARGET_CRS_CODE",
"target_crs_code", -1 },
1977 {
"REMARKS",
"remarks", -1 },
1978 {
"COORD_OP_SCOPE",
"scope", -1 },
1979 {
"AREA_OF_USE_CODE",
"area_of_use_code", -1 },
1985 {
"DEPRECATED",
"deprecated", -1 },
1986 {
"COORD_OP_METHOD_CODE",
"coord_op_method_code", -1 },
1994 {
"PREFERRED",
"preferred", -1 },
1995 {
"COORD_OP_CODE",
"coord_op_code", -1 },
1998 QString update =
"UPDATE tbl_datum_transform SET ";
1999 QString insert, values;
2001 int n = CSLCount( fieldnames );
2003 int idxid = -1, idxrx = -1, idxry = -1, idxrz = -1, idxmcode = -1;
2004 for (
unsigned int i = 0; i <
sizeof( map ) /
sizeof( *map ); i++ )
2006 bool last = i ==
sizeof( map ) /
sizeof( *map ) - 1;
2008 map[i].idx = CSLFindString( fieldnames, map[i].src );
2009 if ( map[i].idx < 0 )
2011 qWarning(
"field %s not found", map[i].src );
2012 CSLDestroy( fieldnames );
2017 if ( strcmp( map[i].src,
"COORD_OP_CODE" ) == 0 )
2019 if ( strcmp( map[i].src,
"RX" ) == 0 )
2021 if ( strcmp( map[i].src,
"RY" ) == 0 )
2023 if ( strcmp( map[i].src,
"RZ" ) == 0 )
2025 if ( strcmp( map[i].src,
"COORD_OP_METHOD_CODE" ) == 0 )
2035 update +=
" WHERE ";
2043 update += QString(
"%1=%%2" ).arg( map[i].dst ).arg( i + 1 );
2045 insert += map[i].dst;
2046 values += QString(
"%%1" ).arg( i + 1 );
2049 insert =
"INSERT INTO tbl_datum_transform(" + insert +
") VALUES (" + values +
")";
2054 CSLDestroy( fieldnames );
2056 Q_ASSERT( idxid >= 0 );
2057 Q_ASSERT( idxrx >= 0 );
2058 Q_ASSERT( idxry >= 0 );
2059 Q_ASSERT( idxrz >= 0 );
2062 int openResult = sqlite3_open( dbPath.toUtf8().constData(), &db );
2063 if ( openResult != SQLITE_OK )
2069 if ( sqlite3_exec( db,
"BEGIN TRANSACTION", 0, 0, 0 ) != SQLITE_OK )
2072 sqlite3_close( db );
2078 v.reserve(
sizeof( map ) /
sizeof( *map ) );
2080 while ( !feof( fp ) )
2082 char **values = CSVReadParseLine( fp );
2086 if ( CSLCount( values ) < n )
2088 qWarning(
"Only %d columns", CSLCount( values ) );
2092 for (
unsigned int i = 0; i <
sizeof( map ) /
sizeof( *map ); i++ )
2094 int idx = map[i].idx;
2095 Q_ASSERT( idx != -1 );
2096 Q_ASSERT( idx < n );
2097 v.insert( i, *values[ idx ] ? quotedValue( values[idx] ) :
"NULL" );
2101 if ( v.at( idxmcode ).compare( QString(
"'9607'" ) ) == 0 )
2103 v[ idxmcode ] =
"'9606'";
2104 v[ idxrx ] =
"'" +
qgsDoubleToString( -( v[ idxrx ].
remove(
"'" ).toDouble() ) ) +
"'";
2105 v[ idxry ] =
"'" +
qgsDoubleToString( -( v[ idxry ].
remove(
"'" ).toDouble() ) ) +
"'";
2106 v[ idxrz ] =
"'" +
qgsDoubleToString( -( v[ idxrz ].
remove(
"'" ).toDouble() ) ) +
"'";
2112 QString sql = QString(
"SELECT coord_op_code FROM tbl_datum_transform WHERE coord_op_code=%1" ).arg( v[ idxid ] );
2113 int prepareRes = sqlite3_prepare( db, sql.toAscii(), sql.size(), &stmt, NULL );
2114 if ( prepareRes != SQLITE_OK )
2117 if ( sqlite3_step( stmt ) == SQLITE_ROW )
2119 cOpCode = (
const char * ) sqlite3_column_text( stmt, 0 );
2121 sqlite3_finalize( stmt );
2123 sql = cOpCode.isEmpty() ? insert : update;
2124 for (
int i = 0; i < v.size(); i++ )
2126 sql = sql.arg( v[i] );
2129 if ( sqlite3_exec( db, sql.toUtf8(), 0, 0, 0 ) != SQLITE_OK )
2131 qCritical(
"SQL: %s", sql.toUtf8().constData() );
2132 qCritical(
"Error: %s", sqlite3_errmsg( db ) );
2136 if ( sqlite3_exec( db,
"COMMIT", 0, 0, 0 ) != SQLITE_OK )
2142 sqlite3_close( db );
2154 return OSRGetAuthorityName( mCRS,
"GEOGCS" ) + QString(
":" ) + OSRGetAuthorityCode( mCRS,
"GEOGCS" );
2164 QStringList projections;
2168 projections = settings.value(
"/UI/recentProjections" ).toStringList();
2172 QStringList projectionsProj4 = settings.value(
"/UI/recentProjectionsProj4" ).toStringList();
2173 QStringList projectionsAuthId = settings.value(
"/UI/recentProjectionsAuthId" ).toStringList();
2174 if ( projectionsAuthId.size() >= projections.size() )
2178 projections.clear();
2179 for (
int i = 0; i < projectionsAuthId.size(); i++ )
2187 if ( i >= projectionsProj4.size() || !crs.
createFromProj4( projectionsProj4.at( i ) ) )
2193 if ( crs.
srsid() == 0 )
2198 projections << QString::number( crs.
srsid() );
QgsCoordinateReferenceSystem()
Default constructor.
bool createFromSrid(const long theSrid)
const QgsCoordinateReferenceSystem & crsByAuthId(const QString &authid)
Returns the CRS for authid, e.g.
void setValidationHint(QString html)
bool createFromWkt(const QString &theWkt)
QString geographicCRSAuthId() const
Returns auth id of related geographic CRS.
bool saveAsUserCRS(QString name)
Copied from QgsCustomProjectionDialog /// Please refactor into SQL handler !!! ///.
static void warning(const QString &msg)
Goes to qWarning.
bool createFromId(const long theId, CrsType theType=PostgisCrsId)
The QGis class provides global constants for use throughout the application.
bool axisInverted() const
static CUSTOM_CRS_VALIDATION customSrsValidation()
Gets custom function.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
bool createFromString(const QString &theDefinition)
static void logMessage(QString message, QString tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
static void setCustomSrsValidation(CUSTOM_CRS_VALIDATION f)
Sets custom function to force valid CRS QGIS uses implementation in QgisGui::customSrsValidation.
bool createFromOgcWmsCrs(QString theCrs)
Set up this CRS from the given OGC CRS.
bool createFromSrsId(const long theSrsId)
#define QgsDebugMsgLevel(str, level)
static QStringList recentProjections()
Returns a list of recently used projections.
bool createFromUserInput(const QString &theDefinition)
const long GEOCRS_ID
Magic number for a geographic coord sys in QGIS srs.db tbl_srs.srs_id.
QgsCoordinateReferenceSystem & operator=(const QgsCoordinateReferenceSystem &srs)
Assignment operator.
QString ellipsoidAcronym() const
~QgsCoordinateReferenceSystem()
QString qgsDoubleToString(const double &a, const int &precision=17)
const int USER_CRS_START_ID
Magick number that determines whether a projection crsid is a system (srs.db) or user (~/...
bool writeXML(QDomNode &theNode, QDomDocument &theDoc) const
QString projectionAcronym() const
Class for storing a coordinate reference system (CRS)
static const QString srsDbFilePath()
Returns the path to the srs.db file.
const int LAT_PREFIX_LEN
The length of the string "+lat_1=".
UnitType
Map units that qgis supports.
bool readXML(QDomNode &theNode)
QString description() const
bool operator!=(const QgsCoordinateReferenceSystem &theSrs) const
void(* CUSTOM_CRS_VALIDATION)(QgsCoordinateReferenceSystem &)
bool operator==(const QgsCoordinateReferenceSystem &theSrs) const
bool geographicFlag() const
static const QString qgisUserDbFilePath()
Returns the path to the user qgis.db file.
static QgsCRSCache * instance()
static void setupESRIWktFix()
const CORE_EXPORT QString GEO_EPSG_CRS_AUTHID
Geographic coord sys from EPSG authority.
bool createFromProj4(const QString &theProjString)
void * OGRSpatialReferenceH
QString toProj4() const
Get the Proj Proj4 string representation of this srs.
QGis::UnitType mapUnits() const