diff --git a/mapbox_vector_tile/encoder.py b/mapbox_vector_tile/encoder.py index f9697e7..f2058d3 100644 --- a/mapbox_vector_tile/encoder.py +++ b/mapbox_vector_tile/encoder.py @@ -66,6 +66,7 @@ def addFeatures(self, features, layer_name='', self.val_idx = 0 self.seen_keys_idx = {} self.seen_values_idx = {} + self.seen_values_bool_idx = {} for feature in features: @@ -284,8 +285,13 @@ def _handle_attr(self, layer, feature, props): feature.tags.append(self.seen_keys_idx[k]) - if v not in self.seen_values_idx: - self.seen_values_idx[v] = self.val_idx + if isinstance(v, bool): + values_idx = self.seen_values_bool_idx + else: + values_idx = self.seen_values_idx + + if v not in values_idx: + values_idx[v] = self.val_idx self.val_idx += 1 val = layer.values.add() @@ -303,4 +309,4 @@ def _handle_attr(self, layer, feature, props): elif isinstance(v, float): val.double_value = v - feature.tags.append(self.seen_values_idx[v]) + feature.tags.append(values_idx[v]) diff --git a/tests/test_encoder.py b/tests/test_encoder.py index b54a945..e2b39c7 100644 --- a/tests/test_encoder.py +++ b/tests/test_encoder.py @@ -490,6 +490,29 @@ def test_too_small_linestring(self): features = result['foo']['features'] self.assertEqual(0, len(features)) + def test_encode_1_True_values(self): + geometry = 'POINT(0 0)' + properties = { + 'foo': True, + 'bar': 1, + } + source = [{ + 'name': 'layer', + 'features': [{ + 'geometry': geometry, + 'properties': properties + }] + }] + encoded = encode(source) + decoded = decode(encoded) + layer = decoded['layer'] + features = layer['features'] + act_props = features[0]['properties'] + self.assertEquals(act_props['foo'], True) + self.assertEquals(act_props['bar'], 1) + self.assertTrue(isinstance(act_props['foo'], bool)) + self.assertFalse(isinstance(act_props['bar'], bool)) + class TestDictGeometries(BaseTestCase):