Importing Shapefiles
CONFOR supports importing geospatial data in Shapefile format to define and update Level 4 forest patrimony units (rodales). This guide explains the file requirements, import process, and troubleshooting.Overview
Shapefile import in CONFOR enables:- Bulk geospatial data loading: Import multiple rodales with geometries
- Hierarchical linking: Connect rodales to existing Level 2 (finca) and Level 3 (lote) units
- Area calculation: Automatic calculation of surface areas in hectares
- Land use tracking: Record current and previous land use, with variation dates
- Asynchronous processing: Large imports are processed in the background by a geospatial worker
Shapefile Requirements
Required Files in ZIP
Your shapefile must be packaged as a ZIP archive containing these files:| File Extension | Required | Purpose |
|---|---|---|
.shp | Yes | Main geometry file (polygons) |
.shx | Yes | Shape index file |
.dbf | Yes | Attribute data (properties) |
.prj | Yes | Coordinate reference system (CRS) |
Spatial Requirements
| Requirement | Value |
|---|---|
| Geometry Type | Polygon or MultiPolygon |
| CRS | Any CRS that can be transformed to EPSG:4326 (WGS84) |
| Validity | Geometries must be valid (no self-intersections, gaps, etc.) |
| Coordinate System | Recommended: EPSG:4326, EPSG:3857, or local UTM zones |
CONFOR automatically transforms geometries to EPSG:4326 for storage. Your input CRS is detected from the
.prj file.Required Attributes (DBF Columns)
Your.dbf file must contain these columns for hierarchical linking:
| Attribute | Required | Description | Example |
|---|---|---|---|
nivel2_id | Yes | Code of Level 2 unit (finca/predio) | FINCA-01 |
nivel3_id | Yes | Code of Level 3 unit (lote/compartimento) | LOTE-01 |
nivel4_id | Yes | Code of Level 4 unit (rodal) | RODAL-001 |
The combination of
nivel2_id + nivel3_id + nivel4_id uniquely identifies each rodal in CONFOR.Optional Attributes
Include these columns for richer data import:| Attribute | Format | Description | Example |
|---|---|---|---|
nombre_rodal | Text | Rodal display name | Rodal Norte |
fuente | Text | Data source | Levantamiento GPS |
fecha_levantamiento | YYYY-MM-DD | Survey date | 2026-03-01 |
observacion | Text | Notes/comments | Sin novedad |
CSV Template Reference
From the README, here’s a sample CSV structure (for reference only—you must use shapefile):Import Process
Navigate to Import Page
Go to Forest Patrimony → Importación Shapefile (or similar path, depending on your navigation setup).
You need
forest-patrimony:CREATE or forest-patrimony:UPDATE permission to import shapefiles.Prepare Your ZIP File
Ensure your ZIP contains:
- Exactly one
.shpfile - Exactly one
.shxfile - Exactly one
.dbffile - Exactly one
.prjfile
Fill in Variation Metadata (Optional)
If this import represents a land use change, provide:
- Fecha de variación: Date when the land use changed (YYYY-MM-DD)
- Observaciones: Notes about the variation
Variation metadata is stored in the import job and applied to all imported rodales.
Upload ZIP File
Click Choose File and select your ZIP archive.Click Upload or Importar.CONFOR validates the ZIP structure before accepting the upload.
Track Import Job
After upload, CONFOR creates a
GeoImportJob with status PENDING.The geospatial worker processes the job asynchronously with these stages:- EXTRACTING: Unzipping files
- VALIDATING: Checking CRS, geometry validity, attributes
- PROCESSING: Transforming geometries, calculating areas, linking hierarchy
- COMPLETED: Import finished successfully
- FAILED: Error occurred (check
errorMessagefield)
Import jobs are polled by the
pnpm worker:geo process (see README). Monitor progress via /api/forest/geo/import/{jobId}.How Hierarchical Linking Works
Organization-Scoped Matching
CONFOR resolves hierarchy codes within your organization only:- Organization ID: Taken from the authenticated user, not from the shapefile
- Level 2 (Finca): Matches
nivel2_idagainstForestPatrimonyLevel2.codewhereorganizationId = user.organizationId - Level 3 (Lote): Matches
nivel3_idagainstForestPatrimonyLevel3.codewherelevel2Id = matchedLevel2.id - Level 4 (Rodal): Matches
nivel4_idagainstForestPatrimonyLevel4.codewherelevel3Id = matchedLevel3.id
What Happens on Import
For each feature in the shapefile:- Validate attributes: Ensure
nivel2_id,nivel3_id,nivel4_idare present - Resolve hierarchy: Match codes to existing database records
- Transform geometry: Convert CRS to EPSG:4326
- Calculate area: Compute surface area in hectares using geodesic calculation
- Store geometry version: Create
ForestGeometryN4record with:geom: MultiPolygon geometrycentroid: Calculated centroid pointsuperficieHa: Area in hectaresvalidFrom: Current timestampisActive: true
- Link to import job: Set
importJobIdfor traceability
Handling Duplicates
If a rodal with the samenivel2_id + nivel3_id + nivel4_id already exists:
- Previous geometry versions: Set
isActive = false,validTo = now() - New geometry version: Create with
isActive = true,validFrom = now()
Geospatial Worker
Worker Configuration
From the README, the worker is configured via environment variables:Starting the Worker
Continuous mode:The worker must be running for shapefile imports to complete. Without the worker, jobs remain in
PENDING state.Manual Job Triggering
If you don’t have the worker running continuously, you can trigger job processing manually:Validation Checklist
Before importing, verify:Attribute Completeness
Attribute Completeness
✅
nivel2_id, nivel3_id, nivel4_id present in all features✅ No null or empty values in required attributes✅ No duplicate nivel2_id + nivel3_id + nivel4_id combinations within the same import batchHierarchy Existence
Hierarchy Existence
✅ All referenced
nivel2_id codes exist in your organization’s Level 2 units✅ All referenced nivel3_id codes exist under their corresponding nivel2_id✅ If updating existing rodales, nivel4_id codes should exist; if creating new ones, they should notZIP Structure
ZIP Structure
✅ ZIP includes
.shp, .shx, .dbf, .prj files✅ All files have the same base name (e.g., rodales.shp, rodales.dbf)✅ No extra folders or nested ZIP filesSpatial Validity
Spatial Validity
✅
.prj file contains a valid CRS definition✅ Geometries are type Polygon or MultiPolygon (not Point, LineString, etc.)✅ No invalid geometries (check with QGIS → Vector → Geometry Tools → Check Validity)✅ CRS is appropriate for your region (e.g., UTM zone matching your location)Downloading Import Templates
CONFOR provides an endpoint to download CSV/Excel templates:These templates show the expected attribute structure. For shapefile imports, replicate these columns in your
.dbf file.Troubleshooting
Import Job Stuck in PENDING
Cause: Geospatial worker is not running. Solution: Start the worker withpnpm worker:geo.
Import Fails with “ZIP incompleto”
Cause: One or more required files (.shp, .shx, .dbf, .prj) are missing from the ZIP.
Solution: Ensure the ZIP contains all four files. Check file extensions (case-sensitive on some systems).
Geometry Validation Errors
Cause: Invalid geometries (self-intersections, unclosed polygons, etc.). Solution:- Open shapefile in QGIS
- Run Vector → Geometry Tools → Check Validity
- Fix invalid geometries with Vector → Geometry Tools → Fix Geometries
- Re-export and re-import
Hierarchy Code Not Found
Cause:nivel2_id, nivel3_id, or nivel4_id doesn’t match existing records in your organization.
Solution:
- Check the codes in your shapefile
.dbf(open with Excel or QGIS attribute table) - Compare against existing codes in CONFOR:
- Level 2: Check
/api/forest/patrimony?level=2 - Level 3: Check
/api/forest/patrimony?level=3&parentId={nivel2Id}
- Level 2: Check
- Update codes in shapefile or create missing hierarchy units in CONFOR first
CRS Transformation Errors
Cause: Missing or invalid.prj file, or unsupported CRS.
Solution:
- Verify
.prjcontains a valid WKT CRS definition (open in text editor) - Re-project shapefile to a common CRS (EPSG:4326 or local UTM) in QGIS:
- Vector → Data Management Tools → Reproject Layer
- Re-export with
.prjincluded
Import Completes but Features Missing
Cause: Features failed validation (logged asFAILED in geo_import_job_items).
Solution:
- Query import job items:
- Review
messagefield for each failed feature - Fix issues in shapefile (missing attributes, invalid codes, etc.)
- Re-import
Organization Security Error
Error:El usuario no tiene una organización asociada
Cause: Your user account doesn’t have an organizationId.
Solution: Contact system administrator to assign you to an organization.
API Reference
Upload Shapefile
Check Job Status
Trigger Worker (Manual)
Best Practices
Validate Data Before Import
Validate Data Before Import
- Use QGIS to check geometry validity
- Verify attribute completeness (no null required fields)
- Test with a small subset (5-10 features) before full import
- Ensure CRS is correctly defined in
.prj
Organize Imports by Date
Organize Imports by Date
- Name ZIP files with dates:
rodales_2026-03-09.zip - Use
variationDateto track when land use changed - Keep source shapefiles archived for audit trail
Monitor Worker Health
Monitor Worker Health
- Run worker as a systemd service or PM2 process (see README)
- Set up monitoring/alerts for worker downtime
- Check worker logs regularly:
pm2 logs confor-geo-worker
Handle Large Imports Incrementally
Handle Large Imports Incrementally
- Split very large shapefiles (>1000 features) into batches
- Import during off-peak hours to reduce system load
- Monitor database disk space (geometries consume significant storage)
Document Hierarchy Codes
Document Hierarchy Codes
- Maintain a mapping document of:
- Level 2 codes → Finca names
- Level 3 codes → Lote names
- Level 4 codes → Rodal names
- Share with field teams to ensure consistent coding
Related Guides
- Forest Hierarchy - Understand Level 2/3/4/5 structure
- Managing Users - Permission requirements
- Audit Logs - Track import history