Isoxml Boundary Fix

Task Details
← Task Board

Task Description

# TASK: Export ISOXML Field Boundary as GeoJSON

**Priority:** HIGH
**Agent:** data_pipeline / engineer
**Filed:** 2026-02-15
**Filed by:** Doug (via Claude Code session)

---

## Problem

The ISOXML processor (`ISOBUS11783/tools/isoxml_processor.py`) exports two DIFFERENT types of boundaries — both legitimate, but only one gets exported as GeoJSON:

1. **`field_boundary.shp`** (line ~3986) — The actual field boundary from the PFD XML in the ISOXML task file. This is the RTK-quality boundary recorded on the Topcon console. Clean, precise polygon. **Exported as .shp only — no .geojson.**

2. **`planted_boundary.geojson` + `planted_boundary.shp`** (lines ~3960-3964) — The planted coverage boundary, calculated from GPS seeding coverage points. This shows what was ACTUALLY seeded (may have holes for wet spots, waterways, etc). Built by `create_planted_boundary()`. **Exported as both .shp and .geojson.**

These are two different things. The planted boundary is correct for what it is (acreage reporting). But downstream tools that scan for `.geojson` boundary files (like the Field Naming Audit) only find the planted_boundary and miss the actual field boundary. The field audit needs the PFD field boundary for field identification, not the coverage-based planted boundary.

## Fix Required

### Step 1: Export field_boundary as GeoJSON (isoxml_processor.py ~line 3988)

After the existing `_write_vectors_with_fallback()` call for `field_boundary.shp`, add a GeoJSON export:

```python
# EXISTING (keep):
res_boundary = _write_vectors_with_fallback(boundary_gdf, boundary_shp, gpkg, "field_boundary")
exports["field_boundary"] = res_boundary["vector_path"]

# ADD THIS:
boundary_geojson = os.path.join(out_dir, "field_boundary.geojson")
boundary_gdf.to_file(boundary_geojson, driver='GeoJSON')
logging.info(f"Wrote field boundary GeoJSON: {boundary_geojson}")
exports["field_boundary_geojson"] = boundary_geojson
```

### Step 2: Re-run processing on Doug's existing ISOXML data

After the code fix, re-process Doug's ISOXML ZIPs so the new `field_boundary.geojson` files get generated:

```bash
python /data/Sandbox/AgentPi/scripts/tap_batch_process.py --customer doug --retry-all
```

Or if that's too broad, at minimum re-process the files that have PFD boundaries (most Topcon TASKDATA.zip files do).

### Step 3: Verify

Check that the output directories now have BOTH:
- `planted_boundary.geojson` (GPS coverage-based, for acreage reporting)
- `field_boundary.geojson` (PFD/RTK-based, for field identification)

```bash
find /data/processed_data/doug/ -name "field_boundary.geojson" | head -5
find /data/processed_data/doug/ -name "planted_boundary.geojson" | head -5
```

## Context

- `_extract_field_boundary()` at line 138 correctly parses PFD XML → Shapely Polygon
- `create_planted_boundary()` at line 1535 is the GPS coverage approach
- Line 3776: PFD boundary is extracted correctly
- Line 3954: PFD boundary is passed to `create_planted_boundary()` but only used to CLIP the GPS coverage polygon, not as the actual boundary
- Line 3978-3992: PFD boundary IS exported as .shp but NOT as .geojson

## DO NOT

- Do NOT change `create_planted_boundary()` — it's correct for its purpose (planted acreage reporting)
- Do NOT remove the planted_boundary export — both boundaries have different uses
- This is a one-line fix + re-processing. Don't over-engineer it.
COMPLETED: 2026-02-16

The ISOXML boundary export issue has been resolved.

## What Was Fixed

The code ALREADY had the field_boundary.geojson export implemented (from a previous session).

However, planted_boundary.geojson export was FAILING silently due to GeoPandas version incompatibility:
- Code used union_all() (requires GeoPandas 0.13+)
- Pi runs GeoPandas 0.12.2
- Error: 'GeoSeries' object has no attribute 'union_all'

## Solution

Replaced all 7 occurrences of .union_all() with .unary_union (backward compatible)

## Verification

Processed test files now correctly export BOTH boundaries:
- field_boundary.geojson (PFD/RTK boundary from ISOXML XML)
- planted_boundary.geojson (GPS coverage-based boundary)

Verified on 7 newly processed directories - all have both files when PFD data exists.

## Commit

49d3e26 - fix: replace union_all() with unary_union for GeoPandas 0.12.2 compatibility

Job Queue (0)

No job queue entries for this task yet