Abstract

This book is a guide to geospatial programming with Python. It is designed for beginners and intermediate users who want to learn how to use Python for geospatial analysis and visualization.

Preface#

Introduction#

Geographic Information Systems (GIS) and geospatial analysis have become fundamental tools across numerous disciplines, from environmental science and urban planning to business analytics and public health. As the volume and complexity of geospatial data continue to grow exponentially, the ability to programmatically process, analyze, and visualize this data has become an essential skill for researchers, analysts, and professionals working with spatial information.

Python has emerged as the leading programming language for geospatial analysis, offering a rich ecosystem of libraries and tools that make complex spatial operations accessible to both beginners and experts. However, the path from Python novice to confident geospatial programmer can seem daunting, with numerous libraries to learn and concepts to master.

This book bridges that gap by providing a structured, practical approach to learning geospatial programming with Python. Rather than overwhelming you with advanced techniques from the start, we focus on building a solid foundation of essential skills that will serve you throughout your geospatial programming journey. Each chapter builds upon the previous ones, ensuring you develop both theoretical understanding and practical expertise.

The approach taken in this book is hands-on and example-driven. You’ll work with real geospatial datasets, solve practical problems, and build projects that demonstrate the power of Python for geospatial analysis and visualization. By the end of this book, you’ll have the confidence and skills to tackle your own geospatial programming challenges.

Who This Book Is For#

This book is designed for a diverse audience of learners who want to harness the power of Python for geospatial analysis and visualization:

Students and Researchers in geography, environmental science, urban planning, data science, and related fields who need to analyze spatial data as part of their studies or research. No prior programming experience is assumed, though basic familiarity with computers and data analysis concepts is helpful.

GIS Professionals who currently use desktop GIS software and want to expand their toolkit with programming skills. If you’ve worked with ArcGIS, QGIS, or similar tools and want to automate workflows or perform analyses that are challenging in traditional GIS software, this book will help you make that transition.

Data Scientists and Analysts who work with location-based data and want to add spatial analysis capabilities to their skillset. If you’re comfortable with Python basics but new to geospatial concepts, this book will introduce you to the spatial thinking and tools you need.

Software Developers interested in building applications that work with geospatial data. Whether you’re developing web mapping applications, mobile apps with location features, or data processing pipelines, this book provides the foundation you need.

Self-Learners and Career Changers who are interested in the growing field of geospatial data science. The book assumes no prior knowledge of either Python programming or GIS concepts, making it accessible to motivated beginners.

Professionals in Government and Industry who need to incorporate spatial analysis into their work, such as urban planners, environmental consultants, market researchers, logistics coordinators, or public health officials.

The key requirement is curiosity and willingness to learn. While programming experience is helpful, it’s not necessary. We start with the fundamentals and build up systematically.

What This Book Covers#

This book is organized into three progressive sections that take you from software setup through Python fundamentals to advanced geospatial programming:

Software Setup prepares your development environment with everything you need for geospatial programming. You’ll learn to install and configure essential tools including Miniconda for package management, VS Code for development, Git for version control, and cloud-based alternatives like Google Colab and JupyterLab. This section ensures you have a solid foundation before diving into programming.

Python Programming Fundamentals builds your core programming skills through seven comprehensive chapters. Starting with Python basics, you’ll master variables and data types, data structures (lists, dictionaries, sets), string operations, control flow with loops and conditionals, functions and classes, file handling, and data analysis with NumPy and Pandas. These skills form the foundation for all geospatial programming tasks.

