Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Applied Aaron Racicots patch for ticket #722
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7461 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Nov 19, 2007
1 parent d62334d commit d030d36
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/core/qgis.h
Expand Up @@ -126,6 +126,8 @@ class CORE_EXPORT QGis
const int PROJ_PREFIX_LEN = 6;
/** The length of teh string "+ellps=" */
const int ELLPS_PREFIX_LEN = 7;
/** The length of teh string "+lat_1=" */
const int LAT_PREFIX_LEN = 7;
/** Magick number that determins whether a projection srsid is a system (srs.db)
* or user (~/.qgis.qgis.db) defined projection. */
const int USER_PROJECTION_START_ID=100000;
Expand Down
69 changes: 59 additions & 10 deletions src/core/qgsspatialrefsys.cpp
Expand Up @@ -566,23 +566,72 @@ bool QgsSpatialRefSys::createFromProj4 (const QString theProj4String)
{
mySrsId=myRecord["srs_id"].toLong();
QgsDebugMsg("QgsSpatialRefSys::createFromProj4 proj4string match search for srsid returned srsid: " \
+ QString::number(mySrsId));
+ QString::number(mySrsId));
if (mySrsId > 0)
{
createFromSrsId(mySrsId);
}
}

else
{
QgsDebugMsg("QgsSpatialRefSys::createFromProj4 globbing search for srsid from this proj string");
mySrsId = findMatchingProj();
QgsDebugMsg("QgsSpatialRefSys::createFromProj4 globbing search for srsid returned srsid: "\
+ QString::number(mySrsId));
if (mySrsId > 0)
{
createFromSrsId(mySrsId);
}
// Ticket #722 - aaronr
// Check if we can swap the lat_1 and lat_2 params (if they exist) to see if we match...
// First we check for lat_1 and lat_2
QRegExp myLat1RegExp( "\\+lat_1=\\S+" );
QRegExp myLat2RegExp( "\\+lat_2=\\S+" );
int myStart1 = 0;
int myLength1 = 0;
int myStart2 = 0;
int myLength2 = 0;
QString lat1Str = "";
QString lat2Str = "";
myStart1 = myLat1RegExp.search(theProj4String, myStart1);
myStart2 = myLat2RegExp.search(theProj4String, myStart2);
if ((myStart1 != -1) && (myStart2 != -1))
{
myLength1 = myLat1RegExp.matchedLength();
myLength2 = myLat2RegExp.matchedLength();
lat1Str = theProj4String.mid(myStart1+LAT_PREFIX_LEN,myLength1-LAT_PREFIX_LEN);
lat2Str = theProj4String.mid(myStart2+LAT_PREFIX_LEN,myLength2-LAT_PREFIX_LEN);
}
// If we found the lat_1 and lat_2 we need to swap and check to see if we can find it...
if ((lat1Str != "") && (lat2Str != ""))
{
// Make our new string to check...
QString theProj4StringModified = theProj4String;
// First just swap in the lat_2 value for lat_1 value
theProj4StringModified.replace(myStart1+LAT_PREFIX_LEN,myLength1-LAT_PREFIX_LEN,lat2Str);
// Now we have to find the lat_2 location again since it has potentially moved...
myStart2 = 0;
myStart2 = myLat2RegExp.search(theProj4String, myStart2);
theProj4StringModified.replace(myStart2+LAT_PREFIX_LEN,myLength2-LAT_PREFIX_LEN,lat1Str);
QgsDebugMsg("QgsSpatialRefSys::createFromProj4 - trying proj4string match with swapped lat_1,lat_2");
myRecord = getRecord("select * from tbl_srs where parameters='" + theProj4StringModified.stripWhiteSpace () + "'");
if (!myRecord.empty())
{
// Success! We have found the proj string by swapping the lat_1 and lat_2
mProj4String = theProj4StringModified;
mySrsId=myRecord["srs_id"].toLong();
QgsDebugMsg("QgsSpatialRefSys::createFromProj4 proj4string match search for srsid returned srsid: " \
+ QString::number(mySrsId));
if (mySrsId > 0)
{
createFromSrsId(mySrsId);
}
}
}
else
{
// Last ditch attempt to piece together what we know of the projection to find a match...
QgsDebugMsg("QgsSpatialRefSys::createFromProj4 globbing search for srsid from this proj string");
mySrsId = findMatchingProj();
QgsDebugMsg("QgsSpatialRefSys::createFromProj4 globbing search for srsid returned srsid: "\
+ QString::number(mySrsId));
if (mySrsId > 0)
{
createFromSrsId(mySrsId);
}
}
}
}

Expand Down

0 comments on commit d030d36

Please sign in to comment.