Les fonctions de construction spatiale créent et convertissent des objets géométriques dans AnalyticDB for MySQL. Utilisez-les pour construire des géométries POINT, LINESTRING et POLYGON à partir de coordonnées ou de texte, convertir entre les représentations Well-Known Text (WKT) et Well-Known Binary (WKB), et passer des systèmes de coordonnées plans aux systèmes sphériques.
La plupart des fonctions spatiales renvoient une valeur GEOMETRY binaire. Interroger directement ces valeurs avecSELECTproduit un résultat illisible. Enveloppez le résultat avecST_AsText()pour obtenir une chaîne WKT lisible.
Résumé des fonctions
| Catégorie | Fonction | Description |
|---|---|---|
| Construction à partir de coordonnées | ST_Point |
Construit un point à partir des coordonnées x et y |
| Construction à partir de WKT | ST_GeometryFromText / ST_GeomFromText |
Construit n'importe quel type de géométrie à partir d'une chaîne WKT |
ST_LineFromText |
Construit une LineString à partir d'une chaîne WKT | |
ST_PointFromText |
Construit un point à partir d'une chaîne WKT | |
ST_PolygonFromText |
Construit un polygone à partir d'une chaîne WKT | |
| Construction à partir de tableaux de points | ST_LineString |
Construit une LineString à partir d'un tableau de points |
ST_MultiPoint |
Construit un MultiPoint à partir d'un tableau de points | |
| Conversion en texte | ST_AsText |
Convertit une géométrie en sa représentation WKT |
| Conversion vers/depuis le binaire | ST_AsBinary |
Convertit une géométrie en sa représentation WKB |
ST_GeomFromBinary |
Construit une géométrie à partir d'une valeur WKB | |
| Validation | ST_IsValidWKT |
Vérifie si une chaîne est un WKT valide |
| Système de coordonnées | To_spherical_geography |
Convertit une géométrie plane en objet géographique sphérique |
To_geometry |
Reconvertit un objet géographique sphérique en géométrie plane | |
| Interopérabilité Hadoop | Geometry_from_hadoop_shape |
Construit une géométrie à partir d'une valeur binaire Spatial Framework for Hadoop |
| Tampon | ST_Buffer |
Renvoie tous les points situés à une distance d d'une géométrie |
ST_Point
ST_Point(x double, y double) → GEOMETRY (subtype POINT)
Renvoie une géométrie POINT à partir des valeurs de coordonnées x et y spécifiées. La valeur de retour est binaire ; enveloppez-la avec ST_AsText() pour obtenir un résultat lisible.
Exemple
SELECT ST_AsText(ST_Point(1, 1));
Résultat :
+--------------------------+
| ST_AsText(ST_Point(1,1)) |
+--------------------------+
| POINT (1 1) |
+--------------------------+
ST_AsText
ST_AsText(geometry) → WKT
Renvoie la représentation Well-Known Text (WKT) d'une géométrie. Utilisez cette fonction pour convertir la sortie binaire d'autres fonctions spatiales en texte lisible.
Exemple
SELECT ST_AsText(ST_Point(1, 1));
Résultat :
+--------------------------+
| ST_AsText(ST_Point(1,1)) |
+--------------------------+
| POINT (1 1) |
+--------------------------+
ST_GeometryFromText / ST_GeomFromText
ST_GeometryFromText(wkt varchar) → GEOMETRY
ST_GeomFromText(wkt varchar) → GEOMETRY
Construit un objet géométrique à partir d'une chaîne WKT. ST_GeometryFromText et ST_GeomFromText sont équivalentes. La valeur de retour est binaire ; enveloppez-la avec ST_AsText() pour obtenir un résultat lisible.
Exemple
SELECT ST_AsText(ST_GeometryFromText('Point(1 1)'));
Résultat :
+----------------------------------------------+
| ST_AsText(ST_GeometryFromText('Point(1 1)')) |
+----------------------------------------------+
| POINT (1 1) |
+----------------------------------------------+
ST_IsValidWKT
ST_IsValidWKT(wkt varchar) → INT
Renvoie 1 si la chaîne d'entrée est un WKT valide, ou 0 dans le cas contraire.
Exemple
SELECT ST_IsValidWKT('MULTIPOINT (1 2, 2 4, 3 6, 4 8)');
Résultat :
+---------------------------------------------------+
| ST_IsValidWKT('MULTIPOINT (1 2, 2 4, 3 6, 4 8)') |
+---------------------------------------------------+
| 1 |
+---------------------------------------------------+
ST_LineFromText
ST_LineFromText(wkt varchar) → GEOMETRY
Renvoie une géométrie LineString à partir d'une chaîne WKT. La valeur de retour est binaire ; enveloppez-la avec ST_AsText() pour obtenir un résultat lisible.
Exemple
SELECT ST_AsText(ST_LineFromText('LINESTRING (1 1, 2 2, 1 3)'));
Résultat :
+----------------------------------------------------------+
| ST_AsText(ST_LineFromText('LINESTRING (1 1, 2 2, 1 3)')) |
+----------------------------------------------------------+
| LINESTRING (1 1, 2 2, 1 3) |
+----------------------------------------------------------+
ST_PointFromText
ST_PointFromText(wkt varchar) → GEOMETRY
Renvoie un objet Point à partir d'une chaîne WKT. La valeur de retour est binaire ; enveloppez-la avec ST_AsText() pour obtenir un résultat lisible.
Exemple
SELECT ST_AsText(ST_PointFromText('POINT (1 2)'));
Résultat :
+-------------------------------------------+
| ST_AsText(ST_PointFromText('POINT (1 2)')) |
+-------------------------------------------+
| POINT (1 2) |
+-------------------------------------------+
ST_PolygonFromText
ST_PolygonFromText(wkt varchar) → GEOMETRY
Renvoie un objet Polygon à partir d'une chaîne WKT. La valeur de retour est binaire ; enveloppez-la avec ST_AsText() pour obtenir un résultat lisible.
Exemple
SELECT ST_AsText(ST_PolygonFromText('POLYGON ((1 1, 1 4, 4 4, 4 1))'));
Résultat :
+----------------------------------------------------------------+
| ST_AsText(ST_PolygonFromText('POLYGON ((1 1, 1 4, 4 4, 4 1))')) |
+----------------------------------------------------------------+
| POLYGON ((1 1, 1 4, 4 4, 4 1)) |
+----------------------------------------------------------------+
ST_LineString
ST_LineString(array(Point)) → GEOMETRY
Renvoie une géométrie LineString construite à partir d'un tableau de géométries de points. La valeur de retour est binaire ; enveloppez-la avec ST_AsText() pour obtenir un résultat lisible.
Exemple
SELECT ST_AsText(ST_LineString(array[ST_Point(1, 2), ST_Point(3, 4)]));
Résultat :
+------------------------------------------------------------------+
| ST_AsText(ST_LineString(array[ST_Point(1,2), ST_Point(3,4)])) |
+------------------------------------------------------------------+
| LINESTRING (1 2, 3 4) |
+------------------------------------------------------------------+
ST_MultiPoint
ST_MultiPoint(array(Point)) → GEOMETRY
Renvoie une géométrie MultiPoint construite à partir d'un tableau de géométries de points. La valeur de retour est binaire ; enveloppez-la avec ST_AsText() pour obtenir un résultat lisible.
Exemple
SELECT ST_AsText(
ST_MultiPoint(array[
ST_GeometryFromText('POINT(1 2)'),
ST_GeometryFromText('POINT (3 4)')
])
);
Résultat :
+---------------------------+
| ST_AsText(...) |
+---------------------------+
| MULTIPOINT ((1 2), (3 4)) |
+---------------------------+
ST_GeomFromBinary
ST_GeomFromBinary(wkb varbinary) → GEOMETRY
Renvoie une géométrie à partir d'une valeur Well-Known Binary (WKB). La valeur de retour est binaire ; enveloppez-la avec ST_AsText() pour obtenir un résultat lisible.
Exemple
L'exemple suivant convertit une géométrie en WKB avec ST_AsBinary(), puis la reconstruit et la lit avec ST_GeomFromBinary() et ST_AsText().
SELECT ST_AsText(
ST_GeomFromBinary(
ST_AsBinary(ST_GeometryFromText('MULTIPOINT ((1 2), (3 4))'))
)
);
Résultat :
+---------------------------+
| ST_AsText(...) |
+---------------------------+
| MULTIPOINT ((1 2), (3 4)) |
+---------------------------+
Geometry_from_hadoop_shape
Geometry_from_hadoop_shape(wkb varbinary) → GEOMETRY
Renvoie une géométrie à partir d'une valeur binaire Spatial Framework for Hadoop. La valeur de retour est binaire ; enveloppez-la avec ST_AsText() pour obtenir un résultat lisible.
Exemple
SELECT ST_AsText(
Geometry_from_hadoop_shape(
from_hex('000000000101000000000000000000F03F0000000000000040')
)
);
Résultat :
+---------------------+
| ST_AsText(...) |
+---------------------+
| POINT (1 2) |
+---------------------+
To_spherical_geography
To_spherical_geography(geometry) → GEOMETRY
Convertit une géométrie plane en objet géographique sphérique. Cette opération transforme un identifiant défini dans un espace 2D en un identifiant défini dans un espace 3D. La valeur de retour est binaire.
Exemple
SELECT To_spherical_geography(ST_Point(-71.0882, 42.3607));
To_geometry
To_geometry(geography) → GEOMETRY
Reconvertit un objet géographique sphérique en géométrie plane. Chaque objet géographique constitue un objet géométrique valide. La valeur de retour est binaire ; enveloppez-la avec ST_AsText() pour obtenir un résultat lisible.
Exemple
SELECT ST_AsText(
To_geometry(To_spherical_geography(ST_Point(61.56, -58.54)))
);
Résultat :
+----------------------+
| ST_AsText(...) |
+----------------------+
| POINT (61.56 -58.54) |
+----------------------+
ST_AsBinary
ST_AsBinary(geometry) → VARBINARY
Renvoie la représentation WKB d'une géométrie sous forme de valeur VARBINARY. Utilisez cette fonction pour stocker ou transmettre des données géométriques au format binaire, puis les reconstruire avec ST_GeomFromBinary().
Exemple
SELECT ST_AsText(
ST_GeomFromBinary(
ST_AsBinary(ST_GeometryFromText('MULTIPOINT ((1 2), (3 4))'))
)
);
Résultat :
+---------------------------+
| ST_AsText(...) |
+---------------------------+
| MULTIPOINT ((1 2), (3 4)) |
+---------------------------+
ST_Buffer
ST_Buffer(geometry, d double) → GEOMETRY
Renvoie une géométrie contenant tous les points dont la distance par rapport à la géométrie d'entrée est inférieure ou égale à d. Pour une entrée de type point, le résultat est un polygone qui approxime un cercle de rayon d centré sur ce point. La valeur de retour est binaire ; enveloppez-la avec ST_AsText() pour obtenir un résultat lisible.
Exemple
SELECT ST_AsText(ST_Buffer(ST_Point(0, 0), 0.5));
Résultat (abrégé) :
+--------------------------------------------------------------------+
| ST_AsText(ST_Buffer(ST_Point(0, 0), 0.5)) |
+--------------------------------------------------------------------+
| POLYGON ((0.5 0, 0.4989294616193014 0.03270156461507146, ...)) |
+--------------------------------------------------------------------+
Le résultat complet est un polygone qui approxime un cercle de rayon 0,5 centré à l'origine. Le polygone est défini par 96 sommets.