Permalink
Browse files

Merge pull request #3 from bonifaido/master

extended radius filtering + code cleaned up
  • Loading branch information...
maxogden committed Jan 17, 2012
2 parents ee281f3 + c9f22f9 commit b9f34cf6b9f4d6e1ceb8709126f0b2437d15405d
Showing with 208 additions and 148 deletions.
  1. +9 −12 README.textile
  2. +199 −136 geojson-utils.js
View
@@ -47,24 +47,21 @@ h2. Point in polygon
h2. Radius filtering
-WARNING: Only works against points right now. TODO: Lines and polygons
-
-If you retrieve a bunch of results from a bounding box query (common with R-Tree geo DBs), but you want to filter the rectangular result set by circular radius:
+If you retrieve a bunch of results from a bounding box query (common with R-tree geo DBs), but you want to filter the rectangular result set by circular radius:
<pre>
<code>
// get the center of the original bounding box
- var center = gju.rectangleCentroid({
+ var center = gju.rectangleCentroid({
"type": "Polygon",
- "coordinates": [[[-122.677, 45.523],[-122.675, 45.524]]]
+ "coordinates": [[[-122.677, 45.523], [-122.675, 45.524]]]
}),
- // draw a circular polygon from the center of
- // the bounding box with a 100 meter radius
- circle = gju.drawCircle(100, center);
-
- for (var point in listOfPointsReturnedFromBoundingBoxQuery) {
- if (gju.pointInPolygon(point, circle)) {
- // ... do stuff with points inside the circle
+ // radius (in meters)
+ radius = 100;
+
+ for (var i in geometryObjectsWithinBBox) {
+ if (gju.geometryWithinRadius(geometryObjectsWithinBBox[i], center, radius)) {
+ // ... do stuff with objects inside the circle
}
}
</code>
Oops, something went wrong.

0 comments on commit b9f34cf

Please sign in to comment.