[Math] How to calculate the number of latitude/longitude coordinates in a specific area at a given precision

geometryspherical-geometry

I am looking into ways of grouping large sets of latitude/longitude coordinates and am wondering if there is an easy/standard way to roughly calculate the number of different coordinates in a given area.

If I have a coordinate 41.174104, -87.853926, how many other coordinates are there at that same level of precision within a mile radius? And if I decrease the precision to 3 decimals 41.174, -87.853, how many different coordinates are there within a mile radius of that?

Just looking for a point in the right direction, I'm a software guy, no serious math background. Thanks.

Best Answer

Since you only want to calculate the number roughly and the distance of a mile is small compared to the Earth's radius, it should be sufficient to use a linear approximation with the surface element of the transformation to Cartesian coordinates. For a rough calculation, we can take the Earth as spherical and assume that the latitude and longitude are spherical coordinates $\theta$ and $\phi$, respectively. The surface element for spherical coordinates is $r^2\sin\theta\mathrm d\theta\mathrm d\phi$. Loosely speaking, that means that an infinitesimal area $\mathrm d\theta\mathrm d\phi$ in the coordinate space corresponds to an infinitesimal surface area $r^2\sin\theta\mathrm d\theta\mathrm d\phi$ on the actual surface of the sphere. For your purposes, we can take $\sin\theta$ as constant, in which case the areas are simply proportional to each other, with proportionality constant $r^2\sin\theta$. For your purposes, we can calculate the area of the circle as if it were flat, so a circle with a radius of one mile has an area $A$ of $\pi$ square miles. The radius $r$ of the Earth is roughly $4000$ miles, and at latitude $\theta=41.174104^\circ$ we have $\sin\theta\approx0.66$, so the corresponding area in coordinate space is $A/(r^2\sin\theta)\approx\pi/(4000^2\cdot0.66)\approx3\cdot10^{-7}$. The area per grid point in a grid of coordinates with $d$ decimals is $(10^{-d})^2=10^{-2d}$, so for instance if you use $d=6$ digits you'd have roughly $3\cdot10^{-7}/10^{-12}=3\cdot10^5$ different coordinates within a one-mile radius, whereas if you use $d=3$ digits the result is $3\cdot10^{-7}/10^{-6}=0.3$, so you wouldn't expect any other coordinates within that radius.