# How to calculate a map scale with bounding box, width and height?

I have a map that will allow the user to select or slice images/pictures out of it.

As example a map width is 1200px * 1200px and the user selects say 700px x 700px square (note: aspect ratio is preserved) I grab the bounding box for that selection and I ask the tile server to generate a 1400px * 1400px image. That being said, I believe the scale of the image changes (ex. 1 inch equals 500feet) as its size change.

So I am trying to re-calculate that new scale level.

• Scale is defined as the ratio of the distance on a map to the corresponding distance on the surface the map represents.
• The distance on the map is the scale given.

How to calculate the corresponding distance on the surface the map represents?

Example: I have bounding box

``````-10655713.482723532,4537884.8313487405,-10650238.680572607,4543359.633499665
``````

The map says 1KM or 3000feet when I grab it. The bounding box width and height on the map is Width : 573px / Height: 573px.

Now I want to resize the image to be 900px by 900px and re calculate the scale, because the scale value changes as the size of the image changes.

## 1 Answer

To calculate scale you need to know two things, a distance on the map and the length of the same line in pixels or inches etc. You then divide one by the other to give a ratio of 1pixel (or inch) to X metres (or feet).

To make life easier we usually use the width or height of the map as we know the bounding box of the map, and the size of the image. If you are paranoid then calculate both height and width based scale and pick one or the other.