-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGatherStatistics.py
115 lines (99 loc) · 4.53 KB
/
GatherStatistics.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
'''
Copyright 2018, US Army Geospatial Center, Leidos Inc., and Cognitics Inc.
Developed as a joint work by The Army Geospatial Center, Leidos Inc.,
and Cognitics Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
Software, and to permit persons to whom the Software is furnished to do so, subject
to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
'''
import os
import sys
#import shapeindex
#import shapemeta
import datetime
import random
#import dbfread
try:
from osgeo import ogr, osr, gdal
except:
sys.exit('ERROR: cannot find GDAL/OGR modules')
version_num = int(gdal.VersionInfo('VERSION_NUM'))
print("GDAL Version " + str(version_num))
if version_num < 2020300:
sys.exit('ERROR: Python bindings of GDAL 2.2.3 or later required due to GeoPackage performance issues.')
shpDriver = ogr.GetDriverByName("ESRI Shapefile")
gpkgDriver = ogr.GetDriverByName("GPKG")
#randomize indexes into array
#for each entry
#Plot layer count vs. open time across all options
# Open all GeoPackage files
#min/max/stddev for open times
#total time
def gatherGeoPackageStats(cDBRoot):
totalLayerCount = 0
totalOpenTime = 0
geoPackageStats = []
for root, dirs, files in os.walk(cDBRoot):
path = root.split(os.sep)
hasShapeFile = False
for file in files:
base,ext = os.path.splitext(file)
filePath = os.path.join(root,file)
if(ext==".gpkg"):
#start timer
geoPackageStart = datetime.datetime.now()
#open dataset
try:
#print("Opening " + filePath)
dataSource = ogr.Open(filePath)
if(dataSource == None):
print("Unable to open " + filePath)
continue
#count layers
layerCount = dataSource.GetLayerCount()
totalLayerCount = totalLayerCount + layerCount
del dataSource
#print("Closed " + filePath)
geoPackageEnd = datetime.datetime.now()
geoPackageDelta = geoPackageEnd - geoPackageStart
totalOpenTime = totalOpenTime + geoPackageDelta.total_seconds()
stat = [str(filePath),str(layerCount),str(geoPackageDelta.total_seconds())]
geoPackageStats.append(stat)
except Exception:
pass
averageOpenTime = totalOpenTime / len(geoPackageStats)
return len(geoPackageStats),totalLayerCount, averageOpenTime
'''
geoPackageStats.sort()
#write a csv file
gpkgStats = open("geopackageStats.csv",'w')
gpkgStats.write('layer_count,file,open_time\n')
for stat in geoPackageStats:
gpkgStats.write( str(stat[1]) + "," + stat[0] + "," + str(stat[2]) + "\n")
gpkgStats.close()
return geoPackageStats
'''
#Random layer query
#min/max/stddev for feature count query
#total time
#gatherGeoPackageStats("f:\\GeoCDB\\")
print("Option, Total GeoPackage Files, Average Layers, Average Open GeoPackage Time")
#numFiles,numLayers,avgOpen = gatherGeoPackageStats("f:\\GeoCDB\\Option1")
#print("Option 1, " + str(numFiles) + "," + str(numLayers / numFiles), + "," + str(avgOpen))
#numFiles,numLayers,avgOpen = gatherGeoPackageStats("f:\\GeoCDB\\Option2")
#print("Option 2, " + str(numFiles) + "," + str(numLayers / numFiles), + "," + str(avgOpen))
#numFiles,numLayers,avgOpen = gatherGeoPackageStats("f:\\GeoCDB\\Option3")
#print("Option 3, " + str(numFiles) + "," + str(numLayers / numFiles), + "," + str(avgOpen))
numFiles,numLayers,avgOpen = gatherGeoPackageStats("f:\\GeoCDB\\Option4")
print("Option 4, " + str(numFiles) + "," + str(numLayers / numFiles), + "," + str(avgOpen))