[Qgis-user] QgsGeometry - how to detect nr of rings and vertices
Carson Farmer
carson.farmer at gmail.com
Tue Nov 11 02:47:29 PST 2008
Hi Andreas,
> I am using QgsGeometry from python. I would like to find out the nr of
> rings and vertices per ring but could not find a function for this purpose
> in http://doc.qgis.org/classQgsGeometry.html
>
I don't think there is one...
> Is there something hidden/undocumented to find out this information?
>
> The idea is to step through all rings and vertices of a QgsGeometry object
> and process the coordinates.
>
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/
More information about the Qgis-user
mailing list