LineString¶
A LineString is a sequence of two or more coordinates connected by straight line segments. It inherits from GeometryObj.
Creating a LineString¶
2D¶
Requires at least 2 (x, y) tuples:
3D¶
Requires at least 2 (x, y, z) tuples:
Passing fewer than 2 coordinates raises GeosGeomError.
Accessors¶
numPoints()¶
Returns the number of points in the LineString.
pointN(index)¶
Returns the point at index (0-based) as a Point. Raises GeosGeomError if the index is out of bounds.
startPoint()¶
Returns the first point as a Point.
endPoint()¶
Returns the last point as a Point.
String representation¶
Full example¶
import nimgeos
var ctx = initGeosContext()
# 2D LineString
let trail = ctx.createLineString([
(1.0, 1.0), (2.5, 3.0), (4.0, 2.0)
])
echo "Points: ", trail.numPoints() # 3
echo "Length: ", trail.length() # ~4.61
echo trail # LineString(3 points)
# 3D LineString
let flight = ctx.createLineString([
(0.0, 0.0, 100.0), (10.0, 0.0, 150.0), (20.0, 10.0, 200.0)
])
echo "3D points: ", flight.numPoints()
# Access individual points
let mid = trail.pointN(1)
echo "Midpoint: ", mid.x(), ", ", mid.y()
let first = trail.startPoint()
let last = trail.endPoint()
echo "Trail from (", first.x(), ", ", first.y(), ") to (", last.x(), ", ", last.y(), ")"