1 # SPDX-License-Identifier: GPL-2.0-only
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Function to add additional OSM data from a file or the API into the database.
10 from pathlib import Path
14 from nominatim.tools.exec_utils import run_osm2pgsql, get_url
16 LOG = logging.getLogger()
18 def add_data_from_file(fname, options):
19 """ Adds data from a OSM file to the database. The file may be a normal
20 OSM file or a diff file in all formats supported by libosmium.
22 options['import_file'] = Path(fname)
23 options['append'] = True
24 run_osm2pgsql(options)
26 # No status update. We don't know where the file came from.
30 def add_osm_object(osm_type, osm_id, use_main_api, options):
31 """ Add or update a single OSM object from the latest version of the
35 base_url = f'https://www.openstreetmap.org/api/0.6/{osm_type}/{osm_id}'
36 if osm_type in ('way', 'relation'):
40 if osm_type == 'node':
41 data = f'node({osm_id});out meta;'
42 elif osm_type == 'way':
43 data = f'(way({osm_id});>;);out meta;'
45 data = f'(rel(id:{osm_id});>;);out meta;'
46 base_url = 'https://overpass-api.de/api/interpreter?' \
47 + urllib.parse.urlencode({'data': data})
49 options['append'] = True
50 options['import_data'] = get_url(base_url).encode('utf-8')
52 run_osm2pgsql(options)