Commit 5e9f7f03 authored by Adrien Pavie's avatar Adrien Pavie
Browse files

Flat nodes as option, wikidata and amin8 info in various themes

parent 627481a0
......@@ -104,6 +104,7 @@ Les paramètres généraux de configuration du service sont à renseigner dans l
* `PG_DB_OLD` : nom de la base de données qui contiendra les données précédemment en production (exemple: `osm4odf_prev`)
* `PARALLEL_JOBS` : nombre de tâches à exécuter en parallèle, idéalement 75% des coeurs du processeur (exemple: `6`)
* `CACHE_MEM` : mémoire à allouer lors de l'import de données, en MB, idéalement 75% de la mémoire vive disponible (exemple: `10000`)
* `FLAT_NODES` : activer l'option `--flat-nodes` de l'outil osm2pgsql, utile pour les imports de grosses régions ou de pays (`true` pour activer, `false` pour désactiver)
### Thèmes
......@@ -138,6 +139,9 @@ FROM <TABLE>
WHERE <GEOMCOND> AND emergency = 'defibrillator'
```
Des balises optionnelles peuvent également être prévues :
* `<ADM8>` : ajouter les métadonnées de la commune (code INSEE, nom)
## Base de données
......
......@@ -124,11 +124,13 @@ function getThemeData(theme, boundary, options) {
// Create view in DB
boundary = "'" + boundary.replace(/'/g, "") + "'";
const dist = options.radius > 0 ? options.radius * 1000 : null;
const geomCond = `b.osm_id = ${boundary} AND ${dist ? `ST_DWithin(t.way, b.center, ${dist})` : "t.way && b.way AND ST_Intersects(t.way, b.way)"}`;
const hasAdm8 = theme.sql.includes("<ADM8>");
const geomCond = `b.osm_id = ${boundary} AND ${dist ? `ST_DWithin(t.way, b.center, ${dist})` : "t.way && b.way AND ST_Intersects(t.way, b.way)"} ${hasAdm8 ? " AND b2.type = 'admin_8' AND ST_Contains(b2.way, ST_Centroid(t.way))" : ""}`;
let request = theme.geomtypes.map(g => (
theme.sql
.replace(/<TABLE>/g, `boundary b, planet_osm_${g} t`)
.replace(/<TABLE>/g, `boundary b, planet_osm_${g} t${hasAdm8 ? ", boundary b2" : ""}`)
.replace(/<GEOM>/g, options.aspoint ? "ST_Centroid(t.way) AS geom" : "t.way AS geom")
.replace(/<ADM8>/g, "b2.name AS adm8_name, b2.ref AS adm8_ref")
)).join(" UNION ");
/*
......
......@@ -10,5 +10,6 @@
"PG_DB_TMP": "osm4odf_next",
"PG_DB_OLD": "osm4odf_prev",
"CACHE_MEM": 10000
"CACHE_MEM": 10000,
"FLAT_NODES": false
}
......@@ -59,7 +59,7 @@ if ! [ -f "${pbf_light_file}" ]; then
osmium tags-filter \
${pbf_file} \
${used_tags} \
-f pbf,add_metadata=id+version+timestamp \
-f pbf,add_metadata=version+timestamp \
--no-progress \
--overwrite -o ${pbf_light_file}
else
......@@ -76,11 +76,18 @@ psql -h "${PG_HOST}" -U "${PG_USER}" -p "${PG_PORT}" -c "DROP DATABASE IF EXISTS
# Start import
echo "======= Import OSM data into DB ======="
flat_nodes="${WORK_DIR}/flat.nodes"
flat_nodes_opts=""
if [ "${FLAT_NODES}" == "true" ]; then
flat_nodes_opts="--flat-nodes ${flat_nodes}"
echo "Flat nodes option enabled"
fi
osm2pgsql --create \
-H "${PG_HOST}" -U "${PG_USER}" -P "${PG_PORT}" -d "${PG_DB_TMP}" \
--cache "${CACHE_MEM}" \
--slim --drop \
--flat-nodes "${flat_nodes}" \
${flat_nodes_opts} \
--number-processes "${PARALLEL_JOBS}" \
--style "import.style" \
--hstore-all --multi-geometry --keep-coastlines --extra-attributes \
......
......@@ -6,6 +6,7 @@ SELECT
t.tags->'operator' AS operator, t.tags->'network' AS network, t.wheelchair,
t.tags->'opening_hours' AS opening_hours, t.tags->'bic' AS bank_id_code,
CASE WHEN t.amenity = 'atm' THEN 'yes' ELSE t.tags->'atm' END AS has_atm,
t.tags->'brand:wikidata' AS brand_wikidata,
<GEOM>
FROM <TABLE>
WHERE <GEOMCOND> AND t.amenity IN ('bank', 'atm')
......@@ -4,6 +4,6 @@
SELECT
t.osm_id, t.tags->'name' AS name, t.tags->'religion' AS religion, t.tags->'denomination' AS religion_denomination,
t.tags->'operator' AS operator, t.wheelchair, t.tags->'opening_hours' AS opening_hours,
<GEOM>
<ADM8>, <GEOM>
FROM <TABLE>
WHERE <GEOMCOND> AND t.landuse = 'cemetery'
......@@ -2,6 +2,8 @@
--GEOMETRY=point,polygon
SELECT
t.osm_id, t.tags->'name' AS name, t.tags->'amenity' AS type, t.tags->'operator:type' AS statut, <GEOM>
t.osm_id, t.tags->'name' AS name, t.tags->'amenity' AS type, t.tags->'school:FR' AS type_fr,
t.tags->'operator:type' AS statut, t.tags->'ref:UAI' AS ref_uai, t.tags->'wikidata' AS wikidata,
<ADM8>, <GEOM>
FROM <TABLE>
WHERE <GEOMCOND> AND t.amenity IN ('school', 'kindergarten', 'college', 'university')
......@@ -4,6 +4,6 @@
SELECT
t.osm_id, t.amenity AS type, t.tags->'name' AS name, t.tags->'ref:isil' AS ref_isil,
t.tags->'operator' AS operator, t.wheelchair, t.tags->'opening_hours' AS opening_hours,
<GEOM>
<ADM8>, <GEOM>
FROM <TABLE>
WHERE <GEOMCOND> AND t.amenity IN ('library', 'public_bookcase')
--METADATA={ "name:fr": "Service public", "name:en": "Service public" }
--GEOMETRY=point,polygon
SELECT
t.osm_id, COALESCE(t.amenity, t.office) AS type, t.tags->'name' AS name, t.tags->'operator' AS operator,
t.wheelchair, t.tags->'opening_hours' AS opening_hours,
<ADM8>, <GEOM>
FROM <TABLE>
WHERE <GEOMCOND> AND (t.amenity IN ('embassy', 'public_building', 'townhall') OR t.office IN ('diplomatic', 'government'))
......@@ -6,6 +6,7 @@ SELECT
t.tags->'brand' AS brand, t.tags->'opening_hours' AS opening_hours,
t.wheelchair, t.tags->'cuisine' AS cuisine, t.tags->'delivery' AS delivery, t.tags->'takeaway' AS takeaway,
t.tags->'stars' AS stars, t.tags->'capacity' AS capacity, t.tags->'drive_through' AS drive_through,
t.tags->'wikidata' AS wikidata, t.tags->'brand:wikidata' AS brand_wikidata, t.tags->'ref:FR:SIRET' AS siret,
<GEOM>
FROM <TABLE>
WHERE <GEOMCOND> AND t.amenity IN ('bar', 'biergarten', 'cafe', 'fast_food', 'food_court', 'ice_cream', 'pub', 'restaurant')
......@@ -5,6 +5,6 @@ SELECT
t.osm_id, COALESCE(t.office, t.craft, t.shop) AS type, t.tags->'name' AS name,
t.tags->'brand' AS brand, t.tags->'operator' AS operator, t.wheelchair,
t.tags->'opening_hours' AS opening_hours, t.tags->'level' AS level, t.tags->'ref:FR:SIRET' AS siret,
<GEOM>
t.tags->'wikidata' AS wikidata, t.tags->'brand:wikidata' AS brand_wikidata, <GEOM>
FROM <TABLE>
WHERE <GEOMCOND> AND (t.shop IS NOT NULL OR t.craft IS NOT NULL OR t.office IS NOT NULL)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment