Skip to content

Instantly share code, notes, and snippets.

View ThomasG77's full-sized avatar

Thomas Gratier ThomasG77

View GitHub Profile
@ThomasG77
ThomasG77 / index.html
Last active January 4, 2023 13:42
Leaflet WFS
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.3/dist/leaflet.css" integrity="sha256-kLaT2GOSpHechhsozzB+flnD+zUyjE2LlfWPgU04xyI=" crossorigin="" />
<!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.2.0/leaflet.css" /> -->
<title></title>
<style>
html,
GNM: GNMRegisterAllInternal
GNM: RegisterGNMFile
GNM: RegisterGNMdatabase
WFS: https://www.wfs.nrw.de/geobasis/wfs_nw_inspire-flurstuecke_alkis?SERVICE=WFS&REQUEST=GetCapabilities
HTTP: Fetch(https://www.wfs.nrw.de/geobasis/wfs_nw_inspire-flurstuecke_alkis?SERVICE=WFS&REQUEST=GetCapabilities)
WFS: No paging support
WFS: No ImplementsStandardJoins support
WFS: No transaction support
GDAL: GDALOpen(WFS:https://www.wfs.nrw.de/geobasis/wfs_nw_inspire-flurstuecke_alkis, this=0x19342f0) succeeds as WFS.
GDAL: QuietDelete(cadastral_parcel_filtered.gpkg) invoking Delete()
@ThomasG77
ThomasG77 / ressources_demo_data_gouv_fr.sh
Created November 28, 2022 15:33
Get datasets/ressources from demo.data.gouv.fr
counter=0
while : ; do
counter=$((counter+1))
curl -s -X GET "https://demo.data.gouv.fr/api/1/datasets/?page=${counter}&page_size=500" >| "page_${counter}.json"
if [[ $( cat "page_${counter}.json" \
| jq '.next_page') == 'null' ]] ; then
break #Exit the loop
fi
done
@ThomasG77
ThomasG77 / debug_wms_capabilities_xml.py
Created November 24, 2022 18:36
Identify if issue with same name in XML WMS capabilities
import argparse
from collections import Counter
import urllib.request
try:
from lxml import etree
except ImportError:
try:
print("Failed to import etree from lxml. Fall to default Python lib")
from xml.etree import ElementTree as etree
@ThomasG77
ThomasG77 / README.md
Last active November 23, 2022 18:16
Permalinks entre les applis carto métier

"Permalinks all the things"

Pour basculer d'une appli à l'autre (carto généraliste) https://tankaru.github.io/OpenSwitchMapsWeb/index.html + extensions Firefox et Chrome https://github.com/tankaru/OpenSwitchMaps

La logique serait intéressante à appliquer à des applications existantes côté public. Le but: rajouter de la transversalité entre des domaines métier différents. Cela permettrait ensuite soit de faire comme les exemples généralistes (basculer d'une page à l'autre), soit de permettre à des applis de faire les "bonnes redirections" vers celle d'autres domaines métiers associés.

Exemples inventoriés

@ThomasG77
ThomasG77 / base-pop-historiques-1876-2019.csv
Last active November 22, 2022 19:32
Base historique population INSEE rapportée aux géographies 2022
We can't make this file beautiful and searchable because it's too large.
CODE_2022,PMUN19,PMUN18,PMUN17,PMUN16,PMUN15,PMUN14,PMUN13,PMUN12,PMUN11,PMUN10,PMUN09,PMUN08,PMUN07,PMUN06,PSDC99,PSDC90,PSDC82,PSDC75,PSDC68,PSDC62,PTOT54,PTOT36,PTOT1931,PTOT1926,PTOT1921,PTOT1911,PTOT1906,PTOT1901,PTOT1896,PTOT1891,PTOT1886,PTOT1881,PTOT1876
01001,779,771,776,767,767,767,767,777,780,784,787,791,804,811,728,579,477,368,347,407,424,506,540,543,566,560,629,637,572,594,622,605,604
01002,256,253,248,243,241,239,236,235,234,221,207,194,195,198,168,159,136,106,88,103,157,203,219,253,256,291,323,357,391,421,486,490,484
01004,14134,14204,14035,14081,14127,14022,14359,14233,13839,13835,13350,12792,12696,12709,11436,10455,9737,9550,8949,7748,7159,6846,6794,5705,4796,4334,4100,4023,3548,3635,3618,3396,3427
01005,1751,1720,1689,1671,1619,1627,1635,1642,1600,1616,1592,1567,1544,1436,1408,1156,848,756,627,588,570,593,618,690,698,805,805,835,852,862,882,879,848
01006,112,112,111,110,109,109,108,110,112,116,120,123,125,120,86,76,65,82,108,107,111,141,135,161,150,159,193,200,206,200,200,213,191
01007,2800,

5 minutes pour passer du JSON vers du GeoJSON avec jq

Récupérez les données (URL fixe prise sur https://www.data.gouv.fr/fr/datasets/lieux-de-mediation-numerique-organisation-cartographie-nationale-des-lieux-de-mediation-numerique-2/)

curl -s https://static.data.gouv.fr/resources/lieux-de-mediation-numerique-organisation-cartographie-nationale-des-lieux-de-mediation-numerique-2/20221110-164433/20221110-hinaura-lieux-de-mediation-numeriques-auvergne-rhone-alpes.json

Prenez le JSON qui dispose déjà de coordonnées longitude, latitude et vous avez votre GeoJSON

Extraction des Services des impots des Entreprises (SIE)

Visible sur https://lannuaire.service-public.fr/navigation/sie

Il s'agit d'un cas particulier mais si vous avez besoin d'une liste d'organismes sur https://lannuaire.service-public.fr, vous serez capable de récupérer les données en adaptant la solution ci-dessous à votre cas. Il est possible de passer par 2 autres alternatives: une API à déployer chez vous et un jeu de données généré presque prêt pour un usage cartographique. Voir la section Alternatives

On utilise jq, pup, wget, curl et on travaille sous Linux

mkdir temporary
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://unpkg.com/leaflet@1.9.2/dist/leaflet.js"></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.2/dist/leaflet.css" />
<style>
html,
@ThomasG77
ThomasG77 / migrate-qgz-ign-urls.py
Last active October 11, 2022 12:55
POC pour rechercher remplacer des URLS dans un projet QGIS
import os
import tempfile
import shutil
import argparse
from pathlib import Path
parser = argparse.ArgumentParser()
parser.add_argument("path", type=str,
help="Provide path to a qgs or qgz file")
args = parser.parse_args()