Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction to spatial databases
4. Foretaste of part 2
Short quiz

Instruction

For our purposes, the most important format for geometries will be Well-Known Text (WKT), which is a text representation that human beings can actually read. In order to convert a geometry column into WKT, we have to use the ST_AsText function, like so:

SELECT 
  ST_AsText(coordinates)
FROM st_atms
...

Thanks to this function, instead of a crazy sequence of characters that make no sense to us, we can get a nice and neat and relatively comprehensible form of something like: POINT(-122.392016105263 37.6138040015053). From the name, you can immediately tell that the above data represents a point. Furthermore, its coordinates are specified inside the parentheses. We'll discuss this in detail in the next part of the course. Stay tuned!

Exercise

In our database there is a table called sf_tram_stops. Select the following columns from the table:

  • id,
  • coordinates,
  • coordinates column represented as WKT (name the column wkt).

You can now see that the wkt column is much more readable than the original coordinates column.

Stuck? Here's a hint!

In order to convert the coordinates column to text, use the ST_AsText(coordinates) function.