[Qgis-user] QgsGeometry - how to detect nr of rings and vertices

Andreas Neumann a.neumann at carto.net
Tue Nov 11 03:02:21 PST 2008


thank you - this definitely helps. As the goal is to step through all
polygons, rings, vertices - your code is perfect as a starter for me.

I am still pretty new with QGIS and python - having some sample code
always helps.

Thanks a lot,
Andreas


> The fTools function extract nodes does something like this (only it's
> not especially efficient...)
>
> What about something like:
>
> ring_count = 0
> vertices_count = 0
> geom = QgsGeometry() # doesn't matter how you get this ;-)
> # figure out the geometry type() here
> if geom.type() == QGis.Polygon:
>     if geom.isMultipart():
>         polygons = geom.fromMultiPolygon()
>     else:
>         polygons = [ geom.fromPolygon() ]
>     for polygon in polygons:
>         for line in polygon: # these are your rings
>             print ring_count
>             for vertices in line: # these are your vertices
>                 print vertices_count
>
> Obviously you wouldn't really loop through all of the vertices and rings
> this way, but you can use this concept to figure out how many of each
> there are:
>
> ...
> num_rings = len( polygon )
> num_vetices = len( line )
>
> I don't know if this is what you were looking for, but hopefully it helps,
>
>
> Carson
>
> --
> Carson J. Q. Farmer
> ISSP Doctoral Fellow
> National Centre for Geocomputation (NCG),
> John Hume Building,
> National University of Ireland, Maynooth,
> Co. Kildare,
> Ireland.
> Phone: +353 (0) 1 708 6726
> Fax:   +353 (0) 1 708 6456
> Email: Carson.Farmer at gmail.com
> Web:   http://www.carsonfarmer.com/
>        http://www.ftools.ca/
>
>


-- 
Andreas Neumann
Böschacherstrasse 6, CH-8624 Grüt/Gossau, Switzerland
Email: a.neumann at carto.net, Web:
* http://www.carto.net/ (Carto and SVG resources)
* http://www.carto.net/neumann/ (personal page)
* http://www.svgopen.org/ (SVG Open Conference)
* http://www.geofoto.ch/ (Georeferenced Photos of Switzerland)




More information about the Qgis-user mailing list