Skip to content

CIAT-DAPA/aclimate_v3_cut_spatial_data

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AClimate V3 Cut Spatial Data 🌍✂️

🏷️ Version & Tags

GitHub release (latest by date)

Tags: gis, raster, geoprocessing, python, geoserver, postgis


📌 Introduction

Python package for advanced spatial data processing that enables:

  • Raster clipping with shapefiles
  • PostGIS integration for SQL-based clipping
  • GeoServer connectivity for geometry extraction and clipping

Use Cases:

  • Climate data processing (e.g., CHIRPS)
  • Agricultural analysis by administrative zones
  • Data extraction for specific areas of interest

✅ Prerequisites

  • Python > 3.10
  • PostGIS (optional, for PostGIS functionality)
  • GeoServer (optional, for GeoServer integration)

⚙️ Installation

pip install git+https://github.com/CIAT-DAPA/aclimate_v3_cut_spatial_data

To install a specific version:

pip install git+https://github.com/CIAT-DAPA/aclimate_v3_cut_spatial_data@v0.0.1

🚀 Basic Usage

  1. Clip with Shapefile
from aclimate_v3_cut_spatial_data import get_clipper


input_raster = "path/raster.tif"
input_shape = "path/shapefile.shp"
output_file = "path/raster_result.tif"
clipper = get_clipper(input_raster, 'shape')
result = clipper.clip(input_shape)
result.rio.to_raster(output_file)

Note

You must change the paths to the paths where the files are.

  1. Clip with GeoServer
from aclimate_v3_cut_spatial_data import get_clipper, GeoServerBasicAuth

input_raster = "path/raster.tif"
output_file = "path/raster_result.tif"
conn = GeoServerBasicAuth()  # Uses .env variables
clipper = get_clipper(input_raster, 'geoserver')
clipper.connection = conn

result = clipper.clip("workspace", "layer", "field_25") # If you want to clip by feature ID
result.rio.to_raster(output_file)

whole_result = clipper.clip("workspace", "layer") # If you want to clip by complete geometry
whole_result.rio.to_raster(output_file)

Note

Required variables:

  1. Clip with PostGIS
from sqlalchemy import create_engine
from aclimate_v3_cut_spatial_data import get_clipper

input_raster = "path/raster.tif"
output_file = "path/raster_result.tif"
database_url = os.getenv("DATABASE_URL") # Uses .env variables
engine = create_engine(database_url)
clipper = get_clipper(input_raster, 'postgis')
clipper.connection = engine
result = clipper.clip("SELECT geom FROM areas WHERE id=1")
result.rio.to_raster(output_file)

Note

Required variables:

  • DATABASE_URL: Database connection string (e.g., postgresql://user:pass@localhost/db)

🔧 Configuration

Environment Variables

Create .env file for GeoServer:

  • Windows:
set GEOSERVER_URL=http://localhost:8080/geoserver
set GEOSERVER_USER=admin
set GEOSERVER_PASSWORD=secure_password
set DATABASE_URL=postgresql://user:pass@localhost/db
  • Linux/Ubuntu:
export GEOSERVER_URL=http://localhost:8080/geoserver
export GEOSERVER_USER=admin
export GEOSERVER_PASSWORD=secure_password
export DATABASE_URL=postgresql://user:pass@localhost/db

🧪 Running Tests

# Install test requirements
pip install pytest pytest-mock

# Run tests
pytest tests/

🔄 CI/CD Pipeline Overview

Workflow Architecture

Our GitHub Actions pipeline implements a three-stage deployment process:

Code Push → Test Stage → Merge Stage → Release Stage

📊 Project Structure

aclimate_v3_cut_spatial_data/
│
├── .github/
│ └── workflows/ # CI/CD pipeline configurations
├── src/
│   └── aclimate_v3_cut_spatial_data/
│       ├── clippers/          # Core clipping classes
│       ├── types/             # Type definitions
│       └── __init__.py        # Public interface
├── tests/
│   ├── test_data/             # Sample files
│   ├── test_shape_clipper.py
│   └── test_geoserver_clipper.py
├── setup.py
└── requirements.txt # Package dependencies

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages