User:Eleanorg/Thematic1.1/Manipulate Longitude 2 - percent

From XPUB & Lens-Based wiki
< User:Eleanorg
Revision as of 15:44, 30 November 2011 by Eleanorg (talk | contribs) (Created page with "Converts any number within a given range into a percentage value, based on its position within the range. In this case, the number is a longitude value, which is converted to an ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Converts any number within a given range into a percentage value, based on its position within the range. In this case, the number is a longitude value, which is converted to an integer between 12528 and 41285.

Heavily commented for your viewing pleasure. <script type=python> import re


      1. convert longitude into 5 digit integer

longitude = str(001.2528) # must be a string for regex to work longint = int(re.sub("\.", "", longitude)) # removes decimal point and converts back to an integer

      1. convert integer into percentage of given range
  1. converts longitude into a percentage, where 1.2528 = 0% and 4.1285 = 100%
  2. range between numbers is 28703, so 1% of range is 28703/100 ---> 287.03. Longitude equivalent to 1% will be 12528 + (28703/100)
  3. thus to convert longitude to percentage, work out its distance from 12528 and divide this distance by 287.03.

percent = int((longint - 12528) / 287.03) </script>