A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.w3resource.com/mysql/mysql-spatial-data-types.php below:

Website Navigation


MySQL Spatial Data Types - w3resource

MySQL Spatial Data TypesLast update on August 19 2022 21:50:42 (UTC/GMT +8 hours) Extensions for Spatial Data

The Open Geospatial Consortium (OGC) is is an international consortium of more than 250 companies, agencies, and universities participating in the development of publicly available conceptual solutions that can be useful with all kinds of applications that manage spatial data.

The specification published by Open Geospatial Consortium publishes (OGC) specifies that how MySQL implements spatial extensions as a subset of the SQL with Geometry Types environment. This term refers to an SQL environment that has been extended with a set of geometry types. A geometry-valued SQL column is implemented as a column that has a geometry type. The specification describes a set of SQL geometry types, as well as functions on those types to create and analyze geometry values.

Features of MySQL Spatial Data Types

MySQL spatial extensions enable the generation, storage, and analysis of geographic features:

MySQL supports a number of Spatial Data Types

MySQL has data types that correspond to OpenGIS classes. Some of these types hold single geometry values:

The other data types hold collections of values:

Geometry Type

Geometry is a word that denotes a geographic feature. Originally the word geometry meant measurement of the earth. Another meaning comes from cartography, referring to the geometric features that cartographers use to map the world. It is a noninstantiable class but has a number of properties, given below are common to all geometry values created from any of the Geometry subclasses.

Name Description type Each geometry belongs to one of the instantiable classes in the hierarchy. SRID The full form of SRID is Spatial Reference Identifier. This system describes the coordinate space in which the geometry object is defined. In MySQL, the SRID value is just an integer associated with the geometry value. coordinates All nonempty geometries include at least one pair of (X,Y) coordinates. Empty geometries contain no coordinates. Coordinates are related to the SRID. interior, boundary, exterior. Every geometry occupies some position in space. The exterior of a geometry is all space not occupied by the geometry. The interior is the space occupied by the geometry. The boundary is the interface between the geometry's interior and exterior. MBR Its MBR (minimum bounding rectangle), or envelope. This is the bounding geometry, formed by the minimum and maximum (X,Y) coordinates: simple or nonsimple. Whether the value is simple or nonsimple. Geometry values of types (LineString, MultiPoint, MultiLineString) are either simple or nonsimple. Each type determines its own assertions for being simple or nonsimple. closed or not closed Whether the value is closed or not closed. Geometry values of types (LineString, MultiString) are either closed or not closed. Each type determines its own assertions for being closed or not closed. empty or nonempty Whether the value is empty or nonempty A geometry is empty if it does not have any points. Exterior, interior, and boundary of an empty geometry are not defined. An empty geometry is defined to be always simple and has an area of 0. dimension Its dimension. A geometry can have a dimension of –1, 0, 1, or 2:
– 1 for an empty geometry.
0 for a geometry with no length and no area.
1 for a geometry with nonzero length and zero area.
2 for a geometry with nonzero area.

Example

Use the CREATE TABLE statement to create a table with a spatial column:

CREATE TABLE geotest (code int(5),descrip varchar(50), g GEOMETRY);
 

Here is the structure of the table:

Sample Output:

MySQL> describe geotest;
+---------+-------------+------+-----+---------+-------+
| Field   | Type        | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| code    | int(5)      | YES  |     | NULL    |       | 
| descrip | varchar(50) | YES  |     | NULL    |       | 
| g       | geometry    | YES  |     | NULL    |       | 
+---------+-------------+------+-----+---------+-------+
3 rows in set (0.01 sec)

Use the ALTER TABLE statement to add or drop a spatial column to or from an existing table:

ALTER TABLE geotest ADD pt_loca POINT; 
ALTER TABLE geotest DROP pt_loca ;

Point Type

A Point is a geometry which represents a single location in coordinate space.

Usage of Point

On a city map, a Point object could represent a rail station.

Point Properties

Example

MySQL> SELECT X(POINT(18, 23));
+------------------+
| X(POINT(18, 23)) |
+------------------+
|               18 | 
+------------------+
1 row in set (0.00 sec)


MySQL> SELECT X(GeomFromText('POINT(18 23)'));
+---------------------------------+
| X(GeomFromText('POINT(18 23)')) |
+---------------------------------+
|                              18 | 
+---------------------------------+
1 row in set (0.00 sec)

