-
Notifications
You must be signed in to change notification settings - Fork 7
/
__init__.py
52 lines (44 loc) · 1.07 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""Example of python-vtzero usage."""
from vtzero.tile import Layer, Linestring, Point, Polygon, Tile, VectorTile
# Create MVT
tile = Tile()
# Add a layer
layer = Layer(tile, b"my_layer")
# Add a point
feature = Point(layer)
feature.add_points(1)
feature.set_point(10, 10)
feature.add_property(b"foo", b"bar")
feature.add_property(b"x", b"y")
feature.commit()
# Add a polygon
feature = Polygon(layer)
feature.add_ring(5)
feature.set_point(0, 0)
feature.set_point(1, 0)
feature.set_point(1, 1)
feature.set_point(0, 1)
feature.close_ring()
feature.commit()
# Add a line
feature = Linestring(layer)
feature.add_linestring(3)
feature.set_point(0, 0)
feature.set_point(1, 1)
feature.set_point(2, 2)
feature.commit()
# Encode mvt
data = tile.serialize()
# Decode MVT and print info
tile = VectorTile(data)
layer = next(tile)
print(f"Layer Name: {layer.name.decode()}")
print(f"MVT version: {layer.version}")
print(f"MVT extent: {layer.extent}")
features = []
while True:
f = next(layer)
if f.geometry_type == 0:
break
features.append(f)
print(f"Nb Features: {len(features)}")