ManageFields | R Documentation |
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.
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.
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.
ManageFields$new(dbCon, action_item)
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.
A new initialized 'AddFields' object.
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.
ManageFields$setup()
None
No arguments needed because they are provided during class initialization.
Prepared R6 class for uploading field information.
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.
ManageFields$execute()
None
No arguments needed because they are provided during class initialization.
Field data uploaded into the 'all_farms.fields' table in the database.
.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.
ManageFields$.setupFields(field_info, field_path = NULL)
field_info
List with information about the field to uplaod.
field_path
Path to the location of field boundary shapefiles.
ESRI shapefile of field boundary.
.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.
ManageFields$.uploadFields(field, db)
field
Field shapefile for upload into 'all_farms.fields'.
db
Database connection.
Field upload into database.
clone()
The objects of this class are cloneable with this method.
ManageFields$clone(deep = FALSE)
deep
Whether to make a deep clone.
DBCon
for database connection class,
ManageDB
for the class that calls this class to manage the database.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.