Spatial Data Types

This feature is outdated.

MonetDB supports the Open Geospatial Consortium (OGC, formerly OpenGIS) types: Point, Curve, LineString, Surface, Polygon, MultiPoint, MultiCurve, MultiLineString, MultiSurface, MultiPolygon, Geometry and GeomCollection. One non-OpenGIS type for fast access using pre-filtering is used. This type mbr is used for storing a 2D box. Functions to create these boxes are specified in following sections.

Conversion from and to Well Known Text

The SRID parameter is a reference to the Spatial Reference System in which the coordinates are expressed.

CREATE FUNCTION GeomFromText(wkt string, srid SMALLINT) RETURNS Geometry;
CREATE FUNCTION PointFromText(wkt string, srid SMALLINT) RETURNS Point;
CREATE FUNCTION LineFromText(wkt string, srid SMALLINT) RETURNS LineString;
CREATE FUNCTION PolyFromText(wkt string, srid SMALLINT) RETURNS Polygon;
CREATE FUNCTION MPointFromText(wkt string, srid SMALLINT) RETURNS MultiPoint;
CREATE FUNCTION MLineFromText(wkt string, srid SMALLINT) RETURNS MultiLineString;
CREATE FUNCTION MPolyFromText(wkt string, srid SMALLINT) RETURNS MultiPolygon;

CREATE FUNCTION GeomCollectionFromText(wkt string, srid SMALLINT) RETURNS MultiPolygon;
-- alias
CREATE FUNCTION PolygonFromText(wkt string, srid SMALLINT) RETURNS Polygon;

CREATE FUNCTION AsText(p Point) RETURNS STRING;
CREATE FUNCTION AsText(c Curve) RETURNS STRING;
CREATE FUNCTION AsText(l LineString) RETURNS STRING;
CREATE FUNCTION AsText(s Surface) RETURNS STRING;
CREATE FUNCTION AsText(p Polygon) RETURNS STRING;
CREATE FUNCTION AsText(p MultiPoint) RETURNS STRING;
CREATE FUNCTION AsText(c MultiCurve) RETURNS STRING;
CREATE FUNCTION AsText(l MultiLineString) RETURNS STRING;
CREATE FUNCTION AsText(s MultiSurface) RETURNS STRING;
CREATE FUNCTION AsText(p MultiPolygon) RETURNS STRING;
CREATE FUNCTION AsText(g Geometry) RETURNS STRING;

Analysis functions on Geometry

The following functions perform analysis operations on geometries:

CREATE FUNCTION Area(g Geometry) RETURNS FLOAT;
CREATE FUNCTION Length(g Geometry) RETURNS FLOAT;
CREATE FUNCTION Distance(a Geometry, b Geometry) RETURNS FLOAT;
CREATE FUNCTION Buffer(a Geometry, distance FLOAT) RETURNS Geometry;
CREATE FUNCTION ConvexHull(a Geometry) RETURNS Geometry;
CREATE FUNCTION Intersection(a Geometry, b Geometry) RETURNS Geometry;
CREATE FUNCTION "Union"(a Geometry, b Geometry) RETURNS Geometry;
CREATE FUNCTION Difference(a Geometry, b Geometry) RETURNS Geometry;
CREATE FUNCTION SymDifference(a Geometry, b Geometry) RETURNS Geometry;

CREATE FUNCTION Dimension(g Geometry) RETURNS integer;
CREATE FUNCTION GeometryTypeId(g Geometry) RETURNS integer;
CREATE FUNCTION SRID(g Geometry) RETURNS integer;
CREATE FUNCTION Envelope(g Geometry) RETURNS Geometry;
CREATE FUNCTION IsEmpty(g Geometry) RETURNS BOOLEAN;
CREATE FUNCTION IsSimple(g Geometry) RETURNS BOOLEAN;
CREATE FUNCTION Boundary(g Geometry) RETURNS Geometry;

CREATE FUNCTION Equals(a Geometry, b Geometry) RETURNS BOOLEAN;
CREATE FUNCTION Disjoint(a Geometry, b Geometry) RETURNS BOOLEAN;
CREATE FUNCTION "Intersect"(a Geometry, b Geometry) RETURNS BOOLEAN;
CREATE FUNCTION Touches(a Geometry, b Geometry) RETURNS BOOLEAN;
CREATE FUNCTION Crosses(a Geometry, b Geometry) RETURNS BOOLEAN;
CREATE FUNCTION Within(a Geometry, b Geometry) RETURNS BOOLEAN;
CREATE FUNCTION Contains(a Geometry, b Geometry) RETURNS BOOLEAN;
CREATE FUNCTION Overlaps(a Geometry, b Geometry) RETURNS BOOLEAN;
CREATE FUNCTION Relate(a Geometry, b Geometry, pattern STRING) RETURNS BOOLEAN;

SQL functions on Point

CREATE FUNCTION X(g Geometry) RETURNS double;
CREATE FUNCTION Y(g Geometry) RETURNS double;
CREATE FUNCTION Point(x double,y double) RETURNS Point;

SQL functions on Curve

CREATE FUNCTION IsRing(l LineString) RETURNS BOOLEAN;
CREATE FUNCTION StartPoint(l LineString) RETURNS Point -- not yet implemented;
CREATE FUNCTION EndPoint(l LineString) RETURNS Point -- not yet implemented;

SQL functions on LineString

CREATE FUNCTION NumPoints(l LineString) RETURNS integer -- not yet implemented;
CREATE FUNCTION PointN(l LineString,i integer) RETURNS Point -- not yet implemented;

SQL functions on Surface

CREATE FUNCTION PointOnSurface(s Surface) RETURNS Point -- not yet implemented;
CREATE FUNCTION Centroid(s Surface) RETURNS Point -- not yet implemented;

SQL functions on Polygon

CREATE FUNCTION ExteriorRing(s Surface) RETURNS LineString -- not yet implemented;
CREATE FUNCTION NumInteriorRing(s Surface) RETURNS integer -- not yet implemented;
CREATE FUNCTION InteriorRingN(s Surface,n integer) RETURNS LineString -- not yet implemented;

SQL functions on GeomCollection

CREATE FUNCTION NumGeometries(GeomCollection c) RETURNS integer -- not yet implemented;
CREATE FUNCTION GeometryN(GeomCollection c,n integer) RETURNS Geometry -- not yet implemented;

SQL functions on spatial objects

The following functions return the minimum bounded rectangle (or boolean) of a given geometry:

CREATE FUNCTION mbr (p Point) RETURNS mbr;
CREATE FUNCTION mbr (c Curve) RETURNS mbr;
CREATE FUNCTION mbr (l LineString) RETURNS mbr;
CREATE FUNCTION mbr (s Surface) RETURNS mbr;
CREATE FUNCTION mbr (p Polygon) RETURNS mbr;
CREATE FUNCTION mbr (m multipoint) RETURNS mbr;
CREATE FUNCTION mbr (m multicurve) RETURNS mbr;
CREATE FUNCTION mbr (m multilinestring) RETURNS mbr;
CREATE FUNCTION mbr (m multisurface) RETURNS mbr;
CREATE FUNCTION mbr (m multipolygon) RETURNS mbr;
CREATE FUNCTION mbr (g Geometry) RETURNS mbr;
CREATE FUNCTION mbr (g GeomCollection) RETURNS mbr;
CREATE FUNCTION mbroverlaps(a mbr, b mbr) RETURNS BOOLEAN;