Calculate a boundary from set of geo locations

498 Views Asked by At

I have list of latitudes and longitudes.

These are acquired from reverse zip look up database and it's under a specific city (Dayton, OH).

39.721286   -84.133892
39.760000   -84.195900
39.757800   -84.177700
39.845339   -84.123287
...

I have a property database in mongodb and, each property has the location defined (lat/lng), when user enters "Dayton, OH", I'm grabbing Dayton's all the zip codes with relevant geo coordinates and what I want to do is to create a boundary and add 5 miles to it and search the property database which covers the lat/lng of dayton zip codes.

What's the best way to create a boundary (square/circle) to search a database within the range using this list of cordinates?

2

There are 2 best solutions below

0
On BEST ANSWER

Found the solution, apparently the best approach is to calculate the border from application end using "convex hull" algorithm and then query.

0
On

You can use the $near operator in MongoDB.

For example:

db.cities.find( { loc : { $near : { $geometry : { type : "Point" , coordinates : [ lon, lat] }, $maxDistance : 1/111.12 } } } )

The above query fiends everything near specific coordinates within a 1km radius (see $maxDistance).

For more information about the $near operator, take a look at the MongoDB Manual.