A programming language that's been around since 1991
Designed to be simple, beautiful, and accessible
Free and open source
Easy to read, easy to use: readability is a core philosophy
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!";
return 0;
}
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
print("Hello, World!")
Some languages use tokens like { } to create logical separations
in the code...
Python just uses whitespace.
# Do this
if good_whitespace is True:
print("Everything is awesome!")
# Don't do this
if good_whitespace is False:
print("This is broken")
What to remember: consistency is important!
A "tab" is not the same as "four spaces"
Python code is saved to a text file with ".py" extension
Use the Python interpreter to run that code
What you need:
*e.g., Notepad++, gedit, TextMate, etc.
(That's it!)
print('Hello, world!')
Use Python from the command prompt to run your code:
> python hello.py
Hello, world!
Hands-on practice is the best way to make progress:
you can learn a lot from making mistakes.
Tip: Python's official documentation is surprisingly easy to read!
Everything that's not geared for online consumption
(desktop-oriented work)
Shapely: After creating or extracting useful data, use this Python library for more complex manipulation & analysis.
Combine Python tools like Fiona + Shapely to chain reading, converting, and analysing spatial data:
>>> with fiona.open('city_parks.shp', 'r') as collection:
>>> parks = [shapely.geometry.shape(c['geometry']) for c in collection]
>>> park = parks[0] # grab the first park out of the feature list
# ask Shapely what type of geometry this feature is
>>> park.type
'Polygon'
>>> park.area
20868.47980
>>> park.buffer(10.0).area
26877.85083
>>> (park.centroid.x, park.centroid.y)
(3100374.119480808, 10106879.690095564)
use Fiona to open a shapefile of Austin city parks in Python,
Getting spatial data online, making it mobile, or
putting it in the "cloud"
Folium: Python library that wraps wraps Leaflet.js
so you can use Python to generate web maps.
"Manipulate your data in Python, then visualize it
on a Leaflet map via Folium."
Web apps are interactive: taking input, storing data, producing output
Geodjango: create web apps that incorporate spatial data
GeoDjango lets you use a spatial database (e.g., PostGIS) to power a spatial-ized app: run spatial queries, return geometries, build maps
Easy ways to start using Python as a GIS person
Use Python to generate calculated field values:
Do it in QGIS with the FieldPyculator plugin
Humans make mistakes: use Python to make QA/QC tools
Let Python do repetitive tasks for you.
Life is too short to manually reproject 50 shapefiles,
then convert them all to GeoJSON...
Python makes a lot of things a lot easier
You don't have to be a programmer to take advantage
Easy to get started, endless possibilities!