[Qgis-developer] List of geometries corrupted when given as a function parameter.

Vincent Damoy vincent.damoy at espaces-naturels.fr
Wed Jan 15 06:10:37 PST 2014

Hi to all,

I'm working with QGIS 2.0.1 on a python plugin to help users enter data 
in a Postgis database.
Among others things, this plugin can convert selected features (from 
points to polygons, from lines to points, etc...)

_The plugin :_
operation_dialog.py is my main module.
convert_geometries module is used to convert features

In this second module, convert_geometries function accepts 2 parameters :
geomlist (a list of geometries),
geomoutput, (output data type : Qgis.point, Qgis.polygon ou Qgis.line).

extract :
/def convert_geometries(geomlist, geomtype):
      ret = None
      if len(set([geom.type() for geom in geomlist])) <> 1:
          print [geom.type() for geom in geomlist]
          ret = None
      else :
          if geomlist[0].type() == QGis.Line and geomtype == QGis.Polygon:
              ret = linestrings_polygon(geomlist)

If geometries in geomlist have different data types, then ret=None (and 
the plugin manage this error).
Else, if features are lines and polygons are needed, corresponding 
conversion function is started.

convert_geometries is started from my main module :

/geom2=convert_geometries([feature.geometry() for feature in 
self.iface.activeLayer().selectedFeatures()],geom_output) /

Here, geomlist is a list of geometries from features selected by user in 
the active layer).
geomtype=geom_output (selected by user in a combobox).

_The problem :_ Things go well if only one feature is selected. However, 
if 2 or more features of the same type are selected, (3 lines for 
example), geometries are systematically corrupted during passage from 
one module to the other, except the last one.

In the main module, this line :
« /print [feature.geometry() for feature in 
self.iface.activeLayer().selectedFeatures()]/ »
returns [1,1,1] (which means [line , line, line]).
However, in convert_geometries, « /print [geom.type() for geom in 
geomlist]/ » line returns [3,3,1]
(that is [unknowm geometry, unknowm geometry, line]).
If I try to display geometries in WKT format (/print [geom.exportToWkt() 
for geom in geomlist]/), QGIS closes without an error message.

_Question :_
Thus, if a list of several geometries is given in function parameter, 
they seems to be corrupted (except the last, or if there is only one 

Do you have an idea of what happens ? Where is my mistake? Do you see 
tests to perform in order to diagnose this issue ? (particularly, why 
the last geometry of a list is not corrupted, unlike others ?)

Thanks for advance

Vincent Damoy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20140115/180f92f6/attachment.html>

More information about the Qgis-developer mailing list