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

2012-05-13 Thread Ricardo Filipe Soares Garcia da
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  wrote:
> Hi Ricardo
>
> On Sun, May 13, 2012 at 1:39 AM, Ricardo Filipe Soares Garcia da
>  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
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


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

2012-05-13 Thread Martin Dobias
Hi Ricardo

On Sun, May 13, 2012 at 1:39 AM, Ricardo Filipe Soares Garcia da
 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
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


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

2012-05-12 Thread Ricardo Filipe Soares Garcia da
Hi list

I'm trying to code some tools for working with lines layers using
python. One such tool is meant to create parallel lines.
I am trying to create my new line geometry by first copying the
geometry of a previously selected linestring and then translating it
according to a specified distance.
But I can't seem to find the correct way of copying the geometry.

I am on Ubuntu 11.10, using QGIS compiled from master #033d58d, built today.
For testing, I'm using layers created with the 'New Memory Layer'
plugin, which uses the memory provider.

I've tried the following approaches:

# python code

line_geometry =
qgis.utils.iface.mapCanvas().currentLayer().selectedFeatures()[-1].geometry()

# approach 1
new_geometry = QgsGeometry(line_geometry)

-> Exception: unknown

# approach 2
new_geometry = QgsGeometry.fromPolyline(line_geometry.asPolyline())

-> no error is thrown, but nothing happens

# approach 3

wkb = line_geometry.asWkb()
g.fromWkb(wkb, len(wkb))

-> RuntimeError: underlying C/C++ object has been deleted

Thanks for your input!

-- 
___ ___ __
Ricardo Garcia Silva
___
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer