# libgeos/geos architecture

> Architecture diagram of the GitHub repository libgeos/geos, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/libgeos/geos
- Repository: https://github.com/libgeos/geos

## Overview

GEOS is a C++ library for two-dimensional vector geometry, with a stable C interface and a CLI for invoking operations. The typical client workflow is to supply geometries, run a spatial operation, and receive a geometry or predicate result; the C wrapper delegates operations to the C++ implementation. Its major capabilities include geometry I/O, spatial predicates and overlay, buffering, coverage processing, and geometric algorithms. The source excerpts show some specific delegation, but not most runtime wiring, so uncertain internal links are dashed and have no evidence path.

Main entry points: [`include/geos/geom/Geometry.h`](https://github.com/libgeos/geos/blob/main/include/geos/geom/Geometry.h) (Geometry model), [`src/coverage/CoverageCleaner.cpp`](https://github.com/libgeos/geos/blob/main/src/coverage/CoverageCleaner.cpp) (Coverage cleaning), [`capi/geos_c.cpp`](https://github.com/libgeos/geos/blob/main/capi/geos_c.cpp) (C API), [`include/geos/operation/overlayng/OverlayNG.h`](https://github.com/libgeos/geos/blob/main/include/geos/operation/overlayng/OverlayNG.h) (Overlay)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["Client interfaces"]
  node_cpp_api["C++ API<br/>[geos.h]"]
  node_c_api["C API<br/>[geos_c.cpp]"]
  node_geosop["geosop CLI<br/>[GeometryOp.cpp]"]
  node_wkt_io["WKT I/O<br/>[WKTReader.cpp]"]
end

subgraph group_geometry["Geometry model"]
  node_geometry_model["Geometry model<br/>[Geometry.h]"]
  node_geometry_factory["Geometry factory"]
end

subgraph group_operations["Spatial operations"]
  node_predicates["Predicates<br/>[RelateNG.h]"]
  node_overlay["Overlay<br/>[OverlayNG.h]"]
  node_buffer["Buffering<br/>[BufferOp.h]"]
  node_coverage_union["Coverage union<br/>[CoverageUnion.cpp]"]
  node_coverage_cleaner["Coverage cleaning"]
  node_coverage_validator["Coverage validation"]
end

subgraph group_algorithms["Algorithms and indexing"]
  node_geometry_algorithms["Geometry algorithms<br/>[Distance.h]"]
  node_noding["Noding<br/>[GeometryNoder.cpp]"]
  node_spatial_indexes["Spatial indexes<br/>[STRtree.cpp]"]
  node_prepared_geometry["Prepared geometry"]
end

node_cpp_client(("C++ client"))
node_c_client(("C client"))

node_cpp_client -->|"uses"| node_cpp_api
node_c_client -->|"uses"| node_c_api
node_cpp_api -.->|"operates on"| node_geometry_model
node_c_api -->|"reads geometry"| node_geometry_model
node_c_api -->|"calls overlay"| node_overlay
node_geosop -.->|"operates on"| node_geometry_model
node_cpp_client -.->|"uses"| node_wkt_io
node_wkt_io -.->|"creates geometries"| node_geometry_factory
node_geometry_factory -.->|"creates geometries"| node_geometry_model
node_geometry_model -.->|"input to"| node_predicates
node_geometry_model -.->|"input to"| node_overlay
node_geometry_model -.->|"input to"| node_buffer
node_geometry_model -.->|"input to"| node_geometry_algorithms
node_coverage_union -->|"delegates to"| node_overlay
node_coverage_cleaner -->|"snaps segments"| node_noding
node_coverage_cleaner -.->|"cleans coverage"| node_coverage_validator
node_coverage_cleaner -.->|"uses union"| node_coverage_union
node_predicates -.->|"uses indexes"| node_spatial_indexes
node_prepared_geometry -.->|"uses indexes"| node_spatial_indexes

click node_cpp_api "https://github.com/libgeos/geos/blob/main/include/geos.h"
click node_c_api "https://github.com/libgeos/geos/blob/main/capi/geos_c.cpp"
click node_geosop "https://github.com/libgeos/geos/blob/main/util/geosop/GeometryOp.cpp"
click node_wkt_io "https://github.com/libgeos/geos/blob/main/src/io/WKTReader.cpp"
click node_geometry_model "https://github.com/libgeos/geos/blob/main/include/geos/geom/Geometry.h"
click node_geometry_factory "https://github.com/libgeos/geos/blob/main/src/geom/GeometryFactory.cpp"
click node_predicates "https://github.com/libgeos/geos/blob/main/include/geos/operation/relateng/RelateNG.h"
click node_overlay "https://github.com/libgeos/geos/blob/main/include/geos/operation/overlayng/OverlayNG.h"
click node_buffer "https://github.com/libgeos/geos/blob/main/include/geos/operation/buffer/BufferOp.h"
click node_coverage_union "https://github.com/libgeos/geos/blob/main/src/operation/overlayng/CoverageUnion.cpp"
click node_coverage_cleaner "https://github.com/libgeos/geos/blob/main/src/coverage/CoverageCleaner.cpp"
click node_coverage_validator "https://github.com/libgeos/geos/blob/main/src/coverage/CoveragePolygonValidator.cpp"
click node_geometry_algorithms "https://github.com/libgeos/geos/blob/main/include/geos/algorithm/Distance.h"
click node_noding "https://github.com/libgeos/geos/blob/main/src/noding/GeometryNoder.cpp"
click node_spatial_indexes "https://github.com/libgeos/geos/blob/main/src/index/strtree/STRtree.cpp"
click node_prepared_geometry "https://github.com/libgeos/geos/blob/main/src/geom/prep/AbstractPreparedPolygonContains.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cpp_api,node_c_api,node_geosop,node_wkt_io,node_cpp_client,node_c_client toneBlue
class node_geometry_model,node_geometry_factory toneAmber
class node_predicates,node_overlay,node_buffer,node_coverage_union,node_coverage_cleaner,node_coverage_validator toneMint
class node_geometry_algorithms,node_noding,node_spatial_indexes,node_prepared_geometry toneRose
```

## Components

### Client interfaces

- [C++ API](https://github.com/libgeos/geos/blob/main/include/geos.h): `include/geos.h`
- [C API](https://github.com/libgeos/geos/blob/main/capi/geos_c.cpp): `capi/geos_c.cpp`
- [geosop CLI](https://github.com/libgeos/geos/blob/main/util/geosop/GeometryOp.cpp): `util/geosop/GeometryOp.cpp`
- [WKT I/O](https://github.com/libgeos/geos/blob/main/src/io/WKTReader.cpp): `src/io/WKTReader.cpp`

### Geometry model

- [Geometry model](https://github.com/libgeos/geos/blob/main/include/geos/geom/Geometry.h): `include/geos/geom/Geometry.h`
- [Geometry factory](https://github.com/libgeos/geos/blob/main/src/geom/GeometryFactory.cpp): `src/geom/GeometryFactory.cpp`

### Spatial operations

- [Predicates](https://github.com/libgeos/geos/blob/main/include/geos/operation/relateng/RelateNG.h): `include/geos/operation/relateng/RelateNG.h`
- [Overlay](https://github.com/libgeos/geos/blob/main/include/geos/operation/overlayng/OverlayNG.h): `include/geos/operation/overlayng/OverlayNG.h`
- [Buffering](https://github.com/libgeos/geos/blob/main/include/geos/operation/buffer/BufferOp.h): `include/geos/operation/buffer/BufferOp.h`
- [Coverage union](https://github.com/libgeos/geos/blob/main/src/operation/overlayng/CoverageUnion.cpp): `src/operation/overlayng/CoverageUnion.cpp`
- [Coverage cleaning](https://github.com/libgeos/geos/blob/main/src/coverage/CoverageCleaner.cpp): `src/coverage/CoverageCleaner.cpp`
- [Coverage validation](https://github.com/libgeos/geos/blob/main/src/coverage/CoveragePolygonValidator.cpp): `src/coverage/CoveragePolygonValidator.cpp`

### Algorithms and indexing

- [Geometry algorithms](https://github.com/libgeos/geos/blob/main/include/geos/algorithm/Distance.h): `include/geos/algorithm/Distance.h`
- [Noding](https://github.com/libgeos/geos/blob/main/src/noding/GeometryNoder.cpp): `src/noding/GeometryNoder.cpp`
- [Spatial indexes](https://github.com/libgeos/geos/blob/main/src/index/strtree/STRtree.cpp): `src/index/strtree/STRtree.cpp`
- [Prepared geometry](https://github.com/libgeos/geos/blob/main/src/geom/prep/AbstractPreparedPolygonContains.cpp): `src/geom/prep/AbstractPreparedPolygonContains.cpp`

### Other components

- **C++ client**
- **C client**

## Connections

- C++ client → C++ API: uses (evidence: `README.md`)
- C client → C API: uses (evidence: `README.md`)
- C++ API → Geometry model: operates on
- C API → Geometry model: reads geometry
- C API → Overlay: calls overlay
- geosop CLI → Geometry model: operates on
- C++ client → WKT I/O: uses
- WKT I/O → Geometry factory: creates geometries
- Geometry factory → Geometry model: creates geometries
- Geometry model → Predicates: input to
- Geometry model → Overlay: input to
- Geometry model → Buffering: input to
- Geometry model → Geometry algorithms: input to
- Coverage union → Overlay: delegates to (evidence: `src/operation/overlayng/CoverageUnion.cpp`)
- Coverage cleaning → Noding: snaps segments (evidence: `src/coverage/CoverageCleaner.cpp`)
- Coverage cleaning → Coverage validation: cleans coverage
- Coverage cleaning → Coverage union: uses union
- Predicates → Spatial indexes: uses indexes
- Prepared geometry → Spatial indexes: uses indexes
