src/nimgeos/geometry_base

Shared base operations for geometry dispatch and multi-geometry iteration.

  • geomN — retrieve the nth sub-geometry of any multi-geometry or collection.
  • Iterators for MultiPoint, MultiLineString, MultiPolygon, GeometryCollection.

This module breaks the circular-import chain that previously forced geomN to live in factories.nim. See also: docs/geometries/multi.md.

Procs

proc geomN(g: Geometry; n: int): Geometry {....raises: [GeosGeomError], tags: [],
    forbids: [].}
Returns a clone of the nth sub-geometry as a concrete-typed Geometry. Works on any multi-geometry or collection.
var ctx = initGeosContext()
let mp = ctx.fromWKT("MULTIPOINT ((0 0), (1 1), (2 2))")
let sub = mp.geomN(1)   # → Point (1 1)
echo sub.toWKT()

Raises GeosGeomError if the geometry is nil or GEOS fails.

Iterators

iterator items(g: GeometryCollection): Geometry {....raises: [GeosGeomError],
    tags: [], forbids: [].}
Iterate over all geometries in a GeometryCollection. Each yielded value is a concrete subtype (Point, LineString, etc.).
for geom in geometryCollection:
  echo geom.type()

Raises GeosGeomError if the geometry is nil or GEOS fails.

iterator items(g: MultiLineString): LineString {....raises: [GeosGeomError],
    tags: [], forbids: [].}
Iterate over all line strings in a MultiLineString.
for ls in multiLineString:
  echo ls.numPoints(), " points"

Raises GeosGeomError if the geometry is nil or GEOS fails.

iterator items(g: MultiPoint): Point {....raises: [GeosGeomError], tags: [],
                                       forbids: [].}
Iterate over all points in a MultiPoint.
for pt in multiPoint:
  echo pt.x(), " ", pt.y()

Raises GeosGeomError if the geometry is nil or GEOS fails.

iterator items(g: MultiPolygon): Polygon {....raises: [GeosGeomError], tags: [],
    forbids: [].}
Iterate over all polygons in a MultiPolygon.
for poly in multiPolygon:
  echo poly.area()

Raises GeosGeomError if the geometry is nil or GEOS fails.