Browse Source

use rtree for first filtering: use boost

rtree
Marc 12 years ago
parent
commit
31b2093d26
  1. 17
      airspace/parser.py
  2. 6
      airspace/zone.py
  3. 7
      test-intersection-from-oair.py

17
airspace/parser.py

@ -85,14 +85,25 @@ re_lines = [aclass,
class ZoneIndex:
def __init__(self):
self.list = []
idx = Rtree()
self.rtree_idx = Rtree()
self.idx = 0
def append(self, zone):
self.idx.add(self.idx, zone.poly.GetEnvelope())
zone.finish()
minLong,maxLong,minLat,maxLat = zone.poly.GetEnvelope()
bbox = (minLong, minLat, maxLong, maxLat)
## print "bbox: ", bbox
self.rtree_idx.add(self.idx, bbox)
self.idx += 1
self.list.append(zone)
def __len__(self):
return len(self.list)
def intersection(self, bbox):
minLong,maxLong,minLat,maxLat = bbox
n_bbox = (minLong, minLat, maxLong, maxLat)
return [self.list[i] for i in self.rtree_idx.intersection(n_bbox)]
class OAIRParser:
"""

6
airspace/zone.py

@ -133,8 +133,10 @@ class PolyZone(Zone):
"""
Closes the zone and returns the polygon
"""
self.ring.CloseRings()
self.poly.AddGeometry(self.ring)
if self.ring :
self.ring.CloseRings()
self.poly.AddGeometry(self.ring)
self.ring = None
return self.poly

7
test-intersection-from-oair.py

@ -40,7 +40,12 @@ found_an_intersection = 0
intersected_segs = []
for zone in p.zones:
print "Track bbox: ", track.GetEnvelope()
zones_to_check = p.zones.intersection(track.GetEnvelope())
print "Potential crossed zones:", len(zones_to_check)
for zone in zones_to_check:
##for zone in p.zones.list:
poly = zone.finish()
if poly.Intersect(track):
found_an_intersection += 1

Loading…
Cancel
Save