Coordinate System – Calculating Bounding Box Coordinates Based on Center and Radius

coordinate system

I need to calculate a bounding box for osm query. I get coordinates of center of the area (WGS84) and radius (meters). How can I do it?

I though about using some kind of projection, calculating projected box coordinates and then convert it back. Is it good idea? If so, which projection will suit the best to this task? I've read that miller's projection is a poor idea and it's better to use state plane projection. But on the other hand in my case bounding box doesn't need to be accurate. The most important for me is to calculate those coordinates quickly.

I would be grateful if you could show me some code example that do conversions essential for calculating bounding box.

I wanted to make this works on whole planet, but if there are better approximations I can assume that it should work in eastern Europe
Latitude: 48.342 – 55.279
Longitude: 13.645 – 25.071

Best Answer

(My original answer forgot about your position and radius being in different units!)

Assuming accuracy is unimportant, then if your centre is (X, Y) and your radius is R, the bounding box corners are simply (X-R, Y-R) and (X+R, Y+R).

Considering the different units:

Assuming accuracy is unimportant, then if

  • your centre is (X, Y), where Y is latitude, X is longitude, in degrees
  • your original search radius is r, and
  • the earth radius is R, in the same units as r

Then the bounding box corners are simply (X - dX, Y - dY) and (X + dX, Y + dY) where

dY = 360 * r / R, the "search radius", as difference in latitude,

dX = dY * cos (rad (Y)), the "search radius", as difference in longitude.

Related Question