OmniSci supports a subset of object types and functions for storing and writing queries for geospatial definitions.
Type  Size  Example 
 Variable  A sequence of 2 or more points and the lines that connect them. For example: 
 Variable  A set of one or more polygons. For example: 
 Variable  A point described by two coordinates. When the coordinates are longitude and latitude, OmniSci stores longitude first, and then latitude. For example: 
 Variable  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 information about geospatial datatype sizes, see Storage and Compression in Datatypes.
For more information on WKT primitives, see Wikipedia: Wellknown 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, ST_SETSRID(a.pt,4326)
.
When representing longitude and latitude, the first coordinate is assumed to be longitude in OmniSci geospatial primitives.
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 straightline 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 poly1
:
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 builtin 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 nongeo 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.
Using SRID 900913 results in variance compared to SRID 4326 as polygons approach the North and South Poles.
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.
Function  Description 
 Computes the geometric center of a geometry as a POINT. 
 Return a specified geometry value from Wellknown Text representation. 
 Return a specified geometry value from Wellknown Text representation and an SRID. 
 Return a specified geography value from Wellknown Text representation. 
 Return a specified geography value from Wellknown 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. Example: 
Function  Description 
 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:

Function  Description 
 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. 
Function  Description 
 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:
<code></code> 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 POINT
, LINESTRING
, POLYGON
, or MULTIPOLYGON
.
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, ST_SETSRID(myPoint, 4326)
.