-
Notifications
You must be signed in to change notification settings - Fork 2
/
bextest.py
49 lines (41 loc) · 1.33 KB
/
bextest.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
# Bextest.py tests binning algoritms against an existing .sbn file
#
import shapefile
from hasbeen import HasBeen
from bextree import Tree
from mapper import mapshapefile
from spatialindex import SBN
import sys
if len(sys.argv) > 1:
shpfile = sys.argv[1]
else:
print "Usage: bextest.py [shapefile]"
print "Bins the features in a shapefile and compares it to an existing sbn"
sys.exit()
h = HasBeen(shpfile)
# open up the existing sbn to compare against
sbn = SBN(shpfile + ".sbn")
# compare the generated sbn versus ESRI's
for id, bin in enumerate(sbn.bins):
if id ==0 : continue
a = len(bin.features) == len(h.bins[id].features)
if not a:
print "Bin %s -" % id,
print "E: %s, L:%s" % (len(bin.features), len(h.bins[id].features))
if len(bin.features) > 0:
tb = bin.features
else:
tb = h.bins[id].features
xmin = 255
ymin = 255
xmax = 0
ymax = 0
for f in tb:
print "%s," % f.id,
xmin = min(xmin,f.xmin)
ymin = min(ymin,f.ymin)
xmax = max(xmax,f.xmax)
ymax = max(ymax,f.ymax)
print "\n f_bbox %s-%s,%s-%s" % (xmin,xmax,ymin,ymax)
node = t.nodes[id]
print " node %s-%s,%s-%s/%s\n" % (node.xmin,node.xmax,node.ymin,node.ymax,node.splitcoord)