@@ -78,12 +78,16 @@ def main(video, output_dir):
7878
7979 click .secho (f'JSON output written to { output_json } ' , fg = 'green' )
8080
81- create_geojson_and_bbox (frames , geojson_out , bbox_out , bbox_geojson_out )
81+ geojson_data = create_geojson_and_bbox (frames )
82+ with open (geojson_out , 'w' ) as f :
83+ json .dump (geojson_data , f , indent = 2 )
84+ click .secho (f'GeoJSON data created with { len (geojson_data ["features" ])} features.' , fg = 'green' )
8285 click .secho (f'GeoJSON written to { geojson_out } ' , fg = 'cyan' )
83- click .secho (f'Bounding box mapping written to { bbox_out } ' , fg = 'cyan' )
8486
8587
86- def create_geojson_and_bbox (frames , geojson_out , bbox_out , bbox_geojson_out ):
88+ def create_geojson_and_bbox (
89+ frames ,
90+ ):
8791 geod = pyproj .Geod (ellps = 'WGS84' )
8892 features = []
8993 polygons = []
@@ -120,14 +124,15 @@ def create_geojson_and_bbox(frames, geojson_out, bbox_out, bbox_geojson_out):
120124
121125 # Point feature at sensor location
122126 point = Point (sensor_lon , sensor_lat )
127+ properties = {"fmvType" : "flight_path" }
128+ properties ["frameId" ] = int (frame_id )
129+ for key , value in frame .items ():
130+ properties [key ] = value
131+
123132 feature = {
124133 "type" : "Feature" ,
125134 "geometry" : mapping (point ),
126- "properties" : {
127- "Frame ID" : frame_id ,
128- "Platform Ground Speed" : frame .get ("Platform Ground Speed (m/s)" ),
129- "Platform Vertical Speed" : frame .get ("Platform Vertical Speed (m/s)" )
130- }
135+ "properties" : properties ,
131136 }
132137 features .append (feature )
133138
@@ -138,58 +143,29 @@ def create_geojson_and_bbox(frames, geojson_out, bbox_out, bbox_geojson_out):
138143 # Add unioned polygon
139144 if polygons :
140145 merged = unary_union (polygons )
141- features .append ({
142- "type" : "Feature" ,
143- "geometry " : mapping ( merged ) ,
144- "properties " : {
145- "type " : "Unioned Bounding Box"
146+ features .append (
147+ {
148+ "type " : "Feature" ,
149+ "geometry " : mapping ( merged ),
150+ "properties " : { "fmvType" : "ground_union" },
146151 }
147- })
148-
149- # Save GeoJSON
150- geojson = {
151- "type" : "FeatureCollection" ,
152- "features" : features
153- }
154-
155- with open (geojson_out , 'w' ) as f :
156- json .dump (geojson , f , indent = 2 )
157-
158- # Save bbox mapping
159- with open (bbox_out , 'w' ) as f :
160- json .dump (frame_to_bbox , f , indent = 2 )
161-
162- def get_gradient_color (idx , total ):
163- r = int (255 * (idx / (total - 1 )))
164- b = int (255 * (1 - idx / (total - 1 )))
165- return f"#{ r :02x} 00{ b :02x} "
152+ )
166153
167154 # Individual frame bbox polygons with styling
168- bbox_features = []
169155 for idx , (frame_id , poly ) in enumerate (frame_polygons ):
170- color = get_gradient_color (idx , total )
171156 feature = {
172157 "type" : "Feature" ,
173158 "geometry" : mapping (poly ),
174159 "properties" : {
175- "frame_id" : frame_id ,
176- "type" : "Unioned Bounding Box" ,
177- "stroke" : color ,
178- "stroke-width" : 2 ,
179- "stroke-opacity" : 1 ,
180- "fill" : "#ff0000" ,
181- "fill-opacity" : 0.5
182- }
160+ "frameId" : int (frame_id ),
161+ "fmvType" : "ground_frame" ,
162+ },
183163 }
184- bbox_features .append (feature )
164+ features .append (feature )
185165
186- bbox_geojson = {
187- "type" : "FeatureCollection" ,
188- "features" : bbox_features
189- }
166+ geojson = {"type" : "FeatureCollection" , "features" : features }
190167
191- with open (bbox_geojson_out , 'w' ) as f :
192- json .dump (bbox_geojson , f , indent = 2 )
168+ return geojson
193169
194170if __name__ == '__main__' :
195171 main ()
0 commit comments