Skip to content
@deckyard/geo

Cheatsheet

Every export of @deckyard/geo, by topic, called through the import alias: import "@deckyard/geo/" as geo; then geo.open(path). Coordinates are WGS 84 degrees, latitude before longitude in every signature; distances are metres.

Version

ConstantValueMeaning
VERSION"0.1.0"The version of this deck.

Errors and precision

ConstantValueMeaning
ERROR_KIND"geo"The kind every Error this deck raises carries.
COORD_PLACES7How many decimal places a latitude or longitude is written with.
ELEVATION_PLACES2How many decimal places an elevation is written with.
MAX_NESTING100How deeply a document may nest containers before a reader raises.

The model

See The model.

Point

One position on the Earth, with whatever the file said about it.

FieldHolds
lat as floatdegrees north of the equator, -90 to 90
lon as floatdegrees east of Greenwich, -180 to 180
ele as floatelevation in metres, as the source gives it; no datum conversion
hasElevation as boolwhether ele came from the source
at as stringwhen the point was recorded, as RFC 3339
hasTime as boolwhether at came from the source
name as stringwhat the source called it
desc as stringa longer description
sym as stringthe symbol or style name to draw it with

Segment

One unbroken run of track points.

FieldHolds
points as list of Pointthe positions, in the order recorded

Track

A recorded path: where something went.

FieldHolds
name as stringwhat the source called it
desc as stringa longer description
kind as stringthe activity, as GPX <type> spells it
segments as list of Segmentthe runs of points, in order

Route

A planned path: where something is meant to go.

FieldHolds
name as stringwhat the source called it
desc as stringa longer description
points as list of Pointthe points to visit, in order

Document

A whole file, in the shape every codec in this deck reads and writes.

FieldHolds
name as stringthe document title
desc as stringa longer description
creator as stringwhat wrote the file
at as stringwhen the file was written, as RFC 3339
waypoints as list of Pointstandalone points of interest
routes as list of Routeplanned paths
tracks as list of Trackrecorded paths

Bounds

A latitude and longitude rectangle.

FieldHolds
minLat as floatthe southern edge
minLon as floatthe western edge
maxLat as floatthe northern edge
maxLon as floatthe eastern edge
SignatureReturnsDoes
point(lat, lon)PointOne point; raises outside -90..90 / -180..180.
named(p, name)PointThe same point, named.
withElevation(p, metres)PointThe same point, at a stated elevation; raises beyond 1,000,000 m.
withTime(p, at)PointThe same point, at a stated RFC 3339 time.
document()DocumentAn empty document.
track(name, points)TrackOne track, from a list of points, as a single segment.
route(name, points)RouteOne route, from a list of points.
trackPoints(t)list of PointEvery point of a track, segments run together.
documentPoints(doc)list of PointEvery point a document holds, whatever it holds it as.
describe(doc)stringOne line saying what a document holds.

Geodesy

On a sphere of radius EARTH_RADIUS. See Measuring.

ConstantValueMeaning
EARTH_RADIUS6371008.8The Earth's mean radius in metres, IUGG R1.
NAUTICAL_MILE1852.0Metres in one nautical mile.
SignatureReturnsDoes
toRadians(degrees)floatDegrees to radians.
toDegrees(radians)floatRadians to degrees.
haversine(aLat, aLon, bLat, bLon)floatThe great-circle distance between two coordinate pairs, in metres, by the haversine formula.
distance(a, b)floatThe great-circle distance between two points, in metres.
bearing(a, b)floatThe initial bearing from one point to another, in degrees from true north, 0 <= result < 360.
finalBearing(a, b)floatThe bearing to steer on arrival, in degrees.
destination(from, degrees, metres)PointWhere you arrive setting off on a bearing and holding it for a distance.
midpoint(a, b)PointThe point half way along the great circle between two points.
pathLength(points)floatThe total length of a path, in metres.
trackDistance(t)floatThe length of a track, in metres, measured per segment.

Geometry

SignatureReturnsDoes
bounds(points)BoundsThe smallest latitude and longitude rectangle holding every point.
containsPoint(box, p)boolWhether a rectangle holds a point, edges included.
boundsCenter(box)PointThe centre of a rectangle.
centroid(points)PointThe mean position of a list of points.
crossTrackDistance(p, a, b)floatHow far a point lies off the great circle through two others, in metres.
simplify(points, tolerance)list of PointRamer-Douglas-Peucker: drop the points that move the path by tolerance metres or less.
pointInPolygon(p, polygon)boolWhether a point lies inside a polygon.
resample(points, spacing)list of PointResample a path to one point every spacing metres.
interpolate(a, b, fraction)PointA point a fraction of the way along the line between two others.

Track statistics

ConstantValueMeaning
ASCENT_THRESHOLD3.0How much a climb must rise to be counted, in metres.
MOVING_SPEED0.5How fast something must be going to count as moving, in metres per second.

