An estafeta is a Panama postal office zone. Every estafeta has a human-readable name (e.g., “Estafeta de Paraiso”), a 2-character zone prefix that appears at the front of every postal code within its boundary (e.g.,Documentation Index
Fetch the complete documentation index at: https://mintlify.com/kass507/panama-postal/llms.txt
Use this file to discover all available pages before exploring further.
AC), an internal zone ID string, and a coverage area measured in square metres. Together, the estafeta prefix and the geographic body form a complete 10-character postal code.
The EstafetaIndex class in panama_postal_estafeta.py loads the official boundary polygons and resolves a coordinate pair to the estafeta that contains it — no network connection required once the file is downloaded.
The
estafeta.geojson.gz file is not included in the Panama Postal repository. It must be downloaded separately from the official government site before estafeta lookups will work.Downloading the Boundary File
EstafetaIndex.from_file()).
How EstafetaIndex Works
Loading the file parses the GeoJSON feature collection and builds a lightweight bounding-box index over every estafeta polygon. When you call lookup(), the index:
- Pre-filters candidates using the bounding box — any polygon whose bbox does not contain the point is skipped immediately.
- Runs ray-casting (point-in-polygon) on the remaining candidates for exact containment.
- Resolves overlaps — if a point falls inside more than one estafeta polygon, the one with the smallest
AREAvalue wins.
Polygon and MultiPolygon GeoJSON geometry types, and correctly handles polygons with holes (interior rings).
Properties Returned by lookup()
idx.lookup(lat, lng) returns a dictionary of raw GeoJSON feature properties, or None if the point does not fall inside any estafeta. The most useful fields are:
| Property | Description |
|---|---|
ESTAF_NAME | Human-readable estafeta name (e.g., "Estafeta de Paraiso") |
VM_LEVEL2D | The 2-character estafeta prefix used in postal codes (e.g., "AC") |
VM_LEVEL | Internal zone level string (e.g., "A6199") |
AREA | Coverage area in m² as a string — divide by 1e6 for km² |
Code Example
Using encode() with Estafeta Lookup
The encode() function returns only the 8-character geographic body of a code. To build the complete 10-character code, prepend the estafeta prefix obtained from EstafetaIndex:
Without the Boundary File
The core library functions —decode(), encode(), and validate() — work entirely without estafeta.geojson.gz. Only the estafeta name, zone code, and area enrichment are unavailable when the file is absent. The CLI will display a reminder with the download command at startup and will continue to decode and validate codes normally.