diff --git a/README.md b/README.md index d8f197a..1f3e631 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,7 @@ resolution is obtained than by using a smaller _maxzoom_ or _detail_. * `-X` or `--exclude-all`: Exclude all properties and encode only geometries * `-T`_attribute_`:`_type_ or `--attribute-type=`_attribute_`:`_type_: Coerce the named feature _attribute_ to be of the specified _type_. The _type_ may be `string`, `float`, `int`, or `bool`. - If the type is `bool`, then original attributes of `0`, `false`, `null`, or the empty string become `false`, and otherwise become `true`. + If the type is `bool`, then original attributes of `0` (or, if numeric, `0.0`, etc.), `false`, `null`, or the empty string become `false`, and otherwise become `true`. If the type is `float` or `int` and the original attribute was non-numeric, it becomes `0`. If the type is `int` and the original attribute was floating-point, it is rounded to the nearest integer. diff --git a/man/tippecanoe.1 b/man/tippecanoe.1 index b3c0b3e..7bea721 100644 --- a/man/tippecanoe.1 +++ b/man/tippecanoe.1 @@ -173,7 +173,7 @@ resolution is obtained than by using a smaller \fImaxzoom\fP or \fIdetail\fP\&. .IP \(bu 2 \fB\fC\-T\fR\fIattribute\fP\fB\fC:\fR\fItype\fP or \fB\fC\-\-attribute\-type=\fR\fIattribute\fP\fB\fC:\fR\fItype\fP: Coerce the named feature \fIattribute\fP to be of the specified \fItype\fP\&. The \fItype\fP may be \fB\fCstring\fR, \fB\fCfloat\fR, \fB\fCint\fR, or \fB\fCbool\fR\&. -If the type is \fB\fCbool\fR, then original attributes of \fB\fC0\fR, \fB\fCfalse\fR, \fB\fCnull\fR, or the empty string become \fB\fCfalse\fR, and otherwise become \fB\fCtrue\fR\&. +If the type is \fB\fCbool\fR, then original attributes of \fB\fC0\fR (or, if numeric, \fB\fC0.0\fR, etc.), \fB\fCfalse\fR, \fB\fCnull\fR, or the empty string become \fB\fCfalse\fR, and otherwise become \fB\fCtrue\fR\&. If the type is \fB\fCfloat\fR or \fB\fCint\fR and the original attribute was non\-numeric, it becomes \fB\fC0\fR\&. If the type is \fB\fCint\fR and the original attribute was floating\-point, it is rounded to the nearest integer. .RE diff --git a/serial.cpp b/serial.cpp index 62ca440..b0015d6 100644 --- a/serial.cpp +++ b/serial.cpp @@ -622,7 +622,7 @@ void coerce_value(std::string const &key, int &vt, std::string &val, std::mapsecond == mvt_bool) { - if (val == "false" || val == "0" || val == "null" || val.size() == 0) { + if (val == "false" || val == "0" || val == "null" || val.size() == 0 || (vt == mvt_double && atof(val.c_str()) == 0)) { vt = mvt_bool; val = "false"; } else { diff --git a/tests/attribute-type/in.json b/tests/attribute-type/in.json index 9744fe3..da36ce2 100644 --- a/tests/attribute-type/in.json +++ b/tests/attribute-type/in.json @@ -7,7 +7,7 @@ { "type": "Feature", "properties": { "booltype": "false", "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } } { "type": "Feature", "properties": { "booltype": true, "expect": true }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } } { "type": "Feature", "properties": { "booltype": 1, "expect": true }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } } -{ "type": "Feature", "properties": { "booltype": 0.0, "expect": true }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } } +{ "type": "Feature", "properties": { "booltype": 0.0, "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } } { "type": "Feature", "properties": { "booltype": "yes", "expect": true }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } } { "type": "Feature", "properties": { "booltype": [ 2, 3 ], "expect": true }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } } { "type": "Feature", "properties": { "stringtype": null, "expect": "null" }, "geometry": { "type": "Point", "coordinates": [ 0,0 ] } } diff --git a/tests/attribute-type/out/-z0_-Tinttype@int_-Tfloattype@float_-Tbooltype@bool_-Tstringtype@string.json b/tests/attribute-type/out/-z0_-Tinttype@int_-Tfloattype@float_-Tbooltype@bool_-Tstringtype@string.json index b69c465..1b60e70 100644 --- a/tests/attribute-type/out/-z0_-Tinttype@int_-Tfloattype@float_-Tbooltype@bool_-Tstringtype@string.json +++ b/tests/attribute-type/out/-z0_-Tinttype@int_-Tfloattype@float_-Tbooltype@bool_-Tstringtype@string.json @@ -30,7 +30,7 @@ , { "type": "Feature", "properties": { "booltype": true, "expect": true }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } } , -{ "type": "Feature", "properties": { "booltype": true, "expect": true }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } } +{ "type": "Feature", "properties": { "booltype": false, "expect": false }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } } , { "type": "Feature", "properties": { "booltype": true, "expect": true }, "geometry": { "type": "Point", "coordinates": [ 0.000000, 0.000000 ] } } ,