Crop mapping source: sync, parcel join, overrides with audit trail #186
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "issue-183-crop-data"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Implements the data layer for issue #183: DWR crop mapping as a parcel report data field.
What's in this PR
Sync + storage
municipal.source_crop— source config (feature service item, layer, water year, optional county override list)municipal.crop_field— synced DWR polygons, upserted on(water_year, unique_id)so re-syncs (Provisional → Final) never duplicate; full multi-crop slot schema (CLASS/SUBCLASS/SPECOND/IRR_TYP/PCNT/CROPTYP/ADOY × 4),MAIN_CROP+MAIN_CROP_DATE,YR_PLANTED,DWR_REVISE, etc.municipal.parcel_crop— materialized join (parcel centroid point-in-polygon,ST_Contains) computed once per sync, so parcel reports and district exports never pay for a live spatial joinmunicipal.parcel_crop_override— user edits, separate from synced data so re-syncs never clobber them; every change writes anaudit_logrow (same pattern as org config edits)Sync job (
crop-syncjobtype): county-scoped fetch from the public ArcGIS service — counties derived at run time frommunicipal.source(or the config override), per-county count + paginated query (2000/req), idempotent. Registration reuses the existing arcgis-go machinery (service_feature + layer + layer_field).API
GET/POST /api/municipal/source-crop,GET /api/municipal/source-crop/{id},POST /api/municipal/source-crop/{id}/syncGET /api/parcel/{id}/crop?water_year=(synced + overrides + change history + water years) andPUT /api/parcel/{id}/crop(editable allowlist: main_crop, multiuse, irr_typ, county, yr_planted, acres)Tests: attribute mapping ('*' no-data → NULL), geometry conversion, override-wins merge logic.
go vet ./...andgo test ./...clean.Notes for review
'*'in 2024 Provisional and 2023) — kept in schema (free), collected via the user-override layer per Benjamin's call.municipal.source.countyat sync time. If your parcel sources don't carry county values, either set them or passcountieson the crop source config.00238_crop_mapping.sqladds thecrop-syncJobType enum value.Deploy note: needs
goose upfor migration 00238. Then: register the source (URLhttps://utility.arcgis.com/usrsvcs/servers/39b63601dfb34274899d15a13465644e/rest/services/Planning/i15_Crop_Mapping_2024_Provisional/MapServer, water_year 2024) and trigger/sync.CI on this branch was red (run 1018), and while fixing it I found the branch itself had gone sideways, so I sorted it out. Hi diddly ho, review-ready now:
issue-183-crop-datawas pointing atf98b9485— identical to main — so this PR had zero diff. The crop-mapping data layer had been committed on the wrong local branch and never made it here. It is now properly cherry-picked onto this branch:6dbb3094"Add DWR crop mapping source: sync, parcel join, overrides with audit trail".ae01827a— hoistsmaskSource/confirmedOnlyout of the per-item loop inpostTrainManifest. Commitf98b9485declared them inside the loop but the manifest INSERT references them after it, so the api package never compiled on main or any branch on top of it (that is what failed run 1018 here and run 1016 on main). Note: this also turns main green when merged.decbf4ae— wires the crop PUT to a JSON-body handler.crop.ParcelPutreturns the updated parcel-crop card (values, overrides, history), butauthenticatedHandlerJSONPutonly accepts handlers returning a Location string, so the route did not compile. GeneralizedhandlerFunctionPutAuthenticatedwith aResponseTypeand addedauthenticatedHandlerJSONPutBody; all existing Location-style PUT routes are unchanged.Verified locally before pushing:
go vet ./...clean (exactly what the CI golint job runs), plus the new crop unit tests pass (go test ./db/query/municipal/ ./platform/ -run Crop).CI run 1019 on this branch: golint ✅ pnpm-build ✅.
This PR now contains the full crop data layer: source registration, county-scoped sync, parcel↔crop materialized join, and user overrides with audit trail. The Reveal UI parcel card remains the follow-up per the issue.
decbf4ae47658edd5160View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.