Import Shapefile (Level 4)
Shapefile import requires a ZIP archive containing
.shp, .shx, .dbf, and .prj files.POST /api/forest/geo/import
Upload a zipped shapefile to import Level 4 geometries. The import process runs asynchronously in a background worker.
Authentication: RequiredPermissions:
forest-patrimony:CREATE or forest-patrimony:UPDATE
Request
ZIP archive containing shapefile components (.shp, .shx, .dbf, .prj)
Date of land use change (ISO 8601 format:
YYYY-MM-DD). Defaults to current date if not provided.Optional notes about the land use variation for auditing purposes
Shapefile Attribute Requirements
Level 2 identifier for hierarchical linking
Level 3 identifier for hierarchical linking
Level 4 identifier (rodal/stand code)
Current land use name (must exist in
LandUseType table)Previous land use name
Feature-level variation date (overrides request-level
variationDate)Feature-level observations
Spatial Requirements
- Geometry Type: Polygon or MultiPolygon
- CRS: Must be transformable to EPSG:4326 (WGS 84)
- Validity: All geometries must be spatially valid
Response
Unique identifier for the import job
Initial job status:
PENDINGConfirmation message
Example: Upload Shapefile
cURL
Response
Get Import Job Status
GET /api/forest/geo/import/[jobId]
Retrieve the status and details of a specific import job.
Authentication: RequiredPermissions: Organization-scoped (user must belong to the same organization as the job)
Path Parameters
UUID of the import job
Response
Job UUID
Organization UUID
Original uploaded file name
Job status:
PENDING, EXTRACTING, VALIDATING, PROCESSING, COMPLETED, or FAILEDTotal number of features in the shapefile
Number of successfully processed features
Number of features that failed validation or processing
Error details if the job failed
Array of import items (up to 100 most recent). Each item contains:
featureIndex: Index of the feature in the shapefilestatus:PROCESSEDorFAILEDlevel2Code,level3Code,level4Code: Extracted hierarchy codesmessage: Error or success messagerawProperties: Original shapefile attributes
Job creation timestamp (ISO 8601)
Processing start timestamp
Processing completion timestamp
Example: Check Job Status
cURL
Response
Download Import Template
GET /api/forest/geo/import?format=csv
Download a sample template for shapefile attribute structure.
Authentication: RequiredPermissions:
forest-patrimony:READ
Query Parameters
Template format:
csv or xlsxResponse
Returns a downloadable file with sample attribute structure:nivel2: Level 2 codenivel3: Level 3 codenivel4: Level 4 codeusoactual: Current land useusoanterior: Previous land usefechavariacion: Variation dateobservaciones: Observations
Example: Download CSV Template
cURL
Field Mapping Alternatives
The import worker supports multiple field name variations for flexibility:| Standard Field | Accepted Alternatives |
|---|---|
nivel2_id | nivel2, nivel_2, cod_n2, codfinca, finca, n2 |
nivel3_id | nivel3, nivel_3, cod_n3, codlote, lote, n3 |
nivel4_id | nivel4, nivel_4, cod_n4, codrodal, rodal, n4 |
usoactual | currentlandusename, uso_actual, uso, landuse, land_use |
usoanterior | previouslandusename, uso_anterior, previoususe, oldlanduse |
fechavariacion | variationdate, fecha_variacion, landusechangedate, fecha_cambio_uso |
observaciones | variationnotes, observacion, nota, notas, comentario, comentarios |
Import Process Workflow
- Upload: File is uploaded and validated for required components (.shp, .shx, .dbf, .prj)
- Job Creation: Import job is created with
PENDINGstatus - Worker Trigger: Background worker is notified (or picks up job on next poll)
- Extraction: Shapefile is parsed into GeoJSON features
- Validation: Each feature is validated for:
- Required hierarchy codes (nivel2_id, nivel3_id, nivel4_id)
- Valid geometry type (Polygon/MultiPolygon)
- Existing Level 2/3/4 relationships in database
- Land use name validation against
LandUseTypetable
- Geometry Storage: Valid geometries are stored in
forest_geometry_n4table - Metrics Calculation: Surface area and centroid are calculated using PostGIS
- Land Use Sync: Organization-level land use totals are recalculated
- Variation Tracking: Land use changes trigger patrimonial variation records
- Completion: Job status is updated to
COMPLETEDorFAILED
The worker processes imports in batches (default: 5 jobs per cycle) with configurable intervals (
GEO_WORKER_INTERVAL_MS).Error Handling
Common Import Errors
| Error | Cause | Resolution |
|---|---|---|
ZIP incompleto. Faltan archivos obligatorios | Missing required shapefile components | Ensure ZIP contains .shp, .shx, .dbf, and .prj files |
No se encontraron códigos de jerarquía | Missing nivel2_id, nivel3_id, or nivel4_id attributes | Add required hierarchy codes to shapefile attributes |
No existe relación jerárquica válida | Hierarchy codes don’t match database records | Verify Level 2/3/4 codes exist and are linked correctly |
Solo se permiten geometrías Polygon o MultiPolygon | Invalid geometry type (Point, LineString, etc.) | Convert geometries to Polygon or MultiPolygon |
El uso actual no existe en la tabla auxiliar | Invalid land use name | Add land use type to configuration or correct attribute value |
Security & Multi-Organization Isolation
- Organization Scoping:
organizationIdis derived from the authenticated user, not from shapefile attributes - Hierarchy Validation: All Level 2/3/4 relationships are validated against the user’s organization
- Cross-Organization Prevention: Imports cannot create or modify geometries in other organizations
- Audit Trail: All imports are tracked with
createdByIdand job metadata
Related Endpoints
- Validate Geometries - Pre-validate shapefiles before import
- Forest Configuration - Manage land use types and other configurations