Bug report #1462

PostGIS layer loaded via Python is not saved correct in qgs project file

Added by Horst Düster almost 12 years ago. Updated about 11 years ago.

Status:Closed
Priority:Low
Assignee:Jürgen Fischer
Category:Project Loading/Saving
Affected QGIS version: Regression?:No
Operating System:All Easy fix?:No
Pull Request or Patch supplied: Resolution:fixed
Crashes QGIS or corrupts data: Copied to github as #:11522

Description

I load a PostGIS layer via Python with:

...
uri = [[QgsDataSourceURI]]()
uri.setConnection(self.DBHOST, self.DBPORT, self.DBNAME, self.DBUSER, self.DBPASSWD)
uri.setDataSource(str(schema), str(table), "wkb_geometry", "archive=0")
vlayer = [[QgsVectorLayer]](uri.uri(), layerName, "postgres")
[[QgsMapLayerRegistry]].instance().addMapLayer(vlayer)    
...

The layer is added to mapcanvas and it is displayed correct. Save the project to testpython.qgs and reload this project-file QGIS reports: Unable to load layer.

Load the same layer with the postgis connector. Save the project to testconnector.qgs and reload this project-file everthing works fine.

I compare the two project files and I see a relevant difference, the following tags are missing in testpython.qgs:

            <edittypes>
                <edittype type="0" name="archive" />
                <edittype type="0" name="archive_date" />
                <edittype type="0" name="gem_bfs" />
                <edittype type="0" name="new_date" />
                <edittype type="0" name="nummer" />
                <edittype type="0" name="ogc_fid" />
            </edittypes>
            <displayfield>ogc_fid</displayfield>
            <label>0</label>
            <attributeactions/>
            <singlesymbol>
                <symbol>
                    <lowervalue></lowervalue>
                    <uppervalue></uppervalue>
                    <label></label>
                    <pointsymbol>hard:circle</pointsymbol>
                    <pointsize>2</pointsize>
                    <rotationclassificationfieldname></rotationclassificationfieldname>
                    <scaleclassificationfieldname></scaleclassificationfieldname>
                    <outlinecolor red="0" blue="0" green="0" />
                    <outlinestyle>SolidLine</outlinestyle>
                    <outlinewidth>0.26</outlinewidth>
                    <fillcolor red="153" blue="60" green="213" />
                    <fillpattern>SolidPattern</fillpattern>
                    <texturepath></texturepath>
                </symbol>
            </singlesymbol>
            <labelattributes>
                <label fieldname="" text="Label" />
                <family fieldname="" name="Sans Serif" />
                <size fieldname="" units="pt" value="12" />
                <bold fieldname="" on="0" />
                <italic fieldname="" on="0" />
                <underline fieldname="" on="0" />
                <color fieldname="" red="0" blue="0" green="0" />
                <x fieldname="" />
                <y fieldname="" />
                <offset x="0" y="0" units="pt" yfieldname="" xfieldname="" />
                <angle fieldname="" value="0" auto="0" />
                <alignment fieldname="" value="center" />
                <buffercolor fieldname="" red="255" blue="255" green="255" />
                <buffersize fieldname="" units="pt" value="1" />
                <bufferenabled fieldname="" on="" />
                <multilineenabled fieldname="" on="" />
            </labelattributes>

Associated revisions

Revision 8c5fb28e
Added by Jürgen Fischer almost 12 years ago

fix #1462

git-svn-id: http://svn.osgeo.org/qgis/trunk/[email protected] c8812cc2-4d05-0410-92ff-de0c093fc19c

Revision bac663a4
Added by Jürgen Fischer almost 12 years ago

fix #1462

git-svn-id: http://svn.osgeo.org/qgis/[email protected] c8812cc2-4d05-0410-92ff-de0c093fc19c

History

#1 Updated by Jürgen Fischer almost 12 years ago

I tried to run your code in the python console. When try to save I get

[[NotImplementedError]]: [[QgsVectorLayer]].writeSymbology() is abstract and must be overridden

I still need to investigate why there's python code fired at all at that point, but if I replace

vlayer = [[QgsVectorLayer]](uri.uri(), layerName, "postgres")
[[QgsMapLayerRegistry]].instance().addMapLayer(vlayer)  

with

iface.addVectorLayer(uri.uri(), layerName, "postgres")

everything is fine again.

#2 Updated by Horst Düster almost 12 years ago

Replying to [comment:1 jef]:

I tried to run your code in the python console. When try to save I get

> [[NotImplementedError]]: [[QgsVectorLayer]].writeSymbology() is abstract and must be overridden

I still need to investigate why there's python code fired at all at that point, but if I replace

> vlayer = [[QgsVectorLayer]](uri.uri(), layerName, "postgres")
> [[QgsMapLayerRegistry]].instance().addMapLayer(vlayer)  

with

> iface.addVectorLayer(uri.uri(), layerName, "postgres")

everything is fine again.

<pre>
self.iface.addVectorLayer(uri.uri(), layerName, "postgres")
vLayer = self.iface.mapCanvas().currentLayer()
vLayer.loadNamedStyle(Path to qml-file)
</pre>

in this case the symbolisation in mapcanvas is updated, but the legend symbolisation is not changed.

#3 Updated by Horst Düster almost 12 years ago

Replying to [comment:2 hdus]:

Replying to [comment:1 jef]:

I tried to run your code in the python console. When try to save I get

> > [[NotImplementedError]]: [[QgsVectorLayer]].writeSymbology() is abstract and must be overridden

I still need to investigate why there's python code fired at all at that point, but if I replace

> > vlayer = [[QgsVectorLayer]](uri.uri(), layerName, "postgres")
> > [[QgsMapLayerRegistry]].instance().addMapLayer(vlayer)  

with

> > iface.addVectorLayer(uri.uri(), layerName, "postgres")

everything is fine again.

> 
<pre>
> self.iface.addVectorLayer(uri.uri(), layerName, "postgres")
> vLayer = self.iface.mapCanvas().currentLayer()
> vLayer.loadNamedStyle(Path to qml-file)
</pre>
> 
> in this case the symbolisation in mapcanvas is updated, but the legend symbolisation is not changed.

<pre>

#4 Updated by Jürgen Fischer almost 12 years ago

  • Resolution set to fixed
  • Status changed from Open to Closed

fixed in

#5 Updated by Anonymous about 11 years ago

Milestone Version 1.0.0 deleted

Also available in: Atom PDF