Python project for land cover classification using GIS data (GeoTIFF + Shapefile). For questions: me+gisc@nuark.xyz
| data | ||
| output | ||
| src | ||
| static | ||
| .dockerignore | ||
| .gitignore | ||
| docker-compose.yml | ||
| Dockerfile | ||
| main.py | ||
| README.md | ||
| requirements.txt | ||
GIS Classification
Python project for land cover classification using GIS data (GeoTIFF + Shapefile).
Project Structure
gis-classification/
├── main.py # Main script with parameters
├── requirements.txt # Dependencies
├── Dockerfile # Docker image configuration
├── docker-compose.yml # Docker Compose configuration
├── .dockerignore # Docker ignore rules
├── data/ # Input data folder
├── output/ # Classification results
├── static/ # Web frontend
└── src/
├── classifier.py # Main classification pipeline
├── api.py # FastAPI web server
├── data/
│ └── loader.py # Data loading (GeoTIFF, Shapefile)
├── strategies/
│ ├── base.py # Strategy interface
│ └── classifiers.py # Built-in strategies (RF, SVM, LR)
└── utils/
Installation
pip install -r requirements.txt
Or with uv:
uv pip install -r requirements.txt
Docker Deployment
Build and run with Docker Compose:
docker-compose up --build
Or run with Docker directly:
docker build -t gis-classification .
docker run -p 8000:8000 -v $(pwd)/data:/app/data -v $(pwd)/output:/app/output gis-classification
Then open http://localhost:8000 in your browser.
Production with Nginx (optional):
- Uncomment the nginx section in
docker-compose.yml - Create
nginx.conf(see example below) - Run
docker-compose up -d
Example nginx.conf:
events { worker_connections 1024; }
http {
server {
listen 80;
location / {
proxy_pass http://gis-classification:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
}
Usage
CLI Mode
-
Place your input files in
data/:landsat.tif- GeoTIFF from Landsatpolygons.shp- Shapefile with class labels
-
Configure parameters in
main.py:- Input/output paths
- Classification strategy (RandomForest, SVM, LogisticRegression)
- Training parameters
-
Run:
python main.py
Web Interface
Start the web server:
uvicorn src.api:app --host 0.0.0.0 --port 8000 --reload
Then open http://localhost:8000 in your browser.
Features:
- Upload GeoTIFF raster and Shapefile training data
- Select classification strategy (Random Forest, SVM, Logistic Regression, MLE)
- View training metrics (Accuracy, Cohen's Kappa)
- Interactive map visualization with Leaflet
- Download classified GeoTIFF results
API Endpoints:
GET /- Web interfacePOST /train- Train classifier with uploaded filesPOST /predict- Run classificationGET /result/{session_id}- Get result metadataGET /result/{session_id}/download- Download classified GeoTIFFGET /docs- Interactive API documentation (Swagger UI)
Adding Custom Classification Strategy
Create a new class implementing ClassificationStrategy:
from src.strategies import ClassificationStrategy
import numpy as np
class MyCustomStrategy(ClassificationStrategy):
def train(self, X: np.ndarray, y: np.ndarray) -> None:
# Your training logic
pass
def predict(self, X: np.ndarray) -> np.ndarray:
# Your prediction logic
pass
def predict_proba(self, X: np.ndarray) -> np.ndarray:
pass
def get_params(self) -> dict:
pass
@property
def name(self) -> str:
return "MyCustom"
Then use in main.py:
STRATEGY = MyCustomStrategy()
Output
output/classified.tif- Classified raster (GeoTIFF)- Console output with accuracy metrics (Accuracy, Cohen's Kappa)
- Web interface visualization with interactive map
Metrics
The classifier reports:
- Accuracy: Overall classification accuracy
- Cohen's Kappa: Agreement statistic accounting for chance (values > 0.8 indicate excellent agreement)