OmniSci supports a subset of object types and functions for storing and writing queries for geospatial definitions.
A sequence of 2 or more points and the lines that connect them. For example:
A set of one or more polygons. For example:
A point described by two coordinates. When the coordinates are longitude and latitude, OmniSci stores longitude first, and then latitude. For example:
A set of one or more rings (closed line strings), with the first representing the shape (external ring) and the rest representing holes in that shape (internal rings). For example:
For more information on WKT primitives, see Wikipedia: Well-known Text: Geometric objects.
OmniSci supports SRID 4326 (WGS 84) and 900913 (Google Web Mercator). When using geospatial fields, you set the SRID to determine which reference system to use. OmniSci does not assign a default SRID.
CREATE TABLE simple_geo (name TEXT ENCODING DICT(32),location GEOMETRY(POINT,4326));
If you do not set the SRID of the geo field in the table, you can set it in a SQL query using
ST_SETSRID(column_name, SRID). For example,
You create geospatial objects as geometries (planar spatial data types), which are supported by the planar geometry engine at run time. When you call
ST_DISTANCE on two geometry objects, the engine returns the shortest straight-line planar distance, in degrees, between those points. For example, the following query returns the shortest distance between the point(s) in
p1 and the polygon(s) in
SELECT ST_DISTANCE(p1, poly1) FROM geo1;
For information about importing data, see Importing Geospatial Data.
Geospatial functions that expect geospatial object arguments accept geospatial columns, geospatial objects returned by other functions, or string literals containing WKT representations of geospatial objects. Supplying a WKT string is equivalent to calling a geometry constructor. For example, these two queries are identical:
SELECT COUNT(*) FROM geo1 WHERE ST_DISTANCE(p1, `POINT(1 2)`) < 1.0;SELECT COUNT(*) FROM geo1 WHERE ST_DISTANCE(p1, ST_GeomFromText('POINT(1 2)')) < 1.0;
You can create geospatial literals with a specific SRID. For example:
SELECT ST_CONTAINS(mpoly2,ST_GeomFromText('POINT(-71.064544 42.28787)', 4326))FROM geo2;
OmniSci provides support for geography objects and geodesic distance calculations, with some limitations.
OmniSciDB supports import from any coordinate system supported by the Geospatial Data Abstraction Library (GDAL). On import, OmniSciDB will convert to and store in WGS84 encoding, and rendering is accurate in Immerse.
However, no built-in way to reference the original coordinates currently exists in Immerse, and coordinates exported from Immerse will be WGS84 coordinates. You can work around this limitation by adding to the dataset a column or columns in non-geo format that could be included for display in Immerse (for exampole, in a popup) or on export.
Currently, OmniSci supports spheroidal distance calculation between:
Two points using either SRID 4326 or 900913.
A point and a polygon/multipolygon using SRID 900913.
The following query returns the points and polygons within 1,000 meters of each other:
SELECT a.poly_name, b.pt_name FROM poly a, pt bWHERE ST_Distance(ST_Transform(b.omnisci_geo, 900913),ST_Transform(b.location, 900913))<1000;
See the tables in Geospatial Functions below for examples.
OmniSci supports the functions listed.
Computes the geometric center of a geometry as a POINT.
Return a specified geometry value from Well-known Text representation.
Return a specified geometry value from Well-known Text representation and an SRID.
Return a specified geography value from Well-known Text representation.
Return a specified geography value from Well-known Text representation and an SRID.
Return a point constructed on the fly from the provided coordinate values. Constant coordinates result in construction of a POINT literal.
Returns a geometry with its coordinates transformed to a different spatial reference. Currently, WGS84 to Web Mercator transform is supported. For example:
Set the SRID to a specific integer value. For example:
Returns the X value from a POINT column.
Returns the Y value from a POINT column.
Returns X minima of a geometry.
Returns X maxima of a geometry.
Returns Y minima of a geometry.
Returns Y maxima of a geometry.
Returns the first point of a LINESTRING as a POINT.
Returns the last point of a LINESTRING as a POINT.
Return the Nth point of a LINESTRING as a POINT.
Returns the number of points in a geometry.
Returns the number of rings in a POLYGON or a MULTIPOLYGON.
Returns the spatial reference identifier for the underlying object.
Returns shortest planar distance between geometries. For example:
You can also calculate the distance between a POLYGON and a POINT. If both fields use SRID 4326, then the calculated distance is in 4326 units (degrees). If both fields use SRID 4326, and both are transformed into 900913, then the results are in 900913 units (meters).
The following SQL code returns the names of polygons where the distance between the point and polygon is less than 1,000 meters.
Returns longest planar distance between geometries. In effect, this is the diameter of a circle that encloses both geometries.For example:
Currently supported variants:
Returns true if the first geometry object contains the second object. For example:
You can also use
Returns true if two geometries intersect spatially, false if they do not share space. For example:
Returns the area of planar areas covered by POLYGON and MULTIPOLYGON geometries. For example:
Web Mercator is not an equal area projection, however. Unless compensated by a scaling factor, Web Mercator areas can vary considerably by latitude.
Returns the cartesian perimeter of POLYGON and MULTIPOLYGON geometries. For example:
Returns the cartesian length of LINESTRING geometries. For example:
Returns true if geometry A is completely within geometry B. For example the following
Returns true if the geometries are within the specified distance of each one another. Distance is specified in units defined by the spatial reference system of the geometries. For example:
Returns true if the geometries are fully within the specified distance of one another. Distance is specified in units defined by the spatial reference system of the geometries. For example:
Returns true if the geometries are spatially disjoint (that is, the geometries do not overlap or touch. For example:
You can use SQL code similar to the examples in this topic as global filters in Immerse.
CREATE TABLE AS SELECT is not currently supported for geo data types in distributed mode.
GROUP BY is not supported for
You can use
\d table_name to determine if the SRID is set for the geo field:
omnisql> \d starting_pointCREATE TABLE starting_point (name TEXT ENCODING DICT(32),myPoint GEOMETRY(POINT, 4326) ENCODING COMPRESSED(32))
If no SRID is returned, you can set the SRID using
ST_SETSRID(column_name, SRID). For example,