mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Much faster centroid computation, and simplified code. Also adds Alexander Bruy as fTools contributor.
git-svn-id: http://svn.osgeo.org/qgis/trunk@13314 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
71a9f815a5
commit
21a8a9e4f3
@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# licensed under the terms of GNU GPL 2
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
@ -53,6 +54,11 @@ This program is free software; you can redistribute it and/or modify it under th
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
fTools DEVELOPERS:
|
||||
Carson J. Q. Farmer
|
||||
Alexander Bruy
|
||||
**If you have contributed code to fTools and I haven't mentioned your name here, please contact me and I will add your name.
|
||||
|
||||
ACKNOWLEDGEMENTS:
|
||||
The following individuals (whether they know it or not) have contributed ideas, help, testing, code, and guidence towards this project, and I thank them.
|
||||
Hawthorn Beyer
|
||||
|
@ -421,52 +421,22 @@ class geometryThread( QThread ):
|
||||
writer = QgsVectorFileWriter( self.myName, self.myEncoding,
|
||||
fields, QGis.WKBPoint, vprovider.crs() )
|
||||
inFeat = QgsFeature()
|
||||
outfeat = QgsFeature()
|
||||
outFeat = QgsFeature()
|
||||
nFeat = vprovider.featureCount()
|
||||
nElement = 0
|
||||
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
|
||||
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
|
||||
while vprovider.nextFeature( inFeat ):
|
||||
geom = inFeat.geometry()
|
||||
area = 0.00
|
||||
bounding = inFeat.geometry().boundingBox()
|
||||
xmin = bounding.xMinimum()
|
||||
ymin = bounding.yMinimum()
|
||||
if geom.type() == 2:
|
||||
cx = 0
|
||||
cy = 0
|
||||
factor = 0
|
||||
if geom.isMultipart():
|
||||
polygons = geom.asMultiPolygon()
|
||||
for polygon in polygons:
|
||||
for line in polygon:
|
||||
for i in range(0,len(line)-1):
|
||||
j = (i + 1) % len(line)
|
||||
factor=((line[i].x()-xmin)*(line[j].y()-ymin)-(line[j].x()-xmin)*(line[i].y()-ymin))
|
||||
cx+=((line[i].x()-xmin)+(line[j].x()-xmin))*factor
|
||||
cy+=((line[i].y()-ymin)+(line[j].y()-ymin))*factor
|
||||
area+=factor
|
||||
else:
|
||||
polygon = geom.asPolygon()
|
||||
for line in polygon:
|
||||
for i in range(0,len(line)-1):
|
||||
j = (i + 1) % len(line)
|
||||
factor=((line[i].x()-xmin)*(line[j].y()-ymin)-(line[j].x()-xmin)*(line[i].y()-ymin))
|
||||
cx+=((line[i].x()-xmin)+(line[j].x()-xmin))*factor
|
||||
cy+=((line[i].y()-ymin)+(line[j].y()-ymin))*factor
|
||||
area+=factor
|
||||
|
||||
if area==0:
|
||||
continue
|
||||
|
||||
cx/=area*3.00
|
||||
cy/=area*3.00
|
||||
outfeat.setGeometry( QgsGeometry.fromPoint( QgsPoint( cx+xmin, cy+ymin ) ) )
|
||||
atMap = inFeat.attributeMap()
|
||||
outfeat.setAttributeMap( atMap )
|
||||
writer.addFeature( outfeat )
|
||||
nElement += 1
|
||||
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
|
||||
inGeom = inFeat.geometry()
|
||||
atMap = inFeat.attributeMap()
|
||||
outGeom = QgsGeometry(inGeom.centroid())
|
||||
if outGeom is None:
|
||||
return "math_error"
|
||||
outFeat.setAttributeMap( atMap )
|
||||
outFeat.setGeometry( outGeom )
|
||||
writer.addFeature( outFeat )
|
||||
del writer
|
||||
return True
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user