Skip to content

mahdiBahramshahi/Python-Georefrencer-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŒ Manual GCP Georeferencing Tool

Python OpenCV License Platform

A desktop application for georeferencing aerial/drone images using Ground Control Points (GCPs)

Features โ€ข Installation โ€ข Usage โ€ข Examples โ€ข FAQ


๐Ÿ“‹ Table of Contents


๐ŸŽฏ Overview

Transform non-georeferenced images (historical aerial photos, drone imagery, or scanned maps) into georeferenced GeoTIFF files compatible with GIS software like QGIS and ArcGIS.

What is Georeferencing?

Georeferencing assigns real-world coordinates to an image, enabling spatial analysis and overlay with other geographic data.


โœจ Features

  • โœ… KML/KMZ Support - Load boundary files directly from Google Earth
  • โœ… Automatic Satellite Download - Fetches reference imagery from Google Maps
  • โœ… Side-by-Side Interface - Interactive point selection on dual canvases
  • โœ… Flexible Transformation - Perspective (4 points) or Homography (4+ points with RANSAC)
  • โœ… GeoTIFF Export - Properly georeferenced output with WGS84 coordinate system
  • โœ… Multi-Format Support - JPG, PNG, TIFF input images

๐Ÿ› ๏ธ Installation

Prerequisites

Python 3.8 or higher

Step 1: Clone the Repository

git clone https://github.com/yourusername/georeferencing-tool.git
cd georeferencing-tool

Step 2: Install Dependencies

Using pip

pip install -r requirements.txt

Manual Installation

pip install pillow numpy opencv-python rasterio requests

For macOS Users

If tkinter is not available:

brew install python-tk@3.11

๐Ÿš€ Quick Start

1. Prepare Your Data

  • KML/KMZ file: Create a boundary polygon in Google Earth
  • Input image: Your aerial/drone photo (JPG, PNG, or TIFF)

2. Run the Application

python app.py

3. Three-Step Workflow

Step Action Description
1 Load KML/KMZ Automatically downloads satellite reference image
2 Load Image Select your input image to georeference
3 Mark Points Click matching points on both images (min. 4 pairs)
4 Apply Export georeferenced GeoTIFF

๐Ÿ“– Detailed Usage

Interface Overview

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  [1. Select KML/KMZ]  [2. Select Image]  [Clear]  [Apply]  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                           โ”‚                               โ”‚
โ”‚    Input Image            โ”‚    Satellite Image            โ”‚
โ”‚    (Your Photo)           โ”‚    (Reference)                โ”‚
โ”‚                           โ”‚                               โ”‚
โ”‚    Points: 4              โ”‚    Points: 4                  โ”‚
โ”‚                           โ”‚                               โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Status: Ready to georeference (4 point pairs)              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Selecting Ground Control Points (GCPs)

Good GCP locations:

  • ๐Ÿข Building corners
  • ๐Ÿ›ฃ๏ธ Road intersections
  • ๐ŸŒ‰ Bridge endpoints
  • โ›ฒ Permanent landmarks

Point distribution:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ 1             2 โ”‚  โ† Cover all corners
โ”‚                 โ”‚
โ”‚                 โ”‚
โ”‚                 โ”‚
โ”‚ 4             3 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Keyboard Shortcuts

Note: Currently manual workflow only. Keyboard shortcuts coming soon!


๐Ÿ“ Technical Details

Coordinate Systems

Component CRS Details
Output WGS84 (EPSG:4326) Standard GPS coordinates
Satellite Tiles Google Maps Zoom level 17 (ยฑ4.77m/pixel)

Transformation Pipeline

graph LR
    A[Input Image] --> B[GCP Selection]
    C[Satellite Image] --> B
    B --> D[Homography Matrix]
    D --> E[Image Warping]
    E --> F[GeoTIFF Export]
Loading

Algorithms Used

  • 4 points: cv2.getPerspectiveTransform() - Direct perspective transformation
  • 5+ points: cv2.findHomography() with RANSAC - Robust outlier rejection

