diff --git a/bin/ui/wndMain.ui b/bin/ui/wndMain.ui index eb2c9f5f7..0b2f2cfc1 100644 --- a/bin/ui/wndMain.ui +++ b/bin/ui/wndMain.ui @@ -249,6 +249,17 @@ If that is the case then randomisations would be invalidated for those analyses. + + + menu_attach_basedata_group_properties_from_rasters + 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. + Attach group properties from a set of rasters + + + menu_attach_ranges_as_properties @@ -751,6 +762,7 @@ This cannot be undone. + diff --git a/lib/Biodiverse/GUI/Callbacks.pm b/lib/Biodiverse/GUI/Callbacks.pm index b9b412f6e..513a29a76 100644 --- a/lib/Biodiverse/GUI/Callbacks.pm +++ b/lib/Biodiverse/GUI/Callbacks.pm @@ -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', }, diff --git a/lib/Biodiverse/GUI/Manager/BaseDatas.pm b/lib/Biodiverse/GUI/Manager/BaseDatas.pm index b80a72fa5..975dcf233 100644 --- a/lib/Biodiverse/GUI/Manager/BaseDatas.pm +++ b/lib/Biodiverse/GUI/Manager/BaseDatas.pm @@ -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; diff --git a/lib/Biodiverse/GUI/Project.pm b/lib/Biodiverse/GUI/Project.pm index 5953a717e..fd3e8a9e0 100644 --- a/lib/Biodiverse/GUI/Project.pm +++ b/lib/Biodiverse/GUI/Project.pm @@ -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