2 # @brief GDAL utility functions and a root class for raster classes.
3 # @details Geo::GDAL wraps many GDAL utility functions and is as a root class
4 # for all GDAL raster classes. A "raster" is an object, whose core is
5 # a rectagular grid of cells, called a "band" in GDAL. Each cell
6 # contains a numeric value of a specific data type.
10 #** @method ApplyVerticalShiftGrid()
12 sub ApplyVerticalShiftGrid {
15 #** @method BuildVRT()
20 push(@DATA_TYPES, $1), next
if /^GDT_(\w+)/;
21 push(@OPEN_FLAGS, $1), next
if /^OF_(\w+)/;
22 push(@RESAMPLING_TYPES, $1), next
if /^GRA_(\w+)/;
23 push(@RIO_RESAMPLING_TYPES, $1), next
if /^GRIORA_(\w+)/;
24 push(@NODE_TYPES, $1), next
if /^CXT_(\w+)/;
26 for my $string (@DATA_TYPES) {
27 my $int = eval
"\$Geo::GDAL::Const::GDT_$string";
28 $S2I{data_type}{$string} = $int;
29 $I2S{data_type}{$int} = $string;
31 for my $string (@OPEN_FLAGS) {
32 my $int = eval
"\$Geo::GDAL::Const::OF_$string";
33 $S2I{open_flag}{$string} = $int;
35 for my $string (@RESAMPLING_TYPES) {
36 my $int = eval
"\$Geo::GDAL::Const::GRA_$string";
37 $S2I{resampling}{$string} = $int;
38 $I2S{resampling}{$int} = $string;
40 for my $string (@RIO_RESAMPLING_TYPES) {
41 my $int = eval
"\$Geo::GDAL::Const::GRIORA_$string";
42 $S2I{rio_resampling}{$string} = $int;
43 $I2S{rio_resampling}{$int} = $string;
45 for my $string (@NODE_TYPES) {
46 my $int = eval
"\$Geo::GDAL::Const::CXT_$string";
47 $S2I{node_type}{$string} = $int;
48 $I2S{node_type}{$int} = $string;
52 $HAVE_PDL = 1 unless $@;
55 #** @method CPLBinaryToHex()
60 #** @method CPLHexToBinary()
65 #** @method ContourGenerateEx()
67 sub ContourGenerateEx {
70 #** @method CreatePansharpenedVRT()
72 sub CreatePansharpenedVRT {
75 #** @method scalar DataTypeIsComplex($DataType)
77 # @param DataType A GDAL raster cell data type (one of those listed by Geo::GDAL::DataTypes).
78 # @return true if the data type is a complex number.
80 sub DataTypeIsComplex {
81 return _DataTypeIsComplex(s2i(data_type => shift));
84 #** @method list DataTypeValueRange($DataType)
86 # @param DataType Data type (one of those listed by Geo::GDAL::DataTypes).
87 # @note Some returned values are inaccurate.
89 # @return the minimum, maximum range of the data type.
91 sub DataTypeValueRange {
94 # these values are from gdalrasterband.cpp
95 return (0,255)
if $t =~ /Byte/;
96 return (0,65535)
if $t =~/UInt16/;
97 return (-32768,32767)
if $t =~/Int16/;
98 return (0,4294967295)
if $t =~/UInt32/;
99 return (-2147483648,2147483647)
if $t =~/Int32/;
100 return (-4294967295.0,4294967295.0)
if $t =~/Float32/;
101 return (-4294967295.0,4294967295.0)
if $t =~/Float64/;
104 #** @method list DataTypes()
105 # Package subroutine.
106 # @return a list of GDAL raster cell data types. These are currently:
107 # Byte, CFloat32, CFloat64, CInt16, CInt32, Float32, Float64, Int16, Int32, UInt16, UInt32, and Unknown.
113 #** @method scalar DecToDMS($angle, $axis, $precision=2)
114 # Package subroutine.
115 # Convert decimal degrees to degrees, minutes, and seconds string
116 # @param angle A number
117 # @param axis A string specifying latitude or longitude ('Long').
119 # @return a string nndnn'nn.nn'"L where n is a number and L is either
125 #** @method scalar DecToPackedDMS($dec)
126 # Package subroutine.
127 # @param dec Decimal degrees
128 # @return packed DMS, i.e., a number DDDMMMSSS.SS
133 #** @method DontUseExceptions()
134 # Package subroutine.
135 # Do not use the Perl exception mechanism for GDAL messages. Instead
136 # the messages are printed to standard error.
138 sub DontUseExceptions {
141 #** @method Geo::GDAL::Driver Driver($Name)
142 # Package subroutine.
143 # Access a format driver.
144 # @param Name The short name of the driver. One of
145 # Geo::GDAL::DriverNames or Geo::OGR::DriverNames.
146 # @note This subroutine is imported into the main namespace if Geo::GDAL
147 # is used with qw/:all/.
148 # @return a Geo::GDAL::Driver object.
151 return 'Geo::GDAL::Driver' unless @_;
153 my $driver = GetDriver($name);
154 error("Driver \"$name\" not found. Is it built in? Check with Geo::GDAL::Drivers or Geo::OGR::Drivers.")
159 #** @method list DriverNames()
160 # Package subroutine.
161 # Available raster format drivers.
163 # perl -MGeo::GDAL -e '@d=Geo::GDAL::DriverNames;print "@d\n"'
165 # @note Use Geo::OGR::DriverNames for vector drivers.
166 # @return a list of the short names of all available GDAL raster drivers.
171 #** @method list Drivers()
172 # Package subroutine.
173 # @note Use Geo::OGR::Drivers for vector drivers.
174 # @return a list of all available GDAL raster drivers.
178 for my $i (0..GetDriverCount()-1) {
179 my $driver = GetDriver($i);
180 push @drivers, $driver
if $driver->TestCapability(
'RASTER');
185 #** @method EscapeString()
190 #** @method scalar FindFile($basename)
191 # Package subroutine.
192 # Search for GDAL support files.
197 # $a = Geo::GDAL::FindFile('pcs.csv');
198 # print STDERR "$a\n";
200 # Prints (for example):
202 # c:\msys\1.0\local\share\gdal\pcs.csv
205 # @param basename The name of the file to search for. For example
207 # @return the path to the searched file or undef.
217 #** @method FinderClean()
218 # Package subroutine.
219 # Clear the set of support file search paths.
224 #** @method GDALMultiDimInfo()
226 sub GDALMultiDimInfo {
229 #** @method GEDTC_COMPOUND()
234 #** @method GEDTC_NUMERIC()
239 #** @method GEDTC_STRING()
244 #** @method GOA2GetAccessToken()
246 sub GOA2GetAccessToken {
249 #** @method GOA2GetAuthorizationURL()
251 sub GOA2GetAuthorizationURL {
254 #** @method GOA2GetRefreshToken()
256 sub GOA2GetRefreshToken {
259 #** @method GVM_Diagonal()
264 #** @method GVM_Edge()
269 #** @method GVM_Max()
274 #** @method GVM_Min()
279 #** @method GVOT_MIN_TARGET_HEIGHT_FROM_DEM()
281 sub GVOT_MIN_TARGET_HEIGHT_FROM_DEM {
284 #** @method GVOT_MIN_TARGET_HEIGHT_FROM_GROUND()
286 sub GVOT_MIN_TARGET_HEIGHT_FROM_GROUND {
287 # keeper maintains child -> parent relationships
288 # child is kept as a key, i.e., string not the real object
289 # parent is kept as the value, i.e., a real object
290 # a child may have only one parent!
291 # call these as Geo::GDAL::*
296 #** @method GVOT_NORMAL()
301 #** @method GetActualURL()
306 #** @method scalar GetCacheMax()
307 # Package subroutine.
308 # @return maximum amount of memory (as bytes) for caching within GDAL.
313 #** @method scalar GetCacheUsed()
314 # Package subroutine.
315 # @return the amount of memory currently used for caching within GDAL.
320 #** @method scalar GetConfigOption($key)
321 # Package subroutine.
322 # @param key A GDAL config option. Consult <a
323 # href="https://trac.osgeo.org/gdal/wiki/ConfigOptions">the GDAL
324 # documentation</a> for available options and their use.
325 # @return the value of the GDAL config option.
327 sub GetConfigOption {
330 #** @method scalar GetDataTypeSize($DataType)
331 # Package subroutine.
332 # @param DataType A GDAL raster cell data type (one of those listed by Geo::GDAL::DataTypes).
333 # @return the size as the number of bits.
335 sub GetDataTypeSize {
336 return _GetDataTypeSize(s2i(data_type => shift, 1));
339 #** @method GetErrorCounter()
341 sub GetErrorCounter {
344 #** @method GetFileMetadata()
346 sub GetFileMetadata {
349 #** @method GetFileSystemOptions()
351 sub GetFileSystemOptions {
354 #** @method GetFileSystemsPrefixes()
356 sub GetFileSystemsPrefixes {
359 #** @method GetJPEG2000StructureAsString()
361 sub GetJPEG2000StructureAsString {
364 #** @method GetSignedURL()
369 #** @method Geo::GDAL::Driver IdentifyDriver($path, $siblings)
370 # Package subroutine.
371 # @param path a dataset path.
372 # @param siblings [optional] A list of names of files that belong to the data format.
373 # @return a Geo::GDAL::Driver.
378 #** @method IdentifyDriverEx()
380 sub IdentifyDriverEx {
383 #** @method MkdirRecursive()
388 #** @method NetworkStatsGetAsSerializedJSON()
390 sub NetworkStatsGetAsSerializedJSON {
393 #** @method NetworkStatsReset()
395 sub NetworkStatsReset {
398 #** @method Geo::GDAL::Dataset Open(%params)
399 # Package subroutine.
401 # An example, which opens an existing raster dataset for editing:
403 # use Geo::GDAL qw/:all/;
404 # $ds = Open(Name => 'existing.tiff', Access => 'Update');
406 # @param params Named parameters:
407 # - \a Name Dataset string (typically a filename). Default is '.'.
408 # - \a Access Access type, either 'ReadOnly' or 'Update'. Default is 'ReadOnly'.
409 # - \a Type Dataset type, either 'Raster', 'Vector', or 'Any'. Default is 'Any'.
410 # - \a Options A hash of GDAL open options passed to candidate drivers. Default is {}.
411 # - \a Files A list of names of files that are auxiliary to the main file. Default is [].
413 # @note This subroutine is imported into the main namespace if Geo::GDAL
414 # is use'd with qw/:all/.
416 # @note Some datasets / dataset strings do not explicitly imply the
417 # dataset type (for example a PostGIS database). If the type is not
418 # specified in such a case the returned dataset may be of either type.
420 # @return a new Geo::GDAL::Dataset object if success.
423 my $p = named_parameters(\@_, Name =>
'.', Access =>
'ReadOnly', Type =>
'Any', Options => {}, Files => []);
425 my %o = (READONLY => 1, UPDATE => 1);
426 error(1, $p->{access}, \%o) unless $o{uc($p->{access})};
427 push @flags, uc($p->{access});
428 %o = (RASTER => 1, VECTOR => 1, ANY => 1);
429 error(1, $p->{type}, \%o) unless $o{uc($p->{type})};
430 push @flags, uc($p->{type}) unless uc($p->{type}) eq
'ANY';
431 my $dataset = OpenEx(Name => $p->{name}, Flags => \@flags, Options => $p->{options}, Files => $p->{files});
433 my $t =
"Failed to open $p->{name}.";
434 $t .=
" Is it a ".lc($p->{type}).
" dataset?" unless uc($p->{type}) eq
'ANY';
440 #** @method Geo::GDAL::Dataset OpenEx(%params)
441 # Package subroutine.
442 # The generic dataset open method, used internally by all Open and OpenShared methods.
443 # @param params Named parameters:
444 # - \a Name The name of the data set or source to open. (Default is '.')
445 # - \a Flags A list of access mode flags. Available flags are listed by Geo::GDAL::OpenFlags(). (Default is [])
446 # - \a Drivers A list of short names of drivers that may be used. Empty list means all. (Default is [])
447 # - \a Options A hash of GDAL open options passed to candidate drivers. (Default is {})
448 # - \a Files A list of names of files that are auxiliary to the main file. (Default is [])
452 # $ds = Geo::GDAL::OpenEx(Name => 'existing.tiff', Flags => [qw/RASTER UPDATE/]);
454 # @return a new Geo::GDAL::Dataset object.
457 my $p = named_parameters(\@_, Name =>
'.', Flags => [], Drivers => [], Options => {}, Files => []);
461 $p = {name => $name, flags => \@flags, drivers => [], options => {}, files => []};
465 for my $flag (@{$p->{flags}}) {
466 $f |= s2i(open_flag => $flag);
470 return _OpenEx($p->{name}, $p->{flags}, $p->{drivers}, $p->{options}, $p->{files});
473 #** @method list OpenFlags()
474 # Package subroutine.
475 # @return a list of GDAL data set open modes. These are currently:
476 # ALL, GNM, MULTIDIM_RASTER, RASTER, READONLY, SHARED, UPDATE, VECTOR, and VERBOSE_ERROR.
482 #** @method scalar PackCharacter($DataType)
483 # Package subroutine.
484 # Get the character that is needed for Perl's pack and unpack when
485 # they are used with Geo::GDAL::Band::ReadRaster and
486 # Geo::GDAL::Band::WriteRaster. Note that Geo::GDAL::Band::ReadTile
487 # and Geo::GDAL::Band::WriteTile have simpler interfaces that do not
488 # require pack and unpack.
489 # @param DataType A GDAL raster cell data type, typically from $band->DataType.
490 # @return a character which can be used in Perl's pack and unpack.
494 $t = i2s(data_type => $t);
495 s2i(data_type => $t); # test
496 my $is_big_endian = unpack(
"h*", pack(
"s", 1)) =~ /01/; # from Programming Perl
497 return 'C' if $t =~ /^Byte$/;
498 return ($is_big_endian ?
'n':
'v')
if $t =~ /^UInt16$/;
499 return 's' if $t =~ /^Int16$/;
500 return ($is_big_endian ?
'N' :
'V')
if $t =~ /^UInt32$/;
501 return 'l' if $t =~ /^Int32$/;
502 return 'f' if $t =~ /^Float32$/;
503 return 'd' if $t =~ /^Float64$/;
506 #** @method scalar PackedDMSToDec($packed)
507 # Package subroutine.
508 # @param packed DMS as a number DDDMMMSSS.SS
509 # @return decimal degrees
514 #** @method PopFinderLocation()
515 # Package subroutine.
516 # Remove the latest addition from the set of support file search
517 # paths. Note that calling this subroutine may remove paths GDAL put
520 sub PopFinderLocation {
523 #** @method PushFinderLocation($path)
524 # Package subroutine.
525 # Add a path to the set of paths from where GDAL support files are
526 # sought. Note that GDAL puts initially into the finder the current
527 # directory and value of GDAL_DATA environment variable (if it
528 # exists), installation directory (prepended with '/share/gdal' or
529 # '/Resources/gdal'), or '/usr/local/share/gdal'. It is usually only
530 # needed to add paths to the finder if using an alternate set of data
531 # files or a non-installed GDAL is used (as in testing).
533 sub PushFinderLocation {
536 #** @method list RIOResamplingTypes()
537 # Package subroutine.
538 # @return a list of GDAL raster IO resampling methods. These are currently:
539 # Average, Bilinear, Cubic, CubicSpline, Gauss, Lanczos, Mode, and NearestNeighbour.
541 sub RIOResamplingTypes {
542 return @RIO_RESAMPLING_TYPES;
545 #** @method list ResamplingTypes()
546 # Package subroutine.
547 # @return a list of GDAL resampling methods. These are currently:
548 # Average, Bilinear, Cubic, CubicSpline, Lanczos, Max, Med, Min, Mode, NearestNeighbour, Q1, and Q3.
550 sub ResamplingTypes {
551 return @RESAMPLING_TYPES;
554 #** @method RmdirRecursive()
559 #** @method SetCacheMax($Bytes)
560 # Package subroutine.
561 # @param Bytes New maximum amount of memory for caching within GDAL.
566 #** @method SetConfigOption($key, $value)
567 # Package subroutine.
568 # @param key A GDAL config option. Consult <a
569 # href="https://trac.osgeo.org/gdal/wiki/ConfigOptions">the GDAL
570 # documentation</a> for available options and their use.
571 # @param value A value for the option, typically 'YES', 'NO',
572 # undef, path, numeric value, or a filename.
574 sub SetConfigOption {
577 #** @method SetCurrentErrorHandlerCatchDebug()
579 sub SetCurrentErrorHandlerCatchDebug {
582 #** @method SetFileMetadata()
584 sub SetFileMetadata {
587 #** @method UnlinkBatch()
592 #** @method UseExceptions()
593 # Package subroutine.
594 # Use the Perl exception mechanism for GDAL messages (failures are
595 # confessed and warnings are warned) and collect the messages
596 # into \@Geo::GDAL::error. This is the default.
601 #** @method VSICurlClearCache()
603 sub VSICurlClearCache {
606 #** @method VSICurlPartialClearCache()
608 sub VSICurlPartialClearCache {
611 #** @method VSIErrorReset()
616 #** @method VSIFEofL()
621 #** @method VSIFFlushL()
626 #** @method VSIFOpenExL()
631 #** @method VSIGetLastErrorMsg()
633 sub VSIGetLastErrorMsg {
636 #** @method VSIGetLastErrorNo()
638 sub VSIGetLastErrorNo {
641 #** @method scalar VersionInfo($request = 'VERSION_NUM')
642 # Package subroutine.
643 # @param request A string specifying the request. Currently either
644 # "VERSION_NUM", "RELEASE_DATE", "RELEASE_NAME", or
645 # "--version". Default is "VERSION_NUM".
646 # @return Requested information.
651 #** @method ViewshedGenerate()
653 sub ViewshedGenerate {
656 #** @method scalar errstr()
657 # Package subroutine.
658 # Clear the error stack and return all generated GDAL error messages in one (possibly multiline) string.
659 # @return the chomped error stack joined with newlines.
665 return join(
"\n", @stack);
667 # usage: named_parameters(\@_, key value list of default parameters);
668 # returns parameters in a hash with low-case-without-_ keys
671 #** @method wrapper_GDALMultiDimTranslateDestName()
673 sub wrapper_GDALMultiDimTranslateDestName {
676 #** @class Geo::GDAL::AsyncReader
677 # @brief Enable asynchronous requests.
678 # @details This class is not yet documented nor tested in the GDAL Perl wrappers
679 # @todo Test and document.
681 package Geo::GDAL::AsyncReader;
685 #** @method GetNextUpdatedRegion()
687 sub GetNextUpdatedRegion {
690 #** @method LockBuffer()
695 #** @method UnlockBuffer()
700 #** @class Geo::GDAL::Attribute
702 package Geo::GDAL::Attribute;
706 #** @method GetDataType()
711 #** @method GetDimensionCount()
713 sub GetDimensionCount {
716 #** @method GetFullName()
721 #** @method GetName()
726 #** @method GetTotalElementsCount()
728 sub GetTotalElementsCount {
731 #** @method ReadAsDouble()
736 #** @method ReadAsInt()
741 #** @method ReadAsString()
746 #** @method ReadAsStringArray()
748 sub ReadAsStringArray {
751 #** @method WriteDouble()
756 #** @method WriteInt()
761 #** @method WriteString()
766 #** @method WriteStringArray()
768 sub WriteStringArray {
771 #** @class Geo::GDAL::Band
772 # @brief A raster band.
775 package Geo::GDAL::Band;
781 # scalar (access as $band->{XSize})
786 # scalar (access as $band->{YSize})
789 #** @method AdviseRead()
794 #** @method AsMDArray()
799 #** @method Geo::GDAL::RasterAttributeTable AttributeTable($AttributeTable)
801 # @param AttributeTable [optional] A Geo::GDAL::RasterAttributeTable object.
802 # @return a new Geo::GDAL::RasterAttributeTable object, whose data is
803 # contained within the band.
807 SetDefaultRAT($self, $_[0])
if @_ and defined $_[0];
808 return unless defined wantarray;
809 my $r = GetDefaultRAT($self);
810 keep($r, $self)
if $r;
813 #** @method list BlockSize()
816 # @return The size of a preferred i/o raster block size as a list
822 #** @method list CategoryNames(@names)
824 # @param names [optional]
829 SetRasterCategoryNames($self, \@_)
if @_;
830 return unless defined wantarray;
831 my $n = GetRasterCategoryNames($self);
835 #** @method scalar Checksum($xoff = 0, $yoff = 0, $xsize = undef, $ysize = undef)
837 # Computes a checksum from the raster or a part of it.
842 # @return the checksum.
847 #** @method hashref ClassCounts($classifier, $progress = undef, $progress_data = undef)
849 # Compute the counts of cell values or number of cell values in ranges.
850 # @note Classifier is required only for float bands.
851 # @note NoData values are counted similar to other values when
852 # classifier is not defined for integer rasters.
854 # @param classifier Anonymous array of format [ $comparison,
855 # $classifier ], where $comparison is a string '<', '<=', '>', or '>='
856 # and $classifier is an anonymous array of format [ $value,
857 # $value|$classifier, $value|$classifier ], where $value is a numeric
858 # value against which the reclassified value is compared to. If the
859 # comparison returns true, then the second $value or $classifier is
860 # applied, and if not then the third $value or $classifier.
862 # In the example below, the line is divided into ranges
863 # [-inf..3), [3..5), and [5..inf], i.e., three ranges with class
864 # indexes 0, 1, and 2. Note that the indexes are used as keys for
865 # class counts and not the class values (here 1.0, 2.0, and 3.0),
866 # which are used in Geo::GDAL::Band::Reclassify.
868 # $classifier = [ '<', [5.0, [3.0, 1.0, 2.0], 3.0] ];
869 # # Howto create this $classifier from @class_boundaries:
870 # my $classifier = ['<='];
871 # my $tree = [$class_boundaries[0], 0, 1];
872 # for my $i (1 .. $#class_boundaries) {
873 # $tree = [$class_boundaries[$i], [@$tree], $i+1];
875 # push @$classifier, $tree;
877 # @return a reference to an anonymous hash, which contains the class
878 # values (indexes) as keys and the number of cells with that value or
879 # in that range as values. If the subroutine is user terminated an
885 #** @method scalar ColorInterpretation($color_interpretation)
887 # @note a.k.a. GetRasterColorInterpretation and GetColorInterpretation
888 # (get only and returns an integer), SetRasterColorInterpretation and
889 # SetColorInterpretation (set only and requires an integer)
890 # @param color_interpretation [optional] new color interpretation, one
891 # of Geo::GDAL::Band::ColorInterpretations.
892 # @return The color interpretation of this band. One of Geo::GDAL::Band::ColorInterpretations.
894 sub ColorInterpretation {
897 $ci = s2i(color_interpretation => $ci);
898 SetRasterColorInterpretation($self, $ci);
900 return unless defined wantarray;
901 i2s(color_interpretation => GetRasterColorInterpretation($self));
904 #** @method ColorInterpretations()
905 # Package subroutine.
906 # @return a list of types of color interpretation for raster
907 # bands. These are currently:
908 # AlphaBand, BlackBand, BlueBand, CyanBand, GrayIndex, GreenBand, HueBand, LightnessBand, MagentaBand, PaletteIndex, RedBand, SaturationBand, Undefined, YCbCr_CbBand, YCbCr_CrBand, YCbCr_YBand, and YellowBand.
910 sub ColorInterpretations {
911 return @COLOR_INTERPRETATIONS;
914 #** @method Geo::GDAL::ColorTable ColorTable($ColorTable)
916 # Get or set the color table of this band.
917 # @param ColorTable [optional] a Geo::GDAL::ColorTable object
918 # @return A new Geo::GDAL::ColorTable object which represents the
919 # internal color table associated with this band. Returns undef this
920 # band does not have an associated color table.
924 SetRasterColorTable($self, $_[0])
if @_ and defined $_[0];
925 return unless defined wantarray;
926 GetRasterColorTable($self);
929 #** @method ComputeBandStats($samplestep = 1)
931 # @param samplestep the row increment in computing the statistics.
932 # @note Returns uncorrected sample standard deviation.
934 # See also Geo::GDAL::Band::ComputeStatistics.
935 # @return a list (mean, stddev).
937 sub ComputeBandStats {
940 #** @method ComputeRasterMinMax($approx_ok = 0)
942 # @return arrayref MinMax = [min, max]
944 sub ComputeRasterMinMax {
947 #** @method list ComputeStatistics($approx_ok, $progress = undef, $progress_data = undef)
949 # @param approx_ok Whether it is allowed to compute the statistics
950 # based on overviews or similar.
951 # @note Returns uncorrected sample standard deviation.
953 # See also Geo::GDAL::Band::ComputeBandStats.
954 # @return a list ($min, $max, $mean, $stddev).
956 sub ComputeStatistics {
959 #** @method Geo::OGR::Layer Contours($DataSource, hashref LayerConstructor, $ContourInterval, $ContourBase, arrayref FixedLevels, $NoDataValue, $IDField, $ElevField, coderef Progress, $ProgressData)
961 # Generate contours for this raster band. This method can also be used with named parameters.
962 # @note This method is a wrapper for ContourGenerate.
967 # $dem = Geo::GDAL::Open('dem.gtiff');
968 # $contours = $dem->Band->Contours(ContourInterval => 10, ElevField => 'z');
969 # $n = $contours->GetFeatureCount;
972 # @param DataSource a Geo::OGR::DataSource object, default is a Memory data source
973 # @param LayerConstructor data for Geo::OGR::DataSource::CreateLayer, default is {Name => 'contours'}
974 # @param ContourInterval default is 100
975 # @param ContourBase default is 0
976 # @param FixedLevels a reference to a list of fixed contour levels, default is []
977 # @param NoDataValue default is undef
978 # @param IDField default is '', i.e., no field (the field is created if this is given)
979 # @param ElevField default is '', i.e., no field (the field is created if this is given)
980 # @param progress [optional] a reference to a subroutine, which will
981 # be called with parameters (number progress, string msg, progress_data)
982 # @param progress_data [optional]
987 my $p = named_parameters(\@_,
989 LayerConstructor => {Name =>
'contours'},
990 ContourInterval => 100,
993 NoDataValue => undef,
997 ProgressData => undef);
999 $p->{layerconstructor}->{Schema}
1000 $p->{layerconstructor}->{Schema}{Fields}
1002 unless ($p->{idfield} =~ /^[+-]?\d+$/ or $fields{$p->{idfield}}) {
1003 push @{$p->{layerconstructor}->{Schema}{Fields}}, {Name => $p->{idfield}, Type =>
'Integer'};
1005 unless ($p->{elevfield} =~ /^[+-]?\d+$/ or $fields{$p->{elevfield}}) {
1006 my $type = $self->DataType() =~ /Float/ ?
'Real' :
'Integer';
1007 push @{$p->{layerconstructor}->{Schema}{Fields}}, {Name => $p->{elevfield}, Type => $type};
1009 my $layer = $p->{datasource}->CreateLayer($p->{layerconstructor});
1010 my $schema = $layer->GetLayerDefn;
1011 for (
'idfield',
'elevfield') {
1012 $p->{$_} = $schema->GetFieldIndex($p->{$_}) unless $p->{$_} =~ /^[+-]?\d+$/;
1014 $p->{progressdata} = 1
if $p->{progress} and not defined $p->{progressdata};
1015 ContourGenerate($self, $p->{contourinterval}, $p->{contourbase}, $p->{fixedlevels},
1016 $p->{nodatavalue}, $layer, $p->{idfield}, $p->{elevfield},
1017 $p->{progress}, $p->{progressdata});
1021 #** @method CreateMaskBand(@flags)
1023 # @note May invalidate any previous mask band obtained with Geo::GDAL::Band::GetMaskBand.
1025 # @param flags one or more mask flags. The flags are Geo::GDAL::Band::MaskFlags.
1027 sub CreateMaskBand {
1030 if (@_ and $_[0] =~ /^\d$/) {
1034 carp
"Unknown mask flag: '$flag'." unless $MASK_FLAGS{$flag};
1035 $f |= $MASK_FLAGS{$flag};
1038 $self->_CreateMaskBand($f);
1041 #** @method scalar DataType()
1043 # @return The data type of this band. One of Geo::GDAL::DataTypes.
1047 return i2s(data_type => $self->{DataType});
1050 #** @method Geo::GDAL::Dataset Dataset()
1052 # @return The dataset which this band belongs to.
1059 #** @method scalar DeleteNoDataValue()
1062 sub DeleteNoDataValue {
1065 #** @method Geo::GDAL::Band Distance(%params)
1067 # Compute distances to specific cells of this raster.
1068 # @param params Named parameters:
1069 # - \a Distance A raster band, into which the distances are computed. If not given, a not given, a new in-memory raster band is created and returned. The data type of the raster can be given in the options.
1070 # - \a Options Hash of options. Options are:
1071 # - \a Values A list of cell values in this band to measure the distance from. If this option is not provided, the distance will be computed to non-zero pixel values. Currently pixel values are internally processed as integers.
1072 # - \a DistUnits=PIXEL|GEO Indicates whether distances will be computed in cells or in georeferenced units. The default is pixel units. This also determines the interpretation of MaxDist.
1073 # - \a MaxDist=n The maximum distance to search. Distances greater than this value will not be computed. Instead output cells will be set to a NoData value.
1074 # - \a NoData=n The NoData value to use on the distance band for cells that are beyond MaxDist. If not provided, the distance band will be queried for a NoData value. If one is not found, 65535 will be used (255 if the type is Byte).
1075 # - \a Use_Input_NoData=YES|NO If this option is set, the NoData value of this band will be respected. Leaving NoData cells in the input as NoData pixels in the distance raster.
1076 # - \a Fixed_Buf_Val=n If this option is set, all cells within the MaxDist threshold are set to this value instead of the distance value.
1077 # - \a DataType The data type for the result if it is not given.
1078 # - \a Progress Progress function.
1079 # - \a ProgressData Additional parameter for the progress function.
1081 # @note This GDAL function behind this API is called GDALComputeProximity.
1083 # @return The distance raster.
1087 my $p = named_parameters(\@_, Distance => undef, Options => undef, Progress => undef, ProgressData => undef);
1088 for my $key (keys %{$p->{options}}) {
1089 $p->{options}{uc($key)} = $p->{options}{$key};
1092 unless ($p->{distance}) {
1093 my ($w, $h) = $self->Size;
1094 $p->{distance} =
Geo::GDAL::Driver(
'MEM')->
Create(Name =>
'distance', Width => $w, Height => $h, Type => $p->{options}{TYPE})->Band;
1096 Geo::GDAL::ComputeProximity($self, $p->{distance}, $p->{options}, $p->{progress}, $p->{progressdata});
1097 return $p->{distance};
1100 #** @method Domains()
1106 #** @method Fill($real_part, $imag_part = 0.0)
1108 # Fill the band with a constant value.
1109 # @param real_part Real component of fill value.
1110 # @param imag_part Imaginary component of fill value.
1116 #** @method FillNoData($mask, $max_search_dist, $smoothing_iterations, $options, coderef progress, $progress_data)
1118 # Interpolate values for cells in this raster. The cells to fill
1119 # should be marked in the mask band with zero.
1121 # @param mask [optional] a mask band indicating cells to be interpolated (zero valued) (default is to get it with Geo::GDAL::Band::GetMaskBand).
1122 # @param max_search_dist [optional] the maximum number of cells to
1123 # search in all directions to find values to interpolate from (default is 10).
1124 # @param smoothing_iterations [optional] the number of 3x3 smoothing filter passes to run (0 or more) (default is 0).
1125 # @param options [optional] A reference to a hash. No options have been defined so far for this algorithm (default is {}).
1126 # @param progress [optional] a reference to a subroutine, which will
1127 # be called with parameters (number progress, string msg, progress_data) (default is undef).
1128 # @param progress_data [optional] (default is undef).
1130 # <a href="http://www.gdal.org/gdal__alg_8h.html">Documentation for GDAL algorithms</a>
1135 #** @method FlushCache()
1137 # Write cached data to disk. There is usually no need to call this
1143 #** @method scalar GetBandNumber()
1145 # @return The index of this band in the parent dataset list of bands.
1150 #** @method GetBlockSize()
1155 #** @method list GetDefaultHistogram($force = 1, coderef progress = undef, $progress_data = undef)
1157 # @param force true to force the computation
1158 # @param progress [optional] a reference to a subroutine, which will
1159 # be called with parameters (number progress, string msg, progress_data)
1160 # @param progress_data [optional]
1161 # @note See Note in Geo::GDAL::Band::GetHistogram.
1162 # @return a list: ($min, $max, arrayref histogram).
1164 sub GetDefaultHistogram {
1167 #** @method list GetHistogram(%parameters)
1169 # Compute histogram from the raster.
1170 # @param parameters Named parameters:
1171 # - \a Min the lower bound, default is -0.5
1172 # - \a Max the upper bound, default is 255.5
1173 # - \a Buckets the number of buckets in the histogram, default is 256
1174 # - \a IncludeOutOfRange whether to use the first and last values in the returned list
1175 # for out of range values, default is false;
1176 # the bucket size is (Max-Min) / Buckets if this is false and
1177 # (Max-Min) / (Buckets-2) if this is true
1178 # - \a ApproxOK if histogram can be computed from overviews, default is false
1179 # - \a Progress an optional progress function, the default is undef
1180 # - \a ProgressData data for the progress function, the default is undef
1181 # @note Histogram counts are treated as strings in the bindings to be
1182 # able to use large integers (if GUIntBig is larger than Perl IV). In
1183 # practice this is only important if you have a 32 bit machine and
1184 # very large bucket counts. In those cases it may also be necessary to
1186 # @return a list which contains the count of values in each bucket
1190 my $p = named_parameters(\@_,
1194 IncludeOutOfRange => 0,
1197 ProgressData => undef);
1198 $p->{progressdata} = 1
if $p->{progress} and not defined $p->{progressdata};
1199 _GetHistogram($self, $p->{min}, $p->{max}, $p->{buckets},
1200 $p->{includeoutofrange}, $p->{approxok},
1201 $p->{progress}, $p->{progressdata});
1204 #** @method Geo::GDAL::Band GetMaskBand()
1206 # @return the mask band associated with this
1211 my $band = _GetMaskBand($self);
1215 #** @method list GetMaskFlags()
1217 # @return the mask flags of the mask band associated with this
1218 # band. The flags are one or more of Geo::GDAL::Band::MaskFlags.
1222 my $f = $self->_GetMaskFlags;
1224 for my $flag (keys %MASK_FLAGS) {
1225 push @f, $flag
if $f & $MASK_FLAGS{$flag};
1227 return wantarray ? @f : $f;
1230 #** @method scalar GetMaximum()
1232 # @note Call Geo::GDAL::Band::ComputeStatistics before calling
1233 # GetMaximum to make sure the value is computed.
1235 # @return statistical minimum of the band or undef if statistics are
1236 # not kept or computed in scalar context. In list context returns the
1237 # maximum value or a (kind of) maximum value supported by the data
1238 # type and a boolean value, which indicates which is the case (true is
1239 # first, false is second).
1244 #** @method scalar GetMinimum()
1246 # @note Call Geo::GDAL::Band::ComputeStatistics before calling
1247 # GetMinimum to make sure the value is computed.
1249 # @return statistical minimum of the band or undef if statistics are
1250 # not kept or computed in scalar context. In list context returns the
1251 # minimum value or a (kind of) minimum value supported by the data
1252 # type and a boolean value, which indicates which is the case (true is
1253 # first, false is second).
1258 #** @method Geo::GDAL::Band GetOverview($index)
1260 # @param index 0..GetOverviewCount-1
1261 # @return a Geo::GDAL::Band object, which represents the internal
1262 # overview band, or undef. if the index is out of bounds.
1265 my ($self, $index) = @_;
1266 my $band = _GetOverview($self, $index);
1270 #** @method scalar GetOverviewCount()
1272 # @return the number of overviews available of the band.
1274 sub GetOverviewCount {
1277 #** @method list GetStatistics($approx_ok, $force)
1279 # @param approx_ok Whether it is allowed to compute the statistics
1280 # based on overviews or similar.
1281 # @param force Whether to force scanning of the whole raster.
1282 # @note Uses Geo::GDAL::Band::ComputeStatistics internally.
1284 # @return a list ($min, $max, $mean, $stddev).
1289 #** @method HasArbitraryOverviews()
1291 # @return true or false.
1293 sub HasArbitraryOverviews {
1296 #** @method list MaskFlags()
1297 # Package subroutine.
1298 # @return the list of mask flags. These are
1299 # - \a AllValid: There are no invalid cell, all mask values will be 255.
1300 # When used this will normally be the only flag set.
1301 # - \a PerDataset: The mask band is shared between all bands on the dataset.
1302 # - \a Alpha: The mask band is actually an alpha band and may have values
1303 # other than 0 and 255.
1304 # - \a NoData: Indicates the mask is actually being generated from NoData values.
1305 # (mutually exclusive of Alpha).
1308 my @f = sort {$MASK_FLAGS{$a} <=> $MASK_FLAGS{$b}} keys %MASK_FLAGS;
1312 #** @method scalar NoDataValue($NoDataValue)
1314 # Get or set the "no data" value.
1315 # @param NoDataValue [optional]
1316 # @note $band->NoDataValue(undef) sets the NoData value to the
1317 # Posix floating point maximum. Use Geo::GDAL::Band::DeleteNoDataValue
1318 # to stop this band using a NoData value.
1319 # @return The NoData value or undef in scalar context. An undef
1320 # value indicates that there is no NoData value associated with this
1326 if (defined $_[0]) {
1327 SetNoDataValue($self, $_[0]);
1329 SetNoDataValue($self, POSIX::FLT_MAX); # hopefully an
"out of range" value
1332 GetNoDataValue($self);
1335 #** @method scalar PackCharacter()
1337 # @return The character to use in Perl pack and unpack for the data of this band.
1344 #** @method Piddle($piddle, $xoff = 0, $yoff = 0, $xsize = <width>, $ysize = <height>, $xdim, $ydim)
1346 # Read or write band data from/into a piddle.
1348 # \note The PDL module must be available for this method to work. Also, you
1349 # should 'use PDL' in the code that you use this method.
1351 # @param piddle [only when writing] The piddle from which to read the data to be written into the band.
1352 # @param xoff, yoff The offset for data in the band, default is top left (0, 0).
1353 # @param xsize, ysize [optional] The size of the window in the band.
1354 # @param xdim, ydim [optional, only when reading from a band] The size of the piddle to create.
1355 # @return A new piddle when reading from a band (no not use when writing into a band).
1358 # TODO: add Piddle sub to dataset too to make Width x Height x Bands piddles
1359 error(
"PDL is not available.") unless $Geo::
GDAL::HAVE_PDL;
1361 my $t = $self->{DataType};
1362 unless (defined wantarray) {
1364 error(
"The datatype of the Piddle and the band do not match.")
1365 unless $PDL2DATATYPE{$pdl->get_datatype} == $t;
1366 my ($xoff, $yoff, $xsize, $ysize) = @_;
1369 my $data = $pdl->get_dataref();
1370 my ($xdim, $ydim) = $pdl->dims();
1371 if ($xdim > $self->{XSize} - $xoff) {
1372 warn
"Piddle XSize too large ($xdim) for this raster band (width = $self->{XSize}, offset = $xoff).";
1373 $xdim = $self->{XSize} - $xoff;
1375 if ($ydim > $self->{YSize} - $yoff) {
1376 $ydim = $self->{YSize} - $yoff;
1377 warn
"Piddle YSize too large ($ydim) for this raster band (height = $self->{YSize}, offset = $yoff).";
1381 $self->_WriteRaster($xoff, $yoff, $xsize, $ysize, $data, $xdim, $ydim, $t, 0, 0);
1384 my ($xoff, $yoff, $xsize, $ysize, $xdim, $ydim, $alg) = @_;
1392 $alg = s2i(rio_resampling => $alg);
1393 my $buf = $self->_ReadRaster($xoff, $yoff, $xsize, $ysize, $xdim, $ydim, $t, 0, 0, $alg);
1395 my $datatype = $DATATYPE2PDL{$t};
1396 error(
"The band datatype is not supported by PDL.") if $datatype < 0;
1397 $pdl->set_datatype($datatype);
1398 $pdl->setdims([$xdim, $ydim]);
1399 my $data = $pdl->get_dataref();
1402 # FIXME: we want approximate equality since no data value can be very large floating point value
1403 my $bad = GetNoDataValue($self);
1404 return $pdl->setbadif($pdl == $bad)
if defined $bad;
1408 #** @method Geo::OGR::Layer Polygonize(%params)
1410 # Polygonize this raster band.
1412 # @param params Named parameters:
1413 # - \a Mask A raster band, which is used as a mask to select polygonized areas. Default is undef.
1414 # - \a OutLayer A vector layer into which the polygons are written. If not given, an in-memory layer 'polygonized' is created and returned.
1415 # - \a PixValField The name of the field in the output layer into which the cell value of the polygon area is stored. Default is 'val'.
1416 # - \a Options Hash or list of options. Connectedness can be set to 8
1417 # to use 8-connectedness, otherwise 4-connectedness is
1418 # used. ForceIntPixel can be set to 1 to force using a 32 bit int buffer
1419 # for cell values in the process. If this is not set and the data type
1420 # of this raster does not fit into a 32 bit int buffer, a 32 bit float
1422 # - \a Progress Progress function.
1423 # - \a ProgressData Additional parameter for the progress function.
1425 # @return Output vector layer.
1429 my $p = named_parameters(\@_, Mask => undef, OutLayer => undef, PixValField =>
'val', Options => undef, Progress => undef, ProgressData => undef);
1430 my %known_options = (Connectedness => 1, ForceIntPixel => 1, DATASET_FOR_GEOREF => 1,
'8CONNECTED' => 1);
1431 for my $option (keys %{$p->{options}}) {
1432 error(1, $option, \%known_options) unless exists $known_options{$option};
1434 my $dt = $self->DataType;
1435 my %leInt32 = (Byte => 1, Int16 => 1, Int32 => 1, UInt16 => 1);
1436 my $leInt32 = $leInt32{$dt};
1437 $dt = $dt =~ /Float/ ?
'Real' :
'Integer';
1439 CreateLayer(Name =>
'polygonized',
1440 Fields => [{Name =>
'val', Type => $dt},
1441 {Name =>
'geom', Type =>
'Polygon'}]);
1442 $p->{pixvalfield} = $p->{outlayer}->GetLayerDefn->GetFieldIndex($p->{pixvalfield});
1443 $p->{options}{
'8CONNECTED'} = 1
if $p->{options}{Connectedness} && $p->{options}{Connectedness} == 8;
1444 if ($leInt32 || $p->{options}{ForceIntPixel}) {
1445 Geo::GDAL::_Polygonize($self, $p->{mask}, $p->{outlayer}, $p->{pixvalfield}, $p->{options}, $p->{progress}, $p->{progressdata});
1447 Geo::GDAL::FPolygonize($self, $p->{mask}, $p->{outlayer}, $p->{pixvalfield}, $p->{options}, $p->{progress}, $p->{progressdata});
1449 set the srs of the outlayer
if it was created here
1450 return $p->{outlayer};
1453 #** @method RasterAttributeTable()
1455 sub RasterAttributeTable {
1458 #** @method scalar ReadRaster(%params)
1460 # Read data from the band.
1462 # @param params Named parameters:
1463 # - \a XOff x offset (cell coordinates) (default is 0)
1464 # - \a YOff y offset (cell coordinates) (default is 0)
1465 # - \a XSize width of the area to read (default is the width of the band)
1466 # - \a YSize height of the area to read (default is the height of the band)
1467 # - \a BufXSize (default is undef, i.e., the same as XSize)
1468 # - \a BufYSize (default is undef, i.e., the same as YSize)
1469 # - \a BufType data type of the buffer (default is the data type of the band)
1470 # - \a BufPixelSpace (default is 0)
1471 # - \a BufLineSpace (default is 0)
1472 # - \a ResampleAlg one of Geo::GDAL::RIOResamplingTypes (default is 'NearestNeighbour'),
1473 # - \a Progress reference to a progress function (default is undef)
1474 # - \a ProgressData (default is undef)
1476 # <a href="http://www.gdal.org/classGDALDataset.html">Entry in GDAL docs (method RasterIO)</a>
1477 # @return a buffer, open the buffer with \a unpack function of Perl. See Geo::GDAL::Band::PackCharacter.
1481 my ($width, $height) = $self->Size;
1482 my ($type) = $self->DataType;
1483 my $p = named_parameters(\@_,
1493 ResampleAlg =>
'NearestNeighbour',
1495 ProgressData => undef
1497 $p->{resamplealg} = s2i(rio_resampling => $p->{resamplealg});
1498 $p->{buftype} = s2i(data_type => $p->{buftype}, 1);
1499 $self->_ReadRaster($p->{xoff},$p->{yoff},$p->{xsize},$p->{ysize},$p->{bufxsize},$p->{bufysize},$p->{buftype},$p->{bufpixelspace},$p->{buflinespace},$p->{resamplealg},$p->{progress},$p->{progressdata});
1502 #** @method array reference ReadTile($xoff = 0, $yoff = 0, $xsize = <width>, $ysize = <height>)
1504 # Read band data into a Perl array.
1506 # \note Accessing band data in this way is slow. Consider using PDL and Geo::GDAL::Band::Piddle.
1508 # Usage example (print the data from a band):
1510 # print "@$_\n" for ( @{ $band->ReadTile() } );
1512 # Another usage example (process the data of a large dataset that has one band):
1514 # my($W,$H) = $dataset->Band()->Size();
1515 # my($xoff,$yoff,$w,$h) = (0,0,200,200);
1517 # if ($xoff >= $W) {
1520 # last if $yoff >= $H;
1522 # my $data = $dataset->Band(1)->ReadTile($xoff,$yoff,min($W-$xoff,$w),min($H-$yoff,$h));
1523 # # add your data processing code here
1524 # $dataset->Band(1)->WriteTile($data,$xoff,$yoff);
1529 # return $_[0] < $_[1] ? $_[0] : $_[1];
1532 # @param xoff Number of cell to skip before starting to read from a row. Pixels are read from left to right.
1533 # @param yoff Number of cells to skip before starting to read from a column. Pixels are read from top to bottom.
1534 # @param xsize Number of cells to read from each row.
1535 # @param ysize Number of cells to read from each column.
1536 # @return a two-dimensional Perl array, organizes as data->[y][x], y =
1537 # 0..height-1, x = 0..width-1. I.e., y is row and x is column.
1540 my($self, $xoff, $yoff, $xsize, $ysize, $w_tile, $h_tile, $alg) = @_;
1548 $alg = s2i(rio_resampling => $alg);
1549 my $t = $self->{DataType};
1550 my $buf = $self->_ReadRaster($xoff, $yoff, $xsize, $ysize, $w_tile, $h_tile, $t, 0, 0, $alg);
1555 for my $y (0..$h_tile-1) {
1556 my @d = unpack($pc.
"[$w_tile]", substr($buf, $offset, $w));
1563 #** @method Reclassify($classifier, $progress = undef, $progress_data = undef)
1565 # Reclassify the cells in the band.
1566 # @note NoData values in integer rasters are reclassified if
1567 # explicitly specified in the hash classifier. However, they are not
1568 # reclassified to the default value, if one is specified. In real
1569 # valued rasters nodata cells are not reclassified.
1570 # @note If the subroutine is user terminated or the classifier is
1571 # incorrect, already reclassified cells will stay reclassified but an
1573 # @param classifier For integer rasters an anonymous hash, which
1574 # contains old class values as keys and new class values as values, or
1575 # an array classifier as in Geo::GDAL::Band::ClassCounts. In a hash
1576 # classifier a special key '*' (star) can be used as default, to act
1577 # as a fallback new class value. For real valued rasters the
1578 # classifier is as in Geo::GDAL::Band::ClassCounts.
1583 #** @method RegenerateOverview(Geo::GDAL::Band overview, $resampling, coderef progress, $progress_data)
1585 # @param overview a Geo::GDAL::Band object for the overview.
1586 # @param resampling [optional] the resampling method (one of Geo::GDAL::RIOResamplingTypes) (default is Average).
1587 # @param progress [optional] a reference to a subroutine, which will
1588 # be called with parameters (number progress, string msg, progress_data)
1589 # @param progress_data [optional]
1591 sub RegenerateOverview {
1593 #Geo::GDAL::Band overview, scalar resampling, subref callback, scalar callback_data
1595 Geo::GDAL::RegenerateOverview($self, @p);
1598 #** @method RegenerateOverviews(arrayref overviews, $resampling, coderef progress, $progress_data)
1600 # @todo This is not yet available
1602 # @param overviews a list of Geo::GDAL::Band objects for the overviews.
1603 # @param resampling [optional] the resampling method (one of Geo::GDAL::RIOResamplingTypes) (default is Average).
1604 # @param progress [optional] a reference to a subroutine, which will
1605 # be called with parameters (number progress, string msg, progress_data)
1606 # @param progress_data [optional]
1608 sub RegenerateOverviews {
1610 #arrayref overviews, scalar resampling, subref callback, scalar callback_data
1612 Geo::GDAL::RegenerateOverviews($self, @p);
1615 #** @method ScaleAndOffset($scale, $offset)
1617 # Scale and offset are used to transform raw cell values into the
1618 # units returned by GetUnits(). The conversion function is:
1620 # Units value = (raw value * scale) + offset
1622 # @return a list ($scale, $offset), the values are undefined if they
1624 # @since version 1.9 of the bindings.
1626 sub ScaleAndOffset {
1628 SetScale($self, $_[0])
if @_ > 0 and defined $_[0];
1629 SetOffset($self, $_[1])
if @_ > 1 and defined $_[1];
1630 return unless defined wantarray;
1631 my $scale = GetScale($self);
1632 my $offset = GetOffset($self);
1633 return ($scale, $offset);
1636 #** @method list SetDefaultHistogram($min, $max, $histogram)
1640 # @note See Note in Geo::GDAL::Band::GetHistogram.
1641 # @param histogram reference to an array containing the histogram
1643 sub SetDefaultHistogram {
1646 #** @method SetStatistics($min, $max, $mean, $stddev)
1648 # Save the statistics of the band if possible (the format can save
1649 # arbitrary metadata).
1658 #** @method Geo::GDAL::Band Sieve(%params)
1660 # Remove small areas by merging them into the largest neighbour area.
1661 # @param params Named parameters:
1662 # - \a Mask A raster band, which is used as a mask to select sieved areas. Default is undef.
1663 # - \a Dest A raster band into which the result is written. If not given, an new in-memory raster band is created and returned.
1664 # - \a Threshold The smallest area size (in number of cells) which are not sieved away.
1665 # - \a Options Hash or list of options. {Connectedness => 4} can be specified to use 4-connectedness, otherwise 8-connectedness is used.
1666 # - \a Progress Progress function.
1667 # - \a ProgressData Additional parameter for the progress function.
1669 # @return The filtered raster band.
1673 my $p = named_parameters(\@_, Mask => undef, Dest => undef, Threshold => 10, Options => undef, Progress => undef, ProgressData => undef);
1674 unless ($p->{dest}) {
1675 my ($w, $h) = $self->Size;
1679 if ($p->{options}{Connectedness}) {
1680 $c = $p->{options}{Connectedness};
1681 delete $p->{options}{Connectedness};
1683 Geo::GDAL::SieveFilter($self, $p->{mask}, $p->{dest}, $p->{threshold}, $c, $p->{options}, $p->{progress}, $p->{progressdata});
1687 #** @method list Size()
1689 # @return The size of the band as a list (width, height).
1693 return ($self->{XSize}, $self->{YSize});
1696 #** @method Unit($type)
1698 # @param type [optional] the unit (a string).
1699 # @note $band->Unit(undef) sets the unit value to an empty string.
1700 # @return the unit (a string).
1701 # @since version 1.9 of the bindings.
1708 SetUnitType($self, $unit);
1710 return unless defined wantarray;
1714 #** @method WriteRaster(%params)
1716 # Write data into the band.
1718 # @param params Named parameters:
1719 # - \a XOff x offset (cell coordinates) (default is 0)
1720 # - \a YOff y offset (cell coordinates) (default is 0)
1721 # - \a XSize width of the area to write (default is the width of the band)
1722 # - \a YSize height of the area to write (default is the height of the band)
1723 # - \a Buf a buffer (or a reference to a buffer) containing the data. Create the buffer with \a pack function of Perl. See Geo::GDAL::Band::PackCharacter.
1724 # - \a BufXSize (default is undef, i.e., the same as XSize)
1725 # - \a BufYSize (default is undef, i.e., the same as YSize)
1726 # - \a BufType data type of the buffer (default is the data type of the band)
1727 # - \a BufPixelSpace (default is 0)
1728 # - \a BufLineSpace (default is 0)
1730 # <a href="http://www.gdal.org/classGDALDataset.html">Entry in GDAL docs (method RasterIO)</a>
1734 my ($width, $height) = $self->Size;
1735 my ($type) = $self->DataType;
1736 my $p = named_parameters(\@_,
1748 confess
"Usage: \$band->WriteRaster( Buf => \$data, ... )" unless defined $p->{buf};
1749 $p->{buftype} = s2i(data_type => $p->{buftype}, 1);
1750 $self->_WriteRaster($p->{xoff},$p->{yoff},$p->{xsize},$p->{ysize},$p->{buf},$p->{bufxsize},$p->{bufysize},$p->{buftype},$p->{bufpixelspace},$p->{buflinespace});
1753 #** @method WriteTile($data, $xoff = 0, $yoff = 0)
1755 # Write band data from a Perl array.
1757 # \note Accessing band data in this way is slow. Consider using PDL and Geo::GDAL::Band::Piddle.
1759 # @param data A two-dimensional Perl array, organizes as data->[y][x], y =
1760 # 0..height-1, x = 0..width-1.
1766 my($self, $data, $xoff, $yoff) = @_;
1769 error(
'The data must be in a two-dimensional array') unless ref $data eq
'ARRAY' && ref $data->[0] eq
'ARRAY';
1770 my $xsize = @{$data->[0]};
1771 if ($xsize > $self->{XSize} - $xoff) {
1772 warn
"Buffer XSize too large ($xsize) for this raster band (width = $self->{XSize}, offset = $xoff).";
1773 $xsize = $self->{XSize} - $xoff;
1775 my $ysize = @{$data};
1776 if ($ysize > $self->{YSize} - $yoff) {
1777 $ysize = $self->{YSize} - $yoff;
1778 warn
"Buffer YSize too large ($ysize) for this raster band (height = $self->{YSize}, offset = $yoff).";
1781 for my $i (0..$ysize-1) {
1782 my $scanline = pack($pc.
"[$xsize]", @{$data->[$i]});
1783 $self->WriteRaster( $xoff, $yoff+$i, $xsize, 1, $scanline );
1787 #** @class Geo::GDAL::ColorTable
1788 # @brief A color table from a raster band or a color table, which can be used for a band.
1791 package Geo::GDAL::ColorTable;
1795 #** @method Geo::GDAL::ColorTable Clone()
1797 # Clone an existing color table.
1798 # @return a new Geo::GDAL::ColorTable object
1803 #** @method list Color($index, @color)
1805 # Get or set a color in this color table.
1806 # @param index The index of the color in the table. Note that the
1807 # color table may expand if the index is larger than the current max
1808 # index of this table and a color is given. An attempt to retrieve a
1809 # color out of the current size of the table causes an error.
1810 # @param color [optional] The color, either a list or a reference to a
1811 # list. If the list is too short or has undef values, the undef values
1812 # are taken as 0 except for alpha, which is taken as 255.
1813 # @note A color is an array of four integers having a value between 0
1814 # and 255: (gray, red, cyan or hue; green, magenta, or lightness;
1815 # blue, yellow, or saturation; alpha or blackband)
1816 # @return A color, in list context a list and in scalar context a reference to an anonymous array.
1821 #** @method list Colors(@colors)
1823 # Get or set the colors in this color table.
1824 # @note The color table will expand to the size of the input list but
1825 # it will not shrink.
1826 # @param colors [optional] A list of all colors (a list of lists) for this color table.
1827 # @return A list of colors (a list of lists).
1832 #** @method CreateColorRamp($start_index, arrayref start_color, $end_index, arrayref end_color)
1834 # @param start_index
1835 # @param start_color
1839 sub CreateColorRamp {
1842 #** @method scalar GetCount()
1844 # @return The number of colors in this color table.
1849 #** @method scalar GetPaletteInterpretation()
1851 # @return palette interpretation (string)
1853 sub GetPaletteInterpretation {
1855 return i2s(palette_interpretation => GetPaletteInterpretation($self));
1858 #** @method Geo::GDAL::ColorTable new($GDALPaletteInterp = 'RGB')
1860 # Create a new empty color table.
1861 # @return a new Geo::GDAL::ColorTable object
1866 $pi = s2i(palette_interpretation => $pi);
1867 my $self = Geo::GDALc::new_ColorTable($pi);
1868 bless $self, $pkg
if defined($self);
1871 #** @class Geo::GDAL::Dataset
1872 # @brief A set of associated raster bands or vector layer source.
1875 package Geo::GDAL::Dataset;
1879 #** @attr $RasterCount
1880 # scalar (access as $dataset->{RasterCount})
1883 #** @attr $RasterXSize
1884 # scalar (access as $dataset->{RasterXSize})
1887 #** @attr $RasterYSize
1888 # scalar (access as $dataset->{RasterYSize})
1891 #** @method AbortSQL()
1896 #** @method AddBand($datatype = 'Byte', hashref options = {})
1898 # Add a new band to the dataset. The driver must support the action.
1899 # @param datatype GDAL raster cell data type (one of those listed by Geo::GDAL::DataTypes).
1900 # @param options reference to a hash of format specific options.
1901 # @return The added band.
1904 my ($self, $type, $options) = @_;
1906 $type = s2i(data_type => $type);
1907 $self->_AddBand($type, $options);
1908 return unless defined wantarray;
1909 return $self->GetRasterBand($self->{RasterCount});
1912 #** @method AdviseRead()
1917 #** @method Geo::GDAL::Band Band($index)
1919 # Create a band object for the band within the dataset.
1920 # @note a.k.a. GetRasterBand
1921 # @param index 1...RasterCount, default is 1.
1922 # @return a new Geo::GDAL::Band object
1927 #** @method list Bands()
1929 # @return a list of new Geo::GDAL::Band objects
1934 for my $i (1..$self->{RasterCount}) {
1935 push @bands, GetRasterBand($self, $i);
1940 #** @method BuildOverviews($resampling, arrayref overviews, coderef progress, $progress_data)
1942 # @param resampling the resampling method, one of Geo::GDAL::RIOResamplingTypes.
1943 # @param overviews The list of overview decimation factors to
1944 # build. For example [2,4,8].
1945 # @param progress [optional] a reference to a subroutine, which will
1946 # be called with parameters (number progress, string msg, progress_data)
1947 # @param progress_data [optional]
1949 sub BuildOverviews {
1952 $p[0] = uc($p[0])
if $p[0];
1954 $self->_BuildOverviews(@p);
1956 confess(last_error()) if $@;
1959 #** @method Geo::GDAL::Dataset BuildVRT($Dest, arrayref Sources, hashref Options, coderef progress, $progress_data)
1961 # Build a virtual dataset from a set of datasets.
1962 # @param Dest Destination raster dataset definition string (typically
1963 # filename), or an object, which implements write and close.
1964 # @param Sources A list of filenames of input datasets or a list of
1966 # @param Options See section \ref index_processing_options.
1967 # @return Dataset object
1969 # @note This subroutine is imported into the main namespace if Geo::GDAL
1970 # is use'd with qw/:all/.
1973 my ($dest, $sources, $options, $progress, $progress_data) = @_;
1974 $options = Geo::GDAL::GDALBuildVRTOptions->new(make_processing_options($options));
1975 error(
"Usage: Geo::GDAL::DataSet::BuildVRT(\$vrt_file_name, \\\@sources)")
1976 unless ref $sources eq 'ARRAY' && defined $sources->[0];
1977 unless (blessed($dest)) {
1978 if (blessed($sources->[0])) {
1979 return Geo::GDAL::wrapper_GDALBuildVRT_objects($dest, $sources, $options, $progress, $progress_data);
1981 return Geo::GDAL::wrapper_GDALBuildVRT_names($dest, $sources, $options, $progress, $progress_data);
1984 if (blessed($sources->[0])) {
1985 return stdout_redirection_wrapper(
1987 \&Geo::GDAL::wrapper_GDALBuildVRT_objects,
1988 $options, $progress, $progress_data);
1990 return stdout_redirection_wrapper(
1992 \&Geo::GDAL::wrapper_GDALBuildVRT_names,
1993 $options, $progress, $progress_data);
1998 #** @method ClearStatistics()
2000 sub ClearStatistics {
2003 #** @method CommitTransaction()
2005 sub CommitTransaction {
2008 #** @method Geo::GDAL::ColorTable ComputeColorTable(%params)
2010 # Compute a color table from an RGB image
2011 # @param params Named parameters:
2012 # - \a Red The red band, the default is to use the red band of this dataset.
2013 # - \a Green The green band, the default is to use the green band of this dataset.
2014 # - \a Blue The blue band, the default is to use the blue band of this dataset.
2015 # - \a NumColors The number of colors in the computed color table. Default is 256.
2016 # - \a Progress reference to a progress function (default is undef)
2017 # - \a ProgressData (default is undef)
2018 # - \a Method The computation method. The default and currently only option is the median cut algorithm.
2020 # @return a new color table object.
2022 sub ComputeColorTable {
2024 my $p = named_parameters(\@_,
2030 ProgressData => undef,
2031 Method =>
'MedianCut');
2032 for my $b ($self->Bands) {
2033 for my $cion ($b->ColorInterpretation) {
2034 if ($cion eq
'RedBand') { $p->{red}
2035 if ($cion eq
'GreenBand') { $p->{green}
2036 if ($cion eq
'BlueBand') { $p->{blue}
2040 Geo::GDAL::ComputeMedianCutPCT($p->{red},
2044 $ct, $p->{progress},
2045 $p->{progressdata});
2049 #** @method Geo::OGR::Layer CopyLayer($layer, $name, hashref options = undef)
2051 # @param layer A Geo::OGR::Layer object to be copied.
2052 # @param name A name for the new layer.
2053 # @param options A ref to a hash of format specific options.
2054 # @return a new Geo::OGR::Layer object.
2059 #** @method Geo::OGR::Layer CreateLayer(%params)
2061 # @brief Create a new vector layer into this dataset.
2063 # @param %params Named parameters:
2064 # - \a Name (scalar) name for the new layer.
2065 # - \a Fields (array reference) a list of (scalar and geometry) field definitions as in
2066 # Geo::OGR::Layer::CreateField.
2067 # - \a ApproxOK (boolean value, default is true) a flag, which is forwarded to Geo::OGR::Layer::CreateField.
2068 # - \a Options (hash reference) driver specific hash of layer creation options.
2069 # - \a Schema (hash reference, deprecated, use \a Fields and \a Name) may contain keys Name, Fields, GeomFields, GeometryType.
2070 # - \a SRS (scalar) the spatial reference for the default geometry field.
2071 # - \a GeometryType (scalar) the type of the default geometry field
2072 # (if only one geometry field). Default is 'Unknown'.
2074 # @note If Fields or Schema|Fields is not given, a default geometry
2075 # field (Name => '', GeometryType => 'Unknown') is created. If it is
2076 # given and it contains spatial fields, both GeometryType and SRS are
2077 # ignored. The type can be also set with the named parameter.
2081 # my $roads = Geo::OGR::Driver('Memory')->Create('road')->
2083 # Fields => [ { Name => 'class',
2084 # Type => 'Integer' },
2086 # Type => 'LineString25D' } ] );
2089 # @note Many formats allow only one spatial field, which currently
2090 # requires the use of GeometryType.
2092 # @return a new Geo::OGR::Layer object.
2096 my $p = named_parameters(\@_,
2099 GeometryType =>
'Unknown',
2104 error(
"The 'Fields' argument must be an array reference.") if $p->{fields} && ref($p->{fields}) ne
'ARRAY';
2105 if (defined $p->{schema}) {
2106 my $s = $p->{schema};
2107 $p->{geometrytype} = $s->{GeometryType}
if exists $s->{GeometryType};
2108 $p->{fields} = $s->{Fields}
if exists $s->{Fields};
2109 $p->{name} = $s->{Name}
if exists $s->{Name};
2111 $p->{fields} = [] unless ref($p->{fields}) eq
'ARRAY';
2112 # if fields contains spatial fields, then do not create default one
2113 for my $f (@{$p->{fields}}) {
2114 error(
"Field definitions must be hash references.") unless ref $f eq 'HASH';
2115 if ($f->{GeometryType} || ($f->{Type} && s_exists(geometry_type => $f->{Type}))) {
2116 $p->{geometrytype} =
'None';
2120 my $gt = s2i(geometry_type => $p->{geometrytype});
2121 my $layer = _CreateLayer($self, $p->{name}, $p->{srs}, $gt, $p->{options});
2122 for my $f (@{$p->{fields}}) {
2123 $layer->CreateField($f);
2125 keep($layer, $self);
2128 #** @method CreateMaskBand()
2130 # Add a mask band to the dataset.
2132 sub CreateMaskBand {
2133 return _CreateMaskBand(@_);
2136 #** @method Geo::GDAL::Dataset DEMProcessing($Dest, $Processing, $ColorFilename, hashref Options, coderef progress, $progress_data)
2138 # Apply a DEM processing to this dataset.
2139 # @param Dest Destination raster dataset definition string (typically filename) or an object, which implements write and close.
2140 # @param Processing Processing to apply, one of "hillshade", "slope", "aspect", "color-relief", "TRI", "TPI", or "Roughness".
2141 # @param ColorFilename The color palette for color-relief.
2142 # @param Options See section \ref index_processing_options.
2143 # @param progress [optional] A reference to a subroutine, which will
2144 # be called with parameters (number progress, string msg, progress_data).
2145 # @param progress_data [optional]
2149 my ($self, $dest, $Processing, $ColorFilename, $options, $progress, $progress_data) = @_;
2150 $options = Geo::GDAL::GDALDEMProcessingOptions->new(make_processing_options($options));
2151 return $self->stdout_redirection_wrapper(
2153 \&Geo::GDAL::wrapper_GDALDEMProcessing,
2154 $Processing, $ColorFilename, $options, $progress, $progress_data
2158 #** @method Dataset()
2165 #** @method DeleteLayer($name)
2167 # Deletes a layer from the data source. Note that if there is a layer
2168 # object for the deleted layer, it becomes unusable.
2169 # @param name name of the layer to delete.
2172 my ($self, $name) = @_;
2174 for my $i (0..$self->GetLayerCount-1) {
2175 my $layer = GetLayerByIndex($self, $i);
2176 $index = $i, last
if $layer->GetName eq $name;
2178 error(2, $name,
'Layer') unless defined $index;
2179 _DeleteLayer($self, $index);
2182 #** @method Geo::GDAL::Band Dither(%params)
2184 # Compute one band with color table image from an RGB image
2185 # @params params Named parameters:
2186 # - \a Red The red band, the default is to use the red band of this dataset.
2187 # - \a Green The green band, the default is to use the green band of this dataset.
2188 # - \a Blue The blue band, the default is to use the blue band of this dataset.
2189 # - \a Dest The destination band. If this is not defined, a new in-memory band (and a dataset) will be created.
2190 # - \a ColorTable The color table for the result. If this is not defined, and the destination band does not contain one, it will be computed with the ComputeColorTable method.
2191 # - \a Progress Reference to a progress function (default is undef). Note that if ColorTable is computed using ComputeColorTable method, the progress will run twice from 0 to 1.
2192 # - \a ProgressData (default is undef)
2194 # @return the destination band.
2196 # Usage example. This code converts an RGB JPEG image into a one band PNG image with a color table.
2198 # my $d = Geo::GDAL::Open('pic.jpg');
2199 # Geo::GDAL::Driver('PNG')->Copy(Name => 'test.png', Src => $d->Dither->Dataset);
2204 my $p = named_parameters(\@_,
2211 ProgressData => undef);
2212 for my $b ($self->Bands) {
2213 for my $cion ($b->ColorInterpretation) {
2214 if ($cion eq
'RedBand') { $p->{red}
2215 if ($cion eq
'GreenBand') { $p->{green}
2216 if ($cion eq
'BlueBand') { $p->{blue}
2219 my ($w, $h) = $self->Size;
2223 Type =>
'Byte')->Band;
2227 Green => $p->{green},
2229 Progress => $p->{progress},
2230 ProgressData => $p->{progressdata});
2231 Geo::GDAL::DitherRGB2PCT($p->{red},
2237 $p->{progressdata});
2238 $p->{dest}->ColorTable($p->{colortable});
2242 #** @method Domains()
2248 #** @method Geo::GDAL::Driver Driver()
2250 # @note a.k.a. GetDriver
2251 # @return a Geo::GDAL::Driver object that was used to open or create this dataset.
2256 #** @method Geo::OGR::Layer ExecuteSQL($statement, $geom = undef, $dialect = "")
2258 # @param statement A SQL statement.
2259 # @param geom A Geo::OGR::Geometry object.
2261 # @return a new Geo::OGR::Layer object. The data source object will
2262 # exist as long as the layer object exists.
2266 my $layer = $self->_ExecuteSQL(@_);
2267 note($layer,
"is result set");
2268 keep($layer, $self);
2271 #** @method Geo::GDAL::Extent Extent(@params)
2273 # @param params nothing, or a list ($xoff, $yoff, $w, $h)
2274 # @return A new Geo::GDAL::Extent object that represents the area that
2275 # this raster or the specified tile covers.
2279 my $t = $self->GeoTransform;
2280 my $extent = $t->Extent($self->Size);
2282 my ($xoff, $yoff, $w, $h) = @_;
2283 my ($x, $y) = $t->Apply([$xoff, $xoff+$w, $xoff+$w, $xoff], [$yoff, $yoff, $yoff+$h, $yoff+$h]);
2284 my $xmin = shift @$x;
2287 $xmin = $x
if $x < $xmin;
2288 $xmax = $x
if $x > $xmax;
2290 my $ymin = shift @$y;
2293 $ymin = $y
if $y < $ymin;
2294 $ymax = $y
if $y > $ymax;
2301 #** @method list GCPs(@GCPs, Geo::OSR::SpatialReference sr)
2303 # Get or set the GCPs and their projection.
2304 # @param GCPs [optional] a list of Geo::GDAL::GCP objects
2305 # @param sr [optional] the projection of the GCPs.
2306 # @return a list of Geo::GDAL::GCP objects followed by a Geo::OSR::SpatialReference object.
2312 $proj = $proj->Export(
'WKT')
if $proj and ref($proj);
2313 SetGCPs($self, \@_, $proj);
2315 return unless defined wantarray;
2317 my $GCPs = GetGCPs($self);
2318 return (@$GCPs, $proj);
2321 #** @method Geo::GDAL::GeoTransform GeoTransform(Geo::GDAL::GeoTransform $geo_transform)
2323 # Transformation from cell coordinates (column,row) to projection
2326 # x = geo_transform[0] + column*geo_transform[1] + row*geo_transform[2]
2327 # y = geo_transform[3] + column*geo_transform[4] + row*geo_transform[5]
2329 # @param geo_transform [optional]
2330 # @return the geo transform in a non-void context.
2336 SetGeoTransform($self, $_[0]);
2338 SetGeoTransform($self, \@_);
2341 confess(last_error())
if $@;
2342 return unless defined wantarray;
2343 my $t = GetGeoTransform($self);
2351 #** @method GetDriver()
2356 #** @method list GetFileList()
2358 # @return list of files GDAL believes to be part of this dataset.
2363 #** @method scalar GetGCPProjection()
2365 # @return projection string.
2367 sub GetGCPProjection {
2370 #** @method GetGCPSpatialRef()
2372 sub GetGCPSpatialRef {
2375 #** @method Geo::OGR::Layer GetLayer($name)
2377 # @param name the name of the requested layer. If not given, then
2378 # returns the first layer in the data source.
2379 # @return a new Geo::OGR::Layer object that represents the layer
2380 # in the data source.
2383 my($self, $name) = @_;
2384 my $layer = defined $name ? GetLayerByName($self,
"$name") : GetLayerByIndex($self, 0);
2386 error(2, $name,
'Layer') unless $layer;
2387 keep($layer, $self);
2390 #** @method list GetLayerNames()
2392 # @note Delivers the functionality of undocumented method GetLayerCount.
2393 # @return a list of the names of the layers this data source provides.
2398 for my $i (0..$self->GetLayerCount-1) {
2399 my $layer = GetLayerByIndex($self, $i);
2400 push @names, $layer->GetName;
2405 #** @method GetNextFeature()
2407 sub GetNextFeature {
2410 #** @method GetRootGroup()
2415 #** @method GetSpatialRef()
2420 #** @method GetStyleTable()
2425 #** @method Geo::GDAL::Dataset Grid($Dest, hashref Options)
2427 # Creates a regular raster grid from this data source.
2428 # This is equivalent to the gdal_grid utility.
2429 # @param Dest Destination raster dataset definition string (typically
2430 # filename) or an object, which implements write and close.
2431 # @param Options See section \ref index_processing_options.
2434 my ($self, $dest, $options, $progress, $progress_data) = @_;
2435 $options = Geo::GDAL::GDALGridOptions->new(make_processing_options($options));
2436 return $self->stdout_redirection_wrapper(
2438 \&Geo::GDAL::wrapper_GDALGrid,
2439 $options, $progress, $progress_data
2443 #** @method scalar Info(hashref Options)
2445 # Information about this dataset.
2446 # @param Options See section \ref index_processing_options.
2449 my ($self, $o) = @_;
2450 $o = Geo::GDAL::GDALInfoOptions->new(make_processing_options($o));
2451 return GDALInfo($self, $o);
2454 #** @method Geo::GDAL::Dataset Nearblack($Dest, hashref Options, coderef progress, $progress_data)
2456 # Convert nearly black/white pixels to black/white.
2457 # @param Dest Destination raster dataset definition string (typically
2458 # filename), destination dataset to which to add an alpha or mask
2459 # band, or an object, which implements write and close.
2460 # @param Options See section \ref index_processing_options.
2461 # @return Dataset if destination dataset definition string was given,
2462 # otherwise a boolean for success/fail but the method croaks if there
2466 my ($self, $dest, $options, $progress, $progress_data) = @_;
2467 $options = Geo::GDAL::GDALNearblackOptions->new(make_processing_options($options));
2468 my $b = blessed($dest);
2469 if ($b && $b eq
'Geo::GDAL::Dataset') {
2470 Geo::GDAL::wrapper_GDALNearblackDestDS($dest, $self, $options, $progress, $progress_data);
2472 return $self->stdout_redirection_wrapper(
2474 \&Geo::GDAL::wrapper_GDALNearblackDestName,
2475 $options, $progress, $progress_data
2480 #** @method Geo::GDAL::Dataset Open()
2481 # Package subroutine.
2482 # The same as Geo::GDAL::Open
2487 #** @method Geo::GDAL::Dataset OpenShared()
2488 # Package subroutine.
2489 # The same as Geo::GDAL::OpenShared
2494 #** @method Geo::GDAL::Dataset Rasterize($Dest, hashref Options, coderef progress, $progress_data)
2496 # Render data from this data source into a raster.
2497 # @param Dest Destination raster dataset definition string (typically
2498 # filename), destination dataset, or an object, which implements write and close.
2499 # @param Options See section \ref index_processing_options.
2500 # @return Dataset if destination dataset definition string was given,
2501 # otherwise a boolean for success/fail but the method croaks if there
2506 my ($self, $dest, $options, $progress, $progress_data) = @_;
2507 $options = Geo::GDAL::GDALRasterizeOptions->new(make_processing_options($options));
2508 my $b = blessed($dest);
2509 if ($b && $b eq
'Geo::GDAL::Dataset') {
2510 Geo::GDAL::wrapper_GDALRasterizeDestDS($dest, $self, $options, $progress, $progress_data);
2512 # TODO: options need to force a new raster be made, otherwise segfault
2513 return $self->stdout_redirection_wrapper(
2515 \&Geo::GDAL::wrapper_GDALRasterizeDestName,
2516 $options, $progress, $progress_data
2521 #** @method scalar ReadRaster(%params)
2523 # Read data from the dataset.
2525 # @param params Named parameters:
2526 # - \a XOff x offset (cell coordinates) (default is 0)
2527 # - \a YOff y offset (cell coordinates) (default is 0)
2528 # - \a XSize width of the area to read (default is the width of the dataset)
2529 # - \a YSize height of the area to read (default is the height of the dataset)
2530 # - \a BufXSize (default is undef, i.e., the same as XSize)
2531 # - \a BufYSize (default is undef, i.e., the same as YSize)
2532 # - \a BufType data type of the buffer (default is the data type of the first band)
2533 # - \a BandList a reference to an array of band indices (default is [1])
2534 # - \a BufPixelSpace (default is 0)
2535 # - \a BufLineSpace (default is 0)
2536 # - \a BufBandSpace (default is 0)
2537 # - \a ResampleAlg one of Geo::GDAL::RIOResamplingTypes (default is 'NearestNeighbour'),
2538 # - \a Progress reference to a progress function (default is undef)
2539 # - \a ProgressData (default is undef)
2541 # <a href="http://www.gdal.org/classGDALDataset.html">Entry in GDAL docs (method RasterIO)</a>
2542 # @return a buffer, open the buffer with \a unpack function of Perl. See Geo::GDAL::Band::PackCharacter.
2546 my ($width, $height) = $self->Size;
2547 my ($type) = $self->Band->DataType;
2548 my $p = named_parameters(\@_,
2560 ResampleAlg =>
'NearestNeighbour',
2562 ProgressData => undef
2564 $p->{resamplealg} = s2i(rio_resampling => $p->{resamplealg});
2565 $p->{buftype} = s2i(data_type => $p->{buftype}, 1);
2566 $self->_ReadRaster($p->{xoff},$p->{yoff},$p->{xsize},$p->{ysize},$p->{bufxsize},$p->{bufysize},$p->{buftype},$p->{bandlist},$p->{bufpixelspace},$p->{buflinespace},$p->{bufbandspace},$p->{resamplealg},$p->{progress},$p->{progressdata});
2569 #** @method ReadTile()
2572 my ($self, $xoff, $yoff, $xsize, $ysize, $w_tile, $h_tile, $alg) = @_;
2574 for my $i (0..$self->Bands-1) {
2575 $data[$i] = $self->Band($i+1)->ReadTile($xoff, $yoff, $xsize, $ysize, $w_tile, $h_tile, $alg);
2580 #** @method ReleaseResultSet($layer)
2582 # @param layer A layer the has been created with ExecuteSQL.
2583 # @note There is no need to call this method. The result set layer is
2584 # released in the destructor of the layer that was created with SQL.
2586 sub ReleaseResultSet {
2587 # a no-op, _ReleaseResultSet is called from Layer::DESTROY
2590 #** @method ResetReading()
2595 #** @method RollbackTransaction()
2597 sub RollbackTransaction {
2600 #** @method SetGCPs2()
2605 #** @method SetSpatialRef()
2610 #** @method SetStyleTable()
2615 #** @method list Size()
2617 # @return (width, height)
2621 return ($self->{RasterXSize}, $self->{RasterYSize});
2624 #** @method Geo::OSR::SpatialReference SpatialReference(Geo::OSR::SpatialReference sr)
2626 # Get or set the projection of this dataset.
2627 # @param sr [optional] a Geo::OSR::SpatialReference object,
2628 # which replaces the existing projection definition of this dataset.
2629 # @return a Geo::OSR::SpatialReference object, which represents the
2630 # projection of this dataset.
2631 # @note Methods GetProjection, SetProjection, and Projection return WKT strings.
2633 sub SpatialReference {
2634 my($self, $sr) = @_;
2635 SetProjection($self, $sr->As(
'WKT'))
if defined $sr;
2636 if (defined wantarray) {
2637 my $p = GetProjection($self);
2643 #** @method StartTransaction()
2645 sub StartTransaction {
2648 #** @method TestCapability()
2650 sub TestCapability {
2651 return _TestCapability(@_);
2654 #** @method Tile(Geo::GDAL::Extent e)
2656 # Compute the top left cell coordinates and width and height of the
2657 # tile that covers the given extent.
2658 # @param e The extent whose tile is needed.
2659 # @note Requires that the raster is a strictly north up one.
2660 # @return A list ($xoff, $yoff, $xsize, $ysize).
2663 my ($self, $e) = @_;
2664 my ($w, $h) = $self->Size;
2665 my $t = $self->GeoTransform;
2666 confess
"GeoTransform is not \"north up\"." unless $t->NorthUp;
2667 my $xoff = floor(($e->[0] - $t->[0])/$t->[1]);
2668 $xoff = 0
if $xoff < 0;
2669 my $yoff = floor(($e->[1] - $t->[3])/$t->[5]);
2670 $yoff = 0
if $yoff < 0;
2671 my $xsize = ceil(($e->[2] - $t->[0])/$t->[1]) - $xoff;
2672 $xsize = $w - $xoff
if $xsize > $w - $xoff;
2673 my $ysize = ceil(($e->[3] - $t->[3])/$t->[5]) - $yoff;
2674 $ysize = $h - $yoff
if $ysize > $h - $yoff;
2675 return ($xoff, $yoff, $xsize, $ysize);
2678 #** @method Geo::GDAL::Dataset Translate($Dest, hashref Options, coderef progress, $progress_data)
2680 # Convert this dataset into another format.
2681 # @param Dest Destination dataset definition string (typically
2682 # filename) or an object, which implements write and close.
2683 # @param Options See section \ref index_processing_options.
2684 # @return New dataset object if destination dataset definition
2685 # string was given, otherwise a boolean for success/fail but the
2686 # method croaks if there was an error.
2689 my ($self, $dest, $options, $progress, $progress_data) = @_;
2690 return $self->stdout_redirection_wrapper(
2694 #** @method Geo::GDAL::Dataset Warp($Dest, hashref Options, coderef progress, $progress_data)
2696 # Reproject this dataset.
2697 # @param Dest Destination raster dataset definition string (typically
2698 # filename) or an object, which implements write and close.
2699 # @param Options See section \ref index_processing_options.
2700 # @note This method can be run as a package subroutine with a list of
2701 # datasets as the first argument to mosaic several datasets.
2704 my ($self, $dest, $options, $progress, $progress_data) = @_;
2705 # can be run as object method (one dataset) and as package sub (a list of datasets)
2706 $options = Geo::GDAL::GDALWarpAppOptions->new(make_processing_options($options));
2707 my $b = blessed($dest);
2708 $self = [$self] unless ref $self eq
'ARRAY';
2709 if ($b && $b eq
'Geo::GDAL::Dataset') {
2710 Geo::GDAL::wrapper_GDALWarpDestDS($dest, $self, $options, $progress, $progress_data);
2712 return stdout_redirection_wrapper(
2715 \&Geo::GDAL::wrapper_GDALWarpDestName,
2716 $options, $progress, $progress_data
2721 #** @method Geo::GDAL::Dataset Warped(%params)
2723 # Create a virtual warped dataset from this dataset.
2725 # @param params Named parameters:
2726 # - \a SrcSRS Override the spatial reference system of this dataset if there is one (default is undef).
2727 # - \a DstSRS The target spatial reference system of the result (default is undef).
2728 # - \a ResampleAlg The resampling algorithm (default is 'NearestNeighbour').
2729 # - \a MaxError Maximum error measured in input cellsize that is allowed in approximating the transformation (default is 0 for exact calculations).
2731 # # <a href="http://www.gdal.org/gdalwarper_8h.html">Documentation for GDAL warper.</a>
2733 # @return a new Geo::GDAL::Dataset object
2737 my $p = named_parameters(\@_, SrcSRS => undef, DstSRS => undef, ResampleAlg =>
'NearestNeighbour', MaxError => 0);
2738 for my $srs (qw/srcsrs dstsrs/) {
2739 $p->{$srs} = $p->{$srs}->ExportToWkt
if $p->{$srs} && blessed $p->{$srs};
2741 $p->{resamplealg} = s2i(resampling => $p->{resamplealg});
2742 my $warped = Geo::GDAL::_AutoCreateWarpedVRT($self, $p->{srcsrs}, $p->{dstsrs}, $p->{resamplealg}, $p->{maxerror});
2743 keep($warped, $self)
if $warped; #
self must live as
long as warped
2746 #** @method WriteRaster(%params)
2748 # Write data into the dataset.
2750 # @param params Named parameters:
2751 # - \a XOff x offset (cell coordinates) (default is 0)
2752 # - \a YOff y offset (cell coordinates) (default is 0)
2753 # - \a XSize width of the area to write (default is the width of the dataset)
2754 # - \a YSize height of the area to write (default is the height of the dataset)
2755 # - \a Buf a buffer (or a reference to a buffer) containing the data. Create the buffer with \a pack function of Perl. See Geo::GDAL::Band::PackCharacter.
2756 # - \a BufXSize (default is undef, i.e., the same as XSize)
2757 # - \a BufYSize (default is undef, i.e., the same as YSize)
2758 # - \a BufType data type of the buffer (default is the data type of the first band)
2759 # - \a BandList a reference to an array of band indices (default is [1])
2760 # - \a BufPixelSpace (default is 0)
2761 # - \a BufLineSpace (default is 0)
2762 # - \a BufBandSpace (default is 0)
2764 # <a href="http://www.gdal.org/classGDALDataset.html">Entry in GDAL docs (method RasterIO)</a>
2768 my ($width, $height) = $self->Size;
2769 my ($type) = $self->Band->DataType;
2770 my $p = named_parameters(\@_,
2784 $p->{buftype} = s2i(data_type => $p->{buftype}, 1);
2785 $self->_WriteRaster($p->{xoff},$p->{yoff},$p->{xsize},$p->{ysize},$p->{buf},$p->{bufxsize},$p->{bufysize},$p->{buftype},$p->{bandlist},$p->{bufpixelspace},$p->{buflinespace},$p->{bufbandspace});
2788 #** @method WriteTile()
2791 my ($self, $data, $xoff, $yoff) = @_;
2794 for my $i (0..$self->Bands-1) {
2795 $self->Band($i+1)->WriteTile($data->[$i], $xoff, $yoff);
2799 #** @class Geo::GDAL::Dimension
2801 package Geo::GDAL::Dimension;
2805 #** @method GetDirection()
2810 #** @method GetFullName()
2815 #** @method GetIndexingVariable()
2817 sub GetIndexingVariable {
2820 #** @method GetName()
2825 #** @method GetSize()
2830 #** @method GetType()
2835 #** @method SetIndexingVariable()
2837 sub SetIndexingVariable {
2840 #** @class Geo::GDAL::Driver
2841 # @brief A driver for a specific dataset format.
2844 package Geo::GDAL::Driver;
2848 #** @attr $HelpTopic
2849 # $driver->{HelpTopic}
2853 # $driver->{LongName}
2856 #** @attr $ShortName
2857 # $driver->{ShortName}
2860 #** @method list Capabilities()
2862 # @return A list of capabilities. When executed as a package subroutine
2863 # returns a list of all potential capabilities a driver may have. When
2864 # executed as an object method returns a list of all capabilities the
2867 # Currently capabilities are:
2868 # CREATE, CREATECOPY, DEFAULT_FIELDS, NOTNULL_FIELDS, NOTNULL_GEOMFIELDS, OPEN, RASTER, UNIQUE_FIELDS, VECTOR, and VIRTUALIO.
2872 # @all_capabilities = Geo::GDAL::Driver::Capabilities;
2873 # @capabilities_of_the_geotiff_driver = Geo::GDAL::Driver('GTiff')->Capabilities;
2878 return @CAPABILITIES unless $self;
2879 my $h = $self->GetMetadata;
2881 for my $cap (@CAPABILITIES) {
2882 my $test = $h->{
'DCAP_'.uc($cap)};
2883 push @cap, $cap
if defined($test) and $test eq
'YES';
2888 #** @method Geo::GDAL::Dataset Copy(%params)
2890 # Create a new raster Geo::GDAL::Dataset as a copy of an existing dataset.
2891 # @note a.k.a. CreateCopy
2893 # @param params Named parameters:
2894 # - \a Name name for the new raster dataset.
2895 # - \a Src the source Geo::GDAL::Dataset object.
2896 # - \a Strict 1 (default) if the copy must be strictly equivalent, or 0 if the copy may adapt.
2897 # - \a Options an anonymous hash of driver specific options.
2898 # - \a Progress [optional] a reference to a subroutine, which will
2899 # be called with parameters (number progress, string msg, progress_data).
2900 # - \a ProgressData [optional]
2901 # @return a new Geo::GDAL::Dataset object.
2905 my $p = named_parameters(\@_, Name =>
'unnamed', Src => undef, Strict => 1, Options => {}, Progress => undef, ProgressData => undef);
2906 return $self->stdout_redirection_wrapper(
2908 $self->can(
'_CreateCopy'),
2909 $p->{src}, $p->{strict}, $p->{options}, $p->{progress}, $p->{progressdata});
2912 #** @method CopyFiles($NewName, $OldName)
2914 # Copy the files of a dataset.
2915 # @param NewName String.
2916 # @param OldName String.
2921 #** @method Geo::GDAL::Dataset Create(%params)
2923 # Create a raster dataset using this driver.
2924 # @note a.k.a. CreateDataset
2926 # @param params Named parameters:
2927 # - \a Name The name for the dataset (default is 'unnamed') or an object, which implements write and close.
2928 # - \a Width The width for the raster dataset (default is 256).
2929 # - \a Height The height for the raster dataset (default is 256).
2930 # - \a Bands The number of bands to create into the raster dataset (default is 1).
2931 # - \a Type The data type for the raster cells (default is 'Byte'). One of Geo::GDAL::Driver::CreationDataTypes.
2932 # - \a Options Driver creation options as a reference to a hash (default is {}).
2934 # @return A new Geo::GDAL::Dataset object.
2938 my $p = named_parameters(\@_, Name =>
'unnamed', Width => 256, Height => 256, Bands => 1, Type =>
'Byte', Options => {});
2939 my $type = s2i(data_type => $p->{type});
2940 return $self->stdout_redirection_wrapper(
2942 $self->can(
'_Create'),
2943 $p->{width}, $p->{height}, $p->{bands}, $type, $p->{options}
2947 #** @method CreateMultiDimensional()
2949 sub CreateMultiDimensional {
2952 #** @method list CreationDataTypes()
2954 # @return a list of data types that can be used for new datasets of this format. A subset of Geo::GDAL::DataTypes
2956 sub CreationDataTypes {
2958 my $h = $self->GetMetadata;
2959 return split /\s+/, $h->{DMD_CREATIONDATATYPES}
if $h->{DMD_CREATIONDATATYPES};
2962 #** @method list CreationOptionList()
2964 # @return a list of options, each option is a hashref, the keys are
2965 # name, type and description or Value. Value is a listref.
2967 sub CreationOptionList {
2970 my $h = $self->GetMetadata->{DMD_CREATIONOPTIONLIST};
2972 $h = ParseXMLString($h);
2973 my($type, $value) = NodeData($h);
2974 if ($value eq
'CreationOptionList') {
2975 for my $o (Children($h)) {
2977 for my $a (Children($o)) {
2978 my(undef, $key) = NodeData($a);
2979 my(undef, $value) = NodeData(Child($a, 0));
2980 if ($key eq
'Value') {
2981 push @{$option{$key}}, $value;
2983 $option{$key} = $value;
2986 push @options, \%option;
2993 #** @method Delete($name)
3000 #** @method Domains()
3006 #** @method scalar Extension()
3008 # @note The returned extension does not contain a '.' prefix.
3009 # @return a suggested single extension or a list of extensions (in
3010 # list context) for datasets.
3014 my $h = $self->GetMetadata;
3016 my $e = $h->{DMD_EXTENSIONS};
3017 my @e = split / /, $e;
3019 for my $i (0..$#e) {
3024 my $e = $h->{DMD_EXTENSION};
3025 return '' if $e =~ /\
3031 #** @method scalar MIMEType()
3033 # @return a suggested MIME type for datasets.
3037 my $h = $self->GetMetadata;
3038 return $h->{DMD_MIMETYPE};
3041 #** @method scalar Name()
3043 # @return The short name of the driver.
3047 return $self->{ShortName};
3052 # The same as Geo::GDAL::Open except that only this driver is allowed.
3056 my @p = @_; # name, update
3057 my @flags = qw/RASTER/;
3058 push @flags, qw/READONLY/
if $p[1] eq
'ReadOnly';
3059 push @flags, qw/UPDATE/
if $p[1] eq
'Update';
3060 my $dataset = OpenEx($p[0], \@flags, [$self->Name()]);
3061 error(
"Failed to open $p[0]. Is it a raster dataset?") unless $dataset;
3065 #** @method Rename($NewName, $OldName)
3067 # Rename (move) a GDAL dataset.
3068 # @param NewName String.
3069 # @param OldName String.
3074 #** @method scalar TestCapability($cap)
3076 # Test whether the driver has the specified capability.
3077 # @param cap A capability string (one of those returned by Capabilities).
3078 # @return a boolean value.
3080 sub TestCapability {
3081 my($self, $cap) = @_;
3082 my $h = $self->GetMetadata->{
'DCAP_'.uc($cap)};
3083 return (defined($h) and $h eq
'YES') ? 1 : undef;
3086 #** @method stdout_redirection_wrapper()
3088 sub stdout_redirection_wrapper {
3089 my ($self, $name, $sub, @params) = @_;
3091 if ($name && blessed $name) {
3093 my $ref = $object->can(
'write');
3094 VSIStdoutSetRedirection($ref);
3095 $name =
'/vsistdout/';
3099 $ds = $sub->($self, $name, @params);
3103 $Geo::GDAL::stdout_redirection{tied(%$ds)} = $object;
3105 VSIStdoutUnsetRedirection();
3109 confess(last_error()) if $@;
3110 confess("Failed. Use Geo::OGR::Driver for vector drivers.") unless $ds;
3114 #** @class Geo::GDAL::EDTComponent
3116 package Geo::GDAL::EDTComponent;
3120 #** @method GetName()
3125 #** @method GetOffset()
3130 #** @method GetType()
3135 #** @class Geo::GDAL::ExtendedDataType
3137 package Geo::GDAL::ExtendedDataType;
3141 #** @method CanConvertTo()
3146 #** @method CreateString()
3151 #** @method Equals()
3156 #** @method GetClass()
3161 #** @method GetMaxStringLength()
3163 sub GetMaxStringLength {
3166 #** @method GetName()
3171 #** @method GetNumericDataType()
3173 sub GetNumericDataType {
3176 #** @method GetSize()
3181 #** @class Geo::GDAL::Extent
3182 # @brief A rectangular area in projection coordinates: xmin, ymin, xmax, ymax.
3184 package Geo::GDAL::Extent;
3186 #** @method ExpandToInclude($extent)
3187 # Package subroutine.
3188 # Extends this extent to include the other extent.
3189 # @param extent Another Geo::GDAL::Extent object.
3191 sub ExpandToInclude {
3192 my ($self, $e) = @_;
3193 return if $e->IsEmpty;
3194 if ($self->IsEmpty) {
3197 $self->[0] = $e->[0]
if $e->[0] < $self->[0];
3198 $self->[1] = $e->[1]
if $e->[1] < $self->[1];
3199 $self->[2] = $e->[2]
if $e->[2] > $self->[2];
3200 $self->[3] = $e->[3]
if $e->[3] > $self->[3];
3204 #** @method IsEmpty()
3208 return $self->[2] < $self->[0];
3211 #** @method scalar Overlap($extent)
3212 # Package subroutine.
3213 # @param extent Another Geo::GDAL::Extent object.
3214 # @return A new, possibly empty, Geo::GDAL::Extent object, which
3215 # represents the joint area of the two extents.
3218 my ($self, $e) = @_;
3221 $ret->[0] = $e->[0]
if $self->[0] < $e->[0];
3222 $ret->[1] = $e->[1]
if $self->[1] < $e->[1];
3223 $ret->[2] = $e->[2]
if $self->[2] > $e->[2];
3224 $ret->[3] = $e->[3]
if $self->[3] > $e->[3];
3228 #** @method scalar Overlaps($extent)
3229 # Package subroutine.
3230 # @param extent Another Geo::GDAL::Extent object.
3231 # @return True if this extent overlaps the other extent, false otherwise.
3234 my ($self, $e) = @_;
3235 return $self->[0] < $e->[2] && $self->[2] > $e->[0] && $self->[1] < $e->[3] && $self->[3] > $e->[1];
3238 #** @method list Size()
3239 # Package subroutine.
3240 # @return A list ($width, $height).
3244 return (0,0)
if $self->
IsEmpty;
3245 return ($self->[2] - $self->[0], $self->[3] - $self->[1]);
3248 #** @method Geo::GDAL::Extent new(@params)
3249 # Package subroutine.
3250 # @param params nothing, a list ($xmin, $ymin, $xmax, $ymax), or an Extent object
3251 # @return A new Extent object (empty if no parameters, a copy of the parameter if it is an Extent object).
3258 } elsif (ref $_[0]) {
3263 bless $self, $class;
3267 #** @class Geo::GDAL::GCP
3268 # @brief A ground control point for georeferencing rasters.
3271 package Geo::GDAL::GCP;
3276 # cell x coordinate (access as $gcp->{Column})
3280 # unique identifier (string) (access as $gcp->{Id})
3284 # informational message (access as $gcp->{Info})
3288 # cell y coordinate (access as $gcp->{Row})
3292 # projection coordinate (access as $gcp->{X})
3296 # projection coordinate (access as $gcp->{Y})
3300 # projection coordinate (access as $gcp->{Z})
3303 #** @method scalar new($x = 0.0, $y = 0.0, $z = 0.0, $column = 0.0, $row = 0.0, $info = "", $id = "")
3305 # @param x projection coordinate
3306 # @param y projection coordinate
3307 # @param z projection coordinate
3308 # @param column cell x coordinate
3309 # @param row cell y coordinate
3310 # @param info informational message
3311 # @param id unique identifier (string)
3312 # @return a new Geo::GDAL::GCP object
3316 my $self = Geo::GDALc::new_GCP(@_);
3317 bless $self, $pkg
if defined($self);
3320 #** @class Geo::GDAL::GDALMultiDimInfoOptions
3322 package Geo::GDAL::GDALMultiDimInfoOptions;
3330 my $self = Geo::GDALc::new_GDALMultiDimInfoOptions(@_);
3331 bless $self, $pkg
if defined($self);
3334 #** @class Geo::GDAL::GDALMultiDimTranslateOptions
3336 package Geo::GDAL::GDALMultiDimTranslateOptions;
3344 my $self = Geo::GDALc::new_GDALMultiDimTranslateOptions(@_);
3345 bless $self, $pkg
if defined($self);
3348 #** @class Geo::GDAL::GeoTransform
3349 # @brief An array of affine transformation coefficients.
3350 # @details The geo transformation has the form
3352 # x = a + column * b + row * c
3353 # y = d + column * e + row * f
3356 # (column,row) is the location in cell coordinates, and
3357 # (x,y) is the location in projection coordinates, or vice versa.
3358 # A Geo::GDAL::GeoTransform object is a reference to an anonymous array [a,b,c,d,e,f].
3360 package Geo::GDAL::GeoTransform;
3362 #** @method Apply($x, $y)
3364 # @param x Column or x, or a reference to an array of columns or x's
3365 # @param y Row or y, or a reference to an array of rows or y's
3366 # @return a list (x, y), where x and y are the transformed coordinates
3367 # or references to arrays of transformed coordinates.
3370 my ($self, $columns, $rows) = @_;
3371 return Geo::GDAL::ApplyGeoTransform($self, $columns, $rows) unless ref($columns) eq
'ARRAY';
3373 for my $i (0..$#$columns) {
3375 Geo::GDAL::ApplyGeoTransform($self, $columns->[$i], $rows->[$i]);
3382 # @return a new Geo::GDAL::GeoTransform object, which is the inverse
3383 # of this one (in void context changes this object).
3387 my @inv = Geo::GDAL::InvGeoTransform($self);
3392 #** @method NorthUp()
3396 return $self->[2] == 0 && $self->[4] == 0;
3399 #** @method new(@params)
3401 # @param params nothing, a reference to an array [a,b,c,d,e,f], a list
3402 # (a,b,c,d,e,f), or named parameters
3403 # - \a GCPs A reference to an array of Geo::GDAL::GCP objects.
3404 # - \a ApproxOK Minimize the error in the coefficients (integer, default is 1 (true), used with GCPs).
3405 # - \a Extent A Geo::GDAL::Extent object used to obtain the coordinates of the up left corner position.
3406 # - \a CellSize The cell size (width and height) (default is 1, used with Extent).
3408 # @note When Extent is specifid, the created geo transform will be
3409 # north up, have square cells, and coefficient f will be -1 times the
3410 # cell size (image y - row - will increase downwards and projection y
3411 # will increase upwards).
3412 # @return a new Geo::GDAL::GeoTransform object.
3418 $self = [0,1,0,0,0,1];
3419 } elsif (ref $_[0]) {
3421 } elsif ($_[0] =~ /^[a-zA-Z]/i) {
3422 my $p = named_parameters(\@_, GCPs => undef, ApproxOK => 1,
Extent => undef, CellSize => 1);
3424 $self = Geo::GDAL::GCPsToGeoTransform($p->{gcps}, $p->{approxok});
3425 } elsif ($p->{extent}) {
3428 error(
"Missing GCPs or Extent");
3434 bless $self, $class;
3437 #** @class Geo::GDAL::Group
3439 package Geo::GDAL::Group;
3443 #** @method CreateAttribute()
3445 sub CreateAttribute {
3448 #** @method CreateDimension()
3450 sub CreateDimension {
3453 #** @method CreateGroup()
3458 #** @method GetAttribute()
3463 #** @method GetFullName()
3468 #** @method GetGroupNames()
3473 #** @method GetMDArrayNames()
3475 sub GetMDArrayNames {
3478 #** @method GetName()
3483 #** @method GetStructuralInfo()
3485 sub GetStructuralInfo {
3488 #** @method OpenGroup()
3493 #** @method OpenGroupFromFullname()
3495 sub OpenGroupFromFullname {
3498 #** @method OpenMDArray()
3503 #** @method OpenMDArrayFromFullname()
3505 sub OpenMDArrayFromFullname {
3508 #** @method ResolveMDArray()
3510 sub ResolveMDArray {
3513 #** @class Geo::GDAL::MDArray
3515 package Geo::GDAL::MDArray;
3519 #** @method AsClassicDataset()
3521 sub AsClassicDataset {
3524 #** @method ComputeStatistics()
3526 sub ComputeStatistics {
3529 #** @method CreateAttribute()
3531 sub CreateAttribute {
3534 #** @method DeleteNoDataValue()
3536 sub DeleteNoDataValue {
3539 #** @method GetAttribute()
3544 #** @method GetDataType()
3549 #** @method GetDimensionCount()
3551 sub GetDimensionCount {
3554 #** @method GetFullName()
3559 #** @method GetMask()
3564 #** @method GetName()
3569 #** @method GetNoDataValueAsDouble()
3571 sub GetNoDataValueAsDouble {
3574 #** @method GetOffset()
3579 #** @method GetScale()
3584 #** @method GetSpatialRef()
3589 #** @method GetStatistics()
3594 #** @method GetStructuralInfo()
3596 sub GetStructuralInfo {
3599 #** @method GetTotalElementsCount()
3601 sub GetTotalElementsCount {
3604 #** @method GetUnit()
3609 #** @method GetUnscaled()
3614 #** @method GetView()
3619 #** @method SetNoDataValueDouble()
3621 sub SetNoDataValueDouble {
3624 #** @method SetOffset()
3629 #** @method SetScale()
3634 #** @method SetSpatialRef()
3639 #** @method SetUnit()
3644 #** @method Transpose()
3649 #** @class Geo::GDAL::MajorObject
3650 # @brief An object, which holds meta data.
3653 package Geo::GDAL::MajorObject;
3657 #** @method scalar Description($description)
3659 # @param description [optional]
3660 # @return the description in a non-void context.
3663 my($self, $desc) = @_;
3664 SetDescription($self, $desc)
if defined $desc;
3665 GetDescription($self)
if defined wantarray;
3668 #** @method Domains()
3669 # Package subroutine.
3670 # @return the class specific DOMAINS list
3676 #** @method scalar GetDescription()
3680 sub GetDescription {
3683 #** @method hash reference GetMetadata($domain = "")
3685 # @note see Metadata
3692 #** @method GetMetadataDomainList()
3694 sub GetMetadataDomainList {
3697 #** @method hash reference Metadata(hashref metadata = undef, $domain = '')
3701 # @return the metadata in a non-void context.
3705 my $metadata = ref $_[0] ? shift : undef;
3707 SetMetadata($self, $metadata, $domain)
if defined $metadata;
3708 GetMetadata($self, $domain)
if defined wantarray;
3711 #** @method SetDescription($NewDesc)
3716 sub SetDescription {
3719 #** @method SetMetadata(hashref metadata, $domain = "")
3721 # @note see Metadata
3729 #** @class Geo::GDAL::RasterAttributeTable
3730 # @brief An attribute table in a raster band.
3733 package Geo::GDAL::RasterAttributeTable;
3744 #** @method ChangesAreWrittenToFile()
3746 sub ChangesAreWrittenToFile {
3749 #** @method Geo::GDAL::RasterAttributeTable Clone()
3751 # @return a new Geo::GDAL::RasterAttributeTable object
3756 #** @method hash Columns(%columns)
3758 # A get/set method for the columns of the RAT
3759 # @param columns optional, a the keys are column names and the values are anonymous
3760 # hashes with keys Type and Usage
3761 # @return a hash similar to the optional input parameter
3766 if (@_) { # create columns
3768 for my $name (keys %columns) {
3769 $self->CreateColumn($name, $columns{$name}{Type}, $columns{$name}{Usage});
3773 for my $c (0..$self->GetColumnCount-1) {
3774 my $name = $self->GetNameOfCol($c);
3775 $columns{$name}{Type} = $self->GetTypeOfCol($c);
3776 $columns{$name}{Usage} = $self->GetUsageOfCol($c);
3781 #** @method CreateColumn($name, $type, $usage)
3784 # @param type one of FieldTypes
3785 # @param usage one of FieldUsages
3788 my($self, $name, $type, $usage) = @_;
3789 for my $color (qw/Red Green Blue Alpha/) {
3790 carp
"RAT column type will be 'Integer' for usage '$color'." if $usage eq $color and $type ne
'Integer';
3792 $type = s2i(rat_field_type => $type);
3793 $usage = s2i(rat_field_usage => $usage);
3794 _CreateColumn($self, $name, $type, $usage);
3797 #** @method DumpReadable()
3802 #** @method list FieldTypes()
3803 # Package subroutine.
3807 return @FIELD_TYPES;
3810 #** @method list FieldUsages()
3811 # Package subroutine.
3815 return @FIELD_USAGES;
3818 #** @method scalar GetColOfUsage($usage)
3824 my($self, $usage) = @_;
3825 _GetColOfUsage($self, s2i(rat_field_usage => $usage));
3828 #** @method scalar GetColumnCount()
3832 sub GetColumnCount {
3835 #** @method scalar GetNameOfCol($column)
3843 #** @method scalar GetRowCount()
3849 #** @method scalar GetRowOfValue($value)
3851 # @param value a cell value
3852 # @return row index or -1
3857 #** @method GetTableType()
3862 #** @method scalar GetTypeOfCol($column)
3868 my($self, $col) = @_;
3869 i2s(rat_field_type => _GetTypeOfCol($self, $col));
3872 #** @method scalar GetUsageOfCol($column)
3878 my($self, $col) = @_;
3879 i2s(rat_field_usage => _GetUsageOfCol($self, $col));
3882 #** @method scalar GetValueAsDouble($row, $column)
3888 sub GetValueAsDouble {
3891 #** @method scalar GetValueAsInt($row, $column)
3900 #** @method scalar GetValueAsString($row, $column)
3906 sub GetValueAsString {
3909 #** @method LinearBinning($Row0MinIn, $BinSizeIn)
3911 # @param Row0MinIn [optional] the lower bound (cell value) of the first category.
3912 # @param BinSizeIn [optional] the width of each category (in cell value units).
3913 # @return ($Row0MinIn, $BinSizeIn) or an empty list if LinearBinning is not set.
3917 SetLinearBinning($self, @_)
if @_ > 0;
3918 return unless defined wantarray;
3919 my @a = GetLinearBinning($self);
3920 return $a[0] ? ($a[1], $a[2]) : ();
3923 #** @method SetRowCount($count)
3931 #** @method SetTableType()
3936 #** @method SetValueAsDouble($row, $column, $value)
3943 sub SetValueAsDouble {
3946 #** @method SetValueAsInt($row, $column, $value)
3956 #** @method SetValueAsString($row, $column, $value)
3963 sub SetValueAsString {
3966 #** @method scalar Value($row, $column, $value)
3970 # @param value [optional]
3974 my($self, $row, $column) = @_;
3975 SetValueAsString($self, $row, $column, $_[3])
if defined $_[3];
3976 return unless defined wantarray;
3977 GetValueAsString($self, $row, $column);
3980 #** @method Geo::GDAL::RasterAttributeTable new()
3982 # @return a new Geo::GDAL::RasterAttributeTable object
3986 my $self = Geo::GDALc::new_RasterAttributeTable(@_);
3987 bless $self, $pkg
if defined($self);
3990 #** @class Geo::GDAL::Statistics
3992 package Geo::GDAL::Statistics;
4000 my $self = Geo::GDALc::new_Statistics(@_);
4001 bless $self, $pkg
if defined($self);
4004 #** @class Geo::GDAL::Transformer
4006 # @details This class is not yet documented for the GDAL Perl bindings.
4007 # @todo Test and document.
4009 package Geo::GDAL::Transformer;
4013 #** @method TransformGeolocations()
4015 sub TransformGeolocations {
4018 #** @method TransformPoint()
4020 sub TransformPoint {
4027 my $self = Geo::GDALc::new_Transformer(@_);
4028 bless $self, $pkg
if defined($self);
4031 #** @class Geo::GDAL::VSIF
4032 # @brief A GDAL virtual file system.
4035 package Geo::GDAL::VSIF;
4037 use base qw(Exporter)
4044 Geo::GDAL::VSIFCloseL($self);
4054 #** @method MkDir($path)
4055 # Package subroutine.
4057 # @param path The directory to make.
4058 # @note The name of this method is VSIMkdir in GDAL.
4062 # mode unused in CPL
4063 Geo::GDAL::Mkdir($path, 0);
4066 #** @method Geo::GDAL::VSIF Open($filename, $mode)
4067 # Package subroutine.
4068 # @param filename Name of the file to open. For example "/vsimem/x".
4069 # @param mode Access mode. 'r', 'r+', 'w', etc.
4070 # @return A file handle on success.
4073 my ($path, $mode) = @_;
4074 my $self = Geo::GDAL::VSIFOpenL($path, $mode);
4075 bless $self,
'Geo::GDAL::VSIF';
4078 #** @method scalar Read($count)
4080 # @param count The number of bytes to read from the file.
4081 # @return A byte string.
4084 my ($self, $count) = @_;
4085 Geo::GDAL::VSIFReadL($count, $self);
4088 #** @method list ReadDir($dir)
4089 # Package subroutine.
4090 # @return Contents of a directory in an anonymous array or as a list.
4094 Geo::GDAL::ReadDir($path);
4097 #** @method scalar ReadDirRecursive($dir)
4098 # Package subroutine.
4099 # @note Give the directory in the form '/vsimem', i.e., without trailing '/'.
4100 # @return Contents of a directory tree in an anonymous array.
4102 sub ReadDirRecursive {
4104 Geo::GDAL::ReadDirRecursive($path);
4107 #** @method Rename($old, $new)
4108 # Package subroutine.
4110 # @note The name of this method is VSIRename in GDAL.
4113 my ($old, $new) = @_;
4114 Geo::GDAL::Rename($old, $new);
4117 #** @method RmDir($path)
4118 # Package subroutine.
4119 # Remove a directory.
4120 # @note The name of this method is VSIRmdir in GDAL.
4123 my ($dirname, $recursive) = @_;
4126 Geo::GDAL::Rmdir($dirname);
4128 for my $f (ReadDir($dirname)) {
4129 next
if $f eq
'..' or $f eq
'.';
4130 my @s = Stat($dirname.
'/'.$f);
4132 Unlink($dirname.
'/'.$f);
4133 } elsif ($s[0] eq
'd') {
4134 Rmdir($dirname.
'/'.$f, 1);
4135 Rmdir($dirname.
'/'.$f);
4142 my $r = $recursive ?
' recursively' :
'';
4143 error(
"Cannot remove directory \"$dirname\"$r.");
4147 #** @method Seek($offset, $whence)
4151 my ($self, $offset, $whence) = @_;
4152 Geo::GDAL::VSIFSeekL($self, $offset, $whence);
4155 #** @method list Stat($filename)
4156 # Package subroutine.
4157 # @return ($filemode, $filesize). filemode is f for a plain file, d
4158 # for a directory, l for a symbolic link, p for a named pipe (FIFO), S
4159 # for a socket, b for a block special file, and c for a character
4164 Geo::GDAL::Stat($path);
4167 #** @method scalar Tell()
4172 Geo::GDAL::VSIFTellL($self);
4175 #** @method Truncate($new_size)
4179 my ($self, $new_size) = @_;
4180 Geo::GDAL::VSIFTruncateL($self, $new_size);
4183 #** @method Unlink($filename)
4184 # Package subroutine.
4185 # @param filename The file to delete.
4186 # @return 0 on success and -1 on an error.
4189 my ($filename) = @_;
4190 Geo::GDAL::Unlink($filename);
4193 #** @method Write($scalar)
4195 # @param scalar The byte string to write to the file.
4196 # @return Number of bytes written into the file.
4199 my ($self, $data) = @_;
4200 Geo::GDAL::VSIFWriteL($data, $self);
4203 #** @class Geo::GDAL::VSILFILE
4205 package Geo::GDAL::VSILFILE;
4209 #** @class Geo::GDAL::XML
4210 # @brief A simple XML parser
4213 package Geo::GDAL::XML;
4215 #** @method new($string)
4217 # @param string String containing XML.
4218 # @return A new Geo::GDAL::XML object, which is a reference to an anonymous array.
4223 my $self = ParseXMLString($xml);
4224 bless $self, $class;
4225 $self->traverse(sub {my $node = shift; bless $node, $class});
4229 #** @method serialize()
4231 # @return The XML serialized into a string.
4235 return SerializeXMLTree($self);
4238 # This file was automatically generated by SWIG (http:
4241 # Do not make changes to this file unless you know what you are doing--modify
4242 # the SWIG interface file instead.
4245 #** @method traverse(coderef subroutine)
4247 # @param subroutine Code reference, which will be called for each node in the XML with parameters: node, node_type, node_value. Node type is either Attribute, Comment, Element, Literal, or Text.
4250 my ($self, $sub) = @_;
4251 my $type = $self->[0];
4252 my $data = $self->[1];
4253 $type = NodeType($type);
4254 $sub->($self, $type, $data);
4255 for my $child (@{$self}[2..$#$self]) {
4256 traverse($child, $sub);
4261 # @brief Base class for geographical networks in GDAL.
4266 #** @method CastToGenericNetwork()
4268 sub CastToGenericNetwork {
4271 #** @method CastToNetwork()
4276 #** @method GATConnectedComponents()
4278 sub GATConnectedComponents {
4281 #** @method GATDijkstraShortestPath()
4283 sub GATDijkstraShortestPath {
4286 #** @method GATKShortestPath()
4288 sub GATKShortestPath {
4291 #** @method GNM_EDGE_DIR_BOTH()
4293 sub GNM_EDGE_DIR_BOTH {
4296 #** @method GNM_EDGE_DIR_SRCTOTGT()
4298 sub GNM_EDGE_DIR_SRCTOTGT {
4301 #** @method GNM_EDGE_DIR_TGTTOSRC()
4303 sub GNM_EDGE_DIR_TGTTOSRC {
4307 #** @class Geo::GNM::GenericNetwork
4310 package Geo::GNM::GenericNetwork;
4314 #** @method ChangeAllBlockState()
4316 sub ChangeAllBlockState {
4319 #** @method ChangeBlockState()
4321 sub ChangeBlockState {
4324 #** @method ConnectFeatures()
4326 sub ConnectFeatures {
4329 #** @method ConnectPointsByLines()
4331 sub ConnectPointsByLines {
4334 #** @method CreateRule()
4339 #** @method DeleteAllRules()
4341 sub DeleteAllRules {
4344 #** @method DeleteRule()
4349 #** @method DisconnectFeatures()
4351 sub DisconnectFeatures {
4354 #** @method DisconnectFeaturesWithId()
4356 sub DisconnectFeaturesWithId {