16kB Blog

15 March 2010

I have been working on a few activity ideas that could be used in high school computer science classes.

This activity involves mapping out a city block or very large school yard by taking readings with a GPS device. I used my iPhone and took photos which then had GPS data in the EXIF tags. I then had to write the code to extract the GPS data from EXIF tag and build a map using Processing.

Processing and Python

In order to get this done quickly I thought I'd try out PyProcessing. I work more quickly in Python then in Processing (partly because I am still not as familiar with Processing) but I also wanted to see what PyProcessing is like. So far I really like it! Real Python - and very similar to Processing. I will still take a stab at coding some of this in Processing to just get a feel for the differences. I still really believe in the role of Python for teaching - the interpreter and the ease of dealing with data just feel so much more immediate and simple.

Test Run

Rough Output

In order to test this idea I did a walk about of my neighborhood taking pictures at the various street intersections. I also sketched a rough map and made notes where I took the photos so that I can easily associate which intersections are which.

I have written a few quick scripts in Python to extract the data and draw a quick map using PyProcessing.

I spent about 1/2 hour doing the walk around and a few hours playing around with the code and different ideas. I have a map but it certainly has some errors in it. I got stuck for a little while just extracting and converting the GPS data. At the very least I would have directions about how they would go about some of that. And I would likely simply give them the code that gets the EXIF data (using PIL which I just found on Stack Overflow - eventually!)

Variations

This activity could be very simple by simply copying out the GPS data by hand into a spreadsheet and then plotting the points in Processing. Of course the latitude and longitude coordinates would need to be re-mapped onto the Processing coordinates. The rest of the details could be added in a drawing program.

A more complex map could be created by using these nodes and then drawing in the streets programmatically. Or additional features could be positioned and drawn in using Processing. In addition to this the images themselves could placed onto the map much like many of the online maps.

GPS Data Is A Bit Weird Looking

I found the data in the iPhone created tags to be a bit strange - instead of listing degrees, minutes and seconds the tags looked like this (as a Python dictionary):

'GPSInfo': {1: 'N', 2: ((43, 1), (2579, 100), (0, 1)), 
  3: 'W', 4: ((79, 1), (3248, 100), (0, 1)), 
  5: 0, 6: (62, 1)},

The 43 is in fact the latitude but 2579 are minutes times 100 for some reason. Perhaps this is a standard format of some kind - I am not that familiar with GPS. But it was easy enough to handle by dividing by 100 and then by 60 and adding to the degrees (I am in the Toronto so the 43 remains a positive number - but my code checks for the "N" or "S"). Whether or not your students would have to work through this could be a choice based on how advanced the class is or how comfortable they are at looking at data and making calculations. It might be a good one to solve for them with simple module if it proves to be a stopping point early in the activity.

Re-mapping the data is a fairly straightforward task in Processing if you have access to the map function. But PyProcessing doesn't have this so having the students re-create a function like Processing's map could be a useful warmup exercise to this activity.

More Accuracy Needed

The GPS info from my phone seems to be detailed to only a 1/5 of a second. A quick calculation gives me about ~5m from that (at least in latitude). But I am not sure what the accuracy of those numbers really are. It seems mapping a city block isn't very feasible with my phone - it just looks very strange due to so much error. I think a dedicated GPS device would do a much better job - I will have to look into this next.

Related tags: GPS, iPhone, Processing, PyProcessing, Python

Latest Posts:

Categories: