/*! \page tips Tips and tricks This page is for tips and tricks when working with Geo::GDAL. \section tips_preamble First few lines You should probably use [Perlbrew](https://perlbrew.pl/) and the latest Perl. \code #!/usr/bin/env perl use strict; use v5.10; use Geo::GDAL; \endcode \section tips_progress GDAL style progress function in Perl \code # call this somewhere early: $|++; # flush print right away for one line progress sub progress { state $s = -1; # requires 'use v5.10;' my $p = int($_[0]*100); return 1 if $p == $s; $s = 0 if $s < 0; while ($s < $p) { print $s%10 == 0 ? $s : ($s%2 == 0 ? '.' : ''); ++$s; } return 1; } \endcode Note: this will not catch Ctrl-C (SIGINT). For that you could cook up something like the following. \code $SIG{'INT'} = progress('Return 0 next time!'); # modify progress to understand the above \endcode \section tips_raster_coordinates Get the raster coordinates in iteration \code my $raster = Geo::GDAL::Open('bigraster.tiff'); my $transform = $raster->GeoTransform; my ($xoff, $yoff, $w, $h) = (0, 0, 200, 200); $|++; while (1) { progress($yoff/$H); if ($xoff >= $W) { $xoff = 0; $yoff += $h; last if $yoff >= $H; } my $data = $raster->Band(1)->ReadTile($xoff, $yoff, min($W-$xoff, $w), min($H-$yoff, $h)); for my $y (0..$#$data) { for my $x (0..$#{$data->[$y]}) { my ($px, $py) = $transform->Apply([$xoff+$x], [$yoff+$y]); my $upper_left = Geo::OGR::Geometry->new( GeometryType => 'Point', Points => [$px->[0], $py->[0]])}); } } $xoff += $w; } sub min { return $_[0] < $_[1] ? $_[0] : $_[1]; } \endcode */