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.
EstafetaIndex is a spatial index that loads Panama’s estafeta boundary polygons from a GeoJSON file and resolves any geographic coordinate to the estafeta that contains it. Internally it combines a bounding-box pre-filter with a ray-casting point-in-polygon algorithm to keep lookups fast even when hundreds of polygon features are loaded.
estafeta.geojson.gz is not bundled in the repository. Download it from the official government endpoint before use:Constructor
"geometry" and "properties" keys). Features missing a geometry or whose bounding box cannot be computed are silently skipped.
A list of GeoJSON feature objects. Each entry must contain a
"geometry" key
with a Polygon or MultiPolygon geometry and an optional "properties" dict.
Pass an empty list to create an empty index.Class Methods
EstafetaIndex.from_file()
Path to the GeoJSON data file. Files ending in
.gz are transparently
decompressed with gzip; any other extension is read as plain UTF-8 JSON.A fully populated
EstafetaIndex instance ready for lookup() calls.Instance Methods
lookup()
- Bounding-box pre-filter — only features whose
(min_lng, min_lat, max_lng, max_lat)envelope contains the point proceed to the next stage. - Ray-casting point-in-polygon — each candidate polygon (or MultiPolygon component) is tested with the ray-casting algorithm. Exterior rings determine containment; interior rings (holes) exclude the point.
AREA value is returned.
Latitude of the point to look up, in decimal degrees (WGS 84).
Longitude of the point to look up, in decimal degrees (WGS 84).
The
"properties" dict of the matching estafeta feature, or None if the
point falls outside every loaded polygon.len() Support
Usage Example
Internal Helpers
The following module-level functions implement the geometry engine. They are used internally byEstafetaIndex and do not need to be called directly.
| Function | Description |
|---|---|
_point_in_ring(lng, lat, ring) | Ray-casting test for a single closed ring ([lng, lat] coordinate pairs). Applies the parity rule: each ray crossing toggles inside/outside. |
_point_in_polygon(lng, lat, polygon) | Tests a full GeoJSON Polygon (list of rings). The point must be inside the outer ring and outside every hole ring. |
_feature_contains(lng, lat, geom) | Dispatches to _point_in_polygon for Polygon geometries and iterates over parts for MultiPolygon. |
_feature_bbox(geom) | Computes the (min_lng, min_lat, max_lng, max_lat) bounding box for a Polygon or MultiPolygon geometry; returns None for empty or unsupported geometries. |
_point_in_ring and _point_in_polygon implement the standard ray-casting algorithm: for a query point a horizontal ray is cast toward +∞, and the number of polygon-edge crossings determines whether the point is inside (odd count) or outside (even count).