def process_file(file_path): df = pd.read_csv(file_path, index_col='TRIP_ID') unique_id = uuid.uuid4().hex _out_path = os.path.join(gpx_folder, unique_id) if not os.path.isdir(_out_path): os.mkdir(_out_path) count = 1 with tqdm(total=len(df)) as pbar: for trip_id, row in df.iterrows(): polyline = ast.literal_eval(row['POLYLINE']) lon, lat = [i for i, j in polyline], [j for i, j in polyline] _df = pd.DataFrame({'x': lon, 'y': lat}) out_path = os.path.join(_out_path, trip_id) out_path = f'{out_path}.gpx' if os.path.exists(out_path): print(f'Duplicate trip ID found {trip_id}') Converter.dataframe_to_gpx(_df, lats_colname='y', longs_colname='x', output_file=out_path) count += 1 if not count % 500: pbar.update(500) pbar.update(500) print(f'Finished processing file {file_path}')
def convert(self): """ Extract GPS points from a route map picture with python/OpenCV and save it in a gpx file """ trace_mask = self.compute_trace_mask() pixel_points = self.compute_trace_points(trace_mask) if DEBUG: cv2.imshow("trace_mask", trace_mask) cv2.imshow("Points", self.img) gps_coords = self.pixels_to_gps_coord(pixel_points) np.savetxt("foo.csv", np.asarray(gps_coords), delimiter=",", header="latitude,longitude", comments='') Converter(input_file='foo.csv').csv_to_gpx(lats_colname='latitude', longs_colname='longitude', output_file='foo.gpx') if DEBUG: cv2.waitKey(0)
def converter(): return Converter(input_file='examples/test_data/test1.gpx')
from gpx_converter import Converter # convert multiple csv files to gpx ( notice to use it as a static method ) Converter.convert_multi_csv_to_gpx(dirpath='test_data/')
from gpx_converter import Converter # convert gpx to a pandas dataframe res = Converter(input_file='test_data/test1.gpx').gpx_to_dataframe()
def gpx_read(file_path): rundf = Converter(input_file=file_path).gpx_to_dataframe() return rundf
from gpx_converter import Converter # convert csv to gpx Converter(input_file='test_data/test1.csv').csv_to_gpx(lats_colname='latitudes', longs_colname='longitudes', output_file='test_data/converted.gpx')
from gpx_converter import Converter # convert gpx to a csv file Converter(input_file='test_data/test1.gpx').gpx_to_csv(output_file='test_data/converted_to_csv.csv')
def test_gpx_to_dataframe(): result = Converter( input_file='examples/test_data/test1.gpx').gpx_to_pandas_dataframe() assert result is not None
from gpx_converter import Converter # convert gpx to a csv file # Converter(input_file='test_data/test1.gpx').gpx_to_csv(output_file='test_data/converted_to_csv.csv') # convert gpx to a pandas dataframe res = Converter(input_file='test_data/test1.gpx').gpx_to_pandas_dataframe() # convert csv to gpx Converter(input_file='test_data/test1.csv').csv_to_gpx( lats_colname='latitudes', longs_colname='longitudes', output_file='test_data/converted.gpx') # convert multiple csv files to gpx ( notice to use it as a static method ) Converter.convert_multi_csv_to_gpx(dirpath='test_data/')
from gpx_converter import Converter # convert gpx to a pandas dataframe res = Converter('test_data/test1.gpx').gpx_to_dictionary( latitude_key='latitude', longitude_key='longitude') print(res)
from gpx_converter import Converter # convert gpx to a csv file Converter(input_file='test_data/test_file.gpx').gpx_to_csv( output_file='test_data/test_file.csv')