Skip to content

Instantly share code, notes, and snippets.

@Tristramg
Tristramg / build_swiss.ipynb
Last active October 2, 2024 08:08
Build an LRS based on swiss opendata
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Tristramg
Tristramg / liblrs.ipynb
Created October 1, 2024 08:23
liblrs python notebook
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Tristramg
Tristramg / locinfra.py
Last active February 13, 2024 14:11
locinfra: extraction rk
import csv
import os
class Row:
def __init__(self, row):
self.srv = f"{row['LIGNE']}-{row['TRONCON']}-{row['VOIE']}"
self.longitude = float(row['LONGITUDE'])
self.latitude = float(row['LATITUDE'])
self.pk = float(row['PK'])
pub struct Id<T> {
id: String,
_phantom: std::marker::PhantomData<T>,
}
use std::collections::HashMap;
pub struct Topology {
pub metadata: Metadata,
pub networks: Vec<Network>,
import tsplib95
import geojson
import pyproj
problem = tsplib95.load('communes.tsp')
f = open("out_linkern","r")
lines = f.readlines()[1:]
transformer = pyproj.Transformer.from_crs(2154, 4326, always_xy=True)
coordinates = []
@Tristramg
Tristramg / script.sh
Created April 12, 2023 14:31
Calcul du niveau d’enclave des communes en France
# On importe le tracé des communes dans la base postgres
# Source des données https://geoservices.ign.fr/adminexpress
# -I pour créer un indexe (ça premet de gagner un peu de temps au moment de croiser les données)
# -D pour le format dump, pour que ça aille plus vite
# -s 2154 pour préciser que les données sont projetée en Lambert 93 (même si par la suite ça n’a pas servi comme précision)
shp2pgsql -s 2154 -I -D ADMIN-EXPRESS_3-1__SHP_LAMB93_FXX_2023-03-20/ADMIN-EXPRESS/1_DONNEES_LIVRAISON_2023-03-20/ADE_3-1_SHP_LAMB93_FXX/COMMUNE.shp communes | psql
# Idem pour les côtes
shp2pgsql -I -D -s 2154 Limite_terre_mer_France_metropolitaine/SHAPE/Limite_terre-mer_France_metropolitaine_fermeturesLIMAR.shp cotes | psql
ALTER TABLE ways RENAME COLUMN gid TO id,
ALTER TABLE ways ADD COLUMN country text;
ALTER TABLE ways RENAME COLUMN maxspeed_forward TO maxspeed;
ALTER TABLE ways DROP COLUMN maxspeed_backward;
ALTER TABLE ways DROP COLUMN cost_s;
ALTER TABLE ways DROP COLUMN reverse_cost_s;
ALTER TABLE ways DROP COLUMN one_way;
ALTER TABLE ways DROP COLUMN oneway;
ALTER TABLE ways DROP COLUMN priority;
ALTER TABLE ways DROP COLUMN tag_id;
"""
This tool is meant to process GTFS files from transport.data.gouv.fr,
convert them to the NeTEx format,
and upload them as community resources to transport.data.gouv.fr
"""
import logging
import subprocess
import tempfile
import urllib.request
"""
This tool is meant to process GTFS files from transport.data.gouv.fr,
convert them to the NeTEx format,
and upload them as community resources to transport.data.gouv.fr
"""
import urllib.request
import tempfile
import subprocess
import requests
import csv
import json
import os
import shutil
import subprocess
import time
import urllib.request
tartare = "../tartare-tools/target/release/gtfs2netexfr"
url = "https://transport.data.gouv.fr/api/datasets"