Guides Reference Source
public class | source

GEOMETRY

Extends:

src/data-types.js~ABSTRACT → GEOMETRY

A column storing Geometry information. It is only available in PostgreSQL (with PostGIS), MariaDB or MySQL.

GeoJSON is accepted as input and returned as output.

In PostGIS, the GeoJSON is parsed using the PostGIS function ST_GeomFromGeoJSON. In MySQL it is parsed using the function ST_GeomFromText.

Therefore, one can just follow the GeoJSON spec for handling geometry objects. See the following examples:

See:

  • DataTypes.GEOGRAPHY

Example:

Defining a Geometry type attribute
DataTypes.GEOMETRY
DataTypes.GEOMETRY('POINT')
DataTypes.GEOMETRY('POINT', 4326)
Create a new point
const point = { type: 'Point', coordinates: [-76.984722, 39.807222]}; // GeoJson format: [lng, lat]

User.create({username: 'username', geometry: point });
Create a new linestring
const line = { type: 'LineString', 'coordinates': [ [100.0, 0.0], [101.0, 1.0] ] };

User.create({username: 'username', geometry: line });
Create a new polygon
const polygon = { type: 'Polygon', coordinates: [
                [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
                  [100.0, 1.0], [100.0, 0.0] ]
                ]};

User.create({username: 'username', geometry: polygon });
Create a new point with a custom SRID
const point = {
  type: 'Point',
  coordinates: [-76.984722, 39.807222], // GeoJson format: [lng, lat]
  crs: { type: 'name', properties: { name: 'EPSG:4326'} }
};

User.create({username: 'username', geometry: point })

Constructor Summary

Public Constructor
public

constructor(type: string, srid: string)

Public Constructors

public constructor(type: string, srid: string) source

Params:

NameTypeAttributeDescription
type string
  • optional

Type of geometry data

srid string
  • optional

SRID of type