Each function that belongs to this group takes a geometry value
as its argument and returns some quantitative or qualitative
property of the geometry. Some functions restrict their argument
type. Such functions return NULL
if the
argument is of an incorrect geometry type. For example,
Area()
returns
NULL
if the object type is neither
Polygon
nor MultiPolygon
.
The functions listed in this section do not restrict their argument and accept a geometry value of any type.
Returns the inherent dimension of the geometry value
g
. The result can be –1, 0, 1, or 2. The meaning of these values is given in Section 11.17.2.2, “ClassGeometry
”.mysql>
SELECT Dimension(GeomFromText('LineString(1 1,2 2)'));
+------------------------------------------------+ | Dimension(GeomFromText('LineString(1 1,2 2)')) | +------------------------------------------------+ | 1 | +------------------------------------------------+Returns the Minimum Bounding Rectangle (MBR) for the geometry value
g
. The result is returned as aPolygon
value.The polygon is defined by the corner points of the bounding box:
POLYGON((MINX MINY, MAXX MINY, MAXX MAXY, MINX MAXY, MINX MINY))
mysql>
SELECT AsText(Envelope(GeomFromText('LineString(1 1,2 2)')));
+-------------------------------------------------------+ | AsText(Envelope(GeomFromText('LineString(1 1,2 2)'))) | +-------------------------------------------------------+ | POLYGON((1 1,2 1,2 2,1 2,1 1)) | +-------------------------------------------------------+Returns as a string the name of the geometry type of which the geometry instance
g
is a member. The name corresponds to one of the instantiableGeometry
subclasses.mysql>
SELECT GeometryType(GeomFromText('POINT(1 1)'));
+------------------------------------------+ | GeometryType(GeomFromText('POINT(1 1)')) | +------------------------------------------+ | POINT | +------------------------------------------+Returns an integer indicating the Spatial Reference System ID for the geometry value
g
.In MySQL, the SRID value is just an integer associated with the geometry value. All calculations are done assuming Euclidean (planar) geometry.
mysql>
SELECT SRID(GeomFromText('LineString(1 1,2 2)',101));
+-----------------------------------------------+ | SRID(GeomFromText('LineString(1 1,2 2)',101)) | +-----------------------------------------------+ | 101 | +-----------------------------------------------+
The OpenGIS specification also defines the following functions, which MySQL does not implement:
Returns a geometry that is the closure of the combinatorial boundary of the geometry value
g
.Returns 1 if the geometry value
g
is the empty geometry, 0 if it is not empty, and –1 if the argument isNULL
. If the geometry is empty, it represents the empty point set.Currently, this function is a placeholder and should not be used. If implemented, its behavior will be as described in the next paragraph.
Returns 1 if the geometry value
g
has no anomalous geometric points, such as self-intersection or self-tangency.IsSimple()
returns 0 if the argument is not simple, and –1 if it isNULL
.The description of each instantiable geometric class given earlier in the chapter includes the specific conditions that cause an instance of that class to be classified as not simple. (See Section 11.17.2.1, “The Geometry Class Hierarchy”.)
A Point
consists of X and Y coordinates,
which may be obtained using the following functions:
Returns the X-coordinate value for the
Point
objectp
as a double-precision number.mysql>
SELECT X(POINT(56.7, 53.34));
+-----------------------+ | X(POINT(56.7, 53.34)) | +-----------------------+ | 56.7 | +-----------------------+Returns the Y-coordinate value for the
Point
objectp
as a double-precision number.mysql>
SELECT Y(POINT(56.7, 53.34));
+-----------------------+ | Y(POINT(56.7, 53.34)) | +-----------------------+ | 53.34 | +-----------------------+
A LineString
consists of
Point
values. You can extract particular
points of a LineString
, count the number of
points that it contains, or obtain its length.
Returns the
Point
that is the endpoint of theLineString
valuels
.mysql>
SET @ls = 'LineString(1 1,2 2,3 3)';
mysql>SELECT AsText(EndPoint(GeomFromText(@ls)));
+-------------------------------------+ | AsText(EndPoint(GeomFromText(@ls))) | +-------------------------------------+ | POINT(3 3) | +-------------------------------------+Returns as a double-precision number the length of the
LineString
valuels
in its associated spatial reference.mysql>
SET @ls = 'LineString(1 1,2 2,3 3)';
mysql>SELECT GLength(GeomFromText(@ls));
+----------------------------+ | GLength(GeomFromText(@ls)) | +----------------------------+ | 2.8284271247462 | +----------------------------+GLength()
is a nonstandard name. It corresponds to the OpenGISLength()
function.Returns the number of
Point
objects in theLineString
valuels
.mysql>
SET @ls = 'LineString(1 1,2 2,3 3)';
mysql>SELECT NumPoints(GeomFromText(@ls));
+------------------------------+ | NumPoints(GeomFromText(@ls)) | +------------------------------+ | 3 | +------------------------------+Returns the
N
-thPoint
in theLinestring
valuels
. Points are numbered beginning with 1.mysql>
SET @ls = 'LineString(1 1,2 2,3 3)';
mysql>SELECT AsText(PointN(GeomFromText(@ls),2));
+-------------------------------------+ | AsText(PointN(GeomFromText(@ls),2)) | +-------------------------------------+ | POINT(2 2) | +-------------------------------------+Returns the
Point
that is the start point of theLineString
valuels
.mysql>
SET @ls = 'LineString(1 1,2 2,3 3)';
mysql>SELECT AsText(StartPoint(GeomFromText(@ls)));
+---------------------------------------+ | AsText(StartPoint(GeomFromText(@ls))) | +---------------------------------------+ | POINT(1 1) | +---------------------------------------+
The OpenGIS specification also defines the following function, which MySQL does not implement:
Returns 1 if the
LineString
valuels
is closed (that is, itsStartPoint()
andEndPoint()
values are the same) and is simple (does not pass through the same point more than once). Returns 0 ifls
is not a ring, and –1 if it isNULL
.
These functions return properties of
MultiLineString
values.
Returns as a double-precision number the length of the
MultiLineString
valuemls
. The length ofmls
is equal to the sum of the lengths of its elements.mysql>
SET @mls = 'MultiLineString((1 1,2 2,3 3),(4 4,5 5))';
mysql>SELECT GLength(GeomFromText(@mls));
+-----------------------------+ | GLength(GeomFromText(@mls)) | +-----------------------------+ | 4.2426406871193 | +-----------------------------+GLength()
is a nonstandard name. It corresponds to the OpenGISLength()
function.Returns 1 if the
MultiLineString
valuemls
is closed (that is, theStartPoint()
andEndPoint()
values are the same for eachLineString
inmls
). Returns 0 ifmls
is not closed, and –1 if it isNULL
.mysql>
SET @mls = 'MultiLineString((1 1,2 2,3 3),(4 4,5 5))';
mysql>SELECT IsClosed(GeomFromText(@mls));
+------------------------------+ | IsClosed(GeomFromText(@mls)) | +------------------------------+ | 0 | +------------------------------+
These functions return properties of
Polygon
values.
Returns as a double-precision number the area of the
Polygon
valuepoly
, as measured in its spatial reference system.mysql>
SET @poly = 'Polygon((0 0,0 3,3 0,0 0),(1 1,1 2,2 1,1 1))';
mysql>SELECT Area(GeomFromText(@poly));
+---------------------------+ | Area(GeomFromText(@poly)) | +---------------------------+ | 4 | +---------------------------+Returns the exterior ring of the
Polygon
valuepoly
as aLineString
.mysql>
SET @poly =
->'Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))';
mysql>SELECT AsText(ExteriorRing(GeomFromText(@poly)));
+-------------------------------------------+ | AsText(ExteriorRing(GeomFromText(@poly))) | +-------------------------------------------+ | LINESTRING(0 0,0 3,3 3,3 0,0 0) | +-------------------------------------------+Returns the
N
-th interior ring for thePolygon
valuepoly
as aLineString
. Rings are numbered beginning with 1.mysql>
SET @poly =
->'Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))';
mysql>SELECT AsText(InteriorRingN(GeomFromText(@poly),1));
+----------------------------------------------+ | AsText(InteriorRingN(GeomFromText(@poly),1)) | +----------------------------------------------+ | LINESTRING(1 1,1 2,2 2,2 1,1 1) | +----------------------------------------------+Returns the number of interior rings in the
Polygon
valuepoly
.mysql>
SET @poly =
->'Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))';
mysql>SELECT NumInteriorRings(GeomFromText(@poly));
+---------------------------------------+ | NumInteriorRings(GeomFromText(@poly)) | +---------------------------------------+ | 1 | +---------------------------------------+
These functions return properties of
MultiPolygon
values.
Returns as a double-precision number the area of the
MultiPolygon
valuempoly
, as measured in its spatial reference system.mysql>
SET @mpoly =
->'MultiPolygon(((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1)))';
mysql>SELECT Area(GeomFromText(@mpoly));
+----------------------------+ | Area(GeomFromText(@mpoly)) | +----------------------------+ | 8 | +----------------------------+
The OpenGIS specification also defines the following functions, which MySQL does not implement:
Returns the mathematical centroid for the
MultiPolygon
valuempoly
as aPoint
. The result is not guaranteed to be on theMultiPolygon
.Returns a
Point
value that is guaranteed to be on theMultiPolygon
valuempoly
.
These functions return properties of
GeometryCollection
values.
Returns the
N
-th geometry in theGeometryCollection
valuegc
. Geometries are numbered beginning with 1.mysql>
SET @gc = 'GeometryCollection(Point(1 1),LineString(2 2, 3 3))';
mysql>SELECT AsText(GeometryN(GeomFromText(@gc),1));
+----------------------------------------+ | AsText(GeometryN(GeomFromText(@gc),1)) | +----------------------------------------+ | POINT(1 1) | +----------------------------------------+Returns the number of geometries in the
GeometryCollection
valuegc
.mysql>
SET @gc = 'GeometryCollection(Point(1 1),LineString(2 2, 3 3))';
mysql>SELECT NumGeometries(GeomFromText(@gc));
+----------------------------------+ | NumGeometries(GeomFromText(@gc)) | +----------------------------------+ | 2 | +----------------------------------+