-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4023fb
commit 943ca44
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
sudo apt-get update -y | ||
sudo apt install npm nodejs -y | ||
|
||
git clone https://github.com/mbloch/mapshaper.git | ||
cd mapshaper | ||
npm install # install dependencies | ||
npm run build # bundle source code files | ||
sudo npm link # (optional) add global symlinks so scripts are available systemwide |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import s3fs | ||
import cartiflette.s3 as s3 | ||
import os | ||
import subprocess | ||
|
||
fs = s3fs.S3FileSystem(client_kwargs={"endpoint_url": ENDPOINT_URL}) | ||
|
||
croisement_decoupage_level = { | ||
## structure -> niveau geo: [niveau decoupage macro], | ||
"REGION": ["FRANCE_ENTIERE"], | ||
"ARRONDISSEMENT_MUNICIPAL" : ['DEPARTEMENT'], | ||
"COMMUNE_ARRONDISSEMENT": ["DEPARTEMENT", "REGION", "FRANCE_ENTIERE"], | ||
"COMMUNE": ["DEPARTEMENT", "REGION", "FRANCE_ENTIERE"], | ||
"DEPARTEMENT": ["REGION", "FRANCE_ENTIERE"] | ||
} | ||
|
||
|
||
|
||
#formats = ["geoparquet", "shp", "gpkg", "geojson"] | ||
formats = ["topojson"] | ||
#formats = ["geojson"] | ||
|
||
#years = [y for y in range(2021, 2023)] | ||
years = [2022] | ||
|
||
#crs_list = [4326, 2154, "official"] | ||
crs_list = [4326] | ||
|
||
sources = ["EXPRESS-COG-CARTO-TERRITOIRE"] | ||
|
||
|
||
#tempdf = s3.crossproduct_parameters_production( | ||
# croisement_filter_by_borders=croisement_decoupage_level, | ||
# list_format=formats, | ||
# years=years, | ||
# crs_list=crs_list, | ||
# sources=sources, | ||
# ) | ||
|
||
dict_corresp = {"REGION": "INSEE_REG"} | ||
|
||
|
||
bucket = "projet-cartiflette" | ||
path_within_bucket = "diffusion/shapefiles-test2" | ||
year=2022 | ||
provider="IGN" | ||
source='EXPRESS-COG-TERRITOIRE' | ||
field="metropole" | ||
|
||
borders="COMMUNE" #tempdf['borders'].iloc[0] | ||
format_output="geojson" #tempdf['format'].iloc[0] | ||
niveau_agreg="REGION"#tempdf['filter_by'].iloc[0] | ||
|
||
|
||
path_bucket = f"{bucket}/{path_within_bucket}/{year=}/raw/{provider=}/{source=}/{field=}" | ||
|
||
list_raw_files = fs.ls(f"{path_bucket}") | ||
list_raw_files = [ | ||
chemin for chemin in list_raw_files if chemin.rsplit("/", maxsplit=1)[-1].startswith(f'{borders}.') | ||
] | ||
|
||
os.mkdir("temp") | ||
|
||
for files in list_raw_files: | ||
fs.download( | ||
files, | ||
"temp/" +\ | ||
files.rsplit("/", maxsplit=1)[-1] | ||
) | ||
|
||
|
||
os.mkdir(niveau_agreg) | ||
|
||
|
||
subprocess.run( | ||
f"mapshaper temp/{borders}.shp name='' -split {dict_corresp[niveau_agreg]} -o '{niveau_agreg}/' format={format_output}", | ||
shell=True | ||
) | ||
|
||
|
||
|
||
|
||
|