Introduction
Points
10. ST_X, ST_Y
Linestrings
Polygons
Summary

Instruction

Excellent. We already mentioned that a point represents a single location on Earth. It has a shape and length of 0. This has both its advantages and disadvantages. On one hand, points take up very little space in spatial databases. Calculations performed with points are also quick. On the other hand, we can't precisely define the shapes of objects represented with points. They are therefore suitable representations of simple objects whose shape does not matter to us, such as tram stops, ATMs, post boxes or road signs.

At this point in the course, it is worth getting to know two functions that can be used to work with points: ST_X(geometry) and ST_Y(geometry). These functions return the X and Y coordinates, respectively, of a point.

SELECT 
  ST_X(coordinates) 
FROM sf_atms;

The above query will return the X coordinates (longitudes) of all ATMs in San Francisco.

Exercise

For each tram stop with possible changes to other lines, show the coordinates as WKT, then the latitude, and then the longitude.

Stuck? Here's a hint!

Use those three functions in the SELECT clause: ST_AsText, ST_X, ST_Y.

Console

Code editor

Result

TableConsole