[Qgis-developer] python plugin - layer intersection ?
wonder.sk at gmail.com
Tue Jan 15 22:12:11 EST 2008
On Jan 15, 2008 9:32 AM, Michaël Douchin <michael.douchin at laposte.net> wrote:
> Hi list
> I am playing with the python bindings.... I would like to know if we can
> use python to develop a layer intersection plugin.
> For example, I have 2 shp layers :
> * mypoly = polygon layer (id_poly, name, area, valuea, valueb, etc.)
> * mypoint = point layer (id_point, name, value1, value2, etc.)
> Is it possible with python to test for each point if it intersects one
> of the polygons, and then give a point layer like this:
> myresult(id_result, id_point, id_poly, valuea, value2)
> In this case, I keep the id of each source layer, and choose to keep
> also one value of each layer. Each new point has the same geometry of
> the source point
QGIS has some support for testing for instersetion:
QgsGeometry::intersects(other) returns if the two geometries
So you can go through all features of the layers and test the
intersections and save them to another layer (use e.g.
One performance note - if your layers are big it would be wise to load
one of the layers to spatial index (QgsSpatialIndex) as using it can
reduce significantly the time needed to check the intersection.
More information about the Qgis-developer