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

Vincent Damoy vincent.damoy at espaces-naturels.fr
Wed Jan 15 09:59:40 PST 2014


Hello Matthias,

Just one question :
How many meters high, the statue? :-)

I've stumbled on this problem for three weeks!
Indeed, this is the right code :

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

Adding QgsGeometry() makes the plugin work perfectly with one or many 
features selected.

Thanks a lot!!
Best regards.

Vincent


Le 15/01/2014 15:35, Matthias Kuhn a écrit :
> Hi Vincent,
>
> Is it possible that you are hit by the bug in this report [1]
>
> The workaround would by to keep a reference to the encapsulating
> feature as long as you need their geometries. (Or possibly to copy the
> geometry with g = QgsGeometry( feature.gemetry() ))
>
> Best
> Matthias
>
> [1] http://hub.qgis.org/issues/777
>
> On Mit 15 Jan 2014 15:10:37 CET, Vincent Damoy wrote:
>> 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
>> geometry)
>>
>> 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
>>
>>
>> _______________________________________________
>> Qgis-developer mailing list
>> Qgis-developer at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
>

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


More information about the Qgis-developer mailing list