0

I want to use the de9im to speed up a call to point within a a polygon, where the polygon may be used many times. I know that de9im has this functionality but I can't seem to figure out how the class in boost even works (geometry/strategies/intersection_result.hpp ). Does anyone know if this class is actually functional and if so can they provide a simple example of a query for a polygon containing a point.

EDIT: I'm comparing the boost geometry library to JTS, which has a prepared geometry class, at this point I'm not 100% that use of the DE-9IM is what is allowing the pre computation but I am still wondering if boost has this functionality in it.

aaronman
  • 18,343
  • 7
  • 63
  • 78

1 Answers1

4

I'm not entirely sure what is the problem exactly.

DE9IM is a model used to describe the spatial relationship of Geometrical objects. See http://en.wikipedia.org/wiki/DE-9IM for more info.

I assume you're looking for a way how to represent Points, Polygons and how to check if one is within the other one. If this is the case then yes, Boost.Geometry of course supports that and many more. For instance to check if a Point is within a Polygon you may use:

  • boost::geometry::model::point<> to represent a Point
  • boost::geometry::model::polygon<> to represent a Polygon
  • boost::geometry::within() function to check the spatial relationship

More info you can find in the docs: http://www.boost.org/libs/geometry

E.g. at the bottom of this page: http://www.boost.org/doc/libs/1_55_0/libs/geometry/doc/html/geometry/reference/algorithms/within/within_2.html you can find an example showing how to create a Point, load Polygon from wkt string and check if one is within another one.

Adam Wulkiewicz
  • 2,068
  • 18
  • 24
  • Yeah I kinda figured out that de-9im wasn't what I need, but does boost geometry have something like a prepared geometry where data structures are precomputed to provide certain calculations faster, I already know how to call the normal within function fine – aaronman May 15 '14 at 21:24
  • No, but I don't know what precomputation do you have in mind. Could you give an example or some link? – Adam Wulkiewicz May 15 '14 at 21:52
  • Ok if you have a big number of Polygons you could build a spatial index storing bounding boxes of those Polygons and their IDs. You could do it once and then use it to find which Polygons should be checked for within(). This is also supported by Boost.Geometry. E.g. check this: http://www.boost.org/doc/libs/1_55_0b1/libs/geometry/doc/html/geometry/spatial_indexes/rtree_examples/index_of_polygons_stored_in_vector.html – Adam Wulkiewicz May 15 '14 at 21:56
  • Already using the rtree, I only ask this question because the JTS implementation of `within` using a prepared geometry is killing `boost::geometry::within`, and JTS is in java – aaronman May 15 '14 at 21:59
  • Boost.Geometry has no prepared geometry concepts. The most obvious thing to do would be (and I'm sure this is done in the JTS) to calculate the bounding Box for a Polygon and check it first. – Adam Wulkiewicz May 15 '14 at 22:42
  • But the rtree already does that for you ;). I think some more complex stuff is going on the PreparedGeometry – aaronman May 15 '14 at 23:02
  • Yes, of course, if you could create the rtree for the input then it should do this job for you. I mentioned about calculating the BoundingBox for a Polygon and reusing it because this is probably the most important optimization which changes the average complexity. Btw, do you know what's the max complexity of within() for prepared Point/Polygon check in the JTS? – Adam Wulkiewicz May 15 '14 at 23:51
  • It's log(n) according to [this](http://lin-ear-th-inking.blogspot.com/2007/07/ultimate-point-in-polygon.html), normal calculation is linear – aaronman May 16 '14 at 02:23