Geometric Types

5.7. Geometric Types

Geometric data types represent two-dimensional spatial objects. Table 5-17 shows the geometric types available in PostgreSQL. The most fundamental type, the point, forms the basis for all of the other types.

Table 5-17. Geometric Types

Geometric TypeStorageRepresentationDescription
point16 bytes(x,y)Point in space
line32 bytes((x1,y1),(x2,y2))Infinite line (not fully implemented)
lseg32 bytes((x1,y1),(x2,y2))Finite line segment
box32 bytes((x1,y1),(x2,y2))Rectangular box
path16+16n bytes((x1,y1),...)Closed path (similar to polygon)
path16+16n bytes[(x1,y1),...]Open path
polygon40+16n bytes((x1,y1),...)Polygon (similar to closed path)
circle24 bytes<(x,y),r>Circle (center and radius)

A rich set of functions and operators is available to perform various geometric operations such as scaling, translation, rotation, and determining intersections. They are explained in Section 6.9.

5.7.1. Point

Points are the fundamental two-dimensional building block for geometric types. point is specified using the following syntax:

( x , y )
  x , y

where the arguments are

x

the x-axis coordinate as a floating-point number

y

the y-axis coordinate as a floating-point number

5.7.2. Line Segment

Line segments (lseg) are represented by pairs of points. lseg is specified using the following syntax:

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

where the arguments are

(x1,y1)
(x2,y2)

the end points of the line segment

5.7.3. Box

Boxes are represented by pairs of points that are opposite corners of the box. box is specified using the following syntax:

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

where the arguments are

(x1,y1)
(x2,y2)

opposite corners of the box

Boxes are output using the first syntax. The corners are reordered on input to store the upper right corner, then the lower left corner. Other corners of the box can be entered, but the lower left and upper right corners are determined from the input and stored corners.

5.7.4. Path

Paths are represented by connected sets of points. Paths can be open, where the first and last points in the set are not connected, and closed, where the first and last point are connected. Functions popen(p) and pclose(p) are supplied to force a path to be open or closed, and functions isopen(p) and isclosed(p) are supplied to test for either type in a query.

path is specified using the following syntax:

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

where the arguments are

(x,y)

End points of the line segments comprising the path. A leading square bracket ([) indicates an open path, while a leading parenthesis (() indicates a closed path.

Paths are output using the first syntax.

5.7.5. Polygon

Polygons are represented by sets of points. Polygons should probably be considered equivalent to closed paths, but are stored differently and have their own set of support routines.

polygon is specified using the following syntax:

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

where the arguments are

(x,y)

End points of the line segments comprising the boundary of the polygon

Polygons are output using the first syntax.

5.7.6. Circle

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

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

where the arguments are

(x,y)

center of the circle

r

radius of the circle

Circles are output using the first syntax.

Home
Online Resources
General
Beginner Tutorials
MySQL
PostgreSQL
Oracle
mSQL
Microsoft SQL
Contact Us
Random quote of the moment:
You can write a small letter to Grandma in the filename. -- Forbes Burkowski, CS, University of Washington
 
http://www.sql.org/
 
Proudly designed and hosted by OmegaSphere, providers of all your Web Hosting, SSL Certificate, and Domain Name needs!