-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdescribe_geodata.py
More file actions
34 lines (27 loc) · 1.03 KB
/
describe_geodata.py
File metadata and controls
34 lines (27 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from osgeo import ogr,osr
import csv
import os
f_output = open('output.csv','wb')
fieldnames_data = ('NAME','GTYPE','PROJECTION','COUNT')
csvwriter_output = csv.DictWriter(f_output, fieldnames=fieldnames_data)
ff = []
for (dirpath, dirnames, filenames) in os.walk('.'):
for filename in filenames:
if filename.endswith('.tab'.upper()):
ff.append(os.sep.join([dirpath, filename]))
for f in ff:
print(f.decode('cp1251'))
ogrData = ogr.Open(f.decode('cp1251'), False)
layer = ogrData[0]
count = layer.GetFeatureCount()
prj = layer.GetSpatialRef().ExportToWkt()
srs = osr.SpatialReference(wkt=prj)
if srs.IsProjected() != 0:
projection = srs.GetAttrValue('PROJECTION')
else:
projection = "Geographic"
gtype = layer.GetGeomType()
csvwriter_output.writerow(dict(NAME=f,
GTYPE=ogr.GeometryTypeToName(gtype),
PROJECTION=projection,
COUNT=count))