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 Implementation of the 'add-data' subcommand.
10 from typing import cast
16 from nominatim.clicmd.args import NominatimArgs
18 # Do not repeat documentation of subcommand classes.
19 # pylint: disable=C0111
20 # Using non-top-level imports to avoid eventually unused imports.
21 # pylint: disable=E0012,C0415
23 LOG = logging.getLogger()
27 Add additional data from a file or an online source.
29 This command allows to add or update the search data in the database.
30 The data can come either from an OSM file or single OSM objects can
31 directly be downloaded from the OSM API. This function only loads the
32 data into the database. Afterwards it still needs to be integrated
33 in the search index. Use the `nominatim index` command for that.
35 The command can also be used to add external non-OSM data to the
36 database. At the moment the only supported format is TIGER housenumber
37 data. See the online documentation at
38 https://nominatim.org/release-docs/latest/admin/Import/#installing-tiger-housenumber-data-for-the-us
42 def add_args(self, parser: argparse.ArgumentParser) -> None:
43 group_name = parser.add_argument_group('Source')
44 group1 = group_name.add_mutually_exclusive_group(required=True)
45 group1.add_argument('--file', metavar='FILE',
46 help='Import data from an OSM file or diff file')
47 group1.add_argument('--diff', metavar='FILE',
48 help='Import data from an OSM diff file (deprecated: use --file)')
49 group1.add_argument('--node', metavar='ID', type=int,
50 help='Import a single node from the API')
51 group1.add_argument('--way', metavar='ID', type=int,
52 help='Import a single way from the API')
53 group1.add_argument('--relation', metavar='ID', type=int,
54 help='Import a single relation from the API')
55 group1.add_argument('--tiger-data', metavar='DIR',
56 help='Add housenumbers from the US TIGER census database')
57 group2 = parser.add_argument_group('Extra arguments')
58 group2.add_argument('--use-main-api', action='store_true',
59 help='Use OSM API instead of Overpass to download objects')
60 group2.add_argument('--osm2pgsql-cache', metavar='SIZE', type=int,
61 help='Size of cache to be used by osm2pgsql (in MB)')
62 group2.add_argument('--socket-timeout', dest='socket_timeout', type=int, default=60,
63 help='Set timeout for file downloads')
66 def run(self, args: NominatimArgs) -> int:
67 from nominatim.tokenizer import factory as tokenizer_factory
68 from nominatim.tools import tiger_data, add_osm_data
71 tokenizer = tokenizer_factory.get_tokenizer_for_db(args.config)
72 return tiger_data.add_tiger_data(args.tiger_data,
74 args.threads or psutil.cpu_count() or 1,
77 osm2pgsql_params = args.osm2pgsql_options(default_cache=1000, default_threads=1)
78 if args.file or args.diff:
79 return add_osm_data.add_data_from_file(args.config.get_libpq_dsn(),
80 cast(str, args.file or args.diff),
84 return add_osm_data.add_osm_object(args.config.get_libpq_dsn(),
90 return add_osm_data.add_osm_object(args.config.get_libpq_dsn(),
96 return add_osm_data.add_osm_object(args.config.get_libpq_dsn(),
97 'relation', args.relation,