Python and Geospatial Algorithms
This chapter will focus on applying Python to algorithms that are typically performed by a geographic information system (GIS) such as QGIS or ArcGIS. An algorithm is like a recipe for a computer. Just like a recipe gives you step-by-step instructions on how to cook a dish, an algorithm gives a computer step-by-step instructions to solve a problem or complete a task. These algorithms are the heart and soul of geospatial analysis. We will continue to use as few external dependencies as possible outside of Python itself so that you have tools with maximum reusability in different environments. In this book, we separate GIS analysis and remote sensing from a programming perspective, which means that, in this chapter, we’ll mostly focus on vector data.
As with the other chapters in this book, the items presented here are core functions that serve as building blocks that you can recombine to solve challenges that you will encounter beyond this book. The topics in this chapter include the following:
- Measuring distance
- Calculating line direction
- Understanding coordinate conversion
- Understanding reprojection
- Understanding coordinate format conversion
- Calculating the area of a polygon
- Using ChatGPT to measure a polygon’s perimeter
This chapter contains many code samples. It covers important algorithms mostly related to measuring distance. Relating objects on Earth by how close they are physically is a core tenant of GIS.