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) {
87 fprintf(stderr, "\n\nYou are running this on 32bit system - this will not work\n");
91 int main(int argc, char *argv[])
93 int long_usage_bool=0;
95 const char *db = "nominatim";
96 const char *username=NULL;
97 const char *host=NULL;
98 const char *password=NULL;
99 const char *port = "5432";
100 const char *conninfo = NULL;
105 const char *file = NULL;
106 const char *tagsfile = "partitionedtags.def";
109 //structuredinputfile = "out.osms";
113 fprintf(stderr, "nominatim SVN version %s\n\n", VERSION);
115 if (sizeof(int*) == 4) {
116 fprintf(stderr, "\n!! You are running this on 32bit system, so at most\n");
117 fprintf(stderr, "!! 3GB of RAM can be used. If you encounter unexpected\n");
118 fprintf(stderr, "!! exceptions during import, you should try running in slim\n");
119 fprintf(stderr, "!! mode using parameter -s.\n");
124 int c, option_index = 0;
125 static struct option long_options[] = {
128 {"verbose", 0, 0, 'v'},
130 {"database", 1, 0, 'd'},
131 {"username", 1, 0, 'U'},
132 {"password", 0, 0, 'W'},
136 {"index", 0, 0, 'i'},
137 {"export", 0, 0, 'e'},
138 {"import", 1, 0, 'I'},
139 {"threads", 1, 0, 't'},
141 {"tagsfile", 1, 0, 'T'},
147 c = getopt_long(argc, argv, "vhd:U:WH:P:ieIt:F:T:", long_options, &option_index);
152 case 'v': verbose=1; break;
153 case 'd': db=optarg; break;
154 case 'U': username=optarg; break;
155 case 'W': pass_prompt=1; break;
156 case 'H': host=optarg; break;
157 case 'P': port=optarg; break;
158 case 'h': long_usage_bool=1; break;
159 case 'i': index=1; break;
160 case 'e': export=1; break;
161 case 'I': import=1; break;
162 case 't': threads=atoi(optarg); break;
163 case 'F': file=optarg; break;
164 case 'T': tagsfile=optarg; break;
167 short_usage(argv[0]);
172 if (long_usage_bool) {
177 if (threads < 1) threads = 1;
180 if (argc == optind) { // No non-switch arguments
181 short_usage(argv[0]);
185 if (index && import) {
186 fprintf(stderr, "Error: --index and --import options can not be used on the same database!\n");
191 password = simple_prompt("Password:", 100, 0);
193 password = getenv("PGPASS");
196 // Test the database connection
197 conninfo = build_conninfo(db, username, password, host, port);
198 conn = PQconnectdb(conninfo);
199 if (PQstatus(conn) != CONNECTION_OK) {
200 fprintf(stderr, "Connection to database failed: %s\n", PQerrorMessage(conn));
205 if (index) nominatim_index(0, 30, threads, conninfo, file);
206 if (export) nominatim_export(0, 30, conninfo, file);
207 if (import) nominatim_import(conninfo, tagsfile, file);