
Creating points
This is a very important function, since tabular data with coordinates stored in separate columns is quite abundant. Examples include geocoded address lists, survey results, and telemetry measurements. Such data can be converted to geometry using the ST_MakePoint function:
SELECT ST_MakePoint(391390,5817855);
Given two numbers, it creates a point geometry. To make it clear what the location really is, and make the created geometry suitable for spatial analysis, an SRID must be given. This can be accomplished using a ST_SetSRID function. So the complete example will be:
SELECT ST_SetSRID(ST_MakePoint(391390,5817855),32633);
The number 32633 is an SRID for UTM coordinates zone 33 north, and in this case, the coordinate pair 391390,5817855 denotes the Hallesches Tor in Berlin.
When the two dimensions aren't enough, a third argument can be added with a Z-coordinate value:
SELECT ST_SetSRID(ST_MakePoint(334216.6,5077675.3,4810),32632);
This will output a 3D point geometry for Mont Blanc peak in the UTM zone 32 north coordinate system.
For geometries with both Z-coordinates and M-coordinates (M for measure, linear referencing) there are third and fourth arguments, the fourth meaning M-value:
SELECT ST_SetSRID(ST_MakePoint(503612.6,5789004.9,89.5,4.408),32634);
This will output a 4D point geometry for Warsaw East train station, located at 503612.6,5789004.9 UTM 34N, 89.5 meters above mean sea level and 4.408 kilometers from the beginning of the line at Central Station.
When a point has an M value but no Z, there is a special ST_MakePointM function:
SELECT ST_SetSRID(ST_MakePointM(503612.6,5789004.9,4.408),32634);
It takes three arguments: X, Y, and M values.