after this finishes loading, use the arrow keys to change slides or
view this presentation in markdown with notes here
Python + geographic data = BFFs
Mele Sax-Barnett

I <3 maps, but making them can be
a pain
the worst part is
getting data to cooperate
it is usually not in the format you need
has several obvious errors
is split up into 50
different files
is in a
different projection

than what you need

and has no metadata,
so you have no idea
what you're even looking at
you could point and click all day in
GIS software,
or you could use Python
about (vector) geodata:
Python packages:
convert and filter your data with Fiona
converting country shapefile data from Natural Earth to GeoJSON format
1. download some data
you can also
filter by bounding box
3. enjoy!
another Python package:
combine Fiona with PyProj to change the projection
2. enjoy!

one more
Fiona example:

assemble a folder of
GPX tracks into
a single GeoJSON file
1. export some data in GPX format
3. enjoy!

before we go any further,
let's talk about GeoJSON:

* JSON for geodata
* easy to use for web mapping
* easy to parse with Python
all you need to do is
treat it like a dictionary
OpenStreetMap data to map-ready GeoJSON
1. download some data
2. convert it to GeoJSON with
your tool of choice,
or you can parse the XML directly
3. process

4. enjoy!
or do this with CSV/XML data:
just put it in a dictionary and assemble valid GeoJSON with only the features and attributes that you want.
if you have a lot of data, switch to reading and writing line-by-line.
because it's just a dictionary, it's easy to create tests for the data:
this is important if your system expects
a very particular format,
while your data comes from a variety of sources
spatial analysis and
data manipulation
with Shapely

tons of examples in the manual:
validate and construct geometry, simplify, buffer, convex hull, envelope, offset, merge, union, interpolate, create polygons from lines, get centroid or representative point, bounds, area, or length, the distance between two objects, check if they are equal or almost equal, get the difference or symmetrical difference, see if one contains the other, if they intersect or touch, work with 3D data and Numpy, etc.
keep only
the GPX tracks
in Portland
1. get Portland or your city as GeoJSON

3. enjoy!
another option for geoprocessing without
GIS software: PostGIS

talk to it with Psycopg2 or your Python PostgreSQL tool of choice
finally, GIS software <3s Python

arcpy scripting and add-ins

console, module, plugins, and development

> 250 plugins
thank you!

questions? @pdxmele or file an issue here
more resources here