Python package to automatically attach images to GeoJSON features
Project description
๐บ๏ธ GeoJSON Image Organizer
A Python package that automatically attaches images to GeoJSON features based on name matching. It uses fuzzy string matching to intelligently link spatial features with corresponding image files โ even when names are slightly different, misspelled, or formatted inconsistently.
โจ Features
- Reads GeoJSON files and matches features to images automatically
- Uses fuzzy matching (rapidfuzz) for intelligent name linking
- Normalizes names โ handles spaces, hyphens, underscores, and case differences
- Returns
nullhonestly when no image matches โ no silent fallbacks - Exports a CSV report of unmatched features
- Configurable match sensitivity with
--cutoff - Full CLI support โ use it directly from terminal
- Supports jpg, jpeg, png, webp, gif image formats
๐ง How It Works
GeoJSON features Image folder
โโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโ
"Kathmandu" โโfuzzyโโโถ kathmandu.jpg โ
matched
"Patan Durbar" โโfuzzyโโโถ patan-durbar.jpg โ
matched
"XYZ Place" โโno matchโโถ null โ ๏ธ reported
- Load GeoJSON file
- Read all images from folder
- Normalize names (lowercase, remove spaces/symbols)
- Match feature names to image filenames using fuzzy matching
- Attach best-matching image path to each feature
- Save updated GeoJSON + optional CSV report of unmatched features
๐ Project Structure
project/
โ
โโโ geojsonfileandimageattacher/
โ โโโ __init__.py
โ โโโ core.py # Main logic
โ โโโ cli.py # CLI interface
โ
โโโ tests/
โ โโโ test_core.py # Full test suite
โ
โโโ demo/
โ โโโ input.geojson # Sample input
โ โโโ images/ # Sample images
โ โโโ output.geojson # Generated output
โ
โโโ setup.py
โโโ pyproject.toml
โโโ README.md
โ๏ธ Requirements
- Python 3.6+
- rapidfuzz
๐ฆ Installation
pip install geojsonfile_image_attacher
Or for local development:
git clone https://github.com/subekshya-s/geojson_image_attacher.git
cd geojson_image_attacher
pip install -e .
โถ๏ธ Usage
CLI (recommended)
# Basic usage
geojson-attach --input map.geojson --images ./photos --output result.geojson
# Stricter matching (default is 75)
geojson-attach --input map.geojson --images ./photos --output result.geojson --cutoff 85
# With CSV report of unmatched features
geojson-attach --input map.geojson --images ./photos --output result.geojson --report
# Help
geojson-attach --help
Python API
from geojsonfileandimageattacher import GeoImageOrganizer
organizer = GeoImageOrganizer(
input_geojson="input.geojson",
image_folder="images/",
output_geojson="output.geojson",
cutoff=75 # match sensitivity 0-100
)
organizer.run()
๐ Output Example
Input feature:
{
"type": "Feature",
"properties": {
"name": "Kathmandu"
}
}
Output feature:
{
"type": "Feature",
"properties": {
"name": "Kathmandu",
"image": "images/kathmandu.jpg",
"image_match_score": 100.0
}
}
Unmatched feature:
{
"type": "Feature",
"properties": {
"name": "Unknown Place",
"image": null,
"image_match_score": 0
}
}
๐ CSV Report (--report flag)
When --report is used, a CSV file is generated next to your output:
feature_name,status
Bhaktapur,no image found
Unknown Place XYZ,no image found
๐ผ๏ธ Screenshots
Add screenshots here after running on demo data
Example:
๐บ๏ธ GeoJSON Image Organizer Input: demo/input.geojson Images: demo/images Output: demo/output.geojson Cutoff: 75 ๐ Results: 5/8 features matched โ ๏ธ No image found for: - Bhaktapur - Unknown Place XYZ - [unnamed feature] ๐พ Output saved to demo/output.geojson ๐ Report saved to demo/output_unmatched.csv
๐งช Running Tests
pip install pytest
python -m pytest tests/ -v
Expected output:
test_normalize PASSED โ
test_get_image_mapping PASSED โ
test_attach_images_with_match PASSED โ
test_attach_images_no_match PASSED โ
test_save_output PASSED โ
test_missing_geojson_raises_error PASSED โ
test_missing_image_folder_raises_error PASSED โ
test_invalid_json_raises_error PASSED โ
๐ง CLI Options
| Option | Required | Default | Description |
|---|---|---|---|
--input |
โ | โ | Path to input GeoJSON file |
--images |
โ | โ | Path to image folder |
--output |
โ | โ | Path to output GeoJSON file |
--cutoff |
โ | 75 | Match sensitivity 0-100 |
--report |
โ | False | Export unmatched CSV report |
๐ License
MIT License โ see LICENSE for details.
๐ฉโ๐ป Author
Subekshya Subedi
- GitHub: @subekshya-s
- Email: subekshyasubedi26@gmail.com
๐ค Contributing
Pull requests are welcome! For major changes, please open an issue first.
git clone https://github.com/subekshya-s/geojson_image_attacher.git
pip install -e .
python -m pytest tests/ -v
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file geojsonfile_image_attacher-0.2.0.tar.gz.
File metadata
- Download URL: geojsonfile_image_attacher-0.2.0.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d2d36d1508f52816b97b30c0edb2ca14021bd3642c34122742adfa9a0861a78
|
|
| MD5 |
a7a8fe0650f04446f11617e1145165d4
|
|
| BLAKE2b-256 |
598195ebb96e25b84d61beab62abb504c7139f8770c10856c194fd18714ec2e8
|
File details
Details for the file geojsonfile_image_attacher-0.2.0-py3-none-any.whl.
File metadata
- Download URL: geojsonfile_image_attacher-0.2.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
895cb6431c3b39246ce0b4a72452a38250ce269d3c6d4fc371230b1ec9eacf0b
|
|
| MD5 |
d79ca9c9e28a1d1d4ecc53b355d6c7f7
|
|
| BLAKE2b-256 |
da86e870f7de98efa76d3f2b9e8561d962596d9bd39d251ab370a8d9d99148e4
|