Skip to content

Instantly share code, notes, and snippets.

View ThomasG77's full-sized avatar

Thomas Gratier ThomasG77

View GitHub Profile

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/[email protected]/dist/leaflet.js"></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/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()
@ThomasG77
ThomasG77 / README.md
Created September 24, 2022 00:19
Miniconda with gdal install
@ThomasG77
ThomasG77 / README.md
Last active September 23, 2022 11:20
Issue for path cli resolving when migrating CommonJS to ES6

Path issue when migrating CommonJS to ES6

Context: migrating to ES6 syntax because some upcoming deps ES6 based (want to avoid transpiling)

Command used to fail

Root of the repo myrepo then running

In CommonJS cli

@ThomasG77
ThomasG77 / index.js
Created September 12, 2022 22:03
mapshaper-info-recreated-via-gdal
import fs from 'fs'
import got from 'got'
import gdal from 'gdal-async'
import { pipeline } from 'stream/promises'
const url = 'https://github.com/deldersveld/topojson/raw/master/countries/germany/germany-regions.json'
const fileName = url.substring(url.lastIndexOf('/') + 1)
const downloadStream = got.stream(url)
const fileWriterStream = fs.createWriteStream(fileName)
{
"name": "order-service",
"version": "0.0.2",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "order-service",
"version": "0.0.2",
"license": "ISC",
@ThomasG77
ThomasG77 / processing-townhalls-ign.sh
Created July 21, 2022 12:59
Generation GeoJSON des mairies avec code INSEE
wget -N -P data/ http://files.opendatarchives.fr/professionnels.ign.fr/adminexpress/ADMIN-EXPRESS-COG_3-1__SHP__FRA_WM_2022-04-15.7z
cd data
7z e ADMIN-EXPRESS-COG_3-1__SHP__FRA_WM_2022-04-15.7z CHFLIEU_COMMUNE.* COMMUNE.* -r
ogr2ogr -overwrite \
-f GeoJSON \
-dialect SQLite \
-sql "SELECT \"INSEE_COM\", CASE WHEN chf.geometry IS NULL THEN 'c' ELSE 'm' END AS t, CASE WHEN chf.geometry IS NULL THEN PointOnSurface(\"COMMUNE\".geometry) ELSE chf.geometry END AS geometry FROM \"COMMUNE\" LEFT JOIN 'CHFLIEU_COMMUNE.shp'.\"CHFLIEU_COMMUNE\" chf ON chf.\"ID_COM\" = \"COMMUNE\".\"ID\"" \
chflieu_commune.geojson \
COMMUNE.shp \
-lco RFC7946=YES \
@ThomasG77
ThomasG77 / fix-validity-qpv.sh
Created July 6, 2022 17:58
Fix QPV validity
wget https://sig.ville.gouv.fr/Atlas/qp-politiquedelaville-shp.zip
unzip qp-politiquedelaville-shp.zip
ogrinfo QP_METROPOLEOUTREMER_WGS84_EPSG4326.shp -dialect SQLite -sql "SELECT count(*) FROM \"QP_METROPOLEOUTREMER_WGS84_EPSG4326\" WHERE NOT IsValid(geometry)"
ogr2ogr out.shp QP_METROPOLEOUTREMER_WGS84_EPSG4326.shp -dialect SQLite -sql "SELECT \"CODE_QP\", \"NOM_QP\", \"COMMUNE_QP\", CASE WHEN NOT IsValid(geometry) THEN ST_MakeValid(geometry) ELSE geometry END AS geometry FROM \"QP_METROPOLEOUTREMER_WGS84_EPSG4326\""
ogrinfo out.shp -dialect SQLite -sql "SELECT count(*) FROM out WHERE NOT IsValid(geometry)"
@ThomasG77
ThomasG77 / check_vat_vie.md
Last active June 18, 2022 02:15
SIREN et autres traitements autour dont la validation VIES (TVA intracommunautaire)

SIREN et autres traitements autour dont la validation VIES (TVA intracommunautaire)

Formule SIREN vers TVA intracommunautaire

Approche Python

COUNTRIES = {
    "AT": "Autriche",
    "BE": "Belgique",