PK!kI""encpoly/__init__.pyfrom .codec import encode, decode PK!Qssencpoly/codec.py""" - Release v0.1.0 - Test precision - Docs - CLI (`polyline --encode --geojson blah`; LineString Feature only) - From/to GeoJSON """ from itertools import chain from math import floor, ceil from operator import sub def polyline_round(number): """ >>> polyline_round(0) 0 >>> polyline_round(1) 1 >>> polyline_round(-1) -1 >>> polyline_round(0.5) 1 >>> polyline_round(-0.5) -1 """ if number > 0: return floor(number + 0.5) else: return ceil(number - 0.5) def encode_coord(coord, precision): coord = polyline_round(coord * precision) << 1 if coord < 0: coord = ~coord encoded_coord = "" while coord >= 0x20: encoded_coord += chr((0x20 | (coord & 0x1F)) + 63) coord >>= 5 encoded_coord += chr(coord + 63) return encoded_coord def encode(locations, precision=5): """ Approx 35% faster. """ precision = 10 ** precision encoded_coords = [] prev_location = (0, 0) for location in locations: encoded_coords.append( encode_coord(p, precision) for p in map(sub, location, prev_location) ) prev_location = location return "".join(chain(*encoded_coords)) def decode_coords(polyline): coord = 0 shift = 0 for char in map(ord, polyline): char -= 63 coord |= (char & 0x1F) << shift shift += 5 if char < 0x20: coord >>= 1 yield ~coord if coord & 1 else coord coord = 0 shift = 0 def decode(polyline, precision=5): """ Approx. 20% faster. """ precision = 10 ** precision prev_location = (0, 0) i = decode_coords(polyline) for coord in i: location = [coord + prev_location[0], next(i) + prev_location[1]] yield [p / precision for p in location] prev_location = location PK!HڽTUencpoly-0.1.0.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!H2q0  encpoly-0.1.0.dist-info/METADATAUo6~_qKln7cɚ͌8ًa uR"CR^ {4^!y1{I]M`N+^F]:f'8Zen3yo6d'-7 d.8Z q)Y!\[2]S%M$'G}τ.?+Ud_L YR/=\O>()] CwzsJ^IS%Xbr[9ZX-XZKkZz!WWbhSQ{{#APK!kI""encpoly/__init__.pyPK!QssSencpoly/codec.pyPK!HڽTUencpoly-0.1.0.dist-info/WHEELPK!H2q0  encpoly-0.1.0.dist-info/METADATAPK!Hka encpoly-0.1.0.dist-info/RECORDPKd