Metadata-Version: 2.4
Name: chile-reverse-geocoder
Version: 0.1.1
Summary: Offline administrative reverse geocoding for Chile (region, province, commune)
Author-email: Gonzalo Sepúlveda Navarrete <sepulveda.navarrete1996@gmail.com>
License: MIT License
        
        Copyright (c) 2026 Gonzalo Sepúlveda Navarrete
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/gonzalosn/chile-reverse-geocoder
Project-URL: Bug Tracker, https://github.com/gonzalosn/chile-reverse-geocoder/issues
Keywords: geocoding,chile,reverse-geocoding,gis,offline,spatial
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Scientific/Engineering :: GIS
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Requires-Dist: shapely>=2.0
Requires-Dist: pyogrio>=0.9
Requires-Dist: pyarrow>=13.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Dynamic: license-file

# chile-reverse-geocoder

Reverse geocoding administrativo offline para Chile. Dado un par de coordenadas (lat, lon), retorna la región, provincia y comuna sin necesidad de API externa ni conexión a internet.

## Fuente de datos

Esta librería utiliza como base la capa oficial **División Política Administrativa (DPA) 2023** publicada por la Infraestructura de Datos Geoespaciales de Chile [IDE Chile](https://geoportal.cl/geoportal/catalog/36391/Divisi%C3%B3n%20Pol%C3%ADtica%20Administrativa%202023)

Los límites administrativos y códigos territoriales corresponden a la cartografía oficial distribuida por IDE Chile.

Fuente:

* IDE Chile — División Político Administrativa (DPA)

Los datos fueron procesados para su uso offline mediante:

* eliminación de atributos no utilizados,
* simplificación de geometrías,
* conversión a formato GeoParquet,
* construcción de índice espacial.

Las modificaciones realizadas corresponden únicamente al formato y optimización del almacenamiento; la fuente original y propiedad de los datos permanecen con el organismo correspondiente.

Consulte la licencia y condiciones de uso del dataset original antes de reutilizar los datos.


## Instalación

```bash
pip install chile-reverse-geocoder
```

## Uso básico

```python
from chile_reverse_geocoder import lookup

result = lookup(-33.4489, -70.6693)
print(result)
# {
#   "region": "Metropolitana de Santiago",
#   "province": "Santiago",
#   "commune": "Santiago",
#   "region_code": "13",
#   "province_code": "131",
#   "commune_code": "13101"
# }
```

## Filtrar por nivel administrativo

```python
# Solo región
lookup(-33.4489, -70.6693, level="region")
# {"region": "Metropolitana de Santiago", "region_code": "13"}

# Solo provincia
lookup(-33.4489, -70.6693, level="province")
# {"province": "Santiago", "province_code": "131"}

# Solo comuna
lookup(-33.4489, -70.6693, level="commune")
# {"commune": "Santiago", "commune_code": "13101"}
```

## Casos especiales

```python
# Coordenadas fuera de Chile → None
lookup(-34.6037, -58.3816)  # Buenos Aires → None

# Coordenadas inválidas → excepción
from chile_reverse_geocoder import InvalidCoordinatesError
lookup(91.0, 0.0)  # raises InvalidCoordinatesError

# Nivel inválido → excepción
from chile_reverse_geocoder import InvalidLevelError
lookup(-33.4489, -70.6693, level="city")  # raises InvalidLevelError
```

## Descripción técnica

- **Offline**: No realiza llamadas a servicios externos. Los datos están empaquetados dentro de la librería (~3 MB).
- **Sin API keys**: No requiere configuración de credenciales.
- **Índice espacial STRtree**: Usa `shapely.STRtree` para búsqueda espacial eficiente O(log n). El índice se construye una sola vez (lazy loading) y se reutiliza en llamadas sucesivas mediante un singleton en memoria.
- **Datos**: División Política Administrativa (DPA) de Chile con 345 comunas. Almacenado en formato GeoParquet con geometrías simplificadas. CRS: EPSG:4326 (WGS84).

## Dependencias

- `shapely >= 2.0`
- `pyogrio >= 0.9`
- `pyarrow >= 13.0`

## Licencia

MIT

Los datos administrativos incluidos o derivados mantienen las condiciones de uso establecidas por la fuente oficial correspondiente (IDE Chile).
