Geofencing
Captures the boundary of a land parcel or crop block as a KML polygon, by walking with GPS, tapping points, drawing in Google Earth or uploading a KML file.
FactsheetAssets & land
- Who uses it
- Cadre user
- How you get here
- Geofence button on a Land row, on a Crop Actual card, or on an ATM item. Compact-block screens reuse the map read-only.
- Tables
farmerassets,ie_asset,portfolio_portfoliolineitem,farming_model- APIs
- 7 calls today, 8 App Service operations
- Offline
- OSM capture works offline (map tiles cached about 3 months). The KML is saved under files/geofencing/ and uploaded later; Google Earth and downloading an existing URL KML need the respective app/internet.
Screens
| Screen | What it does | Source |
|---|---|---|
| Geofencing options | Shows target id and existing geofence; pick a capture method or preview. | app/src/main/java/org/platformcommons/urvi/view/geofencing/GeofencingOptionsActivity.kt |
| Geofencing map | OpenStreetMap capture (fixed, motion, tap) and read-only preview. | app/src/main/java/org/platformcommons/urvi/view/geofencing/GeofencingMapActivity.kt |
| Geofencing view model | Writes the KML and queues the upload. | app/src/main/java/org/platformcommons/urvi/view/geofencing/GeofencingViewModel.kt |
What it captures
| Field | Type | Required | Validation | Options from |
|---|---|---|---|---|
| Capture method | Choice | Yes | OSM Fixed (drag marker, Add point at each corner), OSM Motion (GPS every 2 s, a point each time the user moves more than 5 m), OSM Tap (Capture location drops the current GPS fix), Google Earth (draw and export KML), Upload KML (file picker). | Each method switched on/off by reference data |
| Use existing / Capture new | Choice | If a Crop Actual target has no geofence but its land does | "Use existing" copies the land KML. | Land geofence |
Rules
Conditions from the code, rewritten as plain decision rules.
| When | Then |
|---|---|
| Geofencing for assets is switched off | The Land row geofence button is hidden. |
| The land has 0 acres | The geofence button refuses to open. |
| The target is ATM and has no Tile Id | The screen does not open. |
| No geofence exists yet | A consent dialog "Do you want to capture geofencing?" appears first; Cancel closes the screen. |
| The stored geofence is a URL | The KML is downloaded first; without internet: "Internet not available" or "Unable to download file". |
| The user stops capture | The loop is closed by repeating the first point; with zero points: "No geofencing added". |
| The user stops capture with points | A dialog offers Save, Restart or Preview. |
| A land geofence is saved | It is auto-applied to every current-season, current-month Crop Actual block and every ATM on that land that has no geofence yet. |
| A land geofence is queued | Its upload waits until the farmer create and the land create have synced. |
| Land row geofence state | Green tick = synced, yellow cloud = captured not synced, red = none. |
API contracts
Each call opens to its use case, headers, request and response bodies, and errors.
| App Service v2: operation | Use |
|---|---|
GET /config | Typed config bundle (ETag) |
GET /farmers/snapshot | Cursor-paged hydrated farmer snapshot |
GET /farmers/{farmerId}/lands | A farmer's land parcels |
POST /sync/batch | Apply an ordered batch of offline mutations |
POST /files | Create a file upload (resumable or single-shot) |
GET /files/{fileId} | File metadata and signed download URL |
PATCH /files/{fileId} | Append a chunk to a resumable upload |
HEAD /files/{fileId} | Current offset of a resumable upload |
Behaviour notes
- KML file name: <id or IE alias>_<millis>_<MODULE>_<OSM|googleEarth>.kml, coordinates stored as lon,lat,0.
- Privacy the KML embeds the farmer name and village (plus device and ids) in plain text in its description.
- Possible bug · unverified there is no minimum point count, so a 1-point "polygon" can be saved.
- Possible bug · unverified there is no GPS accuracy threshold, no area calculation, no comparison with declared acres and no self-intersection check.
Improve in the rewrite
- Require at least 3 points, reject fixes worse than about 10-15 m accuracy, compute area and warn when it differs a lot from declared acres.
- Show live accuracy, point count, area and perimeter; allow undo of the last point.
- Remove personal data from the KML; send it as metadata if needed.
- Replace "Preview" as the dialog's negative button with a clear Cancel.