Prepare geometry

Supported in: Batch, Streaming

Prepares a geometry for downstream use, for example indexing to the ontology, by converting a geometry string into valid GeoJSON. Polygons will be closed and deduplicated. Geometries which cross the anti-meridian (as indicated by width > 180 degrees) will be split into multiple features on each side of the anti-meridian. Results will be output in a struct with two fields, "ok" and "error". The "ok" field contains the output geometry if it can be converted; otherwise, the "error" field contains a descriptive error message.

Expression categories: Geospatial

Declared arguments

  • Expression - String to be parsed and converted to GeoJSON.
    Expression<String>

Output type: Struct<ok, error>

Examples

Example 1: Base case

Argument values:

  • Expression: geometry
geometryOutput
{"type":"Polygon","coordinates":[[[0.0,0.0],[10.0,0.0],[10.0,10.0],[0.0,10.0],[0.0,0.0]]]}{
error: null,
ok: {"type":"Polygon","coordinates":[[[0.0,0.0],[0.0,10.0],[10.0,10.0],[10.0,0.0],[0.0,0.0]]]},
}
{"type":"Polygon","coordinates":[[[0.0,0.0,1.0],[1.0,0.0,1.0],[0.0,1.0,1.0],[0.0,0.0,1.0]]]}{
error: null,
ok: {"type":"Polygon","coordinates":[[[0.0,0.0,1.0],[0.0,1.0,1.0],[1.0,0.0,1.0],[0.0,0.0,1.0]]]},
}
{"type":"Polygon","coordinates":[[[0.0,0.0],[1.0,0.0], [0.0,1.0]]]}{
error: null,
ok: {"type":"Polygon","coordinates":[[[0.0,0.0],[0.0,1.0],[1.0,0.0],[0.0,0.0]]]},
}
{"type":"Polygon","coordinates":[[[0.0,0.0],[1.0,0.0], [1.0,0.0], [0.0,1.0], [0.0,0.0]]]}{
error: null,
ok: {"type":"Polygon","coordinates":[[[0.0,0.0],[0.0,1.0],[1.0,0.0],[0.0,0.0]]]},
}
{"type":"Polygon","coordinates":[[[179.0,-30.0],[-179.0,-30.0],[-179.0,30.0],[179.0,30.0],[179.0,-30]]]}{
error: null,
ok: {"type":"MultiPolygon","coordinates":[[[[-180.0,-30.0...
{"type":"LineString","coordinates":[[179.0,30.0],[-179.0,30.0]]}{
error: null,
ok: {"type":"MultiLineString","coordinates":[[[179.0,30.0],[180.0,30.0]],[[-180.0,30.0],[-179.0,30.0]]]},
}
{"type":"GeometryCollection","geometries":[{"type":"LineString","coordinates":[[40.0,10.0],[0.0,1.0]...{
error: null,
ok: {"type":"GeometryCollection","geometries":[{"type":"LineString","coordinates":[[40.0,10.0],[0.0,1.0]...,
}
{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[1.0,0.0]},{"type":"LineString","coordinates":[[179.0,30.0],[-179.0,30.0]]}]}{
error: null,
ok: {"type":"GeometryCollection","geometries":[{"type":"P...

Example 2: Base case

Argument values:

  • Expression: geometry
geometryOutput
{"type":"MultiPolygon","coordinates":[[[[102.0,2.0],[102.0,3.0],[103.0,3.0],[103.0,2.0],[102.0,2.0]]]]}{
error: null,
ok: {"type":"Polygon","coordinates":[[[102.0,2.0],[102.0,3.0],[103.0,3.0],[103.0,2.0],[102.0,2.0]]]},
}
{"type":"MultiPolygon","coordinates":[[[]],[[[102.0,2.0],[103.0,2.0],[103.0,3.0],[102.0,3.0],[102.0,2.0]]]]}{
error: null,
ok: {"type":"Polygon","coordinates":[[[102.0,2.0],[102.0,3.0],[103.0,3.0],[103.0,2.0],[102.0,2.0]]]},
}
{"type":"FeatureCollection","features":[{"geometry":{"type":"MultiPolygon","coordinates":[[[[0.0,0.0],[0.0,1.0],[1.0,0.0],[0.0,0.0]]]]},"properties":{"gaccname":"namehere"},"type":"Feature"}]}{
error: null,
ok: {"type":"Polygon","coordinates":[[[0.0,0.0],[0.0,1.0],[1.0,0.0],[0.0,0.0]]]},
}
{"type":"GeometryCollection","geometries":[{"type":"LineString","coordinates":[[40.0,11.0],[0.0,1.0]]},{"type":"LineString","coordinates":[[10.0,10.0],[20.0,20.0],[10.0,40.0]]}]}{
error: null,
ok: {"type":"MultiLineString","coordinates":[[[40.0,11.0],[0.0,1.0]],[[10.0,10.0],[20.0,20.0],[10.0,40.0]]]},
}

Example 3: Base case

Argument values:

  • Expression: geometry
geometryOutput
{"type":"Polygon","coordinates":[[[0.0,0.0],[1.0,1.0],[0.0,1.0], [1.0,0.0], [0.0,0.0]]]}{
error: null,
ok: {"type":"MultiPolygon","coordinates":[[[[0.0,0.0],[0.5,0.5],[1.0,0.0],[0.0,0.0]]],[[[0.5,0.5],[0.0,1.0],[1.0,1.0],[0.5,0.5]]]]},
}
{"type":"Polygon","coordinates":[[[0.0,0.0],[2.0,0.0],[1.0,1.0],[2.0,2.0],[0.0,2.0],[1.0,1.0],[0.0,0.0]]]}{
error: null,
ok: {"type":"MultiPolygon","coordinates":[[[[0.0,0.0],[1.0,1.0],[2.0,0.0],[0.0,0.0]]],[[[1.0,1.0],[0.0,2.0],[2.0,2.0],[1.0,1.0]]]]},
}
{"type":"Polygon","coordinates":[[[0.0,0.0],[2.0,0.0],[2.0,2.0],[0.0,2.0],[0.0,0.0]],[[0.0,0.0],[2.0,0.0],[1.0,1.0],[0.0,0.0]]]}{
error: null,
ok: {"type":"Polygon","coordinates":[[[0.0,2.0],[2.0,2.0],[2.0,0.0],[1.0,1.0],[0.0,0.0],[0.0,2.0]]]},
}
{"type":"Polygon","coordinates":[[[0.0,0.0],[1.0,0.0],[1.0,1.0],[0.0,1.0],[0.0,0.0]],[[3.0,3.0],[4.0,3.0],[4.0,4.0],[3.0,4.0],[3.0,3.0]]]}{
error: null,
ok: {"type":"MultiPolygon","coordinates":[[[[0.0,1.0],[1.0,1.0],[1.0,0.0],[0.0,0.0],[0.0,1.0]]],[[[3.0,4.0],[4.0,4.0],[4.0,3.0],[3.0,3.0],[3.0,4.0]]]]},
}

Example 4: Null case

Argument values:

  • Expression: geometry
geometryOutput
null{
error: Input is null,
ok: null,
}
Not geojson{
error: Input string could not be parsed as GeoJSON,
ok: null,
}
{"type":"Polygon","coordinates":[[[0.0,0.0],[1.0,0.0,1.0],[0.0,1.0],[0.0,0.0]]]}{
error: Coordinate dimension is mixed,
ok: null,
}
{"type":"LineString","coordinates":[[0.0,0.0]]}{
error: Invalid number of points in LineString (found 1 - must be 0 or >= 2),
ok: null,
}
{"type":"Polygon","coordinates":[[[0.0,0.0],[1.0,91.0],[0.0,1.0],[0.0,0.0]]]}{
error: Coordinates out-of-bounds. Latitudes must fall in [-90, 90] and longitudes in [-180, 180],
ok: null,
}
{"type":"Polygon","coordinates":[[[0.0,-90.1],[1.0,0.0],[0.0,1.0],[0.0,0.0]]]}{
error: Coordinates out-of-bounds. Latitudes must fall in [-90, 90] and longitudes in [-180, 180],
ok: null,
}
{"type":"Polygon","coordinates":[[[0.0,0.0],[181.0,89.0],[0.0,1.0],[0.0,0.0]]]}{
error: Coordinates out-of-bounds. Latitudes must fall in [-90, 90] and longitudes in [-180, 180],
ok: null,
}
{"type":"Polygon","coordinates":[[[0.0,0.0],[-182.0,89.0],[0.0,1.0],[0.0,0.0]]]}{
error: Coordinates out-of-bounds. Latitudes must fall in [-90, 90] and longitudes in [-180, 180],
ok: null,
}
{"type":"Polygon","coordinates":[]}{
error: Expected polygon to contain at least one ring,
ok: null,
}

Example 5: Null case

Argument values:

  • Expression: geometry
geometryOutput
{"type":"Polygon","coordinates":[[]]}{
error: Failed to parse input geometry, likely because it is malformed or incomplete,
ok: null,
}

Example 6: Edge case

Argument values:

  • Expression: geometry
geometryOutput
{"coordinates": [[[-191.9065788394177,5.453742403668187],[-191.9065788394177,-11.163604962907428],[-...{
error: null,
ok: {"type":"MultiPolygon","coordinates":[[[[-180.0,-11.163604962907428],[-180.0,5.453742403668187],[-15...,
}

Example 7: Edge case

Argument values:

  • Expression: geometry
geometryOutput
{"type":"LineString","coordinates":[[1.0, 1.0], [1.0, 1.0], [1.0, 1.0]]}{
error: null,
ok: {"type":"Point","coordinates":[1.0,1.0]},
}

Example 8: Edge case

Argument values:

  • Expression: geometry
geometryOutput
{"type":"MultiPolygon","coordinates":[[[[0.0,0.0],[1.0,0.0],[0.0,0.0]]],[[[102.0,2.0],[103.0,2.0],[103.0,3.0],[102.0,3.0],[102.0,2.0]]]]}{
error: null,
ok: {"type":"GeometryCollection","geometries":[{"type":"L...