I am working with an ESRI stack, storing my layers in a sql-spatial-enabled-SDE- geodatabase (Geometry type, Web Mercator-3857).
I am building a web mapping application, so by default, the tiles are also in web mercator, 3857.
Via stored procs, i use STDistance to query distances from a user's location (Coordinates also in web mercator) to the various layers.
Problem is, due to the distortion of web mercator, my distance calcs are increasingly off, the further from the equator they are made.
I've thought of storing my layers in sql-spatial-geography (rather than geometry) type, but:
- I imagine my distance queries will take much longer (distance calcs on spherical surface)
- i will need to reimport a lot of data
- arcgis services won't be as fast as they will need to project on the fly
If I go to Google maps, and do a distance calc, the distance returned is much more accurate, even in Nortern/southern regions, so I assume Google must be correcting for distortion caused by the web mercator projection.
My question then: Is there a simple factor value that can be applied to distance calcs done in web mercator projection to get the "correct" distance?
Answer
For short distances, you could multiply the calculated distance with cos(lat), since the scale of the mercator projection is proportional to the secant of the latitude (secant is 1/cos). Also see http://en.wikipedia.org/wiki/Mercator_projection#Mathematics_of_the_projection
Addendum thanks to @jeremiah-england: while the above correction would be correct when it comes to true Mercator projections, the Web Mercator (EPSG:3857) is not a Mercator. EPSG calls it a "Pseudo-Mercator." The problem is that it uses WGS84, an eliptical model, and projects it using spherical mercator calculations (which Google used because they are faster). If you scale your distances by 1/cos(phi) with the web Mercator, you'll be about 0.6% off at the equator. See Noel Zinn's presentation on Web Mercator for more details.
According to the above-mentioned presentation, the following method could be used to calculate more accurate distances from web mercator coordinates. Given dx — horizontal coordinate difference (W-E direction), and dy — vertical coordinate difference (S-N direction):
e = 0.081819191
adjustedX = dx * cos(lat) / sqrt(1 - e^2 * sin(lat)^2)
adjustedY = dy * cos(lat) * (1 - e^2) / pow(1 - e^2 * sin(lat)^2, 3/2)
adjustedDistance = hypot(adjustedX, adjustedY)
The ratio between this adjustment and cos(lat) is larger in the S-N direction, ranging from 0.9933 at the equator to 1.0034 at the poles. The W-E direction ratio starts with 1 at the equator and grows to 1.0034 at the poles.
Note that this correction still works reasonably well only for short distances, where planar geometry of the Earth's surface can be assumed.
No comments:
Post a Comment