Created
October 20, 2021 13:44
-
-
Save aliaksei135/01215baa31ec35804c6a22e69ab1e613 to your computer and use it in GitHub Desktop.
A simple script to reverse LineStrings from GeoJSON and export as GPX files
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 sys | |
import geopandas as gpd | |
import shapely.geometry as sg | |
import glob | |
if __name__ == '__main__': | |
path = sys.argv[1] | |
files = glob.glob(path + '**/*.geojson', recursive=True) | |
for file in files: | |
gs = gpd.GeoSeries() | |
gs = gs.from_file(file) | |
coords = gs[0].coords | |
rls = sg.LineString(coords[::1]) | |
rgs = gpd.GeoSeries(rls) | |
fn = file.split('.')[0] | |
rgs.to_file(fn + '.rev.gpx', driver='GPX') | |
rgs.to_file(fn + '.rev.geojson', driver='GeoJSON') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment