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 a folder full of about 2000 files and I would like to generate a kind of key map for each file so people don't need to just randomly load each one in order to find what is what.

I have the following python code using ogr but OGREnvelope isn't really a OGRGeometry so I can't add it to a shape file or export it as wkt to import in QGIS.

for filename in glob.glob(path + "*.shp"):
   ds = ogr.Open(filename)
   layer1 = ds.GetLayer(0)
   #print filename + " : " + str(layer1.GetExtent())
   extent = layer1.GetExtent()
   # I need to be able to export the extent region as a polygon.

I have been looking around but just can't seem to find anything. I really thought something like this would be easy.

share|improve this question
add comment

1 Answer 1

up vote 6 down vote accepted

You can make your own WKT from this. You can try adding something like this to your code.

print 'POLYGON((' \
          + str(extent[0]) + ' ' + str(extent[1]) + ', ' \
          + str(extent[0]) + ' ' + str(extent[3]) + ', ' \
          + str(extent[2]) + ' ' + str(extent[3]) + ', ' \
          + str(extent[2]) + ' ' + str(extent[1]) + ', ' \
          + str(extent[0]) + ' ' + str(extent[1]) + '))'
share|improve this answer
    
Ahh cool. Didn't know you could access the nodes using a index [] –  Nathan W Sep 23 '11 at 5:14
add comment

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.