Geometry Overview¶
All spatial types in nimgeos inherit from GeometryObj (a ref type), which owns a GEOS geometry handle. The handle is destroyed automatically when the ref count reaches zero via ORC.
Type hierarchy¶
GeometryObj (abstract base)
├── PointObj
├── LineStringObj
├── LinearRingObj
├── PolygonObj
├── MultiPointObj
├── MultiLineStringObj
├── MultiPolygonObj
└── GeometryCollectionObj
GeomType enum¶
The type() proc returns the concrete geometry kind:
type GeomType* = enum
gtPoint = 0
gtLineString = 1
gtLinearRing = 2
gtPolygon = 3
gtMultiPoint = 4
gtMultiLineString = 5
gtMultiPolygon = 6
gtGeometryCollection = 7
Base geometry procs¶
These procs are available on all geometry types:
type()¶
Returns the GeomType of the geometry.
isEmpty()¶
Returns true if the geometry is empty (no coordinates).
isValid()¶
Returns true if the geometry is topologically valid per OGC rules.
area()¶
Returns the area of the geometry (polygons and multi-polygons). Returns 0 for non-area geometries.
length()¶
Returns the length of the geometry (linestrings and multi-linestrings). Returns 0 for non-linear geometries.
distance(other)¶
Returns the minimum distance between two geometries.
numCoordinates()¶
Returns the total number of coordinates in the geometry.
numGeometries()¶
Returns the number of component geometries (1 for simple types, N for multi-geometries).
clone()¶
Deep-copies the geometry via GEOSGeom_clone_r. The caller owns the new independent copy.
$ (string representation)¶
Returns a compact summary of the geometry. Each concrete type implements its own format:
Full example¶
import nimgeos
var ctx = initGeosContext()
let p = ctx.createPoint(0.0, 0.0)
let ls = ctx.createLineString([(0.0, 0.0), (3.0, 4.0)])
let shell = ctx.createLinearRing([
(0.0, 0.0), (10.0, 0.0), (10.0, 10.0), (0.0, 10.0), (0.0, 0.0)])
let poly = ctx.createPolygon(shell)
echo p.type() # gtPoint
echo p.isEmpty() # false
echo ls.length() # 5.0
echo poly.area() # 100.0
echo p.distance(ls) # 0.0
echo poly.numCoordinates() # 5