Get altitude by longitude and latitude in Android

My approach is to use USGS Elevation Query Web Service: private double getAltitude(Double longitude, Double latitude) { double result = Double.NaN; HttpClient httpClient = new DefaultHttpClient(); HttpContext localContext = new BasicHttpContext(); String url = “http://gisdata.usgs.gov/” + “xmlwebservices2/elevation_service.asmx/” + “getElevation?X_Value=” + String.valueOf(longitude) + “&Y_Value=” + String.valueOf(latitude) + “&Elevation_Units=METERS&Source_Layer=-1&Elevation_Only=true”; HttpGet httpGet = new HttpGet(url); try { HttpResponse … Read more

Fast Haversine Approximation (Python/Pandas)

Here is a vectorized numpy version of the same function: import numpy as np def haversine_np(lon1, lat1, lon2, lat2): “”” Calculate the great circle distance between two points on the earth (specified in decimal degrees) All args must be of equal length. “”” lon1, lat1, lon2, lat2 = map(np.radians, [lon1, lat1, lon2, lat2]) dlon = … Read more

Fastest Way to Find Distance Between Two Lat/Long Points

I needed to solve similar problem (filtering rows by distance from single point) and by combining original question with answers and comments, I came up with solution which perfectly works for me on both MySQL 5.6 and 5.7. SELECT *, (6371 * ACOS(COS(RADIANS(56.946285)) * COS(RADIANS(Y(coordinates))) * COS(RADIANS(X(coordinates)) – RADIANS(24.105078)) + SIN(RADIANS(56.946285)) * SIN(RADIANS(Y(coordinates))))) AS distance … Read more

Algorithm to detect when and where a point will exit a rectangle area

You need to find what edge is intersected first. Make equations for moving along both coordinates and calculate the first time of intersection. Note that for geographic coordinates you might need more complex calculations because “rectangle” defined by Lat/Lon coordinates is really curvy trapezoid on the Earth surface. Look at “Intersection of two paths given … Read more

tech