diff --git a/Makefile b/Makefile index 3968ed49..f122dfe7 100644 --- a/Makefile +++ b/Makefile @@ -278,6 +278,16 @@ overzoom-test: tippecanoe-overzoom ./tippecanoe-decode tests/pbf/13-1310-3166.pbf 13 1310 3166 > tests/pbf/13-1310-3166.pbf.json.check cmp tests/pbf/13-1310-3166.pbf.json.check tests/pbf/13-1310-3166.pbf.json rm tests/pbf/13-1310-3166.pbf tests/pbf/13-1310-3166.pbf.json.check + # Basic operation, multiple input form + ./tippecanoe-overzoom -o tests/pbf/13-1310-3166.pbf -t 13/1310/3166 tests/pbf/11-327-791.pbf 11/327/791 + ./tippecanoe-decode tests/pbf/13-1310-3166.pbf 13 1310 3166 > tests/pbf/13-1310-3166.pbf.json.check + cmp tests/pbf/13-1310-3166.pbf.json.check tests/pbf/13-1310-3166.pbf.json + rm tests/pbf/13-1310-3166.pbf tests/pbf/13-1310-3166.pbf.json.check + # Multiple inputs + ./tippecanoe-overzoom -o tests/pbf/13-1310-3166-ne.pbf -t 13/1310/3166 tests/pbf/11-327-791.pbf 11/327/791 tests/pbf/0-0-0.pbf 0/0/0 + ./tippecanoe-decode tests/pbf/13-1310-3166-ne.pbf 13 1310 3166 > tests/pbf/13-1310-3166-ne.pbf.json.check + cmp tests/pbf/13-1310-3166-ne.pbf.json.check tests/pbf/13-1310-3166-ne.pbf.json + rm tests/pbf/13-1310-3166-ne.pbf tests/pbf/13-1310-3166-ne.pbf.json.check # Different detail and buffer, and attribute stripping ./tippecanoe-overzoom -d8 -b30 -y NAME -y name -y scalerank -o tests/pbf/13-1310-3166-8-30.pbf tests/pbf/11-327-791.pbf 11/327/791 13/1310/3166 ./tippecanoe-decode tests/pbf/13-1310-3166-8-30.pbf 13 1310 3166 > tests/pbf/13-1310-3166-8-30.pbf.json.check diff --git a/overzoom.cpp b/overzoom.cpp index d365cca3..1ac095e1 100644 --- a/overzoom.cpp +++ b/overzoom.cpp @@ -24,7 +24,7 @@ void usage(char **argv) { } struct source { - std::string file; + std::string fname; int z; int x; int y; @@ -37,7 +37,7 @@ int main(int argc, char **argv) { std::vector sources; - while ((i = getopt(argc, argv, "y:o:d:b:")) != -1) { + while ((i = getopt(argc, argv, "y:o:d:b:t:")) != -1) { switch (i) { case 'y': keep.insert(optarg); @@ -68,7 +68,10 @@ int main(int argc, char **argv) { usage(argv); } - if (outtile == NULL) { + std::vector its; + int nz, nx, ny; + + if (outtile == NULL) { // single input if (argc - optind != 3) { usage(argv); } @@ -81,19 +84,53 @@ int main(int argc, char **argv) { usage(argv); } - int nz, nx, ny; if (sscanf(argv[optind + 2], "%d/%d/%d", &nz, &nx, &ny) != 3) { fprintf(stderr, "%s: not in z/x/y form\n", argv[optind + 2]); usage(argv); } + source s; + s.fname = infile; + s.z = oz; + s.x = ox; + s.y = oy; + + sources.push_back(s); + } else { // multiple inputs + if ((argc - optind) % 2 != 0) { + usage(argv); + } + + if (sscanf(outtile, "%d/%d/%d", &nz, &nx, &ny) != 3) { + fprintf(stderr, "%s: not in z/x/y form\n", outtile); + usage(argv); + } + + for (i = optind; i + 1 < argc; i += 2) { + int oz, ox, oy; + if (sscanf(argv[i + 1], "%d/%d/%d", &oz, &ox, &oy) != 3) { + fprintf(stderr, "%s: not in z/x/y form\n", argv[i + 1]); + usage(argv); + } + + source s; + s.fname = argv[i]; + s.z = oz; + s.x = ox; + s.y = oy; + + sources.push_back(s); + } + } + + for (auto const &s : sources) { std::string tile; char buf[1000]; int len; - FILE *f = fopen(infile, "rb"); + FILE *f = fopen(s.fname.c_str(), "rb"); if (f == NULL) { - perror(infile); + perror(s.fname.c_str()); exit(EXIT_FAILURE); } @@ -102,26 +139,24 @@ int main(int argc, char **argv) { } fclose(f); - f = fopen(outfile, "wb"); - if (f == NULL) { - perror(outfile); - exit(EXIT_FAILURE); - } - input_tile it; it.tile = tile; - it.z = oz; - it.x = ox; - it.y = oy; + it.z = s.z; + it.x = s.x; + it.y = s.y; - std::vector its; its.push_back(it); - - std::string out = overzoom(its, nz, nx, ny, detail, buffer, keep, true, NULL); - fwrite(out.c_str(), sizeof(char), out.size(), f); - fclose(f); - } else { } + std::string out = overzoom(its, nz, nx, ny, detail, buffer, keep, true, NULL); + + FILE *f = fopen(outfile, "wb"); + if (f == NULL) { + perror(outfile); + exit(EXIT_FAILURE); + } + fwrite(out.c_str(), sizeof(char), out.size(), f); + fclose(f); + return 0; } diff --git a/tests/pbf/0-0-0.pbf b/tests/pbf/0-0-0.pbf new file mode 100644 index 00000000..cf7b426b Binary files /dev/null and b/tests/pbf/0-0-0.pbf differ diff --git a/tests/pbf/13-1310-3166-ne.pbf.json b/tests/pbf/13-1310-3166-ne.pbf.json new file mode 100644 index 00000000..852b0102 --- /dev/null +++ b/tests/pbf/13-1310-3166-ne.pbf.json @@ -0,0 +1,21 @@ +{ "type": "FeatureCollection", "properties": { "zoom": 13, "x": 1310, "y": 3166 }, "features": [ +{ "type": "FeatureCollection", "properties": { "layer": "ne_10m_land", "version": 2, "extent": 4096 }, "features": [ +{ "type": "Feature", "properties": { "featurecla": "Land", "scalerank": 0, "min_zoom": 0 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -122.387760, 37.788760 ], [ -122.387094, 37.778754 ], [ -122.386837, 37.778517 ], [ -122.386837, 37.752665 ], [ -122.432499, 37.752665 ], [ -122.432499, 37.788760 ], [ -122.387760, 37.788760 ] ] ] } } +] } +, +{ "type": "FeatureCollection", "properties": { "layer": "ne_10m_populated_places", "version": 2, "extent": 4096 }, "features": [ +{ "type": "Feature", "properties": { "SCALERANK": 1, "NATSCALE": 300, "LABELRANK": 1, "FEATURECLA": "Populated place", "NAME": "San Francisco", "NAMEALT": "San Francisco-Oakland", "NAMEASCII": "San Francisco", "ADM0CAP": 0, "WORLDCITY": 1, "MEGACITY": 1, "SOV0NAME": "United States", "SOV_A3": "USA", "ADM0NAME": "United States of America", "ADM0_A3": "USA", "ADM1NAME": "California", "ISO_A2": "US", "LATITUDE": 37.769196, "LONGITUDE": -122.417169, "POP_MAX": 3450000, "POP_MIN": 732072, "POP_OTHER": 27400, "RANK_MAX": 12, "RANK_MIN": 11, "MEGANAME": "San Francisco-Oakland", "LS_NAME": "San Francisco1", "MAX_POP10": 988636, "MAX_POP20": 1130999, "MAX_POP50": 1371285, "MAX_POP300": 4561697, "MAX_POP310": 4561697, "MAX_NATSCA": 300, "MIN_AREAKM": 218, "MAX_AREAKM": 1748, "MIN_AREAMI": 84, "MAX_AREAMI": 675, "MIN_PERKM": 126, "MAX_PERKM": 755, "MIN_PERMI": 78, "MAX_PERMI": 469, "MIN_BBXMIN": -122.516667, "MAX_BBXMIN": -122.516667, "MIN_BBXMAX": -122.358333, "MAX_BBXMAX": -121.733333, "MIN_BBYMIN": 37.191667, "MAX_BBYMIN": 37.575, "MIN_BBYMAX": 37.816667, "MAX_BBYMAX": 38.041667, "MEAN_BBXC": -122.301354, "MEAN_BBYC": 37.622288, "TIMEZONE": "America/Los_Angeles", "UN_FID": 570, "POP1950": 1855, "POP1955": 2021, "POP1960": 2200, "POP1965": 2361, "POP1970": 2529, "POP1975": 2590, "POP1980": 2656, "POP1985": 2805, "POP1990": 2961, "POP1995": 3095, "POP2000": 3236, "POP2005": 3387, "POP2010": 3450, "POP2015": 3544, "POP2020": 3684, "POP2025": 3803, "POP2050": 3898, "MIN_ZOOM": 2.7, "WIKIDATAID": "Q62", "WOF_ID": 85922583, "CAPALT": 0, "NAME_EN": "San Francisco", "NAME_DE": "San Francisco", "NAME_ES": "San Francisco", "NAME_FR": "San Francisco", "NAME_PT": "São Francisco", "NAME_RU": "Сан-Франциско", "NAME_ZH": "旧金山", "NAME_AR": "سان فرانسيسكو", "NAME_BN": "সান ফ্রান্সিস্কো", "NAME_EL": "Σαν Φρανσίσκο", "NAME_HI": "सैन फ्रांसिस्को", "NAME_HU": "San Francisco", "NAME_ID": "San Francisco", "NAME_IT": "San Francisco", "NAME_JA": "サンフランシスコ", "NAME_KO": "샌프란시스코", "NAME_NL": "San Francisco", "NAME_PL": "San Francisco", "NAME_SV": "San Francisco", "NAME_TR": "San Francisco", "NAME_VI": "San Francisco", "NE_ID": 1159151479, "NAME_FA": "سان فرانسیسکو", "NAME_HE": "סן פרנסיסקו", "NAME_UK": "Сан-Франциско", "NAME_UR": "سان فرانسسکو", "NAME_ZHT": "舊金山", "GEONAMESID": 5391959 }, "geometry": { "type": "Point", "coordinates": [ -122.399583, 37.784249 ] } } +] } +, +{ "type": "FeatureCollection", "properties": { "layer": "ne_10m_roads", "version": 2, "extent": 4096 }, "features": [ +{ "type": "Feature", "properties": { "scalerank": 4, "featurecla": "Road", "type": "Major Highway", "sov_a3": "USA", "edited": "New in version 2.0.0", "name": "101", "question": 0, "length_km": 11, "toll": 0, "ne_part": "ne_1d4_original", "labelrank": 0, "ignore": 0, "add": 0, "rwdb_rd_id": 0, "orig_fid": 0, "uident": 118705, "continent": "North America", "expressway": 1, "level": "Federal", "min_zoom": 4, "min_label": 7 }, "geometry": { "type": "LineString", "coordinates": [ [ -122.407351, 37.767933 ], [ -122.412586, 37.781841 ], [ -122.419496, 37.788760 ] ] } } +, +{ "type": "Feature", "properties": { "scalerank": 3, "featurecla": "Road", "type": "Major Highway", "sov_a3": "USA", "edited": "New in version 2.0.0", "name": "80", "question": 0, "length_km": 14, "toll": 1, "ne_part": "ne_1d4_original", "labelrank": 0, "ignore": 0, "add": 0, "rwdb_rd_id": 0, "orig_fid": 0, "uident": 311505, "continent": "North America", "expressway": 1, "level": "Interstate", "min_zoom": 3, "min_label": 6 }, "geometry": { "type": "LineString", "coordinates": [ [ -122.407351, 37.767933 ], [ -122.388253, 37.785300 ], [ -122.386837, 37.786453 ] ] } } +, +{ "type": "Feature", "properties": { "scalerank": 4, "featurecla": "Road", "type": "Major Highway", "sov_a3": "USA", "edited": "New in version 2.0.0", "name": "280", "question": 0, "length_km": 52, "toll": 0, "ne_part": "ne_1d4_original", "labelrank": 0, "ignore": 0, "add": 0, "rwdb_rd_id": 0, "orig_fid": 0, "uident": 124805, "continent": "North America", "expressway": 1, "level": "Interstate", "min_zoom": 4, "min_label": 7 }, "geometry": { "type": "LineString", "coordinates": [ [ -122.405677, 37.752665 ], [ -122.407351, 37.767933 ] ] } } +] } +, +{ "type": "FeatureCollection", "properties": { "layer": "ne_10m_admin_0_countries", "version": 2, "extent": 4096 }, "features": [ +{ "type": "Feature", "properties": { "featurecla": "Admin-0 country", "scalerank": 0, "LABELRANK": 2, "SOVEREIGNT": "United States of America", "SOV_A3": "US1", "ADM0_DIF": 1, "LEVEL": 2, "TYPE": "Country", "TLC": "1", "ADMIN": "United States of America", "ADM0_A3": "USA", "GEOU_DIF": 0, "GEOUNIT": "United States of America", "GU_A3": "USA", "SU_DIF": 0, "SUBUNIT": "United States", "SU_A3": "USA", "BRK_DIFF": 0, "NAME": "United States of America", "NAME_LONG": "United States", "BRK_A3": "USA", "BRK_NAME": "United States", "ABBREV": "U.S.A.", "POSTAL": "US", "FORMAL_EN": "United States of America", "NAME_CIAWF": "United States", "NAME_SORT": "United States of America", "MAPCOLOR7": 4, "MAPCOLOR8": 5, "MAPCOLOR9": 1, "MAPCOLOR13": 1, "POP_EST": 328239523, "POP_RANK": 17, "POP_YEAR": 2019, "GDP_MD": 21433226, "GDP_YEAR": 2019, "ECONOMY": "1. Developed region: G7", "INCOME_GRP": "1. High income: OECD", "FIPS_10": "US", "ISO_A2": "US", "ISO_A2_EH": "US", "ISO_A3": "USA", "ISO_A3_EH": "USA", "ISO_N3": "840", "ISO_N3_EH": "840", "UN_A3": "840", "WB_A2": "US", "WB_A3": "USA", "WOE_ID": 23424977, "WOE_ID_EH": 23424977, "WOE_NOTE": "Exact WOE match as country", "ADM0_ISO": "USA", "ADM0_TLC": "USA", "ADM0_A3_US": "USA", "ADM0_A3_FR": "USA", "ADM0_A3_RU": "USA", "ADM0_A3_ES": "USA", "ADM0_A3_CN": "USA", "ADM0_A3_TW": "USA", "ADM0_A3_IN": "USA", "ADM0_A3_NP": "USA", "ADM0_A3_PK": "USA", "ADM0_A3_DE": "USA", "ADM0_A3_GB": "USA", "ADM0_A3_BR": "USA", "ADM0_A3_IL": "USA", "ADM0_A3_PS": "USA", "ADM0_A3_SA": "USA", "ADM0_A3_EG": "USA", "ADM0_A3_MA": "USA", "ADM0_A3_PT": "USA", "ADM0_A3_AR": "USA", "ADM0_A3_JP": "USA", "ADM0_A3_KO": "USA", "ADM0_A3_VN": "USA", "ADM0_A3_TR": "USA", "ADM0_A3_ID": "USA", "ADM0_A3_PL": "USA", "ADM0_A3_GR": "USA", "ADM0_A3_IT": "USA", "ADM0_A3_NL": "USA", "ADM0_A3_SE": "USA", "ADM0_A3_BD": "USA", "ADM0_A3_UA": "USA", "ADM0_A3_UN": -99, "ADM0_A3_WB": -99, "CONTINENT": "North America", "REGION_UN": "Americas", "SUBREGION": "Northern America", "REGION_WB": "North America", "NAME_LEN": 24, "LONG_LEN": 13, "ABBREV_LEN": 6, "TINY": -99, "HOMEPART": 1, "MIN_ZOOM": 0, "MIN_LABEL": 1.7, "MAX_LABEL": 5.7, "LABEL_X": -97.482602, "LABEL_Y": 39.538479, "NE_ID": 1159321369, "WIKIDATAID": "Q30", "NAME_AR": "الولايات المتحدة", "NAME_BN": "মার্কিন যুক্তরাষ্ট্র", "NAME_DE": "Vereinigte Staaten", "NAME_EN": "United States of America", "NAME_ES": "Estados Unidos", "NAME_FA": "ایالات متحده آمریکا", "NAME_FR": "États-Unis", "NAME_EL": "Ηνωμένες Πολιτείες Αμερικής", "NAME_HE": "ארצות הברית", "NAME_HI": "संयुक्त राज्य अमेरिका", "NAME_HU": "Amerikai Egyesült Államok", "NAME_ID": "Amerika Serikat", "NAME_IT": "Stati Uniti d'America", "NAME_JA": "アメリカ合衆国", "NAME_KO": "미국", "NAME_NL": "Verenigde Staten van Amerika", "NAME_PL": "Stany Zjednoczone", "NAME_PT": "Estados Unidos", "NAME_RU": "США", "NAME_SV": "USA", "NAME_TR": "Amerika Birleşik Devletleri", "NAME_UK": "Сполучені Штати Америки", "NAME_UR": "ریاستہائے متحدہ امریکا", "NAME_VI": "Hoa Kỳ", "NAME_ZH": "美国", "NAME_ZHT": "美國", "FCLASS_ISO": "Admin-0 country", "FCLASS_TLC": "Admin-0 country" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -122.432499, 37.788081 ], [ -122.386837, 37.788081 ], [ -122.386837, 37.752665 ], [ -122.432499, 37.752665 ], [ -122.432499, 37.788081 ] ] ] } } +] } +] }