mirror of
https://github.com/felt/tippecanoe.git
synced 2026-11-27 19:01:18 +01:00
Compare commits
17
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c7649e39e5 | ||
|
|
caa91203b7 | ||
|
|
21f63a756f | ||
|
|
219f47e51c | ||
|
|
159b04fa8e | ||
|
|
f82a868e88 | ||
|
|
0170dd8bea | ||
|
|
baba6d382d | ||
|
|
3ffc04a0b2 | ||
|
|
9c4c95295f | ||
|
|
f9ec00d50d | ||
|
|
0a4f6fe546 | ||
|
|
72731a9fce | ||
|
|
30e5a5ce9b | ||
|
|
08f9d0d71d | ||
|
|
1afe03ed96 | ||
|
|
aaad2e3af8 |
@@ -4,18 +4,12 @@ on: [push]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ${{ matrix.os }}
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest]
|
||||
version: ['Release', 'Debug']
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Install dependencies (Ubuntu)
|
||||
if: runner.os == 'Linux'
|
||||
run: sudo apt-get install libsqlite3-dev
|
||||
- name: Install dependencies (macOS)
|
||||
if: runner.os == 'macOS'
|
||||
run: brew install sqlite3
|
||||
- run: sudo apt-get install libsqlite3-dev
|
||||
- run: uname -a; BUILDTYPE=${{ matrix.version }} make
|
||||
- run: make test
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
# 2.73.0
|
||||
|
||||
* Correctly clip features down to nothing when the clip region doesn't intersect the tile at all
|
||||
|
||||
# 2.72.0
|
||||
|
||||
* Add --clip-polygon-file and --feature-filter-file options to tippecanoe-overzoom
|
||||
|
||||
# 2.71.0
|
||||
|
||||
* Add --clip-bounding-box and --clip-polygon options to tippecanoe-overzoom
|
||||
|
||||
# 2.70.1
|
||||
|
||||
* Raise tippecanoe-decode limit on the size of individual tiles
|
||||
|
||||
@@ -59,7 +59,7 @@ C = $(wildcard *.c) $(wildcard *.cpp)
|
||||
INCLUDES = -I/usr/local/include -I. -Iclipper2/include
|
||||
LIBS = -L/usr/local/lib
|
||||
|
||||
tippecanoe: geojson.o jsonpull/jsonpull.o tile.o pool.o mbtiles.o geometry.o projection.o memfile.o mvt.o serial.o main.o platform.o text.o dirtiles.o pmtiles_file.o plugin.o read_json.o write_json.o geobuf.o flatgeobuf.o evaluator.o geocsv.o csv.o geojson-loop.o json_logger.o visvalingam.o compression.o clip.o sort.o attribute.o thread.o shared_borders.o clipper2/src/clipper.engine.o
|
||||
tippecanoe: geojson.o jsonpull/jsonpull.o tile.o pool.o mbtiles.o geometry.o projection.o memfile.o mvt.o serial.o main.o text.o dirtiles.o pmtiles_file.o plugin.o read_json.o write_json.o geobuf.o flatgeobuf.o evaluator.o geocsv.o csv.o geojson-loop.o json_logger.o visvalingam.o compression.o clip.o sort.o attribute.o thread.o shared_borders.o clipper2/src/clipper.engine.o
|
||||
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3 -lpthread
|
||||
|
||||
tippecanoe-enumerate: enumerate.o
|
||||
@@ -68,7 +68,7 @@ tippecanoe-enumerate: enumerate.o
|
||||
tippecanoe-decode: decode.o projection.o mvt.o write_json.o text.o jsonpull/jsonpull.o dirtiles.o pmtiles_file.o
|
||||
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3
|
||||
|
||||
tile-join: tile-join.o platform.o projection.o mbtiles.o mvt.o memfile.o dirtiles.o jsonpull/jsonpull.o text.o evaluator.o csv.o write_json.o pmtiles_file.o clip.o attribute.o thread.o read_json.o clipper2/src/clipper.engine.o
|
||||
tile-join: tile-join.o projection.o mbtiles.o mvt.o memfile.o dirtiles.o jsonpull/jsonpull.o text.o evaluator.o csv.o write_json.o pmtiles_file.o clip.o attribute.o thread.o read_json.o clipper2/src/clipper.engine.o
|
||||
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3 -lpthread
|
||||
|
||||
tippecanoe-json-tool: jsontool.o jsonpull/jsonpull.o csv.o text.o geojson-loop.o
|
||||
@@ -326,11 +326,6 @@ overzoom-test: tippecanoe-overzoom
|
||||
./tippecanoe-decode tests/pbf/0-0-0-pop-expr.pbf 0 0 0 > tests/pbf/0-0-0-pop-expr.pbf.json.check
|
||||
cmp tests/pbf/0-0-0-pop-expr.pbf.json.check tests/pbf/0-0-0-pop-expr.pbf.json
|
||||
rm tests/pbf/0-0-0-pop-expr.pbf tests/pbf/0-0-0-pop-expr.pbf.json.check
|
||||
# Same filter test, but reading the filter from a file
|
||||
./tippecanoe-overzoom -y NAME -J tests/pbf/scalerank-0-filter.json -o tests/pbf/0-0-0-pop-expr.pbf tests/pbf/0-0-0-pop.pbf 0/0/0 0/0/0
|
||||
./tippecanoe-decode tests/pbf/0-0-0-pop-expr.pbf 0 0 0 > tests/pbf/0-0-0-pop-expr.pbf.json.check
|
||||
cmp tests/pbf/0-0-0-pop-expr.pbf.json.check tests/pbf/0-0-0-pop-expr.pbf.json
|
||||
rm tests/pbf/0-0-0-pop-expr.pbf tests/pbf/0-0-0-pop-expr.pbf.json.check
|
||||
# Filtering with multiplier
|
||||
# 243 features in the source tile tests/pbf/0-0-0-pop.pbf
|
||||
# 8 features survive into the output, from 9 clusters of 30
|
||||
@@ -382,16 +377,6 @@ overzoom-test: tippecanoe-overzoom
|
||||
./tippecanoe-decode tests/pbf/bin-11-327-791-ids.pbf.out 11 327 791 > tests/pbf/bin-11-327-791-ids.pbf.out.json.check
|
||||
cmp tests/pbf/bin-11-327-791-ids.pbf.out.json.check tests/pbf/bin-11-327-791-ids.pbf.out.json
|
||||
rm tests/pbf/bin-11-327-791-ids.pbf.out.json.check tests/pbf/bin-11-327-791-ids.pbf.out
|
||||
# Binning by id, clipping by polygon
|
||||
./tippecanoe-overzoom -o tests/pbf/bin-11-327-791-ids-clip.pbf.out --clip-polygon='{"coordinates":[[[-122.4527379,37.8128815],[-122.4598853,37.7834743],[-122.4280914,37.7959397],[-122.4527379,37.8128815]]],"type":"Polygon"}' --assign-to-bins tests/pbf/sf-zips.json --bin-by-id-list bin-ids tests/pbf/yearbuilt.pbf 11/327/791 11/327/791
|
||||
./tippecanoe-decode tests/pbf/bin-11-327-791-ids-clip.pbf.out 11 327 791 > tests/pbf/bin-11-327-791-ids-clip.pbf.out.json.check
|
||||
cmp tests/pbf/bin-11-327-791-ids-clip.pbf.out.json.check tests/pbf/bin-11-327-791-ids-clip.pbf.out.json
|
||||
rm tests/pbf/bin-11-327-791-ids-clip.pbf.out.json.check tests/pbf/bin-11-327-791-ids-clip.pbf.out
|
||||
# Binning by id, clipping by polygon from file
|
||||
./tippecanoe-overzoom -o tests/pbf/bin-11-327-791-ids-clip.pbf.out --clip-polygon-file=tests/pbf/clip-poly.json --assign-to-bins tests/pbf/sf-zips.json --bin-by-id-list bin-ids tests/pbf/yearbuilt.pbf 11/327/791 11/327/791
|
||||
./tippecanoe-decode tests/pbf/bin-11-327-791-ids-clip.pbf.out 11 327 791 > tests/pbf/bin-11-327-791-ids-clip.pbf.out.json.check
|
||||
cmp tests/pbf/bin-11-327-791-ids-clip.pbf.out.json.check tests/pbf/bin-11-327-791-ids-clip.pbf.out.json
|
||||
rm tests/pbf/bin-11-327-791-ids-clip.pbf.out.json.check tests/pbf/bin-11-327-791-ids-clip.pbf.out
|
||||
# Binning by id, attribute stripping
|
||||
# Note that it still works even if we exclude the ID that we are binning by
|
||||
./tippecanoe-overzoom -yZCTA5CE10 -ytippecanoe:count -o tests/pbf/bin-11-327-791-ids-zip.pbf.out --assign-to-bins tests/pbf/sf-zips.json --bin-by-id-list bin-ids tests/pbf/yearbuilt.pbf 11/327/791 11/327/791
|
||||
@@ -434,15 +419,6 @@ overzoom-test: tippecanoe-overzoom
|
||||
./tippecanoe-decode tests/pbf/places-1-1-0-clip.pbf 1 1 0 > tests/pbf/places-1-1-0-clip.json.check
|
||||
cmp tests/pbf/places-1-1-0-clip.json.check tests/pbf/places-1-1-0-clip.json
|
||||
rm tests/pbf/places-1-1-0-clip.pbf tests/pbf/places-1-1-0-clip.json.check
|
||||
# Polygon clipping, with excessively large clip region
|
||||
./tippecanoe-overzoom -b10 -o tests/pbf/countries-8-135-86-bigclip.pbf --clip-polygon "`cat tests/pbf/region.json`" tests/pbf/countries-1-1-0.pbf 1/1/0 8/135/86
|
||||
./tippecanoe-decode tests/pbf/countries-8-135-86-bigclip.pbf 8 135 86 > tests/pbf/countries-8-135-86-bigclip.json.check
|
||||
cmp tests/pbf/countries-8-135-86-bigclip.json.check tests/pbf/countries-8-135-86-bigclip.json
|
||||
rm tests/pbf/countries-8-135-86-bigclip.pbf tests/pbf/countries-8-135-86-bigclip.json.check
|
||||
# Clip region that does not intersect with the tile
|
||||
./tippecanoe-overzoom -o tests/pbf/squirrels-13-2413-3077-clip.pbf --clip-polygon-file tests/pbf/squirrels-clip.json tests/pbf/squirrels-13-2413-3077.pbf 13/2413/3077 13/2413/3077
|
||||
cmp tests/pbf/squirrels-13-2413-3077-clip.pbf /dev/null # clipped away
|
||||
rm tests/pbf/squirrels-13-2413-3077-clip.pbf
|
||||
|
||||
join-test: tippecanoe tippecanoe-decode tile-join
|
||||
./tippecanoe -q -f -z12 -o tests/join-population/tabblock_06001420.mbtiles -YALAND10:'Land area' -L'{"file": "tests/join-population/tabblock_06001420.json", "description": "population"}'
|
||||
|
||||
@@ -387,7 +387,8 @@ drawvec clean_or_clip_poly(drawvec &geom, int z, int buffer, bool clip, bool try
|
||||
return ret;
|
||||
}
|
||||
|
||||
drawvec clip_poly_poly(drawvec const &geom, drawvec const &bounds) {
|
||||
drawvec clip_poly(drawvec &geom, drawvec const &bounds) {
|
||||
geom = remove_noop(geom, VT_POLYGON, 0);
|
||||
mapbox::geometry::multi_polygon<long long> result;
|
||||
|
||||
{
|
||||
@@ -449,7 +450,7 @@ drawvec clip_poly_poly(drawvec const &geom, drawvec const &bounds) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
drawvec clip_point_poly(drawvec const &geom, drawvec const &bounds) {
|
||||
drawvec clip_point_poly(drawvec &geom, drawvec const &bounds) {
|
||||
drawvec out;
|
||||
for (auto const &p : geom) {
|
||||
if (pnpoly_mp(bounds, p.x, p.y)) {
|
||||
@@ -459,51 +460,6 @@ drawvec clip_point_poly(drawvec const &geom, drawvec const &bounds) {
|
||||
return out;
|
||||
}
|
||||
|
||||
static Clipper2Lib::Paths64 geom_to_clipper(drawvec const &geom) {
|
||||
Clipper2Lib::Paths64 subject;
|
||||
|
||||
for (size_t i = 0; i < geom.size(); i++) {
|
||||
if (geom[i].op == VT_MOVETO) {
|
||||
Clipper2Lib::Path64 path({{geom[i].x, geom[i].y}});
|
||||
size_t j;
|
||||
for (j = i + 1; j < geom.size(); j++) {
|
||||
if (geom[j].op != VT_LINETO) {
|
||||
break;
|
||||
}
|
||||
path.emplace_back(geom[j].x, geom[j].y);
|
||||
}
|
||||
subject.push_back(path);
|
||||
}
|
||||
}
|
||||
|
||||
return subject;
|
||||
}
|
||||
|
||||
static void clipper_to_geom(Clipper2Lib::Paths64 const &geom, drawvec &out) {
|
||||
for (auto const &ring : geom) {
|
||||
for (size_t i = 0; i < ring.size(); i++) {
|
||||
out.emplace_back(i == 0 ? VT_MOVETO : VT_LINETO, ring[i].x, ring[i].y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
drawvec clip_lines_poly(drawvec const &geom, drawvec const ®ion) {
|
||||
Clipper2Lib::Paths64 subject = geom_to_clipper(geom);
|
||||
Clipper2Lib::Paths64 clip = geom_to_clipper(region);
|
||||
|
||||
Clipper2Lib::Clipper64 clipper;
|
||||
clipper.AddOpenSubject(subject);
|
||||
clipper.AddClip(clip);
|
||||
|
||||
Clipper2Lib::Paths64 solution, open_solution;
|
||||
clipper.Execute(Clipper2Lib::ClipType::Intersection, Clipper2Lib::FillRule::Positive, solution, open_solution);
|
||||
|
||||
drawvec out;
|
||||
clipper_to_geom(solution, out);
|
||||
clipper_to_geom(open_solution, out);
|
||||
return out;
|
||||
}
|
||||
|
||||
void to_tile_scale(drawvec &geom, int z, int detail) {
|
||||
if (32 - detail - z < 0) {
|
||||
for (size_t i = 0; i < geom.size(); i++) {
|
||||
@@ -1227,7 +1183,7 @@ clipbbox parse_clip_poly(std::string arg) {
|
||||
exit(EXIT_ARGS);
|
||||
}
|
||||
|
||||
std::pair<int, drawvec> parsed_geometry = parse_geometry(j, jp, j, 0, 0, 0, 1LL << 32, false, false);
|
||||
std::pair<int, drawvec> parsed_geometry = parse_geometry(j, jp, j, 0, 0, 0, 1LL << 32, false);
|
||||
json_end(jp);
|
||||
|
||||
clipbbox out;
|
||||
@@ -1536,34 +1492,19 @@ static bool feature_out(std::vector<tile_feature> const &features, mvt_layer &ou
|
||||
long long dy = (long long) ny << (32 - nz);
|
||||
double scale = (double) outlayer.extent / (1LL << (32 - nz));
|
||||
|
||||
for (auto const &c_world : clipbboxes) {
|
||||
clipbbox c = c_world;
|
||||
|
||||
c.minx = std::llround((c_world.minx - dx) * scale);
|
||||
c.miny = std::llround((c_world.miny - dy) * scale);
|
||||
c.maxx = std::llround((c_world.maxx - dx) * scale);
|
||||
c.maxy = std::llround((c_world.maxy - dy) * scale);
|
||||
|
||||
for (auto &p : c.dv) {
|
||||
p.x = std::llround((p.x - dx) * scale);
|
||||
p.y = std::llround((p.y - dy) * scale);
|
||||
}
|
||||
for (auto const &c : clipbboxes) {
|
||||
clipbbox local;
|
||||
local.minx = std::llround((c.minx - dx) * scale);
|
||||
local.miny = std::llround((c.miny - dy) * scale);
|
||||
local.maxx = std::llround((c.maxx - dx) * scale);
|
||||
local.maxy = std::llround((c.maxy - dy) * scale);
|
||||
|
||||
if (t == VT_POLYGON) {
|
||||
geom = simple_clip_poly(geom, c.minx, c.miny, c.maxx, c.maxy, false);
|
||||
if (c.dv.size() > 0 && geom.size() > 0) {
|
||||
geom = clip_poly_poly(geom, c.dv);
|
||||
}
|
||||
geom = simple_clip_poly(geom, local.minx, local.miny, local.maxx, local.maxy, false);
|
||||
} else if (t == VT_LINE) {
|
||||
geom = clip_lines(geom, c.minx, c.miny, c.maxx, c.maxy);
|
||||
if (c.dv.size() > 0 && geom.size() > 0) {
|
||||
geom = clip_lines_poly(geom, c.dv);
|
||||
}
|
||||
geom = clip_lines(geom, local.minx, local.miny, local.maxx, local.maxy);
|
||||
} else if (t == VT_POINT) {
|
||||
geom = clip_point(geom, c.minx, c.miny, c.maxx, c.maxy);
|
||||
if (c.dv.size() > 0 && geom.size() > 0) {
|
||||
geom = clip_point_poly(geom, c.dv);
|
||||
}
|
||||
geom = clip_point(geom, local.minx, local.miny, local.maxx, local.maxy);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1999,6 +1940,51 @@ mvt_tile assign_to_bins(mvt_tile &features,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static Clipper2Lib::Paths64 geom_to_clipper(drawvec const &geom) {
|
||||
Clipper2Lib::Paths64 subject;
|
||||
|
||||
for (size_t i = 0; i < geom.size(); i++) {
|
||||
if (geom[i].op == VT_MOVETO) {
|
||||
Clipper2Lib::Path64 path({{geom[i].x, geom[i].y}});
|
||||
size_t j;
|
||||
for (j = i + 1; j < geom.size(); j++) {
|
||||
if (geom[j].op != VT_LINETO) {
|
||||
break;
|
||||
}
|
||||
path.emplace_back(geom[j].x, geom[j].y);
|
||||
}
|
||||
subject.push_back(path);
|
||||
}
|
||||
}
|
||||
|
||||
return subject;
|
||||
}
|
||||
|
||||
static void clipper_to_geom(Clipper2Lib::Paths64 const &geom, drawvec &out) {
|
||||
for (auto const &ring : geom) {
|
||||
for (size_t i = 0; i < ring.size(); i++) {
|
||||
out.emplace_back(i == 0 ? VT_MOVETO : VT_LINETO, ring[i].x, ring[i].y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
drawvec clip_lines(drawvec const &geom, drawvec const ®ion) {
|
||||
Clipper2Lib::Paths64 subject = geom_to_clipper(geom);
|
||||
Clipper2Lib::Paths64 clip = geom_to_clipper(region);
|
||||
|
||||
Clipper2Lib::Clipper64 clipper;
|
||||
clipper.AddOpenSubject(subject);
|
||||
clipper.AddClip(clip);
|
||||
|
||||
Clipper2Lib::Paths64 solution, open_solution;
|
||||
clipper.Execute(Clipper2Lib::ClipType::Intersection, Clipper2Lib::FillRule::Positive, solution, open_solution);
|
||||
|
||||
drawvec out;
|
||||
clipper_to_geom(solution, out);
|
||||
clipper_to_geom(open_solution, out);
|
||||
return out;
|
||||
}
|
||||
|
||||
std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int ny,
|
||||
int detail_or_unspecified, int buffer,
|
||||
std::set<std::string> const &keep,
|
||||
@@ -2080,12 +2066,12 @@ std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int
|
||||
if (t == VT_POLYGON) {
|
||||
geom = simple_clip_poly(geom, c.minx, c.miny, c.maxx, c.maxy, false);
|
||||
if (c.dv.size() > 0 && geom.size() > 0) {
|
||||
geom = clip_poly_poly(geom, c.dv);
|
||||
geom = clip_poly(geom, c.dv);
|
||||
}
|
||||
} else if (t == VT_LINE) {
|
||||
geom = clip_lines(geom, c.minx, c.miny, c.maxx, c.maxy);
|
||||
if (c.dv.size() > 0 && geom.size() > 0) {
|
||||
geom = clip_lines_poly(geom, c.dv);
|
||||
geom = clip_lines(geom, c.dv);
|
||||
}
|
||||
} else if (t == VT_POINT) {
|
||||
geom = clip_point(geom, c.minx, c.miny, c.maxx, c.maxy);
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
#include "clipper2/clipper.core.h"
|
||||
#include "clipper2/clipper.engine.h"
|
||||
#include "clipper2/clipper.offset.h"
|
||||
#include "clipper2/clipper.minkowski.h"
|
||||
#include "clipper2/clipper.rectclip.h"
|
||||
|
||||
namespace Clipper2Lib {
|
||||
|
||||
@@ -129,6 +132,35 @@ namespace Clipper2Lib {
|
||||
return BooleanOp(ClipType::Xor, fillrule, subjects, clips, decimal_prec);
|
||||
}
|
||||
|
||||
inline Paths64 InflatePaths(const Paths64& paths, double delta,
|
||||
JoinType jt, EndType et, double miter_limit = 2.0,
|
||||
double arc_tolerance = 0.0)
|
||||
{
|
||||
if (!delta) return paths;
|
||||
ClipperOffset clip_offset(miter_limit, arc_tolerance);
|
||||
clip_offset.AddPaths(paths, jt, et);
|
||||
Paths64 solution;
|
||||
clip_offset.Execute(delta, solution);
|
||||
return solution;
|
||||
}
|
||||
|
||||
inline PathsD InflatePaths(const PathsD& paths, double delta,
|
||||
JoinType jt, EndType et, double miter_limit = 2.0,
|
||||
int precision = 2, double arc_tolerance = 0.0)
|
||||
{
|
||||
int error_code = 0;
|
||||
CheckPrecisionRange(precision, error_code);
|
||||
if (!delta) return paths;
|
||||
if (error_code) return PathsD();
|
||||
const double scale = std::pow(10, precision);
|
||||
ClipperOffset clip_offset(miter_limit, arc_tolerance);
|
||||
clip_offset.AddPaths(ScalePaths<int64_t,double>(paths, scale, error_code), jt, et);
|
||||
if (error_code) return PathsD();
|
||||
Paths64 solution;
|
||||
clip_offset.Execute(delta * scale, solution);
|
||||
return ScalePaths<double, int64_t>(solution, 1 / scale, error_code);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline Path<T> TranslatePath(const Path<T>& path, T dx, T dy)
|
||||
{
|
||||
@@ -169,6 +201,72 @@ namespace Clipper2Lib {
|
||||
return TranslatePaths<double>(paths, dx, dy);
|
||||
}
|
||||
|
||||
inline Paths64 RectClip(const Rect64& rect, const Paths64& paths)
|
||||
{
|
||||
if (rect.IsEmpty() || paths.empty()) return Paths64();
|
||||
RectClip64 rc(rect);
|
||||
return rc.Execute(paths);
|
||||
}
|
||||
|
||||
inline Paths64 RectClip(const Rect64& rect, const Path64& path)
|
||||
{
|
||||
if (rect.IsEmpty() || path.empty()) return Paths64();
|
||||
RectClip64 rc(rect);
|
||||
return rc.Execute(Paths64{ path });
|
||||
}
|
||||
|
||||
inline PathsD RectClip(const RectD& rect, const PathsD& paths, int precision = 2)
|
||||
{
|
||||
if (rect.IsEmpty() || paths.empty()) return PathsD();
|
||||
int error_code = 0;
|
||||
CheckPrecisionRange(precision, error_code);
|
||||
if (error_code) return PathsD();
|
||||
const double scale = std::pow(10, precision);
|
||||
Rect64 r = ScaleRect<int64_t, double>(rect, scale);
|
||||
RectClip64 rc(r);
|
||||
Paths64 pp = ScalePaths<int64_t, double>(paths, scale, error_code);
|
||||
if (error_code) return PathsD(); // ie: error_code result is lost
|
||||
return ScalePaths<double, int64_t>(
|
||||
rc.Execute(pp), 1 / scale, error_code);
|
||||
}
|
||||
|
||||
inline PathsD RectClip(const RectD& rect, const PathD& path, int precision = 2)
|
||||
{
|
||||
return RectClip(rect, PathsD{ path }, precision);
|
||||
}
|
||||
|
||||
inline Paths64 RectClipLines(const Rect64& rect, const Paths64& lines)
|
||||
{
|
||||
if (rect.IsEmpty() || lines.empty()) return Paths64();
|
||||
RectClipLines64 rcl(rect);
|
||||
return rcl.Execute(lines);
|
||||
}
|
||||
|
||||
inline Paths64 RectClipLines(const Rect64& rect, const Path64& line)
|
||||
{
|
||||
return RectClipLines(rect, Paths64{ line });
|
||||
}
|
||||
|
||||
inline PathsD RectClipLines(const RectD& rect, const PathsD& lines, int precision = 2)
|
||||
{
|
||||
if (rect.IsEmpty() || lines.empty()) return PathsD();
|
||||
int error_code = 0;
|
||||
CheckPrecisionRange(precision, error_code);
|
||||
if (error_code) return PathsD();
|
||||
const double scale = std::pow(10, precision);
|
||||
Rect64 r = ScaleRect<int64_t, double>(rect, scale);
|
||||
RectClipLines64 rcl(r);
|
||||
Paths64 p = ScalePaths<int64_t, double>(lines, scale, error_code);
|
||||
if (error_code) return PathsD();
|
||||
p = rcl.Execute(p);
|
||||
return ScalePaths<double, int64_t>(p, 1 / scale, error_code);
|
||||
}
|
||||
|
||||
inline PathsD RectClipLines(const RectD& rect, const PathD& line, int precision = 2)
|
||||
{
|
||||
return RectClipLines(rect, PathsD{ line }, precision);
|
||||
}
|
||||
|
||||
namespace details
|
||||
{
|
||||
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
/*******************************************************************************
|
||||
* Author : Angus Johnson *
|
||||
* Date : 1 November 2023 *
|
||||
* Website : http://www.angusj.com *
|
||||
* Copyright : Angus Johnson 2010-2023 *
|
||||
* Purpose : Minkowski Sum and Difference *
|
||||
* License : http://www.boost.org/LICENSE_1_0.txt *
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef CLIPPER_MINKOWSKI_H
|
||||
#define CLIPPER_MINKOWSKI_H
|
||||
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "clipper2/clipper.core.h"
|
||||
|
||||
namespace Clipper2Lib
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
inline Paths64 Minkowski(const Path64& pattern, const Path64& path, bool isSum, bool isClosed)
|
||||
{
|
||||
size_t delta = isClosed ? 0 : 1;
|
||||
size_t patLen = pattern.size(), pathLen = path.size();
|
||||
if (patLen == 0 || pathLen == 0) return Paths64();
|
||||
Paths64 tmp;
|
||||
tmp.reserve(pathLen);
|
||||
|
||||
if (isSum)
|
||||
{
|
||||
for (const Point64& p : path)
|
||||
{
|
||||
Path64 path2(pattern.size());
|
||||
std::transform(pattern.cbegin(), pattern.cend(),
|
||||
path2.begin(), [p](const Point64& pt2) {return p + pt2; });
|
||||
tmp.push_back(path2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (const Point64& p : path)
|
||||
{
|
||||
Path64 path2(pattern.size());
|
||||
std::transform(pattern.cbegin(), pattern.cend(),
|
||||
path2.begin(), [p](const Point64& pt2) {return p - pt2; });
|
||||
tmp.push_back(path2);
|
||||
}
|
||||
}
|
||||
|
||||
Paths64 result;
|
||||
result.reserve((pathLen - delta) * patLen);
|
||||
size_t g = isClosed ? pathLen - 1 : 0;
|
||||
for (size_t h = patLen - 1, i = delta; i < pathLen; ++i)
|
||||
{
|
||||
for (size_t j = 0; j < patLen; j++)
|
||||
{
|
||||
Path64 quad;
|
||||
quad.reserve(4);
|
||||
{
|
||||
quad.push_back(tmp[g][h]);
|
||||
quad.push_back(tmp[i][h]);
|
||||
quad.push_back(tmp[i][j]);
|
||||
quad.push_back(tmp[g][j]);
|
||||
};
|
||||
if (!IsPositive(quad))
|
||||
std::reverse(quad.begin(), quad.end());
|
||||
result.push_back(quad);
|
||||
h = j;
|
||||
}
|
||||
g = i;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Paths64 Union(const Paths64& subjects, FillRule fillrule)
|
||||
{
|
||||
Paths64 result;
|
||||
Clipper64 clipper;
|
||||
clipper.AddSubject(subjects);
|
||||
clipper.Execute(ClipType::Union, fillrule, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
inline Paths64 MinkowskiSum(const Path64& pattern, const Path64& path, bool isClosed)
|
||||
{
|
||||
return detail::Union(detail::Minkowski(pattern, path, true, isClosed), FillRule::NonZero);
|
||||
}
|
||||
|
||||
inline PathsD MinkowskiSum(const PathD& pattern, const PathD& path, bool isClosed, int decimalPlaces = 2)
|
||||
{
|
||||
int error_code = 0;
|
||||
double scale = pow(10, decimalPlaces);
|
||||
Path64 pat64 = ScalePath<int64_t, double>(pattern, scale, error_code);
|
||||
Path64 path64 = ScalePath<int64_t, double>(path, scale, error_code);
|
||||
Paths64 tmp = detail::Union(detail::Minkowski(pat64, path64, true, isClosed), FillRule::NonZero);
|
||||
return ScalePaths<double, int64_t>(tmp, 1 / scale, error_code);
|
||||
}
|
||||
|
||||
inline Paths64 MinkowskiDiff(const Path64& pattern, const Path64& path, bool isClosed)
|
||||
{
|
||||
return detail::Union(detail::Minkowski(pattern, path, false, isClosed), FillRule::NonZero);
|
||||
}
|
||||
|
||||
inline PathsD MinkowskiDiff(const PathD& pattern, const PathD& path, bool isClosed, int decimalPlaces = 2)
|
||||
{
|
||||
int error_code = 0;
|
||||
double scale = pow(10, decimalPlaces);
|
||||
Path64 pat64 = ScalePath<int64_t, double>(pattern, scale, error_code);
|
||||
Path64 path64 = ScalePath<int64_t, double>(path, scale, error_code);
|
||||
Paths64 tmp = detail::Union(detail::Minkowski(pat64, path64, false, isClosed), FillRule::NonZero);
|
||||
return ScalePaths<double, int64_t>(tmp, 1 / scale, error_code);
|
||||
}
|
||||
|
||||
} // Clipper2Lib namespace
|
||||
|
||||
#endif // CLIPPER_MINKOWSKI_H
|
||||
@@ -0,0 +1,124 @@
|
||||
/*******************************************************************************
|
||||
* Author : Angus Johnson *
|
||||
* Date : 24 March 2024 *
|
||||
* Website : http://www.angusj.com *
|
||||
* Copyright : Angus Johnson 2010-2024 *
|
||||
* Purpose : Path Offset (Inflate/Shrink) *
|
||||
* License : http://www.boost.org/LICENSE_1_0.txt *
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef CLIPPER_OFFSET_H_
|
||||
#define CLIPPER_OFFSET_H_
|
||||
|
||||
#include "clipper.core.h"
|
||||
#include "clipper.engine.h"
|
||||
|
||||
namespace Clipper2Lib {
|
||||
|
||||
enum class JoinType { Square, Bevel, Round, Miter };
|
||||
//Square : Joins are 'squared' at exactly the offset distance (more complex code)
|
||||
//Bevel : Similar to Square, but the offset distance varies with angle (simple code & faster)
|
||||
|
||||
enum class EndType {Polygon, Joined, Butt, Square, Round};
|
||||
//Butt : offsets both sides of a path, with square blunt ends
|
||||
//Square : offsets both sides of a path, with square extended ends
|
||||
//Round : offsets both sides of a path, with round extended ends
|
||||
//Joined : offsets both sides of a path, with joined ends
|
||||
//Polygon: offsets only one side of a closed path
|
||||
|
||||
typedef std::function<double(const Path64& path, const PathD& path_normals, size_t curr_idx, size_t prev_idx)> DeltaCallback64;
|
||||
|
||||
class ClipperOffset {
|
||||
private:
|
||||
|
||||
class Group {
|
||||
public:
|
||||
Paths64 paths_in;
|
||||
std::optional<size_t> lowest_path_idx{};
|
||||
bool is_reversed = false;
|
||||
JoinType join_type;
|
||||
EndType end_type;
|
||||
Group(const Paths64& _paths, JoinType _join_type, EndType _end_type);
|
||||
};
|
||||
|
||||
int error_code_ = 0;
|
||||
double delta_ = 0.0;
|
||||
double group_delta_ = 0.0;
|
||||
double temp_lim_ = 0.0;
|
||||
double steps_per_rad_ = 0.0;
|
||||
double step_sin_ = 0.0;
|
||||
double step_cos_ = 0.0;
|
||||
PathD norms;
|
||||
Path64 path_out;
|
||||
Paths64* solution = nullptr;
|
||||
PolyTree64* solution_tree = nullptr;
|
||||
std::vector<Group> groups_;
|
||||
JoinType join_type_ = JoinType::Bevel;
|
||||
EndType end_type_ = EndType::Polygon;
|
||||
|
||||
double miter_limit_ = 0.0;
|
||||
double arc_tolerance_ = 0.0;
|
||||
bool preserve_collinear_ = false;
|
||||
bool reverse_solution_ = false;
|
||||
|
||||
#ifdef USINGZ
|
||||
ZCallback64 zCallback64_ = nullptr;
|
||||
void ZCB(const Point64& bot1, const Point64& top1,
|
||||
const Point64& bot2, const Point64& top2, Point64& ip);
|
||||
#endif
|
||||
DeltaCallback64 deltaCallback64_ = nullptr;
|
||||
size_t CalcSolutionCapacity();
|
||||
bool CheckReverseOrientation();
|
||||
void DoBevel(const Path64& path, size_t j, size_t k);
|
||||
void DoSquare(const Path64& path, size_t j, size_t k);
|
||||
void DoMiter(const Path64& path, size_t j, size_t k, double cos_a);
|
||||
void DoRound(const Path64& path, size_t j, size_t k, double angle);
|
||||
void BuildNormals(const Path64& path);
|
||||
void OffsetPolygon(Group& group, const Path64& path);
|
||||
void OffsetOpenJoined(Group& group, const Path64& path);
|
||||
void OffsetOpenPath(Group& group, const Path64& path);
|
||||
void OffsetPoint(Group& group, const Path64& path, size_t j, size_t k);
|
||||
void DoGroupOffset(Group &group);
|
||||
void ExecuteInternal(double delta);
|
||||
public:
|
||||
explicit ClipperOffset(double miter_limit = 2.0,
|
||||
double arc_tolerance = 0.0,
|
||||
bool preserve_collinear = false,
|
||||
bool reverse_solution = false) :
|
||||
miter_limit_(miter_limit), arc_tolerance_(arc_tolerance),
|
||||
preserve_collinear_(preserve_collinear),
|
||||
reverse_solution_(reverse_solution) { };
|
||||
|
||||
~ClipperOffset() { Clear(); };
|
||||
|
||||
int ErrorCode() const { return error_code_; };
|
||||
void AddPath(const Path64& path, JoinType jt_, EndType et_);
|
||||
void AddPaths(const Paths64& paths, JoinType jt_, EndType et_);
|
||||
void Clear() { groups_.clear(); norms.clear(); };
|
||||
|
||||
void Execute(double delta, Paths64& paths);
|
||||
void Execute(double delta, PolyTree64& polytree);
|
||||
void Execute(DeltaCallback64 delta_cb, Paths64& paths);
|
||||
|
||||
double MiterLimit() const { return miter_limit_; }
|
||||
void MiterLimit(double miter_limit) { miter_limit_ = miter_limit; }
|
||||
|
||||
//ArcTolerance: needed for rounded offsets (See offset_triginometry2.svg)
|
||||
double ArcTolerance() const { return arc_tolerance_; }
|
||||
void ArcTolerance(double arc_tolerance) { arc_tolerance_ = arc_tolerance; }
|
||||
|
||||
bool PreserveCollinear() const { return preserve_collinear_; }
|
||||
void PreserveCollinear(bool preserve_collinear){preserve_collinear_ = preserve_collinear;}
|
||||
|
||||
bool ReverseSolution() const { return reverse_solution_; }
|
||||
void ReverseSolution(bool reverse_solution) {reverse_solution_ = reverse_solution;}
|
||||
|
||||
#ifdef USINGZ
|
||||
void SetZCallback(ZCallback64 cb) { zCallback64_ = cb; }
|
||||
#endif
|
||||
void SetDeltaCallback(DeltaCallback64 cb) { deltaCallback64_ = cb; }
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif /* CLIPPER_OFFSET_H_ */
|
||||
@@ -0,0 +1,82 @@
|
||||
/*******************************************************************************
|
||||
* Author : Angus Johnson *
|
||||
* Date : 5 July 2024 *
|
||||
* Website : http://www.angusj.com *
|
||||
* Copyright : Angus Johnson 2010-2024 *
|
||||
* Purpose : FAST rectangular clipping *
|
||||
* License : http://www.boost.org/LICENSE_1_0.txt *
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef CLIPPER_RECTCLIP_H
|
||||
#define CLIPPER_RECTCLIP_H
|
||||
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
#include "clipper2/clipper.core.h"
|
||||
|
||||
namespace Clipper2Lib
|
||||
{
|
||||
|
||||
// Location: the order is important here, see StartLocsIsClockwise()
|
||||
enum class Location { Left, Top, Right, Bottom, Inside };
|
||||
|
||||
class OutPt2;
|
||||
typedef std::vector<OutPt2*> OutPt2List;
|
||||
|
||||
class OutPt2 {
|
||||
public:
|
||||
Point64 pt;
|
||||
size_t owner_idx = 0;
|
||||
OutPt2List* edge = nullptr;
|
||||
OutPt2* next = nullptr;
|
||||
OutPt2* prev = nullptr;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// RectClip64
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class RectClip64 {
|
||||
private:
|
||||
void ExecuteInternal(const Path64& path);
|
||||
Path64 GetPath(OutPt2*& op);
|
||||
protected:
|
||||
const Rect64 rect_;
|
||||
const Path64 rect_as_path_;
|
||||
const Point64 rect_mp_;
|
||||
Rect64 path_bounds_;
|
||||
std::deque<OutPt2> op_container_;
|
||||
OutPt2List results_; // each path can be broken into multiples
|
||||
OutPt2List edges_[8]; // clockwise and counter-clockwise
|
||||
std::vector<Location> start_locs_;
|
||||
void CheckEdges();
|
||||
void TidyEdges(size_t idx, OutPt2List& cw, OutPt2List& ccw);
|
||||
void GetNextLocation(const Path64& path,
|
||||
Location& loc, size_t& i, size_t highI);
|
||||
OutPt2* Add(Point64 pt, bool start_new = false);
|
||||
void AddCorner(Location prev, Location curr);
|
||||
void AddCorner(Location& loc, bool isClockwise);
|
||||
public:
|
||||
explicit RectClip64(const Rect64& rect) :
|
||||
rect_(rect),
|
||||
rect_as_path_(rect.AsPath()),
|
||||
rect_mp_(rect.MidPoint()) {}
|
||||
Paths64 Execute(const Paths64& paths);
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// RectClipLines64
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class RectClipLines64 : public RectClip64 {
|
||||
private:
|
||||
void ExecuteInternal(const Path64& path);
|
||||
Path64 GetPath(OutPt2*& op);
|
||||
public:
|
||||
explicit RectClipLines64(const Rect64& rect) : RectClip64(rect) {};
|
||||
Paths64 Execute(const Paths64& paths);
|
||||
};
|
||||
|
||||
} // Clipper2Lib namespace
|
||||
#endif // CLIPPER_RECTCLIP_H
|
||||
@@ -102,10 +102,6 @@ int pnpoly(const drawvec &vert, size_t start, size_t nvert, long long testx, lon
|
||||
bool pnpoly_mp(drawvec const &geom, long long x, long long y);
|
||||
double distance_from_line(long long point_x, long long point_y, long long segA_x, long long segA_y, long long segB_x, long long segB_y);
|
||||
|
||||
drawvec clip_poly_poly(drawvec const &geom, drawvec const &bounds);
|
||||
drawvec clip_lines_poly(drawvec const &geom, drawvec const &bounds);
|
||||
drawvec clip_point_poly(drawvec const &geom, drawvec const &bounds);
|
||||
|
||||
struct input_tile {
|
||||
std::string tile;
|
||||
int z;
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <limits.h>
|
||||
#include <sqlite3.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/resource.h>
|
||||
#include <pthread.h>
|
||||
#include <getopt.h>
|
||||
#include <signal.h>
|
||||
@@ -66,7 +67,6 @@
|
||||
#include "sort.hpp"
|
||||
#include "attribute.hpp"
|
||||
#include "thread.hpp"
|
||||
#include "platform.hpp"
|
||||
|
||||
static int low_detail = 12;
|
||||
static int full_detail = -1;
|
||||
@@ -187,7 +187,7 @@ void init_cpus() {
|
||||
if (TIPPECANOE_MAX_THREADS != NULL) {
|
||||
CPUS = atoi_require(TIPPECANOE_MAX_THREADS, "TIPPECANOE_MAX_THREADS");
|
||||
} else {
|
||||
CPUS = get_num_avail_cpus();
|
||||
CPUS = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
}
|
||||
|
||||
if (CPUS < 1) {
|
||||
@@ -202,7 +202,13 @@ void init_cpus() {
|
||||
// Round down to a power of 2
|
||||
CPUS = 1 << (int) (log(CPUS) / log(2));
|
||||
|
||||
MAX_FILES = get_max_open_files();
|
||||
struct rlimit rl;
|
||||
if (getrlimit(RLIMIT_NOFILE, &rl) != 0) {
|
||||
perror("getrlimit");
|
||||
exit(EXIT_PTHREAD);
|
||||
} else {
|
||||
MAX_FILES = rl.rlim_cur;
|
||||
}
|
||||
|
||||
// Don't really want too many temporary files, because the file system
|
||||
// will start to bog down eventually
|
||||
@@ -216,7 +222,7 @@ void init_cpus() {
|
||||
long long fds[MAX_FILES];
|
||||
long long i;
|
||||
for (i = 0; i < MAX_FILES; i++) {
|
||||
fds[i] = open(get_null_device(), O_RDONLY | O_CLOEXEC);
|
||||
fds[i] = open("/dev/null", O_RDONLY | O_CLOEXEC);
|
||||
if (fds[i] < 0) {
|
||||
break;
|
||||
}
|
||||
@@ -893,7 +899,7 @@ void radix1(int *geomfds_in, int *indexfds_in, int inputs, int prefix, int split
|
||||
std::atomic<long long> indexpos(indexst.st_size);
|
||||
int bytes = sizeof(struct index);
|
||||
|
||||
int page = get_page_size();
|
||||
int page = sysconf(_SC_PAGESIZE);
|
||||
// Don't try to sort more than 2GB at once,
|
||||
// which used to crash Macs and may still
|
||||
long long max_unit = 2LL * 1024 * 1024 * 1024;
|
||||
@@ -1063,6 +1069,31 @@ void prep_drop_states(struct drop_state *ds, int maxzoom, int basezoom, double d
|
||||
}
|
||||
}
|
||||
|
||||
static size_t calc_memsize() {
|
||||
size_t mem;
|
||||
|
||||
#ifdef __APPLE__
|
||||
int64_t hw_memsize;
|
||||
size_t len = sizeof(int64_t);
|
||||
if (sysctlbyname("hw.memsize", &hw_memsize, &len, NULL, 0) < 0) {
|
||||
perror("sysctl hw.memsize");
|
||||
exit(EXIT_MEMORY);
|
||||
}
|
||||
mem = hw_memsize;
|
||||
#else
|
||||
long long pagesize = sysconf(_SC_PAGESIZE);
|
||||
long long pages = sysconf(_SC_PHYS_PAGES);
|
||||
if (pages < 0 || pagesize < 0) {
|
||||
perror("sysconf _SC_PAGESIZE or _SC_PHYS_PAGES");
|
||||
exit(EXIT_MEMORY);
|
||||
}
|
||||
|
||||
mem = (long long) pages * pagesize;
|
||||
#endif
|
||||
|
||||
return mem;
|
||||
}
|
||||
|
||||
void radix(std::vector<struct reader> &readers, int nreaders, FILE *geomfile, FILE *indexfile, const char *tmpdir, std::atomic<long long> *geompos, int maxzoom, int basezoom, double droprate, double gamma) {
|
||||
// Run through the index and geometry for each reader,
|
||||
// splitting the contents out by index into as many
|
||||
@@ -1415,7 +1446,7 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
|
||||
size_t dist_count = 0;
|
||||
double area_sum = 0;
|
||||
|
||||
int files_open_before_reading = open(get_null_device(), O_RDONLY | O_CLOEXEC);
|
||||
int files_open_before_reading = open("/dev/null", O_RDONLY | O_CLOEXEC);
|
||||
if (files_open_before_reading < 0) {
|
||||
perror("open /dev/null");
|
||||
exit(EXIT_OPEN);
|
||||
@@ -1856,7 +1887,7 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
|
||||
}
|
||||
}
|
||||
|
||||
int files_open_after_reading = open(get_null_device(), O_RDONLY | O_CLOEXEC);
|
||||
int files_open_after_reading = open("/dev/null", O_RDONLY | O_CLOEXEC);
|
||||
if (files_open_after_reading < 0) {
|
||||
perror("open /dev/null");
|
||||
exit(EXIT_OPEN);
|
||||
@@ -3697,7 +3728,7 @@ int main(int argc, char **argv) {
|
||||
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
files_open_at_start = open(get_null_device(), O_RDONLY | O_CLOEXEC);
|
||||
files_open_at_start = open("/dev/null", O_RDONLY | O_CLOEXEC);
|
||||
if (files_open_at_start < 0) {
|
||||
perror("open /dev/null");
|
||||
exit(EXIT_OPEN);
|
||||
@@ -3847,7 +3878,7 @@ int main(int argc, char **argv) {
|
||||
muntrace();
|
||||
#endif
|
||||
|
||||
i = open(get_null_device(), O_RDONLY | O_CLOEXEC);
|
||||
i = open("/dev/null", O_RDONLY | O_CLOEXEC);
|
||||
// i < files_open_at_start is not an error, because reading from a pipe closes stdin
|
||||
if (i > files_open_at_start) {
|
||||
fprintf(stderr, "Internal error: did not close all files: %d\n", i);
|
||||
|
||||
+1
-1
@@ -700,7 +700,7 @@ metadata make_metadata(const char *fname, int minzoom, int maxzoom, double minla
|
||||
|
||||
m.strategies_json = stringify_strategies(strategies);
|
||||
|
||||
if (std::isinf(droprate)) {
|
||||
if (isinf(droprate)) {
|
||||
droprate = LLONG_MAX;
|
||||
}
|
||||
if (basezoom != maxzoom || droprate != 2.5 || retain_points_multiplier != 1) {
|
||||
|
||||
+20
-89
@@ -40,26 +40,6 @@ void usage(char **argv) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::string read_json_file(const char *fname) {
|
||||
std::string out;
|
||||
|
||||
FILE *f = fopen(fname, "r");
|
||||
if (f == NULL) {
|
||||
perror(optarg);
|
||||
exit(EXIT_OPEN);
|
||||
}
|
||||
|
||||
char buf[2000];
|
||||
size_t nread;
|
||||
while ((nread = fread(buf, sizeof(char), 2000, f)) != 0) {
|
||||
out += std::string(buf, nread);
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int i;
|
||||
const char *outtile = NULL;
|
||||
@@ -80,7 +60,6 @@ int main(int argc, char **argv) {
|
||||
{"output", required_argument, 0, 'o'},
|
||||
{"filter-points-multiplier", no_argument, 0, 'm'},
|
||||
{"feature-filter", required_argument, 0, 'j'},
|
||||
{"feature-filter-file", required_argument, 0, 'J'},
|
||||
{"preserve-input-order", no_argument, 0, 'o' & 0x1F},
|
||||
{"accumulate-attribute", required_argument, 0, 'E'},
|
||||
{"unidecode-data", required_argument, 0, 'u' & 0x1F},
|
||||
@@ -90,10 +69,10 @@ int main(int argc, char **argv) {
|
||||
{"assign-to-bins", required_argument, 0, 'b' & 0x1F},
|
||||
{"bin-by-id-list", required_argument, 0, 'c' & 0x1F},
|
||||
{"accumulate-numeric-attributes", required_argument, 0, 'a' & 0x1F},
|
||||
{"numeric-attributes", required_argument, 0, 'a' & 0x1F},
|
||||
{"no-tile-compression", no_argument, 0, 'd' & 0x1F},
|
||||
{"clip-bounding-box", required_argument, 0, 'k' & 0x1F},
|
||||
{"clip-polygon", required_argument, 0, 'l' & 0x1F},
|
||||
{"clip-polygon-file", required_argument, 0, 'm' & 0x1F},
|
||||
|
||||
{0, 0, 0, 0},
|
||||
};
|
||||
@@ -144,10 +123,6 @@ int main(int argc, char **argv) {
|
||||
filter = optarg;
|
||||
break;
|
||||
|
||||
case 'J':
|
||||
filter = read_json_file(optarg);
|
||||
break;
|
||||
|
||||
case 'o' & 0x1F:
|
||||
preserve_input_order = true;
|
||||
break;
|
||||
@@ -207,12 +182,6 @@ int main(int argc, char **argv) {
|
||||
break;
|
||||
}
|
||||
|
||||
case 'm' & 0x1F: {
|
||||
clipbbox clip = parse_clip_poly(read_json_file(optarg));
|
||||
clipbboxes.push_back(clip);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
fprintf(stderr, "Unrecognized flag -%c\n", i);
|
||||
usage(argv);
|
||||
@@ -291,72 +260,34 @@ int main(int argc, char **argv) {
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
// clip the clip polygons, if any, to the tile bounds,
|
||||
// to reduce their complexity
|
||||
|
||||
bool clipped_to_nothing = false;
|
||||
if (clipbboxes.size() > 0) {
|
||||
long long wx1 = (nx - buffer / 256.0) * (1LL << (32 - nz));
|
||||
long long wy1 = (ny - buffer / 256.0) * (1LL << (32 - nz));
|
||||
long long wx2 = (nx + 1 + buffer / 256.0) * (1LL << (32 - nz));
|
||||
long long wy2 = (ny + 1 + buffer / 256.0) * (1LL << (32 - nz));
|
||||
|
||||
drawvec tile_bounds;
|
||||
tile_bounds.emplace_back(VT_MOVETO, wx1, wy1);
|
||||
tile_bounds.emplace_back(VT_LINETO, wx2, wy1);
|
||||
tile_bounds.emplace_back(VT_LINETO, wx2, wy2);
|
||||
tile_bounds.emplace_back(VT_LINETO, wx1, wy2);
|
||||
tile_bounds.emplace_back(VT_LINETO, wx1, wy1);
|
||||
|
||||
for (auto &c : clipbboxes) {
|
||||
c.minx = std::max(c.minx, wx1);
|
||||
c.miny = std::max(c.miny, wy1);
|
||||
c.maxx = std::min(c.maxx, wx2);
|
||||
c.maxy = std::min(c.maxy, wy2);
|
||||
|
||||
if (c.dv.size() > 0) {
|
||||
c.dv = clip_poly_poly(c.dv, tile_bounds);
|
||||
|
||||
if (c.dv.size() == 0) {
|
||||
clipped_to_nothing = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
json_object *json_filter = NULL;
|
||||
if (filter.size() > 0) {
|
||||
json_filter = parse_filter(filter.c_str());
|
||||
}
|
||||
|
||||
std::string out;
|
||||
for (auto const &s : sources) {
|
||||
std::string tile;
|
||||
char buf[1000];
|
||||
int len;
|
||||
|
||||
if (!clipped_to_nothing) {
|
||||
json_object *json_filter = NULL;
|
||||
if (filter.size() > 0) {
|
||||
json_filter = parse_filter(filter.c_str());
|
||||
FILE *f = fopen(s.tile.c_str(), "rb");
|
||||
if (f == NULL) {
|
||||
perror(s.tile.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (auto const &s : sources) {
|
||||
std::string tile;
|
||||
char buf[1000];
|
||||
int len;
|
||||
|
||||
FILE *f = fopen(s.tile.c_str(), "rb");
|
||||
if (f == NULL) {
|
||||
perror(s.tile.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
while ((len = fread(buf, sizeof(char), 1000, f)) > 0) {
|
||||
tile.append(std::string(buf, len));
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
input_tile t = s;
|
||||
t.tile = std::move(tile);
|
||||
its.push_back(std::move(t));
|
||||
while ((len = fread(buf, sizeof(char), 1000, f)) > 0) {
|
||||
tile.append(std::string(buf, len));
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
out = overzoom(its, nz, nx, ny, detail, buffer, keep, exclude, exclude_prefix, do_compress, NULL, demultiply, json_filter, preserve_input_order, attribute_accum, unidecode_data, simplification, tiny_polygon_size, bins, bin_by_id_list, accumulate_numeric, SIZE_MAX, clipbboxes);
|
||||
input_tile t = s;
|
||||
t.tile = std::move(tile);
|
||||
its.push_back(std::move(t));
|
||||
}
|
||||
|
||||
std::string out = overzoom(its, nz, nx, ny, detail, buffer, keep, exclude, exclude_prefix, do_compress, NULL, demultiply, json_filter, preserve_input_order, attribute_accum, unidecode_data, simplification, tiny_polygon_size, bins, bin_by_id_list, accumulate_numeric, SIZE_MAX, clipbboxes);
|
||||
|
||||
FILE *f = fopen(outfile, "wb");
|
||||
if (f == NULL) {
|
||||
perror(outfile);
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
#include "platform.hpp"
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <unistd.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
#if defined(__APPLE__) || defined(__FreeBSD__)
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/mount.h>
|
||||
#endif
|
||||
|
||||
#include "errors.hpp"
|
||||
|
||||
long get_num_avail_cpus() {
|
||||
return sysconf(_SC_NPROCESSORS_ONLN);
|
||||
}
|
||||
|
||||
long get_page_size() {
|
||||
return sysconf(_SC_PAGESIZE);
|
||||
}
|
||||
|
||||
size_t calc_memsize() {
|
||||
size_t mem;
|
||||
|
||||
#ifdef __APPLE__
|
||||
int64_t hw_memsize;
|
||||
size_t len = sizeof(int64_t);
|
||||
if (sysctlbyname("hw.memsize", &hw_memsize, &len, NULL, 0) < 0) {
|
||||
perror("sysctl hw.memsize");
|
||||
exit(EXIT_MEMORY);
|
||||
}
|
||||
mem = hw_memsize;
|
||||
#else
|
||||
long long pagesize = sysconf(_SC_PAGESIZE);
|
||||
long long pages = sysconf(_SC_PHYS_PAGES);
|
||||
if (pages < 0 || pagesize < 0) {
|
||||
perror("sysconf _SC_PAGESIZE or _SC_PHYS_PAGES");
|
||||
exit(EXIT_MEMORY);
|
||||
}
|
||||
|
||||
mem = (long long) pages * pagesize;
|
||||
#endif
|
||||
|
||||
return mem;
|
||||
}
|
||||
|
||||
size_t get_max_open_files() {
|
||||
struct rlimit rl;
|
||||
if (getrlimit(RLIMIT_NOFILE, &rl) != 0) {
|
||||
perror("getrlimit");
|
||||
exit(EXIT_PTHREAD);
|
||||
}
|
||||
return rl.rlim_cur;
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
#ifndef PLATFORM_HPP
|
||||
#define PLATFORM_HPP
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
long get_num_avail_cpus();
|
||||
|
||||
long get_page_size();
|
||||
|
||||
size_t calc_memsize();
|
||||
|
||||
size_t get_max_open_files();
|
||||
|
||||
constexpr const char *get_null_device() {
|
||||
return "/dev/null";
|
||||
}
|
||||
|
||||
#endif // PLATFORM_HPP
|
||||
+4
-7
@@ -179,7 +179,7 @@ static std::vector<mvt_geometry> to_feature(drawvec &geom) {
|
||||
}
|
||||
|
||||
std::pair<int, drawvec> parse_geometry(json_object *geometry, json_pull *jp, json_object *j,
|
||||
int z, int x, int y, long long extent, bool fix_longitudes, bool mvt_style) {
|
||||
int z, int x, int y, long long extent, bool fix_longitudes) {
|
||||
json_object *geometry_type = json_hash_get(geometry, "type");
|
||||
if (geometry_type == NULL) {
|
||||
fprintf(stderr, "Filter output:%d: null geometry (additional not reported): ", jp->line);
|
||||
@@ -291,11 +291,8 @@ std::pair<int, drawvec> parse_geometry(json_object *geometry, json_pull *jp, jso
|
||||
}
|
||||
}
|
||||
dv = remove_noop(dv, mb_geometry[t], 0);
|
||||
|
||||
if (mvt_style) {
|
||||
if (mb_geometry[t] == VT_POLYGON) {
|
||||
dv = close_poly(dv);
|
||||
}
|
||||
if (mb_geometry[t] == VT_POLYGON) {
|
||||
dv = close_poly(dv);
|
||||
}
|
||||
|
||||
return std::pair<int, drawvec>(t, dv);
|
||||
@@ -367,7 +364,7 @@ std::vector<mvt_layer> parse_layers(FILE *fp, int z, unsigned x, unsigned y, int
|
||||
exit(EXIT_JSON);
|
||||
}
|
||||
|
||||
std::pair<int, drawvec> parsed_geometry = parse_geometry(geometry, jp, j, z, x, y, extent, fix_longitudes, true);
|
||||
std::pair<int, drawvec> parsed_geometry = parse_geometry(geometry, jp, j, z, x, y, extent, fix_longitudes);
|
||||
|
||||
int t = parsed_geometry.first;
|
||||
drawvec &dv = parsed_geometry.second;
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ extern int mb_geometry[GEOM_TYPES];
|
||||
void json_context(json_object *j);
|
||||
void parse_coordinates(int t, json_object *j, drawvec &out, int op, const char *fname, int line, json_object *feature);
|
||||
std::pair<int, drawvec> parse_geometry(json_object *geometry, json_pull *jp, json_object *j,
|
||||
int z, int x, int y, long long extent, bool fix_longitudes, bool mvt_style);
|
||||
int z, int x, int y, long long extent, bool fix_longitudes);
|
||||
std::vector<mvt_layer> parse_layers(FILE *fp, int z, unsigned x, unsigned y, int extent, bool fix_longitudes);
|
||||
|
||||
serial_val stringify_value(json_object *value, const char *reading, int line, json_object *feature);
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
{ "type": "FeatureCollection", "properties": { "zoom": 11, "x": 327, "y": 791 }, "features": [
|
||||
{ "type": "FeatureCollection", "properties": { "layer": "parsed", "version": 2, "extent": 4096 }, "features": [
|
||||
{ "type": "Feature", "properties": { "bin-ids": "236,237,510,514", "ZCTA5CE10": "94129", "GEOID10": "94129", "CLASSFP10": "B5", "MTFCC10": "G6350", "FUNCSTAT10": "S", "ALAND10": 5968455, "AWATER10": 14697, "INTPTLAT10": "+37.7973402", "INTPTLON10": "-122.4644664", "tippecanoe:count": 4 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -122.448120, 37.806936 ], [ -122.448120, 37.806393 ], [ -122.448463, 37.806122 ], [ -122.448292, 37.804766 ], [ -122.451553, 37.803409 ], [ -122.450180, 37.802867 ], [ -122.450008, 37.802460 ], [ -122.447605, 37.800697 ], [ -122.447262, 37.798527 ], [ -122.448120, 37.798255 ], [ -122.448292, 37.797848 ], [ -122.447948, 37.797441 ], [ -122.448635, 37.797441 ], [ -122.448635, 37.797034 ], [ -122.447948, 37.796899 ], [ -122.447948, 37.796492 ], [ -122.448978, 37.796356 ], [ -122.447433, 37.795814 ], [ -122.447433, 37.795542 ], [ -122.447777, 37.795407 ], [ -122.448635, 37.795542 ], [ -122.448978, 37.795000 ], [ -122.448635, 37.794728 ], [ -122.447948, 37.793101 ], [ -122.448463, 37.792829 ], [ -122.448635, 37.791880 ], [ -122.458334, 37.789879 ], [ -122.454300, 37.806495 ], [ -122.452412, 37.806258 ], [ -122.448120, 37.806936 ] ], [ [ -122.452583, 37.803274 ], [ -122.452412, 37.803138 ], [ -122.450008, 37.802460 ], [ -122.451210, 37.803138 ], [ -122.452583, 37.803274 ] ] ] } }
|
||||
,
|
||||
{ "type": "Feature", "properties": { "bin-ids": "529,531", "ZCTA5CE10": "94123", "GEOID10": "94123", "CLASSFP10": "B5", "MTFCC10": "G6350", "FUNCSTAT10": "S", "ALAND10": 2646572, "AWATER10": 218721, "INTPTLAT10": "+37.8009336", "INTPTLON10": "-122.4383664", "tippecanoe:count": 2 }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ -122.447004, 37.808936 ], [ -122.428250, 37.796051 ], [ -122.433529, 37.795407 ], [ -122.433357, 37.794457 ], [ -122.434902, 37.794322 ], [ -122.435074, 37.795271 ], [ -122.436790, 37.795000 ], [ -122.436619, 37.794050 ], [ -122.440739, 37.793508 ], [ -122.440910, 37.794457 ], [ -122.441769, 37.794322 ], [ -122.441597, 37.793372 ], [ -122.446404, 37.792829 ], [ -122.446232, 37.791880 ], [ -122.447605, 37.791744 ], [ -122.448635, 37.794728 ], [ -122.448978, 37.795000 ], [ -122.448635, 37.795542 ], [ -122.447777, 37.795407 ], [ -122.447433, 37.795542 ], [ -122.447433, 37.795814 ], [ -122.448978, 37.796356 ], [ -122.447948, 37.796492 ], [ -122.447948, 37.796899 ], [ -122.448635, 37.797034 ], [ -122.448635, 37.797441 ], [ -122.447948, 37.797441 ], [ -122.448292, 37.797848 ], [ -122.448120, 37.798255 ], [ -122.447262, 37.798527 ], [ -122.447605, 37.800697 ], [ -122.450008, 37.802460 ], [ -122.450180, 37.802867 ], [ -122.451553, 37.803409 ], [ -122.448292, 37.804766 ], [ -122.448463, 37.806122 ], [ -122.448120, 37.806393 ], [ -122.448120, 37.806936 ], [ -122.448635, 37.808563 ], [ -122.447004, 37.808936 ] ] ], [ [ [ -122.452583, 37.803274 ], [ -122.451210, 37.803138 ], [ -122.450008, 37.802460 ], [ -122.452583, 37.803274 ] ] ] ] } }
|
||||
] }
|
||||
] }
|
||||
@@ -1 +0,0 @@
|
||||
{"coordinates":[[[-122.4527379,37.8128815],[-122.4598853,37.7834743],[-122.4280914,37.7959397],[-122.4527379,37.8128815]]],"type":"Polygon"}
|
||||
@@ -1,5 +0,0 @@
|
||||
{ "type": "FeatureCollection", "properties": { "zoom": 8, "x": 135, "y": 86 }, "features": [
|
||||
{ "type": "FeatureCollection", "properties": { "layer": "ne_10m_admin_0_countries", "version": 2, "extent": 4096 }, "features": [
|
||||
{ "type": "Feature", "properties": { "NAME": "Germany" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 11.210518, 50.771208 ], [ 11.304932, 50.271568 ], [ 11.304932, 49.802541 ], [ 9.788818, 49.802541 ], [ 9.788818, 50.771208 ], [ 11.210518, 50.771208 ] ] ] } }
|
||||
] }
|
||||
] }
|
||||
@@ -1 +0,0 @@
|
||||
{"*":["SCALERANK","eq",0]}
|
||||
Binary file not shown.
@@ -1 +0,0 @@
|
||||
{"coordinates":[[[-73.9722549,40.7904659],[-73.9755817,40.7674848],[-73.938783,40.767022],[-73.9457082,40.7791562],[-73.9628855,40.7760201],[-73.9629534,40.7914425],[-73.9722549,40.7904659]]],"crs":{"properties":{"name":"EPSG:4326"},"type":"name"},"type":"Polygon"}
|
||||
+1
-2
@@ -43,7 +43,6 @@
|
||||
#include "errors.hpp"
|
||||
#include "geometry.hpp"
|
||||
#include "thread.hpp"
|
||||
#include "platform.hpp"
|
||||
|
||||
int pk = false;
|
||||
int pC = false;
|
||||
@@ -1200,7 +1199,7 @@ int main(int argc, char **argv) {
|
||||
|
||||
struct tileset_reader *readers = NULL;
|
||||
|
||||
CPUS = get_num_avail_cpus();
|
||||
CPUS = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
|
||||
const char *TIPPECANOE_MAX_THREADS = getenv("TIPPECANOE_MAX_THREADS");
|
||||
if (TIPPECANOE_MAX_THREADS != NULL) {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
#ifndef VERSION_HPP
|
||||
#define VERSION_HPP
|
||||
|
||||
#define VERSION "v2.73.0"
|
||||
#define VERSION "v2.70.1"
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user