Geocomputation with Python (geocompy) is motivated by the need for an introductory, yet rigorous and up-to-date, resource for working with geographic data with the most popular programming language in the world. A unique selling point of the book is its cohesive and joined-up coverage of both vector and raster geographic data models and consistent learning curve. We aim to minimize surprises, with each section and chapter building on the previous. If you’re just starting out with Python for working with geographic data, this book is an excellent place to start.

There are many resources on Python on β€˜GeoPython’ but none that fill this need for an introductory resource that provides strong foundations for future work. We want to avoid reinventing the wheel and provide something that fills an β€˜ecological niche’ in the wider free and open source software for geospatial (FOSS4G) ecosystem. Key features include:

  1. Doing basic operations well
  2. Integration of vector and raster datasets operations
  3. Clear explanation of each line of code in the book to minimize surprises
  4. Exercises at the end of each chapter with reproducible and open solutions
  5. Provision of lucid example datasets and meaningful operations to illustrate the applied nature of geographic research

This book is complementary with, and adds value to, other projects in the ecosystem, as highlighted in the following comparison between Geocomputation with Python and related GeoPython books:

Another unique feature of the book is that it is part of a wider community. Geocomputation with Python is a sister project of Geocomputation with R, a book on geographic data analysis, visualization, and modeling using the R programming language that has 60+ contributors and an active community, not least in the associated Discord group. Links with the vibrant β€˜R-spatial’ community, and other communities such as GeoRust and JuliaGeo, lead to many opportunities for mutual benefit across open source ecosystems.

Code and sample data

To run the code examples, you can download the ZIP file of the GitHub repository. In the ZIP file, the ipynb directory contains the source files of the chapters in Jupyter Notebook format, the data directory contains the sample data files, and the output directory contains the files created in code examples (some of which are also used as inputs in other code sections). Place them together as follows to run the code:

β”œβ”€β”€ data
β”‚   β”œβ”€β”€ aut.tif
β”‚   β”œβ”€β”€ ch.tif
β”‚   β”œβ”€β”€ coffee_data.csv
β”‚   β”œβ”€β”€ cycle_hire.gpkg
β”‚   β”œβ”€β”€ cycle_hire_osm.gpkg
β”‚   β”œβ”€β”€ cycle_hire_xy.csv
β”‚   β”œβ”€β”€ dem.tif
β”‚   β”œβ”€β”€ landsat.tif
β”‚   β”œβ”€β”€ nlcd.tif
β”‚   β”œβ”€β”€ nz_elev.tif
β”‚   β”œβ”€β”€ nz.gpkg
β”‚   β”œβ”€β”€ nz_height.gpkg
β”‚   β”œβ”€β”€ seine.gpkg
β”‚   β”œβ”€β”€ srtm.tif
β”‚   β”œβ”€β”€ us_states.gpkg
β”‚   β”œβ”€β”€ world.gpkg
β”‚   β”œβ”€β”€ world_wkt.csv
β”‚   β”œβ”€β”€ zion.gpkg
β”‚   └── zion_points.gpkg
β”œβ”€β”€ output
β”‚   β”œβ”€β”€ cycle_hire_xy.csv
β”‚   β”œβ”€β”€ dem_agg5.tif
β”‚   β”œβ”€β”€ dem_contour.gpkg
β”‚   β”œβ”€β”€ dem_resample_maximum.tif
β”‚   β”œβ”€β”€ dem_resample_nearest.tif
β”‚   β”œβ”€β”€ elev.tif
β”‚   β”œβ”€β”€ grain.tif
β”‚   β”œβ”€β”€ map.html
β”‚   β”œβ”€β”€ ne_10m_airports.cpg
β”‚   β”œβ”€β”€ ne_10m_airports.dbf
β”‚   β”œβ”€β”€ ne_10m_airports.prj
β”‚   β”œβ”€β”€ ne_10m_airports.README.html
β”‚   β”œβ”€β”€ ne_10m_airports.shp
β”‚   β”œβ”€β”€ ne_10m_airports.shx
β”‚   β”œβ”€β”€ ne_10m_airports.VERSION.txt
β”‚   β”œβ”€β”€
β”‚   β”œβ”€β”€ nlcd_4326_2.tif
β”‚   β”œβ”€β”€ nlcd_4326.tif
β”‚   β”œβ”€β”€ nlcd_modified_crs.tif
β”‚   β”œβ”€β”€ plot_geopandas.jpg
β”‚   β”œβ”€β”€ plot_rasterio2.svg
β”‚   β”œβ”€β”€ plot_rasterio.jpg
β”‚   β”œβ”€β”€ r3.tif
β”‚   β”œβ”€β”€ r_nodata_float.tif
β”‚   β”œβ”€β”€ r_nodata_int.tif
β”‚   β”œβ”€β”€ r.tif
β”‚   β”œβ”€β”€ srtm_32612_aspect.tif
β”‚   β”œβ”€β”€ srtm_32612_slope.tif
β”‚   β”œβ”€β”€ srtm_32612.tif
β”‚   β”œβ”€β”€ srtm_masked_cropped.tif
β”‚   β”œβ”€β”€ srtm_masked.tif
β”‚   β”œβ”€β”€ w_many_features.gpkg
β”‚   β”œβ”€β”€ w_many_layers.gpkg
β”‚   └── world.gpkg
β”œβ”€β”€ 01-spatial-data.qmd
β”œβ”€β”€ 02-attribute-operations.qmd
β”œβ”€β”€ 03-spatial-operations.qmd
β”œβ”€β”€ 04-geometry-operations.qmd
β”œβ”€β”€ 05-raster-vector.qmd
β”œβ”€β”€ 06-reproj.qmd
β”œβ”€β”€ 07-read-write.qmd
└── 08-mapping.qmd


We acknowledge Robin Lovelace, Jakub Nowosad, and Jannes Muenchowβ€”authors of Geocomputation with R (Robin and Jakub also author the present book), a book on the same topic for a different programming language (R). The structure, topics, and most of the theoretical discussions were adapted from that earlier publication.

We thank the authors of the Python language, and the authors of the shapely, pandas, geopandas, and rasterio packages which are used extensively in the book, for building these wonderful tools.

We acknowledge of GitHub users Will Deakin, Sean Gillies, Josh Cole, and Jt Miclat (at the time of writing; full list here) for their contributions during the open-source development of the book.