Nodejs lookup long lat point in a geojson data structure.
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

We have a geojson file with a lot of polygons in it. Here is an example geojson file of our data

What we need to do is accept a long lat input and then be able to lookup if the point is inside one of these geojson polygons or not. If it does match we will return some of the meta info about that polygon

For the bounty we have 3 inputs. Long, Lat, geojson file. (in you might be able to just have a static file with your code so we dont need to upload it at runtime). Then we have a button that says “Lookup”. If we dont have a match you can just return “false”, if we do have a match you can return a json reply with something like i suppose we need to handle the case where there is more than 1 match, its rare but would be good to assume it.Last data piece we should include is processing time. This is so we can get an idea of the overall performance of the solution. I am thinking something like Scanned X polygons in Y ms. We will use this as a metric in awarding the winner.

Bounty proof should be posted to so we can run it easily and confirm it working. One note, it would be acceptable if you need to transform the geojson data structure to something more efficient( compact and fast), but we will need to understand the code of the transform so we can replicate it.

awarded to radosinsky

Crowdsource coding tasks.

2 Solutions

Hi QDev,

I think this should do the work you need. I can't test solution precisely because I don't have a point that is inside one of the GeoJSON polygon you provided. Do you have any coordinate that is inside a polygon and that we can test with ?

  • For MultiPolygon I assume that if one polygon is defined in another one, it's considered as an hole.
  • For LineString, I ignore them as it is not a closed polygon.

The interface should ask for longitude and latitude at the beginning.

Best regards.

Technically would a node itself be considered inside of a polygon? I'm trying to figure out how to approach this... here is my writeup. its a lot to put in a comment so im linking to a google doc to make it easier thanks for the help!
Qdev 4 months ago
I checked manually the inital file and the coordinates you gave in your example are not in a poly. (I look for polylines having coordinates near -72.99 but areas are very very small). Regarding the geojson file it seems that order is longitude, latitude, so you will have to revert the google maps data that is having latitude/longitude.
kerncy 4 months ago
Winning solution

Hello Qdev,

here's my solution using Turf.js library:

Here are some points you can test:

  1. Check this map with the polygons:

  2. Coordinates of the VINATERÍA restaurant (outside of the polygon) are: 40.80662358271101, -73.95403116539366

Point [40.80662358271101, -73.95403116539366] found in 0/140 polygon(s).

  1. Coordinates of the Des Ambassades restaurant (inside of the polygon) are: 40.806116202361565, -73.95388702757946

{ Name: 'New York, NY', description: '', tessellate: -1, OBJECTID: '79', EZECNAME: 'New York, NY Empowerment Zone',...
Point [40.806116202361565, -73.95388702757946] found in 1/140 polygon(s).

I choose those two points to show that the script works with multipolygons too.

Note that the execution time is much longer while on (usually 1 to 3 seconds). It takes ~100ms on my computer to check all 140 polygons from the provided geojson file.

Let me know if this solves your problem or if you have any questions. Thank you!

View Timeline