Geospatial $near within current document field value

Yes it’s possible. You just use $geoNear instead. Beware the catches and read carefully. Presuming that your intent to is to store a field such as “travelDistance” to indicate on the document that any such searches must be “within” that supplied distance from the queried point to be valid. Then we simply query and evaluate … Read more

Whats the fastest way to lookup big tables for points within radius MySQL (latitude longitude)

Well first of all if you have a lot of geospatial data, you should be using mysql’s geospatial extensions rather than calculations like this. You can then create spatial indexes that would speed up many queries and you don’t have to write long drawn out queries like the one above. Using a comparision with ST_Distance … Read more

How to calculate the area of a polygon on the earth’s surface using python?

Let’s say you have a representation of the state of Colorado in GeoJSON format {“type”: “Polygon”, “coordinates”: [[ [-102.05, 41.0], [-102.05, 37.0], [-109.05, 37.0], [-109.05, 41.0] ]]} All coordinates are longitude, latitude. You can use pyproj to project the coordinates and Shapely to find the area of any projected polygon: co = {“type”: “Polygon”, “coordinates”: … Read more

MongoDB print distance between two points

You can use the $geoNear aggregate pipeline stage to produce a distance from the queried point: db.new_stores.aggregate([ { “$geoNear”: { “near”: { “type”: “Point”, “coordinates”: [ -81.093699, 32.074673 ] }, “maxDistance”: 500 * 1609, “spherical”: true, “distanceField”: “distance”, “distanceMultiplier”: 0.000621371 }} ]).pretty() This allows you to specify “distanceField” which will produce another field in the … Read more

Decoding the Google Maps embedded parameters

This intermediate is not the final answer, and the sequel follows)), just some thoughts Undocumented method. (with ftid instead of place_id parameter) Places API Web Service No warranty in future: https://maps.googleapis.com/maps/api/place/details/json?key=YOUR_API_KEY&ftid=0xd62377123a70817:0x85e89b65fcf7c648& The documented request is: https://maps.googleapis.com/maps/api/place/details/json?key=YOUR_API_KEY&placeid=ChIJFwinI3E3Yg0RSMb3_GWb6IU Need API KEY for this requests Setting up API keys Answer from Google: (JSON – light parsing) { “html_attributions” … Read more

How to calculate distance from a point to a line segment, on a sphere?

Here’s my own solution, based on the idea in ask Dr. Math. I’d be happy to see your feedback. Disclaimer first. This solution is correct for spheres. Earth isn’t a sphere, and the coordinates system (WGS 84) doesn’t assume it’s a sphere. So this is just an approximation, and I can’t really estimate is error. … Read more

Formulas to Calculate Geo Proximity

The Law of Cosines and the Haversine Formula will give identical results assuming a machine with infinite precision. The Haversine formula is more robust to floating point errors. However, today’s machines have double precision of the order of 15 significant figures, and the law of cosines may work just fine for you. Both these formulas … Read more

Pandas Latitude-Longitude to distance between successive rows [duplicate]

you can use this great solution (c) @derricw (don’t forget to upvote it ;-): # vectorized haversine function def haversine(lat1, lon1, lat2, lon2, to_radians=True, earth_radius=6371): “”” slightly modified version: of http://stackoverflow.com/a/29546836/2901002 Calculate the great circle distance between two points on the earth (specified in decimal degrees or in radians) All (lat, lon) coordinates must have … Read more