Skip to content

Commit

Permalink
Add group property from raster interface to GUI
Browse files Browse the repository at this point in the history
Updates #761
  • Loading branch information
shawnlaffan committed Apr 23, 2022
1 parent 9f34b61 commit 61a9a4f
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
12 changes: 12 additions & 0 deletions bin/ui/wndMain.ui
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,17 @@ If that is the case then randomisations would be invalidated for those analyses.
<signal handler="on_basedata_attach_properties" name="activate"/>
</object>
</child>
<child>
<object class="GtkAction" id="menu_attach_basedata_group_properties_from_rasters">
<property name="name">menu_attach_basedata_group_properties_from_rasters</property>
<property name="tooltip" translatable="yes">Attach properties (e.g. environmental conditions) to the groups.
It will only work if your basedata has no analysis outputs,
as these might have used existing properties.
If that is the case then randomisations would be invalidated for those analyses. </property>
<property name="label" translatable="yes">Attach group properties from a set of rasters</property>
<signal handler="on_basedata_attach_group_properties_from_rasters" name="activate"/>
</object>
</child>
<child>
<object class="GtkAction" id="menu_attach_ranges_as_properties">
<property name="name">menu_attach_ranges_as_properties</property>
Expand Down Expand Up @@ -751,6 +762,7 @@ This cannot be undone. </property>
<menuitem action="menu_rename_basedata_groups"/>
<menuitem action="menu_binarise_basedata_elements"/>
<menuitem action="menu_attach_basedata_properties"/>
<menuitem action="menu_attach_basedata_group_properties_from_rasters"/>
<menuitem action="menu_attach_ranges_as_properties"/>
<menuitem action="menu_attach_abundances_as_properties"/>
<menuitem action="menu_delete_element_properties"/>
Expand Down
3 changes: 3 additions & 0 deletions lib/Biodiverse/GUI/Callbacks.pm
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ my %data_funcs = (
on_basedata_attach_properties => {
METHOD => 'do_basedata_attach_properties',
},
on_basedata_attach_group_properties_from_rasters => {
METHOD => 'do_basedata_attach_group_properties_from_rasters',
},
on_basedata_attach_label_abundances_as_properties => {
METHOD => 'do_basedata_attach_label_abundances_as_properties',
},
Expand Down
62 changes: 62 additions & 0 deletions lib/Biodiverse/GUI/Manager/BaseDatas.pm
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,68 @@ sub do_basedata_attach_properties {
return;
}

sub do_basedata_attach_group_properties_from_rasters {
my $self = shift;

my $bd = $self->{project}->get_selected_base_data();
croak "Cannot add properties to Basedata with existing outputs\n"
. "Use the Duplicate Without Outputs option to create a copy without deleting the outputs.\n"
if $bd->get_output_ref_count;


my $dlg = Gtk2::FileChooserDialog->new(
'Select one or more rasters',
undef,
'open',
'gtk-cancel' => 'cancel',
'gtk-ok' => 'ok',
);
$dlg->set_select_multiple(1);

my $filter = Gtk2::FileFilter->new();
$filter->set_name("raster files");
foreach my $extension (qw /tif tiff img asc flt/) {
$filter->add_pattern("*.$extension");
}
$dlg->add_filter($filter);
$dlg->set_modal(1);

my $response = $dlg->run;

return if !$response eq 'ok';

my @raster_list = $dlg->get_filenames();

$dlg->destroy();

my $basedatas = $bd->assign_group_properties_from_rasters(
rasters => \@raster_list,
#return_basedatas => $return_basedatas,
);

$self->set_dirty();

my $count = @raster_list;
my $summary_text
= "Assigned properties using $count rasters.\n"
. "If not all are assigned then check the respective "
. "extents and coordinate systems.";
my $summary_dlg = Gtk2::MessageDialog->new(
$self->{gui},
'destroy-with-parent',
'info', # message type
'ok', # which set of buttons?
$summary_text,
);
$summary_dlg->set_title('Assigned properties');

$summary_dlg->run;
$summary_dlg->destroy;

return;
}


sub do_delete_element_properties {
my $self = shift;
my $bd = $self->{project}->get_selected_base_data;
Expand Down
1 change: 1 addition & 0 deletions lib/Biodiverse/GUI/Project.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,7 @@ sub manage_empty_basedatas {
menu_rename_basedata_labels
menu_rename_basedata_groups
menu_attach_basedata_properties
menu_attach_basedata_group_properties_from_rasters
menu_delete_element_properties
menu_basedata_reorder_axes
menu_basedata_drop_axes
Expand Down

0 comments on commit 61a9a4f

Please sign in to comment.