My table has a geometric field, in EPSG:3857, of type point. I need the latitude and longitude, in EPSG: 4326, of each point. Could someone give me a valid example of how to use ST_Transform().
From the PostGIS docs,
ST_Transform — Returns a new geometry with its coordinates transformed to the SRID referenced by the integer parameter.
geometry ST_Transform (geometry g, integer srid);
So, to read transformed points
SELECT ST_AsText (ST_Transform (geom, 4326)) FROM table ...
If you want long and lat as separate fields
SELECT ST_X (ST_Transform (geom, 4326)) AS long, ST_Y (ST_Transform (geom, 4326)) AS lat FROM table ...
Try this below. ST_AsText returns the well-known text. ST_X and ST_Y return the actual longitude and latitude (assuming geom is in the appropriate SRS).
SELECT ST_AsText(geom), ST_X(geom), ST_Y(geom) FROM table
SRID to your table:
SELECT UpdateGeometrySRID('Table Name' , 'the_geom' ,32645)
SELECT *, ST_X(ST_Transform (the_geom, 4326)) AS "Longitude", ST_Y(ST_Transform (the_geom, 4326)) AS "Latitude" FROM "Table Name"
These st_x/st_y functions are confusing. I am working with PostGresQL/PostGIS 2.4 as we speak. This is the bounding rect roughly enclosing the country of Kenya:
bounds.northeast = new LatLng(4.959918, 41.012352); bounds.southwest = new LatLng(-1.603490, 33.849266);
Converting one of the points into a geometry object, then use st_x() = 4.95... st_y()=41.012... If you use google maps, x is latitude and y is longitude !