Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
linogaliana committed Dec 26, 2023
1 parent 8f44df2 commit bb7d6d7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
41 changes: 22 additions & 19 deletions cartiflette/mapshaper/mapshaper_split.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import subprocess



DICT_CORRESP_IGN = {"REGION": "INSEE_REG", "DEPARTEMENT": "INSEE_DEP"}


Expand Down Expand Up @@ -101,7 +99,6 @@ def mapshaperize_split(
return output_path



def mapshaperize_split_merge(
local_dir="temp",
extension_initial="shp",
Expand Down Expand Up @@ -131,36 +128,42 @@ def mapshaperize_split_merge(
# PREPROCESS CITIES
subprocess.run(
(
f"mapshaper {local_dir}/COMMUNE.{extension_initial} name='COMMUNE' "
f"-proj EPSG:{crs} "
f"-filter '\"69123,13055,75056\".indexOf(INSEE_COM) > -1' invert "
f"-each \"INSEE_COG=INSEE_COM\" "
f"-o {output_path}/communes_simples.{format_intermediate} format={format_intermediate} extension=\".{format_intermediate}\" singles"
f"mapshaper {local_dir}/COMMUNE.{extension_initial} name='COMMUNE' "
f"-proj EPSG:{crs} "
f"-filter '\"69123,13055,75056\".indexOf(INSEE_COM) > -1' invert "
f"-each \"INSEE_COG=INSEE_COM\" "
f"-o {output_path}/communes_simples.{format_intermediate} "
f"format={format_intermediate} extension=\".{format_intermediate}\" singles"
),
shell=True
)

# PREPROCESS ARRONDISSEMENT
subprocess.run(
(
f"mapshaper {local_dir}/ARRONDISSEMENT_MUNICIPAL.{extension_initial} name='ARRONDISSEMENT_MUNICIPAL' "
f"-proj EPSG:{crs} "
f"-rename-fields INSEE_COG=INSEE_ARM "
f"-each 'STATUT=\"Arrondissement municipal\" ' "
f"-o {output_path}/arrondissements.{format_intermediate} format={format_intermediate} extension=\".{format_intermediate}\""
f"mapshaper {local_dir}/ARRONDISSEMENT_MUNICIPAL.{extension_initial} "
f"name='ARRONDISSEMENT_MUNICIPAL' "
f"-proj EPSG:{crs} "
f"-rename-fields INSEE_COG=INSEE_ARM "
f"-each 'STATUT=\"Arrondissement municipal\" ' "
f"-o {output_path}/arrondissements.{format_intermediate} "
f"format={format_intermediate} extension=\".{format_intermediate}\""
),
shell=True
)

# MERGE CITIES AND ARRONDISSEMENT
subprocess.run(
(
f"mapshaper {output_path}/communes_simples.{format_intermediate} {output_path}/arrondissements.{format_intermediate} snap combine-files "
f"-proj EPSG:{crs} "
f"-rename-layers COMMUNE,ARRONDISSEMENT_MUNICIPAL "
f"-merge-layers target=COMMUNE,ARRONDISSEMENT_MUNICIPAL force "
f"-rename-layers COMMUNE_ARRONDISSEMENT "
f"-o {output_path}/raw.{format_intermediate} format={format_intermediate} extension=\".{format_intermediate}\""
f"mapshaper "
f"{output_path}/communes_simples.{format_intermediate} "
f"{output_path}/arrondissements.{format_intermediate} snap combine-files "
f"-proj EPSG:{crs} "
f"-rename-layers COMMUNE,ARRONDISSEMENT_MUNICIPAL "
f"-merge-layers target=COMMUNE,ARRONDISSEMENT_MUNICIPAL force "
f"-rename-layers COMMUNE_ARRONDISSEMENT "
f"-o {output_path}/raw.{format_intermediate} "
f"format={format_intermediate} extension=\".{format_intermediate}\""
),
shell=True
)
Expand Down
11 changes: 4 additions & 7 deletions cartiflette/pipeline/mapshaper_split_from_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from cartiflette.mapshaper import mapshaperize_split, mapshaperize_split_merge
from .prepare_mapshaper import prepare_local_directory_mapshaper


def mapshaperize_split_from_s3(
path_bucket,
config,
Expand All @@ -29,7 +30,7 @@ def mapshaperize_split_from_s3(
path_within_bucket = config.get("path_within_bucket", PATH_WITHIN_BUCKET)
local_dir = config.get("local_dir", "temp")

local_directories = prepare_local_directory_mapshaper(
prepare_local_directory_mapshaper(
path_bucket,
borders=borders,
niveau_agreg=filter_by,
Expand Down Expand Up @@ -73,7 +74,6 @@ def mapshaperize_split_from_s3(
})
fs.put(f"{output_path}/{values}", path_s3)


return output_path


Expand All @@ -85,7 +85,7 @@ def mapshaperize_merge_split_from_s3(

format_output = config.get("format_output", "topojson")
filter_by = config.get("filter_by", "DEPARTEMENT")
borders = config.get("borders", "COMMUNE")
# borders = config.get("borders", "COMMUNE")
territory = config.get("territory", "metropole")

provider = config.get("provider", "IGN")
Expand All @@ -100,7 +100,7 @@ def mapshaperize_merge_split_from_s3(
path_within_bucket = config.get("path_within_bucket", PATH_WITHIN_BUCKET)
local_dir = config.get("local_dir", "temp")

local_directory = prepare_local_directory_mapshaper(
prepare_local_directory_mapshaper(
path_bucket,
borders="COMMUNE",
niveau_agreg=filter_by,
Expand All @@ -120,7 +120,6 @@ def mapshaperize_merge_split_from_s3(
fs=fs
)


output_path = mapshaperize_split_merge(
local_dir=local_dir,
extension_initial="shp",
Expand Down Expand Up @@ -154,6 +153,4 @@ def mapshaperize_merge_split_from_s3(
})
fs.put(f"{output_path}/{values}", path_s3)


return output_path

1 change: 0 additions & 1 deletion cartiflette/pipeline/prepare_cog_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from cartiflette.s3 import upload_s3_raw



def prepare_cog_metadata(
path_within_bucket: str,
local_dir: str = "temp",
Expand Down

0 comments on commit bb7d6d7

Please sign in to comment.