From a standalone python script (i.e. not running within QGIS) I am manipulating QGIS a project file (*.qgs
) to have its layers point to different geometry data.
That geometry data can be in different spatial reference systems (SRS), so I'd like to also adapt the <maplayer>
's <srs>
child element, so that QGIS will know it and display it correctly in the layer properties dialog.
Unfortunately, (like many other things in the QGIS project files) this element seems to be unnecessarily redundant and QGIS seems to actually depend on redundant information for the display. The entry might look like this:
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
<qgis projectname="" version="2.18.10">
<!-- ... -->
<projectlayers>
<maplayer <!-- ... --> >
<!-- ... -->
<srs>
<spatialrefsys>
<proj4>+proj=longlat +ellps=intl +towgs84=72.438,345.918,79.486,1.6045,0.8823,0.5565,1.3746 +no_defs</proj4>
<srsid>3482</srsid>
<srid>4629</srid>
<authid>EPSG:4629</authid>
<description>Tahaa 54</description>
<projectionacronym>longlat</projectionacronym>
<ellipsoidacronym>intl</ellipsoidacronym>
<geographicflag>true</geographicflag>
</spatialrefsys>
</srs>
<!-- ... -->
</maplayer>
</projectlayers>
<!-- ... -->
</qgis>
Having just the PostGIS/EPSG SRID, how do I get the rest of the information needed to create such an entry consistently? The SRS can differ but is known (by its SRID) at runtime.
I tried giving only the PostGIS/EPSG SRID by shortening the entry to
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
<qgis projectname="" version="2.18.10">
<!-- ... -->
<projectlayers>
<maplayer <!-- ... --> >
<!-- ... -->
<srs>
<spatialrefsys>
<srid>4629</srid>
</spatialrefsys>
</srs>
<!-- ... -->
</maplayer>
</projectlayers>
<!-- ... -->
</qgis>
but then QGIS will not display it correctly in the layer properties:
expected:
(Also, while the data is being displayed, I'm not sure whether it would be projected correctly with that partial information.)
Where does QGIS take this information from when creating a new layer?