CX · Reference guidegeo
PlaygroundDownloadsAboutv0.18.0-pre.1

geo

Coordinate primitives without a new scalar kind — geometries are ordinary CXDM elements. Covers construction of points, bounding boxes, and polygons; distance and bearing (Haversine by default, high-precision Vincenty on demand); bounding-box and polygon operations including area, centroid, and point-in-polygon; WKT and GeoJSON format I/O; and longitude/latitude normalization. All coordinates are WGS84 (EPSG:4326) latitude and longitude in decimal degrees, with no reprojection or alternate coordinate systems.

geo:point

[$geo:point] -> element — Construct a point from latitude and longitude; wraps out-of-range longitude and rejects bad latitude.

      [?lib 'cx-stdlib/geo']
[?let [= $p [$geo:point 37.7749 -122.4194]] $p/lat]
    
      3.77749e1
    

geo:bbox

[$geo:bbox] -> element — Construct the minimum bounding box enclosing a sequence of points.

      [?lib 'cx-stdlib/geo']
[?let [= $bb [$geo:bbox ([$geo:point 37.7 -122.5], [$geo:point 37.85 -122.35])]] $bb/min-lat]
    
      3.77e1
    

geo:polygon

[$geo:polygon] -> element — Construct a polygon from an outer ring of points, auto-closing the ring if open.

      [?lib 'cx-stdlib/geo']
[$geo:polygon-is-closed [$geo:polygon ([$geo:point 37.7 -122.5], [$geo:point 37.7 -122.4], [$geo:point 37.8 -122.4], [$geo:point 37.8 -122.5])]]
    
      true
    

geo:polygon-with-holes

[$geo:polygon-with-holes] -> element — Construct a polygon from an outer ring plus interior hole rings.

      [?lib 'cx-stdlib/geo']
[$geo:polygon-is-closed [$geo:polygon-with-holes ([$geo:point 0.0 0.0], [$geo:point 0.0 10.0], [$geo:point 10.0 10.0], [$geo:point 10.0 0.0], [$geo:point 0.0 0.0]) (([$geo:point 2.0 2.0], [$geo:point 2.0 4.0], [$geo:point 4.0 4.0], [$geo:point 4.0 2.0], [$geo:point 2.0 2.0]))]]
    
      true
    

geo:distance

[$geo:distance] -> float — Great-circle distance between two points by the Haversine formula, in the given unit.

      [?lib 'cx-stdlib/geo']
[?lib 'cx-stdlib/math']
[$math:round [$geo:distance [$geo:point 40.7128 -74.0060] [$geo:point 33.9416 -118.4085] "km"]]
    
      3955
    

geo:distance-vincenty

[$geo:distance-vincenty] -> float — High-precision ellipsoidal distance by Vincenty; may fail to converge for near-antipodal points.

      [?lib 'cx-stdlib/geo']
[?lib 'cx-stdlib/math']
[$math:round [$geo:distance-vincenty [$geo:point 40.7128 -74.0060] [$geo:point 33.9416 -118.4085] "km"]]
    
      3963
    

geo:bearing

[$geo:bearing] -> float — Initial bearing from one point to another in degrees, where 0 is north.

      [?lib 'cx-stdlib/geo']
[$geo:bearing [$geo:point 0.0 0.0] [$geo:point 0.0 1.0]]
    
      9.0e1
    

geo:destination

[$geo:destination] -> element — Compute the endpoint reached from an origin along a bearing for a given distance.

      [?lib 'cx-stdlib/geo']
[?let [= $d [$geo:destination [$geo:point 0.0 0.0] 0.0 100.0 "km"]] $d/lon]
    
      0.0e0
    

geo:bbox-of

[$geo:bbox-of] -> element — Compute the minimum bounding box covering a sequence of points.

      [?lib 'cx-stdlib/geo']
[?let [= $bb [$geo:bbox-of ([$geo:point 37.7 -122.5], [$geo:point 37.85 -122.35], [$geo:point 37.8 -122.4])]] $bb/min-lat]
    
      3.77e1
    

geo:bbox-of-polygon

