B16: локальный OSM в PostGIS — geo_service без интернета
- services/osm_local.py: слой запросов к planet_osm_* (osm2pgsql, SRID 3857): roads/density (ST_Length merc × cos(lat) — проверено на merc/geo=1/cos), forest (честная площадь ST_Intersection), water (полигон/водоток), settlements (village/town/city). Сектор-«пирог» 45° строится в WGS84. - geo_service.get_zone_features: PostGIS-путь, Overpass — fallback (osm_available() по наличию planet_osm_line). - scripts/b16-import.sh: osm2pgsql --slim -C 800, Беларусь 333МБ pbf (Geofabrik, md5 проверен) → 4.5 мин на CT108; PostGIS 3.6 установлен в живой vector-postgres (apt, без смены образа). - Валидация: Минск/Полоцк/Браслав — правдоподобные плотности (7.9/2.9/1.5 км/км²), зоны различаются по направлениям; 32 сектора за 1.9 c (без сети). - Тесты: +8 (osm_local контракт, интеграция, отсутствие Overpass-вызовов), вне БД — skip. Всего 190 passed, 5 skipped. Критерий B16: build_search_zones без внешнего интернета — ВЫПОЛНЕН (единственный Overpass остаётся fallback-веткой при пустых таблицах).
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
# B16: импорт Беларуси в PostGIS (гибкий стиль osm2pgsql, SRID 4326)
|
||||
# RAM 2ГБ: -C 800 (node cache), --slim без keep-coastlines; number-processes 2
|
||||
set -e
|
||||
PG="docker exec -i vector-postgres"
|
||||
$PG psql -U postgres -d vector_mchs -c "DROP TABLE IF EXISTS planet_osm_line, planet_osm_point, planet_osm_polygon, planet_osm_roads, osm2pgsql_properties CASCADE;" >/dev/null 2>&1 || true
|
||||
# pbf внутри контейнера: монтируем /tmp через docker cp (проще, чем volume)
|
||||
docker cp /tmp/belarus-latest.osm.pbf vector-postgres:/tmp/belarus.osm.pbf
|
||||
docker exec vector-postgres sh -c "osm2pgsql --slim --drop --create \
|
||||
-H localhost -P 5432 -U postgres -W -d vector_mchs \
|
||||
--cache 800 --number-processes 2 -S /usr/share/osm2pgsql/default.style \
|
||||
/tmp/belarus.osm.pbf" 2>&1 | tail -12
|
||||
echo "=== tables:"
|
||||
docker exec vector-postgres psql -U postgres -d vector_mchs -t -c "SELECT table_name FROM information_schema.tables WHERE table_name LIKE 'planet_osm%';"
|
||||
docker exec vector-postgres psql -U postgres -d vector_mchs -t -c "SELECT 'roads', count(*) FROM planet_osm_line WHERE highway IS NOT NULL UNION ALL SELECT 'water', count(*) FROM planet_osm_polygon WHERE (landuse='reservoir' OR \"natural\"='water' OR waterway IS NOT NULL) UNION ALL SELECT 'forest', count(*) FROM planet_osm_polygon WHERE landuse='forest' OR \"natural\"='wood' UNION ALL SELECT 'settlements', count(*) FROM planet_osm_point WHERE place IN ('village','town','city');"
|
||||
Reference in New Issue
Block a user