[QGIS Commit] r13314 - in trunk/qgis/python/plugins/fTools: . tools
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Wed Apr 14 20:29:39 EDT 2010
Author: cfarmer
Date: 2010-04-14 20:29:39 -0400 (Wed, 14 Apr 2010)
New Revision: 13314
Modified:
trunk/qgis/python/plugins/fTools/doAbout.py
trunk/qgis/python/plugins/fTools/tools/doGeometry.py
Log:
Much faster centroid computation, and simplified code. Also adds Alexander Bruy as fTools contributor.
Modified: trunk/qgis/python/plugins/fTools/doAbout.py
===================================================================
--- trunk/qgis/python/plugins/fTools/doAbout.py 2010-04-15 00:27:11 UTC (rev 13313)
+++ trunk/qgis/python/plugins/fTools/doAbout.py 2010-04-15 00:29:39 UTC (rev 13314)
@@ -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 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
Modified: trunk/qgis/python/plugins/fTools/tools/doGeometry.py
===================================================================
--- trunk/qgis/python/plugins/fTools/tools/doGeometry.py 2010-04-15 00:27:11 UTC (rev 13313)
+++ trunk/qgis/python/plugins/fTools/tools/doGeometry.py 2010-04-15 00:29:39 UTC (rev 13314)
@@ -421,52 +421,22 @@
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
More information about the QGIS-commit
mailing list