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.

I have bounding box coordinates of my shapefile
(fetched from layer.GetExtent() Python with GDAL/OGR):

(-38.6102467739459, -38.017601026186576, 33.01563382506067, 33.624945228091406)

So I assume it's SW and NE points of the rectangle.

I would like to find out the center of this rectangle (in lat/lon).
How should I proceed?

share|improve this question
    
the order is minx,maxx,miny,maxy –  nickves Jun 21 '13 at 12:30

3 Answers 3

calculate the width and height of the box by subtracting one corner from the other then add half the width to the left edge and half the height to the bottom edge.

share|improve this answer

for a small bbox, in a long/lat coordinate system, you can assume the earth is flat at that area and you can use the average of x and y:

 >>> coords = (-38.6102467739459, -38.017601026186576, 33.01563382506067, 33.624945228091406)

 >>> centerx,centery = ( numpy.average(coords[:2]),numpy.average(coords[2:]))

 >>> centerx,centery
(-38.313923900066243, 33.320289526576033)
share|improve this answer

you can use st_box2 and st_centroid functions

select
          st_astext(st_centroid(st_box2d(
                                st_geomfromtext('LINESTRING(-38.6102467739459 33.624945228091406, -38.017601026186576 33.01563382506067)',4326)
                                                )
                                )
                    ) CENTER;


                   center 
------------------------------------------  
 POINT(-38.3139239000662 33.320289526576)

Be careful of the order you plug in the coordinates.

share|improve this answer
    
I'm not using postgis, but python gdal/ogr... –  eouti Jun 21 '13 at 12:10
1  
lol, sorry i was reading some postgis questions :) –  nickves Jun 21 '13 at 12:16

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.