### Install Cartographer Elixir Library Source: https://context7.com/afronski/cartographer/llms.txt Instructions for adding the Cartographer Elixir library to your project's dependencies in the `mix.exs` file. This ensures the library is available for use in your Elixir application. ```elixir defp deps do [ {:cartographer, "~> 0.0.1"} ] end ``` -------------------------------- ### Get Base32 Alphabet Size (Elixir) Source: https://context7.com/afronski/cartographer/llms.txt Returns the size of a single character in the base32 alphabet, which is 5 bits. This utility function is helpful when calculating precision requirements for geohash operations. ```elixir iex> Cartographer.base32_size() 5 ``` -------------------------------- ### Convert Bitstring to Geohash String (Elixir) Source: https://context7.com/afronski/cartographer/llms.txt Converts a bitstring into a geohash string using the base32 alphabet. This is a low-level conversion function used internally by the encoder. It supports custom alphabets and word sizes for specialized encoding schemes. ```elixir # Convert 5-bit values to geohash characters iex> Cartographer.to_geohash(<<0::5>>) "0" iex> Cartographer.to_geohash(<<31::5>>) "z" # Convert multi-bit sequences iex> Cartographer.to_geohash(<<0::1, 0::1, 1::1, 0::1, 1::1>>) "5" # Empty bitstring returns empty string iex> Cartographer.to_geohash(<<>>) "" # Custom binary alphabet with 1-bit word size iex> Cartographer.to_geohash(<<0::5>>, "ab", 1) "aaaaa" iex> Cartographer.to_geohash(<<31::5>>, "ab", 1) "bbbbb" iex> Cartographer.to_geohash(<<10::5>>, "ab", 1) "ababa" ``` -------------------------------- ### Decode Geohash to Coordinates (Elixir) Source: https://context7.com/afronski/cartographer/llms.txt Decodes a geohash string back into latitude and longitude coordinates. An optional precision parameter controls the number of decimal places in the output (default 1). Shorter geohashes result in coordinates with larger error margins. ```elixir # Decode a single character geohash (low precision) iex> Cartographer.Decoder.from_geohash("0") {-67.5, -157.5} # Decode a 5-character geohash iex> Cartographer.Decoder.from_geohash("ezs42") {42.6, -5.6} # Round-trip encoding and decoding with integer precision iex> coords = {45, 90} iex> geohash = Cartographer.Encoder.to_base32_geohash(45, 90, 4) iex> Cartographer.Decoder.from_geohash(geohash, 0) {45.0, 90.0} # Higher precision decoding (3 decimal places) requires longer geohash iex> geohash = Cartographer.Encoder.to_base32_geohash(52.233, 21.017, 9) iex> Cartographer.Decoder.from_geohash(geohash, 3) {52.233, 21.017} ``` -------------------------------- ### Calculate Total Bits for Geohash Length (Elixir) Source: https://context7.com/afronski/cartographer/llms.txt Calculates the total number of bits required for a geohash of a specified length. This is useful for understanding the precision and storage requirements of geohashes. It depends on the Cartographer.base32_size() function to determine the number of bits per character. ```elixir iex> geohash_length = 9 iex> total_bits = geohash_length * Cartographer.base32_size() 45 ``` -------------------------------- ### Convert Geohash String to Bitstring (Elixir) Source: https://context7.com/afronski/cartographer/llms.txt Converts a geohash string back into a bitstring representation. This is the inverse of `to_geohash/3` and is used internally by the decoder. It also supports custom alphabets for specialized decoding. ```elixir # Convert geohash characters to 5-bit values iex> Cartographer.to_bits("0") <<0::5>> iex> Cartographer.to_bits("z") <<31::5>> iex> Cartographer.to_bits("5") <<0::1, 0::1, 1::1, 0::1, 1::1>> # Empty string returns empty bitstring iex> Cartographer.to_bits("") <<>> # Custom binary alphabet with 1-bit word size iex> Cartographer.to_bits("aaaaa", "ab", 1) <<0::5>> iex> Cartographer.to_bits("bbbbb", "ab", 1) <<31::5>> iex> Cartographer.to_bits("ababa", "ab", 1) <<10::5>> ``` -------------------------------- ### Encode Coordinates to Base32 Geohash (Elixir) Source: https://context7.com/afronski/cartographer/llms.txt Encodes latitude and longitude coordinates into a base32 geohash string. Supports default precision (4 characters) or custom string lengths for higher accuracy. Valid latitude range is -90 to 90, and longitude range is -180 to 180. ```elixir # Encode coordinates with default precision (4 characters) iex> Cartographer.Encoder.to_base32_geohash(0.0, 0.0) "s000" # Encode with custom precision (9 characters for high accuracy) iex> Cartographer.Encoder.to_base32_geohash(52.2333, 21.0167, 9) "u3qcnhzch" # Encode Warsaw, Poland coordinates iex> Cartographer.Encoder.to_base32_geohash(52.2333, 21.0167, 9) "u3qcnhzch" # Encode Aalborg, Denmark coordinates with 11-character precision iex> Cartographer.Encoder.to_base32_geohash(57.64911, 10.40744, 11) "u4pruydqqvj" # Edge cases - coordinate boundaries iex> Cartographer.Encoder.to_base32_geohash(90.0, 180.0) "zzzz" iex> Cartographer.Encoder.to_base32_geohash(-90.0, -180.0) "0000" # Negative coordinates iex> Cartographer.Encoder.to_base32_geohash(-1.0, -1.0) "7zz6" # Positive coordinates iex> Cartographer.Encoder.to_base32_geohash(1.0, 1.0) "s00t" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.