ManageFarms: R6 Class for adding or updating farm information in OFPE...

ManageFarmsR Documentation

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

Description

R6 class that takes a database connection object, path to the folder with the farm boundaries, and a list with farm information to upload. Uploads boundaries to the database. Adds a unique ID field for each farm that is used for internal relationships. If a farm 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.

farm_info

List of farms to update, with each element a list with a 'farm_name' field for the name of the farm, a 'farm_shp_name' field with the name of the shapefile with the farm boundary, and a field called 'farmer_name' with the name of the farmer who own the farm.

farm_path

File path to the location of farm boundary shapefiles.

farms

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

Methods

Public methods


Method new()

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

Usage
ManageFarms$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 AddFarms method, from the list passed into the ManageDB class. This includes a list of farm information and a path to where the farm boundaries are stored.

Returns

A new initialized 'ManageFarms' object.


Method setup()

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

Usage
ManageFarms$setup()
Arguments
None

No arguments needed because they are provided during class initialization.

Returns

Prepared R6 class for uploading farmer information.


Method execute()

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

Usage
ManageFarms$execute()
Arguments
None

No arguments needed because they are provided during class initialization.

Returns

Farm data uploaded into the 'all_farms.farms' table in the database.


Method .setupFarms()

Converts a list with information about the farms 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. Converts to EPSG 4326 for storage.

Usage
ManageFarms$.setupFarms(farm_info, farm_path = NULL)
Arguments
farm_info

List with information about the farm to upload.

farm_path

Path to the location of farm boundary shapefiles.

Returns

ESRI shapefile of farm boundary.


Method .uploadFarms()

Uploads a farm to the database. Takes the farm shapefile and identifies the coresponding farmeridx, adds it as a column, and then uploads to the 'all_farms.farms' table. Makes sure there is no conflict defined in the .buildTables method of the BuildDB class. A farmidx is automatically generated upon upload by PostgreSQL and the area of the farm is calculated and converted to acres. The dot indicates that this function would be private if not for documentations sake.

Usage
ManageFarms$.uploadFarms(farm, db)
Arguments
farm

Farm shapefile for upload into 'all_farms.farmers'.

db

Database connection.

Returns

Farm upload into database.


Method clone()

The objects of this class are cloneable with this method.

Usage
ManageFarms$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.