Skip to main content

Grid Point Code (GPC) – Python

Overview

Grid Point Code (GPC) is a geocoding system that gives any global geographic location a compact 11-character alphanumeric code. This Python implementation encodes and decodes between latitude/longitude coordinates and GPCs offline, at the format's fixed precision of five decimal places.

Features

  • Unique Global Codes: Every location is mapped to its own alphanumeric string.
  • Bi-directional Conversion: Exact at a fixed precision of 5 decimal places.
  • Offline Functionality: No network access required.
  • No Dependencies: Nothing beyond the Python standard library.
  • Formatted Output: Standardized format: #XXXX-XXXX-XXX.
  • Open Source: Available under the Apache License 2.0.

How It Works

  • Encoding: Converts latitude and longitude into an 11-character base-27 alphanumeric code.
  • Decoding: Converts a GPC string back to geographic coordinates.
  • Validation: Ensures coordinates and codes fall within valid ranges.
  • Formatting: Adds visual separators to GPCs for readability.

Installation

Install from PyPI:

pip install gridpointcode-algo-pranavpatel-ca

Requirements

Python 3.9 or later. No third-party dependencies.

Usage

Encoding Coordinates

from gridpointcode_algo_pranavpatel_ca import GPC

# Encode latitude and longitude into GPC
gpc_code = GPC.encode(43.65000, -79.38000)  # Toronto
print(gpc_code)  # Output: #FN5G-CDKL-HDC

Decoding a GPC

# Decode GPC into latitude and longitude
lat, lng = GPC.decode("#FN5G-CDKL-HDC")
print(lat, lng)

Validating a GPC

# Validate GPC format and range
valid, message = GPC.is_valid_gpc("#FN5G-CDKL-HDC")
print(valid, message)

Code Format

  • GPC Structure: #XXXX-XXXX-XXX (11 base-27 characters)
  • Alphabet: "CDFGHJKLMNPRTVWXY0123456789" (base-27)
  • Precision: 5 decimal places in latitude/longitude

Precision and Limits

  • A code addresses a cell of five decimal places of latitude and longitude, roughly 1.1 m across at the equator. decode returns the coordinates of that cell, so a value carrying more than five decimals does not come back unchanged: encoding and then decoding is exact only to the format's fixed precision.
  • Codes are not ordered by geography. Two codes that look alike may be anywhere on Earth, and two neighbouring locations may be given codes with nothing in common. Never read distance or containment out of the characters themselves; decode both codes and compare the coordinates.

Changelog

See CHANGELOG.md for what changed in each release.

License

Licensed under the Apache License, Version 2.0.

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests on GitHub.

Release files for gridpointcode-algo-pranavpatel-ca 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gridpointcode-algo-pranavpatel-ca 1.1.0
File Size Uploaded
gridpointcode_algo_pranavpatel_ca-1.1.0.tar.gz 13.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gridpointcode-algo-pranavpatel-ca 1.1.0
File Interpreter ABI Platform
gridpointcode_algo_pranavpatel_ca-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 25.8 kB

Release files / gridpointcode_algo_pranavpatel_ca-1.1.0.tar.gz

Download URL gridpointcode_algo_pranavpatel_ca-1.1.0.tar.gz
Size 13.1 kB
Tags Source
SHA-256 checksum
How to use checksums
bf584ebf8cdc642a07f9ff9c156c393c67aee425752c1a05142a474414ef26c5
BLAKE2b-256 checksum
How to use checksums
c16963d537b0146d4959c51d36f2b9aab92acf999d9949e0d09d00647f2efb6c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / gridpointcode_algo_pranavpatel_ca-1.1.0-py3-none-any.whl

Download URL gridpointcode_algo_pranavpatel_ca-1.1.0-py3-none-any.whl
Size 12.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2b78b539b51d17cc988b684bad69cabd118c80f8c31572908d277a9eca4995e3
BLAKE2b-256 checksum
How to use checksums
ed99ddb636d6c1497f6a2f641fab9336d49193e0cdca474ec428c4dc936d8989
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release history Release notifications | RSS feed

2.0.0

2 release files

This release

1.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page