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 aPolygonvalue.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
gis a member. The name corresponds to one of the instantiableGeometrysubclasses.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
gis 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
ghas 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
Pointobjectpas 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
Pointobjectpas 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
Pointthat is the endpoint of theLineStringvaluels.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
LineStringvaluelsin 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
Pointobjects in theLineStringvaluels.mysql>
SET @ls = 'LineString(1 1,2 2,3 3)';mysql>SELECT NumPoints(GeomFromText(@ls));+------------------------------+ | NumPoints(GeomFromText(@ls)) | +------------------------------+ | 3 | +------------------------------+Returns the
N-thPointin theLinestringvaluels. 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
Pointthat is the start point of theLineStringvaluels.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
LineStringvaluelsis closed (that is, itsStartPoint()andEndPoint()values are the same) and is simple (does not pass through the same point more than once). Returns 0 iflsis 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
MultiLineStringvaluemls. The length ofmlsis 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
MultiLineStringvaluemlsis closed (that is, theStartPoint()andEndPoint()values are the same for eachLineStringinmls). Returns 0 ifmlsis 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
Polygonvaluepoly, 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
Polygonvaluepolyas 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 thePolygonvaluepolyas 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
Polygonvaluepoly.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
MultiPolygonvaluempoly, 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
MultiPolygonvaluempolyas aPoint. The result is not guaranteed to be on theMultiPolygon.Returns a
Pointvalue that is guaranteed to be on theMultiPolygonvaluempoly.
These functions return properties of
GeometryCollection values.
Returns the
N-th geometry in theGeometryCollectionvaluegc. 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
GeometryCollectionvaluegc.mysql>
SET @gc = 'GeometryCollection(Point(1 1),LineString(2 2, 3 3))';mysql>SELECT NumGeometries(GeomFromText(@gc));+----------------------------------+ | NumGeometries(GeomFromText(@gc)) | +----------------------------------+ | 2 | +----------------------------------+