bug722fix.diff

Patch for bug 722 - bug722fix.diff - Aaron Racicot -, 2007-11-17 09:58 PM

Download (4.02 KB)

View differences:

src/core/qgsspatialrefsys.cpp (working copy)
566 566
    {
567 567
      mySrsId=myRecord["srs_id"].toLong();
568 568
      QgsDebugMsg("QgsSpatialRefSys::createFromProj4 proj4string match search for srsid returned srsid: " \
569
+ QString::number(mySrsId));
569
		  + QString::number(mySrsId));
570 570
      if (mySrsId > 0)
571 571
      {
572 572
        createFromSrsId(mySrsId);
573 573
      }
574 574
    }
575

  
576 575
    else
577 576
    {
578
      QgsDebugMsg("QgsSpatialRefSys::createFromProj4 globbing search for srsid from this proj string");
579
      mySrsId = findMatchingProj();
580
      QgsDebugMsg("QgsSpatialRefSys::createFromProj4 globbing search for srsid returned srsid: "\
581
		  + QString::number(mySrsId));
582
      if (mySrsId > 0)
583
      {
584
        createFromSrsId(mySrsId);
585
      }
577
      // Ticket #722 - aaronr
578
      // Check if we can swap the lat_1 and lat_2 params (if they exist) to see if we match...
579
      // First we check for lat_1 and lat_2
580
      QRegExp myLat1RegExp( "\\+lat_1=\\S+" );
581
      QRegExp myLat2RegExp( "\\+lat_2=\\S+" );
582
      int myStart1 = 0;
583
      int myLength1 = 0;
584
      int myStart2 = 0;
585
      int myLength2 = 0;
586
      QString lat1Str = "";
587
      QString lat2Str = "";
588
      myStart1 = myLat1RegExp.search(theProj4String, myStart1);
589
      myStart2 = myLat2RegExp.search(theProj4String, myStart2);
590
      if ((myStart1 != -1) && (myStart2 != -1))
591
	{
592
	  myLength1 = myLat1RegExp.matchedLength();
593
	  myLength2 = myLat2RegExp.matchedLength();
594
	  lat1Str = theProj4String.mid(myStart1+LAT_PREFIX_LEN,myLength1-LAT_PREFIX_LEN);
595
	  lat2Str = theProj4String.mid(myStart2+LAT_PREFIX_LEN,myLength2-LAT_PREFIX_LEN);
596
	}
597
      // If we found the lat_1 and lat_2 we need to swap and check to see if we can find it...
598
      if ((lat1Str != "") && (lat2Str != ""))
599
	{
600
	  // Make our new string to check...
601
	  QString theProj4StringModified = theProj4String;
602
	  // First just swap in the lat_2 value for lat_1 value
603
	  theProj4StringModified.replace(myStart1+LAT_PREFIX_LEN,myLength1-LAT_PREFIX_LEN,lat2Str);
604
	  // Now we have to find the lat_2 location again since it has potentially moved...
605
	  myStart2 = 0;
606
	  myStart2 = myLat2RegExp.search(theProj4String, myStart2);
607
	  theProj4StringModified.replace(myStart2+LAT_PREFIX_LEN,myLength2-LAT_PREFIX_LEN,lat1Str);
608
	  QgsDebugMsg("QgsSpatialRefSys::createFromProj4 - trying proj4string match with swapped lat_1,lat_2");
609
	  myRecord = getRecord("select * from tbl_srs where parameters='" + theProj4StringModified.stripWhiteSpace () + "'");
610
	  if (!myRecord.empty())
611
	    {
612
	      // Success!  We have found the proj string by swapping the lat_1 and lat_2
613
	      mProj4String = theProj4StringModified;
614
	      mySrsId=myRecord["srs_id"].toLong();
615
	      QgsDebugMsg("QgsSpatialRefSys::createFromProj4 proj4string match search for srsid returned srsid: " \
616
			  + QString::number(mySrsId));
617
	      if (mySrsId > 0)
618
		{
619
		  createFromSrsId(mySrsId);
620
		}
621
	    }
622
	}
623
      else
624
	{
625
	  // Last ditch attempt to piece together what we know of the projection to find a match...
626
	  QgsDebugMsg("QgsSpatialRefSys::createFromProj4 globbing search for srsid from this proj string");
627
	  mySrsId = findMatchingProj();
628
	  QgsDebugMsg("QgsSpatialRefSys::createFromProj4 globbing search for srsid returned srsid: "\
629
		      + QString::number(mySrsId));
630
	  if (mySrsId > 0)
631
	    {
632
	      createFromSrsId(mySrsId);
633
	    }
634
	}
586 635
    }
587 636
  }
588 637

  
src/core/qgis.h (working copy)
126 126
  const int PROJ_PREFIX_LEN = 6;
127 127
  /** The length of teh string "+ellps=" */
128 128
  const int ELLPS_PREFIX_LEN = 7;
129
  /** The length of teh string "+lat_1=" */
130
  const int LAT_PREFIX_LEN = 7;
129 131
  /** Magick number that determins whether a projection srsid is a system (srs.db)
130 132
   *  or user (~/.qgis.qgis.db) defined projection. */
131 133
  const int USER_PROJECTION_START_ID=100000;