For example, I can draw a map showing countries in the UK based on the tutorial here.
I then have a some points which have coordinates but no indication as to which country they lie within.
I would like to display a total point count for each country.
Can I work out which country contains each point in the browser, or do I need to preprocess my point data on the server using PostGIS or similar?
d3 has you covered: https://github.com/d3/d3-geo#geoContains
Returns true if and only if the specified GeoJSON object contains the specified point, or false if the object does not contain the point. The point must be specified as a two-element array [longitude, latitude] in degrees. For Point and MultiPoint geometries, an exact test is used; for a Sphere, true is always returned; for other geometries, an epsilon threshold is applied.
Expanding the @thedude answer's you can also use geojson-lookup if you need to do this check more than once on a given GeoJSON.
©2020 All rights reserved.