• Stars
    star
    334
  • Rank 121,841 (Top 3 %)
  • Language
    Jupyter Notebook
  • License
    Other
  • Created almost 10 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Notebooks and libraries for spatial/geo Python explorations

Geocomputation, Cartography, and Spatial Analysis Techniques Using Python

Tweetcity

This is a repository of various geo/spatial analysis techniques using Python libraries, chiefly Numpy, Pandas, Shapely, Fiona, Descartes, Matplotlib, and Matplotlib-Basemap.

These tutorials, visualisations, and libraries are an occasional side effect of being embroiled in a PhD at the Bartlett Centre for Advanced Spatial Analysis, at UCL, and teaching on the undergraduate Data Science and Visualisation course.

CASA

The Notebooks

Hovertube.
Process TfL tube and rail data, and display it using Mapbox GL JS

Inset.
TfL bike rental travel time isochrone calculation

Airbnb

Airbnb: mapping Airbnb rental data in London

Boroughs

GWR: An introduction to Geographically Weighted Regression using PySAL, using a worked example.

Convert: demonstrates point, choropleth, and hexbin mapping techniques using pandas and Matplotlib Basemap

Convert_Folium: demonstrates the use of the Folium library for creating web-based maps from Python data (pandas) using Leaflet to generate a choropleth map

Router Comparison: analyses route characteristics of journeys from the London Cycle Hire network centroid to 554 stations, calculated using OSRM, Mapzen's new Valhalla router, and the Google Maps Directions API. There's also some outlier identification using RANSAC, and hopefully useful wrappers for route retrieval in helpers.py.

Routers

WLS: demonstrates the use of weighted least-squares estimation of similarity and affine transforms to calculate parameters for a transformation matrix which can be used to transform and align coordinates. This approach is useful for e.g. georeferencing raster data, and map feature alignment and correction.

weighted

Contour: demonstrates interpolation of irregularly-spaced point data (mean rainfall) into a regular grid, calculating a contour plot, and imposing it onto a basemap (see graphic below). Two approaches for calculating continuous surfaces are then compared – Delaunay Natural Neighbour (matplotlib.griddata), and refinement of a coarse Delaunay mesh using matplotlib.UniformTriRefiner, which uses recursive subdivision and cubic interpolation. High-res images are available in the data folder, all beginning with rainfall_.
Finally, the map is partitioned into clipped Voronoi cells based on the sensor locations, and some plotting methods (more flexible than scipy.spatial.voronoi2d) are shown.

Make it rain

Cellular

Bikepath: takes a subset of London bicycle hire stations, creates a DataFrame of all possible origin and destination pairs, and then uses MapZen's wonderful open Valhalla endpoint to get valid bicycle routes between them. These routes are then plotted (it's just the first 400 – there are over 490k origin / destination pairs in total) on a map.

Bikepath

Isochrone: an isochrone is computed for the complete London bike network from an origin at its centroid. Given a network of stations, Single-Source Shortest Path Length, weighted by the travel time between the origin and destinations can be used to generate travel times – though this isn't necessary for a single origin.

Isochrone

Plaques_Geopandas: demonstrates Geopandas and its spatial join functionality, used to create a choropleth.

Choropleth

Libraries

Circles
Demonstrates drawing circles with correct distortion characteristics on a map (the dot-shaded circle is erroneously non-distorted). The helper library used to plot the circles is available here.

Lonlat-BNG
A demonstration of writing a Rust library, and linking it to Python using FFI, in order to carry out fast Longitude and Latitude to British National Grid transformations, using multithreading. I've blogged about the process here. The Python library is available here.

Pypolyline
A Python library for encoding and decoding Google encoded polylines, using a Rust binary and FFI.

RDP
A Rust implementation of the Ramer–Douglas–Peucker line simplification algorithm. Includes an FFI wrapper.