[$geo:bbox-of-polygon] -> element — Compute the bounding box enclosing a polygon.

      [?lib 'cx-stdlib/geo']
[?let [= $bb [$geo:bbox-of-polygon [$geo:polygon ([$geo:point 37.7 -122.5], [$geo:point 37.7 -122.4], [$geo:point 37.8 -122.4], [$geo:point 37.8 -122.5])]]] $bb/min-lon]
    
      -1.225e2
    

geo:within-bbox

[$geo:within-bbox] -> bool — Report whether a point lies inside a bounding box, handling antimeridian crossing.

      [?lib 'cx-stdlib/geo']
[$geo:within-bbox [$geo:point 37.75 -122.45] [$geo:bbox ([$geo:point 37.7 -122.5], [$geo:point 37.85 -122.35])]]
    
      true
    

geo:bbox-intersects

[$geo:bbox-intersects] -> bool — Report whether two bounding boxes overlap.

      [?lib 'cx-stdlib/geo']
[$geo:bbox-intersects [$geo:bbox ([$geo:point 0.0 0.0], [$geo:point 10.0 10.0])] [$geo:bbox ([$geo:point 5.0 5.0], [$geo:point 15.0 15.0])]]
    
      true
    

geo:bbox-area

[$geo:bbox-area] -> float — Compute the area of a bounding box in the given unit.

      [?lib 'cx-stdlib/geo']
[$geo:bbox-area [$geo:bbox ([$geo:point 5.0 5.0], [$geo:point 5.0 5.0])] "km2"]
    
      0.0e0
    

geo:bbox-expand

[$geo:bbox-expand] -> element — Grow a bounding box outward by a distance in meters on every side.

      [?lib 'cx-stdlib/geo']
[?let [= $bb [$geo:bbox-expand [$geo:bbox ([$geo:point 37.7 -122.5], [$geo:point 37.85 -122.35])] 0.0]] $bb/min-lat]
    
      3.77e1
    

geo:bbox-center

[$geo:bbox-center] -> element — Compute the center point of a bounding box.

      [?lib 'cx-stdlib/geo']
[?let [= $c [$geo:bbox-center [$geo:bbox ([$geo:point 0.0 0.0], [$geo:point 10.0 20.0])]]] $c/lat]
    
      5.0e0
    

geo:polygon-area

[$geo:polygon-area] -> float — Compute geodesic polygon area on the WGS84 ellipsoid in the given unit; requires a valid polygon.

      [?lib 'cx-stdlib/geo']
[$geo:polygon-area [$geo:polygon ([$geo:point 0.0 0.0], [$geo:point 0.0 1.0], [$geo:point 0.0 2.0], [$geo:point 0.0 0.0])] "km2"]
    
      cx-err:CXER3602
    

geo:polygon-perimeter

[$geo:polygon-perimeter] -> float — Compute the perimeter length of a polygon's outer ring in the given unit.

      [?lib 'cx-stdlib/geo']
[$geo:polygon-perimeter [$geo:polygon ([$geo:point 5.0 5.0], [$geo:point 5.0 5.0], [$geo:point 5.0 5.0], [$geo:point 5.0 5.0])] "km"]
    
      0.0e0
    

geo:polygon-centroid

[$geo:polygon-centroid] -> element — Compute the centroid point of a polygon.

      [?lib 'cx-stdlib/geo']
[?let [= $c [$geo:polygon-centroid [$geo:polygon ([$geo:point 0.0 0.0], [$geo:point 0.0 10.0], [$geo:point 10.0 10.0], [$geo:point 10.0 0.0], [$geo:point 0.0 0.0])]]] $c/lat]
    
      5.0e0
    

geo:point-in-polygon

[$geo:point-in-polygon] -> bool — Report whether a point lies inside a polygon by ray-casting, accounting for holes.

      [?lib 'cx-stdlib/geo']
[$geo:point-in-polygon [$geo:point 5.0 5.0] [$geo:polygon ([$geo:point 0.0 0.0], [$geo:point 0.0 10.0], [$geo:point 10.0 10.0], [$geo:point 10.0 0.0], [$geo:point 0.0 0.0])]]
    
      true
    