TrackStats

What a recorded path adds up to.

FieldHolds
points as inthow many positions it holds
distance as floathow far it went, in metres
ascent as floathow much it climbed, in metres
descent as floathow much it dropped, in metres
minElevation as floatthe lowest elevation, in metres
maxElevation as floatthe highest elevation, in metres
hasElevation as boolwhether any point carried an elevation
totalSeconds as intseconds from the first timed fix to the last
movingSeconds as intseconds of that spent at MOVING_SPEED or faster
hasTime as boolwhether the timing fields mean anything
averageSpeed as floatmetres per second over movingSeconds
maxSpeed as floatthe fastest leg, in metres per second
SignatureReturnsDoes
statsOf(points)TrackStatsMeasure a recorded path.
statsWith(points, climbThreshold, movingSpeed)TrackStatsMeasure a recorded path, with the thresholds stated.
secondsBetween(from, to2)intSeconds between two RFC 3339 timestamps, or -1 when either does not parse.

Geohashes

See Addressing.

ConstantValueMeaning
GEOHASH_ALPHABET"0123456789bcdefghjkmnpqrstuvwxyz"The 32 characters a geohash is spelled with.
GEOHASH_LENGTH9A default length to pass to geohash: a cell of about 4.8 m.
SignatureReturnsDoes
geohash(p, length)stringA point as a geohash of 1 to 20 characters.
geohashBounds(hash)BoundsThe box a geohash names.
geohashDecode(hash)PointThe centre of the box a geohash names.

Map tiles

Web Mercator slippy-map tiles. See Addressing.

ConstantValueMeaning
MERCATOR_LIMIT85.0511287798The northern and southern limit of Web Mercator, in degrees.
MAX_ZOOM22The largest zoom level a tile address is defined for.

Tile

One map tile.

FieldHolds
x as inthow far east, 0 to 2^z - 1
y as inthow far south, 0 to 2^z - 1
z as intthe zoom level
SignatureReturnsDoes
tileOf(p, zoom)TileThe tile a point falls in.
tileBounds(t)BoundsThe box a tile covers.
quadkey(t)stringA tile as a Bing Maps quadkey.

GPX

Reads GPX 1.0 and 1.1, writes 1.1. See GPX.

ConstantValueMeaning
GPX_NAMESPACE"http://www.topografix.com/GPX/1/1"The namespace a GPX 1.1 document declares.
GPX_CREATOR"@deckyard/geo"What this deck writes in a GPX creator attribute.
SignatureReturnsDoes
readGpx(text)DocumentRead a GPX document.
writeGpx(doc)stringWrite a document as GPX 1.1.

KML and KMZ

See KML and KMZ.

ConstantValueMeaning
KML_NAMESPACE"http://www.opengis.net/kml/2.2"The namespace a KML 2.2 document declares.
KMZ_ENTRY"doc.kml"The entry a KMZ archive keeps its document in.
SignatureReturnsDoes
readKml(text)DocumentRead a KML document.
writeKml(doc)stringWrite a document as KML 2.2.
readKmz(data)DocumentRead a KMZ archive.
writeKmz(doc)bytesWrite a document as a KMZ archive.

GeoJSON

RFC 7946. See GeoJSON.

SignatureReturnsDoes
readGeojson(text)DocumentRead a GeoJSON document.
writeGeojson(doc)stringWrite a document as a GeoJSON FeatureCollection.

GML geometry

The GML 3.2 geometry subset. See GML geometry.

ConstantValueMeaning
GML_NAMESPACE"http://www.opengis.net/gml/3.2"The namespace a GML 3.2 document declares.
GML_CRS"urn:ogc:def:crs:EPSG::4326"The coordinate reference system this deck reads and writes GML in.
SignatureReturnsDoes
readGml(text)DocumentRead the geometries out of a GML document.
writeGml(doc)stringWrite a document as a GML 3.2 feature collection.

Files and formats

See Formats.

ConstantValueMeaning
FORMAT_UNKNOWN""What formatOf returns for an extension it does not recognise.
SignatureReturnsDoes
formatOf(target)string"gpx", "kml", "kmz", "geojson" or "gml", from a path's extension.
open(target)DocumentRead a file, in whichever format its extension names.
save(doc, target)nullWrite a document to a file, in whichever format its extension names.
writeText(doc, format)stringWrite a document in a named text format: gpx, kml, geojson or gml.
readText(text, format)DocumentRead a document from text in a named text format.
openGpx(target)DocumentRead a GPX file.
saveGpx(doc, target)nullWrite a document to a file as GPX 1.1.
openKml(target)DocumentRead a KML file.
saveKml(doc, target)nullWrite a document to a file as KML 2.2.
openKmz(target)DocumentRead a KMZ file.
saveKmz(doc, target)nullWrite a document to a file as KMZ.
convertFile(from, to2)DocumentOpen one file and save it as another; returns what was read.