]> git.openstreetmap.org Git - nominatim.git/blob - nominatim/clicmd/add_data.py
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / nominatim / clicmd / add_data.py
1 """
2 Implementation of the 'add-data' subcommand.
3 """
4 import logging
5
6 # Do not repeat documentation of subcommand classes.
7 # pylint: disable=C0111
8 # Using non-top-level imports to avoid eventually unused imports.
9 # pylint: disable=E0012,C0415
10
11 LOG = logging.getLogger()
12
13 class UpdateAddData:
14     """\
15     Add additional data from a file or an online source.
16
17     Data is only imported, not indexed. You need to call `nominatim index`
18     to complete the process.
19     """
20
21     @staticmethod
22     def add_args(parser):
23         group_name = parser.add_argument_group('Source')
24         group = group_name.add_mutually_exclusive_group(required=True)
25         group.add_argument('--file', metavar='FILE',
26                            help='Import data from an OSM file or diff file')
27         group.add_argument('--diff', metavar='FILE',
28                            help='Import data from an OSM diff file (deprecated: use --file)')
29         group.add_argument('--node', metavar='ID', type=int,
30                            help='Import a single node from the API')
31         group.add_argument('--way', metavar='ID', type=int,
32                            help='Import a single way from the API')
33         group.add_argument('--relation', metavar='ID', type=int,
34                            help='Import a single relation from the API')
35         group.add_argument('--tiger-data', metavar='DIR',
36                            help='Add housenumbers from the US TIGER census database.')
37         group = parser.add_argument_group('Extra arguments')
38         group.add_argument('--use-main-api', action='store_true',
39                            help='Use OSM API instead of Overpass to download objects')
40         group.add_argument('--osm2pgsql-cache', metavar='SIZE', type=int,
41                            help='Size of cache to be used by osm2pgsql (in MB)')
42         group.add_argument('--socket-timeout', dest='socket_timeout', type=int, default=60,
43                            help='Set timeout for file downloads.')
44
45     @staticmethod
46     def run(args):
47         from nominatim.tokenizer import factory as tokenizer_factory
48         from nominatim.tools import tiger_data, add_osm_data
49
50         if args.tiger_data:
51             tokenizer = tokenizer_factory.get_tokenizer_for_db(args.config)
52             return tiger_data.add_tiger_data(args.tiger_data,
53                                              args.config, args.threads or 1,
54                                              tokenizer)
55
56         osm2pgsql_params = args.osm2pgsql_options(default_cache=1000, default_threads=1)
57         if args.file or args.diff:
58             return add_osm_data.add_data_from_file(args.file or args.diff,
59                                                    osm2pgsql_params)
60
61         if args.node:
62             return add_osm_data.add_osm_object('node', args.node,
63                                                args.use_main_api,
64                                                osm2pgsql_params)
65
66         if args.way:
67             return add_osm_data.add_osm_object('way', args.way,
68                                                args.use_main_api,
69                                                osm2pgsql_params)
70
71         if args.relation:
72             return add_osm_data.add_osm_object('relation', args.relation,
73                                                args.use_main_api,
74                                                osm2pgsql_params)
75
76         return 0