Skip to content

Commit

Permalink
- renamed QgsGeometry::difference to QgsGeometry::makeDifference
Browse files Browse the repository at this point in the history
- more geoprocessing in QgsGeometry: convexHull, intersection, Union, difference, symDifference


git-svn-id: http://svn.osgeo.org/qgis/trunk@7994 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jan 17, 2008
1 parent 585d22f commit d011ea4
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 5 deletions.
17 changes: 16 additions & 1 deletion python/core/qgsgeometry.sip
Expand Up @@ -195,7 +195,7 @@ not disjoint with existing polygons of the feature*/
/**Changes this geometry such that it does not intersect the other geometry
@param other geometry that should not be intersect
@return 0 in case of success*/
int difference(QgsGeometry* other);
int makeDifference(QgsGeometry* other);

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

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

/** Returns a geometry representing the points shared by this geometry and other. */
QgsGeometry* intersection(QgsGeometry* geometry) /Factory/;

/** Returns a geometry representing all the points in this geometry and other. */
QgsGeometry* Union(QgsGeometry* geometry) /Factory/;

/** Returns a geometry representing the points making up this geometry that do not make up other. */
QgsGeometry* difference(QgsGeometry* geometry) /Factory/;

/** Returns a Geometry representing the points making up this Geometry that do not make up other. */
QgsGeometry* symDifference(QgsGeometry* geometry) /Factory/;

/**Creates a geos geometry from this features geometry. Note, that the returned object needs to be deleted*/
// TODO: unsupported class... would be possible to use PyGEOS?
//geos::Geometry* geosGeometry() const;
Expand Down
67 changes: 66 additions & 1 deletion src/core/qgsgeometry.cpp
Expand Up @@ -2934,7 +2934,7 @@ int QgsGeometry::splitGeometry(const QList<QgsPoint>& splitLine, QList<QgsGeomet
return returnCode;
}

int QgsGeometry::difference(QgsGeometry* other)
int QgsGeometry::makeDifference(QgsGeometry* other)
{
//make sure geos geometry is up to date
if(!mGeos || mDirtyGeos)
Expand Down Expand Up @@ -5523,3 +5523,68 @@ QgsGeometry* QgsGeometry::buffer(double distance, int segments)
return g;
}

QgsGeometry* QgsGeometry::convexHull()
{
if (mGeos == NULL)
exportWkbToGeos();
GEOS_GEOM::Geometry* geos = mGeos->convexHull();
QgsGeometry* g = new QgsGeometry;
g->setGeos(geos);
return g;
}

QgsGeometry* QgsGeometry::intersection(QgsGeometry* geometry)
{
if (geometry == NULL)
return NULL;
if (mGeos == NULL)
exportWkbToGeos();
if (geometry->mGeos == NULL)
geometry->exportWkbToGeos();
GEOS_GEOM::Geometry* geos = mGeos->intersection(geometry->mGeos);
QgsGeometry* g = new QgsGeometry;
g->setGeos(geos);
return g;
}

QgsGeometry* QgsGeometry::Union(QgsGeometry* geometry)
{
if (geometry == NULL)
return NULL;
if (mGeos == NULL)
exportWkbToGeos();
if (geometry->mGeos == NULL)
geometry->exportWkbToGeos();
GEOS_GEOM::Geometry* geos = mGeos->Union(geometry->mGeos);
QgsGeometry* g = new QgsGeometry;
g->setGeos(geos);
return g;
}

QgsGeometry* QgsGeometry::difference(QgsGeometry* geometry)
{
if (geometry == NULL)
return NULL;
if (mGeos == NULL)
exportWkbToGeos();
if (geometry->mGeos == NULL)
geometry->exportWkbToGeos();
GEOS_GEOM::Geometry* geos = mGeos->difference(geometry->mGeos);
QgsGeometry* g = new QgsGeometry;
g->setGeos(geos);
return g;
}

QgsGeometry* QgsGeometry::symDifference(QgsGeometry* geometry)
{
if (geometry == NULL)
return NULL;
if (mGeos == NULL)
exportWkbToGeos();
if (geometry->mGeos == NULL)
geometry->exportWkbToGeos();
GEOS_GEOM::Geometry* geos = mGeos->symDifference(geometry->mGeos);
QgsGeometry* g = new QgsGeometry;
g->setGeos(geos);
return g;
}
17 changes: 16 additions & 1 deletion src/core/qgsgeometry.h
Expand Up @@ -265,7 +265,7 @@ not disjoint with existing polygons of the feature*/
/**Changes this geometry such that it does not intersect the other geometry
@param other geometry that should not be intersect
@return 0 in case of success*/
int difference(QgsGeometry* other);
int makeDifference(QgsGeometry* other);

/**Returns the bounding box of this feature*/
QgsRect boundingBox();
Expand All @@ -281,6 +281,21 @@ not disjoint with existing polygons of the feature*/
/** 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 the smallest convex polygon that contains all the points in the geometry. */
QgsGeometry* convexHull();

/** Returns a geometry representing the points shared by this geometry and other. */
QgsGeometry* intersection(QgsGeometry* geometry);

/** Returns a geometry representing all the points in this geometry and other. */
QgsGeometry* Union(QgsGeometry* geometry);

/** Returns a geometry representing the points making up this geometry that do not make up other. */
QgsGeometry* difference(QgsGeometry* geometry);

/** Returns a Geometry representing the points making up this Geometry that do not make up other. */
QgsGeometry* symDifference(QgsGeometry* geometry);

/** Exports the geometry to mWkt
@return true in case of success and false else
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -1781,11 +1781,11 @@ int QgsVectorLayer::removePolygonIntersections(QgsGeometry* geom)

for(; it != featureList.end(); ++it)
{
//call geometry->difference for each feature
//call geometry->makeDifference for each feature
currentGeom = it->geometry();
if(currentGeom)
{
if(geom->difference(it->geometry()) != 0)
if(geom->makeDifference(it->geometry()) != 0)
{
returnValue = 2;
}
Expand Down

0 comments on commit d011ea4

Please sign in to comment.