Updated on 2024-05-07 GMT+08:00

Geometric

Table 1 lists the geometric types that can be used in GaussDB. The most fundamental type, the point, forms the basis for all of the other types.

Table 1 Geometric types

Name

Storage Space

Description

Representation

point

16 bytes

Point on a plane

(x,y)

lseg

32 bytes

Finite line segment

((x1,y1),(x2,y2))

box

32 bytes

Rectangle

((x1,y1),(x2,y2))

path

16 + 16n bytes

Closed path (similar to polygon)

((x1,y1),...)

path

16+16n bytes

Open path

[(x1,y1),...]

polygon

40+16n bytes

Polygon (similar to closed path)

((x1,y1),...)

circle

24 bytes

Circle

<(x,y),r> (center point and radius)

A rich set of functions and operators is available in GaussDB to perform various geometric operations, such as scaling, translation, rotation, and determining intersections. For details, see Geometric Functions and Operators.

Points

Points are the fundamental two-dimensional building block for geometric types. Values of the point type are specified using either of the following syntax:

( x , y )
x , y

x and y are the respective coordinates, as floating-point numbers. The value type of the points is float8.

Points are output using the first syntax.

Example:

gaussdb=# select point(1.1, 2.2);
   point
-----------
 (1.1,2.2)
(1 row)

Line Segments

Line segments (lseg) are represented by pairs of points. Values of the lseg type are specified using any of the following syntaxes:

[ ( x1 , y1 ) , ( x2 , y2 ) ]
( ( x1 , y1 ) , ( x2 , y2 ) )
( x1 , y1 ) , ( x2 , y2 )
x1 , y1   ,   x2 , y2

(x1,y1) and (x2,y2) are the end points of the line segment. The value type of the points is float8.

Line segments are output using the first syntax.

Example:

gaussdb=# select lseg(point(1.1, 2.2), point(3.3, 4.4));
         lseg
-----------------------
 [(1.1,2.2),(3.3,4.4)]
(1 row)

Rectangles

Boxes are represented by pairs of points that are opposite corners of the box. Values of the box type are specified using any of the following syntaxes:

( ( x1 , y1 ) , ( x2 , y2 ) )
( x1 , y1 ) , ( x2 , y2 )
x1 , y1   ,   x2 , y2

(x1,y1) and (x2,y2) are any two opposite corners of the rectangle. The value type of the points is float8.

Rectangles are output using the second syntax.

Any two opposite corners can be supplied on input, but in this order, the values will be reordered as needed to store the upper right and lower left corners.

Example:

gaussdb=# select box(point(1.1, 2.2), point(3.3, 4.4));
         box
---------------------
 (3.3,4.4),(1.1,2.2)
(1 row)

Paths

Paths are represented by lists of connected points. Paths can be open, where the first and last points in the list are considered not connected, or closed, where the first and last points are considered connected.

Values of the path type are specified using any of the following syntaxes:

[ ( x1 , y1 ) , ... , ( xn , yn ) ]
( ( x1 , y1 ) , ... , ( xn , yn ) )
( x1 , y1 ) , ... , ( xn , yn )
( x1 , y1   , ... ,   xn , yn )
x1 , y1   , ... ,   xn , yn

The points are the end points of the line segments comprising the path. The value type of the points is float8. Square brackets ([]) indicate an open path, while parentheses (()) indicate a closed path. When the outermost parentheses are omitted, as in the third through fifth syntax, a closed path is assumed.

Paths are output using the first or second syntax.

Example:

gaussdb=# select path(polygon '((0,0),(1,1),(2,0))');
        path
---------------------
 ((0,0),(1,1),(2,0))
(1 row)

Polygons

Polygons are represented by lists of points (the vertexes of the polygon). Polygons are very similar to closed paths, but are stored differently and have their own set of support functions.

Values of the polygon type are specified using any of the following syntaxes:

( ( x1 , y1 ) , ... , ( xn , yn ) )
( x1 , y1 ) , ... , ( xn , yn )
( x1 , y1   , ... ,   xn , yn )
x1 , y1   , ... ,   xn , yn

A point indicates the vertex of a polygon. The value type of a point is float8.

Polygons are output using the first syntax.

Example:

gaussdb=# select polygon(box '((0,0),(1,1))');
          polygon
---------------------------
 ((0,0),(0,1),(1,1),(1,0))
(1 row)

Circles

Circles are represented by a center point and radius. Values of the circle type are specified using the following syntax:

< ( x , y ) , r >
( ( x , y ) , r )
( x , y ) , r
x , y   , r

(x,y) is the center point and r is the radius of the circle. The value type of the points is float8.

Circles are output using the first syntax.

Example:

gaussdb=# select circle(point(0,0),1);
  circle
-----------
 <(0,0),1>
(1 row)