How to find which polygon contains the given GPS coordinate from list of polygons, in server-side?

400 Views Asked by At

Background Information

I am using Node JS with MongoDB as database to build an API for a mobile application which collects geospatial data. The data consists of latitude and longitude information along with other data relevant to the application.

Problem Statement

The mobile app collects data from different states from India, and within each states, the area is divided into divisions and ranges. Shape files of each divisions and ranges are available in KML file or in [{lat, long}] array format. The App has to find out, which division/range the gps location is from, given that division/range is a polygon. There are 15 states where app is functional and each state has approximately 12-15 divisions. Each divisions consists of 6-10 ranges.

My problem is:-

  1. If a GPS coordinate is given as input the API, I want the output to be the state, division & range name in which the point lies in. If it is not inside any polygon (state/division/range), saved in database the API should return null.

  2. Given that I have list of divisions and ranges with their boundaries in [{lat, long}] array format, how to store it in MongoDB for the purpose of above asked question.

A rough drawing of what I expect

Assuming 1, 2 & 3 are different division/range polygons inside a state (assuming the entire white paper represents a state in India),

  1. When the input is point A (lat : x1, long : y1), the output should be null as it is not inside any division/range
  2. When the input is point B (lat : x2, long : y2), the output should be Polygon 3, as the point lies inside polygon 3.

Thanks in advance!

0

There are 0 best solutions below