File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 1+ A simple index for matching points against a set of GeoJSON polygons to find what polygon a point belongs to.
2+
3+ For example, given a GeoJSON of world countries, it can be used to determine what country a location belongs to.
4+
5+
6+ ### Example usage
7+
8+ Using [ this 50m world countries dataset] ( https://s3.amazonaws.com/geojson-please/naturalearth-3.3.0/ne_50m_admin_0_countries.geojson ) :
9+
10+ ``` js
11+ var geojson = require (' ./countries.json' );
12+ var tree = whichPolygon .index (geojson);
13+
14+ whichPolygon .query (tree, [30.5 , 50.5 ]).admin ; // 'Ukraine'
15+ ```
16+
17+ The input GeoJSON must be a feature collection of polygons or multipolygons.
18+
19+ Once the index is built, queries are pretty fast —
20+ 20 seconds to query 1 million random locations on a Macbook Pro in this particular case.
You can’t perform that action at this time.
0 commit comments