Last active
October 17, 2023 10:19
-
-
Save dhardy92/a14cede46898031fa52ef05c8f9b0f34 to your computer and use it in GitHub Desktop.
Est ce que je suis passé par des cols
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
<!-- usage : | |
xsltproc --param dep 01 colXml2CSV.xsl 01.xml | |
use a loop on files an write in a single csv: | |
for i in {01..95} ; do xsltproc --param dep "$i" colXml2CSV.xsl $i.xml >> cols_fr.csv ; done | |
--> | |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
<xsl:output method="text" encoding="utf-8" /> | |
<xsl:param name="dep" /> | |
<xsl:template match="/"> | |
<xsl:apply-templates select="markers/marker" /> | |
</xsl:template> | |
<xsl:template match="marker"> | |
<xsl:value-of select="concat($dep, ';')" /> | |
<xsl:value-of select="concat(@nom, ';')" /> | |
<xsl:value-of select="concat(@altitude, ';')" /> | |
<xsl:value-of select="concat(@lat, ';')" /> | |
<xsl:value-of select="concat(@lng, '
')" /> | |
</xsl:template> | |
</xsl:stylesheet> |
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
for i in {01..95}; | |
do # ecris 1 fichier XML par deparetement français dans un repertoire "cols" | |
curl https://www.carte-cols-france.com/infos.php?departement=$i \ | |
-H "User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/118.0" \ | |
-H "Referer: https://www.carte-cols-france.com/cols-departement-aude-d$i.html" > cols/$i.xml; | |
done |
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 gpxpy.geo | |
import gpxpy.gpx | |
import math | |
import sys | |
import argparse | |
import csv | |
import os | |
def dofile(file): | |
gpx_file = open(file, 'r') | |
gpx = gpxpy.parse(gpx_file) | |
global cols | |
i=0 | |
for col in cols: | |
nl = gpx.get_nearest_location(col[2]) | |
nl_dist = nl.location.distance_2d(col[2]) | |
if len(cols[i]) <=3: | |
cols[i].append(nl_dist) | |
cols[i].append(nl.location) | |
cols[i].append(file) | |
elif cols[i][3] > nl_dist : | |
cols[i][3] = nl_dist; | |
cols[i][4] = nl.location | |
cols[i][5] = file | |
i=i+1 | |
#main | |
parser = argparse.ArgumentParser() | |
parser.add_argument("-f", "--file", help="GPX input file or directory containing GPX files") | |
parser.add_argument("-c", "--csv", help="CSV files of PoI (cols) for search in GPX") | |
args = parser.parse_args() | |
global cols | |
cols = [] | |
with open(args.csv, newline='') as csvfile: | |
reader = csv.reader(csvfile,delimiter=';') | |
for l in reader: | |
loc = gpxpy.geo.Location(latitude=float(l[3]), longitude=float(l[4]),elevation=int(l[2])) | |
cols.append([l[0],l[1],loc]) | |
if os.path.isdir(args.file): | |
for file in os.scandir(args.file): | |
if file.path.endswith('gpx'): | |
dofile(file) | |
else: | |
dofile(args.file) | |
print(cols) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment