Modern GIS toolkit for Python - Simplifying geospatial workflows with built-in data sources, intelligent caching, and fluent APIs
This example demonstrates how to manage the PyMapGIS data cache using both its Python API and its command-line interface (CLI). Effective cache management can help save disk space and ensure you are using the most up-to-date data when needed.
The Python script cache_cli_api_example.py
showcases the following cache operations via the PyMapGIS API:
tiger://rails?year=2022
) to ensure there are items in the cache.pmg.cache.get_cache_dir()
).pmg.cache.get_cache_size()
).pmg.cache.list_cache()
).pmg.cache.clear_cache()
).The script also lists the equivalent CLI commands that can be used in a terminal for the same operations.
Ensure PyMapGIS is installed: If you haven’t installed PyMapGIS: ```bash pip install pymapgis ```
Navigate to the example directory: ```bash cd docs/examples/cache_management_example ```
Run the script: ```bash python cache_cli_api_example.py ```
The script will print information to the console, including:
You can also manage the cache directly from your terminal using the pymapgis
CLI:
Get cache path: ```bash pymapgis cache path ```
Get cache size: ```bash pymapgis cache size ```
List cached items: ```bash pymapgis cache list ```
Clear all items from cache: ```bash pymapgis cache clear ```
Clean expired items from cache:
PyMapGIS uses requests-cache
, which can also handle cache expiry. The clean
command typically removes only expired entries based on their original cache headers or settings.
```bash
pymapgis cache clean
```
Running these commands in your terminal will provide direct feedback from the PyMapGIS CLI.