Go to most recent revision | Blame | Last modification | View Log | RSS feed
#!/bin/bash
# Utilisation : ./pbf2mysql-boundary
# Paramètres : .
# - 1 : nom du fichier .pbf dont on veut extraire les relations boundary (sans extenssion)
ageEnSeconde(){ expr `date +%s` - `stat -c %Y $1`; };
if [ -f pbf2mysql-boundary.cfg ] ; then
source pbf2mysql-boundary.cfg
echo $DATE;
else
echo "Veuillez paramétrer le script en renommant le fichier 'pbf2mysql-boundary.defaut.cfg' en 'pbf2mysql-boundary.cfg'."
exit;
fi
# Récupération du fichier OSM dont on veut extraire les relations de type boundary vers Mysql
FICHIER=$1
URL_DOWNLOAD=$2
echo "Export de l'emplacement du binaire Java dans la variable d'environnement JAVACMD";
export JAVACMD="$BIN_JAVA"
echo "Export de l'emplacement du dossier tmp pour Osmosis"
export JAVACMD_OPTIONS="-Djava.io.tmpdir=${OSMOSIS_DOSSIER_TMP} -Xmx${OSMOSIS_MAX_MEMORY} -server"
#if [ ! -f "${DOSSIER_OSM}/${FICHIER}.osm.pbf" ] || [ `ageEnSeconde "${DOSSIER_OSM}/${FICHIER}.osm.pbf"` -gt 86000 ] ; then
# echo "Téléchargement du nouveau fichier PBF ...";
# wget $URL_DOWNLOAD -O "${DOSSIER_OSM}/${FICHIER}.osm.pbf"
#else
# echo "Fichier ${FICHIER}.osm.pbf existant depuis moins d'un jour.";
#fi
if [ ! -f "${DOSSIER_OSM}/${FICHIER}_boundary.osm.pbf" ] || [ `ageEnSeconde "${DOSSIER_OSM}/${FICHIER}_boundary.osm.pbf"` -gt 86000 ] ; then
echo "Filtrage du fichier en cours ...";
$BIN_OSMOSIS \
-v \
--read-pbf-fast "${DOSSIER_OSM}/${FICHIER}.osm.pbf" workers=6 \
--tf accept-relations admin_level=* \
--tf accept-relations type=boundary \
--used-way \
--used-node \
--buffer --write-pbf "${DOSSIER_OSM}/${FICHIER}_boundary.osm.pbf"
# Test avec communauté de communes du Haut-Allier
# --tf accept-relations admin_level=8 \
# --tf accept-relations type=boundary \
# --tf accept-relations ref:INSEE=48010,48041,48048,48062,48080,48086,48105,48129,48150 \
else
echo "Fichier filtré ${FICHIER}_boundary.osm.pbf existant depuis moins d'un jour.";
fi
#------------------------------------------------------------------------------------------------------------
# ATTENTION : nécessite ici de reconstruire les relations incomplètes avant d'utiliser ogr2ogr
#------------------------------------------------------------------------------------------------------------
if [ ! -f "${DOSSIER_OSM}/${FICHIER}_boundary.osm.pbf" ] ; then
echo "Impossible de trouver ${FICHIER}_boundary.osm.pbf existant depuis moins d'un jour.";
else
echo "Importation dans MySQL en cours ...";
$BIN_OGR \
--config OSM_CONFIG_FILE $OSM_CONF_INI \
--config MYSQL_UNIX_PORT $MYSQL_UNIX_PORT \
-overwrite \
-progress \
-f "MySQL" MYSQL:${MYSQL_DATABASE},user=${MYSQL_USER},password=${MYSQL_PASSWORD},host=${MYSQL_HOST},port=${MYSQL_PORT} \
-lco engine=MYISAM \
-lco spatial_index=no \
"${DOSSIER_OSM}/${FICHIER}_boundary.osm.pbf" multipolygons points
fi