[+/-]
This section describes how to create spatial values using Well-Known Text and Well-Known Binary functions that are defined in the OpenGIS standard, and using MySQL-specific functions.
MySQL provides a number of functions that take as arguments a Well-Known Text representation and, optionally, a spatial reference system identifier (SRID). They return the corresponding geometry.
GeomFromText()
accepts a WKT of
any geometry type as its first argument. An implementation
also provides type-specific construction functions for
construction of geometry values of each geometry type.
GeomCollFromText(
,
wkt
[,srid
])GeometryCollectionFromText(
wkt
[,srid
])
Constructs a GEOMETRYCOLLECTION
value
using its WKT representation and SRID.
GeomFromText(
,
wkt
[,srid
])GeometryFromText(
wkt
[,srid
])
Constructs a geometry value of any type using its WKT representation and SRID.
LineFromText(
,
wkt
[,srid
])LineStringFromText(
wkt
[,srid
])
Constructs a LINESTRING
value using its
WKT representation and SRID.
MLineFromText(
,
wkt
[,srid
])MultiLineStringFromText(
wkt
[,srid
])
Constructs a MULTILINESTRING
value
using its WKT representation and SRID.
MPointFromText(
,
wkt
[,srid
])MultiPointFromText(
wkt
[,srid
])
Constructs a MULTIPOINT
value using its
WKT representation and SRID.
MPolyFromText(
,
wkt
[,srid
])MultiPolygonFromText(
wkt
[,srid
])
Constructs a MULTIPOLYGON
value using
its WKT representation and SRID.
Constructs a POINT
value using its WKT
representation and SRID.
PolyFromText(
,
wkt
[,srid
])PolygonFromText(
wkt
[,srid
])
Constructs a POLYGON
value using its
WKT representation and SRID.
The OpenGIS specification also defines the following optional
functions, which MySQL does not implement. These functions
construct Polygon
or
MultiPolygon
values based on the WKT
representation of a collection of rings or closed
LineString
values. These values may
intersect.
Constructs a MultiPolygon
value from a
MultiLineString
value in WKT format
containing an arbitrary collection of closed
LineString
values.
Constructs a Polygon
value from a
MultiLineString
value in WKT format
containing an arbitrary collection of closed
LineString
values.
MySQL provides a number of functions that take as arguments a
BLOB
containing a Well-Known
Binary representation and, optionally, a spatial reference
system identifier (SRID). They return the corresponding
geometry.
As of MySQL 5.1.35, these functions also accept geometry objects for compatibility with the changes made in MySQL 5.1.35 to the return value of the functions in Section 11.13.4.2.3, “Creating Geometry Values Using MySQL-Specific Functions”. Thus, those functions may continue to be used to provide the first argument to the functions in this section.
GeomCollFromWKB(
,
wkb
[,srid
])GeometryCollectionFromWKB(
wkb
[,srid
])
Constructs a GEOMETRYCOLLECTION
value
using its WKB representation and SRID.
GeomFromWKB(
,
wkb
[,srid
])GeometryFromWKB(
wkb
[,srid
])
Constructs a geometry value of any type using its WKB representation and SRID.
LineFromWKB(
,
wkb
[,srid
])LineStringFromWKB(
wkb
[,srid
])
Constructs a LINESTRING
value using its
WKB representation and SRID.
MLineFromWKB(
,
wkb
[,srid
])MultiLineStringFromWKB(
wkb
[,srid
])
Constructs a MULTILINESTRING
value
using its WKB representation and SRID.
MPointFromWKB(
,
wkb
[,srid
])MultiPointFromWKB(
wkb
[,srid
])
Constructs a MULTIPOINT
value using its
WKB representation and SRID.
MPolyFromWKB(
,
wkb
[,srid
])MultiPolygonFromWKB(
wkb
[,srid
])
Constructs a MULTIPOLYGON
value using
its WKB representation and SRID.
Constructs a POINT
value using its WKB
representation and SRID.
PolyFromWKB(
,
wkb
[,srid
])PolygonFromWKB(
wkb
[,srid
])
Constructs a POLYGON
value using its
WKB representation and SRID.
The OpenGIS specification also describes optional functions
for constructing Polygon
or
MultiPolygon
values based on the WKB
representation of a collection of rings or closed
LineString
values. These values may
intersect. MySQL does not implement these functions:
Constructs a MultiPolygon
value from a
MultiLineString
value in WKB format
containing an arbitrary collection of closed
LineString
values.
Constructs a Polygon
value from a
MultiLineString
value in WKB format
containing an arbitrary collection of closed
LineString
values.
MySQL provides a set of useful nonstandard functions for creating geometry values. The functions described in this section are MySQL extensions to the OpenGIS specification.
As of MySQL 5.1.35, these functions produce geometry objects
from either WKB values or geometry objects as arguments. If
any argument is not a proper WKB or geometry representation of
the proper object type, the return value is
NULL
.
Before MySQL 5.1.35, these functions produce
BLOB
values containing WKB
representations of geometry values with no SRID from WKB
arguments. The WKB value returned from these functions can be
converted to geometry arguments by using them as the first
argument to functions in the
GeomFromWKB()
function family.
For example, as of MySQL 5.1.35, you can insert the geometry
return value from Point()
directly into a Point
column:
INSERT INTO t1 (pt_col) VALUES(Point(1,2));
Prior to MySQL 5.1.35, convert the WKB return value to a
Point
before inserting it:
INSERT INTO t1 (pt_col) VALUES(GeomFromWKB(Point(1,2)));
Constructs a GeometryCollection
.
Constructs a LineString
value from a
number of Point
or WKB
Point
arguments. If the number of
arguments is less than two, the return value is
NULL
.
Constructs a MultiLineString
value
using LineString
or WKB
LineString
arguments.
Constructs a MultiPoint
value using
Point
or WKB Point
arguments.
Constructs a MultiPolygon
value from a
set of Polygon
or WKB
Polygon
arguments.
Constructs a Point
using its
coordinates.
Constructs a Polygon
value from a
number of LineString
or WKB
LineString
arguments. If any argument
does not represent a LinearRing
(that
is, not a closed and simple
LineString
), the return value is
NULL
.
User Comments
Add your own comment.