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 input parameters a Well-Known Text representation (and, optionally, a spatial reference system identifier (SRID)), and 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.
GeomFromText(wkt[,srid]) , GeometryFromText(wkt[,srid]) | Constructs a geometry value of any type using its WKT representation and SRID. |
PointFromText(wkt[,srid]) | Constructs a POINT value using its WKT representation and SRID. |
LineFromText(wkt[,srid]) , LineStringFromText(wkt[,srid]) | Constructs a LINESTRING value using its WKT representation and SRID. |
PolyFromText(wkt[,srid]) , PolygonFromText(wkt[,srid]) | Constructs a POLYGON value using its WKT representation and SRID. |
MPointFromText(wkt[,srid]) , MultiPointFromText(wkt[,srid]) | Constructs a MULTIPOINT value using its WKT representation and SRID. |
MLineFromText(wkt[,srid]) , MultiLineStringFromText(wkt[,srid]) | Constructs a MULTILINESTRING value using its WKT representation and SRID. |
MPolyFromText(wkt[,srid]) , MultiPolygonFromText(wkt[,srid]) | Constructs a MULTIPOLYGON value using its WKT representation and SRID. |
GeomCollFromText(wkt[,srid]) , GeometryCollectionFromText(wkt[,srid]) | Constructs a GEOMETRYCOLLECTION value using its WKT representation and SRID. |
The OpenGIS specification also describes optional functions for constructing Polygon or MultiPolygon values based on the WKT representation of a collection of rings or closed LineString values. These values may intersect. MySQL does not yet implement these functions:
BdPolyFromText(wkt,srid) | Constructs a Polygon value from a MultiLineString value in WKT format containing an arbitrary collection of closed LineString values. |
BdMPolyFromText(wkt,srid) | Constructs a MultiPolygon 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 input parameters a BLOB containing a Well-Known Binary representation (and, optionally, a spatial reference system identifier (SRID)), and return the corresponding geometry.
GeomFromWKT() accepts a WKB 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.
GeomFromWKB(wkb[,srid]) , GeometryFromWKB(wkt[,srid]) | Constructs a geometry value of any type using its WKB representation and SRID. |
PointFromWKB(wkb[,srid]) | Constructs a POINT value using its WKB representation and SRID. |
LineFromWKB(wkb[,srid]) , LineStringFromWKB(wkb[,srid]) | Constructs a LINESTRING value using its WKB representation and SRID. |
PolyFromWKB(wkb[,srid]) , PolygonFromWKB(wkb[,srid]) | Constructs a POLYGON value using its WKB representation and SRID. |
MPointFromWKB(wkb[,srid]) , MultiPointFromWKB(wkb[,srid]) | Constructs a MULTIPOINT value using its WKB representation and SRID. |
MLineFromWKB(wkb[,srid]) , MultiLineStringFromWKB(wkb[,srid]) | Constructs a MULTILINESTRING value using its WKB representation and SRID. |
MPolyFromWKB(wkb[,srid]) , MultiPolygonFromWKB(wkb[,srid]) | Constructs a MULTIPOLYGON value using its WKB representation and SRID. |
GeomCollFromWKB(wkb[,srid]) , GeometryCollectionFromWKB(wkt[,srid]) | Constructs a GEOMETRYCOLLECTION 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 yet implement these functions:
BdPolyFromWKB(wkb,srid) | Constructs a Polygon value from a MultiLineString value in WKB format containing an arbitrary collection of closed LineString values. |
BdMPolyFromWKB(wkb,srid) | Constructs a MultiPolygon value from a MultiLineString value in WKB format containing an arbitrary collection of closed LineString values. |
Note: MySQL does not yet implement the functions listed in this section.
MySQL provides a set of useful functions for creating geometry WKB representations. The functions described in this section are MySQL extensions to the OpenGIS specifications. The results of these functions are BLOB values containing WKB representations of geometry values with no SRID. The results of these functions can be substituted as the first argument for any function in the GeomFromWKB() function family.
Point(x,y) | Constructs a WKB Point using its coordinates. |
MultiPoint(pt1,pt2,...) | Constructs a WKB MultiPoint value using WKB Point arguments. If any argument is not a WKBPoint, the return value is NULL. |
LineString(pt1,pt2,...) | Constructs a WKB LineString value from a number of WKB Point arguments. If any argument is not a WKB Point, the return value is NULL. If the number of Point arguments is less than two, the return value is NULL. |
MultiLineString(ls1,ls2,...) | Constructs a WKB MultiLineString value using using WBK LineString arguments. If any argument is not a LineString, the return value is NULL. |
Polygon(ls1,ls2,...) | Constructs a WKB Polygon value from a number of WKB LineString arguments. If any argument does not represent the WKB of a LinearRing (that is, not a closed and simple LineString) the return value is NULL. |
MultiPolygon(poly1,poly2,...) | Constructs a WKB MultiPolygon value from a set of WKB Polygon arguments. If any argument is not a WKB Polygon, the rerurn value is NULL. |
GeometryCollection(g1,g2,...) | Constucts a WKB GeometryCollection. If any argument is not a well-formed WKB representation of a geometry, the return value is NULL. |