Converting geo coordinates from degree to decimal

Use the measurements package from CRAN which has a unit conversion function already so you don’t need to make your own: x = read.table(text = ” lat long 105252 30°25.264 9°01.331 105253 30°39.237 8°10.811 105255 31°37.760 8°06.040 105258 31°41.190 8°06.557 105259 31°41.229 8°06.622 105260 31°38.891 8°06.281″, header = TRUE, stringsAsFactors = FALSE) Once your data.frame … 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

Determine timezone from latitude/longitude without using web services like Geonames.org

I had this problem a while back and did exactly what adam suggested: Download the database of cities from geonames.org convert it to a compact lat/lon -> timezone list use an R-Tree implementation to efficiently lookup the nearest city (or rather, its timezone) to a given coordinate IIRC it took less than 1 second to … Read more

Leaflet- marker click event works fine but methods of the class are undefined in the callback function

This is a classic JavaScript mistake. this in JavaScript does not necessarily refer to your class instance object. It is the context of the function when it is called. You can force this context with bind, and in many libraries you can easily force it as well. In this case with Leaflet you can pass … Read more

Calculating area enclosed by arbitrary polygon on Earth’s surface

There several ways to do this. 1) Integrate the contributions from latitudinal strips. Here the area of each strip will be (Rcos(A)(B1-B0))(RdA), where A is the latitude, B1 and B0 are the starting and ending longitudes, and all angles are in radians. 2) Break the surface into spherical triangles, and calculate the area using Girard’s … Read more

tech