The GEOMETRY Data Type

MatrixOne supports the GEOMETRY spatial data type for storing and manipulating geographic and geometric data. Geometries are stored internally as WKB (Well-Known Binary) and can be created from WKT (Well-Known Text) or WKB input. SRID metadata is tracked at the column or expression type level rather than in the WKB payload. GEOMETRY values can be constrained by subtype and SRID at the column level.

Syntax

Column declaration syntax for CREATE TABLE and ALTER TABLE statements:

column_name GEOMETRY [SRID n]
column_name POINT [SRID n]
column_name LINESTRING [SRID n]
column_name POLYGON [SRID n]
column_name MULTIPOINT [SRID n]
column_name MULTILINESTRING [SRID n]
column_name MULTIPOLYGON [SRID n]
column_name GEOMETRYCOLLECTION [SRID n]

32-bit float coordinate variants:

column_name GEOMETRY32 [SRID n]
column_name POINT32 [SRID n]
column_name POLYGON32 [SRID n]

GEOGRAPHY aliases with implicit default SRID 4326:

column_name GEOGRAPHY
column_name GEOGRAPHY32

For example, declaring a column for geodetic point coordinates:

CREATE TABLE places (
    id INT,
    loc POINT SRID 4326
);

Arguments

Subtype Names

When declaring a GEOMETRY column, you can optionally specify a subtype name. A column declared with a specific subtype (for example, POINT) enforces that only geometries of that subtype can be stored. A generic GEOMETRY column accepts any geometry subtype.

Type Name

Constraint

GEOMETRY

Accepts any geometry subtype (no constraint).

POINT

Accepts only POINT values.

LINESTRING

Accepts only LINESTRING values.

POLYGON

Accepts only POLYGON values.

MULTIPOINT

Accepts only MULTIPOINT values.

MULTILINESTRING

Accepts only MULTILINESTRING values.

MULTIPOLYGON

Accepts only MULTIPOLYGON values.

GEOMETRYCOLLECTION

Accepts only GEOMETRYCOLLECTION values.

MatrixOne also provides 32-bit float coordinate variants (GEOMETRY32, POINT32, POLYGON32) and geodetic aliases GEOGRAPHY and GEOGRAPHY32 (which set a default SRID of 4326). See Type Hierarchy and 32-bit Float Variants for details.

SRID Attribute

The optional SRID n clause specifies the Spatial Reference System Identifier for the column. A column with an SRID constraint only accepts geometries whose SRID matches the specified value. Attempting to insert a geometry with a mismatched SRID produces an error.

Examples

The following example demonstrates subtype-constrained columns, generic geometry storage, and SRID column behavior:

DROP DATABASE IF EXISTS geo_demo;
CREATE DATABASE geo_demo;
USE geo_demo;

-- A generic geometry column accepts any subtype.
CREATE TABLE any_geom (
    id INT,
    g GEOMETRY
);
INSERT INTO any_geom VALUES
    (1, ST_GeomFromText('POINT(1 2)')),
    (2, ST_GeomFromText('LINESTRING(0 0, 3 4)')),
    (3, ST_GeomFromText('POLYGON((0 0, 2 0, 2 2, 0 2, 0 0))'));
SELECT id, ST_AsText(g) AS wkt FROM any_geom ORDER BY id;
SELECT id, ST_GeometryType(g) AS gtype FROM any_geom ORDER BY id;

-- A subtype-constrained column accepts only its subtype.
CREATE TABLE points_only (g POINT);
INSERT INTO points_only VALUES (ST_GeomFromText('POINT(1 1)'));

-- This insert is rejected because the input is a LINESTRING, not a POINT.
-- Expected-Success: false
INSERT INTO points_only VALUES (ST_GeomFromText('LINESTRING(0 0, 1 1)'));
;

-- SRID column example.
CREATE TABLE gs (g POINT SRID 4326);
INSERT INTO gs VALUES (ST_GeomFromText('POINT(1 1)', 4326));
SELECT ST_AsText(g) AS wkt, ST_SRID(g) AS srid FROM gs;

-- Mismatched SRID is rejected.
-- Expected-Success: false
INSERT INTO gs VALUES (ST_GeomFromText('POINT(3 3)', 0));
;

DROP TABLE any_geom;
DROP TABLE points_only;
DROP TABLE gs;
DROP DATABASE geo_demo;

Type Hierarchy

The GEOMETRY type is the base type for all spatial values. The following subtype aliases are available as column type names:

Type Name

Description

GEOMETRY

Base type; accepts any geometry subtype.

POINT

A single point (x, y).

LINESTRING

A sequence of points forming a line.

POLYGON

A planar surface defined by one exterior ring and zero or more interior rings (holes).

MULTIPOINT

A collection of points.

MULTILINESTRING

A collection of linestrings.

MULTIPOLYGON

A collection of polygons.

GEOMETRYCOLLECTION

A heterogeneous collection of any geometry types.

32-bit Float Variants

MatrixOne provides 32-bit float coordinate variants for reduced storage. These are MO-specific extensions:

Type Name

Description

GEOMETRY32

Generic geometry with float32 coordinates.

POINT32

Point with float32 coordinates.

POLYGON32

Polygon with float32 coordinates.

GEOGRAPHY

Alias for GEOMETRY with default SRID 4326 (geodetic).

GEOGRAPHY32

Alias for GEOMETRY32 with default SRID 4326.

Storage Format

Geometries are stored internally as WKB (Well-Known Binary). When a geometry value is rendered in query output, it is displayed in its canonical WKT form. WKB binary I/O is supported via ST_GeomFromWKB / ST_AsWKB.

WKT / WKB I/O Reference

Geometries can be created from and converted to WKT and WKB:

Function

Description

ST_GeomFromText(wkt [, srid])

Create geometry from WKT string; optional SRID.

ST_GeometryFromText(wkt [, srid])

Synonym for ST_GeomFromText.

ST_AsText(geom)

Return the canonical WKT representation.

ST_AsWKT(geom)

Synonym for ST_AsText.

ST_GeomFromWKB(wkb)

Create geometry from WKB binary.

ST_AsWKB(geom)

Return the WKB binary representation.

ST_AsBinary(geom)

Synonym for ST_AsWKB.

ST_GeomFromBinary(wkb)

Synonym for ST_GeomFromWKB.

Typed Constructor Functions

Each geometry subtype has a dedicated constructor function that validates the WKT input matches the expected type:

Function

Expected Type

ST_PointFromText(wkt)

POINT

ST_LineFromText(wkt)

LINESTRING

ST_LinestringFromText(wkt)

Synonym for ST_LineFromText.

ST_PolyFromText(wkt)

POLYGON

ST_PolygonFromText(wkt)

Synonym for ST_PolyFromText.

ST_MPointFromText(wkt)

MULTIPOINT

ST_MLineFromText(wkt)

MULTILINESTRING

ST_MPolyFromText(wkt)

MULTIPOLYGON

ST_GeomCollFromText(wkt)

GEOMETRYCOLLECTION

ST_PointFromWKB(wkb)

POINT (from WKB)

ST_PolyFromWKB(wkb)

POLYGON (from WKB)

Subtype mismatch is rejected with an error. For example, calling ST_PointFromText with a LINESTRING WKT produces an error.

See Also

For the complete list of spatial functions, see Geo Functions Overview.