2

I know this has been asked a million times in here, but I can't really understand it,

I am using OpenStreetMap (OSM) particularly Overpass API, as I only need roadway information.

I know that I need to use the Mercator projection formula stated in thread like this;

Mercator projection: formula for latitude based on pixels?

and I also found source code that uses it perfectly like; https://github.com/Anubha-Banerjee/3d-mapLand

but I'm a little bit confused with regards to the "width" part of the formula. The forum says, its an image width, but since I am just getting information from Overpass API with a bounding box, I don't know what will be the "width" value.

In the first link it has this function.

function getPixelShift ( pxWidth, map_latitude )
{
    var pi = Math.PI;   
    var pixelShift = (pxWidth / ( 2 * pi) ) * Math.log( Math.tan( pi / 4 + (map_latitude/2) * pi / 180 ) );    
    return pixelShift.toFixed(2);
}

How do I know what values to supply in the pxWidth variable?

Same as that of 3d-mapLand code which has this formula for conversion

double convert_lat_to_y(double lat)
{
    double y = 0, w = 2000;
    double latRad = m3dDegToRad(lat);
    y = (w / (2 * M_PI) * log(tan(M_PI / 4 + latRad / 2)) * SCALE);
    y = y + map.shiftY;
    return y;
}

As you can see, the variable "w" was hardcoded with value 2000 without any explanation on what it is and how it was derived? (tried to contact the author to no avail/reply yet)

Can somebody explain further how to get this value in the formula?

  • 1
    I think they just refer to the width of your final image, the image you're trying to create. – barrycarter Jul 13 '18 at 0:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.