Curve Type

A Curve is a one-dimensional geometry, in general, it represented by a sequence of points. Particular subclasses of Curve define the type of interpolation between points. The curve is a noninstantiable class.

Curve Properties

LineString Type

A LineString is a Curve with linear interpolation between points.

Usage of LineString

LineString objects could represent a river within a country map.

LineString Properties

Example

MySQL> SET @g = 'LINESTRING(0 0,1 2,2 4)';
Query OK, 0 rows affected (0.00 sec)
MySQL> INSERT INTO geotest VALUES (123,"Test Data",GeomFromText(@g));
Query OK, 1 row affected (0.00 sec)

Surface Type

A Surface is a two-dimensional geometry. It is a noninstantiable class. Its only instantiable subclass is Polygon.

Surface Properties

Polygon Type

A Polygon is a planar Surface representing a multisided geometry. It is defined by a single exterior boundary and zero or more interior boundaries, where each interior boundary defines a hole in the Polygon.

Usage of Polygon

The Polygon objects could represent districts, blocks and so on from a state map.

Polygon Assertions

Example

MySQL> SET @g = 'POLYGON((0 0,8 0,12 9,0 9,0 0),(5 3,4 5,7 9,3 7, 2 5))';
Query OK, 0 rows affected (0.00 sec)

MySQL> INSERT INTO geotest VALUES (123,"Test Data",GeomFromText(@g));
Query OK, 1 row affected (0.03 sec)

GeometryCollection Type

A GeometryCollection is a geometry that is a collection of one or more geometries of any class.

All the elements in a GeometryCollection must be in the same Spatial Reference System. There are no other constraints on the elements of a GeometryCollection, although the subclasses of GeometryCollection described in the following sections may restrict membership. Restrictions may be based on:

Example

MySQL> SET @g ='GEOMETRYCOLLECTION(POINT(3 2),LINESTRING(0 0,1 3,2 5,3 5,4 7))';
Query OK, 0 rows affected (0.00 sec)

MySQL> INSERT INTO geotest VALUES (123,"Test Data",GeomFromText(@g));
Query OK, 1 row affected (0.00 sec)

MultiPoint Type

A MultiPoint is a geometry collection composed of Point elements. The points are not connected or ordered in any way.

Usage of MultiPoint

On a world map, a MultiPoint could represent a chain of small islands.

MultiPoint Properties

MultiCurve Type

A MultiCurve is a geometry collection composed of Curve elements. MultiCurve is a noninstantiable class.

MultiCurve Properties

MySQL> SET @g ='MULTIPOINT(0 0, 15 25, 45 65)';
Query OK, 0 rows affected (0.00 sec)

MySQL> INSERT INTO geotest VALUES (123,"Multipoint",GeomFromText(@g));
Query OK, 1 row affected (0.00 sec)

MultiLineString Type

A MultiLineString is a MultiCurve geometry collection composed of LineString elements.

Usage of MultiLineString

Example

MySQL> SET @g ='MULTILINESTRING((12 12, 22 22), (19 19, 32 18))';
Query OK, 0 rows affected (0.00 sec)

MySQL> INSERT INTO geotest VALUES (123,"Multistring",GeomFromText(@g));
Query OK, 1 row affected (0.00 sec)

MultiSurface Type

A MultiSurface is a geometry collection composed of surface elements. MultiSurface is a noninstantiable class. Its only instantiable subclass is MultiPolygon.

MultiSurface Assertions

MultiPolygon Type

MultiPolygon is a MultiSurface object composed of Polygon elements.

Usage of MultiPolygon

A MultiPolygon could represent a system of lakes on a region map.

MultiPolygon Assertions

MultiPolygon Properties

Example

MySQL> SET @g ='MULTIPOLYGON(((0 0,11 0,12 11,0 9,0 0)),((3 5,7 4,4 7,7 7,3 5)))';
Query OK, 0 rows affected (0.00 sec)

MySQL> INSERT INTO geotest VALUES (123,"Multipolygon",GeomFromText(@g));
Query OK, 1 row affected (0.00 sec)

Summary : MySQL Data Types

Previous: MySQL Data Types
Next: Connecting to and disconnecting from MySQL


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4