2 #-----------------------------------------------------------------------------
3 # nominatim - [description]
4 #-----------------------------------------------------------------------------
5 # Copyright 2010, Brian Quinion
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #-----------------------------------------------------------------------------
37 #include "nominatim.h"
38 #include "postgresql.h"
46 void exit_nicely(void)
48 fprintf(stderr, "Error occurred, cleaning up\n");
52 void short_usage(char *arg0)
54 const char *name = basename(arg0);
56 fprintf(stderr, "Usage error. For further information see:\n");
57 fprintf(stderr, "\t%s -h|--help\n", name);
60 static void long_usage(char *arg0)
62 const char *name = basename(arg0);
64 fprintf(stderr, "Usage:\n");
65 fprintf(stderr, "\t%s [options] planet.osms\n", name);
66 fprintf(stderr, "\nThis will import the structured osm data into a PostgreSQL database\n");
67 fprintf(stderr, "suitable for nominatim search engine\n");
68 fprintf(stderr, "\nOptions:\n");
69 fprintf(stderr, " -d|--database\tThe name of the PostgreSQL database to connect\n");
70 fprintf(stderr, " \tto (default: nominatim).\n");
71 fprintf(stderr, " -U|--username\tPostgresql user name.\n");
72 fprintf(stderr, " -W|--password\tForce password prompt.\n");
73 fprintf(stderr, " -H|--host\t\tDatabase server hostname or socket location.\n");
74 fprintf(stderr, " -P|--port\t\tDatabase server port.\n");
75 fprintf(stderr, " -i|--index\t\tIndex the database.\n");
76 fprintf(stderr, " -e|--export\t\tGenerate a structured file.\n");
77 fprintf(stderr, " -I|--import\t\tImport a structured file.\n");
78 fprintf(stderr, " -t|--threads\t\tNumber of threads to create for indexing.\n");
79 fprintf(stderr, " -F|--file\t\tfile to use (either to import or export).\n");
80 fprintf(stderr, " -T|--tagfile\t\tfile containing 'special' tag pairs\n");
81 fprintf(stderr, " \t(default: partitionedtags.def).\n");
82 fprintf(stderr, " -h|--help\t\tHelp information.\n");
83 fprintf(stderr, " -v|--verbose\t\tVerbose output.\n");
84 fprintf(stderr, "\n");
86 if (sizeof(int*) == 4)
88 fprintf(stderr, "\n\nYou are running this on 32bit system - this will not work\n");
92 int main(int argc, char *argv[])
94 int long_usage_bool=0;
96 const char *db = "nominatim";
97 const char *username=NULL;
98 const char *host=NULL;
99 const char *password=NULL;
100 const char *port = "5432";
101 const char *conninfo = NULL;
106 const char *file = NULL;
107 const char *tagsfile = "partitionedtags.def";
110 //structuredinputfile = "out.osms";
114 fprintf(stderr, "nominatim SVN version %s\n\n", VERSION);
118 int c, option_index = 0;
119 static struct option long_options[] =
123 {"verbose", 0, 0, 'v'},
125 {"database", 1, 0, 'd'},
126 {"username", 1, 0, 'U'},
127 {"password", 0, 0, 'W'},
131 {"index", 0, 0, 'i'},
132 {"export", 0, 0, 'e'},
133 {"import", 1, 0, 'I'},
134 {"threads", 1, 0, 't'},
136 {"tagsfile", 1, 0, 'T'},
142 c = getopt_long(argc, argv, "vhd:U:WH:P:ieIt:F:T:", long_options, &option_index);
179 threads=atoi(optarg);
189 short_usage(argv[0]);
200 if (threads < 1) threads = 1;
203 if (argc == optind) { // No non-switch arguments
204 short_usage(argv[0]);
210 fprintf(stderr, "Error: --index and --import options can not be used on the same database!\n");
215 password = simple_prompt("Password:", 100, 0);
218 password = getenv("PGPASS");
221 // Test the database connection
222 conninfo = build_conninfo(db, username, password, host, port);
223 conn = PQconnectdb(conninfo);
224 if (PQstatus(conn) != CONNECTION_OK)
226 fprintf(stderr, "Connection to database failed: %s\n", PQerrorMessage(conn));
231 if (!index && !export && !import)
233 fprintf(stderr, "Please select index, export or import.\n");
236 if (index) nominatim_index(0, 30, threads, conninfo, file);
237 if (export) nominatim_export(0, 30, conninfo, file);
238 if (import) nominatim_import(conninfo, tagsfile, file);