@@ -270,32 +270,36 @@ def decode(code):
270
270
Note that short codes with an odd number of characters will have their
271
271
last character decoded using the grid refinement algorithm.
272
272
Args:
273
- shortCode : A valid short OLC character sequence.
273
+ code : A valid OLC character sequence.
274
274
referenceLatitude: The latitude (in signed decimal degrees) to use to
275
275
find the nearest matching full code.
276
276
referenceLongitude: The longitude (in signed decimal degrees) to use
277
277
to find the nearest matching full code.
278
278
Returns:
279
279
The nearest full Open Location Code to the reference location that matches
280
280
the short code. If the passed code was not a valid short code, but was a
281
- valid full code, it is returned unchanged.
282
- """
283
- def recoverNearest (shortcode , referenceLatitude , referenceLongitude ):
284
- if not isShort (shortcode ):
285
- raise ValueError ('Passed short code is not valid - ' + str (shortcode ))
281
+ valid full code, it is returned with proper capitalization but otherwise
282
+ unchanged.
283
+ """
284
+ def recoverNearest (code , referenceLatitude , referenceLongitude ):
285
+ # if code is a valid full code, return it properly capitalized
286
+ if isFull (code ):
287
+ return code .upper ()
288
+ if not isShort (code ):
289
+ raise ValueError ('Passed short code is not valid - ' + str (code ))
286
290
# Ensure that latitude and longitude are valid.
287
291
referenceLatitude = clipLatitude (referenceLatitude )
288
292
referenceLongitude = normalizeLongitude (referenceLongitude )
289
293
# Clean up the passed code.
290
- shortcode = shortcode .upper ()
294
+ code = code .upper ()
291
295
# Compute the number of digits we need to recover.
292
- paddingLength = SEPARATOR_POSITION_ - shortcode .find (SEPARATOR_ )
296
+ paddingLength = SEPARATOR_POSITION_ - code .find (SEPARATOR_ )
293
297
# The resolution (height and width) of the padded area in degrees.
294
298
resolution = pow (20 , 2 - (paddingLength / 2 ))
295
299
# Distance from the center to an edge (in degrees).
296
300
halfResolution = resolution / 2.0
297
301
# Use the reference location to pad the supplied short code and decode it.
298
- codeArea = decode (encode (referenceLatitude , referenceLongitude )[0 :paddingLength ] + shortcode )
302
+ codeArea = decode (encode (referenceLatitude , referenceLongitude )[0 :paddingLength ] + code )
299
303
# How many degrees latitude is the code from the reference? If it is more
300
304
# than half the resolution, we need to move it north or south but keep it
301
305
# within -90 to 90 degrees.
0 commit comments