Skip to content

Commit

Permalink
adds both simplify and centroid to qgsgeometry -> these will be used …
Browse files Browse the repository at this point in the history
…by the qgsanalysis branch

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10392 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
cfarmer committed Mar 21, 2009
1 parent 7808ef5 commit af34446
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 9 deletions.
8 changes: 8 additions & 0 deletions python/core/qgsgeometry.sip
Expand Up @@ -224,6 +224,14 @@ not disjoint with existing polygons of the feature*/
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 center of mass of a geometry
* @note for line based geometries, the center point of the line is returned,
* and for point based geometries, the point itself is returned */
QgsGeometry* centroid() /Factory/;

/** Returns the smallest convex polygon that contains all the points in the geometry. */
QgsGeometry* convexHull() /Factory/;

Expand Down
41 changes: 38 additions & 3 deletions src/core/qgsgeometry.cpp
Expand Up @@ -132,8 +132,10 @@ static GEOSInit geosinit;
#define GEOSGetInteriorRingN(g,i) GEOSGetInteriorRingN( (GEOSGeometry *)g, i )
#define GEOSDisjoint(g0,g1) GEOSDisjoint( (GEOSGeometry *)g0, (GEOSGeometry*)g1 )
#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 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 GEOSGetCentroid(g) GEOSGetCentroid( (GEOSGeometry*) g )

#define GEOSCoordSeq_getSize(cs,n) GEOSCoordSeq_getSize( (GEOSCoordSequence *) cs, n )
#define GEOSCoordSeq_getX(cs,i,x) GEOSCoordSeq_getX( (GEOSCoordSequence *)cs, i, x )
Expand Down Expand Up @@ -5328,6 +5330,40 @@ QgsGeometry* QgsGeometry::buffer( double distance, int segments )
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::centroid()
{
if ( mGeos == NULL )
{
exportWkbToGeos();
}
if ( !mGeos )
{
return 0;
}
try
{
return fromGeosGeom( GEOSGetCentroid( mGeos ) );
}
CATCH_GEOS( 0 )
}

QgsGeometry* QgsGeometry::convexHull()
{
if ( mGeos == NULL )
Expand Down Expand Up @@ -5450,7 +5486,6 @@ QgsGeometry* QgsGeometry::symDifference( QgsGeometry* geometry )
CATCH_GEOS( 0 )
}


QList<QgsGeometry*> QgsGeometry::asGeometryCollection()
{
if ( mGeos == NULL )
Expand Down
10 changes: 8 additions & 2 deletions src/core/qgsgeometry.h
Expand Up @@ -128,8 +128,6 @@ class CORE_EXPORT QgsGeometry
bool isMultipart();




double distance( QgsGeometry& geom );

/**
Expand Down Expand Up @@ -269,6 +267,14 @@ class CORE_EXPORT QgsGeometry
/** 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 center of mass of a geometry
* @note for line based geometries, the center point of the line is returned,
* and for point based geometries, the point itself is returned */
QgsGeometry* centroid();

/** Returns the smallest convex polygon that contains all the points in the geometry. */
QgsGeometry* convexHull();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsgenericprojectionselector.cpp
Expand Up @@ -40,7 +40,7 @@ void QgsGenericProjectionSelector::setMessage( QString theMessage )
{
// Set up text edit pane
QString format( "<h2>%1</h2>%2 %3" );
QString header = tr( "Define this layer's projection:" );
QString header = tr( "Define this layer's coordinate reference system:" );
QString sentence1 = tr( "This layer appears to have no projection specification." );
QString sentence2 = tr( "By default, this layer will now have its projection set to that of the project, "
"but you may override this by selecting a different projection below." );
Expand Down
8 changes: 5 additions & 3 deletions src/ui/qgsgenericprojectionselectorbase.ui
Expand Up @@ -10,10 +10,12 @@
</rect>
</property>
<property name="windowTitle" >
<string>Projection Selector</string>
<string>Coordinate Reference System Selector</string>
</property>
<property name="windowIcon" >
<iconset/>
<iconset>
<normaloff/>
</iconset>
</property>
<property name="modal" >
<bool>true</bool>
Expand Down Expand Up @@ -53,7 +55,7 @@
<item row="2" column="0" >
<widget class="QDialogButtonBox" name="buttonBox" >
<property name="standardButtons" >
<set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
Expand Down

0 comments on commit af34446

Please sign in to comment.