CoordSeq¶
Coordinate sequence — the underlying data structure for Point, LineString, and LinearRing geometries.
Type¶
A CoordSeq wraps a GEOS CoordSequence handle. It is non-copyable — assign by var or use clone().
Constructor¶
Creates a new coordinate sequence with size slots and dims dimensions (2 or 3). The sequence owns its handle and will be destroyed when it goes out of scope.
Extract from geometry¶
Extracts a clone of the coordinate sequence from a Point, LineString, or LinearRing. The caller owns the returned CoordSeq.
let ls = ctx.createLineString([(0.0, 0.0), (1.0, 1.0), (2.0, 2.0)])
let cs = ls.coordSeq()
echo cs.len # 3
Property accessors¶
Setters¶
proc setX*(cs: CoordSeq; idx: int; val: float)
proc setY*(cs: CoordSeq; idx: int; val: float)
proc setZ*(cs: CoordSeq; idx: int; val: float)
proc setCoord*(cs: CoordSeq; idx: int; x, y: float)
proc setCoord*(cs: CoordSeq; idx: int; x, y, z: float)
Set individual coordinates by index.
Getters¶
proc getX*(cs: CoordSeq; idx: int): float
proc getY*(cs: CoordSeq; idx: int): float
proc getZ*(cs: CoordSeq; idx: int): float
proc getCoord*(cs: CoordSeq; idx: int): (float, float)
proc getCoord3D*(cs: CoordSeq; idx: int): (float, float, float)
let x = cs.getX(0)
let y = cs.getY(0)
let (cx, cy) = cs.getCoord(0)
let (cx, cy, cz) = cs.getCoord3D(0)
Clone¶
Deep-copies the coordinate sequence. The caller owns the result.
Iterators¶
iterator items*(cs: CoordSeq): (float, float)
iterator items3D*(cs: CoordSeq): (float, float, float)
String representation¶
Returns a summary: CoordSeq(N coords, Dd).
Full example¶
import nimgeos
var ctx = initGeosContext()
# Create a coordinate sequence
var cs = newCoordSeq(ctx, 3, 2)
cs.setCoord(0, 0.0, 0.0)
cs.setCoord(1, 1.0, 1.0)
cs.setCoord(2, 2.0, 2.0)
echo cs.len() # 3
echo cs.dims() # 2
# Iterate
for (x, y) in cs:
echo "(", x, ", ", y, ")"
# Clone
let copy = cs.clone()
# Extract from geometry
let ls = ctx.createLineString([(10.0, 10.0), (20.0, 20.0)])
let ls_cs = ls.coordSeq()
echo ls_cs.len() # 2
# 3D coordinates
var cs3d = newCoordSeq(ctx, 2, 3)
cs3d.setCoord(0, 1.0, 2.0, 3.0)
cs3d.setCoord(1, 4.0, 5.0, 6.0)
let (x, y, z) = cs3d.getCoord3D(0)
echo x, ", ", y, ", ", z # 1.0, 2.0, 3.0