Skip to content

Commit c5bb76e

Browse files
author
wonder
committed
- renamed QgsGeometry::difference to QgsGeometry::makeDifference
- more geoprocessing in QgsGeometry: convexHull, intersection, Union, difference, symDifference git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7994 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent e048352 commit c5bb76e

File tree

4 files changed

+100
-5
lines changed

4 files changed

+100
-5
lines changed

python/core/qgsgeometry.sip

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ not disjoint with existing polygons of the feature*/
195195
/**Changes this geometry such that it does not intersect the other geometry
196196
@param other geometry that should not be intersect
197197
@return 0 in case of success*/
198-
int difference(QgsGeometry* other);
198+
int makeDifference(QgsGeometry* other);
199199

200200
/**Returns the bounding box of this feature*/
201201
QgsRect boundingBox();
@@ -212,6 +212,21 @@ not disjoint with existing polygons of the feature*/
212212
of segments used to approximate curves */
213213
QgsGeometry* buffer(double distance, int segments) /Factory/;
214214

215+
/** Returns the smallest convex polygon that contains all the points in the geometry. */
216+
QgsGeometry* convexHull() /Factory/;
217+
218+
/** Returns a geometry representing the points shared by this geometry and other. */
219+
QgsGeometry* intersection(QgsGeometry* geometry) /Factory/;
220+
221+
/** Returns a geometry representing all the points in this geometry and other. */
222+
QgsGeometry* Union(QgsGeometry* geometry) /Factory/;
223+
224+
/** Returns a geometry representing the points making up this geometry that do not make up other. */
225+
QgsGeometry* difference(QgsGeometry* geometry) /Factory/;
226+
227+
/** Returns a Geometry representing the points making up this Geometry that do not make up other. */
228+
QgsGeometry* symDifference(QgsGeometry* geometry) /Factory/;
229+
215230
/**Creates a geos geometry from this features geometry. Note, that the returned object needs to be deleted*/
216231
// TODO: unsupported class... would be possible to use PyGEOS?
217232
//geos::Geometry* geosGeometry() const;

src/core/qgsgeometry.cpp

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2934,7 +2934,7 @@ int QgsGeometry::splitGeometry(const QList<QgsPoint>& splitLine, QList<QgsGeomet
29342934
return returnCode;
29352935
}
29362936

2937-
int QgsGeometry::difference(QgsGeometry* other)
2937+
int QgsGeometry::makeDifference(QgsGeometry* other)
29382938
{
29392939
//make sure geos geometry is up to date
29402940
if(!mGeos || mDirtyGeos)
@@ -5523,3 +5523,68 @@ QgsGeometry* QgsGeometry::buffer(double distance, int segments)
55235523
return g;
55245524
}
55255525

5526+
QgsGeometry* QgsGeometry::convexHull()
5527+
{
5528+
if (mGeos == NULL)
5529+
exportWkbToGeos();
5530+
GEOS_GEOM::Geometry* geos = mGeos->convexHull();
5531+
QgsGeometry* g = new QgsGeometry;
5532+
g->setGeos(geos);
5533+
return g;
5534+
}
5535+
5536+
QgsGeometry* QgsGeometry::intersection(QgsGeometry* geometry)
5537+
{
5538+
if (geometry == NULL)
5539+
return NULL;
5540+
if (mGeos == NULL)
5541+
exportWkbToGeos();
5542+
if (geometry->mGeos == NULL)
5543+
geometry->exportWkbToGeos();
5544+
GEOS_GEOM::Geometry* geos = mGeos->intersection(geometry->mGeos);
5545+
QgsGeometry* g = new QgsGeometry;
5546+
g->setGeos(geos);
5547+
return g;
5548+
}
5549+
5550+
QgsGeometry* QgsGeometry::Union(QgsGeometry* geometry)
5551+
{
5552+
if (geometry == NULL)
5553+
return NULL;
5554+
if (mGeos == NULL)
5555+
exportWkbToGeos();
5556+
if (geometry->mGeos == NULL)
5557+
geometry->exportWkbToGeos();
5558+
GEOS_GEOM::Geometry* geos = mGeos->Union(geometry->mGeos);
5559+
QgsGeometry* g = new QgsGeometry;
5560+
g->setGeos(geos);
5561+
return g;
5562+
}
5563+
5564+
QgsGeometry* QgsGeometry::difference(QgsGeometry* geometry)
5565+
{
5566+
if (geometry == NULL)
5567+
return NULL;
5568+
if (mGeos == NULL)
5569+
exportWkbToGeos();
5570+
if (geometry->mGeos == NULL)
5571+
geometry->exportWkbToGeos();
5572+
GEOS_GEOM::Geometry* geos = mGeos->difference(geometry->mGeos);
5573+
QgsGeometry* g = new QgsGeometry;
5574+
g->setGeos(geos);
5575+
return g;
5576+
}
5577+
5578+
QgsGeometry* QgsGeometry::symDifference(QgsGeometry* geometry)
5579+
{
5580+
if (geometry == NULL)
5581+
return NULL;
5582+
if (mGeos == NULL)
5583+
exportWkbToGeos();
5584+
if (geometry->mGeos == NULL)
5585+
geometry->exportWkbToGeos();
5586+
GEOS_GEOM::Geometry* geos = mGeos->symDifference(geometry->mGeos);
5587+
QgsGeometry* g = new QgsGeometry;
5588+
g->setGeos(geos);
5589+
return g;
5590+
}

src/core/qgsgeometry.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ not disjoint with existing polygons of the feature*/
265265
/**Changes this geometry such that it does not intersect the other geometry
266266
@param other geometry that should not be intersect
267267
@return 0 in case of success*/
268-
int difference(QgsGeometry* other);
268+
int makeDifference(QgsGeometry* other);
269269

270270
/**Returns the bounding box of this feature*/
271271
QgsRect boundingBox();
@@ -281,6 +281,21 @@ not disjoint with existing polygons of the feature*/
281281
/** Returns a buffer region around this geometry having the given width and with a specified number
282282
of segments used to approximate curves */
283283
QgsGeometry* buffer(double distance, int segments);
284+
285+
/** Returns the smallest convex polygon that contains all the points in the geometry. */
286+
QgsGeometry* convexHull();
287+
288+
/** Returns a geometry representing the points shared by this geometry and other. */
289+
QgsGeometry* intersection(QgsGeometry* geometry);
290+
291+
/** Returns a geometry representing all the points in this geometry and other. */
292+
QgsGeometry* Union(QgsGeometry* geometry);
293+
294+
/** Returns a geometry representing the points making up this geometry that do not make up other. */
295+
QgsGeometry* difference(QgsGeometry* geometry);
296+
297+
/** Returns a Geometry representing the points making up this Geometry that do not make up other. */
298+
QgsGeometry* symDifference(QgsGeometry* geometry);
284299

285300
/** Exports the geometry to mWkt
286301
@return true in case of success and false else

src/core/qgsvectorlayer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,11 +1781,11 @@ int QgsVectorLayer::removePolygonIntersections(QgsGeometry* geom)
17811781

17821782
for(; it != featureList.end(); ++it)
17831783
{
1784-
//call geometry->difference for each feature
1784+
//call geometry->makeDifference for each feature
17851785
currentGeom = it->geometry();
17861786
if(currentGeom)
17871787
{
1788-
if(geom->difference(it->geometry()) != 0)
1788+
if(geom->makeDifference(it->geometry()) != 0)
17891789
{
17901790
returnValue = 2;
17911791
}

0 commit comments

Comments
 (0)