This shows you the differences between the selected revision and the current version of the page.
| — | rawgps:mapping 2009/03/20 09:49 current | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Map Co-ordinates ====== | ||
| + | |||
| + | This is a demonstration program to convert GPS degrees to pixel positions on a map. It is currently in AWK. The most efficient way to convert to a map which uses UTM or a co-ordinate system which is not GPS is to rescale the map image itself. | ||
| + | |||
| + | <code> | ||
| + | # Use co-ordinates from the Bottom Left and Top Right of the map: | ||
| + | # | ||
| + | # +--------+ Lat 51.453, Lon -2.592 | ||
| + | # | | (120, -159) | ||
| + | # | | | ||
| + | # | | | ||
| + | # | | | ||
| + | # Lat 51.448, Lon -2.602 | | | ||
| + | # (-119, 160) +--------+ | ||
| + | |||
| + | # Define the constants once at the start | ||
| + | BEGIN { | ||
| + | |||
| + | # Flash screen in pixels (240 x 320) | ||
| + | BottomLeftX = -119 | ||
| + | BottomLeftY = 160 | ||
| + | TopRightX = 120 | ||
| + | TopRightY = -159 | ||
| + | |||
| + | # Map in Lat, Lon | ||
| + | BottomLeftLat = 51.448 | ||
| + | BottomLeftLon = -2.602 | ||
| + | TopRightLat = 51.453 | ||
| + | TopRightLon = -2.592 | ||
| + | |||
| + | # Use these in the calculation | ||
| + | ScaleX = (TopRightX - BottomLeftX) / (TopRightLon - BottomLeftLon) | ||
| + | ScaleY = (TopRightY - BottomLeftY) / (TopRightLat - BottomLeftLat) | ||
| + | } | ||
| + | # End constant initialisation | ||
| + | |||
| + | # Given Lon and Lat we can calculate X and Y | ||
| + | { | ||
| + | Lat = $1; Lon = $2; | ||
| + | X = (Lon - BottomLeftLon) * ScaleX + BottomLeftX | ||
| + | Y = (Lat - BottomLeftLat) * ScaleY + BottomLeftY | ||
| + | print X,Y; | ||
| + | } | ||
| + | </code> | ||