Polylabel-rs
A Rust implementation of the Mapbox Polylabel algorithm, which determines optimum label placement on a polygon by calculating its pole of inaccessibility. The library has an FFI wrapper, and a sample Python script which demonstrates its use (I know Shapely also includes the algorithm, but it's a pure-Python implementation, and this one is…somewhat faster)

Circles


Installation and usage

Note that for most users, the Enthought Canopy Python distribution is probably the best way to get the required libraries (You'll have to install Folium and GeoPandas separately – they aren't included). However, feel free to install the libraries manually using requirements.txt if you know what you're doing, in which case you'll also need various compilers (GCC, Fortran), and libraries (GDAL, GEOS). The use of a virtualenv is advised.
The Rust libraries (though not their Python counterparts) require a Rust installation. For most platforms (OS X, Windows, *nix), using rustup.rs is the easiest way to install and update a Rust installation.

License

© Stephan Hügel 2017

Unless otherwise specified, the wards.geojson file and any UK shapefiles are provided under Crown Copyright, and their use must be acknowledged in any output by reproducing the following notice:

Contains Ordnance Survey data © Crown copyright and database right 2015

Unless otherwise specified, all other files are provided under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International license.

CC BY-NC-SA 4.0

More Repositories

1

pyzotero

Pyzotero: a Python client for the Zotero API
Python
749
star
2

simplification

Very fast Python line simplification using either the RDP or Visvalingam-Whyatt algorithm implemented in Rust
Python
152
star
3

CityEngine-Twitter

Visualise Twitter activity using a procedurally-generated 3D city model
Python
71
star
4

polylabel-rs

A Rust implementation of the Polylabel algorithm, with FFI.
Rust
48
star
5

convertbng

Fast, accurate WGS84 ⬅️➡️ OSGB36 (OSTN15) conversion, using Python and Rust
Python
37
star
6

pypolyline

Fast Google Polyline encoding and decoding using a Rust binary
Python
36
star
7

lonlat_bng

A multithreaded Rust library with FFI for converting WGS84 longitude and latitude coordinates into BNG (OSGB36) Eastings and Northings and vice versa (using OSTN15)
Rust
25
star
8

rdp

A library providing FFI access to fast Ramer–Douglas–Peucker and Visvalingam-Whyatt line simplification algorithms
Rust
20
star
9

router_comparison

Comparative explorations of the Bicycle journey characteristics calculated by the OSRM, Valhalla, and Google Maps routing engines
Python
16
star
10

geojson_example

Minimal examples of GeoJSON parsing using Rust
Rust
14
star
11

lovecraft

A basic NLTK demo, using the collected works of H. P. Lovecraft as a corpus
Jupyter Notebook
13
star
12

polylabel_cmd

A command-line utility for generating optimum polygon label coordinates from GeoJSON
Rust
12
star
13

hexagrams

Procedural generation of I Ching hexagrams and trigrams using PIL and NumPy
Python
10
star
14

linalg

Least-squares estimation (regression analysis) using Python (statsmodels and Pandas)
Jupyter Notebook
7
star
15

rust_anybar

A command-line Anybar client written in Rust
Rust
7
star
16

geojson_d3

Make RFC 7946 GeoJSON (Multi)Polygons d3-geo-compatible, or vice versa
Rust
6
star
17

hexcover

Hexcover: tile an area with regular flat-topped hexagons
Python
6
star
18

cocktails

🍹Branch and bound solution using Rust to calculate an optimal cocktail ingredient list of arbitrary length 🍸
Rust
6
star
19

WIREs

Scientometric Analysis for a literature review article --->
Jupyter Notebook
5
star
20

Circles

Draw geodesic circles exhibiting projection distortion using Basemap
Python
5
star
21

Plowman

A Python script which tweets epic poetry from plain text files
Python
5
star
22

ckmeans

Optimal univariate k-means clustering using dynamic programming
Rust
4
star
23

project-euler

Project Euler solutions
Python
4
star
24

Twitrends

Output top ten trending twitter topics to Growl, based on WOEID
Python
4
star
25

tweetstodb

Example script to log tweets from a set of Twitter users to a Postgres DB
Python
4
star
26

minimal_cross_manylinux

Example of a minimal CI setup using Cross to build a manylinux2010-compatible Rust binary
Rust
4
star
27

hovertube

TfL's rail lines, hovering, ghost-like in the sky above the city 👻
Jupyter Notebook
3
star
28

cleantwitter

Safari 5, Firefox 3, and Google Chrome 5 extensions which remove annoying ‘social’ features such as ‘Who to follow’ and ‘Trending’ topics from twitter.com
JavaScript
3
star
29

CDP

British Museum CDPP
Python
3
star
30

HH-Expunge

A Safari extension that allows users to be selectively ignored
JavaScript
3
star
31

edit_my_tilde

Send pull requests with content for my tilde.club page:
JavaScript
3
star
32

ostn15_phf

A Rust crate providing Ordnance Survey OSTN15 adjustments for ETRS89 coordinates
Rust
3
star
33

greggs

Greggs and Pret Heat Map
JavaScript
2
star
34

rustfest

My Rustfest 2016 slides
2
star
35

tweetmute

Twitter keyword mute regexes
2
star
36

mefignore

A Safari extension for ignoring MetaFilter users
JavaScript
1
star
37

rust_fizzbuzz

Implementing FizzBuzz using Rust 1.0
Rust
1
star
38

irishsecondaryschools

Irish Secondary Schools spatial- and metadata, 2022
1
star
39

urschrei

1
star
40

robust-wasm

WASM port of the robust crate
Rust
1
star
41

polyline-ffi

FFI Bindings for the rust-polyline crate
Rust
1
star
42

patterns

An example showing efficient matching of arbitrary ASCII string patterns in Rust
Rust
1
star