[Qgis-developer] how to create a new geometry from an existing one with python

Ricardo Filipe Soares Garcia da ricardo.garcia.silva at gmail.com
Sun May 13 04:37:25 PDT 2012


Thanks
I got it working now!
I now have a different doubt, regarding geometry vertex iteration
(sending another e-mail with it).

On Sun, May 13, 2012 at 9:24 AM, Martin Dobias <wonder.sk at gmail.com> wrote:
> Hi Ricardo
>
> On Sun, May 13, 2012 at 1:39 AM, Ricardo Filipe Soares Garcia da
> <ricardo.garcia.silva at gmail.com> wrote:
>> [...]
>>
>> # python code
>>
>> line_geometry =
>> qgis.utils.iface.mapCanvas().currentLayer().selectedFeatures()[-1].geometry()
>>
>> # approach 1
>> new_geometry = QgsGeometry(line_geometry)
>
> This approach is correct (and other seems to be fine, too). The
> problem is elsewhere: you are being bitten by this bug:
> http://hub.qgis.org/issues/777
>
> Basically the problem is that the feature containing the line_geometry
> gets deleted when the first line is executed. So your line_geometry
> contains an invalid pointer leading to these strange errors. To
> overcome this, store the list of features and then access it without
> problems...
>
> Regards
> Martin



-- 
___________________________ ___ __
Ricardo Garcia Silva


More information about the Qgis-developer mailing list