Spatial Data Types and Formats
Discover the spatial data types and formats available in MySQL.
We'll cover the following
We need to manage various spatial data types in our startup that offers rides with e-scooters in Berlin. We require a system that can handle different spatial entities to organize the structure effectively. For instance, we track the locations of our e-scooters, which are represented as points. Additionally, we delineate specific zones where customers can park the e-scooters. Furthermore, the routes taken by our customers are recorded as paths, which, for simplicity, we treat as sampled locations connected by lines.
To manage these spatial entities efficiently, we need a database management system that supports spatial data types, including points, polygons, and multilines. MySQL is well-suited for this task as it offers comprehensive support for spatial data types by implementing the OpenGIS geometry model.
Spatial data types
The OpenGIS model defines a hierarchy of geometries, including Point
, Curve
, Surface
, and GeometryCollection
, with Geometry
being the root. However, not all these entities are directly usable; for example, Curve
and Surface
cannot be instantiated. Instead, LineString
and its subtypes (Line
and LinearRing
), as well as Polygon
, extend their respective non-instantiable entities to become usable. GeometryCollection
allows for combining different spatial types, such as MultiPoint
, MultiCurve
/MultiLineString
, and MultiSurface
/MultiPolygon
, with only the latter instantiable variants usable. This model can be understood by drawing parallels with Java programming, where non-instantiable entities are akin to abstract classes, and their instantiable counterparts are like concrete classes.
Geometry
establishes fundamental properties shared by all its subclasses. These properties include the geometry’s type, its classification within the hierarchy, and the spatial reference identifier (SRID), indicating the associated spatial reference system (SRS) that defines the coordinate space. The geometry’s coordinates, represented as double-precision numbers, express its position in the SRS. Additionally, the geometry possesses interior, boundary, and exterior components, with the interior representing the space it occupies, the exterior denoting unoccupied space, and the boundary defining the interface between the interior and exterior.
The point
represents a single location in a coordinate space. It is zero-dimensional, indicating that it has no length or area. The key properties of a Point
include its x-coordinate value and y-coordinate value, pinpointing its exact position. In practical terms, a Point
object could represent various singular locations, such as cities on a world map or bus stops on a city map.
Curve
is a one-dimensional geometry often represented by a sequence of points and serves as a noninstantiable class. It encompasses properties such as the coordinates of its points, defined as a one-dimensional geometry. A Curve
is considered simple if it does not pass through the same point twice, except when the start and end points are the same. It is closed if its start point is equal to its endpoint. When a Curve
is simple and closed, it is called a LinearRing
. The LineString
, a subclass of Curve
, represents a Curve
with linear interpolation between points. It is often employed to depict linear features such as rivers on a world map or streets on a city map. The properties of a LineString
include coordinates of segments defined by each consecutive pair of points. If a LineString
consists of exactly two points, it is termed a Line
. Applying the same definitions as Curve
, a LineString
is considered a LinearRing
if it is both closed and simple.
Get hands-on with 1400+ tech skills courses.