Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Using the PostGIS shp2pgsql -s 4326 ... I generated the sql file and created my spatially enabled table.

When executing my query:

select box2d(ST_extent(the_geom)) from feature_data;

I'm returned with:

BOX(490755.1875 5460528,504640.4375 5466997)

My result appears to be in Easting and Northing, but I would like to return the bounding box in latitude / longitude. I have limited experience with GIS. How can I convert this result to the latitude / longitude coordinate system?

share|improve this question
    
It doesn't seem like the shapefile you started off with was using EPSG:4326. Check the projection information using a desktop GIS or reading the information in the .prj file. –  underdark Aug 12 '11 at 20:40
    
It looks like it's using Transverse_Mercator. The contents of the .proj file: PROJCS["NAD_1983_UTM_Zone_10N",GEOGCS["GCS_North_American_1983",DATUM["D_North_A‌​merican_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.‌​0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER‌​["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Mer‌​idian",-123.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.‌​0],UNIT["Meter",1.0]] –  Adam Kahtava Aug 13 '11 at 16:15

2 Answers 2

use ST_Transform

Returns a new geometry with its coordinates transformed to spatial reference system referenced by the SRID integer parameter. The destination SRID must exist in the SPATIAL_REF_SYS table.

ST_Transform is often confused with ST_SetSRID(). ST_Transform actually changes the coordinates of a geometry from one spatial reference system to another, while ST_SetSRID() simply changes the SRID identifier of the geometry

    SELECT ST_AsText(ST_Transform(ST_GeomFromText('POLYGON((743238 2967416,743238 2967450,
    743265 2967450,743265.625 2967416,743238 2967416))',2249),4326)) As wgs_geom;

 wgs_geom
---------------------------
 POLYGON((-71.1776848522251 42.3902896512902,-71.1776843766326 42.3903829478009,
-71.1775844305465 42.3903826677917,-71.1775825927231 42.3902893647987,-71.177684
8522251 42.3902896512902));
(1 row)

http://www.postgis.org/docs/ST_Transform.html

For you

feature_data(ST_Transform(ST_GeomFromText(ASTEXT(ST_EXTENT(ST_Envelope(wkb_geometry))),YOUR_SRID),4326))

Change 'YOUR_SRID' to your data SRID

share|improve this answer
    
'select ST_Transform(ST_GeomFromText(AsText(ST_Extent(ST_Envelope(the_geom))),4326),4326‌​) from feature_data;' Doesn't return lat / long coordinates, it returns: '0103000020E610000001000000050000005839B4C80CF41D41871659088CD454415839B4C80CF41‌​D415A643B3BDDDA5441BC7493A801CD1E415A643B3BDDDA5441BC7493A801CD1E41871659088CD454‌​415839B4C80CF41D41871659088CD45441' 'select AsText(ST_Extent(ST_Envelope(the_geom))) from feature_data;' returns a polygon in an alternate format also. The result: 'POLYGON((490755.196 5460528.1304375,490755.196 5466996...))' Suggestions? –  Adam Kahtava Aug 15 '11 at 17:54

Looks like your shapefile uses the following projection: http://spatialreference.org/ref/sr-org/6855/

At least this looks like the content of the .prj file you posted: http://spatialreference.org/ref/sr-org/6855/html/

To add this reference system to PostGIS, you can run: http://spatialreference.org/ref/sr-org/6855/postgis/

The correct query then would be:

SELECT box2d(ST_Transform(ST_SetSRID(the_geom,96855),4326)) FROM feature_data;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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