Geospatial Capabilities
OmniSci supports a subset of object types and functions for storing and writing queries for geospatial definitions.
Geospatial Datatypes
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: 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.
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 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 poly1
:
For information about importing data, see Importing Geospatial Data.
Geospatial Literals
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:
You can create geospatial literals with a specific SRID. For example:
Support for Geography
OmniSci provides support for geography objects and geodesic distance calculations, with some limitations.
Exporting Coordinates from Immerse
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.
Distance Calculation
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:
See the tables in Geospatial Functions below for examples.
Geospatial Functions
OmniSci supports the functions listed.
Geometry Constructors
Function | Description |
| 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. Example: |
Geometry Editors
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:
|
Geometry Accessors
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. |
Spatial Relationships and Measurements
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:
|
Additional Notes
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 forPOINT
,LINESTRING
,POLYGON
, orMULTIPOLYGON
.You can use
\d table_name
to determine if the SRID is set for the geo field:If no SRID is returned, you can set the SRID using
ST_SETSRID(column_name, SRID)
. For example,ST_SETSRID(myPoint, 4326)
.
Last updated