A few important gotchas are highlighted: GEOMETRY vs GEOGRAPHY accuracy tradeoff, SQLite/SpatiaLite requiring a PRAGMA, and the MBR pre-filter + precise function performance pattern for large datasets.
Column types that store geometric/geographic objects.
MySQL Spatial Types
Type
Description
Example
POINT
Single X,Y coordinate
A shop location
LINESTRING
Ordered sequence of points
A road, river
POLYGON
Closed ring(s) β area with holes
A city boundary
MULTIPOINT
Collection of Points
Multiple ATMs
MULTILINESTRING
Collection of LineStrings
Multiple roads
MULTIPOLYGON
Collection of Polygons
Country with islands
GEOMETRYCOLLECTION
Mix of any geometry types
Mixed dataset
GEOMETRY
Generic β accepts any type
Flexible column
Declaring Spatial Columns
1
2
3
4
5
6
7
8
CREATETABLElocations(idINTNOTNULLAUTO_INCREMENTPRIMARYKEY,nameVARCHAR(100)NOTNULL,positionPOINTNOTNULLSRID4326,-- WGS84 lat/lngregionPOLYGON,routeLINESTRING,geomGEOMETRY-- accepts any type);
SRID β Spatial Reference System Identifier
SRID
System
Unit
Use
4326
WGS 84 (GPS)
Degrees lat/lng
Global GPS coordinates
3857
Web Mercator
Meters
Google Maps, OpenStreetMap tiles
32636
UTM Zone 36N
Meters
Egypt / Middle East
2263
NY State Plane
Feet
Local US surveys
1
2
3
4
5
6
7
8
-- Create column with enforced SRIDpositionPOINTNOTNULLSRID4326-- Check SRID of a geometrySELECTST_SRID(position)FROMlocations;-- Change SRIDSELECTST_SRID(position,4326)FROMlocations;-- MySQL 8.0+
Cross-Engine β Spatial Types
Type
MySQL
SQLite + SpatiaLite
PostgreSQL + PostGIS
SQL Server
Oracle Spatial
POINT
β
β
β
β geometry
β SDO_GEOMETRY
LINESTRING
β
β
β
β
β
POLYGON
β
β
β
β
β
GEOMETRY (generic)
β
β
β
β
β
GEOGRAPHY (spherical)
β
β
β
β
β
SRID enforcement
β 8.0+
β
β
β
β
π‘ GEOMETRY vs GEOGRAPHY: GEOMETRY uses flat (Euclidean) math β fast but inaccurate over long distances. GEOGRAPHY uses spherical (ellipsoidal) math β slower but accurate for real-world GPS distances. Use GEOGRAPHY in PostGIS / SQL Server for distances > ~100 km.
2. Geometry Constructors
Build geometry objects from coordinates.
POINT
1
2
3
4
5
6
7
8
-- ST_Point(longitude, latitude) β note X=lng, Y=lat orderSELECTST_Point(31.2357,30.0444);-- CairoSELECTST_PointFromText('POINT(31.2357 30.0444)',4326);SELECTPoint(31.2357,30.0444);-- MySQL shorthand (no SRID)-- Store a pointINSERTINTOlocations(name,position)VALUES('Cairo Center',ST_PointFromText('POINT(31.2357 30.0444)',4326));
LINESTRING
1
2
3
4
5
6
7
8
-- Road from point A to point B to point CSELECTST_LineStringFromText('LINESTRING(31.2 30.0, 31.3 30.1, 31.4 30.2)',4326);SELECTLineString(Point(31.2,30.0),Point(31.3,30.1),Point(31.4,30.2));
POLYGON
1
2
3
4
5
6
7
8
9
10
11
12
13
14
-- Closing ring: first point = last pointSELECTST_PolygonFromText('POLYGON((31.0 29.9, 31.5 29.9, 31.5 30.5, 31.0 30.5, 31.0 29.9))',4326);-- Polygon with a hole (donut shape)SELECTST_PolygonFromText('POLYGON(
(31.0 29.9, 31.5 29.9, 31.5 30.5, 31.0 30.5, 31.0 29.9),
(31.1 30.0, 31.2 30.0, 31.2 30.1, 31.1 30.1, 31.1 30.0)
)',4326);
SELECTST_GeometryType(geom)FROMlocations;-- 'ST_Point', 'ST_Polygon' β¦SELECTST_IsValid(geom)FROMregions;-- 1 = valid, 0 = invalidSELECTST_IsEmpty(geom)FROMregions;-- 1 if empty geometrySELECTST_IsSimple(geom)FROMroutes;-- 1 if no self-intersectionsSELECTST_IsClosed(geom)FROMroutes;-- 1 if LineString start = endSELECTST_Dimension(geom)FROMshapes;-- 0=point, 1=line, 2=polygonSELECTST_SRID(position)FROMlocations;-- spatial reference system ID
Points & Coordinates
1
2
3
4
5
6
7
8
9
10
SELECTST_X(position)FROMlocations;-- longitude (X)SELECTST_Y(position)FROMlocations;-- latitude (Y)SELECTST_Latitude(position)FROMlocations;-- MySQL 8.0+ β latitudeSELECTST_Longitude(position)FROMlocations;-- MySQL 8.0+ β longitude-- Extract start/end of a linestringSELECTST_StartPoint(route)FROMroutes;SELECTST_EndPoint(route)FROMroutes;SELECTST_NumPoints(route)FROMroutes;-- total points in linestringSELECTST_PointN(route,2)FROMroutes;-- 2nd point (1-indexed)
Polygon Rings
1
2
3
SELECTST_ExteriorRing(boundary)FROMregions;-- outer ring as LINESTRINGSELECTST_NumInteriorRings(boundary)FROMregions;-- count of holesSELECTST_InteriorRingN(boundary,1)FROMregions;-- 1st hole as LINESTRING
Collections
1
2
SELECTST_NumGeometries(collection)FROMmulti_shapes;-- count of sub-geometriesSELECTST_GeometryN(collection,1)FROMmulti_shapes;-- extract 1st geometry
Cross-Engine β Properties
Function
MySQL
SpatiaLite
PostGIS
SQL Server
Oracle
ST_GeometryType()
β
β
β
β οΈ .STGeometryType()
β οΈ .Get_GType()
ST_X() / ST_Y()
β
β
β
β οΈ .STX / .STY properties
β οΈ SDO_UTIL.GETVERTICES()
ST_IsValid()
β
β
β
β οΈ .STIsValid()
β οΈ SDO_GEOM.VALIDATE_GEOMETRY()
ST_StartPoint()
β
β
β
β οΈ .STStartPoint()
β
ST_NumPoints()
β
β
β
β οΈ .STNumPoints()
β
ST_ExteriorRing()
β
β
β
β οΈ .STExteriorRing()
β
5. Measurement Functions
Calculate distances, areas, and lengths.
Distance
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
-- Cartesian (flat) distance β fast, less accurate over long distancesSELECTST_Distance(ST_PointFromText('POINT(31.2357 30.0444)',4326),-- CairoST_PointFromText('POINT(29.9553 31.1342)',4326)-- Giza)ASdist_degrees;-- Spherical distance β accurate real-world distance in metersSELECTST_Distance_Sphere(ST_PointFromText('POINT(31.2357 30.0444)',4326),ST_PointFromText('POINT(29.9553 31.1342)',4326))ASdist_meters;-- PostGIS β use GEOGRAPHY type for accurate sphere distanceSELECTST_Distance('SRID=4326;POINT(31.2357 30.0444)'::geography,'SRID=4326;POINT(29.9553 31.1342)'::geography)ASdist_meters;
Area
1
2
3
4
5
6
-- ST_Area returns area in the unit of the SRID-- SRID 4326 β square degrees (not useful); use projected SRID (e.g. 3857) for mΒ²SELECTST_Area(boundary)FROMregions;-- PostGIS with geography for mΒ²SELECTST_Area(boundary::geography)/1000000ASarea_km2FROMregions;
Length / Perimeter
1
2
3
4
5
SELECTST_Length(route)FROMroutes;-- length of linestringSELECTST_Perimeter(boundary)FROMregions;-- perimeter of polygon-- PostGIS β accurate length in meters using geographySELECTST_Length(route::geography)ASlength_mFROMroutes;
-- How similar are two line shapes? (lower = more similar)SELECTST_HausdorffDistance(route_a,route_b)FROMroute_pairs;SELECTST_FrechetDistance(route_a,route_b)FROMroute_pairs;-- MySQL 8.0.37+
Cross-Engine β Measurement
Function
MySQL
SpatiaLite
PostGIS
SQL Server
Oracle
ST_Distance() (flat)
β
β
β
β οΈ .STDistance()
β οΈ SDO_GEOM.SDO_DISTANCE()
ST_Distance_Sphere()
β
β SphereDistance()
β οΈ Use geography type
β οΈ Use geography type
β οΈ SDO_GEOM.SDO_DISTANCE() with tolerance
ST_Area()
β
β
β
β οΈ .STArea()
β οΈ SDO_GEOM.SDO_AREA()
ST_Length()
β
β
β
β οΈ .STLength()
β οΈ SDO_GEOM.SDO_LENGTH()
ST_Perimeter()
β
β
β
β use .STLength() on ring
β
ST_HausdorffDistance()
β
β
β
β
β
6. Spatial Relationship Functions
Test topological and geometric relationships between two geometries.
-- Contains: does A completely contain B?SELECTST_Contains(region,point)FROMareas,locations;-- 1 or 0-- Within: is A completely inside B?SELECTST_Within(point,region)FROMlocations,areas;-- inverse of Contains-- Intersects: do A and B share any space?SELECTST_Intersects(geom_a,geom_b)FROMshapes;-- Overlaps: do A and B partially overlap (same dimension)?SELECTST_Overlaps(poly_a,poly_b)FROMpolygons;-- Touches: do A and B share only a boundary point?SELECTST_Touches(geom_a,geom_b)FROMshapes;-- Crosses: do A and B cross each other (different dimensions)?SELECTST_Crosses(linestring,poly)FROMroutes,areas;-- Disjoint: do A and B share NO space at all?SELECTST_Disjoint(geom_a,geom_b)FROMshapes;-- Equals: are A and B geometrically identical?SELECTST_Equals(geom_a,geom_b)FROMshapes;
MBR (Minimum Bounding Rectangle) Predicates β Faster but less precise
1
2
3
4
5
6
7
8
9
10
-- Use MBR checks for large dataset filtering (index-friendly)SELECTST_MBRContains(mbr_a,mbr_b)FROMshapes;SELECTST_MBRWithin(mbr_a,mbr_b)FROMshapes;SELECTST_MBRIntersects(mbr_a,mbr_b)FROMshapes;SELECTST_MBROverlaps(mbr_a,mbr_b)FROMshapes;SELECTST_MBREquals(mbr_a,mbr_b)FROMshapes;SELECTST_MBRDisjoint(mbr_a,mbr_b)FROMshapes;SELECTST_MBRTouches(mbr_a,mbr_b)FROMshapes;SELECTST_MBRCoveredBy(mbr_a,mbr_b)FROMshapes;SELECTST_MBRCovers(mbr_a,mbr_b)FROMshapes;
Practical: Find all points inside a polygon
1
2
3
4
5
-- Find all stores inside a city boundarySELECTs.name,ST_AsText(s.position)FROMstoressJOINcitiescONc.name='Cairo'WHEREST_Contains(c.boundary,s.position);
Practical: Find points within a radius
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
-- All restaurants within 2 km of a given point (flat distance)SELECTnameFROMrestaurantsWHEREST_Distance_Sphere(position,ST_PointFromText('POINT(31.2357 30.0444)',4326))<=2000;-- Better: use bounding box first (uses spatial index), then refineSELECTnameFROMrestaurantsWHEREMBRContains(ST_Buffer(ST_PointFromText('POINT(31.2357 30.0444)',4326),0.02),position)ANDST_Distance_Sphere(position,ST_PointFromText('POINT(31.2357 30.0444)',4326))<=2000;
Cross-Engine β Relationships
Function
MySQL
SpatiaLite
PostGIS
SQL Server
Oracle
ST_Contains()
β
β
β
β οΈ .STContains()
β οΈ SDO_CONTAINS()
ST_Within()
β
β
β
β οΈ .STWithin()
β οΈ SDO_WITHIN_DISTANCE()
ST_Intersects()
β
β
β
β οΈ .STIntersects()
β οΈ SDO_ANYINTERACT()
ST_Overlaps()
β
β
β
β οΈ .STOverlaps()
β οΈ SDO_OVERLAPS()
ST_Touches()
β
β
β
β οΈ .STTouches()
β οΈ SDO_TOUCH()
ST_Crosses()
β
β
β
β οΈ .STCrosses()
β οΈ SDO_CROSSES()
ST_Disjoint()
β
β
β
β οΈ .STDisjoint()
β οΈ SDO_DISJOINT()
ST_Equals()
β
β
β
β οΈ .STEquals()
β οΈ SDO_EQUAL()
MBR predicates
β
β
β οΈ && operator
β
β
7. Spatial Set Operations
Compute new geometries from the intersection, union, or difference of two geometries.
Intersection β shared area
1
2
SELECTST_AsText(ST_Intersection(poly_a,poly_b))FROMregion_pairs;-- Returns the geometry that both inputs share
Union β combined area
1
2
SELECTST_AsText(ST_Union(poly_a,poly_b))FROMregion_pairs;-- Returns one geometry covering both inputs (no duplicates)
Difference β subtract B from A
1
2
SELECTST_AsText(ST_Difference(city_boundary,restricted_zone))FROMareas;-- Returns the part of A that is NOT in B
Symmetric Difference β XOR of geometries
1
2
SELECTST_AsText(ST_SymDifference(poly_a,poly_b))FROMregion_pairs;-- Returns area in A or B but NOT in both (like XOR)
Buffer β expand geometry by distance
1
2
3
4
5
6
7
8
9
10
11
12
13
-- Buffer a point (creates a circle in flat/Cartesian space)SELECTST_AsText(ST_Buffer(ST_PointFromText('POINT(31.2357 30.0444)',4326),0.01));-- Buffer a road corridorSELECTST_AsText(ST_Buffer(route,0.001))FROMroutes;-- PostGIS β buffer with projected SRID (meters)SELECTST_AsText(ST_Buffer(ST_Transform(ST_PointFromText('POINT(31.2357 30.0444)',4326),32636),500-- 500 meters in UTM Zone 36N));
-- Reduce complexity of a detailed polygon (Douglas-Peucker algorithm)SELECTST_AsText(ST_Simplify(boundary,0.001))FROMregions;-- Tolerance: larger = more simplification, less detail
Centroid β geometric center point
1
2
3
SELECTST_AsText(ST_Centroid(boundary))FROMregions;-- Note: centroid may fall OUTSIDE a concave polygon-- Use ST_PointOnSurface() for a guaranteed-inside point (PostGIS)
Cross-Engine β Set Operations
Function
MySQL
SpatiaLite
PostGIS
SQL Server
Oracle
ST_Intersection()
β
β
β
β οΈ .STIntersection()
β οΈ SDO_GEOM.SDO_INTERSECTION()
ST_Union()
β
β
β
β οΈ .STUnion()
β οΈ SDO_GEOM.SDO_UNION()
ST_Difference()
β
β
β
β οΈ .STDifference()
β οΈ SDO_GEOM.SDO_DIFFERENCE()
ST_SymDifference()
β
β
β
β οΈ .STSymDifference()
β οΈ SDO_GEOM.SDO_XOR()
ST_Buffer()
β
β
β
β οΈ .STBuffer()
β οΈ SDO_GEOM.SDO_BUFFER()
ST_ConvexHull()
β
β
β
β οΈ .STConvexHull()
β οΈ SDO_GEOM.SDO_CONVEXHULL()
ST_Simplify()
β
β
β
β
β οΈ SDO_UTIL.SIMPLIFY()
ST_Centroid()
β
β
β
β use .STCentroid() MSSQL extension
β
8. Coordinate & Projection Functions
Transform coordinates between spatial reference systems.
Transform (Reproject)
1
2
3
4
5
6
7
8
9
10
-- PostGIS β transform from WGS84 (4326) to UTM (32636)SELECTST_AsText(ST_Transform(ST_PointFromText('POINT(31.2357 30.0444)',4326),32636));-- MySQL 8.0+SELECTST_Transform(position,32636)FROMlocations;
Swap X/Y coordinates
1
2
-- Fix geometries where lat/lng are accidentally reversedSELECTST_SwapXY(position)FROMlocations;
Line Interpolation (point along a line)
1
2
3
4
5
6
7
8
-- Point 50% along a routeSELECTST_AsText(ST_LineInterpolatePoint(route,0.5))FROMroutes;-- Multiple points at regular intervals along a routeSELECTST_AsText(ST_LineInterpolatePoints(route,0.25))FROMroutes;-- every 25%-- Point at specific distance from startSELECTST_AsText(ST_PointAtDistance(route,1000))FROMroutes;-- 1000 map units from start
Geohash (encode coordinates as string)
1
2
3
4
5
6
7
8
9
10
11
-- Encode point as geohash (shorter = lower precision)SELECTST_GeoHash(position,10)FROMlocations;-- 10-char precisionSELECTST_GeoHash(ST_PointFromText('POINT(31.2357 30.0444)',4326),8);-- β 'svhwsq3w'-- Decode geohash back to pointSELECTST_AsText(ST_PointFromGeoHash('svhwsq3w',0));-- Extract lat/lng from geohashSELECTST_LatFromGeoHash('svhwsq3w');SELECTST_LongFromGeoHash('svhwsq3w');
Cross-Engine β Projections
Function
MySQL
SpatiaLite
PostGIS
SQL Server
Oracle
ST_Transform()
β 8.0+
β
β
β οΈ manual via CLR
β οΈ SDO_CS.TRANSFORM()
ST_SwapXY()
β
β
β
β
β
ST_LineInterpolatePoint()
β
β
β
β
β
ST_GeoHash()
β
β
β
β
β
ST_PointFromGeoHash()
β
β
β οΈ ST_GeomFromGeoHash()
β
β
9. GeoJSON & Geohash
Exchange spatial data in standard web-friendly formats.
Critical for performance β without a spatial index, every spatial query does a full table scan.
MySQL β SPATIAL INDEX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
-- Require NOT NULL + no SRID on older MySQL, or SRID on 8.0+CREATETABLElocations(idINTNOTNULLAUTO_INCREMENTPRIMARYKEY,nameVARCHAR(100)NOTNULL,positionPOINTNOTNULLSRID4326,SPATIALINDEXidx_position(position)-- inline at creation);-- Add spatial index laterALTERTABLElocationsADDSPATIALINDEXidx_position(position);CREATESPATIALINDEXidx_positionONlocations(position);-- Drop spatial indexDROPINDEXidx_positionONlocations;ALTERTABLElocationsDROPINDEXidx_position;
PostgreSQL (PostGIS) β GiST / SP-GiST / BRIN
1
2
3
4
5
6
7
8
9
10
11
-- GiST index β most common, supports all operatorsCREATEINDEXidx_positionONlocationsUSINGGIST(position);-- SP-GiST β better for non-overlapping data (points, quadtrees)CREATEINDEXidx_positionONlocationsUSINGSPGIST(position);-- BRIN β very small, good for large append-only tablesCREATEINDEXidx_positionONlocationsUSINGBRIN(position);-- Partial spatial index (only index active records)CREATEINDEXidx_active_posONlocationsUSINGGIST(position)WHEREactive=TRUE;
SQL Server β Spatial Index
1
2
3
4
CREATESPATIALINDEXidx_positionONlocations(position)USINGGEOMETRY_AUTO_GRIDWITH(BOUNDING_BOX=(29.0,22.0,37.0,32.0));-- xmin,ymin,xmax,ymax for Egypt
β οΈ Performance tip: Always use a spatial index + a bounding box pre-filter (MBR/envelope check) before applying precise spatial functions like ST_Contains or ST_Distance. This dramatically reduces the number of rows that need exact computation.
11. Window & Aggregate Spatial Functions
Aggregate geometries across groups or windows.
ST_Collect β aggregate into a collection (no merge)
1
2
3
4
-- PostGIS: collect all points per city into a MULTIPOINTSELECTcity,ST_Collect(position)ASall_positionsFROMlocationsGROUPBYcity;
ST_Union β aggregate and merge (dissolve boundaries)
1
2
3
4
-- PostGIS: merge all district polygons into a single city polygonSELECTcity_id,ST_Union(district_boundary)AScity_boundaryFROMdistrictsGROUPBYcity_id;
ST_Extent β bounding box of a group
1
2
3
4
5
-- PostGIS: bounding box of all stores in a regionSELECTregion,ST_Extent(position)ASbboxFROMstoresGROUPBYregion;-- β BOX(minX minY, maxX maxY)
ST_ConvexHull on group
1
2
3
4
-- Convex hull enclosing all delivery points per routeSELECTroute_id,ST_AsText(ST_ConvexHull(ST_Collect(position)))AShullFROMdeliveriesGROUPBYroute_id;
Nearest Neighbor (PostGIS KNN)
1
2
3
4
5
6
-- 5 nearest locations to a target point using <-> distance operatorSELECTname,ST_Distance(position,target.pt)ASdistFROMlocations,(SELECTST_PointFromText('POINT(31.2357 30.0444)',4326)ASpt)targetORDERBYposition<->target.ptLIMIT5;
Pattern 2 β Find all points within N km of a location
1
2
3
4
5
6
7
8
9
10
-- All stores within 5 km of a given pointSET@center=ST_PointFromText('POINT(31.2357 30.0444)',4326);SET@radius_m=5000;SELECTname,ROUND(ST_Distance_Sphere(position,@center))ASdistance_mFROMstoresWHEREST_Distance_Sphere(position,@center)<=@radius_mORDERBYdistance_m;
Pattern 3 β Find points inside a polygon (geofencing)
1
2
3
4
5
6
7
8
9
10
-- Define a delivery zone polygonSET@zone=ST_GeomFromText('POLYGON((31.1 29.9, 31.4 29.9, 31.4 30.2, 31.1 30.2, 31.1 29.9))',4326);-- Find all orders inside the delivery zoneSELECTo.id,o.customer_nameFROMordersoWHEREST_Contains(@zone,o.delivery_point);
Pattern 4 β Calculate area of a region (PostGIS)
1
2
3
4
5
6
-- Area in kmΒ² using geography type for accuracySELECTname,ROUND(ST_Area(boundary::geography)/1000000,2)ASarea_km2FROMregionsORDERBYarea_km2DESC;
Pattern 5 β Route length in kilometers
1
2
3
4
5
6
7
-- MySQL (flat approximation)SELECTname,ST_Length(route)ASlength_degreesFROMroutes;-- PostGIS (accurate using geography)SELECTname,ROUND(ST_Length(route::geography)/1000,2)ASlength_kmFROMroutes;
-- 10 nearest hospitals to a patient locationSELECTh.name,ST_Distance(h.position::geography,p.location::geography)ASdist_mFROMhospitalsh,(SELECTST_SetSRID(ST_Point(31.2357,30.0444),4326)::geographyASlocation)pORDERBYh.position::geography<->p.locationLIMIT10;
Pattern 7 β Dissolve district boundaries into city boundary
Pattern 8 β Generate a buffer zone (PostGIS with reprojection)
1
2
3
4
5
6
7
8
9
10
-- 500m buffer around a hospital in UTM (accurate meters)SELECTname,ST_AsGeoJSON(ST_Transform(ST_Buffer(ST_Transform(position,32636),500),-- buffer 500m in UTM4326-- back to WGS84))ASbuffer_geojsonFROMhospitals;
Pattern 9 β Track which admin region a GPS point falls in
1
2
3
4
5
6
7
8
-- Reverse geocode: find which city a point belongs toSELECTc.nameAScity,c.countryFROMcitiescWHEREST_Contains(c.boundary,ST_PointFromText('POINT(31.2357 30.0444)',4326))LIMIT1;
Pattern 10 β Spatial join: count points per polygon
1
2
3
4
5
6
7
8
-- Count stores per districtSELECTd.nameASdistrict,COUNT(s.id)ASstore_countFROMdistrictsdLEFTJOINstoressONST_Contains(d.boundary,s.position)GROUPBYd.id,d.nameORDERBYstore_countDESC;
Quick Reference Card
Task
Function(s)
Create point from lng/lat
ST_PointFromText('POINT(lng lat)', 4326)
Get coordinates
ST_X(pt) β lng, ST_Y(pt) β lat
Distance (spherical)
ST_Distance_Sphere(pt_a, pt_b) β meters
Point inside polygon
ST_Contains(polygon, point)
Points in radius
ST_Distance_Sphere(pt, center) <= radius
Overlap check
ST_Intersects(geom_a, geom_b)
Merge polygons
ST_Union(poly_a, poly_b)
Expand shape
ST_Buffer(geom, distance)
Shape center
ST_Centroid(geom)
Bounding box
ST_Envelope(geom)
Convert to GeoJSON
ST_AsGeoJSON(geom)
Convert to WKT
ST_AsText(geom)
Reproject
ST_Transform(geom, target_srid)
Validate geometry
ST_IsValid(geom)
Syntax primarily shown for MySQL 8.x. PostGIS (PostgreSQL), SQL Server, Oracle, and SpatiaLite (SQLite) alternatives noted throughout.