MySQL Spatial Data Types: Storing Points with POINT and GEOMETRY
MySQL doesn't have a specific data type called 'point'. However, you can store points using spatial data types. MySQL supports two spatial data types for storing points:
- POINT: Represents a single point in a two-dimensional space with X and Y coordinates.
- GEOMETRY: Stores points, lines, polygons, and other spatial objects, offering flexibility for various spatial data types.
To use spatial data types, enable spatial extensions when creating the table. Here's an example of creating a table with a 'POINT' column:
CREATE TABLE locations (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255),
coordinates POINT
);
Insert points using the 'POINT()' function:
INSERT INTO locations (name, coordinates)
VALUES ('New York', POINT(40.7128, -74.0060));
MySQL provides spatial functions and operators for querying and manipulating spatial data. These functions enable operations like distance calculation, intersection, and buffer creation.
Remember, spatial data types and functions require the MySQL spatial extensions to be enabled, and your MySQL version must support them.
原文地址: https://www.cveoy.top/t/topic/peJv 著作权归作者所有。请勿转载和采集!