Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 210 lines (190 sloc) 7.448 kb
e2d20035 »
2012-04-20 Add options used and some stats to output database.
1 /*
2
3 Copyright 2012 Jochen Topf <jochen@topf.org>.
4
5 This file is part of OSMCoastline.
6
7 OSMCoastline is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 OSMCoastline is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with OSMCoastline. If not, see <http://www.gnu.org/licenses/>.
19
20 */
21
22 #include <iostream>
23 #include <string>
24 #include <cstring>
25 #include <cstdlib>
26 #include <getopt.h>
27
28 #include "osmcoastline.hpp"
29 #include "options.hpp"
30
31 Options::Options(int argc, char* argv[]) :
32 inputfile(),
33 bbox_overlap(-1),
34 close_distance(1.0),
35 close_rings(true),
36 create_index(true),
37 debug(false),
38 max_points_in_polygon(1000),
39 split_large_polygons(true),
fef35c51 »
2012-05-21 Change command line options to allow output of land and water polygon…
40 output_polygons(land),
e2d20035 »
2012-04-20 Add options used and some stats to output database.
41 output_database(),
42 overwrite_output(false),
43 output_rings(false),
93ca9fcc »
2012-05-13 Add outpu-lines option
44 output_lines(false),
e2d20035 »
2012-04-20 Add options used and some stats to output database.
45 epsg(4326),
46 simplify(false),
47 tolerance(0),
fef35c51 »
2012-05-21 Change command line options to allow output of land and water polygon…
48 verbose(false)
e2d20035 »
2012-04-20 Add options used and some stats to output database.
49 {
50 static struct option long_options[] = {
51 {"bbox-overlap", required_argument, 0, 'b'},
52 {"close-distance", required_argument, 0, 'c'},
53 {"no-index", no_argument, 0, 'i'},
54 {"debug", no_argument, 0, 'd'},
55 {"help", no_argument, 0, 'h'},
93ca9fcc »
2012-05-13 Add outpu-lines option
56 {"output-lines", no_argument, 0, 'l'},
e2d20035 »
2012-04-20 Add options used and some stats to output database.
57 {"max-points", required_argument, 0, 'm'},
58 {"output-database", required_argument, 0, 'o'},
fef35c51 »
2012-05-21 Change command line options to allow output of land and water polygon…
59 {"output-polygons", required_argument, 0, 'p'},
e2d20035 »
2012-04-20 Add options used and some stats to output database.
60 {"output-rings", no_argument, 0, 'r'},
61 {"overwrite", no_argument, 0, 'f'},
62 {"srs", required_argument, 0, 's'},
63 #ifdef EXPERIMENTAL
64 {"simplify", required_argument, 0, 'S'},
65 #endif
66 {"verbose", no_argument, 0, 'v'},
67 {0, 0, 0, 0}
68 };
69
70 while (1) {
fef35c51 »
2012-05-21 Change command line options to allow output of land and water polygon…
71 int c = getopt_long(argc, argv, "b:c:idhlm:o:p:rfs:S:v", long_options, 0);
e2d20035 »
2012-04-20 Add options used and some stats to output database.
72 if (c == -1)
73 break;
74
75 switch (c) {
76 case 'b':
77 bbox_overlap = atof(optarg);
78 break;
79 case 'c':
80 close_distance = atoi(optarg);
81 if (close_distance == 0) {
82 close_rings = false;
83 }
84 break;
85 case 'i':
86 create_index = false;
87 break;
88 case 'd':
89 debug = true;
90 std::cerr << "Enabled debug option\n";
91 break;
92 case 'h':
93 print_help();
94 exit(return_code_ok);
93ca9fcc »
2012-05-13 Add outpu-lines option
95 case 'l':
96 output_lines = true;
97 break;
e2d20035 »
2012-04-20 Add options used and some stats to output database.
98 case 'm':
99 max_points_in_polygon = atoi(optarg);
100 if (max_points_in_polygon == 0) {
101 split_large_polygons = false;
102 }
103 break;
104 case 'p':
fef35c51 »
2012-05-21 Change command line options to allow output of land and water polygon…
105 if (!strcmp(optarg, "none")) {
106 output_polygons = none;
107 } else if (!strcmp(optarg, "land")) {
108 output_polygons = land;
109 } else if (!strcmp(optarg, "water")) {
110 output_polygons = water;
111 } else if (!strcmp(optarg, "both")) {
112 output_polygons = both;
113 } else {
114 std::cerr << "Unknown argument '" << optarg << "' for -p/--output-polygon option\n";
115 exit(return_code_cmdline);
116 }
e2d20035 »
2012-04-20 Add options used and some stats to output database.
117 break;
118 case 'o':
119 output_database = optarg;
120 break;
121 case 'r':
122 output_rings = true;
123 break;
124 case 'f':
125 overwrite_output = true;
126 break;
127 case 's':
128 epsg = get_epsg(optarg);
129 break;
130 #ifdef EXPERIMENTAL
131 case 'S':
132 simplify = true;
133 tolerance = atof(optarg);
134 break;
135 #endif
136 case 'v':
137 verbose = true;
138 break;
139 default:
140 exit(return_code_cmdline);
141 }
142 }
143
fef35c51 »
2012-05-21 Change command line options to allow output of land and water polygon…
144 if (!split_large_polygons && (output_polygons == water || output_polygons == both)) {
145 std::cerr << "Can not use -m/--max-points=0 when writing out water polygons\n";
e2d20035 »
2012-04-20 Add options used and some stats to output database.
146 exit(return_code_cmdline);
147 }
148
149 if (optind != argc - 1) {
150 std::cerr << "Usage: " << argv[0] << " [OPTIONS] OSMFILE\n";
151 exit(return_code_cmdline);
152 }
153
27821cb6 »
2012-04-24 Removed -O option from osmcoastline.
154 if (output_database.empty()) {
155 std::cerr << "Missing --output-database/-o option.\n";
e2d20035 »
2012-04-20 Add options used and some stats to output database.
156 exit(return_code_cmdline);
157 }
158
159 if (bbox_overlap == -1) {
160 if (epsg == 4326) {
161 bbox_overlap = 0.0001;
162 } else {
163 bbox_overlap = 10;
164 }
165 }
166
167 inputfile = argv[optind];
168 }
169
170 int Options::get_epsg(const char* text) {
171 if (!strcasecmp(text, "WGS84") || !strcmp(text, "4326")) {
172 return 4326;
173 }
174 if (!strcmp(text, "3857")) {
175 return 3857;
176 }
177 if (!strcmp(text, "3785") || !strcmp(text, "900913")) {
178 std::cerr << "Please use code 3857 for the 'Google Mercator' projection!\n";
179 exit(return_code_cmdline);
180 }
181 std::cerr << "Unknown SRS '" << text << "'. Currently only 4326 (WGS84) and 3857 ('Google Mercator') are supported.\n";
182 exit(return_code_cmdline);
183 }
184
77376454 »
2012-05-02 Add check target to Makefile
185 void Options::print_help() const {
e2d20035 »
2012-04-20 Add options used and some stats to output database.
186 std::cout << "osmcoastline [OPTIONS] OSMFILE\n"
27821cb6 »
2012-04-24 Removed -O option from osmcoastline.
187 << "\nOptions:\n"
e2d20035 »
2012-04-20 Add options used and some stats to output database.
188 << " -h, --help - This help message\n"
189 << " -c, --close-distance - Distance between nodes under which open rings\n"
190 << " are closed (0 - disable closing of rings)\n"
191 << " -b, --bbox-overlap - Set overlap when splitting polygons\n"
192 << " -i, --no-index - Do not create spatial indexes in output database\n"
193 << " -d, --debug - Enable debugging output\n"
194 << " -f, --overwrite - Overwrite output files if they already exist\n"
93ca9fcc »
2012-05-13 Add outpu-lines option
195 << " -l, --output-lines - Output coastlines as lines to database file\n"
fef35c51 »
2012-05-21 Change command line options to allow output of land and water polygon…
196 << " -m, --max-points - Split lines/polygons with more than this many points\n"
e2d20035 »
2012-04-20 Add options used and some stats to output database.
197 << " (0 - disable splitting)\n"
198 << " -o, --output-database=FILE - Spatialite database file for output\n"
fef35c51 »
2012-05-21 Change command line options to allow output of land and water polygon…
199 << " -p, --output-polygons=land|water|both|none\n"
200 << " - Which polygons to write out (default: land)\n"
e2d20035 »
2012-04-20 Add options used and some stats to output database.
201 << " -r, --output-rings - Output rings to database file\n"
202 << " -s, --srs=EPSGCODE - Set SRS (4326 for WGS84 (default) or 3857)\n"
203 #ifdef EXPERIMENTAL
204 << " -S, --simplify=TOLERANCE - Simplify coastline with given tolerance\n"
205 #endif
206 << " -v, --verbose - Verbose output\n"
27821cb6 »
2012-04-24 Removed -O option from osmcoastline.
207 << "\n";
e2d20035 »
2012-04-20 Add options used and some stats to output database.
208 }
209
Something went wrong with that request. Please try again.