0

I need to query the bounding box of a table (in WGS 84, srid 4326), and transform it to Web Mercator to be consumed by an OpenLayers map.

Currently, I am using this to retrieve the bounding box:

SELECT ST_Extent(geom) FROM mytable

Which returns the string "BOX(2067507.49369776 650368.674310103,2095742.80207396 691604.021270793)". I have tried a variety of ways to transform this, but none have worked.

Transforming the geometry before getting the extent doesn't work:

SELECT ST_Extent(ST_Transform(geom, 3857)) FROM mytable

It returns:

ERROR:  transform: couldn't project point (2.0841e+06 678457 0): latitude or longitude exceeded limits (-14)

Does anyone know what would be causing this error?

7

That coordinate set isn't in SRID 4326. If it was in 4326, it would look like a longitude / latitude pair. The error is telling you whats wrong - its expecting something in the range [-180...180, -90...90].

You need to figure out what the real source SRID is.

  • You're right. It turns out that the data wasn't projected upon import - it was just assigned the SRID. I re-imported it properly, and now it transforms fine. It being in the wrong spatial reference hadn't crossed my mind since the data displayed properly in QGIS and TileMill. Thanks. – Tanner Nov 15 '13 at 17:31
2

How about:

select st_transform(st_extent(geom,900913),4326) from mytable;

Or the way around:

select st_transform(st_extent(geom,4326),900913) from mytable;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.