I haven’t blogged in a while. But I haven’t been idle at all.
Part 1) A month ago, I was working on a project where I had to collect GPS coordinates of a 25-acre piece of land. Real survey information was not needed but I had to show the outline of my project site on a variety of maps. I thought to myself – “Wouldn’t it be nice to be able to take the laptop running ArcGIS to the field, hook it up to my handheld GPS, and plot your GPS location in realtime?” – So what were my options ?
1) Google Earth offers such capability using a very straightforward process, especially if you’re using a Garmin GPS. With a few clicks you’ll be op and running. Directions are here. Unfortunately, this only works well while you’re connected to the web, and my laptop has no wireless service to allow it to work in the middle of nowhere.
2) Since most of my GIS work has been with ESRI (I’ve had my share of annoying freezes and crashes lately!), I was hoping for an ArcMap solution. In fact, there is a .NET project by Edan Cain for ArcGIS Explorer. I spent some time installing & uninstalling Explorer and subsequently the entire ESRI suite, only to run into the same non-descript error when I tried to run the script. I had similar bad luck with another similar tool for ArcMap.
3) GPS Trackmaker (it’s free!) worked well when it comes to displaying your current position as provided by the GPS. But getting it to accept my existing shapefiles as basemaps was too much of a headache to warrant further efforts. If you know the secret of how to get this to work, please let me know.
Part 2) – By now, I was frustrated enough with the “big packages”. Why not try to coomunicated with the GPS using Python, and then be able to work with the data, if not in realtime, at least at your discretion. Surely, this would just be a matter of locating a few modules and writing a few lines of code. In fact, there are plenty of examples on the web, and I also found one in Mapping Hacks on my shelf.
When downloading waypoints to Garmin’s Mapsource software or third-party utilities, I’ve always used the USB cable. But for use in Python, I quickly found people were saying reading from USB was a lot more complicated than from the serial port. There is a USB module – pyusb. But I had no luck with it. Most people seemed to be having success with serial.py, a Python extension for the PC’s serial port. So I ordered a serial cable which hadn’t originally been included with my GPS. When
However, something as simple as:
>>> import serial
>>> ser = serial.Serial(0) #open connectionto COM1
didn’t work. When I checked what I had actually installed, I found there was no serial modules but one called serialwin32 in a folder serial. Using the following worked.
from serial import serialwin32
Then I tried:
s = ser.readline()
and nothing happened. I am not sure I have ever used my serial port before. My PC is only 2 years old. So I had to make sure I knew which port was COM1. I finally had to check BIOS settings to make sure they were ok.
I abandoned my work using serial.py, and looked at gpsd, a Linux daemon that can be run with cygwin under Windows. I installed this version and Cygwin, and tried to use the Python wrapper (gps.py) that comes with it, but soon got bogged down in strange errors and missing modules.
I had similar problems using Pygarmin, which sounded like a dream come true. It was designed for use with Garmin GPS technology and included a set of classes for the NMEA specificiation. But it appears this module has not seen any development in some time, and it didn’t work for me. Same with pygps. I spent time installing and got sidetracked searching for missing modules related to GTK. My last ditch effort was to use a Python wrapper for GPSBabel. But no luck here either.
Instead, I tried the initial serial.py script one more time, and then decided to see if I could check on the status of COM1 while the GPS was plugged in. A handy toll for that is Comtest. While the script did nothing, Comtest showed me some output that looked like this:
That’s YYMMDDGMT ! Somebody was talking to COM1 !!
Then, it occurred to me that I should replace ser.readline() with ser.read(). And wham-bam, I was in business.
from serial import serialwin32
ser = serialwin32.Serial(0)
s = ser.read(1000)
The GPS was set for TEXT output mode at 9600 baud, and I was getting strings of text like this line:
Date Time Latitude Longitude Gobbledeegook
Granted, I spent a lot of time to get something this simple to work. Some of it because I didn’t know much about serial ports, some of it because I got sidetracked trying out different scenarios. But I learned a lot more than what was needed to get a solution, and I have made a long list of things. This is what I love about teaching myself programming skills. You started at A, wanting to go to B, and you get there via Z. Needless to say, I need to spend some more time trying to get pygarmin.py and nmea.py to work.