[Qgis-developer] script to update the srs.db

Marco Hugentobler marco.hugentobler at karto.baug.ethz.ch
Mon Jun 23 03:44:53 EDT 2008

Hi Maciej,

Since no one else replied, I give it a try. Keep in mind crs is not my special 
area of competence, so others please feel free to correct me where I'm wrong.

> <SpatialRefSys>
>   <ProjectSRSProj4String type="QString" >+proj=tmerc +lat_0=0 (snip...)
>   <ProjectSRSID type="int" >181</ProjectSRSID>
> </SpatialRefSys>
> Which tag does QGIS depend on to recognize the project's SRS? Does it
> consider the <srsid> or <ProjectSRSID type="int" > at all?>

From what I have seen in the code, if a srs is read from XML file, import is 
done from proj4 string using OGR.

qgsspatialrefsys.cpp: 665

void QgsSpatialRefSys::setProj4String (QString theProj4String)
  const char *oldlocale = setlocale(LC_ALL, NULL);
  setlocale(LC_ALL, "C");
  mIsValidFlag = OSRImportFromProj4(mSRS, theProj4String.toLatin1
().constData() )==OGRERR_NONE;
  setlocale(LC_ALL, oldlocale);

and for transformation, the proj4 string is exported from OGR and passed to 
proj4 library.

It seems to me that the QGIS srsid is only used to create a default srs if the 
<spatialrefsys> tag is not present:

qgsspatialrefsys.cpp: 908

QDomNode srsNode  = theNode.namedItem( "spatialrefsys" );

if ( ! srsNode.isNull() )
    // Return default SRS if none was found in the XML.

where GEOSRS_ID is:

qgis.h:123:  const long GEOSRS_ID = 2585;

I wonder if we just could replace that with epsg number 4326 and then use

const long DEFAULT_EPGS = 4326;



That way, it would be possible to change the qgis srs ids without affecting 
project file support.


Am Mittwoch 11 Juni 2008 22:55:36 schrieb Maciej Sieczka:
> Tim Sutton pisze:
> > Hi Richard
> >
> > One thing I would like to do if you assemble small test datasets is
> > to create some unit tests for srs stuff. One basic form of test I am
> > thinking is to simply have a directory with a bunch of shapefiles
> > with a single feature each, each shp being in a different srs. The
> > test would load each one in turn and verify that it gets the correct
> >  epsg etc for it. So if you so start getting little test files in,
> > bear this in mind so that we can use them for more formal unit
> > testing too.
> >
> > Secondly if I recall correctly, the reason we originally opted to use
> >  our own srs identifier was that the srs db did inclide some srs
> > definitions that did not have an epsg code yet.
> Please anybody who knows details speak up!
> > It would be good if we could maintain the original srs id pkeys in
> > any updates you do
> This could be done with some extra work, but I don't think
> QGIS should depend on it's own SRS numbering scheme, when EPSG provides
> an universal, stable scheme for that. That's what EPSG database is good
> at and let's make use of it if possible.
> > since changing them may introduce regressions for people loading .qgs
> >  project files.
> In a .qgs the layer's and on the <mapcanvas> SRS part looks like this:
> <spatialrefsys>
>   <proj4>+proj=tmerc +lat_0=0 +lon_0=19 +k=0 +x_0=500000 (snip...)
>   <srsid>181</srsid>
>   <srid>2180</srid>
>   <epsg>2180</epsg>
>   <description>ETRS89 / Poland CS92</description>
>   <projectionacronym>tmerc</projectionacronym>
>   <ellipsoidacronym>GRS80</ellipsoidacronym>
>   <geographicflag>false</geographicflag>
> </spatialrefsys>
> The <properties> SRS (how does differ from the <mapcanvas> one???) is eg.:
> <SpatialRefSys>
>   <ProjectSRSProj4String type="QString" >+proj=tmerc +lat_0=0 (snip...)
>   <ProjectSRSID type="int" >181</ProjectSRSID>
> </SpatialRefSys>
> Which tag does QGIS depend on to recognize the project's SRS? Does it
> consider the <srsid> or <ProjectSRSID type="int" > at all?
> Cheers,
> Maciek

Dr. Marco Hugentobler
Institute of Cartography
ETH Zurich
Technical Advisor QGIS Project Steering Committee

More information about the Qgis-developer mailing list