Geographic information systems (GIS) have become increasingly important in helping us understand complex social, economic, and natural dynamics where spatial components play a key role. The critical algorithms used in GIS, however, are notoriously difficult to both teach and understand, in part due to the lack of a coherent representation. GIS Algorithms attempts to address this problem by combining rigorous formal language with example case studies and student exercises. Using Python code throughout, Xiao breaks the subject down into three fundamental areas:  • Geometric Algorithms  • Spatial Indexing  • Spatial Analysis and Modelling With its comprehensive coverage of the many algorithms involved, GIS Algorithms is a key new textbook in this complex and critical area of geography.

### Polygon Overlay

Polygon Overlay

And outside the walls, for half a mile around in every direction, the air was scented with the heavy rich smell of melting chocolate!

Roald Dahl, Charlie and the Chocolate Factory

It is a common task in GIS to calculate the intersections between line segments. For example, we may want to know where the path of a hurricane passes the coast of a country and the size of the area affected. This chapter contains fundamental algorithms that can be used to address such issues.

### 3.1 Line segment intersections

The algorithm for calculating the intersection between two line segments can be extended to the case of a set of line segments. A straightforward approach is simply to run a loop so that each pair of line ...