Geometry
Any one of the six geometries, sent as the GeoJSON geometry it holds.
Geospatial; not ordered; since Jadpo 0.1.0.
Make one
Pick one of its variants and give its fields, Geometry.point { point: ... }.
These operations give one: geo.from_geojson and geo.from_wkt.
Variants
| Variant | Fields |
|---|---|
point |
point: Point |
line_string |
line_string: LineString |
polygon |
polygon: Polygon |
multi_point |
multi_point: MultiPoint |
multi_line_string |
multi_line_string: MultiLineString |
multi_polygon |
multi_polygon: MultiPolygon |
Text, JSON and storage
It has no single text form, so text.from and text.parse don't take it. JSON sends a GeoJSON geometry, its positions longitude first.
| JSON |
|---|
{"type":"Point","coordinates":[-0.1276,51.5072]} |
{"type":"LineString","coordinates":[[0,0],[1,1]]} |
{"type":"Polygon","coordinates":[[[0,0],[1,0],[1,1],[0,1],[0,0]]]} |
{"type":"MultiPoint","coordinates":[[0,0],[1,1]]} |
{"type":"MultiLineString","coordinates":[[[0,0],[1,1]]]} |
{"type":"MultiPolygon","coordinates":[[[[0,0],[1,0],[1,1],[0,1],[0,0]]]]} |
It is stored in one column named for the field, of type geography. {"type":"MultiPoint","coordinates":[[0,0],[1,1]]} is stored as 'SRID=4326;MULTIPOINT (0 0, 1 1)'::geography.
Shown to people
text.format(value, locale:) shows it to people in their locale.
With locale: Locale.en_gb:
| Value | Shown |
|---|---|
{"type":"Point","coordinates":[-0.1276,51.5072]} |
51.5072° N, 0.1276° W |
{"type":"LineString","coordinates":[[0,0],[1,1]]} |
(0°, 0°; 1° N, 1° E) |
{"type":"Polygon","coordinates":[[[0,0],[1,0],[1,1],[0,1],[0,0]]]} |
((0°, 0°; 0°, 1° E; 1° N, 1° E; 1° N, 0°; 0°, 0°)) |
{"type":"MultiPoint","coordinates":[[0,0],[1,1]]} |
(0°, 0°; 1° N, 1° E) |
{"type":"MultiLineString","coordinates":[[[0,0],[1,1]]]} |
((0°, 0°; 1° N, 1° E)) |
{"type":"MultiPolygon","coordinates":[[[[0,0],[1,0],[1,1],[0,1],[0,0]]]]} |
(((0°, 0°; 0°, 1° E; 1° N, 1° E; 1° N, 0°; 0°, 0°))) |
Operations
geo.bounding_box(shape: T) -> BoundingBox: The smallest box of parallels and meridians holding the shape, an edge's highest or lowest point counted, across the antimeridian when that box is narrower; a shape holding a pole runs from -180 to 180.geo.centroid(shape: T) -> Point: The shape's centre on the sphere, as PostGIS'sST_Centroid(x, false)finds it: each point a unit vector, weighted by area, length or count by the shape's kind, summed, and back to latitude and longitude. It may lie outside a concave polygon.geo.contains(a: T, b: U) -> Bool: Whether no point ofblies outsidea, edges included.amay be aBoundingBox, whose sides are compared directly, or aCircle, holding the points within its radius of its centre.geo.from_geojson(text: Text) -> Geometry: The geometry GeoJSON text (RFC 7946) writes, each position longitude first:{"type":"Point","coordinates":[-0.1276,51.5072]}, any of the six, held as theGeometryof its kind, each ring wound by the right-hand rule. A coordinate out of its range fails without_of_range, and text that isn't one of the six geometries, a polygon whose rings aren't valid or a geometry mixing altitudes included, withmalformed, which the call'sattemptmaps.geo.from_wkt(text: Text) -> Geometry: The geometry WKT or EWKT text writes, longitude first:POLYGON((-0.2 51.49,-0.05 51.49,-0.05 51.54,-0.2 51.49)), any of the six, withZfor an altitude, held as theGeometryof its kind.SRID=4326;may lead; another system, or a coordinate out of its range, fails without_of_range, and text that isn't one of the six geometries, a polygon whose rings aren't valid included, withmalformed, which the call'sattemptmaps.geo.intersects(a: T, b: U) -> Bool: Whether the two share at least one point, edges included.geo.to_wkt(shape: T) -> Text: The shape as WKT, longitude first, as PostGIS'sST_AsTextwrites it:POINT(-0.1276 51.5072),POINT Z (-0.1276 51.5072 35)with an altitude, each ring in the order it holds its points.geo.within(a: T, b: U, distance: Length?) -> Bool:geo.contains(b, a); or, withdistance:, whether two points are at most that far apart, asgeo.distancemeasures them.
Like every standard type, it also has the contract's own operations: text.format, json.read, json.write and ==. It isn't ordered, so < and sorting don't take it. Every standard type meets one contract says how they work.
Markdown for agents: /docs/types/type-geometry.md.Built from Jadpo main at e00e61f.