[GIS] Coordinate values are out of range [-180 -90, 180 90] for GEOGRAPHY type

osm2pgsqlpostgissrid

After import some data from OSM file into Postgre, the coordinates numbers are too big and having trouble to cast to Geography:

Coordinate values are out of range [-180 -90, 180 90] for GEOGRAPHY type

In my table:

select ST_AsText( the_geom )  from routes limit 4

"LINESTRING(-4902130.86 -2265840.91,-4902083.04 -2265907.16)"
"LINESTRING(-4903296.22 -2266295.18,-4903363.69 -2266333.39)"
"LINESTRING(-5705594.67 -3518944.1,-5705523.22 -3518937.37)"
"LINESTRING(-5484056.84 -1884629.16,-5484093.47 -1884510.24)"

I think the numbers should be between (-90 / 90, -180 / 180) …

Info:

1: select ST_SRID( the_geom ) returns 900913 for all lines.

2: select UpdateGeometrySRID('public', 'routes', 'the_geom', 4326) does not converts the numbers, but SRID now shows 4326.

Best Answer

From @Jakub Kania tip :

ALTER TABLE routes ADD temp geometry;
select UpdateGeometrySRID('public', 'routes', 'temp', 4326) ;
update routes set temp = ST_Transform(the_geom,4326);
select UpdateGeometrySRID('public', 'routes', 'the_geom', 4326) ;
update routes set the_geom = temp;
alter table routes drop column temp;