Skip to content

Commit f4da413

Browse files
author
Steve Hill
committed
This introduces 2 new commandline options: "-e <zoomlevel>" and "-o <dirty tile list output file>". So, specifying "-e 17 -o /tmp/dirty_tiles" when importing a delta will cause osm2pgsql to generate a list of all zoom level 17 tiles which the delta has made dirty and store it in /tmp/dirty_tiles. Proviso: for polygons, it currently takes a simplistic approach of drawing a bounding box around the whole polygon and marking every tile in the box as dirty. If the bounding box is large (over 30x30Km) the polygon is treated as a line instead, so only the perimeter will be marked as dirty (this is so that huge polygons don't expire vast numbers of tiles and is based on the assumption that we probably aren't going to shade the area of massive polygons). The dirty tile list is maintained in memory as a binary tree and dumped to disk at the end of the run.
1 parent 063e635 commit f4da413

8 files changed

Lines changed: 499 additions & 1 deletion

File tree

build_geometry.cpp

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,85 @@ void clear_wkts()
176176
areas.clear();
177177
}
178178

179+
static int coords2nodes(CoordinateSequence * coords, struct osmNode ** nodes) {
180+
size_t num_coords;
181+
size_t i;
182+
Coordinate coord;
183+
184+
num_coords = coords->getSize();
185+
*nodes = (struct osmNode *) malloc(num_coords * sizeof(struct osmNode));
186+
187+
for (i = 0; i < num_coords; i++) {
188+
coord = coords->getAt(i);
189+
(*nodes)[i].lon = coord.x;
190+
(*nodes)[i].lat = coord.y;
191+
}
192+
return num_coords;
193+
}
194+
195+
int parse_wkt(const char * wkt, struct osmNode *** xnodes, int ** xcount, int * polygon) {
196+
GeometryFactory gf;
197+
WKTReader reader(&gf);
198+
std::string wkt_string(wkt);
199+
Geometry * geometry;
200+
const Geometry * subgeometry;
201+
GeometryCollection * gc;
202+
CoordinateSequence * coords;
203+
size_t num_geometries;
204+
size_t i;
205+
206+
*polygon = 0;
207+
try {
208+
geometry = reader.read(wkt_string);
209+
switch (geometry->getGeometryTypeId()) {
210+
// Single geometries
211+
case geos::GEOS_POLYGON:
212+
// Drop through
213+
case geos::GEOS_LINEARRING:
214+
*polygon = 1;
215+
// Drop through
216+
case geos::GEOS_POINT:
217+
// Drop through
218+
case geos::GEOS_LINESTRING:
219+
*xnodes = (struct osmNode **) malloc(2 * sizeof(struct osmNode *));
220+
*xcount = (int *) malloc(sizeof(int));
221+
coords = geometry->getCoordinates();
222+
(*xcount)[0] = coords2nodes(coords, &((*xnodes)[0]));
223+
(*xnodes)[1] = NULL;
224+
delete coords;
225+
break;
226+
// Geometry collections
227+
case geos::GEOS_MULTIPOLYGON:
228+
*polygon = 1;
229+
// Drop through
230+
case geos::GEOS_MULTIPOINT:
231+
// Drop through
232+
case geos::GEOS_MULTILINESTRING:
233+
gc = (GeometryCollection *) geometry;
234+
num_geometries = gc->getNumGeometries();
235+
*xnodes = (struct osmNode **) malloc((num_geometries + 1) * sizeof(struct osmNode *));
236+
*xcount = (int *) malloc(num_geometries * sizeof(int));
237+
for (i = 0; i < num_geometries; i++) {
238+
subgeometry = gc->getGeometryN(i);
239+
coords = subgeometry->getCoordinates();
240+
(*xcount)[0] = coords2nodes(coords, &((*xnodes)[i]));
241+
delete coords;
242+
}
243+
(*xnodes)[i] = NULL;
244+
break;
245+
default:
246+
std::cerr << std::endl << "unexpected object type while processing PostGIS data" << std::endl;
247+
delete geometry;
248+
return -1;
249+
}
250+
delete geometry;
251+
} catch (...) {
252+
std::cerr << std::endl << "excepton caught parsing PostGIS data" << std::endl;
253+
return -1;
254+
}
255+
return 0;
256+
}
257+
179258
size_t build_geometry(int osm_id, struct osmNode **xnodes, int *xcount, int make_polygon) {
180259
size_t wkt_size = 0;
181260
std::auto_ptr<std::vector<Geometry*> > lines(new std::vector<Geometry*>);

build_geometry.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ extern "C" {
2929

3030
#include "osmtypes.h"
3131

32+
int parse_wkt(const char * wkt, struct osmNode *** xnodes, int ** xcount, int * polygon);
33+
3234
char *get_wkt_simple(struct osmNode *, int count, int polygon, double *area, double *int_x, double *int_y);
3335

3436
char* get_wkt(size_t index);

0 commit comments

Comments
 (0)