[QGIS Commit] r10339 - in branches/analysis_branch: python/core src/analysis/vector src/core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri Mar 20 15:27:56 EDT 2009


Author: cfarmer
Date: 2009-03-20 15:27:55 -0400 (Fri, 20 Mar 2009)
New Revision: 10339

Modified:
   branches/analysis_branch/python/core/qgsgeometry.sip
   branches/analysis_branch/src/analysis/vector/qgsgeometryanalyzer.cpp
   branches/analysis_branch/src/analysis/vector/qgsgeometryanalyzer.h
   branches/analysis_branch/src/core/qgsgeometry.cpp
   branches/analysis_branch/src/core/qgsgeometry.h
Log:
changes to geometryanalyzer (passes tests) and added simplify to qgsgeometry


Modified: branches/analysis_branch/python/core/qgsgeometry.sip
===================================================================
--- branches/analysis_branch/python/core/qgsgeometry.sip	2009-03-20 18:55:30 UTC (rev 10338)
+++ branches/analysis_branch/python/core/qgsgeometry.sip	2009-03-20 19:27:55 UTC (rev 10339)
@@ -224,6 +224,9 @@
         of segments used to approximate curves */
     QgsGeometry* buffer(double distance, int segments) /Factory/;
 
+    /** Returns a simplified version of this geometry using a specified tolerance value */
+    QgsGeometry* simplify(double tolerance) /Factory/;
+
     /** Returns the smallest convex polygon that contains all the points in the geometry. */
     QgsGeometry* convexHull() /Factory/;
     

Modified: branches/analysis_branch/src/analysis/vector/qgsgeometryanalyzer.cpp
===================================================================
--- branches/analysis_branch/src/analysis/vector/qgsgeometryanalyzer.cpp	2009-03-20 18:55:30 UTC (rev 10338)
+++ branches/analysis_branch/src/analysis/vector/qgsgeometryanalyzer.cpp	2009-03-20 19:27:55 UTC (rev 10339)
@@ -21,7 +21,6 @@
 #include "qgsapplication.h"
 #include "qgsfield.h"
 #include "qgsfeature.h"
-#include "qgsgeometry.h"
 #include "qgslogger.h"
 #include "qgscoordinatereferencesystem.h"
 #include "qgsvectorfilewriter.h"
@@ -405,7 +404,7 @@
   
 }
 
-bool QgsGeometryAnalyzer::simpleMeasure( QgsGeometry& geometry )
+QList<double> QgsGeometryAnalyzer::simpleMeasure( QgsGeometry& geometry )
 {
   /*
     if inGeom.wkbType() == QGis.WKBPoint:
@@ -424,7 +423,7 @@
 
  */ 
 }
-bool QgsGeometryAnalyzer::perimeterMeasure( QgsGeometry& geometry )
+double QgsGeometryAnalyzer::perimeterMeasure( QgsGeometry& geometry )
 {
   /*
     value = 0.00
@@ -442,7 +441,7 @@
   
 }
 
-bool QgsGeometryAnalyzer::checkGeometryFields( QgsGeometry& geometry )
+QgsFieldMap QgsGeometryAnalyzer::checkGeometryFields( QgsGeometry& geometry, int index1, int index2 )
 {
   /*
     vprovider = vlayer.dataProvider()
@@ -486,10 +485,9 @@
         fieldList[index2] = field
     return (fieldList, index1, index2)
 */
-
   
 }
-bool QgsGeometryAnalyzer::extractAsLine( QgsGeometry& geometry )
+QgsPolyline QgsGeometryAnalyzer::extractAsLine( QgsGeometry& geometry )
 {
   /*
     multi_geom = QgsGeometry()
@@ -509,7 +507,7 @@
   */
 
 }
-bool QgsGeometryAnalyzer::extractAsSingle( QgsGeometry& geometry )
+QgsGeometry QgsGeometryAnalyzer::extractAsSingle( QgsGeometry& geometry )
 {
 /*
     multi_geom = QgsGeometry()
@@ -540,7 +538,8 @@
 */
   
 }
-bool QgsGeometryAnalyzer::extractAsMulti( QgsGeometry& geometry )
+
+QgsGeometry QgsGeometryAnalyzer::extractAsMulti( QgsGeometry& geometry )
 {
 /*
   if ( geometry->mGeos == NULL )
@@ -592,7 +591,8 @@
 */
   
 }
-bool QgsGeometryAnalyzer::convertGeometry( QgsGeometry& geometry )
+
+QgsGeometry QgsGeometryAnalyzer::convertGeometry( QgsGeometry& geometry )
 {
   /*
     if vType == 0:
@@ -604,7 +604,7 @@
   */
 }
 
