Skip to content

Commit

Permalink
Cluster outputs: add option to export grouped data to shapefile
Browse files Browse the repository at this point in the history
Updates #757
  • Loading branch information
shawnlaffan committed Nov 11, 2021
1 parent ce449bc commit 9e40b4b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/Biodiverse/BaseStruct/Export.pm
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ sub export_shapefile {
if (defined $list_name) { # repeated polys per list item
push @list_col_specs_gdal,
{Name => 'KEY', Type => 'String'},
{Name => 'VALUE', Type => 'Real'},
{Name => 'VALUE', Type => $args{list_val_type} // 'Real'},
}

my $layer = GetDriver('ESRI Shapefile')
Expand Down
34 changes: 34 additions & 0 deletions lib/Biodiverse/Cluster.pm
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,40 @@ sub export_shapefile {
return;
}

sub get_metadata_export_shapefile_grouped {
my $self = shift;

my $metadata = $self->get_metadata_export_shapefile;
$metadata->{format} = 'Shapefile grouped';
push @{$metadata->{parameters}},
$self->get_grouped_export_metadata;
splice @{$metadata->{parameters}}, 1, 1; # dirty hack

for (@{$metadata->{parameters}}) {
bless $_, $parameter_metadata_class;
}

return wantarray ? %$metadata : $metadata;
}

sub export_shapefile_grouped {
my ($self, %args) = @_;

my $bs = $self->to_basestruct_group_nodes(
%args,
terminals_only => 1,
#sub_list => $args{list},
);
$bs->set_param(CELL_SIZES => scalar $self->get_basedata_ref->get_cell_sizes);

$bs->export_shapefile (
%args,
list => 'node_data',
list_val_type => 'String', # hacky that we need to set this
);

return;
}

# some of this can be refactored wth Spatial::get_spatial_conditions_ref
sub process_spatial_conditions_and_def_query {
Expand Down
20 changes: 14 additions & 6 deletions lib/Biodiverse/Tree.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1221,11 +1221,8 @@ sub export_tabular_tree {
return 1;
}

sub get_metadata_export_table_grouped {
my ($self, %args) = @_;

my @parameters = (
$args{sub_list_meta} || $self->get_lists_export_metadata(),
sub get_grouped_export_metadata {
my @params = (
{
name => 'num_clusters',
label_text => 'Number of groups',
Expand Down Expand Up @@ -1257,6 +1254,16 @@ sub get_metadata_export_table_grouped {
type => 'boolean',
default => 0,
},
);

return wantarray ? @params : \@params;
}

sub get_metadata_export_table_grouped {
my ($self, %args) = @_;

my @parameters = (
$args{sub_list_meta} || $self->get_lists_export_metadata,
{
name => 'symmetric',
label_text => 'Force output table to be symmetric',
Expand Down Expand Up @@ -1290,7 +1297,8 @@ sub get_metadata_export_table_grouped {
type => 'boolean',
default => 1,
},
$self->get_table_export_metadata(),
$self->get_grouped_export_metadata,
$self->get_table_export_metadata,
);

for (@parameters) {
Expand Down

0 comments on commit 9e40b4b

Please sign in to comment.