# Create a bounding box from a lat/long

I'm trying to create a bounding box from a simple Lat/Long, given an increase size in metres.

For example, create a bounding box from X/Y which goes outwards 5000m at the NE / SW corner. (yes, this isn't a circle so the radius isn't even, etc).

Result:

• NorthEast corner Lat/Long
• SouthWest corner Lat/Long.

My guess is I need to convert meters to ..something? are they Radians?

I'm used to just using SQL Server geospatial to create new polygons from a point. e.g. `@somePoint.STBuffer(5000)` creates a new circle with a radius of 5000 meters, from the centre point (given the point is WSG84).

How can I do this?

EDIT 1:

As requested re: GIS tools - this is tools agnostic. As in, i'm just after some common math formula to calculate the new co-ordinates. I'm not using any GIS program, but doing some coding.

EDIT 2: - This will be used to search for all points in a poly, on Earth. I just need to create a rough/simple square from a Lat/Long (GPS coordinate). - Then finally, I will either do this in a spatial query in a DB (for example, RavenDb, SqlServer, PostGIS, etc) or more likely, in .NET C#. So I was hoping to see if there was a common algorithm before I checked if this has been coded up in some coding language.

• Please Edit the question to clarify what environment you intend to use for this, what GIS tools you have available, and to explain what you have tried. This is a variant of the Forward Problem of geodesy , for which fast or accurate solutions are available (but not both) Jun 1, 2020 at 14:26
• Updated O.P. with new edits Jun 1, 2020 at 22:29
• There is not enough information. Do you want to go 5000m, on what surface? Can I imagine on a sphere but perhaps on an ellipsoid, also on the WGS84 ellipsoid? And in which direction? The shortest distance doesn't have a constant azimuth, so can I imagine starting with an azimuth of 135 degrees? Do you want to calculate the point on the WGS84 ellipsoid, starting with an azimuth of 135 degrees, 5000m away from a starting point? Do you want to write the code for it or can we recommend a pre-written code for that? Jun 4, 2020 at 3:41
• @GabrielDeLuca updated OP. I hope the edits give some more accurate info to help get an answer. Jun 4, 2020 at 9:11
• @Pure.Krome, the Earth surface is not a plane and a Lat/Long pairs bounding box is not a rough/simple square. In a rough/single square you can say that the angle of the diagonal is always 45 degrees and that all sides of the square has the same length, but in a curved surface bounding box that is not neccesarily true. Also, the Earth is not a mathematical surface, so we need to know to what mathematical surface do you want to reduce the Earth surface. In any case, the solution is not a conversion from 5000m to other unit of measure and you need to solve de direct problem of geodesy. Jun 4, 2020 at 10:32

Depending on the tolerance accepted in your work, you have several ways to solve your problem. Starting from the simplest and most imprecise to the most complex and precise.

But let's start with the first one, then you will see if the imprecision of the solution does not satisfy the work tolerance.

Let's think that the Earth is flat at 5000m around a point. If we want to draw a square, it would have 3535.53m on each side.

So it would suffice to find the meridian at that distance to the east and the parallel at that distance to the south, from the point of origin.

Now suppose that the Earth is a sphere of radius R.

If phi_1 is the latitude and lambda_1 is the longitude of the origin point, then the longitude of the destination point is:

`lambda_2 = lambda_1 + R * cos(phi_1) * 2 * PI / 3535.53m`

(where R * cos(phi_1) is the radius of the parallel of latitude phi_1).

And the latitude of the destination point is:

`phi_2 = phi_1 - R * 2 * PI / 3535.53m`

(not true near the South Pole).

That is all. The simplest and most imprecise way to get the longitude and latitude of the second point for the bounding box that you are trying to calculate.

The north side of the bounding box will measure 3535.53m meters over a sphere of radius R. The south side probably not. Both east and west sides will measure the same distance over the same sphere.

The shortest distance between the first and the second point will not measure exactly 5000m, because the Earth is not flat 5000m around a point, and the difference will depend of the radius R in the sphere and also of the location if you will compare it with an ellipsoid.

But it is simple, and an acceptable way to start thinking about geographic coordinates.

• Hi again @gabrieldeluca ! Wow - that's a very helpful answer. Simple is totally ok also. I'm not doing some military software with pin point precision. It's just a quick and rough bounding box ... so if it's out by 100m meters, that's kewl. but if it's out by 10km, that's a bit too simplistic then. And yeah, Jun 5, 2020 at 1:51
• Also,I totally get that the sphere of the Earth changes things. I've been doing geospatial db queries for a good decade+ and MS-SQL has geography and geometry. Geography is so the calcs take the earth's sphere into math-calcs. I'll try giving this a go and seeing what it looks like on a google map with some calculated bounding boxes based on the math above. Using DB's hides away the math and it's all magical :) Watch this space! Jun 5, 2020 at 1:51
• Oh - one more question/comment @gabrielDeLuca - does the above formula have a common geospatial name? Like this is the "DeLuca Mapping Formula / Haversine Function / etc" which is well known so I can just read up about it / reference stuff about it? Jun 5, 2020 at 5:54
• Hi @Pure.Krome, we are using the formulas for the length of arcs of parallel and meridian over a sphere. The radius can be calculated as a function of the latitude to get a more precise value, but the main source of imprecision is the first reduction to a plane to get the length of the north and west sides of the bounding box, I think that for 5km will be ok. Jun 5, 2020 at 11:20