Add a New Point with an Explicit SRID to Locations
Insert a Point with a Specific SRID
Write a MySQL query to insert a new record into the Locations table with a point that includes an SRID using ST_GeomFromText.
Solution:
-- Insert a new location into the Locations table with an explicitly defined SRID for the spatial data.
INSERT INTO Locations (name, location)
-- Use the ST_GeomFromText function to create a POINT geometry with coordinates (-73.985130, 40.758896).
-- The second argument specifies the SRID (4326), which corresponds to the WGS 84 coordinate system.
VALUES ('Times Square', ST_GeomFromText('POINT(-73.985130 40.758896)', 4326));
Explanation:
- Purpose of the Query:
- The goal is to store spatial data with an associated spatial reference identifier.
- This demonstrates how to include an SRID when inserting spatial data.
- Key Components:
- ST_GeomFromText('POINT(...)', 4326) : Converts the WKT to a spatial object with SRID 4326.
- Real-World Application:
- Ensures consistency in spatial data by clearly defining the coordinate system used.
Notes:
- The SRID must match the spatial reference system used by your application.
For more Practice: Solve these Related Problems:
- Write a MySQL query to insert a new record into the "Locations" table with a point defined by ST_GeomFromText and an SRID of 4326.
- Write a MySQL query to insert a record into "MapPoints" with a point geometry using ST_GeomFromText, explicitly setting the SRID to 3857.
- Write a MySQL query to insert spatial data into "GeoLocations" with a point value that includes an SRID parameter via ST_GeomFromText.
- Write a MySQL query to insert a location record into "CityCenters" with a point and an SRID of 4326 using ST_GeomFromText.
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous MySQL Exercise: Transform Spatial Data to a Different SRID.
Next MySQL Exercise: Find Locations within a Bounding Box.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics