[Qgis-developer] intersect error

Martin Dobias wonder.sk at gmail.com
Mon Jan 26 17:05:35 EST 2009

On Sun, Jan 25, 2009 at 5:37 PM, Carson Farmer <carson.farmer at gmail.com> wrote:
> Howdy list...
> 1. implement support for geometry collections: probably a partial
> implementation allowing to retrieve parts of geometry collection from
> GEOS would suffice for the begin.
> If I did implement this (as a partial implementation) would you recommend
> simply returning the geometry  collection as a list of geometries, or
> retrieving parts of the collection based on some input parameter (i.e.
> retrieve polygons only). From an initial glance at the GOES api, this first
> implementation looks possible, but I'm not a strong c++ programmer, so I'll
> likely have to run it by others once I'm done...
> The approach with returning a list of geometry parts looks like a more
> flexible approach to me.
> Ok, so I really don't know what I'm doing here, maybe someone can tell me
> why I can't quite get this to return a filled list:
> QList<QgsGeometry*> QgsGeometry::asGeometryCollection()
> {
> [...]

Hi Carson,

I've took your code, modified it slightly and commited in r10026 :-)

Not sure what was the reason of your problems (I've modified it to my
preferences before trying it out). One thing worth mentioning -
casting from const to non-const isn't a good idea as the const
modifier usually has some reason, e.g. when constructing a geometry
with QgsGeometry::fromGeos() you should pass a new instance. Passing
an existing instance will probably cause havoc when deleting the
geometries (because both original geometry collection and its part
will try to delete the same geos geometry).

Looks like it's working now:

>>> g1 = QgsGeometry.fromPolygon( [ [ QgsPoint(0,0),QgsPoint(0,1),QgsPoint(1,1),QgsPoint(1,0) ] ] )
>>> g2 = QgsGeometry.fromPolygon( [ [ QgsPoint(0,0),QgsPoint(2,0),QgsPoint(2,1),QgsPoint(1,1),QgsPoint(1,0.5),QgsPoint(0,0.5) ] ] )
>>> gg = g1.intersection(g2)
>>> gg.asGeometryCollection()
[<qgis.core.QgsGeometry object at 0x8af0b2c>, <qgis.core.QgsGeometry
object at 0x8b1afac>]
>>> GG1 = gg.asGeometryCollection()[0]
>>> GG2 = gg.asGeometryCollection()[1]
>>> GG1.wkbType()
>>> GG1.asPolyline()
[(1,1), (1,0.5)]
>>> GG2.asPolygon()
[[(0,0), (0,0.5), (1,0.5), (1,0), (0,0)]]


More information about the Qgis-developer mailing list