Skip to content
Permalink
Browse files
added a method QgsGeometry::fast_intersect. This method does the same…
… 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 f97e8bb2b2e3944ca36a28f8ce91707e41b42b32
Showing with 48 additions and 0 deletions.
  1. +45 −0 src/core/qgsgeometry.cpp
  2. +3 −0 src/core/qgsgeometry.h
@@ -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
{
@@ -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;

0 comments on commit f97e8bb

Please sign in to comment.