To support standard GIS objects in AsterixDB, you need to use the geometry data type as follows.
DROP dataverse GeoJSON if exists; CREATE dataverse GeoJSON; USE GeoJSON; CREATE TYPE GeometryType AS{ id : int, myGeometry : geometry }; CREATE DATASET Geometries (GeometryType) PRIMARY KEY id;
Please note that even though the SRID input is supported for certain functions and is represented internally in the correct manner the serialized result (printed in the output) displays the SRID as 4326 always because of the limitations in Esri API.
The Geometry datatype can be created by the constructor functions.
Creates a 2D,3DZ or 4D point geometry.
Example:
st_make_point(-71, 42);
{"type":"Point","coordinates":[-71,42],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}
st_make_point(1,2,1.59);
{"type":"Point","coordinates":[1,2,1.59],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}
Return a specified ST_Geometry value from Well-Known Text representation (WKT).
Example:
st_geom_from_text("LINESTRING(1 2,3 4,5 6)");
{"type":"LineString","coordinates":[[1,2],[3,4],[5,6]],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}
st_geom_from_text('MULTILINESTRING((1 2,3 4,5 6),(7 8,9 10))');
{"type":"MultiLineString","coordinates":[[[1,2],[3,4],[5,6]],[[7,8],[9,10]]],"crs":null}
Creates a geometry instance from a Well-Known Binary geometry representation (WKB) and optional SRID.
Example:
st_geom_from_wkb(hex("010100000000000000000000400000000000001440"));
{"type":"Point","coordinates":[2,5],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}
Creates a geometry instance from its GeoJSON representation
Example:
st_geom_from_geojson({"type":"Point","coordinates":[2,5],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}});
Result:
{"type":"Point","coordinates":[2,5],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}
Creates a rectangular Polygon formed from the given minimums and maximums. Input values must be in SRS specified by the SRID.
Example:
st_make_envelope(10, 10, 11, 11, 4326);
{"type":"Polygon","coordinates":[[[10,10],[11,10],[11,11],[10,11],[10,10]]],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}
There are primitive functions that take as input geometry/es and return a primitive type.
Return the area of the surface if it is a Polygon or MultiPolygon. For geometry, a 2D Cartesian area is determined with units specified by the SRID. For geography, area is determined on a curved surface with units in square meters.
Example:
st_area(st_geom_from_text('POLYGON((7 2,4 9,3 6,2.6 7,8 16))'));
26.500000000000007
Return the coordinate dimension of the Geometry value.
Example:
st_coord_dim(st_make_point(1,2));
2
Return the inherent dimension of this Geometry object, which must be less than or equal to the coordinate dimension.
Example:
st_dimension(st_geom_from_text('GEOMETRYCOLLECTION(LINESTRING(1 1,0 0),POINT(0 0))'));
1
Return the type of the geometry as a string. Eg: ‘LINESTRING’, ‘POLYGON’, ‘MULTIPOINT’, etc.
Example:
geometry_type(st_geom_from_text('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)'));
"LineString"
Return the M coordinate of the point, or NULL if not available. Input must be a point.
Example:
st_m(st_make_point(1, 2, 3, 4));
4.0
Return the number of points (vertexes) in a geometry.
Example:
st_n_points(st_geom_from_text('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)'));
4
If the geometry is a polygon or multi-polygon return the number of rings.
Example:
st_n_rings(st_geom_from_text('POLYGON((10.689 -25.092, 34.595 -20.170, 38.814 -35.639, 13.502 -39.155, 10.689 -25.092))'));
1
If geometry is a GEOMETRYCOLLECTION (or MULTI*) return the number of geometries, for single geometries will return 1, otherwise return NULL.
Example:
st_num_geometries(st_geom_from_text('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)'));
1
st_num_geometries(st_geom_from_text('GEOMETRYCOLLECTION(MULTIPOINT(-2 3 , -2 2), LINESTRING(5 5 ,10 10), POLYGON((-7 4.2,-7.1 5,-7.1 4.3,-7 4.2)))'));
3
Return the number of interior rings of a polygon geometry.
Example:
* Command:
st_num_interior_rings(st_geom_from_text("POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10),(20 30, 35 35, 30 20, 20 30))"));
1
Return the X coordinate of the point, or NULL if not available. Input must be a point.
Example:
st_x(st_make_point(1, 2, 3, 4));
1.0
Return the Y coordinate of the point, or NULL if not available. Input must be a point.
Example:
st_y(st_make_point(1, 2, 3, 4));
1.0
Return X maximum of a bounding box 2d or 3d or a geometry.
Example:
st_x_max(st_geom_from_text('POLYGON((10.689 -25.092, 34.595 -20.170, 38.814 -35.639, 13.502 -39.155, 10.689 -25.092))'));
38.814
Return the Well-Known Binary (WKB) representation of the geometry/geography without SRID meta data.
Example:
st_as_binary(st_geom_from_geojson({"type":"Point","coordinates":[2,5],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}));
"010100000000000000000000400000000000001440"
Return the geometry as a GeoJSON element.
Example:
st_as_geojson(st_geom_from_text('POLYGON((10.689 -25.092, 34.595 -20.170, 38.814 -35.639, 13.502 -39.155, 10.689 -25.092))'));
"{\"type\":\"Polygon\",\"coordinates\":[[[10.689,-25.092],[13.502,-39.155],[38.814,-35.639],[34.595,-20.17],[10.689,-25.092]]],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}}"
For geometry type Return the 2D Cartesian distance between two geometries in projected units (based on spatial ref). For geography type defaults to return minimum geodesic distance between two geographies in meters.
Example:
st_distance(st_geom_from_text('POINT(-72.1235 42.3521)'),st_geom_from_text('LINESTRING(-72.1260 42.45, -72.123 42.1546)'));
0.0015056772638282166
Return the 2D length of the geometry if it is a LineString or MultiLineString. geometry are in units of spatial reference and geography are in meters (default spheroid).
Example:
st_length(st_geom_from_text('LINESTRING(-72.1260 42.45, -72.1240 42.45666, -72.123 42.1546)'));
0.30901547439030225
Spatial predicate functions test for a relationship between two geometries and return a Boolean value (true/false).
Return TRUE if the Geometries/Geography “spatially intersect in 2D”.
Example:
st_intersects(st_geom_from_text('POINT(0 0)'), st_geom_from_text('LINESTRING ( 0 0, 0 2 )'));
true
Return TRUE if the LINESTRING’s start and end points are coincident.
Example:
st_is_closed(st_geom_from_text('LINESTRING(0 0, 0 1, 1 1, 0 0)'));
true
Return TRUE if the argument is a collection (MULTI*, GEOMETRYCOLLECTION, …)
Example:
st_is_collection(st_geom_from_text('MULTIPOINT EMPTY'));
true
Return true if this Geometry is an empty geometrycollection, polygon, point etc.
Example:
st_is_empty(st_geom_from_text('POLYGON EMPTY'));
true
Return TRUE if this LINESTRING is both closed and simple.
Example:
st_is_ring(st_geom_from_text('LINESTRING(0 0, 0 1, 1 1, 1 0, 0 0)'));
true
Return (TRUE) if this Geometry has no anomalous geometric points, such as self intersection or self tangency.
Example:
st_is_simple(st_geom_from_text('LINESTRING(1 1,2 2,2 3.5,1 3,1 2,2 1)'));
false
Return true if and only if no points of B lie in the exterior of A, and at least one point of the interior of B lies in the interior of A.
Example:
st_contains(st_geom_from_text('LINESTRING(1 1,-1 -1,2 3.5,1 3,1 2,2 1)'), st_make_point(-1, -1));
true
Return TRUE if the supplied geometries have some, but not all, interior points in common.
Example:
st_crosses(st_geom_from_text('LINESTRING(1 1,2 2,3 3,4 4, 5 5,6 6)'), st_geom_from_text('LINESTRING(0 2,1 2,2 2,3 2,4 2,5 2)'));
true
Return TRUE if the Geometries do not “spatially intersect” - if they do not share any space together.
Example:
st_disjoint(st_geom_from_text('LINESTRING(1 1,2 2,3 3,4 4, 5 5,6 6)'), st_geom_from_text('POINT(0 0)'));
true
Return true if the given geometries represent the same geometry. Directionality is ignored.
Example:
st_equals(st_geom_from_text('LINESTRING(0 0, 10 10)'), st_geom_from_text('LINESTRING(0 0, 5 5, 10 10)'));
true
Return TRUE if the Geometries share space, are of the same dimension, but are not completely contained by each other.
Example:
st_overlaps(st_geom_from_text('LINESTRING(1 1,2 2,3 3,4 4, 5 5,6 6)'), st_geom_from_text('LINESTRING(0 2,1 2,2 2,3 3,4 2,5 2)'));
true
Return true if this Geometry is spatially related to anotherGeometry, by testing for intersections between the Interior, Boundary and Exterior of the two geometries as specified by the values in the intersectionMatrixPattern.
Example:
st_relate(st_geom_from_text('LINESTRING(1 2, 3 4)'), st_geom_from_text('LINESTRING(5 6, 7 8)'), "FF1FF0102");
true
Spatial analysis functions take as input one or more geometries and return a geometry as output.
Return a geometry that represents the point set union of the Geometries.
Example:
st_union(st_geom_from_text('LINESTRING(0 0, 1 1, 0 2)'), st_geom_from_text('POINT(0 2)'));
{"type":"LineString","coordinates":[[0,0],[1,1],[0,2]],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}
Return the closure of the combinatorial boundary of this Geometry.
Example:
st_boundary(st_geom_from_text('POLYGON((1 1,0 0, -1 1, 1 1))'));
{"type":"MultiLineString","coordinates":[[[1,1],[-1,1],[0,0],[1,1]]],"crs":null}
Return the last point of a LINESTRING or CIRCULARLINESTRING geometry as a POINT.
Example:
st_end_point(st_geom_from_text('LINESTRING(1 1, 2 2, 3 3)'));
{"type":"Point","coordinates":[3,3],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}
Return a geometry representing the double precision (float8) bounding box of the supplied geometry.
Example:
st_envelope(st_geom_from_text('LINESTRING(1 1, 2 2, 3 3)'));
{"type":"Polygon","coordinates":[[[1,1],[3,1],[3,3],[1,3],[1,1]]],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}
Return a line string representing the exterior ring of the POLYGON geometry. Return NULL if the geometry is not a polygon. Will not work with MULTIPOLYGON.
Example:
st_exterior_ring(st_geom_from_text("POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10),(20 30, 35 35, 30 20, 20 30))"));
{"type":"LineString","coordinates":[[35,10],[45,45],[15,40],[10,20],[35,10]],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}
Return the 1-based Nth geometry if the geometry is a GEOMETRYCOLLECTION, (MULTI)POINT, (MULTI)LINESTRING, MULTICURVE or (MULTI)POLYGON, POLYHEDRALSURFACE. Otherwise, return NULL.
Example:
st_geometry_n(st_geom_from_text('GEOMETRYCOLLECTION(MULTIPOINT(-2 3 , -2 2),LINESTRING(5 5 ,10 10),POLYGON((-7 4.2,-7.1 5,-7.1 4.3,-7 4.2)))'),2);
{"type":"Polygon","coordinates":[[[-7,4.2],[-7.1,5],[-7.1,4.3],[-7,4.2]]],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}
Return the Nth interior linestring ring of the polygon geometry. Return NULL if the geometry is not a polygon or the given N is out of range.
Example:
st_interior_ring_n(st_geom_from_text("POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10),(20 30, 35 35, 30 20, 20 30))"), 0);
{"type":"LineString","coordinates":[[20,30],[35,35],[30,20],[20,30]],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}
Return the Nth point in the first LineString or circular LineString in the geometry. Negative values are counted backwards from the end of the LineString. Return NULL if there is no linestring in the geometry.
Example:
st_point_n(st_geom_from_text("LINESTRING(1 1, 2 2, 3 3)"), 1);
{"type":"Point","coordinates":[2,2],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}
Return the first point of a LINESTRING geometry as a POINT.
Example:
st_start_point(st_geom_from_text("LINESTRING(1 1, 2 2, 3 3)"));
{"type":"Point","coordinates":[1,1],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}
Return a geometry that represents that part of geometry A that does not intersect with geometry B.
Example:
st_difference(st_geom_from_text("LINESTRING(1 1, 2 2, 3 3)"), st_geom_from_text("POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10),(20 30, 35 35, 30 20, 20 30))"));
{"type":"LineString","coordinates":[[1,1],[2,2],[3,3]],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}
Return a geometry that represents the shared portion of geomA and geomB.
Example:
st_intersection(st_geom_from_text("LINESTRING(1 1,2 2,3 3,4 4, 5 5,6 6)"), st_geom_from_text("LINESTRING(0 2,1 2,2 2,3 3,4 2,5 2)"));
{"type":"LineString","coordinates":[[2,2],[3,3]],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}
Return a geometry that represents the portions of A and B that do not intersect. It is called a symmetric difference because ST_SymDifference(A,B) = ST_SymDifference(B,A).
Example:
st_sym_difference(st_geom_from_text("LINESTRING(1 1,2 2,3 3,4 4, 5 5,6 6)"), st_geom_from_text("LINESTRING(0 2,1 2,2 2,3 3,4 2,5 2)"));
{"type":"MultiLineString","coordinates":[[[0,2],[1,2],[2,2],[1,1]],[[5,2],[4,2],[3,3],[4,4],[5,5],[6,6]]],"crs":null}
Aggregate. Creates a GeometryCollection containing possible polygons formed from the constituent linework of a set of geometries.
Example:
st_polygonize([st_geom_from_text("LINESTRING(1 1,2 2,3 3,4 4, 5 5,6 6)"), st_geom_from_text("LINESTRING(0 2,1 2,2 2,3 3,4 2,5 2)")]);
{"type":"GeometryCollection","geometries":[{"type":"LineString","coordinates":[[1,1],[2,2],[3,3],[4,4],[5,5],[6,6]]},{"type":"LineString","coordinates":[[0,2],[1,2],[2,2],[3,3],[4,2],[5,2]]}],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}
spatial aggregate function which takes as input a set of geometries and return one geometry as the result.
Returns a geometry that represents the point set union of the Geometries.
Example:
st_union((SELECT VALUE gbu FROM [st_make_point(1.0,1.0),st_make_point(1.0,2.0)] as gbu));
{"type":"MultiPoint","coordinates":[[1,1],[1,2]],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}