Overview
The Geospatial Import module enables users to upload Shapefile data to create or update Level 4 management unit geometries. The system automatically:- Extracts geometries from ZIP archives containing Shapefiles
- Validates hierarchy codes (Level 2, 3, 4)
- Calculates polygon areas in hectares
- Creates geometry versions with temporal validity
- Generates land patrimonial variations for accounting
CONFOR uses PostGIS for spatial operations and stores geometries in WGS 84 (EPSG:4326) coordinate system.
Key Features
Shapefile Upload
Upload ZIP archives containing .shp, .shx, .dbf, and .prj files
Auto Area Calculation
Automatic calculation of polygon areas in hectares
Temporal Versioning
Track geometry changes over time with valid_from/valid_to
Variation Generation
Automatically create land accounting variations from geometry changes
Data Model
Geometry Storage
prisma/schema.prisma
Import Job
prisma/schema.prisma
Import Job Item
Tracks individual features from the Shapefile:prisma/schema.prisma
Upload Process
User Workflow
Prepare Shapefile
Create a Shapefile with Level 4 polygons containing attributes:
nivel2orn2: Level 2 codenivel3orn3: Level 3 codenivel4orn4: Level 4 codeusoactual: Current land use (optional)usoanterior: Previous land use (optional)fechavariacion: Variation date (optional)
Create ZIP Archive
Package required Shapefile components:
.shp- Shape format (required).shx- Shape index (required).dbf- Attribute data (required).prj- Projection info (required).cpg- Character encoding (optional)
Upload via UI
Navigate to Forest → Geospatial → Import:
- Select ZIP file
- Set variation date (for land accounting)
- Add notes (optional)
- Submit upload
Background Processing
System creates import job and processes asynchronously:
- Extracts Shapefile
- Validates hierarchy codes
- Calculates areas
- Creates/updates geometries
- Generates variations
API Endpoints
Download Template
GET/api/forest/geo/import?format=csv
Download template CSV or Excel file with sample data:
Upload Shapefile
POST/api/forest/geo/import
Content-Type: multipart/form-data
Parameters:
file: ZIP file containing Shapefile componentsvariationDate: Date for land accounting variations (ISO 8601)variationNotes: Optional notes for all variations
The import job is processed asynchronously. Use the returned
jobId to check status.Check Job Status
GET/api/forest/geo/import/[jobId]
Response:
Shapefile Attribute Mapping
The system recognizes these attribute names (case-insensitive):| Required/Optional | Attribute Names | Description |
|---|---|---|
| Required | nivel2, n2, level2 | Level 2 code |
| Required | nivel3, n3, level3 | Level 3 code |
| Required | nivel4, n4, level4 | Level 4 code |
| Optional | usoactual, landuse, uso | Current land use |
| Optional | usoanterior, previoususe | Previous land use |
| Optional | fechavariacion, vardate | Variation date |
| Optional | observaciones, notes | Notes |
Hierarchy Validation
The import process validates that:- Level 2 exists: Matches existing
ForestPatrimonyLevel2.code - Level 3 exists: Matches existing
ForestPatrimonyLevel3.codeunder correct Level 2 - Level 4 exists or is created: Matches or creates
ForestPatrimonyLevel4 - Organization scope: All codes must belong to the user’s organization
Area Calculation
Areas are automatically calculated from polygon geometries:- Uses
geographytype for accurate area on ellipsoid - Result in square meters, divided by 10,000 for hectares
- Precision up to 4 decimal places (0.0001 ha = 1 m²)
Temporal Versioning
Each geometry import creates a new version:Creating New Version
Querying Current Geometries
Querying Historical Geometries
Automatic Variation Generation
When geometries are imported with land use data, the system generates patrimonial variations:src/app/api/forest/geo/import/route.ts
- Compare
usoanterior(previous) vsusoactual(current) - If different, create
LandPatrimonialVariationwith statusPENDIENTE - Calculate area from geometry
- Apply default variation date and notes from import job
- User later processes variations to update Level 4 land use
Geometry Recalculation Jobs
When Level 4 units are modified, geometry recalculation jobs can be queued:prisma/schema.prisma
- Level 4 totalAreaHa is updated
- Level 4 is activated/deactivated
- Hierarchy changes affect Level 4
src/app/api/forest/patrimony/route.ts
Map Visualization
View imported geometries on interactive map: GET/api/forest/geo/layers/nivel4
Returns GeoJSON for all Level 4 geometries in the organization:
Error Handling
Common Errors
Missing Shapefile Components
Missing Shapefile Components
Error:
ZIP incompleto. Faltan archivos obligatorios: .prjSolution: Ensure ZIP contains .shp, .shx, .dbf, and .prj filesInvalid Hierarchy Codes
Invalid Hierarchy Codes
Error:
Level 3 no encontrado: COMP-ZSolution: Verify codes exist in database and match parent hierarchyCoordinate System Mismatch
Coordinate System Mismatch
Error:
Invalid projection. Expected EPSG:4326Solution: Reproject Shapefile to WGS 84 (EPSG:4326) before uploadAttribute Name Not Recognized
Attribute Name Not Recognized
Error:
Código Level 4 no encontrado en atributosSolution: Use recognized attribute names (nivel4, n4, or level4)Partial Success
Jobs can complete with some records failed:Best Practices
Prepare Clean Data
- Validate Shapefile in QGIS/ArcGIS before upload
- Check for topology errors (gaps, overlaps)
- Ensure attribute names match expected fields
- Use consistent code formatting
Use Correct Projection
- Always use WGS 84 (EPSG:4326)
- Verify .prj file contains correct definition
- Reproject if necessary using GIS software
Test with Subset
- Upload small sample (5-10 features) first
- Verify geometry and attributes correct
- Review generated variations
- Scale up to full dataset
Document Imports
- Use descriptive file names (e.g.,
2024-Q1-nivel4-update.zip) - Add detailed notes to variation fields
- Keep source Shapefiles for reference
- Log import dates and purposes
Related Documentation
- Forest Patrimony - Understanding the hierarchy
- Land Accounting - Processing variations generated from imports
- API Reference - Geospatial API endpoints