geo:polygon-is-valid

[$geo:polygon-is-valid] -> bool — Report whether a polygon passes the full OGC Simple Features validity check.

      [?lib 'cx-stdlib/geo']
[$geo:polygon-is-valid [$geo:polygon ([$geo:point 0.0 0.0], [$geo:point 0.0 10.0], [$geo:point 10.0 10.0], [$geo:point 10.0 0.0], [$geo:point 0.0 0.0])]]
    
      true
    

geo:polygon-is-closed

[$geo:polygon-is-closed] -> bool — Report whether a polygon's rings are closed (each ring's first point equals its last).

      [?lib 'cx-stdlib/geo']
[$geo:polygon-is-closed [$geo:polygon ([$geo:point 37.7 -122.5], [$geo:point 37.7 -122.4], [$geo:point 37.8 -122.4], [$geo:point 37.8 -122.5])]]
    
      true
    

geo:normalize-lat

[$geo:normalize-lat] -> float — Clamp a latitude into [-90, 90] — an explicit, opt-in lossy clamp for raw numeric pipelines.

      [?lib 'cx-stdlib/geo']
[$geo:normalize-lat 95.0]
    
      9.0e1
    

geo:normalize-lon

[$geo:normalize-lon] -> float — Wrap a longitude losslessly into [-180, 180], since longitude is cyclic.

      [?lib 'cx-stdlib/geo']
[$geo:normalize-lon 190.0]
    
      -1.7e2
    

geo:normalize-point

[$geo:normalize-point] -> element — Normalize a point's coordinates — wrap longitude and clamp latitude into range.

      [?lib 'cx-stdlib/geo']
[?let [= $p [$geo:normalize-point [$geo:point 45.0 190.0]]] $p/lon]
    
      -1.7e2
    

geo:normalize-bbox

[$geo:normalize-bbox] -> element — Normalize a bounding box's coordinates into valid longitude and latitude ranges.

      [?lib 'cx-stdlib/geo']
[?let [= $bb [$geo:normalize-bbox [$geo:bbox ([$geo:point 0.0 170.0], [$geo:point 10.0 190.0])]]] $bb/max-lon]
    
      -1.7e2
    

geo:is-valid-lat

[$geo:is-valid-lat] -> bool — Report whether a latitude lies within [-90, 90].

      [?lib 'cx-stdlib/geo']
[$geo:is-valid-lat 45.0]
    
      true
    

geo:is-valid-lon

[$geo:is-valid-lon] -> bool — Report whether a longitude lies within [-180, 180].

      [?lib 'cx-stdlib/geo']
[$geo:is-valid-lon 180.0]
    
      true
    

geo:parse-wkt

[$geo:parse-wkt] -> element — Parse an OGC Well-Known Text string into a geometry element.

      [?lib 'cx-stdlib/geo']
[?let [= $p [$geo:parse-wkt "POINT(-122.4194 37.7749)"]] $p/lat]
    
      3.77749e1
    

geo:format-wkt

[$geo:format-wkt] -> string — Render a geometry element as an OGC Well-Known Text string.

      [?lib 'cx-stdlib/geo']
[$geo:format-wkt [$geo:point 37.7749 -122.4194]]
    
      'POINT(-122.4194 37.7749)'
    

geo:parse-geojson

[$geo:parse-geojson] -> element — Parse an RFC 7946 GeoJSON string into a geometry or feature element.

      [?lib 'cx-stdlib/geo']
[?let [= $p [$geo:parse-geojson "{\"type\":\"Point\",\"coordinates\":[-122.4194,37.7749]}"]] $p/lat]
    
      3.77749e1
    

geo:format-geojson

[$geo:format-geojson] -> string — Render a geometry or feature element as an RFC 7946 GeoJSON string.

      [?lib 'cx-stdlib/geo']
[?let [= $p [$geo:parse-geojson [$geo:format-geojson [$geo:point 37.7749 -122.4194]]]] $p/lat]
    
      3.77749e1