Jan. 7, 2011, 8:59 a.m.
posted by lambda
Map Your Meatspace
A bird's-eye view of the world on your Linux desktop.
When Global Positioning System (GPS) technology was launched, it was heralded as the next big thing. Although its usefulness has not been quite as explosive in the consumer market as many people predicted it would be, GPS has proved useful in areas, such as satellite navigation systems and mapping tools. Although many people think only ramblers and walkers use GPS, the technology actually is useful in numerous applications, many of which you can perform from your Linux desktop. This hack shows you how you can hook up a GPS unit to your Linux desktop and use some open source tools to help map out your area.
Connect the GPS to Linux
A number of GPS units are compatible with Linux, and all of them come with either serial or USB connections. Although two types of connections are available, the USB connector simply uses a special chip called the FTDI chip to convert a legacy serial connector to a USB connector. This chip requires a special driver to convert from a USB to a serial port. A Linux driver has been developed for this and it is available at http://ftdi-usb-sio.sourceforge.net/.
Each connector is compatible with Linux, and most of the USB GPS units include the FTDI driver in the kernel. If you are using one of these USB devices, you need to ensure that you have USB drivers compiled into the kernel. You should ensure you have the UHCI, UHCI Alternate Driver, or OHCI options from the USB Support page in the kernel configuration tool. Which option you choose depends on your motherboard; consult your motherboard's manual for information on this.
When you have installed the USB or serial drivers and you have plugged in the device, the GPS unit should be available on the system in /dev/ttyS[n] for a serial GPS or /dev/ttyUSB[n] for the USB equivalent. Now you can look in /dev to see the name of the port from which you can access the GPS:
[email protected]:~$ ls -al /dev/ttyS*
Or, if you have a USB device:
[email protected]:~$ ls -al /dev/ttyUSB*
At this point your GPS is recognized by the system, and you can configure your GPS applications to look at this port for your GPS unit. If you are thinking of purchasing a GPS unit, it is recommended that you get one with full NMEA compatibility. This will ensure that the unit will work with most of the common GPS software tools.
Use Mapping Software
You probably want to use GPS so that you can view a map of your area as you travel through it. Some GPSes display a general map with streets and street names, and other maps go one step further to provide instructions on where to go (such as "at the end of the road, turn left" instructions). The former system uses general mapping information and the latter is a vector-based satellite navigation system.
For general mapping information, a useful tool is GpsDrive (http://gpsdrive.kraftvoll.at/). You can use this application to indicate your current location, to plot waypoints (locations in latitude and longitude), and to interact with other GPS users over a wireless network.
Although GpsDrive is a useful tool, one of its problems is that free maps of Europe and many other parts of the world are not available for use with it. The lack of free maps is a big problem with GPS software in general. GpsDrive does spider some online mapping web sites to download maps for the areas you are in, but that is useful only when a map is available, and only if you have wireless connectivity when you enter a new area. To solve this problem, you need to use a script that can download maps of entire areas in advance of your visit (this script is covered later in this hack).
Another option, particularly if you just want to see where your location is in the world, is to use the free NASA maps to plot your position inside GpsDrive. Before you do this, you should ensure you have at least 3GB of disk space available, as the NASA maps are huge. You need to download two maps from ftp://mitch.gsfc.nasa.gov/pub/stockli/bluemarble/ called MOD09A1.W.interpol.cyl.retouched.topo.3x21600x21600.gz and MOD09A1.E.interpol.cyl.retouched.topo.3x21600x21600.gz. When you have downloaded the files, create a nasamaps directory inside your ~/.gpsdrive configuration folder:
[email protected]:~$ mkdir ~/.gpsdrive/nasamaps
Now copy the files into this directory, and rename them to top_nasamap_east.raw and top_nasamap_west.raw, respectively:
[email protected]:~$ mv MOD09A1.E* top_nasamap_east.raw [email protected]:~$ mv MOD09A1.W* top_nasamap_west.raw
Now when you run GpsDrive, the smaller maps for the different parts of the world will be created on-the-fly from these larger maps. To see these maps, you need to select "Topo map" in the "Show map type" field.
Spidering Mapping Information
Although GpsDrive allows you to download maps displaying the area you are in, it is likely that you will want to download a number of maps displaying different parts of your area or country. You can do this with a small shell script called gpsfetchmap.pl, which is included with GpsDrive. You can use this script to spider a number of maps between two sets of longitude and latitude points and download all the content for use with GpsDrive. All these maps will be downloaded from the Expedia Germany web site (http://www.expedia.de/).
To use the script, you need to pass it the latitude and longitude of the top left corner and bottom right corner of the region you want maps for. The top left corner is referred to as the starting latitude/longitude, and the bottom right corner is the ending latitude/longitude. You should also pass the script the scale of the map. For street-level detail, a scale of 1500 is recommended. Here is an example of the command in use:
[email protected]:~$ gpsfetchmap107.pl --start-lat 52.2401 --end-lat 52.3096 --start-lon 13.2265 --end-lon 13.3203 -sc 1500 -a 4 -p