HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlModerate

How do I create a point with an SRID in MySQL?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
createpointwithsridmysqlhow

Problem

MySQL supports using ST_PointFromText to construct a point with an SRID,



-
ST_PointFromText(wkt[, srid [, options]])


Constructs a Point value using its WKT representation and SRID.


This assumes the input is Well-Known Text (WKT). How do I construct a point with latitude and longitude as doubles (or floating point types).

Solution

MySQL 8.0+

MySQL supports Point(x,y) which is a GIS function that constructs a point. With MySQL 8.0 and newer, you can further assign an SRID to that point with ST_SRID(srid)

SELECT ST_SRID( Point(0,0), 4326);


This is a relatively new feature implemented in MySQL 8.0 with #WL8543. MariaDB does not support it.

In PostGIS, you would use,

SELECT ST_SetSRID( ST_MakePoint(0,0), 4326);


In MariaDB, your only option is,

ST_PointFromText(wkt[, srid [, options]])

Code Snippets

SELECT ST_SRID( Point(0,0), 4326);
SELECT ST_SetSRID( ST_MakePoint(0,0), 4326);
ST_PointFromText(wkt[, srid [, options]])

Context

StackExchange Database Administrators Q#213813, answer score: 12

Revisions (0)

No revisions yet.