Skip to content

Commit

Permalink
Raster imports: handle north-oriented file orders
Browse files Browse the repository at this point in the history
This boils down to south-oriented files needing to be
shifted down half a basedata cell while south oriented files
are shifted up.

Updates #845
  • Loading branch information
shawnlaffan committed Jan 31, 2023
1 parent 7cd3027 commit 18f22df
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/Biodiverse/BaseData/Import.pm
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,9 @@ sub import_data_raster {
# that it should since Biodiverse doesn't either.
$cellsize_e ||= abs $tf_1;
$cellsize_n ||= abs $tf_5;
if ($tf_5 < 0) { # shift down south-oriented files
$halfcellsize_n = -(abs $halfcellsize_n);
}

# iterate over each band
foreach my $band_id ( 1 .. $band_count ) {
Expand Down Expand Up @@ -835,7 +838,7 @@ sub import_data_raster {
floor( ( $ngeo - $cellorigin_n ) / $cellsize_n );
$grpn =
$cellorigin_n +
$ncell * $cellsize_n -
$ncell * $cellsize_n +
$halfcellsize_n;
}

Expand Down Expand Up @@ -878,10 +881,9 @@ sub import_data_raster {
$ngeo = $tf_3 + $gridx * $tf_4 + $gridy * $tf_5;
$ncell = floor( ( $ngeo - $cellorigin_n ) / $cellsize_n );

# subtract half cell width since position is top-left
$grpn =
$cellorigin_n +
$ncell * $cellsize_n -
$ncell * $cellsize_n +
$halfcellsize_n;

# cannot guarantee constant groups
Expand Down

0 comments on commit 18f22df

Please sign in to comment.