Package sabx10 :: Package map :: Module glineenc
[hide private]
[frames] | no frames]

Module glineenc

source code

Encode a list of lat,lon points in the base64 format that Google Maps understands.

This is code (very) gratefully borrowed from the bycycle.org project. All credit goes to them. I simply took advantage of their good work.

Functions [hide private]
string,string
encode_pairs(points)
Encode a set of lat/long points.
source code
string, int
encode_lat_or_long(x, prev_int)
Encode a single latitude or longitude.
source code
 
encode_signed(n) source code
 
encode_unsigned(n) source code
 
douglas_peucker_distances(points) source code
 
distance(point, A, B)
Compute distance of point from line A, B.
source code
 
compute_level(distance)
Compute the appropriate zoom level of a point in terms of its distance from the relevant segment in the DP algorithm.
source code
 
test_encode_negative() source code
 
test_encode_positive() source code
 
test_encode_one_pair() source code
 
test_encode_pairs() source code
Variables [hide private]
  threshold = 1e-05
  num_levels = 4
  zoom_factor = 32
  zoom_level_breaks = [0.32768, 0.01024, 0.00032, 1e-05]
  __package__ = 'sabx10.map'
  i = 3
Function Details [hide private]

encode_pairs(points)

source code 

Encode a set of lat/long points. Generate:

  • An encoded string representing points within our error threshold,
  • An encoded string representing the maximum zoom level for each of those points

Example:

   >>> pairs = ((38.5, -120.2), (43.252, -126.453), (40.7, -120.95))
   >>> encode_pairs(pairs)
   ('_p~iF~ps|U_c_\\fhde@~lqNwxq`@', 'BBB')
Parameters:
  • points (list of (float,float)) - a list of lat/long points ((lat, long), ...) Note carefully that the order is latitude, longitude
Returns: string,string
points string, zoom string

encode_lat_or_long(x, prev_int)

source code 

Encode a single latitude or longitude.

Example:

   >>> x = -179.9832104
   >>> encoded_x, prev = encode_lat_or_long(x, 0)
   >>> encoded_x
   '`~oia@'
   >>> prev
   -17998321
   >>> x = -120.2
   >>> encode_lat_or_long(x, prev)
   ('al{kJ', -12020000)
Parameters:
  • x - the latitude or longitude to encode
  • prev_int - the integer value of the previous latitude or longitude
Returns: string, int
the encoded value and its int value, which is used