Skip to main content

Python package to automatically attach images to GeoJSON features

Project description

๐Ÿ—บ๏ธ GeoJSON Image Organizer

PyPI version Python License: MIT Tests

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 null honestly 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
  1. Load GeoJSON file
  2. Read all images from folder
  3. Normalize names (lowercase, remove spaces/symbols)
  4. Match feature names to image filenames using fuzzy matching
  5. Attach best-matching image path to each feature
  6. 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


๐Ÿค 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

geojsonfile_image_attacher-0.2.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

geojsonfile_image_attacher-0.2.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file geojsonfile_image_attacher-0.2.0.tar.gz.

File metadata

File hashes

Hashes for geojsonfile_image_attacher-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8d2d36d1508f52816b97b30c0edb2ca14021bd3642c34122742adfa9a0861a78
MD5 a7a8fe0650f04446f11617e1145165d4
BLAKE2b-256 598195ebb96e25b84d61beab62abb504c7139f8770c10856c194fd18714ec2e8

See more details on using hashes here.

File details

Details for the file geojsonfile_image_attacher-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for geojsonfile_image_attacher-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 895cb6431c3b39246ce0b4a72452a38250ce269d3c6d4fc371230b1ec9eacf0b
MD5 d79ca9c9e28a1d1d4ecc53b355d6c7f7
BLAKE2b-256 da86e870f7de98efa76d3f2b9e8561d962596d9bd39d251ab370a8d9d99148e4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page