[GIS] How to calculate the bounding box for given a distance and latitude/longitude

distanceextentswgs84

I need to be able to calculate a bounding box or circle for a given WGS84 latitude and WGS84 longitude, and distance but have no idea where to start!

The distance from the start Lat/Lon would be 10Km or less.

Would it be possible for someone to give me some pointers / Example on how to do this

Best Answer

WGS-what? WGS-84? Depending on what accuracy you need, you may need to know a lot more information - my guess is that's why you've been down voted, though no-one bothered to leave a comment saying why.

Here are two ways:

Inaccurate, but probably 'good enough'

One degree of latitude is approximately 10001.965729/90 kilometres (distance from the equator to the pole, divided by ninety degrees) or 111.113 kilometres, using the WGS-84 datum. This is an approximation because of the shape of the earth, and because distances change as you approach the poles (one reason to use latitude, not longitude - eventually the distance of one degree of longitude is zero!) The earth is also not a perfect sphere. Both these are reasons to use a more complex projection- and datum-based approach, in my second answer.

10001.965729km = 90 degrees
1km = 90/10001.965729 degrees = 0.0089982311916 degrees
10km = 0.089982311915998 degrees

This is using decimal degrees, not degrees / minutes / seconds.

So, your bounding box will be your point, plus and minus 0.08999 degrees. Alternatively you could use this number as a radius, giving you a bounding circle.

Any GIS person reading this will shudder. It will be mostly accurate, though, depending where you are in the world. For a 10km radius it should be fine.

Much more accurate, but more code

Use a projection library and specify your datum, etc. I recommend Proj4; it's widely used so Google returns heaps of results for questions about it, and there are Delphi wrappers. If you have trouble using it, post another question here on SO - it's out of scope for this one. The Proj4 website has examples using the basic APIs, and although these are in C it should be fairly easily translatable. Their API reference is the best place to start, followed by the FAQ.

I'd use WGS-84 as a basic datum (representation of the earth) unless you know a specific one you want to use, or that was used for creating your coordinates. It's commonly used and pretty accurate.

If your position comes from Google Maps (for example), specify a Mercator projection. You may want to use another projection, or use, say, UTM coordinates instead of latitude and longitude, depending on the source of your data and if you want high accuracy for a small local area. (UTM has multiple zones, all of which change the distortion so that within that zone, it's highly accurate; if you use a zone for coordinates outside it the distortion will greatly increase as you move away. If you view the whole earth projected from one zone, it might ben unrecognisable. But within a zone, UTM translations will be about as good as you can get. Coordinates are generally specified in meters, not in degrees, so it may be more useful for your you, given you need a 10km radius. 10km is easily within a single zone, you just need to choose the appropriate zone based on your centre coordinate. The only tricky bit is when you approach a border: it's a common situation, and it's fine, just be consistent in how you choose which one you use. Proj4 will also let you translate projections, so you can go from your Mercator WGS-84 lat/long to a UTM zone n, for example, or to and from two UTM zones.)