feat: add FastAPI web interface for GIS classification
This commit is contained in:
parent
5a9b8469bd
commit
6815769d2b
5 changed files with 1458 additions and 15 deletions
51
README.md
51
README.md
|
|
@ -10,8 +10,10 @@ gis-classification/
|
|||
├── requirements.txt # Dependencies
|
||||
├── 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/
|
||||
|
|
@ -26,8 +28,15 @@ gis-classification/
|
|||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
Or with uv:
|
||||
```bash
|
||||
uv pip install -r requirements.txt
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### CLI Mode
|
||||
|
||||
1. Place your input files in `data/`:
|
||||
- `landsat.tif` - GeoTIFF from Landsat
|
||||
- `polygons.shp` - Shapefile with class labels
|
||||
|
|
@ -42,6 +51,31 @@ pip install -r requirements.txt
|
|||
python main.py
|
||||
```
|
||||
|
||||
### Web Interface
|
||||
|
||||
Start the web server:
|
||||
|
||||
```bash
|
||||
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 interface
|
||||
- `POST /train` - Train classifier with uploaded files
|
||||
- `POST /predict` - Run classification
|
||||
- `GET /result/{session_id}` - Get result metadata
|
||||
- `GET /result/{session_id}/download` - Download classified GeoTIFF
|
||||
- `GET /docs` - Interactive API documentation (Swagger UI)
|
||||
|
||||
## Adding Custom Classification Strategy
|
||||
|
||||
Create a new class implementing `ClassificationStrategy`:
|
||||
|
|
@ -54,17 +88,17 @@ 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"
|
||||
|
|
@ -78,4 +112,11 @@ STRATEGY = MyCustomStrategy()
|
|||
## Output
|
||||
|
||||
- `output/classified.tif` - Classified raster (GeoTIFF)
|
||||
- Console output with accuracy metrics
|
||||
- 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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue