Объединение shape файлов OSM с сайта Geofabrik.de

Ответить
Kuper
Интересующийся
Сообщения: 17
Зарегистрирован: 25 янв 2016, 12:48
Репутация: 5
Откуда: Москва

Объединение shape файлов OSM с сайта Geofabrik.de

Сообщение Kuper » 28 июл 2022, 14:46

На сайте Geofabrik.de можно скачать данные OSM по различным регионам. Чтобы объединить одинаковые слои по разным регионам можно использовать следующий код. Вызывать нужно в командной строке из папки QGIS\bin или если установить osgeo gdal , то из автономного скрипта (имейте в виду, что osgeo работает с python не выше 3.7)

#импорт библиотек
import os
import subprocess
from subprocess import call
import fnmatch

isFirst = True


path_in = r'C:\Users\Asus\Documents\WORK\01_DATA\OSM\Geofabrik_OSM_shp\RUS'
path_out = r'C:\Users\Asus\Documents\WORK\01_DATA\OSM\Geofabrik_OSM_shp\merged'

dict_tags = {'gis_osm_buildings_a_free_1.shp': 'osm_buildings_a.shp', 'gis_osm_landuse_a_free_1.shp': 'osm_landuse_a.shp',
'gis_osm_natural_free_1.shp': 'osm_natural.shp', 'osm_places_a_free_1.shp': 'osm_places_a.shp',
'gis_osm_places_free_1.shp': 'osm_places.shp', 'gis_osm_pois_a_free_1.shp': 'osm_pois_a.shp',
'gis_osm_pois_free_1.shp': 'osm_pois.shp', 'gis_osm_railways_free_1.shp': 'osm_railways.shp',
'gis_osm_roads_free_1.shp': 'osm_roads.shp', 'gis_osm_traffic_a_free_1.shp': 'osm_traffic_a.shp',
'gis_osm_traffic_free_1.shp': 'osm_traffic.shp',
'gis_osm_transport_a_free_1.shp': 'osm_transport_a.shp', 'gis_osm_transport_free_1.shp': 'osm_transport.shp',
'gis_osm_water_a_free_1.shp': 'osm_water_a.shp', 'gis_osm_waterways_1.shp': 'osm_waterways.shp'}



try:
for k,v in dict_tags.items():
print(f'Загружается слой {k}')
for dirpath, dirnames, filenames in os.walk(path_in):
for dirname in dirnames:
print(dirname)
for file in filenames:
if file.endswith("shp") and file == k:
in_file = os.path.join(dirpath, file)
print(in_file)
out_file = os.path.join(path_out, v)
print(out_file)
if (isFirst):
command_create = fr'ogr2ogr -progress {out_file} {in_file} -lco ENCODING=UTF-8 '
call(command_create)
isFirst = False
else:
command_append = fr'ogr2ogr -progress -update -append {out_file} {in_file} -lco ENCODING=UTF-8 '
call(command_append)
else:
continue
except:
print("Something wrong")
Геоаналитика, Тг @kaaaweeeu

Ответить

Вернуться в «GDAL/OGR»

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и 8 гостей