Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i have a shapefile of country subdivisions and i would like to extract an array of bounding lat and lon for each division.. is it possible to do?

share|improve this question
Please clarify: do you have a shapefile or an Excel file? – whuber Nov 24 '10 at 15:08
The title doesn't really reflect your question, please think about editing it. – DavidF Nov 24 '10 at 15:21
i have a shapefile – mossplix Nov 24 '10 at 15:43
up vote 24 down vote accepted

Using the ogr Python module from OSGEO, this example will give you a tuple containing the coords that define an envelope for each feature.

from osgeo import ogr

ds = ogr.Open("mn_counties.shp")
lyr = ds.GetLayerByName("mn_counties")


for feat in lyr:
    # get bounding coords in minx, maxx, miny, maxy format
    env = feat.GetGeometryRef().GetEnvelope()
    # get bounding coords in minx, miny, maxx, maxy format
    bbox = [env[0], env[2], env[1], env[3]]
    print env
    print bbox
share|improve this answer
+1 for python :D – mossplix Nov 24 '10 at 15:45
... and free geospatial python at that ; / – DavidF Nov 24 '10 at 15:56

One possible way to proceed using SAGA GIS After opening your shapefile run these 3 modules: 1. Modules\Shapes\Tools\Get Shapes extent

  1. Modules\Shapes\Tools\Points\Points from lines [contrary to what the name suggest you can also use this to get points from a polygon]

  2. Modules\Shapes\Tools\Points\Add Coordinates to points This will give you a table which contains the x and y coordinates of the 4 corners of the bounding box of your polygon file.

share|improve this answer

In arcgis, here's python code. result is a list of minx, miny, maxx, maxy, minM, maxM, minZ, maxZ (

import arcpy
for feat in arcpy.SearchCursor(r"c:\data\f.gdb\counties"):
    print feat.Shape.extent

-2.66852727251546 49.4265363633626 -2.52848181818121 49.5079454546192 NaN NaN NaN NaN
-10.463336363782 51.4455454544593 -6.01305454583045 55.3799909091533 NaN NaN NaN NaN
-4.77778181827614 54.0555454544593 -4.35347272688468 54.4100000000002 NaN NaN NaN NaN
share|improve this answer

Here's an R version, using example data from the rgdal package:

dsn <- system.file("vectors/ps_cant_31.MIF", package = "rgdal")[1]
d <- readOGR(dsn = dsn, layer="ps_cant_31")

## transform if this is not longlat
if (is.projected(d)) d <- spTransform(d, CRS("+proj=longlat +ellps=WGS84"))

for (i in 1:nrow(d)) {
share|improve this answer

I use fiona and shapely for that kind of tasks:

import fiona
from shapely.geometry import shape

with'd:\Projects\_00_Data\_USstates\fe_2007_us_state00.shp', 'r') as features:
    for i, feat in enumerate(features):
        geom = shape(feat['geometry'])
        name = feat['properties']['NAME00']
        print ','.join((name,) + tuple([str(i) for i in geom.bounds]))
share|improve this answer

Your Answer


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.