9

This is somewhat related to another question I asked: Translate GPS coordinates to location on PDF Map. That got me to this point, now I'm stuck on the math.

Let's say I have a floor plan of a building, I've taken gps coordinate readings from each corner of the building. Also assume that the floor plan is lined up with the latitude and longitude.

How do I convert a GPS coordinate to a X,Y position on this map? I can't seem to get the math right.

alt text

Community
  • 1
  • 1
christo16
  • 4,843
  • 5
  • 42
  • 53

2 Answers2

11

Let delta_long and delta_lat be the differences, in degrees, in the GPS coordinates of the building's corners. Let delta_x = 320 and delta_y = 480 (feet, let's say). Then:

vertical_scale = delta_y/delta_lat with units feet/degree latitude

horizontal_scale = delta_x/(cos(latitude)*delta_long) with units feet/degree longitude.

The cos(latitude) factor compensates for the varying length of 1 degree of longitude as one moves from the equator to the poles. We can assume for this application that it won't change appreciably between the north and south ends of the building.

Then for any nearby (lat,long) point, subtract off the coordinates of the southwest corner of the building, and apply the vertical and horizontal scales in the obvious way to locate that point with respect to the building layout.

Jim Lewis
  • 43,505
  • 7
  • 82
  • 96
  • Thanks for the great answer. I forgot to mention, the iPhone coordinate's plane is reversed, so that (0,0) is in the top left corner of the sample image. How does this affect the calculations? – christo16 Aug 30 '10 at 18:10
  • It should be mentioned that this is the "Equirectangular projection" http://en.wikipedia.org/wiki/Equirectangular_projection – INS Mar 24 '11 at 07:15
  • So Jim, you are saying that `x = ( lon_origin - lon ) * horizontal_scale` and `y = ( lat_origin - lat ) * vertical_scale`, where lat_origin,lon_origin are gps coords of the southwest corner. Right? – Marco Panichi Sep 06 '17 at 12:54
  • @Marco: I'd use `(lon - lon_origin)` and `(lat - lat_origin)` to make the signs come out right, but that's the idea, yes. – Jim Lewis Sep 06 '17 at 16:58
  • I'm little confused. (lon - lon_origin) is delta_long. isn't it? Can you kindly edit your answer in order to explicit formulas that brings to x and y? – Marco Panichi Sep 07 '17 at 06:11
0

What you need to do is calculate the ECEF coordinates of the lat/long point:

Latitude and Longitude, GPS Conversion

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
ennuikiller
  • 46,381
  • 14
  • 112
  • 137
  • The building layout does not represent an earth-centered coordinate system, so this is quite different from what christo16 is looking for (which is closer to a topocentric than a geocentric position). – Jim Lewis Aug 27 '10 at 23:25