[GIS] Reprojecting in postGIS from 900913 to 4326. Wrong coordinates

coordinate systemleafletpostgissrid

I'm working with postGIS 2.1
I have a table called 'xacementos' created with the srid: 900913. I took the points coordinates from google maps and I want to convert them to SRID:4326 to show the points in a map created over leaflet. (if a input the 900913 coordinates as geoJSON in the leaflet code the points show a little bit displaced)
I'm using the function ST_Transform:

SELECT ST_AsText(ST_Transform(geom,4326))
FROM xacementos
WHERE enderezo='Rua Franja 9-11';

but the coordinates that show up are not correct:

"POINT(-7.54315344075162e-005 0.000389606525237254)"

The input coordinates in the 900913 srid are "POINT(-8.397 43.3708)"

I'm newby in this postGIS stuff and I'm not sure if i'm following the right path.

Any suggestion??

Best Answer

I guess you are confused with what the different coordinates are.

EPSG:900913 (officially EPSG:3857) has an extent (worldwide) of

-20037508.34,-20037508.34,20037508.34,20037508.34

Your point (-8.397 43.3708) does not seem to be in this range (it's in portugal, right?)

This means that your point is in EPSG:4326 ("lat/lons") already.

You saying that "I took the points coordinates from google maps" confirms this to me, as google maps uses spherical mercator (EPSG:900913) internally, but it's api (and web pages) exposes all coordinates as EPSG:4326

Therefore, you should store your coordinates in PostGIS with EPSG:4326, and if this is what you need to get out there should be no need for transformations.

Related Question