Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions farm_field_geo/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

=======================
Farm Field — Geospatial
=======================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:156d6ff91db3f7522e9501d6a413cbc2a2e29881632c0f19543ed5de002262fc
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-ledoent%2Ffarm--pack-lightgray.png?logo=github
:target: https://github.com/ledoent/farm-pack/tree/19.0/farm_field_geo
:alt: ledoent/farm-pack

|badge1| |badge2| |badge3|

Adds PostGIS polygon boundaries to ``farm.field`` and auto-computes
acreage from the geometry.

Without this module, ``farm.field.acres`` is a manual decimal entry.
With it, set a WGS84 polygon as the field's boundary and the acreage
updates from the polygon area, reprojected to EPSG:5070 (Conus Albers
Equal Area) — the projection NRCS and NASS use for lower-48 area
calculations, so the number matches what soil-survey and yield tooling
would report for the same parcel.

``acres`` remains editable as a fallback: fields without a digitized
boundary keep working with a manual estimate, and the compute only fires
once a polygon is set.

**Scope.** This module ships a single ``GeoPolygon`` per field —
non-contiguous plots (two disconnected polygons that are
administratively one "field") should be recorded as separate
``farm.field`` records for now. A future ``farm_field_multi_polygon``
extension can promote the column to ``GeoMultiPolygon`` if the demand
materializes.

**Install requirement.** The Postgres instance must have PostGIS
enabled. ``base_geoengine`` declares the extension; install will fail
cleanly if the extension is missing. The base ``farm_field`` module
stays usable without PostGIS — install this extension only when geometry
support is wanted.

**Table of contents**

.. contents::
:local:

Usage
=====

1. Open Farm → Fields → Fields and pick a field.
2. The **Boundary** notebook tab renders a Leaflet map of the field's
polygon.
3. Set the polygon via the geoengine map view (vertex drag works there)
or by importing a WKT string. In-form vertex editing through the
boundary tab arrives once ``web_leaflet_draw_lib`` is migrated to
Odoo 19.
4. Save. The **Acres** field auto-recomputes from the polygon area,
reprojected to EPSG:5070 Albers Equal Area.
5. Switch the action's view to **Map** (geoengine) to see every field at
once.

The ``acres`` field stays editable as a fallback: fields without a
digitized boundary can carry a manual estimate. Once a polygon is set,
the compute overrides the manual value.

Multi-plot fields (a "north 40" that is two non-contiguous polygons)
need ``GeoMultiPolygon`` rather than ``GeoPolygon`` — out of scope for
the MVP; record each plot as its own ``farm.field`` for now.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/ledoent/farm-pack/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/ledoent/farm-pack/issues/new?body=module:%20farm_field_geo%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Ledo Enterprises

Contributors
------------

- Daniel Kendall <dkendall@ledoweb.com>

Maintainers
-----------

.. |maintainer-dnplkndll| image:: https://github.com/dnplkndll.png?size=40px
:target: https://github.com/dnplkndll
:alt: dnplkndll

Current maintainer:

|maintainer-dnplkndll|

This module is part of the `ledoent/farm-pack <https://github.com/ledoent/farm-pack/tree/19.0/farm_field_geo>`_ project on GitHub.

You are welcome to contribute.
1 change: 1 addition & 0 deletions farm_field_geo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions farm_field_geo/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "Farm Field — Geospatial",
"version": "19.0.1.0.0",
"summary": "PostGIS polygons + auto-computed acreage for farm.field",
"author": "Ledo Enterprises, Odoo Community Association (OCA)",
"maintainers": ["dnplkndll"],
"website": "https://github.com/ledoent/farm-pack",
"license": "AGPL-3",
"category": "Vertical/Agriculture",
"depends": [
"farm_field",
"base_geoengine",
],
"data": [
"views/farm_field_views.xml",
],
"installable": True,
"application": False,
}
1 change: 1 addition & 0 deletions farm_field_geo/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import farm_field
37 changes: 37 additions & 0 deletions farm_field_geo/models/farm_field.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from odoo import api, fields, models

# Square meters in one US survey acre. Used to convert EPSG:5070 area
# (Albers Equal Area, units = m^2) to acres.
M2_PER_ACRE = 4046.8564224

# Conus Albers Equal Area — the projection NRCS and USDA use for area
# calculations across the lower 48. We reproject the WGS84 polygon to 5070
# before measuring area so the number matches what soil-survey and NASS
# tooling would report for the same parcel.
ALBERS_CONUS_SRID = 5070


class FarmField(models.Model):
_inherit = "farm.field"

geom = fields.GeoPolygon(
string="Boundary",
srid=4326,
help="Field boundary as a WGS84 polygon. Drives the computed acreage; "
"stored as PostGIS geometry.",
)
acres = fields.Float(
compute="_compute_acres_from_geom",
store=True,
readonly=False,
digits=(8, 2),
help="Auto-computed from the polygon area when a boundary is drawn. "
"Editable as a fallback for fields without a digitized boundary yet.",
)

@api.depends("geom")
def _compute_acres_from_geom(self):
for rec in self:
if not rec.geom:
continue
rec.acres = rec.geom.transform(ALBERS_CONUS_SRID).area / M2_PER_ACRE
3 changes: 3 additions & 0 deletions farm_field_geo/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
1 change: 1 addition & 0 deletions farm_field_geo/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Daniel Kendall &lt;dkendall@ledoweb.com&gt;
23 changes: 23 additions & 0 deletions farm_field_geo/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Adds PostGIS polygon boundaries to `farm.field` and auto-computes acreage
from the geometry.

Without this module, `farm.field.acres` is a manual decimal entry. With it,
set a WGS84 polygon as the field's boundary and the acreage updates from the
polygon area, reprojected to EPSG:5070 (Conus Albers Equal Area) — the
projection NRCS and NASS use for lower-48 area calculations, so the number
matches what soil-survey and yield tooling would report for the same parcel.

`acres` remains editable as a fallback: fields without a digitized boundary
keep working with a manual estimate, and the compute only fires once a
polygon is set.

**Scope.** This module ships a single `GeoPolygon` per field — non-contiguous
plots (two disconnected polygons that are administratively one "field")
should be recorded as separate `farm.field` records for now. A future
`farm_field_multi_polygon` extension can promote the column to
`GeoMultiPolygon` if the demand materializes.

**Install requirement.** The Postgres instance must have PostGIS enabled.
`base_geoengine` declares the extension; install will fail cleanly if the
extension is missing. The base `farm_field` module stays usable without
PostGIS — install this extension only when geometry support is wanted.
16 changes: 16 additions & 0 deletions farm_field_geo/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
1. Open Farm → Fields → Fields and pick a field.
2. The **Boundary** notebook tab renders a Leaflet map of the field's polygon.
3. Set the polygon via the geoengine map view (vertex drag works there) or by
importing a WKT string. In-form vertex editing through the boundary tab
arrives once `web_leaflet_draw_lib` is migrated to Odoo 19.
4. Save. The **Acres** field auto-recomputes from the polygon area, reprojected
to EPSG:5070 Albers Equal Area.
5. Switch the action's view to **Map** (geoengine) to see every field at once.

The `acres` field stays editable as a fallback: fields without a digitized
boundary can carry a manual estimate. Once a polygon is set, the compute
overrides the manual value.

Multi-plot fields (a "north 40" that is two non-contiguous polygons) need
`GeoMultiPolygon` rather than `GeoPolygon` — out of scope for the MVP;
record each plot as its own `farm.field` for now.
Empty file.
Loading