diff --git a/CHANGELOG.md b/CHANGELOG.md index 31d35b2..cbed223 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.32.4 + +* Ignore leading zeroes when converting string attributes to feature IDs + ## 1.32.3 * Add an option to convert stringified number feature IDs to numbers diff --git a/serial.cpp b/serial.cpp index 132aaed..6ef8605 100644 --- a/serial.cpp +++ b/serial.cpp @@ -373,6 +373,17 @@ static long long scale_geometry(struct serialization_state *sst, long long *bbox return geom.size(); } +static std::string strip_zeroes(std::string s) { + // Doesn't do anything special with '-' followed by leading zeros + // since integer IDs must be positive + + while (s.size() > 0 && s[0] == '0') { + s.erase(s.begin()); + } + + return s; +} + // called from frontends int serialize_feature(struct serialization_state *sst, serial_feature &sf) { struct reader *r = &(*sst->readers)[sst->segment]; @@ -595,7 +606,7 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf) { fprintf(stderr, "Warning: Can't represent non-integer feature ID %s\n", sf.full_values[i].s.c_str()); warned_frac = true; } - } else if (std::to_string(id_value) != sf.full_values[i].s) { + } else if (std::to_string(id_value) != strip_zeroes(sf.full_values[i].s)) { static bool warned = false; if (!warned) { diff --git a/tests/stringid/in.json b/tests/stringid/in.json index 83869dd..9c93409 100644 --- a/tests/stringid/in.json +++ b/tests/stringid/in.json @@ -9,3 +9,4 @@ { "type": "Feature", "id": 1234, "properties": { "yes": "no", "special": 27.5, "something": false }, "geometry": { "type": "Point", "coordinates": [ 9, 1 ] } } { "type": "Feature", "id": 1234, "properties": { "yes": "no", "special": 98237489273489274389728497289472839478297489274892734892, "something": false }, "geometry": { "type": "Point", "coordinates": [ 10, 1 ] } } { "type": "Feature", "properties": { "yes": "no", "special": 27, "something": false }, "geometry": { "type": "Point", "coordinates": [ 11, 1 ] } } +{ "type": "Feature", "properties": { "yes": "no", "special": "01005", "something": false }, "geometry": { "type": "Point", "coordinates": [ 12, 1 ] } } diff --git a/tests/stringid/out/-z0.json b/tests/stringid/out/-z0.json index 4e55f18..7ae6444 100644 --- a/tests/stringid/out/-z0.json +++ b/tests/stringid/out/-z0.json @@ -1,9 +1,9 @@ { "type": "FeatureCollection", "properties": { -"bounds": "1.000000,1.000000,11.000000,1.000000", +"bounds": "1.000000,1.000000,12.000000,1.000000", "center": "1.000000,1.000000,0", "description": "tests/stringid/out/-z0.json.check.mbtiles", "format": "pbf", -"json": "{\"vector_layers\": [ { \"id\": \"in\", \"description\": \"\", \"minzoom\": 0, \"maxzoom\": 0, \"fields\": {\"something\": \"Boolean\", \"special\": \"Mixed\", \"yes\": \"String\"} } ],\"tilestats\": {\"layerCount\": 1,\"layers\": [{\"layer\": \"in\",\"count\": 11,\"geometry\": \"Point\",\"attributeCount\": 3,\"attributes\": [{\"attribute\": \"something\",\"count\": 1,\"type\": \"boolean\",\"values\": [false]},{\"attribute\": \"special\",\"count\": 4,\"type\": \"mixed\",\"values\": [\"27\",27,27.5,9.823748927348929e+55],\"min\": 27,\"max\": 9.823748927348929e+55},{\"attribute\": \"yes\",\"count\": 1,\"type\": \"string\",\"values\": [\"no\"]}]}]}}", +"json": "{\"vector_layers\": [ { \"id\": \"in\", \"description\": \"\", \"minzoom\": 0, \"maxzoom\": 0, \"fields\": {\"something\": \"Boolean\", \"special\": \"Mixed\", \"yes\": \"String\"} } ],\"tilestats\": {\"layerCount\": 1,\"layers\": [{\"layer\": \"in\",\"count\": 12,\"geometry\": \"Point\",\"attributeCount\": 3,\"attributes\": [{\"attribute\": \"something\",\"count\": 1,\"type\": \"boolean\",\"values\": [false]},{\"attribute\": \"special\",\"count\": 5,\"type\": \"mixed\",\"values\": [\"01005\",\"27\",27,27.5,9.823748927348929e+55],\"min\": 27,\"max\": 9.823748927348929e+55},{\"attribute\": \"yes\",\"count\": 1,\"type\": \"string\",\"values\": [\"no\"]}]}]}}", "maxzoom": "0", "minzoom": "0", "name": "tests/stringid/out/-z0.json.check.mbtiles", @@ -33,6 +33,8 @@ { "type": "Feature", "id": 1234, "properties": { "yes": "no", "special": 9.823748927348929e+55, "something": false }, "geometry": { "type": "Point", "coordinates": [ 9.931641, 1.054628 ] } } , { "type": "Feature", "properties": { "yes": "no", "special": 27, "something": false }, "geometry": { "type": "Point", "coordinates": [ 10.986328, 1.054628 ] } } +, +{ "type": "Feature", "properties": { "yes": "no", "special": "01005", "something": false }, "geometry": { "type": "Point", "coordinates": [ 11.953125, 1.054628 ] } } ] } ] } ] } diff --git a/tests/stringid/out/-z0_--use-attribute-for-id_special.json b/tests/stringid/out/-z0_--use-attribute-for-id_special.json index 2d68ca9..c995162 100644 --- a/tests/stringid/out/-z0_--use-attribute-for-id_special.json +++ b/tests/stringid/out/-z0_--use-attribute-for-id_special.json @@ -1,9 +1,9 @@ { "type": "FeatureCollection", "properties": { -"bounds": "1.000000,1.000000,11.000000,1.000000", +"bounds": "1.000000,1.000000,12.000000,1.000000", "center": "1.000000,1.000000,0", "description": "tests/stringid/out/-z0_--use-attribute-for-id_special.json.check.mbtiles", "format": "pbf", -"json": "{\"vector_layers\": [ { \"id\": \"in\", \"description\": \"\", \"minzoom\": 0, \"maxzoom\": 0, \"fields\": {\"something\": \"Boolean\", \"special\": \"Mixed\", \"yes\": \"String\"} } ],\"tilestats\": {\"layerCount\": 1,\"layers\": [{\"layer\": \"in\",\"count\": 11,\"geometry\": \"Point\",\"attributeCount\": 3,\"attributes\": [{\"attribute\": \"something\",\"count\": 1,\"type\": \"boolean\",\"values\": [false]},{\"attribute\": \"special\",\"count\": 3,\"type\": \"mixed\",\"values\": [\"27\",27.5,9.823748927348929e+55],\"min\": 27.5,\"max\": 9.823748927348929e+55},{\"attribute\": \"yes\",\"count\": 1,\"type\": \"string\",\"values\": [\"no\"]}]}]}}", +"json": "{\"vector_layers\": [ { \"id\": \"in\", \"description\": \"\", \"minzoom\": 0, \"maxzoom\": 0, \"fields\": {\"something\": \"Boolean\", \"special\": \"Mixed\", \"yes\": \"String\"} } ],\"tilestats\": {\"layerCount\": 1,\"layers\": [{\"layer\": \"in\",\"count\": 12,\"geometry\": \"Point\",\"attributeCount\": 3,\"attributes\": [{\"attribute\": \"something\",\"count\": 1,\"type\": \"boolean\",\"values\": [false]},{\"attribute\": \"special\",\"count\": 4,\"type\": \"mixed\",\"values\": [\"01005\",\"27\",27.5,9.823748927348929e+55],\"min\": 27.5,\"max\": 9.823748927348929e+55},{\"attribute\": \"yes\",\"count\": 1,\"type\": \"string\",\"values\": [\"no\"]}]}]}}", "maxzoom": "0", "minzoom": "0", "name": "tests/stringid/out/-z0_--use-attribute-for-id_special.json.check.mbtiles", @@ -33,6 +33,8 @@ { "type": "Feature", "id": 1234, "properties": { "yes": "no", "special": 9.823748927348929e+55, "something": false }, "geometry": { "type": "Point", "coordinates": [ 9.931641, 1.054628 ] } } , { "type": "Feature", "id": 27, "properties": { "yes": "no", "something": false }, "geometry": { "type": "Point", "coordinates": [ 10.986328, 1.054628 ] } } +, +{ "type": "Feature", "properties": { "yes": "no", "special": "01005", "something": false }, "geometry": { "type": "Point", "coordinates": [ 11.953125, 1.054628 ] } } ] } ] } ] } diff --git a/tests/stringid/out/-z0_-aI.json b/tests/stringid/out/-z0_-aI.json index 38864f4..d74e045 100644 --- a/tests/stringid/out/-z0_-aI.json +++ b/tests/stringid/out/-z0_-aI.json @@ -1,9 +1,9 @@ { "type": "FeatureCollection", "properties": { -"bounds": "1.000000,1.000000,11.000000,1.000000", +"bounds": "1.000000,1.000000,12.000000,1.000000", "center": "1.000000,1.000000,0", "description": "tests/stringid/out/-z0_-aI.json.check.mbtiles", "format": "pbf", -"json": "{\"vector_layers\": [ { \"id\": \"in\", \"description\": \"\", \"minzoom\": 0, \"maxzoom\": 0, \"fields\": {\"something\": \"Boolean\", \"special\": \"Mixed\", \"yes\": \"String\"} } ],\"tilestats\": {\"layerCount\": 1,\"layers\": [{\"layer\": \"in\",\"count\": 11,\"geometry\": \"Point\",\"attributeCount\": 3,\"attributes\": [{\"attribute\": \"something\",\"count\": 1,\"type\": \"boolean\",\"values\": [false]},{\"attribute\": \"special\",\"count\": 4,\"type\": \"mixed\",\"values\": [\"27\",27,27.5,9.823748927348929e+55],\"min\": 27,\"max\": 9.823748927348929e+55},{\"attribute\": \"yes\",\"count\": 1,\"type\": \"string\",\"values\": [\"no\"]}]}]}}", +"json": "{\"vector_layers\": [ { \"id\": \"in\", \"description\": \"\", \"minzoom\": 0, \"maxzoom\": 0, \"fields\": {\"something\": \"Boolean\", \"special\": \"Mixed\", \"yes\": \"String\"} } ],\"tilestats\": {\"layerCount\": 1,\"layers\": [{\"layer\": \"in\",\"count\": 12,\"geometry\": \"Point\",\"attributeCount\": 3,\"attributes\": [{\"attribute\": \"something\",\"count\": 1,\"type\": \"boolean\",\"values\": [false]},{\"attribute\": \"special\",\"count\": 5,\"type\": \"mixed\",\"values\": [\"01005\",\"27\",27,27.5,9.823748927348929e+55],\"min\": 27,\"max\": 9.823748927348929e+55},{\"attribute\": \"yes\",\"count\": 1,\"type\": \"string\",\"values\": [\"no\"]}]}]}}", "maxzoom": "0", "minzoom": "0", "name": "tests/stringid/out/-z0_-aI.json.check.mbtiles", @@ -33,6 +33,8 @@ { "type": "Feature", "id": 1234, "properties": { "yes": "no", "special": 9.823748927348929e+55, "something": false }, "geometry": { "type": "Point", "coordinates": [ 9.931641, 1.054628 ] } } , { "type": "Feature", "properties": { "yes": "no", "special": 27, "something": false }, "geometry": { "type": "Point", "coordinates": [ 10.986328, 1.054628 ] } } +, +{ "type": "Feature", "properties": { "yes": "no", "special": "01005", "something": false }, "geometry": { "type": "Point", "coordinates": [ 11.953125, 1.054628 ] } } ] } ] } ] } diff --git a/tests/stringid/out/-z0_-aI_--use-attribute-for-id_special.json b/tests/stringid/out/-z0_-aI_--use-attribute-for-id_special.json index c3b5699..aad76e0 100644 --- a/tests/stringid/out/-z0_-aI_--use-attribute-for-id_special.json +++ b/tests/stringid/out/-z0_-aI_--use-attribute-for-id_special.json @@ -1,9 +1,9 @@ { "type": "FeatureCollection", "properties": { -"bounds": "1.000000,1.000000,11.000000,1.000000", +"bounds": "1.000000,1.000000,12.000000,1.000000", "center": "1.000000,1.000000,0", "description": "tests/stringid/out/-z0_-aI_--use-attribute-for-id_special.json.check.mbtiles", "format": "pbf", -"json": "{\"vector_layers\": [ { \"id\": \"in\", \"description\": \"\", \"minzoom\": 0, \"maxzoom\": 0, \"fields\": {\"something\": \"Boolean\", \"special\": \"Number\", \"yes\": \"String\"} } ],\"tilestats\": {\"layerCount\": 1,\"layers\": [{\"layer\": \"in\",\"count\": 11,\"geometry\": \"Point\",\"attributeCount\": 3,\"attributes\": [{\"attribute\": \"something\",\"count\": 1,\"type\": \"boolean\",\"values\": [false]},{\"attribute\": \"special\",\"count\": 2,\"type\": \"number\",\"values\": [27.5,9.823748927348929e+55],\"min\": 27.5,\"max\": 9.823748927348929e+55},{\"attribute\": \"yes\",\"count\": 1,\"type\": \"string\",\"values\": [\"no\"]}]}]}}", +"json": "{\"vector_layers\": [ { \"id\": \"in\", \"description\": \"\", \"minzoom\": 0, \"maxzoom\": 0, \"fields\": {\"something\": \"Boolean\", \"special\": \"Number\", \"yes\": \"String\"} } ],\"tilestats\": {\"layerCount\": 1,\"layers\": [{\"layer\": \"in\",\"count\": 12,\"geometry\": \"Point\",\"attributeCount\": 3,\"attributes\": [{\"attribute\": \"something\",\"count\": 1,\"type\": \"boolean\",\"values\": [false]},{\"attribute\": \"special\",\"count\": 2,\"type\": \"number\",\"values\": [27.5,9.823748927348929e+55],\"min\": 27.5,\"max\": 9.823748927348929e+55},{\"attribute\": \"yes\",\"count\": 1,\"type\": \"string\",\"values\": [\"no\"]}]}]}}", "maxzoom": "0", "minzoom": "0", "name": "tests/stringid/out/-z0_-aI_--use-attribute-for-id_special.json.check.mbtiles", @@ -33,6 +33,8 @@ { "type": "Feature", "id": 1234, "properties": { "yes": "no", "special": 9.823748927348929e+55, "something": false }, "geometry": { "type": "Point", "coordinates": [ 9.931641, 1.054628 ] } } , { "type": "Feature", "id": 27, "properties": { "yes": "no", "something": false }, "geometry": { "type": "Point", "coordinates": [ 10.986328, 1.054628 ] } } +, +{ "type": "Feature", "id": 1005, "properties": { "yes": "no", "something": false }, "geometry": { "type": "Point", "coordinates": [ 11.953125, 1.054628 ] } } ] } ] } ] } diff --git a/version.hpp b/version.hpp index d6eb94c..6dae7da 100644 --- a/version.hpp +++ b/version.hpp @@ -1,6 +1,6 @@ #ifndef VERSION_HPP #define VERSION_HPP -#define VERSION "v1.32.3" +#define VERSION "v1.32.4" #endif