1717import io
1818import os
1919import shutil
20- from pprint import pprint
20+ from pprint import pprint
2121import json
2222
2323import pandas as pd
@@ -37,6 +37,7 @@ class BasePersister(Loggable):
3737 Class to persist the data to a file or cloud storage.
3838 If persisting to a file, the output directory is created by config._make_output_path()
3939 """
40+
4041 add_extension : str = "csv"
4142
4243 def __init__ (self ):
@@ -107,13 +108,14 @@ def add_extension(self, path: str):
107108
108109 def _write (self , path : str , records ):
109110 raise NotImplementedError
110-
111+
111112 def _dump_timeseries (self , path : str , timeseries : list ):
112113 raise NotImplementedError
113114
114115 def _make_output_directory (self , output_directory : str ):
115116 os .mkdir (output_directory )
116117
118+
117119def write_csv_file (path , func , records ):
118120 with open (path , "w" , newline = "" ) as f :
119121 func (csv .writer (f ), records )
@@ -221,19 +223,25 @@ def _write(self, path: str, records: list):
221223 "type" : "Feature" ,
222224 "geometry" : {
223225 "type" : "Point" ,
224- "coordinates" : [record .get ("longitude" ), record .get ("latitude" ), record .get ("elevation" )],
226+ "coordinates" : [
227+ record .get ("longitude" ),
228+ record .get ("latitude" ),
229+ record .get ("elevation" ),
230+ ],
231+ },
232+ "properties" : {
233+ k : record .get (k )
234+ for k in record .keys
235+ if k not in ["latitude" , "longitude" , "elevation" ]
225236 },
226- "properties" : {k : record .get (k ) for k in record .keys if k not in ["latitude" , "longitude" , "elevation" ]},
227237 }
228238 for record in records
229239 ]
230240 feature_collection ["features" ].extend (features )
231241
232-
233242 with open (path , "w" ) as f :
234243 json .dump (feature_collection , f , indent = 4 )
235244
236-
237245 def _get_gdal_type (self , dtype ):
238246 """
239247 Map pandas dtypes to GDAL-compatible types for the schema.
@@ -249,6 +257,7 @@ def _get_gdal_type(self, dtype):
249257 else :
250258 return "str" # Default to string for unsupported types
251259
260+
252261# class ST2Persister(BasePersister):
253262# extension = "st2"
254263#
0 commit comments