https://github.com/urschrei/geopython
Notebooks and libraries for spatial/geo Python explorations
https://github.com/urschrei/geopython
basemap choropleth computational-geometry geo geographical-information-system geographically-weighted-regression geopandas geospatial isochrones jupyter matplotlib pandas rust shapely spatial-analysis
Last synced: 5 months ago
JSON representation
Notebooks and libraries for spatial/geo Python explorations
- Host: GitHub
- URL: https://github.com/urschrei/geopython
- Owner: urschrei
- License: other
- Created: 2014-07-30T14:44:43.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2025-02-02T20:14:48.000Z (8 months ago)
- Last Synced: 2025-04-09T04:04:42.692Z (6 months ago)
- Topics: basemap, choropleth, computational-geometry, geo, geographical-information-system, geographically-weighted-regression, geopandas, geospatial, isochrones, jupyter, matplotlib, pandas, rust, shapely, spatial-analysis
- Language: Jupyter Notebook
- Homepage:
- Size: 78.4 MB
- Stars: 358
- Watchers: 28
- Forks: 67
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
## Geocomputation, Cartography, and Spatial Analysis Techniques Using Python
[](http://urschrei.github.io/CityEngine-Twitter/ "Tweet")
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](http://www.bartlett.ucl.ac.uk/casa), at [UCL](http://www.ucl.ac.uk), and teaching on the undergraduate [Data Science and Visualisation](http://www.ucl.ac.uk/basc/prospective/core/qm2/#tabs-2) course.
[](http://www.bartlett.ucl.ac.uk/casa/programmes/postgraduate "Bloomsbury is lovely, you know.")
### The Notebooks
[](https://github.com/urschrei/hovertube "Ghostly. vv ghostly").
Process TfL tube and rail data, and display it using Mapbox GL JS[](isochrone.ipynb "Yo Dawg").
TfL bike rental travel time isochrone calculation[](https://github.com/urschrei/Geopython/blob/master/airbnb.ipynb "All that is solid melts into air")
[Airbnb](https://github.com/urschrei/Geopython/blob/master/airbnb.ipynb): mapping Airbnb rental data in London
[](https://github.com/urschrei/Geopython/blob/master/airbnb.ipynb "Can I borough a feeling")
[GWR](https://github.com/urschrei/Geopython/blob/master/geographically_weighted_regression.ipynb): An introduction to Geographically Weighted Regression using PySAL, using a worked example.
[Convert](convert.ipynb): demonstrates point, choropleth, and hexbin mapping techniques using pandas and Matplotlib Basemap
[Convert_Folium](convert_folium.ipynb): demonstrates the use of the [Folium](https://github.com/wrobstory/folium) library for creating web-based maps from Python data (pandas) using [Leaflet](http://leafletjs.com) to generate a choropleth map
[Router Comparison](https://github.com/urschrei/router_comparison): analyses route characteristics of journeys from the London Cycle Hire network centroid to 554 stations, calculated using [OSRM](https://mapzen.com/blog/osrm-sunset), Mapzen's new [Valhalla](https://mapzen.com/projects/valhalla/) router, and the [Google Maps Directions API](https://developers.google.com/maps/documentation/directions/intro). There's also some outlier identification using RANSAC, and hopefully useful wrappers for route retrieval in `helpers.py`.
[](https://github.com/urschrei/router_comparison "IT'S CALLED VALHALLA. LIKE IN FURY ROAD. AAAAA. I LIVE. I DIE. I LIVE AGAIN!")
[WLS](https://github.com/urschrei/linalg/blob/master/notebooks/weighted_least_squares.ipynb): 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.
[](https://github.com/urschrei/linalg/blob/master/notebooks/weighted_least_squares.ipynb "Weighty")
[Contour](contour.ipynb): 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](data) folder, all beginning with `rainfall_`. :umbrella::umbrella::umbrella:
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.[](contour.ipynb "Anigifs are the future of spatial analysis")
[](https://raw.githubusercontent.com/urschrei/Geopython/master/data/voronoi.png "Tesselate Everything")
[Bikepath](bikepath.ipynb): 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](https://mapzen.com/projects/valhalla) 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.ipynb "Unpleasantly vascular, no?")
[Isochrone](http://nbviewer.ipython.org/github/urschrei/Geopython/blob/master/isochrone.ipynb): an [isochrone](http://en.wikipedia.org/wiki/Isochrone_map) is computed for the complete London bike network from an origin at its centroid. Given a network of stations, [Single-Source Shortest Path Length](https://networkx.github.io/documentation/latest/reference/algorithms.shortest_paths.html), 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.ipynb "The Burning Eye of Bike Hire")
[Plaques_Geopandas](plaques_geopandas.ipynb): demonstrates [Geopandas](http://geopandas.org) and its spatial join functionality, used to create a choropleth.
[](http://sensitivecities.com/so-youd-like-to-make-a-map-using-python-EN.html "Boropleth")
## Libraries
[Circles](circles.ipynb)
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](https://github.com/urschrei/Circles).[Lonlat-BNG](https://github.com/urschrei/lonlat_bng/blob/master/rust_BNG.ipynb)
A demonstration of writing a [Rust](http://www.rust-lang.org) 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](http://sensitivecities.com/rust-python-ffi-bng-EN.html). The Python library is available [here](https://github.com/urschrei/convertbng).[Pypolyline](https://github.com/urschrei/pypolyline)
A Python library for encoding and decoding Google encoded polylines, using a Rust binary and FFI.[RDP](https://github.com/urschrei/rdp)
A Rust implementation of the Ramer–Douglas–Peucker line simplification algorithm. Includes an FFI wrapper.[Polylabel-rs](https://github.com/urschrei/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)[](https://github.com/urschrei/Circles "Borges's 'The Circular Ruins' is a good story. Also an apt title for my PhD.")
---
### Installation and usage`pip install -r requirements.txt` or `uv pip install -r requirements.txt`. The use of a [virtualenv](http://virtualenv.readthedocs.org/en/latest/) is advised.
The Rust libraries (though not their Python counterparts) require a Rust installation. For most platforms (macOS, Windows, *nix), using [rustup.rs](https://rustup.rs) is the easiest way to install and update a Rust installation.### License
© Stephan Hügel 2017 - 2025Unless otherwise specified, the [wards.geojson](wards.geojson) file and any UK shapefiles are provided under
[Crown Copyright](http://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/copyright/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](http://creativecommons.org/licenses/by-nc-sa/4.0/) license.
