Skip to content

Commit

Permalink
Merge pull request #7 from sharedstreets/migurski/update-tiles-180312
Browse files Browse the repository at this point in the history
Update tiles to spec v0.02 (2018-03-12)
  • Loading branch information
migurski authored Apr 15, 2018
2 parents 5b51316 + 8294077 commit 02e288d
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 30 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,15 @@ Python implementation of [SharedStreets Reference System](https://github.com/sha

gunicorn sharedstreets.webapp:app

## API
## Protobufs

Current `.proto` files can can be found at
[sharedstreets/sharedstreets-ref-system](https://github.com/sharedstreets/sharedstreets-ref-system/tree/master/proto).

[Install `protoc`](https://github.com/google/protobuf) and
[follow Python directions](https://developers.google.com/protocol-buffers/docs/reference/python-generated#invocation)
to regenerate `sharedstreets/sharedstreets_pb2.py` if necessary:

protoc --proto_path=sharedstreets-ref-system/proto \
--python_out=sharedstreets-python/sharedstreets \
sharedstreets-ref-system/proto/sharedstreets.proto
7 changes: 7 additions & 0 deletions sharedstreets/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ def main():
buffer = file.read()
n = 0
while n < len(buffer):
print('=' * 80)
print('bytes', n, end=' ')

msg_len, new_pos = _DecodeVarint32(buffer, n)
n = new_pos
msg_buf = buffer[n:n+msg_len]
n += msg_len

print('to', n, '--', msg_buf[:12].hex(), '...', msg_buf[-12:].hex())

if ProtobufClass is None:
for ProtobufClass in protobuf_classes:
test_object = ProtobufClass()
Expand All @@ -45,6 +50,8 @@ def main():
print('ok:', ProtobufClass)
break

print(' -' * 40)

object = ProtobufClass()
object.ParseFromString(msg_buf)
print(object)
52 changes: 33 additions & 19 deletions sharedstreets/sharedstreets_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions sharedstreets/tests/data/20180312-geometry.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
�
80832506185371acf24df519ce271d31 bd188f40bcf79a5f0ea449d517634256 bcf50f7542fa573650bb988664e29a61" d972d167f9874b1367961cbd5c8cba04* 157e6746fc5ed0df77971ca8c7831f270:PV2[�^�+~���B@Q���ʒ^�n����B@���’^��|ޯ�B@�C�Y’^��f
��B@K�����^��6���B@�
80a8a7c120332bfb679f877472c9c18d b538bf59f065f54cf3c6f6113870c0ea dccf37896f270405fe288e9c6ec20422" 4bc556d4b905bb2bf789d77ea257c9f1* 09af6339fc020e47daf0039176308e890: r9���^�~�8h
�B@- ��ؒ^��=� �B@�
82b5776e9fcce1c64a431a14bd59b15d ccc0fe7c9d2a9b1836ffe2d88ceceacb cf1838fe859aceec5f54bad0c35e3731" bad3720e86397a9164ea532c2d209ac70:��j��1�^������B@Q�o!4�^��#01��B@-V�4�^���-���B@㡔5�^���r?��B@���G6�^��A{���B@gh��6�^��~ ���B@��#7�^����:��B@[X�k8�^��O����B@
Expand Down
4 changes: 4 additions & 0 deletions sharedstreets/tests/data/20180312-intersection.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
�
80ff395c936bb42f328b1eb872174ea9Բ�����ګ�^�!~�H��B@* 5a7b79e6b6bb2e4e66e436c1aa973342* d0ca85d13b170d468ac5b00d1fd8aad92 0da054dff7510a1e4f9d80bda17e844c~
81b8be7e93822aa8aec950aec959bfd8��©]�~y�^�!��uc�B@* f76daca404bbf712ce3031b537ac000e2 d0651bbbfa5f63ca952d38cfb8641bab�
81966cd8b3352f5b819009bffb0ff6c1�ͧ���2h�^�!�)���B@* 712284b01661708e941a730d059be17f* 0fb5dc53986ecdcce8710a7c702822402 98199156d499a69bd23538fb5fea30712 d19a3e4b75cfdc353c55b163048ddd40
8 changes: 8 additions & 0 deletions sharedstreets/tests/data/20180312-metadata.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
W
80832506185371acf24df519ce271d313
���2����ا���������اCarleton Street:
80a8a7c120332bfb679f877472c9c18d
�ס�2
��������r
82b5776e9fcce1c64a431a14bd59b15dN
2ᦩ2'ۧ�/��������Ӳ������Բ�������篶West MacArthur Boulevard
10 changes: 10 additions & 0 deletions sharedstreets/tests/data/20180312-reference.pbf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
�
0da8eb83f863b1c7484e3705230e4632 4c6740bae7b8ed7fc15b4f79ade6af82"9
8b60a7a14db65f50b3138cdd1a29c3b8~5�N�^�4���B@(O0�N"6
8739b929eae329e18ec631c8363206deՍ����^�&����B@ _�
f61c335244e8222f9c31b6eb14fea48a 1f624570a89b260bc88e97509be49c96"9
d4715dff9b7de5b5dcd107d127f9ffd2?�4�^�$��t�B@( 0�F"6
988b0c91439ae6663ddc2b0d4808185c��%+�^�0�0!��B@ �
c99662b7d646b3f930abc1cbf3e7290c 1f624570a89b260bc88e97509be49c96":
988b0c91439ae6663ddc2b0d4808185c��%+�^�0�0!��B@(�0�F"7
d4715dff9b7de5b5dcd107d127f9ffd2?�4�^�$��t�B@ �
100 changes: 91 additions & 9 deletions sharedstreets/tests/test_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,92 @@ def respond_locally(url, request):

class TestTile (unittest.TestCase):

def test_iter_objects_intersection(self):
def test_iter_objects_20180312_intersection(self):

with httmock.HTTMock(respond_locally):
intersections = tile.iter_objects('http://example.com/intersection.pbf',
intersections = tile.iter_objects('http://example.com/20180312-intersection.pbf',
tile.data_classes['intersection'])
i1, i2, i3 = list(intersections)

self.assertEqual(i1.id, '80ff395c936bb42f328b1eb872174ea9')
self.assertEqual((i1.lon, i1.lat), (-122.26048920000001, 37.8110133))

self.assertEqual(i2.id, '81b8be7e93822aa8aec950aec959bfd8')
self.assertEqual((i2.lon, i2.lat), (-122.2730403, 37.8311603))

self.assertEqual(i3.id, '81966cd8b3352f5b819009bffb0ff6c1')
self.assertEqual((i3.lon, i3.lat), (-122.2876097, 37.8022963))

def test_iter_objects_20180312_geometry(self):

with httmock.HTTMock(respond_locally):
geometries = tile.iter_objects('http://example.com/20180312-geometry.pbf',
tile.data_classes['geometry'])
g1, g2, g3 = list(geometries)

self.assertEqual(g1.id, '80832506185371acf24df519ce271d31')
self.assertEqual(g1.lonlats[0:2], [-122.2951692, 37.8564139])
self.assertEqual(len(g1.lonlats), 10)

self.assertEqual(g2.id, '80a8a7c120332bfb679f877472c9c18d')
self.assertEqual(g2.lonlats[0:2], [-122.2926467, 37.7971926])
self.assertEqual(len(g2.lonlats), 4)

self.assertEqual(g3.id, '82b5776e9fcce1c64a431a14bd59b15d')
self.assertEqual(g3.lonlats[0:2], [-122.28428740000001, 37.827691900000005])
self.assertEqual(len(g3.lonlats), 16)

def test_iter_objects_20180312_reference(self):

with httmock.HTTMock(respond_locally):
references = tile.iter_objects('http://example.com/20180312-reference.pbf',
tile.data_classes['reference'])
r1, r2, r3 = list(references)

self.assertEqual(r1.id, '0da8eb83f863b1c7484e3705230e4632')
self.assertEqual(r1.geometryId, '4c6740bae7b8ed7fc15b4f79ade6af82')
self.assertEqual(len(r1.locationReferences), 2)
self.assertEqual(r1.locationReferences[0].intersectionId, '8b60a7a14db65f50b3138cdd1a29c3b8')
self.assertEqual(r1.locationReferences[1].intersectionId, '8739b929eae329e18ec631c8363206de')

self.assertEqual(r2.id, 'f61c335244e8222f9c31b6eb14fea48a')
self.assertEqual(r2.geometryId, '1f624570a89b260bc88e97509be49c96')
self.assertEqual(len(r2.locationReferences), 2)
self.assertEqual(r2.locationReferences[0].intersectionId, 'd4715dff9b7de5b5dcd107d127f9ffd2')
self.assertEqual(r2.locationReferences[1].intersectionId, '988b0c91439ae6663ddc2b0d4808185c')

self.assertEqual(r3.id, 'c99662b7d646b3f930abc1cbf3e7290c')
self.assertEqual(r3.geometryId, '1f624570a89b260bc88e97509be49c96')
self.assertEqual(len(r3.locationReferences), 2)
self.assertEqual(r3.locationReferences[0].intersectionId, '988b0c91439ae6663ddc2b0d4808185c')
self.assertEqual(r3.locationReferences[1].intersectionId, 'd4715dff9b7de5b5dcd107d127f9ffd2')

def test_iter_objects_20180312_metadata(self):

with httmock.HTTMock(respond_locally):
metadata = tile.iter_objects('http://example.com/20180312-metadata.pbf',
tile.data_classes['metadata'])
m1, m2, m3 = list(metadata)

self.assertEqual(m1.geometryId, '80832506185371acf24df519ce271d31')
self.assertEqual(len(m1.osmMetadata.waySections), 1)
self.assertEqual(m1.osmMetadata.waySections[0].wayId, 6346743)
self.assertEqual(m1.osmMetadata.name, 'Carleton Street')

self.assertEqual(m2.geometryId, '80a8a7c120332bfb679f877472c9c18d')
self.assertEqual(len(m2.osmMetadata.waySections), 1)
self.assertEqual(m2.osmMetadata.waySections[0].wayId, 405302258)
self.assertEqual(m2.osmMetadata.name, '')

self.assertEqual(m3.geometryId, '82b5776e9fcce1c64a431a14bd59b15d')
self.assertEqual(len(m3.osmMetadata.waySections), 1)
self.assertEqual(m3.osmMetadata.waySections[0].wayId, 11162465)
self.assertEqual(m3.osmMetadata.name, 'West MacArthur Boulevard')

def test_iter_objects_20180307_intersection(self):

with httmock.HTTMock(respond_locally):
intersections = tile.iter_objects('http://example.com/20180307-intersection.pbf',
tile.data_classes['intersection'])
i1, i2, i3 = list(intersections)

Expand All @@ -29,10 +111,10 @@ def test_iter_objects_intersection(self):
self.assertEqual(i3.id, '80e533ecdcc667e37c9473c4b6fdb03d')
self.assertEqual((i3.lon, i3.lat), (-122.28473890000001, 37.840128500000006))

def test_iter_objects_geometry(self):
def test_iter_objects_20180307_geometry(self):

with httmock.HTTMock(respond_locally):
geometries = tile.iter_objects('http://example.com/geometry.pbf',
geometries = tile.iter_objects('http://example.com/20180307-geometry.pbf',
tile.data_classes['geometry'])
g1, g2, g3 = list(geometries)

Expand All @@ -48,10 +130,10 @@ def test_iter_objects_geometry(self):
self.assertEqual(g3.lonlats[0:2], [-122.25996420000001, 37.853876400000004])
self.assertEqual(len(g3.lonlats), 6)

def test_iter_objects_reference(self):
def test_iter_objects_20180307_reference(self):

with httmock.HTTMock(respond_locally):
references = tile.iter_objects('http://example.com/reference.pbf',
references = tile.iter_objects('http://example.com/20180307-reference.pbf',
tile.data_classes['reference'])
r1, r2, r3 = list(references)

Expand All @@ -73,10 +155,10 @@ def test_iter_objects_reference(self):
self.assertEqual(r3.locationReferences[0].intersectionId, '38d5bb092bc572bd305a7812f0c8c0bf')
self.assertEqual(r3.locationReferences[1].intersectionId, '0ad982f6c3e46b256115742f49da8da5')

def test_iter_objects_metadata(self):
def test_iter_objects_20180307_metadata(self):

with httmock.HTTMock(respond_locally):
metadata = tile.iter_objects('http://example.com/metadata.pbf',
metadata = tile.iter_objects('http://example.com/20180307-metadata.pbf',
tile.data_classes['metadata'])
m1, m2, m3 = list(metadata)

Expand All @@ -95,7 +177,7 @@ def test_iter_objects_metadata(self):
def test_is_inside(self):

with httmock.HTTMock(respond_locally):
geometries = tile.iter_objects('http://example.com/geometry.pbf',
geometries = tile.iter_objects('http://example.com/20180307-geometry.pbf',
tile.data_classes['geometry'])

# 11th Street between Castro & MLK
Expand Down
2 changes: 1 addition & 1 deletion sharedstreets/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
logger = logging.getLogger(__name__)

# https://github.com/sharedstreets/sharedstreets-ref-system/issues/16
data_url_template, data_zoom = 'https://tiles.sharedstreets.io/{z}-{x}-{y}.{layer}.pbf', 12
data_url_template, data_zoom = 'https://tiles.sharedstreets.io/osm/planet-180312/{z}-{x}-{y}.{layer}.6.pbf', 12
data_classes = {
'reference': sharedstreets_pb2.SharedStreetsReference,
'intersection': sharedstreets_pb2.SharedStreetsIntersection,
Expand Down

0 comments on commit 02e288d

Please sign in to comment.