ManageFields: R6 Class for adding or updating field information in OFPE...

ManageFieldsR Documentation

R6 Class for adding or updating field information in OFPE database.

Description

R6 class that takes a database connection object, path to the folder with the field boundaries, and a list with field information to upload. Uploads boundaries to the database. Adds a unique ID column for each field that is used for internal relationships. If a field is already present in the database, it's information will be updated. This follows the ManageDB interface and includes a setup and execute method that is called from the ManageDB class.

Public fields

dbCon

Database connection object connected to an OFPE formatted database, see DBCon class.

field_info

List of fields to update, with each element a list with a 'field_name' element for the name of the field, a 'field_shp_name' element with the name of the shapefile with the field boundary, and a element called 'farmer_name' with the name of the farmer who own the field.

field_path

File path to the location of field boundary shapefiles.

fields

List with data prepared for upload to the database. Contains shapefiles with a column indicating the associated farmer and farm name.

Methods

Public methods


Method new()

Create an ManageFields object. The database connection and a list with field information used to upload field information to the database with the appropriate owner information. The field_path argument indicates the file path in which to follow for the field boundary shapefiles that are to be uploaded to the database. Instantiates the class for running the setup and execute methods.

Usage
ManageFields$new(dbCon, action_item)
Arguments
dbCon

Database connection object connected to an OFPE formatted database, see DBCon class.

action_item

List of inputs to the AddFields method, from the list passed into the ManageDB class. This includes a list of field information and a path to where the field boundaries are stored.

Returns

A new initialized 'AddFields' object.


Method setup()

Prepares the field data prior to uploading to the database. Imports shapefiles from the field path and puts them into a list with the corresponding farmer to be uploaded to the database.

Usage
ManageFields$setup()
Arguments
None

No arguments needed because they are provided during class initialization.

Returns

Prepared R6 class for uploading field information.


Method execute()

Executes the upload of prepared field information to the database in the 'all_farms' schema and the 'fields' table. If a field boundary is already present with the same field name and farmer that owns it, the entry in the database is replaced.

Usage
ManageFields$execute()
Arguments
None

No arguments needed because they are provided during class initialization.

Returns

Field data uploaded into the 'all_farms.fields' table in the database.


Method .setupFields()

Converts a list with information about the fields into a format ready for uploading to the database. Imports the shapefile using the path name in the list provided and adds a column for the farmer name. If fields contain multiple unconnected portions, the 'id' column associated with these sections is renamed 'wfid' for 'within field ID'. Converts to EPSG 4326 for storage.

Usage
ManageFields$.setupFields(field_info, field_path = NULL)
Arguments
field_info

List with information about the field to uplaod.

field_path

Path to the location of field boundary shapefiles.

Returns

ESRI shapefile of field boundary.


Method .uploadFields()

Uploads a field to the database. Takes the field shapefile and identifies the corresponding farmeridx, adds it as a column, and then uploads to the 'all_farms.fields' table. Makes sure there is no conflict defined in the .buildTables method of the BuildDB class. A fieldidx is automatically generated upon upload by PostgreSQL based on the 'wfid' and 'fieldname'. After uploading, PostGIS is used to identify the farm the field falls within and a the 'farmidx' column is filled and the area of the field is calculated and converted to acres. The dot indicates that this function would be private if not for documentations sake.

Usage
ManageFields$.uploadFields(field, db)
Arguments
field

Field shapefile for upload into 'all_farms.fields'.

db

Database connection.

Returns

Field upload into database.


Method clone()

The objects of this class are cloneable with this method.

Usage
ManageFields$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

DBCon for database connection class, ManageDB for the class that calls this class to manage the database.


paulhegedus/OFPE documentation built on Nov. 23, 2022, 5:09 a.m.