Geospatial Programming with Python comprises fourteen specialized chapters that transform you into a confident geospatial programmer:

  • Introduction to Geospatial Python - Core concepts and the Python geospatial ecosystem

  • Vector Data Analysis with GeoPandas - Working with points, lines, and polygons

  • Raster Data with Rasterio - Processing satellite imagery and gridded datasets

  • Multi-dimensional Data Analysis with Xarray - Handling complex scientific datasets

  • Raster Analysis with Rioxarray - Advanced raster processing and analysis

  • Interactive Visualization with Leafmap - Creating dynamic, interactive maps

  • Geoprocessing with WhiteboxTools - Advanced spatial analysis operations

  • 3D Mapping with MapLibre - Building three-dimensional visualizations

  • Cloud Computing with Earth Engine and Geemap - Leveraging Google Earth Engine for large-scale analysis

  • Hyperspectral Data Visualization with HyperCoast - Working with hyperspectral data

  • High-Performance Geospatial Analytics with DuckDB - High-performance spatial data processing

  • Geospatial Data Processing with GDAL and OGR - Working with various geospatial data formats

  • Building Interactive Dashboards with Solara - Creating interactive dashboards for geospatial applications

  • Distributed Computing with Apache Sedona - Processing large geospatial datasets in a distributed environment

Each chapter follows a consistent structure:

  • Clear concept explanations with real-world context

  • Step-by-step code examples with detailed annotations

  • Hands-on exercises using authentic geospatial datasets

  • Common pitfalls and troubleshooting guidance

  • References to additional resources and further reading

The progression is carefully designed so that each chapter builds upon previous concepts while introducing new capabilities, ensuring you develop both breadth and depth in geospatial programming.

Getting the Most Out of This Book#

To maximize your learning experience with this book, consider the following recommendations:

Set Up a Proper Development Environment: Install Python and the required libraries as described in the first section of the book. A well-configured environment will save you time and frustration throughout your learning journey. Consider using conda or uv to manage your Python packages, as this simplifies the installation of geospatial libraries.

Follow Along with Code Examples: This book is designed to be interactive. Don’t just read the code—type it out, run it, and experiment with modifications. Understanding comes through practice, and each example builds skills you’ll need later.

Work Through the Exercises: Each chapter includes exercises designed to reinforce the concepts you’ve learned. These are not optional extras—they are an integral part of the learning process. Start with the guided exercises, then challenge yourself with your own projects.

Use Real Data: While the book provides datasets for examples and exercises, try applying the techniques to data from your own field or interests. This will help you understand how the concepts apply to real-world scenarios and build confidence in your abilities.

Build Projects: As you progress through the book, consider working on a personal project that interests you. This could be analyzing data from your research, creating maps for your community, or solving a problem you’ve encountered in your work.

Be Patient with Yourself: Programming can be frustrating, especially when you’re learning. Expect to encounter errors, spend time debugging, and occasionally feel stuck. This is normal and part of the learning process. Take breaks when needed, and remember that expertise develops gradually through consistent practice. If you get stuck, don’t hesitate to ask for help on the book’s GitHub repository.

Keep Practicing: The skills in this book require regular practice to maintain and develop. Set aside time regularly to work on geospatial programming projects, even if they’re small ones.

Conventions Used in This Book#

This book uses several conventions to help you navigate the content and understand the code examples:

Code Formatting: All Python code appears in monospaced font within code blocks. When code appears within regular text, it is formatted like this. File and directory names are also formatted in monospaced font.

Code Examples: Most code examples are complete and runnable. They include comments explaining the key concepts and techniques being demonstrated. Line numbers may be included for reference in the accompanying text.

# This is an example of a code block
import leafmap

m = leafmap.Map()
m.add_basemap("OpenTopoMap")  # add a basemap to the map
m

Command Line Instructions: Commands to be entered at the command line or terminal are shown with a $ prompt:

$ pip install leafmap
$ python script.py

Downloading the Code Examples#

All code examples, datasets, and supplementary materials for this book are freely available on GitHub:

giswqs/intro-gispro

To download the materials, you can use one of the following methods:

  • Clone the repository (if you have Git installed):

    $ git clone https://github.com/giswqs/intro-gispro.git
    
  • Download as ZIP (if you prefer not to use Git):

    • Visit the GitHub repository page

    • Click the green Code button

    • Select Download ZIP

    • Extract the files to your preferred location

  • Browse individual files online through the GitHub interface if you only need specific examples

