GPS coordinates: 1km square around a point
Asked Answered
A

4

20

I was hoping someone out there could provide me with an equation to calculate a 1km square (X from a.aaa to b.bbb, Y from c.ccc to c.ccc) around a given point, say lat = 53.38292839 and lon = -6.1843984? I'll also need 2km, 5km and 10km squares around a point.

I've tried googling around to no avail... It's late at night and was hoping someone might have quick fix handy before I delve into the trigonometry...

I'll be running all this in Javascript, although any language is fine.

Aggression answered 22/10, 2010 at 20:53 Comment(5)
You realize that they won't be "square" in most senses of the word, especially if your points are near the poles?Dwyer
Do you need squares, or will radius do the trick?Finch
@Paul Tomblin Yes, you're right about the "square". For all intents and purposes, the kind of simple square I'm talking about is square enough for me!Aggression
@mna, I need a range to do a search in a database. Hence the square. I don't know how I could search for a circle in a linear database.Aggression
look at this answer https://mcmap.net/q/234339/-sqlite-getting-nearest-locations-with-latitude-and-longitudeMelcher
T
44

If the world were a perfect sphere, according to basic trigonometry...

Degrees of latitude have the same linear distance anywhere in the world, because all lines of latitude are the same size. So 1 degree of latitude is equal to 1/360th of the circumference of the Earth, which is 1/360th of 40,075 km.

The length of a lines of longitude depends on the latitude. The line of longitude at latitude l will be cos(l)*40,075 km. One degree of longitude will be 1/360th of that.

So you can work backwards from that. Assuming you want something very close to one square kilometre, you'll want 1 * (360/40075) = 0.008983 degrees of latitude.

At your example latitude of 53.38292839, the line of longitude will be cos(53.38292839)*40075 = [approx] 23903.297 km long. So 1 km is 1 * (360/23903.297) = 0.015060 degrees.

In reality the Earth isn't a perfect sphere, it's fatter at the equator. And the above gives a really good answer for most of the useful area of the world, but is prone to go a little odd near the poles (where rectangles in long/lat stop looking anything like rectangles on the globe). If you were on the equator, for example, the hypothetical line of longitude is 0 km long. So how you'd deal with a need to count degrees on that will depend on why you want the numbers.

Tallu answered 22/10, 2010 at 21:8 Comment(2)
Ok. Jim's 1 mile = 0.014472 degrees of latitude (or equivalently .008983 in km) seems just about right. Many thanks.Aggression
Note: While calculating cos(lat), be sure to convert lat to radians as almost all programming languages use radians in their Cos/Sin trig methods.Husein
A
4

Here is something from my notes to be used on Android with its decimal GPS.

Lat Long: NY City 40N 47 73W 58 40.783333 73.966667

Wash DC 38N 53 77W 02 38.883333 77.033333

yields = 209 miles !! VERY CLOSE

Distance (miles) (x) = 69.1 (lat2-lat1) Distance(miles) (y) = 53.0 (long2 - long1) As crow flys sqrt (x2 + y2) ... duh!@

delta(LAT) / Mile = .014472 delta(LONG) / Mile = .018519

Using a box as approximation To find someone within 100 miles (100 north / 100 south, 100 E / 100 W) From 0,0 -14.472 / + 14.472 , -18.519 / 18.519

Afrikaner answered 22/10, 2010 at 20:56 Comment(5)
ok, so delta_lat is 0.014472 miles and delta_lon is 0.018519? Cool, I'll just convert that to km and I should be sorted. Many thanks for that. I though it was going to be much more complicated than that!Aggression
Distances in latitude and longitude don't obey Pythagoras because you're tracing across a curved surface, not a flat one. Look up the haversine formula to get the correct result — it's not pretty but you can immediately reproduce it in about five lines of code and then shuffle it off into a library somewhere.Tallu
I am aware of this, this works fairly well withing a 200 mile distance which is why I bookmarked it. It's quick on the server. If you want something more exact .... here ya go! meridianworlddata.com/Distance-Calculation.aspAfrikaner
REMEMBER if you are going to use squares to make your db queries manageable the diagonal from center on a square can be 50% greater than the radius...hummm what to do?Afrikaner
Yes, it's a square I'm looking for. Thanks for the response.Aggression
J
1

A simpler way of generating a gps square given the centre would be to use the indirect Vincenty algorithm.The Javascript code here shows how to do it http://www.movable-type.co.uk/scripts/latlong.html. Creating a square using a circle isn't to hard. Squares are equal distance to each point. So given a centre point, distance from the centre, change the bearing from 0 or any number depending on rotation of the square and increment by 90 degrees or PI/2 radians. By incrementing by 90 degrees each time and you will up with a square in circular space.

I use this myself for generating GPS points around a centre point with a given distance .---. --/- --0-- -/-- .---.

Jointer answered 12/1, 2015 at 13:35 Comment(0)
D
0

TL;DR

10 km = 0.08999 radius from a certain geopoint. This calculation is only based on latitude values and applies only to geopoints with WGS84 projection.

More details

If you want a more accurate answer you must have to calculate it by building a function of some sort. However it still don't guarantee because people even quarrel for the degrees of error. Taking altitude into account, mercator or not, etc.

Caution

The value above is just a rule of a thumb so don not use it for critical applications.

Reference

GIS StackExchange, How do I calculate the bounding box for given a distance and latitude/longitude, answer by David the Australian developer

Devy answered 2/8, 2019 at 7:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.