Skip to content

Instantly share code, notes, and snippets.

@jgcasta
Last active December 12, 2015 08:58
Show Gist options
  • Save jgcasta/4747435 to your computer and use it in GitHub Desktop.
Save jgcasta/4747435 to your computer and use it in GitHub Desktop.
Get the extent from a shapefile
#!/usr/bin/env python
# -*- coding: utf-8
"""
Get extent from SHP
version 1.0
autor José Gómez Castaño
email jgcasta@gmail.com
@precondition GDAL must be installed
"""
from os import chdir,system
from osgeo import ogr
system("clear")
driver = ogr.GetDriverByName('ESRI Shapefile')
dataSource1 = driver.Open('madrid.shp', 0)
layer1 = dataSource1.GetLayer()
extent = layer1.GetExtent()
print 'Extent:', extent
print 'UL:', extent[0], extent[3]
print 'LR:', extent[1], extent[2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment