support_scripts package¶
This is some script that didn’t fit in any other places, the scripts supports the other scripts
add_field module¶
-
class
geodatafarm.support_scripts.add_field.
AddField
(parent_widget)¶ Bases:
object
This class handle the creation of Fields. This class is also imported in the MeanAnalyse class.
- Parameters
parent_widget (GeoDataFarm) –
-
clicked_define_field
(ignore_name=True)¶ Creates an empty polygon that’s define a field
-
finish
(result, values)¶ Produces either an error message telling what went wrong or adds the fields to canvas and zoom to the layers.
- Parameters
result (object) –
values (list) –
- If all went ok:
[True, list of layers]
- Else:
[False, exception, traceback]
-
help
()¶ A function that gives some advice on how the function works for the user.
-
quit
()¶ Closes the widget.
-
remove_field
()¶ Removes a field that the user wants, a check that there are no data that is depended on is made.
-
run
()¶ Presents the sub widget AddField and connects the different buttons to their function
-
save
()¶ Saves the field in the database
-
set_widget_connections
()¶ Function that sets the main widget connections.
-
view_fields
()¶ Add all fields that aren’t displayed on the canvas, if no background map is loaded Google maps are loaded.
-
geodatafarm.support_scripts.add_field.
add_fields_2_canvas
(task, db, fields_db, defined_field, sources)¶ A function that adds fields that are not added previously.
- Parameters
task (QgsTask) – a QgsTask to run the function in
db (DB) – A database connection
fields_db (list) – list of the names of all fields in the database
defined_field (str) – the last added field name
sources (list) – list of source names
- Returns
- If all went ok:
[True, list of layers]
- Else:
[False, exception, traceback]
- Return type
list
add_layer_to_canvas module¶
-
class
geodatafarm.support_scripts.add_layer_to_canvas.
AddLayerToCanvas
(parent)¶ Bases:
object
A class that adds layers to the canvas
The function adds AddToCanvas class on self.dlg The function populate_widget is run with this function.
- Parameters
parent (object) – The GeoDataFarm parent class
-
add_2_canvas
(data)¶ Adds the parameter to the canvas
- Parameters
data (dict) – A dict containing index_col, tbl_name, schema
-
add_selected
()¶ All checked items in the ListWidget is added to the canvas. Afterwards the button becomes disconnected and this widget closes
-
get_tables
()¶ Fills the dict ‘parameters’ with an int as key and a dict as the value The value dict has following args: index_col, schema, and tbl_name
-
populate_widget
()¶ For all selected data sets in the GeoDataFarm widget adds all column names to a ListWidget except if there is only one, then it is directly added to the canvas.
-
run
()¶ Displays the widget and connects the button
create_guiding_file module¶
-
class
geodatafarm.support_scripts.create_guiding_file.
CreateGuideFile
(parent_widget)¶ Bases:
object
This class creates a guide file
- Parameters
parent_widget (GeoDataFarm) –
-
add_to_param_list
()¶ Adds the selected columns to the list of fields that should be treated as “special” in the database both to work as a parameter that could be evaluated and as a layer that is added to the canvas
-
create_file
()¶ Creates the guide file with the information from the user.
-
fill_cb
()¶ Updates the ComboBox with names from the differnt schemas in the database
-
help
()¶ Shows a help message in a QMessageBox
-
possible_attr
(text)¶ Adds the name of the table which the user than can use as base for calculation of the guiding file.
- Parameters
text (str) – The schema.table
-
remove_from_param_list
()¶ Removes the selected columns from the list of fields that should be treated as “special” in the database
-
run
()¶ Presents the sub widget HandleInput and connects the different buttons to their function
-
set_output_path
()¶ Sets the path where the guide file should be saved.
-
update_max_min
()¶ Update the text min, max text and set the equation for the guide file.
create_layer module¶
-
class
geodatafarm.support_scripts.create_layer.
CreateLayer
(db, dock_widget=None)¶ Bases:
object
Creates a layer with color coded attributes
-
create_layer_style
(layer, target_field, tbl_name, schema, min=None, max=None, steps=20)¶ Create the layer and adds the layer to the canvas
- Parameters
layer (QgsVectorLayer) –
target_field (str) –
tbl_name (str) –
schema (str) –
min (float, optional) –
max (float, optional) –
steps (int, optional default 20) –
-
equal_count
(layer, data_values_list, field, steps=10, min_value=None, max_value=None)¶ - Parameters
layer –
data_values_list –
field –
steps –
min_value –
max_value –
-
repaint_layer
()¶ Applies the new min and max and repaints the layer with new colors
-
-
geodatafarm.support_scripts.create_layer.
add_background
()¶ Check if there are no other tiles present on the canvas then adds a google satellite as a background map.
-
geodatafarm.support_scripts.create_layer.
hist_edges_equal
(x, nbin)¶ - Histogram with equal number of points in each bin, inspired by:
https://stackoverflow.com/questions/39418380/histogram-with-equal-number-of-points-in-each-bin
- Parameters
x (list) – list of all values to put in the histogram
nbin (int) – Number of bins to use in the histogram
- Returns
Returns the second parameter (bins) in plt.hist
- Return type
bins
-
geodatafarm.support_scripts.create_layer.
set_label
(layer, field_label)¶ Function that sets the label to a field value. Inspiration found at: https://gis.stackexchange.com/questions/277106/loading-labels-from-python-script-in-qgis
- Parameters
layer (QgsVectorLayer) – valid qgis layer.
field_label (str) – The label of the field
-
geodatafarm.support_scripts.create_layer.
set_zoom
(iface, extra_extent)¶ Sets the zoom level to include all layers (excluding tiles layer) with some extra extent
- Parameters
iface (QGIS interface) – The QGIS iface module.
extra_extent (float) – How much extra space around the layers eg. 1.1 is 10% extra
generate_reports module¶
-
class
geodatafarm.support_scripts.generate_reports.
MyDocTemplate
(filename, plugin_dir, growing_year, cur_date, **kw)¶ Bases:
reportlab.platypus.doctemplate.BaseDocTemplate
Generate a basic A4 pdf document
- Parameters
filename (str) – The file name to store the PDF document
tr (translation) – The Translation function from GeoDataFarm
plugin_dir (str) – path to the plugin dir in order to find the icon
growing_year (int) – What growing year
cur_date (str) – Current date, to write on the report
kw –
-
header
(canvas, doc, growing_year, cur_date)¶ Create the header of the document
- Parameters
canvas –
doc –
growing_year (int) –
cur_date (str, with the current date) –
-
class
geodatafarm.support_scripts.generate_reports.
RapportGen
(parent)¶ Bases:
object
Generates reports from GeoDataFarm
- Parameters
parent (GeoDataFarm) –
-
static
collect_data
(task, data)¶ Collect data from the different schemas at the server and store them in a dict
- Parameters
task (QgsTask) –
data (dict) –
- Returns
- if success:
[bool, dict]
- else:
[bool, str, str]
- Return type
list
-
report_per_field
()¶ Creates a QgsTask in order to collect data then on finish it runs simple_field.
-
report_per_operation
()¶ Creates a QgsTask in order to collect data then on finish it runs simple_operation.
-
select_folder
()¶ A function that lets the user select the folder for the generated reports. The self.path will be updated with this function.
-
set_widget_connections
()¶ A simple function that sets the buttons on the report tab
-
simple_field
(result, values)¶ Generates a simple report of all operations listed by fields.
- Parameters
result (QgsTask.result) – Not used
values (list) –
- if success:
[True, dict]
- else:
[False, message, tracback]
-
simple_operation
(result, values)¶ Generates a simple report of all operations
- Parameters
result (QgsTask.result) – Not used
values (list) –
- if success:
[True, dict]
- else:
[False, message, tracback]
multiedit module¶
-
class
geodatafarm.support_scripts.multiedit.
MultiEdit
(parent)¶ Bases:
object
This class enable the user to edit the attributes in a simple way, it is almost a copy of QuickMultiAttributeEdit, so all cred to them for it! https://github.com/lucadelu/QuickMultiAttributeEdit
Initiate the plugin and calls on do_checks
-
do_checks
()¶ Checks that all is ready to be updated
-
run
()¶ Change the values, if it is a postgres database source it does the update directly to the server and then reloads the layer.
-
show
()¶ Displays the widget
-
-
geodatafarm.support_scripts.multiedit.
bool2str
(b_var)¶ Converts a str to bool
- Parameters
b_var (bool) –
- Returns
- Return type
str
-
geodatafarm.support_scripts.multiedit.
rm_if_too_old_settings_file
(my_path_and_file)¶ Removes the settings file if it is too old.
-
geodatafarm.support_scripts.multiedit.
str2bool
(b_var)¶ Converts a str to bool
- Parameters
b_var (str) –
- Returns
- Return type
bool
populate_lists module¶
-
class
geodatafarm.support_scripts.populate_lists.
Populate
(parent)¶ Bases:
object
A class to set/reload list widgets and comboBoxes
Starts/resets the class and all its objects, calls: - reload_fields,
reload_crops,
update_table_list
- Parameters
parent (GeoDataFarm class) –
-
get_items_in_table
()¶ Returns the list of list ‘items in table’ :returns: :rtype: list
-
get_lw_list
()¶ Function returns the list of lists with [[ListWidget, ‘name’]] :returns: :rtype: list
-
reload_crops
(cmd_box=None)¶ Reloads all crops comboBoxes in the GeoDataFarm widget :param cmd_box: a comboBox to fill with the crop names (used in text_data_handler) :type cmd_box: QtComboBox, optional
-
reload_fields
(cmd_box=None)¶ Reloads all field comboBoxes in the GeoDataFarm widget :param cmd_box: a comboBox to fill with the field names (used in text_data_handler) :type cmd_box: QtComboBox, optional
-
update_table_list
()¶ Update the list of tables in the docket widget
radio_box module¶
rain_dancer module¶
-
class
geodatafarm.support_scripts.rain_dancer.
MyRainDancer
(client='000001', username='Demo', password='Demo')¶ Bases:
object
Creates a Raindancer object with auth
- Parameters
client (str) –
username (str) –
password (str) –
-
get_operation_data
()¶ Collects data from crops returns a list of list with guid and names for the crops
- Returns
dict
or str = Failed
RG module¶
-
geodatafarm.support_scripts.RG.
rg
(percent)¶ A colour map with 100 colours, from green(0) to yellow to red(1)
- Parameters
percent (float) – Anywhere between 0 and 1
- Returns
The RGB code corresponding to the percentage, 0=red, 0.5 yellow and 1=green
- Return type
list
fix_rows module¶
-
class
geodatafarm.support_scripts.fix_rows.
RowFixer
(parent)¶ Bases:
object
Runs Row Fixer
References
self: fill_cb
Connects
self: initiate_update
-
fill_cb
()¶ Updates the ComboBox with names from the different schemas in the database
References
- db: get_tabels_in_db
schema
Connects
self: set_possible_columns
-
finish
(result, values)¶ CProduce a message telling if the operation went well or not
- Parameters
result (object) – The result object
values (list) – list with [bool, str, str]
-
initiate_update
()¶ Initiate the update with QgsTask manager
Connects
self: update_geom
-
set_possible_columns
(text)¶ Adds the columns that could be used.
- Parameters
text (str) – The schema.table
References
- db: get_all_columns
table, schema, exclude
-
update_geom
(task)¶ Runs the sql query that updates the ‘polygon’ and adds ‘new_row_id
- Parameters
task (QgsTask) –
References
- db: execute_sql
sql
-