Skip to content

Commit

Permalink
update pgsql2shp subprocess command
Browse files Browse the repository at this point in the history
should fix errors due to accents
  • Loading branch information
leavauchier committed Apr 9, 2024
1 parent 4ab546a commit a0a0c21
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions lidar_prod/tasks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,28 +254,24 @@ def request_bd_uni_for_building_shapefile(
WHERE (reservoir.gcms_territoire = territoire.code) \
AND reservoir.geometrie \
&& ST_MakeEnvelope({bbox["x_min"]}, {bbox["y_min"]}, {bbox["x_max"]}, {bbox["y_max"]}, 0) \
AND (reservoir.nature = 'Château d''eau' OR reservoir.nature = 'Réservoir industriel') \
AND (unaccent(reservoir.nature) = 'Reservoir industriel' OR unaccent(reservoir.nature) = 'Chateau d''eau') \
AND NOT gcms_detruit"""

sql_select_list = [sql_batiment, sql_reservoir]
sql_request = sql_territoire + " UNION ".join(sql_select_list)

cmd = [
"pgsql2shp",
"-f",
shapefile_path,
"-h",
bd_params.host,
"-u",
bd_params.user,
"-P",
bd_params.pwd,
bd_params.bd_name,
sql_request,
]
cmd = f"""pgsql2shp -f {shapefile_path} \
-h {bd_params.host} \
-u {bd_params.user} \
-P {bd_params.pwd} \
{bd_params.bd_name} \
\"{sql_request}\""""

# This call may yield
try:
subprocess.check_output(cmd, stderr=subprocess.STDOUT, timeout=120)
subprocess.check_output(
cmd, shell=True, stderr=subprocess.STDOUT, timeout=120, encoding="utf-8"
)
except subprocess.CalledProcessError as e:
# In empty zones, pgsql2shp does not create a shapefile
if (
Expand Down

0 comments on commit a0a0c21

Please sign in to comment.