The repository is regularly updated with corrections, improvements, and additional examples. Check back periodically for updates, or watch the repository on GitHub to be notified of changes.

If you find errors in the code or have suggestions for improvements, please open an issue or submit a pull request on GitHub. Community contributions help make this resource better for everyone.

Video Tutorials#

Complementing the written content, this book is supported by a comprehensive series of video tutorials that walk through key concepts and provide additional examples:

https://tinyurl.com/intro-gispro-videos

The videos are designed to complement, not replace, the written material. They’re particularly helpful for:

  • Visual learners who benefit from seeing code being written and executed

  • Understanding complex concepts through multiple explanations

  • Learning about the development workflow and best practices

  • Seeing how to approach problems and debug issues

The playlist is organized to follow the book’s structure. You can watch them in order as you progress through the book, or jump to specific topics as needed.

The videos were created in Fall 2024 when I was teaching the Introduction to GIS Programming [1] course at the University of Tennessee. Although the course has concluded, the videos remain relevant and can be used as a reference for the book. Additional videos will be added in the future.

Get in Touch#

I welcome feedback, questions, and suggestions from readers. Your input helps improve the book and makes it more useful for the geospatial programming community.

For book-related questions and discussions:

Types of feedback that are particularly helpful:

  • Errors or unclear explanations in the text or code

  • Suggestions for additional examples or use cases

  • Ideas for new topics or chapters

  • Reports of compatibility issues with different operating systems or library versions

  • Success stories of how you’ve applied the techniques from the book

Acknowledgments#

This book would not have been possible without the contributions and support of many individuals and the broader open-source geospatial community.

The Open-Source Community: This book builds upon the incredible work of countless open-source developers who have created and maintained the Python geospatial ecosystem. Special thanks to the developers and maintainers of NumPy, Pandas, GeoPandas, Rasterio, Xarray, Rioxarray, Folium, ipyleaflet, MapLibre, GDAL, and the many other libraries that make geospatial programming accessible.

Students and Colleagues: The questions, challenges, and insights from students in my geospatial programming courses at the University of Tennessee have shaped the approach and content of this book. Their feedback on what works and what doesn’t has been invaluable in creating materials that truly serve learners.

Research Collaborators: Colleagues and collaborators in the geospatial research community have provided real-world use cases, datasets, and problem scenarios that inform the practical examples throughout the book.

Family and Friends: Writing a technical book requires significant time and focus. I’m grateful for the patience and support of family and friends who understood the many evenings and weekends dedicated to this project.

The Broader GIS Community: The geospatial field is built on a foundation of sharing knowledge and tools. This book is part of that tradition, and I’m honored to contribute to the resources available for learning geospatial programming.

This book was written using MyST Markdown [2] and compiled using Typst [3] with the min-book [4] template. Credits to developers and maintainers of the Typst and MyST Markdown projects. Special thanks to Maycon F. Melo [5] for the min-book template and their help with customizing the template for this book.

Any errors or omissions in this book remain my responsibility. I’m committed to addressing issues and improving the content based on reader feedback.

About the Author#

Dr. Qiusheng Wu is an Associate Professor and the Director of Graduate Studies in the Department of Geography & Sustainability at the University of Tennessee, Knoxville. He also serves as an Amazon Scholar. Dr. Wu’s research focuses on geospatial data science and open-source software development, with an emphasis on leveraging big geospatial data and cloud computing to study environmental change, particularly surface water and wetland inundation dynamics. He is the creator of several widely used open-source Python packages, including geemap [6], leafmap [7], segment-geospatial [8], and geoai [9], which support advanced geospatial analysis and interactive visualization. His open-source work is available at the Open Geospatial Solutions [10] on GitHub.