Image Processing Steps

  1. Load and normalize images
  2. Collect GCP pairs from user clicks
  3. Convert display coordinates to image coordinates
  4. Calculate transformation matrix
  5. Warp input image to match satellite geometry
  6. Export with geospatial metadata

๐ŸŽฏ Use Cases

Use Case Description Example
๐Ÿ—บ๏ธ Historical Maps Digitize and georeference old paper maps City plans from 1940s
๐Ÿš Drone Imagery Align photos without GPS metadata Agricultural surveys
๐Ÿ“ธ Aerial Photos Rectify oblique aerial photographs Urban planning analysis
๐Ÿ•ฐ๏ธ Time-Series Prepare multi-temporal datasets Land use change detection
๐Ÿ›๏ธ Heritage Archive historical aerial imagery Cultural heritage preservation

๐Ÿ’ก Tips & Best Practices

โœ… Do's

  • Use 6-10 GCPs for optimal accuracy
  • Distribute points evenly across the entire image
  • Choose permanent features that exist in both images
  • Verify correspondence before applying transformation
  • Save intermediate results during complex projects

โŒ Don'ts

  • Don't cluster all points in one area
  • Don't use temporary features (cars, people)
  • Don't rush the point selection process
  • Don't use too few points (<4)
  • Don't ignore point distribution warnings

Accuracy Tips

Number of Points โ†’ Accuracy:
4 points   โ†’ Basic alignment
6-8 points โ†’ Good accuracy  โญ
10+ points โ†’ Excellent precision โญโญโญ

๐Ÿ”ง Troubleshooting

โŒ Satellite image not loading

Possible causes:

  • No internet connection
  • Invalid KML coordinates
  • Area too large (>10kmยฒ)

Solutions:

1. Check internet connectivity
2. Verify KML file in Google Earth
3. Reduce area of interest
4. Try different zoom level
โŒ Poor georeferencing results

Possible causes:

  • Insufficient GCP points
  • Uneven point distribution
  • Incorrect point correspondence

Solutions:

1. Add more GCPs (8-12 recommended)
2. Distribute points to all corners
3. Clear and restart point selection
4. Verify each point pair carefully
โŒ Application crashes on Mac

Solution:

# Install tkinter
brew install python-tk@3.11

# Verify installation
python3 -m tkinter
โŒ "ModuleNotFoundError: rasterio"

Solution:

# Install GDAL first (macOS)
brew install gdal

# Then install rasterio
pip install rasterio

๐ŸŒŸ Roadmap

Phase 1: Current Version โœ…

  • Manual GCP selection
  • KML/KMZ support
  • Satellite image download
  • GeoTIFF export

Phase 2: Semi-Automated (In Progress) ๐Ÿšง

  • Deep learning-based point matching (SuperGlue)
  • ROI selection tool
  • Manual refinement interface
  • Batch processing

Phase 3: Advanced Features ๐Ÿ”ฎ

  • Multi-temporal registration (60+ year gap)
  • Quality assessment metrics
  • Point cloud support
  • Web-based interface

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Development Setup

# Clone repository
git clone https://github.com/mahdiBahramshahi/Python-Georefrencer-app.git

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt


---

## ๐Ÿ‘จโ€๐Ÿ’ป Author

**Mahdi Bahramshahi**
- GitHub: [@mahdibahramshahi](https://github.com/mahdiBahramshahi)
- LinkedIn: (https://www.linkedin.com/in/mahdi-bahramshahi/)

---

## ๐Ÿ™ Acknowledgments

- Google Maps API for satellite imagery
- OpenCV community for computer vision tools
- Rasterio for geospatial raster processing

---

## ๐Ÿ“ž Support

- ๐Ÿ“ง Email: bahramshahimahdi92@gmail.com
---

<div align="center">

### โญ Star this repository if you find it helpful!

Made with โค๏ธ for the GIS community

</div>

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages