src/nimgeos/spatial_operations

Spatial operations โ€” produce new Geometry instances from existing ones. All operations return concrete-typed Geometry refs via factories/geomFromHandle. See also: docs/operations/spatial-operations.md.

Procs

proc boundary(g: Geometry): Geometry {....raises: [GeosGeomError],
                                       tags: [RootEffect], forbids: [].}
Returns the topological boundary of a geometry. For points, boundary is empty; for polygons, boundary is ring(s). Raises GeosGeomError if g is nil or GEOS fails.
proc buffer(g: Geometry; width: float; quadsegs: int = 8): Geometry {.
    ...raises: [GeosGeomError], tags: [], forbids: [].}
Returns a geometry expanded (or shrunk if negative) by width. quadsegs controls arc approximation quality (default 8, matching GEOS default).
var ctx = initGeosContext()
let p = ctx.createPoint(0.0, 0.0)
echo p.buffer(10.0).area()   # โ‰ˆ 312.14 (polygon approx. of ฯ€ยท10ยฒ = 314.16)

Raises GeosGeomError if g is nil or GEOS fails.

proc centroid(g: Geometry): Geometry {....raises: [GeosGeomError],
                                       tags: [RootEffect], forbids: [].}
Returns the geometric centre of the geometry as a Point. Raises GeosGeomError if g is nil or GEOS fails.
proc convexHull(g: Geometry): Geometry {....raises: [GeosGeomError],
    tags: [RootEffect], forbids: [].}
Returns the smallest convex polygon that contains the geometry. Raises GeosGeomError if g is nil or GEOS fails.
proc difference(g, other: Geometry): Geometry {....raises: [GeosGeomError],
    tags: [RootEffect], forbids: [].}
Returns the part of g that does not intersect other. Raises GeosGeomError if either argument is nil or GEOS fails.
proc envelope(g: Geometry): Geometry {....raises: [GeosGeomError],
                                       tags: [RootEffect], forbids: [].}
Returns the bounding box of the geometry as a Polygon (or Point/Line for degenerate cases). Raises GeosGeomError if g is nil or GEOS fails.
proc intersection(g, other: Geometry): Geometry {....raises: [GeosGeomError],
    tags: [RootEffect], forbids: [].}
Returns the geometry shared by both inputs.
var ctx = initGeosContext()
let a = ctx.fromWKT("POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))")
let b = ctx.fromWKT("POLYGON ((5 5, 5 15, 15 15, 15 5, 5 5))")
echo a.intersection(b).area()   # 25.0

Raises GeosGeomError if either argument is nil or GEOS fails.

proc simplify(g: Geometry; tol: float): Geometry {....raises: [GeosGeomError],
    tags: [RootEffect], forbids: [].}
Simplifies the geometry using the Douglas-Peucker tolerance tol. Higher tolerance removes more detail but may alter topology. Raises GeosGeomError if g is nil or GEOS fails.
proc snap(g, other: Geometry; tol: float): Geometry {....raises: [GeosGeomError],
    tags: [RootEffect], forbids: [].}
Snaps g vertices/segments toward other where within tolerance tol. Raises GeosGeomError if either argument is nil or GEOS fails.
proc symmetricDifference(g, other: Geometry): Geometry {.
    ...raises: [GeosGeomError], tags: [RootEffect], forbids: [].}
Returns the geometry covered by exactly one input (exclusive-or). Raises GeosGeomError if either argument is nil or GEOS fails.
proc topologyPreserveSimplify(g: Geometry; tol: float): Geometry {.
    ...raises: [GeosGeomError], tags: [RootEffect], forbids: [].}
Simplifies the geometry while preserving topology, using tolerance tol. Useful for polygons where validity must be retained. Raises GeosGeomError if g is nil or GEOS fails.
proc unaryUnion(g: Geometry): Geometry {....raises: [GeosGeomError],
    tags: [RootEffect], forbids: [].}
Computes a union over all components of a collection geometry. For non-collections, GEOS returns an equivalent normalized geometry. Raises GeosGeomError if g is nil or GEOS fails.
proc union(g, other: Geometry): Geometry {....raises: [GeosGeomError],
    tags: [RootEffect], forbids: [].}
Returns the geometry covered by either input. Raises GeosGeomError if either argument is nil or GEOS fails.