Created
May 13, 2023 08:32
-
-
Save simbamangu/3d768ff6eb3adfbc319b7e73ea096bd2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import geopandas as gpd | |
from shapely.geometry import Point | |
from datetime import date, time, datetime, timedelta | |
# Load laser file | |
data = pd.read_csv('Laser.txt', header=None) | |
# Remove ' ft' and ' mph' from the height and speed columns and convert them to integers | |
data[1] = data[1].str.replace(' ft', '').astype(int) | |
data[2] = data[2].str.replace(' mph', '').astype(int) | |
# Create a new column for the 'geometry' using the longitude and latitude | |
data['geometry'] = data.apply(lambda row: Point(row[3], row[4]), axis=1) | |
# Rename the columns | |
data = data.rename(columns={ | |
0: 'time_of_day', | |
1: 'agl', | |
2: 'gs_mph', | |
3: 'lon', | |
4: 'lat', | |
'geometry': 'geometry' | |
}) | |
# Add date to create datetime | |
filedate = date(2023, 5, 28) | |
data['date'] = pd.to_datetime(filedate) | |
data['time'] = pd.to_timedelta(data['time_of_day']) | |
data['time'] = data['date'] + data['time'] | |
# Convert from UTC+2 to Zulu time (GPX requires this) | |
data['time'] = data['time'] - timedelta(hours = 2) | |
# Clean up | |
data = data.drop(columns = ['time_of_day', 'date', 'lat', 'lon']) | |
# Convert the DataFrame to a GeoDataFrame | |
geo_data = gpd.GeoDataFrame(data, geometry='geometry') | |
# Save as GeoPackage | |
geo_data.to_file("output.gpkg", driver='GPKG') | |
# Save as a GPX | |
geo_data['track_fid'] = 0 | |
geo_data['track_seg_id'] = 0 | |
geo_data.to_file(filename="Laser.gpx", | |
layer = "track_points", | |
driver = 'GPX', | |
GPX_USE_EXTENSIONS=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment