| Documentation PostgreSQL 7.4.29 | ||||
|---|---|---|---|---|
| Précédent | Arrière rapide | Chapitre 9. Fonctions et opérateurs | Avance rapide | Suivant |
Les types géométriques point, box, lseg, line, path, polygon et circle ont un large ensemble de support natif de fonctions et d'opérateurs, affichés dans Tableau 9-28, Tableau 9-29 et Tableau 9-30.
Tableau 9-28. Opérateurs géométriques
| Opérateur | Description | Exemple |
|---|---|---|
| + | Translation | box '((0,0),(1,1))' + point '(2.0,0)' |
| - | Translation | box '((0,0),(1,1))' - point '(2.0,0)' |
| * | Échelle/rotation | box '((0,0),(1,1))' * point '(2.0,0)' |
| / | Échelle/rotation | box '((0,0),(2,2))' / point '(2.0,0)' |
| # | Point ou boîte d'intersection | '((1,-1),(-1,1))' # '((1,1),(-1,-1))' |
| # | Nombre de points dans le chemin ou le polygone | # '((1,0),(0,1),(-1,0))' |
| @-@ | Longueur ou circonférence | @-@ path '((0,0),(1,0))' |
| @@ | Centre | @@ circle '((0,0),10)' |
| ## | Point le plus proche entre le premier et le second opérande | point '(0,0)' ## lseg '((2,0),(0,2))' |
| <-> | Distance entre | circle '((0,0),1)' <-> circle '((5,0),1)' |
| && | Surcharge ? | box '((0,0),(1,1))' && box '((0,0),(2,2))' |
| &< | Surcharge ou à gauche de ? | box '((0,0),(1,1))' &< box '((0,0),(2,2))' |
| &> | Surcharge ou à droite de ? | box '((0,0),(3,3))' &> box '((0,0),(2,2))' |
| << | À gauche de ? | circle '((0,0),1)' << circle '((5,0),1)' |
| >> | À droite de ? | circle '((5,0),1)' >> circle '((0,0),1)' |
| <^ | En dessous de ? | circle '((0,0),1)' <^ circle '((0,5),1)' |
| >^ | Au dessus de ? | circle '((0,5),1)' >^ circle '((0,0),1)' |
| ?# | Intersection ? | lseg '((-1,0),(1,0))' ?# box '((-2,-2),(2,2))' |
| ?- | Horizontal ? | ?- lseg '((-1,0),(1,0))' |
| ?- | Sont-ils alignés horizontalement ? | point '(1,0)' ?- point '(0,0)' |
| ?| | Vertical ? | ?| lseg '((-1,0),(1,0))' |
| ?| | Sont-ils verticalement alignés ? | point '(0,1)' ?| point '(0,0)' |
| ?-| | Perpendiculaire ? | lseg '((0,0),(0,1))' ?-| lseg '((0,0),(1,0))' |
| ?|| | Parallèle ? | lseg '((-1,0),(1,0))' ?|| lseg '((-1,2),(1,2))' |
| ~ | Contient ? | circle '((0,0),2)' ~ point '(1,1)' |
| @ | Contenu ou contenant ? | point '(1,1)' @ circle '((0,0),2)' |
| ~= | Identique à ? | polygon '((0,0),(1,1))' ~= polygon '((1,1),(0,0))' |
Tableau 9-29. Fonctions géométriques
| Fonction | Type de retour | Description | Exemple |
|---|---|---|---|
area
(object) | double precision | aire | area(box '((0,0),(1,1))') |
box_intersect(box,
box) | box | boîte d'intersection | box_intersect(box '((0,0),(1,1))',box '((0.5,0.5),(2,2))') |
center
(object) | point | centre | center(box '((0,0),(1,2))') |
diameter(circle) | double precision | diamètre d'un cercle | diameter(circle '((0,0),2.0)') |
height(box) | double precision | taille verticale d'une boîte | height(box '((0,0),(1,1))') |
isclosed(path) | boolean | un chemin fermé ? | isclosed(path '((0,0),(1,1),(2,0))') |
isopen(path) | boolean | un chemin ouvert ? | isopen(path '[(0,0),(1,1),(2,0)]') |
length(object)</
entry>
| double precision | longueur | length(path '((-1,0),(1,0))') |
npoints(path) | integer | nombre de points | npoints(path '[(0,0),(1,1),(2,0)]') |
npoints(polygon) | integer | nombre de points | npoints(polygon '((1,1),(0,0))') |
pclose(path) | path | convertit un chemin en chemin fermé | popen(path '[(0,0),(1,1),(2,0)]') |
popen(path) | path | convertit un chemin en chemin ouvert | popen(path '((0,0),(1,1),(2,0))') |
radius(circle) | double precision | radius d'un cercle | radius(circle '((0,0),2.0)') |
width(box) | double precision | taille horizontale d'une boîte | width(box '((0,0),(1,1))') |
Tableau 9-30. Fonctions de conversion d'un type géométrique
| Fonction | Type de retour | Description | Exemple |
|---|---|---|---|
box(circle) | box | cercle vers boîte | box(circle '((0,0),2.0)') |
box(point,
point) | box | points vers boîte | box(point '(0,0)', point '(1,1)') |
box(polygon) | box | polygone vers boîte | box(polygon '((0,0),(1,1),(2,0))') |
circle(box) | circle | boîte vers cercle | circle(box '((0,0),(1,1))') |
circle(point, double
precision) | circle | point et radius vers cercle | circle(point '(0,0)', 2.0) |
lseg(box) | lseg | diagonale d'une boîte vers un segment de ligne | lseg(box '((-1,0),(1,0))') |
lseg(point,
point) | lseg | points vers un segment de ligne | lseg(point '(-1,0)', point '(1,0)') |
path(polygon) | point | polygone vers chemin | path(polygon '((0,0),(1,1),(2,0))') |
point(circle) | point | centre d'un cercle | point(circle '((0,0),2.0)') |
point(lseg,
lseg) | point | intersection | point(lseg '((-1,0),(1,0))', lseg '((-2,-2),(2,2))') |
point(polygon) | point | centre d'un polygone | point(polygon '((0,0),(1,1),(2,0))') |
polygon(box) | polygon | boîte vers polygone à quatre points | polygon(box '((0,0),(1,1))') |
polygon(circle) | polygon | cercle vers polygone à 12 points | polygon(circle '((0,0),2.0)') |
polygon(npts, circle) | polygon | cercle vers polygone npts-point | polygon(12, circle '((0,0),2.0)') |
polygon(path) | polygon | chemin vers polygone | polygon(path '((0,0),(1,1),(2,0))') |
Il est possible d'accéder aux deux numéros composant d'un point comme si c'était un tableau avec les index 0 et 1. Par exemple, si t.p est une colonne de type point, alors SELECT p[0] FROM t récupère les coordonnées X et UPDATE t SET p[1] = ... modifie les coordonnées Y. De la même façon, une valeur de type box ou lseg pourrait être traitée comme un tableau de deux valeurs de type point.
| Précédent | Sommaire | Suivant |
| Fonctions et opérateurs pour date/heure | Niveau supérieur | Fonctions pour le type des adresses réseau |