Skip to content

Commit

Permalink
improve point generation algorithm for multipart polygons
Browse files Browse the repository at this point in the history
when the horizontal line through the weightpoint doesn't intersect
any part (error reported by ozak)
  • Loading branch information
zsiki committed May 24, 2014
1 parent 8b1bb97 commit 06fbdd1
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions realcentroid.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ def centroids(self):
while fit.nextFeature(inFeat):
#nElement += 1
inGeom = inFeat.geometry()
if inGeom.isMultipart:
# find largest part in case of multipart
maxarea = 0
tmpGeom = QgsGeometry()
for part in inGeom.asGeometryCollection():
area = part.area()
if area > maxarea:
tmpGeom = part
maxare = area
inGeom = tmpGeom
atMap = inFeat.attributes()
outGeom = inGeom.centroid()
if not inGeom.contains(outGeom):
Expand Down

0 comments on commit 06fbdd1

Please sign in to comment.