diff --git a/Makefile b/Makefile index 7de48863..30743475 100644 --- a/Makefile +++ b/Makefile @@ -581,7 +581,7 @@ join-test: tippecanoe tippecanoe-decode tile-join # # Test sql join # - ./tile-join -i -f -o tests/join-sql/countries.pmtiles --join-sqlite tests/join-sql/countries.gpkg --join-table countries --join-tile-column ne10-admin0:name_en --join-table-column country tests/join-sql/bboxes.pmtiles + ./tile-join -i -f -o tests/join-sql/countries.pmtiles --join-sqlite tests/join-sql/countries.gpkg --join-table countries --join-tile-attribute ne10-admin0:name_en --join-table-expression 'lower(country)' tests/join-sql/bboxes.pmtiles ./tippecanoe-decode -x generator tests/join-sql/countries.pmtiles > tests/join-sql/countries.pmtiles.json.check cmp tests/join-sql/countries.pmtiles.json.check tests/join-sql/countries.pmtiles.json rm -f tests/join-sql/countries.pmtiles tests/join-sql/countries.pmtiles.json.check diff --git a/tests/join-sql/countries.pmtiles.json b/tests/join-sql/countries.pmtiles.json index 625e928d..9581da99 100644 --- a/tests/join-sql/countries.pmtiles.json +++ b/tests/join-sql/countries.pmtiles.json @@ -4,7 +4,7 @@ "center": "0.000000,0.000000,0", "description": "/tmp/tmp588djzw6/bboxes.pmtiles", "format": "pbf", -"generator_options": "tippecanoe '--tile-stats-values-limit=1' -o /tmp/tmp588djzw6/bboxes.pmtiles -l parsed-bboxes -U1 '--smallest-maximum-zoom-guess=7' -Bg --drop-fraction-as-needed -P --hilbert --generate-variable-depth-tile-pyramid -rp -b0 '--extend-zooms-if-still-dropping-maximum=3' '--extra-detail=30' -D10 '--tiny-polygon-size=1' --no-tiny-polygon-reduction-at-maximum-zoom '--simplification=1' '--simplification-at-maximum-zoom=0.25' --detect-longitude-wraparound --preserve-input-order '--maximum-tile-bytes=2621440' '--maximum-string-attribute-length=65536' --preserve-point-density-threshold 64 --set-attribute '{\"felt:cluster_size\": 1}' --accumulate-attribute '{\"felt:cluster_size\": \"sum\"}' --preserve-multiplier-density-threshold 512 '--accumulate-numeric-attributes=felt' /tmp/tmpg9jf8evz/parsed.geojsonseq.gz; ./tile-join -i -f -o tests/join-sql/countries.pmtiles --join-sqlite tests/join-sql/countries.gpkg --join-table countries --join-tile-column ne10-admin0:name_en --join-table-column country tests/join-sql/bboxes.pmtiles", +"generator_options": "tippecanoe '--tile-stats-values-limit=1' -o /tmp/tmp588djzw6/bboxes.pmtiles -l parsed-bboxes -U1 '--smallest-maximum-zoom-guess=7' -Bg --drop-fraction-as-needed -P --hilbert --generate-variable-depth-tile-pyramid -rp -b0 '--extend-zooms-if-still-dropping-maximum=3' '--extra-detail=30' -D10 '--tiny-polygon-size=1' --no-tiny-polygon-reduction-at-maximum-zoom '--simplification=1' '--simplification-at-maximum-zoom=0.25' --detect-longitude-wraparound --preserve-input-order '--maximum-tile-bytes=2621440' '--maximum-string-attribute-length=65536' --preserve-point-density-threshold 64 --set-attribute '{\"felt:cluster_size\": 1}' --accumulate-attribute '{\"felt:cluster_size\": \"sum\"}' --preserve-multiplier-density-threshold 512 '--accumulate-numeric-attributes=felt' /tmp/tmpg9jf8evz/parsed.geojsonseq.gz; ./tile-join -i -f -o tests/join-sql/countries.pmtiles --join-sqlite tests/join-sql/countries.gpkg --join-table countries --join-tile-attribute ne10-admin0:name_en --join-table-expression 'lower(country)' tests/join-sql/bboxes.pmtiles", "json": "{\"vector_layers\":[{\"id\":\"parsed-bboxes\",\"description\":\"\",\"minzoom\":0,\"maxzoom\":0,\"fields\":{\"another\":\"String\",\"country\":\"String\",\"felt:cluster_size\":\"Number\",\"fid\":\"Number\",\"ne10-admin0:iso_a2_eh\":\"String\",\"ne10-admin0:iso_a3_eh\":\"String\",\"ne10-admin0:name_en\":\"String\",\"something\":\"String\"}}],\"tilestats\":{\"layerCount\":1,\"layers\":[{\"layer\":\"parsed-bboxes\",\"count\":3,\"geometry\":\"Polygon\",\"attributeCount\":8,\"attributes\":[{\"attribute\":\"another\",\"count\":3,\"type\":\"string\",\"values\":[\"bar\",\"why\",\"yes\"]},{\"attribute\":\"country\",\"count\":3,\"type\":\"string\",\"values\":[\"France\",\"Germany\",\"Italy\"]},{\"attribute\":\"felt:cluster_size\",\"count\":1,\"type\":\"number\",\"values\":[1],\"min\":1,\"max\":1},{\"attribute\":\"fid\",\"count\":3,\"type\":\"number\",\"values\":[1,2,3],\"min\":1,\"max\":3},{\"attribute\":\"ne10-admin0:iso_a2_eh\",\"count\":3,\"type\":\"string\",\"values\":[\"de\",\"fr\",\"it\"]},{\"attribute\":\"ne10-admin0:iso_a3_eh\",\"count\":3,\"type\":\"string\",\"values\":[\"deu\",\"fra\",\"ita\"]},{\"attribute\":\"ne10-admin0:name_en\",\"count\":3,\"type\":\"string\",\"values\":[\"france\",\"germany\",\"italy\"]},{\"attribute\":\"something\",\"count\":3,\"type\":\"string\",\"values\":[\"blah\",\"foo\",\"what\"]}]}]}}", "maxzoom": "0", "minzoom": "0", diff --git a/tile-join.cpp b/tile-join.cpp index a9b2eea7..8589c5ad 100644 --- a/tile-join.cpp +++ b/tile-join.cpp @@ -57,8 +57,8 @@ std::map renames; bool exclude_all = false; bool exclude_all_tile_attributes = false; std::vector unidecode_data; -std::string join_tile_column; -std::string join_table_column; +std::string join_tile_attribute; +std::string join_table_expression; std::string join_table; std::string attribute_for_id; @@ -83,10 +83,8 @@ std::vector> get_joined_rows(sqlite3 *db, const ret.resize(join_keys.size()); // double quotes for table and column identifiers - const char *s = sqlite3_mprintf("select LOWER(LTRIM(SUBSTR(\"%w\",1,LENGTH(\"%w\")-3),'0')||SUBSTR(\"%w\",-3,3)), * from \"%w\" where LOWER(LTRIM(SUBSTR(\"%w\",1,LENGTH(\"%w\")-3),'0')||SUBSTR(\"%w\",-3,3)) in (", - join_table_column.c_str(), join_table_column.c_str(), join_table_column.c_str(), - join_table.c_str(), - join_table_column.c_str(), join_table_column.c_str(), join_table_column.c_str()); + const char *s = sqlite3_mprintf("select %s, * from \"%w\" where %s in (", + join_table_expression.c_str(), join_table.c_str(), join_table_expression.c_str()); std::string query = s; sqlite3_free((void *) s); @@ -258,7 +256,7 @@ void append_tile(std::string message, int z, unsigned x, unsigned y, std::map