Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

intersector now creates Intersection object.

Exports to GeoJSON if needed (Intersection obj has geointerface)
  • Loading branch information...
commit 5321646b6beed7c63b8a285f9e9d34ea2415d18c 1 parent 8502598
Marc Poulhiès authored

Showing 2 changed files with 74 additions and 23 deletions. Show diff stats Hide diff stats

  1. +12 0 airspace/__init__.py
  2. +62 23 bin/intersector.py
12 airspace/__init__.py
@@ -29,3 +29,15 @@ def __geo_interface__(self):
29 29 'properties': self.meta,
30 30 'geometry': self.geometry}
31 31 return f
  32 +
  33 +class Intersection:
  34 + def __init__(self, zone, tracks):
  35 + self.zone = zone
  36 + self.tracks = tracks
  37 +
  38 + @property
  39 + def __geo_interface__(self):
  40 + f= {'type' : 'GeometryCollection',
  41 + 'geometries' : [self.zone, self.tracks]
  42 + }
  43 + return f
85 bin/intersector.py
@@ -24,6 +24,7 @@
24 24 import rtree
25 25 import airspace.altiresolver
26 26 import argparse
  27 +import geojson
27 28
28 29 def main():
29 30 parser = argparse.ArgumentParser(description='Check airspace.')
@@ -41,6 +42,10 @@ def main():
41 42 parser.add_argument('--altiresolver-ossim-config', metavar='FILE', type=str,
42 43 help='Config file path for ossim mode',
43 44 required=False)
  45 +
  46 + parser.add_argument('--dumpjson', metavar='FILE', type=str,
  47 + help='dump intersecting data as GeoJSON in FILE',
  48 + required=False)
44 49
45 50 args = parser.parse_args()
46 51
@@ -97,49 +102,83 @@ def main():
97 102 for pot_zone in potential_zones:
98 103 print "-", pot_zone[0].meta['name']
99 104
100   - potential_zones2 = []
  105 + potential_zones2 = {}
101 106
102 107 for pot_zone,track in potential_zones:
103 108 if track.intersects(pot_zone.geometry):
104 109 inter_track = track.intersection(pot_zone.geometry)
105   - potential_zones2.append((pot_zone, track, inter_track))
  110 + inters = potential_zones2.get(pot_zone, [])
  111 + inters.append(inter_track)
  112 + potential_zones2[pot_zone] = inters
106 113
107 114 print "Found %d potential zone(s):" % len(potential_zones2)
108   -
109   - confirmed_zones = []
110 115
111   - for pot_z,t,it in potential_zones2:
  116 + for p in potential_zones2:
  117 + print "-", p.meta['name']
  118 +
  119 + confirmed_zones = {}
  120 +
  121 + for pot_z in potential_zones2:
112 122 confirmed = False
113 123 import shapely.geometry.multilinestring
114 124 import shapely.geometry.linestring
115 125
116   - if isinstance(it, shapely.geometry.multilinestring.MultiLineString):
117   - for it_ls in list(it):
118   - for p in it_ls.coords:
  126 + for it in potential_zones2[pot_z]:
  127 + if isinstance(it, shapely.geometry.multilinestring.MultiLineString):
  128 + for it_ls in list(it):
  129 + new_inter_coords = []
  130 + for p in it_ls.coords:
  131 + floor = airspace.util.getFloorAtPoint(altir, pot_z.meta, p[0], p[1])
  132 + ceil = airspace.util.getCeilAtPoint(altir, pot_z.meta, p[0], p[1])
  133 + if p[2] > floor and p[2] < ceil:
  134 + new_inter_coords.append(p)
  135 + elif new_inter_coords:
  136 + l = confirmed_zones.get(pot_z,[])
  137 + l.append(new_inter_coords)
  138 + confirmed_zones[pot_z] = l
  139 + new_inter_coords = []
  140 + ## print floor, "<", p[2], "<", ceil
  141 + # if not confirmed:
  142 + # confirmed_zones.append(pot_z)
  143 + # confirmed = True
  144 +
  145 + elif isinstance(it, shapely.geometry.linestring.LineString):
  146 + new_inter_coords = []
  147 + for p in it.coords:
119 148 floor = airspace.util.getFloorAtPoint(altir, pot_z.meta, p[0], p[1])
120 149 ceil = airspace.util.getCeilAtPoint(altir, pot_z.meta, p[0], p[1])
  150 +
121 151 if p[2] > floor and p[2] < ceil:
122   - ## print floor, "<", p[2], "<", ceil
123   - if not confirmed:
124   - confirmed_zones.append(pot_z)
125   - confirmed = True
126   -
127   - elif isinstance(it, shapely.geometry.linestring.LineString):
128   - for p in it.coords:
129   - floor = airspace.util.getFloorAtPoint(altir, pot_z.meta, p[0], p[1])
130   - ceil = airspace.util.getCeilAtPoint(altir, pot_z.meta, p[0], p[1])
131   - if p[2] > floor and p[2] < ceil:
  152 + new_inter_coords.append(p)
  153 + elif new_inter_coords:
  154 + l = confirmed_zones.get(pot_z,[])
  155 + l.append(new_inter_coords)
  156 + confirmed_zones[pot_z] = l
  157 + new_inter_coords = []
  158 +
132 159 ## print floor, "<", p[2], "<", ceil
133   - if not confirmed:
134   - confirmed_zones.append(pot_z)
135   - confirmed = True
  160 + # if not confirmed:
  161 + # confirmed_zones.append(pot_z)
  162 + # confirmed = True
  163 +
  164 + intersections = []
  165 + for z in confirmed_zones:
  166 + i = airspace.Intersection(z, shapely.geometry.multilinestring.MultiLineString(confirmed_zones[z]))
  167 + intersections.append(i)
136 168
137   - print "Confirmed zone(s) :", len(confirmed_zones)
  169 + print "Confirmed zone(s) :", len(confirmed_zones), len(intersections)
138 170 for conf_zone in confirmed_zones:
139 171 print "-", conf_zone.meta['name']
140 172
  173 + if args.dumpjson:
  174 + fout = open(args.dumpjson, "w")
  175 + izs = geojson.GeometryCollection(intersections)
  176 + print >> fout, "var intersections = " + geojson.dumps(izs) + ';\n'
  177 + fout.close()
  178 +
141 179 return 0
142   -
  180 +
  181 +
143 182
144 183 if __name__ == "__main__":
145 184 main()

0 comments on commit 5321646

Please sign in to comment.
Something went wrong with that request. Please try again.