Using GPSLogger for Android (available on F-Droid) to collect CSV files with geo-locations. Create daily zip files, which are uploaded into the /gps folder. (The /locations folder contains data from the now mostly defunct Google Location History.)
The scripts form a kind of pipeline, each creating files required for the next script.
There is a script called run_all_scripts.py which runs all the other scripts. Ideally, this just works.
run_all_scripts.py uses a centralized configuration dictionary that controls which scripts to run and their parameters. Each script has its own section in the config dictionary with options like:
config = {
'script_name': {
'run': True, # Whether to run this script
'overwrite': False # Whether to overwrite existing files
# Other script-specific parameters
},
# Other scripts...
}You can modify these settings in run_all_scripts.py to control the behavior of each script. The run parameter determines whether a script is executed, and overwrite (when supported) controls whether files are recreated or if only files are created that do not yet exist.
Scripts are executed in two different ways in run_all_scripts.py:
- As Python modules:
extract_csv_files.py,split_csv_by_day.py,add_ice_export_to_csv.py, andcleanup_for_speed.pyare imported and run as modules - As subprocesses: All other scripts are executed as separate Python processes
Not sure all scripts create the folders they need... hopefully. Anyway, the structure looks like this:
├── all
├── basisdaten
├── csv
├── cumulative
├── cumulative_visualizations
├── fast
├── gps
├── locations
├── output
├── points
├── points_yearly
├── shapefile_cumulative
├── shapefile_yearly
├── slow
├── static
├── droid
├── fantasque
├── jetbrains
├── mono
├── trips
├── venv
├── visualizations
├── visualizations_geopandas
├── visualizations_square
├── visualizations_square_with_dates
├── visualizations_vertical
├── visualizations_vertical_with_dates
├── visualizations_with_dates
├── visualizations_with_years
├── visualizations_yearly_geopandas
All the Python files are in the root.
To start the process there needs to be CSV Files, with the location track for a day, in the /csv Folder, with a naming pattern like yyyymmdd.csv. These scripts might help you create them.
extract_csv_files.pyextracts the data from/gpsand/locationsinto CSV files, creating one CSV file with geo-locations per day. Preferably, it uses a copy from the CSV in a zip file in/gps. Only if this does not exist does it go to other sources. At the end, there should be a CSV file with a bunch of geo-locations for each day, using ayyyymmdd.csvnaming scheme like this:- Note: This script is now imported and run as a module in
run_all_scripts.py - Config options:
run(whether to run this script),overwrite(ifTruealready created files are overwritten, otherwise not)
- Note: This script is now imported and run as a module in
time,lat,lon,elevation,accuracy,bearing,speed,satellites,provider,hdop,vdop,pdop,geoidheight,ageofdgpsdata,dgpsid,activity,battery,annotation,timestamp_ms,time_offset,distance,starttimestamp_ms,profile_name,battery_charging
2024-03-19T23:12:40.600Z,48.1861084,11.5593367,561.6000366210938,,,,,network,,,,,,,,,,,,,,,
-
split_csv_by_day.pyis an alternative to the script above. It takes CSV files in the format described above from the folder/csv_rawand splits same into one file per day into/csv. This might be helpful if your CSV data is organized monthly.- Note: This script is now imported and run as a module in
run_all_scripts.py - Config options:
run(whether to run this script)
- Note: This script is now imported and run as a module in
-
add_ice_export_to_csv.pyintegrates ICE train location data into the CSV files. The/tripsfolder can contain JSON files downloaded from the WifiOnICE portal when traveling on ICE trains. If provided, this more precise train location data is used instead of GPS data during train rides.- Note: This script is imported and run as a module in
run_all_scripts.py - Config options:
run(whether to run this script)
- Note: This script is imported and run as a module in
-
cleanup_for_speed.pycleans up CSV data in preparation for speed calculation.- Note: This script is imported and run as a module in
run_all_scripts.py - Config options:
run(whether to run this script)
- Note: This script is imported and run as a module in
-
calculate_speed_and_filter.pytakes the created CSV files and calculates the speed between two points. It then creates four GeoJSON files: one is a line between all the points of a day in the folder/all, one only contains lines if the speed between those points is above 10 km/h (/fast), the next one only contains lines between points below 10 km/h (/slow), and last but not least,/pointscontains points every 500 meters along the lines with a speed below 10 km/h.- Config options:
run(whether to run this script),overwrite(ifTruealready created files are overwritten, otherwise not)
- Config options:
-
cumulative_points.pytakes the points from/pointsand creates a cumulative points file in/cumulativewith a naming scheme like this:20200319_points.geojson. These include all points up to that date. Even if no location file exists for a day, a cumulative one is still present. From now on, every date from the start date is covered. You need to set the start date in the header of this file!- Variables:
start_datesets the Date from which calculation is done. Must be set likedatetime(2020, 1, 1) - Variables:
overwriteif Set toTruealready created files are overwritten, otherwise not.
- Variables:
-
combine_points_yearly.pytakes the points from/points(which only include points for distances traveled at less than 10 km/h) and creates a file for each year.- Variables:
overwriteif Set toTruealready created files are overwritten, otherwise not.
- Variables:
-
visualize_points_with_counts.pycreates shapefiles for the yearly points created withcombine_points_yearly.py.- Variables:
onlygermanyif Set toTrueonly german "Gemeinden" are used, otherwise a european Local Area Units NUTS file is used from http://ec.europa.eu/eurostat/web/gisco/geodata/statistical-units/local-administrative-units - Variables:
overwriteif Set toTruealready created files are overwritten, otherwise not.
- Variables:
-
visualize_cumulative_points_with_counts.pytakes the files created incumulative_points.pyand creates a shapefile with the counts of the points in each polygon. It creates one shapefile for each day.- Variables:
onlygermanyif Set toTrueonly german "Gemeinden" are used, otherwise a european Local Area Units NUTS file is used from http://ec.europa.eu/eurostat/web/gisco/geodata/statistical-units/local-administrative-units - Variables:
overwriteif Set toTruealready created files are overwritten, otherwise not.
- Variables:
-
visualize_points_geopandas.pytakes the shapefiles created invisualize_cumulative_points_with_counts.pyand creates a.pngimage using background data from the/basisdatenfolder for each day. You need to set the start date in the header of this file!- Variables:
start_datesets the Date from which calculation is done. Set as StringYYYY-MM-DD. - Variables:
overwriteif Set toTruealready created files are overwritten, otherwise not.
- Variables:
-
visualize_points_geopandas_yearly_new.pycreates a yearly visualization and an additional file that writes the name on it.- Variables:
overwriteif Set toTruealready created files are overwritten, otherwise not.
- Variables:
-
create_cropped_images.pycreates cropped images (square and vertical) of the images created byvisualize_points_geopandas.py. -
create_video_from_images.pycreates a copy of each of the.pngfiles created byvisualize_points_geopandas.pyand adds the date to the lower right corner (/visualizations_with_dates). It then also crops these into square and vertical images and adds the date to those as well. All these images are then combined into three.mp4files (16:9 4K, vertical, and square video).- Variables:
recreate_imagesif Set toTruealready created image-files are overwritten, otherwise not. - Variables:
overwriteif Set toTruealready created video-files are overwritten, otherwise not.
- Variables:
Example: https://www.youtube.com/watch?v=zHYTjOnBznY
- "basisdaten/LAU_RG_01M_2023_3035.shp" from https://ec.europa.eu/eurostat/web/gisco/geodata/statistical-units/local-administrative-units the data may not be used for commercial puposes. https://ec.europa.eu/eurostat/web/gisco/geodata/statistical-units DE: © EuroGeographics bezüglich der Verwaltungsgrenzen
This code was created using, among other tools, LLM tools like ChatGPT.
