[GIS] Center of a bounding box

extentsgdalpython

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?

Best 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)