License New BSD license
Lines 33
Keywords
extents (3) GIS (7) OGR (2) vector (5)
Permissions
Viewable by Everyone
Editable by All Siafoo Users

Find Extents of GIS Vector Data Atom Feed 1

In Brief Gets the extents (range of coordinates covered by the data) of any OGR-compatible vector data file and returns them as [minx, miny, maxx, maxy].
# 's
 1# Copyright 2007 Regents of the University of California
2# Written by David Isaacson at the University of California, Davis
3# BSD License
4
5import ogr, os
6
7def findOGRCoordinates(path):
8 if not os.path.isfile(path):
9 return[]
10 dataSource = ogr.Open(path)
11 if not dataSource:
12 return []
13 extents = []
14 for i in range(0,dataSource.GetLayerCount()):
15 layer = dataSource.GetLayer(i)
16 extents.append(layer.GetExtent())
17
18 dataSource.Release()
19
20 if not extents:
21 return []
22 extent = extents[0]
23 minx = extent[0]
24 maxx = extent[1]
25 miny = extent[2]
26 maxy = extent[3]
27
28 if len(extents) > 1:
29 for extent in extents[1:]:
30 if extent[0]<minx: minx = extent[0]
31 if extent[1]>maxx: maxx = extent[1]
32 if extent[2]<miny: miny = extent[2]
33 if extent[3]>maxy: maxy = extent[3]
34
35 return [minx,miny,maxx,maxy]

Gets the extents (range of coordinates covered by the data) of any OGR-compatible vector data file and returns them as [minx, miny, maxx, maxy].