The following line of code prints out the type of the first element of a list from a shapefile:
Running the script in Python 2 results in:
type(sr.shape): <type 'instance'>
which is not very informative. Python 3 does much better:
type(sr): <class 'shapefile._ShapeRecord'>
Anyway, since my final project is due tomorrow, I had to cut the investigation into using pyshp short, but I'll be sure to continue looking into it soon.
My goal was to represent Columbia Pike in bright yellow or orange on my map. Columbia Pike is the road on which the proposed streetcar that had such a profound impact on the Vihstadt / Howze election ran. I thought adding it to the map would provide visual interest. It also gave me a chance to explore adding more than one layer to a map.
I wrote several scripts to make maps as part of investigating this.
- Renders all 883 shapes from the Roads shapefile in a map.
- Renders a single shape from the Roads shapefile as a new layer on the precincts map.
- I used trial and error (and a bit of divide and conquer) to find shapes among the 883 that represented roads on and near Columbia Pike.
- Finally, I added this roads layer to the election results map I made yesterday.
QGIS, but I googled how to load a shapefile as a vector layer to see how it would compare:
I assumed that each of the 883 shapes in the Roads shapefile represented a single road. I was disappointed that the metadata didn't include names associated with each of the shapes, but I figured I could use a kind of binary search to print out half of them, render the map, and see which half Columbia Pike was in, cut that in half, and so forth, until I found Columbia Pike. Soon I'll be able to read geospatial coordinates from the shapes and write a script that selects the shapes I want, but for now I figured this approach would be the quickest way to get to my goal.
It turns out that the reason there are no road names associated with the shapes is that each shape represents a cluster of connected road segments rather then a single road. a_road_shape.py illustrates this:
roads_near_columbia_pike.py to render them:
election_map_with_roads_near_cp.py to produce:
Where I'll Go From HereOpenStreetMap is an incredible resource for open source mapping projects, and yesterday I did a quick search to see if it might provide me with a solution to my rendering Columbia Pike project. I found out that OSM stores streets as a collections of ordered nodes called ways. This way holds a piece of Columbia Pike near where I live:
Here are the things I think I should investigate next:
pyproj module will be the tool to use to convert among different geospatial data formats.