Skip to content

Commit

Permalink
added a method QgsGeometry::fast_intersect. This method does the same…
Browse files Browse the repository at this point in the history
… as QgsGeometry::intersect, but it uses direct generation of geos geometry with QgsGeometry::geosGeometry(). In contrast, QgsGeometry::intersect uses wkt export of QgsGeometry and wkb import of geos. Therefore it is slower than fast_intersect (but better tested). After 0.8, QgsGeometry::fast_intersect may replace QgsGeometry::intersect

git-svn-id: http://svn.osgeo.org/qgis/trunk@5736 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Aug 25, 2006
1 parent 10ea5eb commit f97e8bb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/core/qgsgeometry.cpp
Expand Up @@ -2088,6 +2088,51 @@ bool QgsGeometry::intersects(QgsRect* r) const
return returnval;
}

bool QgsGeometry::fast_intersects(const QgsRect* r) const
{
bool returnval=false;

//use the geos export of QgsGeometry
geos::Geometry *geosGeom = geosGeometry();

//write the selection rectangle to wkt by hand
QString rectwkt="POLYGON((";
rectwkt+=QString::number(r->xMin(),'f',3);
rectwkt+=" ";
rectwkt+=QString::number(r->yMin(),'f',3);
rectwkt+=",";
rectwkt+=QString::number(r->xMax(),'f',3);
rectwkt+=" ";
rectwkt+=QString::number(r->yMin(),'f',3);
rectwkt+=",";
rectwkt+=QString::number(r->xMax(),'f',3);
rectwkt+=" ";
rectwkt+=QString::number(r->yMax(),'f',3);
rectwkt+=",";
rectwkt+=QString::number(r->xMin(),'f',3);
rectwkt+=" ";
rectwkt+=QString::number(r->yMax(),'f',3);
rectwkt+=",";
rectwkt+=QString::number(r->xMin(),'f',3);
rectwkt+=" ";
rectwkt+=QString::number(r->yMin(),'f',3);
rectwkt+="))";
geos::GeometryFactory *gf = new geos::GeometryFactory();
geos::WKTReader *wktReader = new geos::WKTReader(gf);
geos::Geometry *geosRect = wktReader->read( qstrdup(rectwkt) );

if(geosGeom->intersects(geosRect))
{
returnval=true;
}

delete geosGeom;
delete geosRect;
delete gf;
delete wktReader;
return returnval;
}


bool QgsGeometry::contains(QgsPoint* p) const
{
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsgeometry.h
Expand Up @@ -181,6 +181,9 @@ class QgsGeometry {
/** Test for intersection with a rectangle (uses GEOS) */
bool intersects(QgsRect* r) const;

/**Also tests for intersection, but uses direct geos export of QgsGeometry instead wkb export and geos wkb import. Therefore this method is faster and could replace QgsGeometry::intersects in the future*/
bool fast_intersects(const QgsRect* r) const;

/** Test for containment of a point (uses GEOS) */
bool contains(QgsPoint* p) const;

Expand Down

0 comments on commit f97e8bb

Please sign in to comment.