[GIS] Calculating radius / buffer on EPSG 3785 in meters vs buffer in WGS 84 in meters

distancegoogle maps

The goal is working in EPSG 3785 and in particular Google Maps, one wishes to render (on a tile) a circle of a given radius in meters. The rendering is done in pixels.

I would guess that one could take a very simple linear approach to identify the meters per pixel for a given tile zoom:

metersPerPixel = MercWorldWidthMeters / (2 ^ zoom) / tileSize

Now, considering you wish to draw a radius of let's say 100 meters around a point in pixels, then you convert to pixels:

pixelRadius = metersRadius / metersPerPixel

This should in my mind produce a circle of metersRadius on the tile.

However, actually measuring the produced circle's radius with a circle produced in WGS 84 and Great Circle logic, it shows that it is actually about 40% smaller than expected… a big difference.

Does the logic above have a flaw?

Note that I am not interested in finding an alternative algorithm (going to Great Circle calculations and the like)… my question here is "why are the results (so much) different than expected".

All conversions this far have been working fine with the above logic but once I decided to calculate actual distance on EPSG 3785 I seem to be hitting a break wall.


To give an example with figures:

Radius: 0.08 miles ( = 128.74752 meters )
MercWorldWidthMeters: 20037508.342789 * 2
Zoom: 16
TileSize: 256

Above logic suggests a circle of ~107 pixels diameter.
Great Circle suggests a circle of ~175 pixels diameter.

Best Answer

At any given zoom, pixels to real-world distance varies with Latitude. This is why you cannot use the following assumption:

 metersPerPixel = MercWorldWidthMeters / (2 ^ zoom) / tileSize

Note that if you are using Google Maps API, as suggested above, you can simply create a Circle with whatever radius (in meters) you want, and it will draw it appropriately. If you draw some circles near the equator and some near the poles, you will see the difference in pixel size quite easily.

For more robust algorithms and the concepts behind them you may be interested to read http://www.movable-type.co.uk/scripts/latlong.html. In addition you may be interested in the geometry library (http://code.google.com/apis/maps/documentation/javascript/geometry.html#Distance)