I’m working on a module for a transport app.
My boss gave me this task: We have a class called CitizenRequest
where there’s an attribute, called PointPath
, which stores the latitude and longitude of a citizen’s location.
This data is stored in a JSON file in a MongoDB database.
What I have to do is: Take this JSON, find the minimum PointPath
(or else, minimum latitude and longitude), the maximum, and use this to positions to make a square, which will represent our area of transport.
Now, I have to divide this square into other mini squares, and each one of these will become a "zone". This zone will then have an ID, and must be stored into another collection.
The purpose of this collection should be to store how many requests we have for each zone. So, for example, we will see that in the zone with ID=149, we have X requests.
To do so, I should create an algorithm that analyzes latitude and longitude to understand in which zone it falls.
I know this may sound pretty difficult. Still, I have absolutely no idea how to implement this. So I’m asking you if you have solutions or ideas. I don’t really think I must use APIs to do so, I think it just requires some logic behind it. Any help?
2
Answers
To rephrase,so I understand correctly.
You have one big square which is your valid area (area of transport) and in this square you have a grid, where you try to see where the most requests come from.
First lattitude and longlitude values Look confusing and nothing saying at first: 10,000001 20,002567.
Change that, make it human readable.
If I unverstanden correctly, you need to start and find your point 0.
If you Think of your valid area as a square it would be the bottom left most point. If it is 5.0002345, 10.124567 you would subtract that value of all other values. 5.0003345 10.124567 => 0.0001, 0 so a little bit heigher, than your startingpoint.
Now its way easier to find all the requests in your valid zone. You would take all the points and plot them in an easy x/y plot. Well the implementation I dont know about your dev setup.
I would recomend an simple KNN algorhytmus, to Cluster the request. Maybee the plot itself will be sufficent.
Assume docs contain points like this:
then something like this will capture locations in squares inside the bounding rectangle: