37 lines
954 B
Python
37 lines
954 B
Python
|
#!/bin/python3
|
||
|
|
||
|
import argparse
|
||
|
import gpxpy
|
||
|
import gpxpy.gpx
|
||
|
import shapely
|
||
|
import pickle
|
||
|
|
||
|
|
||
|
def main(args):
|
||
|
with open(args.polygon_file, 'rb') as f:
|
||
|
area = pickle.load(f)
|
||
|
|
||
|
with open(args.input_file, 'rb') as f:
|
||
|
gpx = gpxpy.parse(f)
|
||
|
|
||
|
gpx.waypoints = list(filter(lambda wp: area.contains(
|
||
|
shapely.Point(wp.latitude, wp.longitude)), gpx.waypoints))
|
||
|
|
||
|
with open(args.output_file, 'w') as f:
|
||
|
f.write(gpx.to_xml())
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
parser = argparse.ArgumentParser(description="""
|
||
|
Takes an input GPX file containing
|
||
|
geocaches and filters out any waypoints outside a given area.
|
||
|
""")
|
||
|
parser.add_argument("input-file", help="Input GPX file")
|
||
|
parser.add_argument("output-file", help="Output GPX file")
|
||
|
parser.add_argument(
|
||
|
"-p", "--polygon-file", help="File containing area's polygon",
|
||
|
default="polygon.pickle")
|
||
|
args = parser.parse_args()
|
||
|
|
||
|
main(args)
|