@@ -143,15 +143,23 @@ def main():
143143
144144 outfile = os .path .join ("/tmp/code" , "leeway" , "output" , args .id )
145145
146- simulation .run (
146+ ds = simulation .run (
147147 duration = timedelta (hours = args .duration ), time_step = 600 , outfile = f"{ outfile } .nc"
148148 )
149149
150150 # Plotting results
151- lon , lat = np .array (simulation .get_lonlats ())
151+ lon = ds ['lon' ].values
152+ lat = ds ['lat' ].values
152153 lon [lon == 0 ] = np .nan
153154 lat [lat == 0 ] = np .nan
154155
156+ segments = [
157+ [(float (lo ), float (la )) for lo , la in zip (lon_row , lat_row )]
158+ for lon_row , lat_row in zip (lon , lat )
159+ ]
160+
161+ geojson = segments_to_geojson (segments )
162+
155163 crs = ccrs .Mercator () # Mercator projection to have angle true projection
156164 gcrs = ccrs .PlateCarree (globe = crs .globe ) # PlateCarree for straight lines
157165
@@ -369,6 +377,28 @@ def get_zebra_line(points, gcrs):
369377 lc .set_linewidth (4 )
370378 return lc
371379
380+ def segments_to_geojson (segments ):
381+ """
382+ Convert a list of segments to a GeoJSON GeometryCollection of LineStrings.
383+
384+ Parameters:
385+ segments: list of shape (N, 2+) where each element is a list of (lon, lat) points
386+
387+ Returns:
388+ dict: GeoJSON GeometryCollection
389+ """
390+ geometries = [
391+ {
392+ "type" : "LineString" ,
393+ "coordinates" : [list (point ) for point in line ]
394+ }
395+ for line in segments
396+ ]
397+
398+ return {
399+ "type" : "GeometryCollection" ,
400+ "geometries" : geometries
401+ }
372402
373403if __name__ == "__main__" :
374404 main ()
0 commit comments