We've already learned how to change the internal PostGIS format to WKT (via the
ST_AsText function). How about doing it the other way round?
ST_GeomFromText function allows us to change the coordinates we provided to the internal PostGIS format. It may help us to check whether something in our data corresponds to the provided longitude and latitude. Let's suppose that we have latitude = 37.468980000000002 and longitude = -122.432969999999997. It's quite easy to make a point with this information: simply type
POINT and pass in the longitude and latitude as the arguments, in that order, like so:
Note that we inverted the longitude and latitude. As we mentioned previously, the longitude comes first in PostGIS!
Alright, now that we've constructed our point, we can check whether something corresponds to these coordinates in the
sf_atms table. Let's take a look at how this can be done:
WHERE coordinates = ST_GeomFromText(
There are two very important things worth noting. First, we had to put our
POINT(-122.432969999999997 37.468980000000002) into quotation marks. This is because
ST_GeomFromText expects a string as its first argument. The second argument is an SRID. In this case the SRID equals 4326. Don't worry about what SRIDs are. We'll get to it in a while.