-bool QgsGeometryAnalyzer::extractPoints( QgsGeometry& geometry )
+QList<QPoint> QgsGeometryAnalyzer::extractPoints( QgsGeometry& geometry )
 {
 /*
 	QList multi_geom;

Modified: branches/analysis_branch/src/analysis/vector/qgsgeometryanalyzer.h
===================================================================
--- branches/analysis_branch/src/analysis/vector/qgsgeometryanalyzer.h	2009-03-20 18:55:30 UTC (rev 10338)
+++ branches/analysis_branch/src/analysis/vector/qgsgeometryanalyzer.h	2009-03-20 19:27:55 UTC (rev 10339)
@@ -21,6 +21,9 @@
 
 #include "qgsvectorlayer.h"
 #include "qgsfield.h"
+#include "qgsfeature.h"
+#include "qgsgeometry.h"
+#include "qgsfield.h"
 
 
 /** \ingroup analysis
@@ -65,7 +68,7 @@
     bool polygonsToLines( QgsVectorLayer* layer,
         const QString& shapefileName,
         const QString& fileEncoding );
-
+        
     /**
      * Add vector layer geometry info to point (XCOORD, YCOORD), line (LENGTH),
      * or polygon (AREA, PERIMETER) layer.
@@ -98,16 +101,17 @@
     bool layerExtent( QgsVectorLayer* layer,
         const QString& shapefileName,
         const QString& fileEncoding );
-
+                             
   private:
-    bool simpleMeasure( QgsGeometry& geometry );
-    bool perimeterMeasure( QgsGeometry& geometry );
-    bool checkGeometryFields( QgsGeometry& geometry );
-    bool extractAsLine( QgsGeometry& geometry );
-    bool extractAsSingle( QgsGeometry& geometry );
-    bool extractAsMulti( QgsGeometry& geometry );
-    bool convertGeometry( QgsGeometry& geometry );
-    bool extractPoints( QgsGeometry& geometry );
 
+    QList<double> simpleMeasure( QgsGeometry& geometry );
+    double perimeterMeasure( QgsGeometry& geometry );
+    QgsFieldMap checkGeometryFields( QgsGeometry& geometry, int index1, int index2 );
+    QgsPolyline extractAsLine( QgsGeometry& geometry );
+    QgsGeometry extractAsSingle( QgsGeometry& geometry );
+    QgsGeometry extractAsMulti( QgsGeometry& geometry );
+    QgsGeometry convertGeometry( QgsGeometry& geometry );
+    QList<QPoint> extractPoints( QgsGeometry& geometry );
+
 };
 #endif //QGSVECTORANALYZER

Modified: branches/analysis_branch/src/core/qgsgeometry.cpp
===================================================================
--- branches/analysis_branch/src/core/qgsgeometry.cpp	2009-03-20 18:55:30 UTC (rev 10338)
+++ branches/analysis_branch/src/core/qgsgeometry.cpp	2009-03-20 19:27:55 UTC (rev 10339)
@@ -134,6 +134,7 @@
 #define GEOSIntersection(g0,g1) GEOSIntersection( (GEOSGeometry*) g0, (GEOSGeometry*)g1 )
 #define GEOSBuffer(g, d, s) GEOSBuffer( (GEOSGeometry*) g, d, s)
 #define GEOSArea(g, a) GEOSArea( (GEOSGeometry*) g, a)
+#define GEOSSimplify(g, t) GEOSSimplify( (GEOSGeometry*) g, t)
 
 #define GEOSCoordSeq_getSize(cs,n) GEOSCoordSeq_getSize( (GEOSCoordSequence *) cs, n )
 #define GEOSCoordSeq_getX(cs,i,x) GEOSCoordSeq_getX( (GEOSCoordSequence *)cs, i, x )
@@ -5328,6 +5329,23 @@
   CATCH_GEOS( 0 )
 }
 
+QgsGeometry* QgsGeometry::simplify( double tolerance )
+{
+  if ( mGeos == NULL )
+  {
+    exportWkbToGeos();
+  }
+  if ( !mGeos )
+  {
+    return 0;
+  }
+  try
+  {
+    return fromGeosGeom( GEOSSimplify( mGeos, tolerance ) );
+  }
+  CATCH_GEOS( 0 )
+}
+
 QgsGeometry* QgsGeometry::convexHull()
 {
   if ( mGeos == NULL )
@@ -5450,7 +5468,6 @@
   CATCH_GEOS( 0 )
 }
 
-
 QList<QgsGeometry*> QgsGeometry::asGeometryCollection()
 {
   if ( mGeos == NULL )

Modified: branches/analysis_branch/src/core/qgsgeometry.h
===================================================================
--- branches/analysis_branch/src/core/qgsgeometry.h	2009-03-20 18:55:30 UTC (rev 10338)
+++ branches/analysis_branch/src/core/qgsgeometry.h	2009-03-20 19:27:55 UTC (rev 10339)
@@ -269,6 +269,9 @@
     /** Returns a buffer region around this geometry having the given width and with a specified number
         of segments used to approximate curves */
     QgsGeometry* buffer( double distance, int segments );
+    
+    /** Returns a simplified version of this geometry using a specified tolerance value */
+    QgsGeometry* simplify( double tolerance );
 
     /** Returns the smallest convex polygon that contains all the points in the geometry. */
     QgsGeometry* convexHull();



More information about the QGIS-commit mailing list