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 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 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 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 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.