Geo::GDAL  2.4
all.pm
Go to the documentation of this file.
1 #** @class Geo::GDAL
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.
7 #*
8 package Geo::GDAL;
9 
10 #** @method ApplyVerticalShiftGrid()
11 #*
12 sub ApplyVerticalShiftGrid {
13 }
14 
15 #** @method BuildVRT()
16 #*
17 sub BuildVRT {
18  for (keys %Geo::GDAL::Const::) {
19  next if /TypeCount/;
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+)/;
25  }
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;
30  }
31  for my $string (@OPEN_FLAGS) {
32  my $int = eval "\$Geo::GDAL::Const::OF_$string";
33  $S2I{open_flag}{$string} = $int;
34  }
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;
39  }
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;
44  }
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;
49  }
50  our $HAVE_PDL;
51  eval 'require PDL';
52  $HAVE_PDL = 1 unless $@;
53 }
54 
55 #** @method CPLBinaryToHex()
56 #*
57 sub CPLBinaryToHex {
58 }
59 
60 #** @method CPLHexToBinary()
61 #*
62 sub CPLHexToBinary {
63 }
64 
65 #** @method ContourGenerateEx()
66 #*
67 sub ContourGenerateEx {
68 }
69 
70 #** @method CreatePansharpenedVRT()
71 #*
72 sub CreatePansharpenedVRT {
73 }
74 
75 #** @method scalar DataTypeIsComplex($DataType)
76 # Package subroutine.
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.
79 #*
80 sub DataTypeIsComplex {
81  return _DataTypeIsComplex(s2i(data_type => shift));
82 }
83 
84 #** @method list DataTypeValueRange($DataType)
85 # Package subroutine.
86 # @param DataType Data type (one of those listed by Geo::GDAL::DataTypes).
87 # @note Some returned values are inaccurate.
88 #
89 # @return the minimum, maximum range of the data type.
90 #*
91 sub DataTypeValueRange {
92  my $t = shift;
93  s2i(data_type => $t);
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/;
102 }
103 
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.
108 #*
109 sub DataTypes {
110  return @DATA_TYPES;
111 }
112 
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').
118 # @param precision
119 # @return a string nndnn'nn.nn'"L where n is a number and L is either
120 # N or E
121 #*
122 sub DecToDMS {
123 }
124 
125 #** @method scalar DecToPackedDMS($dec)
126 # Package subroutine.
127 # @param dec Decimal degrees
128 # @return packed DMS, i.e., a number DDDMMMSSS.SS
129 #*
130 sub DecToPackedDMS {
131 }
132 
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.
137 #*
138 sub DontUseExceptions {
139 }
140 
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.
149 #*
150 sub Driver {
151  return 'Geo::GDAL::Driver' unless @_;
152  my $name = shift;
153  my $driver = GetDriver($name);
154  error("Driver \"$name\" not found. Is it built in? Check with Geo::GDAL::Drivers or Geo::OGR::Drivers.")
155  unless $driver;
156  return $driver;
157 }
158 
159 #** @method list DriverNames()
160 # Package subroutine.
161 # Available raster format drivers.
162 # \code
163 # perl -MGeo::GDAL -e '@d=Geo::GDAL::DriverNames;print "@d\n"'
164 # \endcode
165 # @note Use Geo::OGR::DriverNames for vector drivers.
166 # @return a list of the short names of all available GDAL raster drivers.
167 #*
168 sub DriverNames {
169 }
170 
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.
175 #*
176 sub Drivers {
177  my @drivers;
178  for my $i (0..GetDriverCount()-1) {
179  my $driver = GetDriver($i);
180  push @drivers, $driver if $driver->TestCapability('RASTER');
181  }
182  return @drivers;
183 }
184 
185 #** @method EscapeString()
186 #*
187 sub EscapeString {
188 }
189 
190 #** @method scalar FindFile($basename)
191 # Package subroutine.
192 # Search for GDAL support files.
193 #
194 # An example:
195 # \code
196 # use Geo::GDAL;
197 # $a = Geo::GDAL::FindFile('pcs.csv');
198 # print STDERR "$a\n";
199 # \endcode
200 # Prints (for example):
201 # \code
202 # c:\msys\1.0\local\share\gdal\pcs.csv
203 # \endcode
204 #
205 # @param basename The name of the file to search for. For example
206 # 'pcs.csv'.
207 # @return the path to the searched file or undef.
208 #*
209 sub FindFile {
210  if (@_ == 1) {
211  _FindFile('', @_);
212  } else {
213  _FindFile(@_);
214  }
215 }
216 
217 #** @method FinderClean()
218 # Package subroutine.
219 # Clear the set of support file search paths.
220 #*
221 sub FinderClean {
222 }
223 
224 #** @method GOA2GetAccessToken()
225 #*
226 sub GOA2GetAccessToken {
227 }
228 
229 #** @method GOA2GetAuthorizationURL()
230 #*
231 sub GOA2GetAuthorizationURL {
232 }
233 
234 #** @method GOA2GetRefreshToken()
235 #*
236 sub GOA2GetRefreshToken {
237 }
238 
239 #** @method GetActualURL()
240 #*
241 sub GetActualURL {
242 }
243 
244 #** @method scalar GetCacheMax()
245 # Package subroutine.
246 # @return maximum amount of memory (as bytes) for caching within GDAL.
247 #*
248 sub GetCacheMax {
249 }
250 
251 #** @method scalar GetCacheUsed()
252 # Package subroutine.
253 # @return the amount of memory currently used for caching within GDAL.
254 #*
255 sub GetCacheUsed {
256 }
257 
258 #** @method scalar GetConfigOption($key)
259 # Package subroutine.
260 # @param key A GDAL config option. Consult <a
261 # href="https://trac.osgeo.org/gdal/wiki/ConfigOptions">the GDAL
262 # documentation</a> for available options and their use.
263 # @return the value of the GDAL config option.
264 #*
265 sub GetConfigOption {
266 }
267 
268 #** @method scalar GetDataTypeSize($DataType)
269 # Package subroutine.
270 # @param DataType A GDAL raster cell data type (one of those listed by Geo::GDAL::DataTypes).
271 # @return the size as the number of bits.
272 #*
273 sub GetDataTypeSize {
274  return _GetDataTypeSize(s2i(data_type => shift, 1));
275 }
276 
277 #** @method GetErrorCounter()
278 #*
279 sub GetErrorCounter {
280 }
281 
282 #** @method GetFileSystemOptions()
283 #*
284 sub GetFileSystemOptions {
285 }
286 
287 #** @method GetFileSystemsPrefixes()
288 #*
289 sub GetFileSystemsPrefixes {
290 }
291 
292 #** @method GetJPEG2000StructureAsString()
293 #*
294 sub GetJPEG2000StructureAsString {
295 }
296 
297 #** @method GetSignedURL()
298 #*
299 sub GetSignedURL {
300 }
301 
302 #** @method Geo::GDAL::Driver IdentifyDriver($path, $siblings)
303 # Package subroutine.
304 # @param path a dataset path.
305 # @param siblings [optional] A list of names of files that belong to the data format.
306 # @return a Geo::GDAL::Driver.
307 #*
308 sub IdentifyDriver {
309 }
310 
311 #** @method IdentifyDriverEx()
312 #*
313 sub IdentifyDriverEx {
314 }
315 
316 #** @method MkdirRecursive()
317 #*
318 sub MkdirRecursive {
319 }
320 
321 #** @method Geo::GDAL::Dataset Open(%params)
322 # Package subroutine.
323 # Open a dataset.
324 # An example, which opens an existing raster dataset for editing:
325 # \code
326 # use Geo::GDAL qw/:all/;
327 # $ds = Open(Name => 'existing.tiff', Access => 'Update');
328 # \endcode
329 # @param params Named parameters:
330 # - \a Name Dataset string (typically a filename). Default is '.'.
331 # - \a Access Access type, either 'ReadOnly' or 'Update'. Default is 'ReadOnly'.
332 # - \a Type Dataset type, either 'Raster', 'Vector', or 'Any'. Default is 'Any'.
333 # - \a Options A hash of GDAL open options passed to candidate drivers. Default is {}.
334 # - \a Files A list of names of files that are auxiliary to the main file. Default is [].
335 #
336 # @note This subroutine is imported into the main namespace if Geo::GDAL
337 # is use'd with qw/:all/.
338 #
339 # @note Some datasets / dataset strings do not explicitly imply the
340 # dataset type (for example a PostGIS database). If the type is not
341 # specified in such a case the returned dataset may be of either type.
342 #
343 # @return a new Geo::GDAL::Dataset object if success.
344 #*
345 sub Open {
346  my $p = named_parameters(\@_, Name => '.', Access => 'ReadOnly', Type => 'Any', Options => {}, Files => []);
347  my @flags;
348  my %o = (READONLY => 1, UPDATE => 1);
349  error(1, $p->{access}, \%o) unless $o{uc($p->{access})};
350  push @flags, uc($p->{access});
351  %o = (RASTER => 1, VECTOR => 1, ANY => 1);
352  error(1, $p->{type}, \%o) unless $o{uc($p->{type})};
353  push @flags, uc($p->{type}) unless uc($p->{type}) eq 'ANY';
354  my $dataset = OpenEx(Name => $p->{name}, Flags => \@flags, Options => $p->{options}, Files => $p->{files});
355  unless ($dataset) {
356  my $t = "Failed to open $p->{name}.";
357  $t .= " Is it a ".lc($p->{type})." dataset?" unless uc($p->{type}) eq 'ANY';
358  error($t);
359  }
360  return $dataset;
361 }
362 
363 #** @method Geo::GDAL::Dataset OpenEx(%params)
364 # Package subroutine.
365 # The generic dataset open method, used internally by all Open and OpenShared methods.
366 # @param params Named parameters:
367 # - \a Name The name of the data set or source to open. (Default is '.')
368 # - \a Flags A list of access mode flags. Available flags are listed by Geo::GDAL::OpenFlags(). (Default is [])
369 # - \a Drivers A list of short names of drivers that may be used. Empty list means all. (Default is [])
370 # - \a Options A hash of GDAL open options passed to candidate drivers. (Default is {})
371 # - \a Files A list of names of files that are auxiliary to the main file. (Default is [])
372 #
373 # An example
374 # \code
375 # $ds = Geo::GDAL::OpenEx(Name => 'existing.tiff', Flags => [qw/RASTER UPDATE/]);
376 # \endcode
377 # @return a new Geo::GDAL::Dataset object.
378 #*
379 sub OpenEx {
380  my $p = named_parameters(\@_, Name => '.', Flags => [], Drivers => [], Options => {}, Files => []);
381  unless ($p) {
382  my $name = shift // '';
383  my @flags = @_;
384  $p = {name => $name, flags => \@flags, drivers => [], options => {}, files => []};
385  }
386  if ($p->{flags}) {
387  my $f = 0;
388  for my $flag (@{$p->{flags}}) {
389  $f |= s2i(open_flag => $flag);
390  }
391  $p->{flags} = $f;
392  }
393  return _OpenEx($p->{name}, $p->{flags}, $p->{drivers}, $p->{options}, $p->{files});
394 }
395 
396 #** @method list OpenFlags()
397 # Package subroutine.
398 # @return a list of GDAL data set open modes. These are currently:
399 # ALL, GNM, RASTER, READONLY, SHARED, UPDATE, VECTOR, and VERBOSE_ERROR.
400 #*
401 sub OpenFlags {
402  return @DATA_TYPES;
403 }
404 
405 #** @method scalar PackCharacter($DataType)
406 # Package subroutine.
407 # Get the character that is needed for Perl's pack and unpack when
408 # they are used with Geo::GDAL::Band::ReadRaster and
409 # Geo::GDAL::Band::WriteRaster. Note that Geo::GDAL::Band::ReadTile
410 # and Geo::GDAL::Band::WriteTile have simpler interfaces that do not
411 # require pack and unpack.
412 # @param DataType A GDAL raster cell data type, typically from $band->DataType.
413 # @return a character which can be used in Perl's pack and unpack.
414 #*
415 sub PackCharacter {
416  my $t = shift;
417  $t = i2s(data_type => $t);
418  s2i(data_type => $t); # test
419  my $is_big_endian = unpack("h*", pack("s", 1)) =~ /01/; # from Programming Perl
420  return 'C' if $t =~ /^Byte$/;
421  return ($is_big_endian ? 'n': 'v') if $t =~ /^UInt16$/;
422  return 's' if $t =~ /^Int16$/;
423  return ($is_big_endian ? 'N' : 'V') if $t =~ /^UInt32$/;
424  return 'l' if $t =~ /^Int32$/;
425  return 'f' if $t =~ /^Float32$/;
426  return 'd' if $t =~ /^Float64$/;
427 }
428 
429 #** @method scalar PackedDMSToDec($packed)
430 # Package subroutine.
431 # @param packed DMS as a number DDDMMMSSS.SS
432 # @return decimal degrees
433 #*
434 sub PackedDMSToDec {
435 }
436 
437 #** @method PopFinderLocation()
438 # Package subroutine.
439 # Remove the latest addition from the set of support file search
440 # paths. Note that calling this subroutine may remove paths GDAL put
441 # into the finder.
442 #*
443 sub PopFinderLocation {
444 }
445 
446 #** @method PushFinderLocation($path)
447 # Package subroutine.
448 # Add a path to the set of paths from where GDAL support files are
449 # sought. Note that GDAL puts initially into the finder the current
450 # directory and value of GDAL_DATA environment variable (if it
451 # exists), installation directory (prepended with '/share/gdal' or
452 # '/Resources/gdal'), or '/usr/local/share/gdal'. It is usually only
453 # needed to add paths to the finder if using an alternate set of data
454 # files or a non-installed GDAL is used (as in testing).
455 #*
456 sub PushFinderLocation {
457 }
458 
459 #** @method list RIOResamplingTypes()
460 # Package subroutine.
461 # @return a list of GDAL raster IO resampling methods. These are currently:
462 # Average, Bilinear, Cubic, CubicSpline, Gauss, Lanczos, Mode, and NearestNeighbour.
463 #*
464 sub RIOResamplingTypes {
465  return @RIO_RESAMPLING_TYPES;
466 }
467 
468 #** @method list ResamplingTypes()
469 # Package subroutine.
470 # @return a list of GDAL resampling methods. These are currently:
471 # Average, Bilinear, Cubic, CubicSpline, Lanczos, Max, Med, Min, Mode, NearestNeighbour, Q1, and Q3.
472 #*
473 sub ResamplingTypes {
474  return @RESAMPLING_TYPES;
475 }
476 
477 #** @method RmdirRecursive()
478 #*
479 sub RmdirRecursive {
480 }
481 
482 #** @method SetCacheMax($Bytes)
483 # Package subroutine.
484 # @param Bytes New maximum amount of memory for caching within GDAL.
485 #*
486 sub SetCacheMax {
487 }
488 
489 #** @method SetConfigOption($key, $value)
490 # Package subroutine.
491 # @param key A GDAL config option. Consult <a
492 # href="https://trac.osgeo.org/gdal/wiki/ConfigOptions">the GDAL
493 # documentation</a> for available options and their use.
494 # @param value A value for the option, typically 'YES', 'NO',
495 # undef, path, numeric value, or a filename.
496 #*
497 sub SetConfigOption {
498 }
499 
500 #** @method UseExceptions()
501 # Package subroutine.
502 # Use the Perl exception mechanism for GDAL messages (failures are
503 # confessed and warnings are warned) and collect the messages
504 # into \@Geo::GDAL::error. This is the default.
505 #*
506 sub UseExceptions {
507 }
508 
509 #** @method VSICurlClearCache()
510 #*
511 sub VSICurlClearCache {
512 }
513 
514 #** @method VSICurlPartialClearCache()
515 #*
516 sub VSICurlPartialClearCache {
517 }
518 
519 #** @method VSIErrorReset()
520 #*
521 sub VSIErrorReset {
522 }
523 
524 #** @method VSIFEofL()
525 #*
526 sub VSIFEofL {
527 }
528 
529 #** @method VSIFFlushL()
530 #*
531 sub VSIFFlushL {
532 }
533 
534 #** @method VSIFOpenExL()
535 #*
536 sub VSIFOpenExL {
537 }
538 
539 #** @method VSIGetLastErrorMsg()
540 #*
541 sub VSIGetLastErrorMsg {
542 }
543 
544 #** @method VSIGetLastErrorNo()
545 #*
546 sub VSIGetLastErrorNo {
547 }
548 
549 #** @method scalar VersionInfo($request = 'VERSION_NUM')
550 # Package subroutine.
551 # @param request A string specifying the request. Currently either
552 # "VERSION_NUM", "RELEASE_DATE", "RELEASE_NAME", or
553 # "--version". Default is "VERSION_NUM".
554 # @return Requested information.
555 #*
556 sub VersionInfo {
557 }
558 
559 #** @method scalar errstr()
560 # Package subroutine.
561 # Clear the error stack and return all generated GDAL error messages in one (possibly multiline) string.
562 # @return the chomped error stack joined with newlines.
563 #*
564 sub errstr {
565  my @stack = @error;
566  chomp(@stack);
567  @error = ();
568  return join("\n", @stack);
569 }
570 # usage: named_parameters(\@_, key value list of default parameters);
571 # returns parameters in a hash with low-case-without-_ keys
572 }
573 
574 #** @class Geo::GDAL::AsyncReader
575 # @brief Enable asynchronous requests.
576 # @details This class is not yet documented nor tested in the GDAL Perl wrappers
577 # @todo Test and document.
578 #*
579 package Geo::GDAL::AsyncReader;
580 
581 use base qw(Geo::GDAL)
582 
583 #** @method GetNextUpdatedRegion()
584 #*
585 sub GetNextUpdatedRegion {
586 }
587 
588 #** @method LockBuffer()
589 #*
590 sub LockBuffer {
591 }
592 
593 #** @method UnlockBuffer()
594 #*
595 sub UnlockBuffer {
596 }
597 
598 #** @class Geo::GDAL::Band
599 # @brief A raster band.
600 # @details
601 #*
602 package Geo::GDAL::Band;
603 
605 
606 #** @attr $XSize
607 # Object attribute.
608 # scalar (access as $band->{XSize})
609 #*
610 
611 #** @attr $YSize
612 # Object attribute.
613 # scalar (access as $band->{YSize})
614 #*
615 
616 #** @method AdviseRead()
617 #*
618 sub AdviseRead {
619 }
620 
621 #** @method Geo::GDAL::RasterAttributeTable AttributeTable($AttributeTable)
622 # Object method.
623 # @param AttributeTable [optional] A Geo::GDAL::RasterAttributeTable object.
624 # @return a new Geo::GDAL::RasterAttributeTable object, whose data is
625 # contained within the band.
626 #*
627 sub AttributeTable {
628  my $self = shift;
629  SetDefaultRAT($self, $_[0]) if @_ and defined $_[0];
630  return unless defined wantarray;
631  my $r = GetDefaultRAT($self);
632  keep($r, $self) if $r;
633 }
634 
635 #** @method list BlockSize()
636 # Object method.
637 # A.k.a GetBlockSize
638 # @return The size of a preferred i/o raster block size as a list
639 # (width, height).
640 #*
641 sub BlockSize {
642 }
643 
644 #** @method list CategoryNames(@names)
645 # Object method.
646 # @param names [optional]
647 # @return
648 #*
649 sub CategoryNames {
650  my $self = shift;
651  SetRasterCategoryNames($self, \@_) if @_;
652  return unless defined wantarray;
653  my $n = GetRasterCategoryNames($self);
654  return @$n;
655 }
656 
657 #** @method scalar Checksum($xoff = 0, $yoff = 0, $xsize = undef, $ysize = undef)
658 # Object method.
659 # Computes a checksum from the raster or a part of it.
660 # @param xoff
661 # @param yoff
662 # @param xsize
663 # @param ysize
664 # @return the checksum.
665 #*
666 sub Checksum {
667 }
668 
669 #** @method hashref ClassCounts($classifier, $progress = undef, $progress_data = undef)
670 # Object method.
671 # Compute the counts of cell values or number of cell values in ranges.
672 # @note Classifier is required only for float bands.
673 # @note NoData values are counted similar to other values when
674 # classifier is not defined for integer rasters.
675 #
676 # @param classifier Anonymous array of format [ $comparison,
677 # $classifier ], where $comparison is a string '<', '<=', '>', or '>='
678 # and $classifier is an anonymous array of format [ $value,
679 # $value|$classifier, $value|$classifier ], where $value is a numeric
680 # value against which the reclassified value is compared to. If the
681 # comparison returns true, then the second $value or $classifier is
682 # applied, and if not then the third $value or $classifier.
683 #
684 # In the example below, the line is divided into ranges
685 # [-inf..3), [3..5), and [5..inf], i.e., three ranges with class
686 # indexes 0, 1, and 2. Note that the indexes are used as keys for
687 # class counts and not the class values (here 1.0, 2.0, and 3.0),
688 # which are used in Geo::GDAL::Band::Reclassify.
689 # \code
690 # $classifier = [ '<', [5.0, [3.0, 1.0, 2.0], 3.0] ];
691 # # Howto create this $classifier from @class_boundaries:
692 # my $classifier = ['<='];
693 # my $tree = [$class_boundaries[0], 0, 1];
694 # for my $i (1 .. $#class_boundaries) {
695 # $tree = [$class_boundaries[$i], [@$tree], $i+1];
696 # }
697 # push @$classifier, $tree;
698 # \endcode
699 # @return a reference to an anonymous hash, which contains the class
700 # values (indexes) as keys and the number of cells with that value or
701 # in that range as values. If the subroutine is user terminated an
702 # error is raised.
703 #*
704 sub ClassCounts {
705 }
706 
707 #** @method scalar ColorInterpretation($color_interpretation)
708 # Object method.
709 # @note a.k.a. GetRasterColorInterpretation and GetColorInterpretation
710 # (get only and returns an integer), SetRasterColorInterpretation and
711 # SetColorInterpretation (set only and requires an integer)
712 # @param color_interpretation [optional] new color interpretation, one
713 # of Geo::GDAL::Band::ColorInterpretations.
714 # @return The color interpretation of this band. One of Geo::GDAL::Band::ColorInterpretations.
715 #*
716 sub ColorInterpretation {
717  my($self, $ci) = @_;
718  if (defined $ci) {
719  $ci = s2i(color_interpretation => $ci);
720  SetRasterColorInterpretation($self, $ci);
721  }
722  return unless defined wantarray;
723  i2s(color_interpretation => GetRasterColorInterpretation($self));
724 }
725 
726 #** @method ColorInterpretations()
727 # Package subroutine.
728 # @return a list of types of color interpretation for raster
729 # bands. These are currently:
730 # AlphaBand, BlackBand, BlueBand, CyanBand, GrayIndex, GreenBand, HueBand, LightnessBand, MagentaBand, PaletteIndex, RedBand, SaturationBand, Undefined, YCbCr_CbBand, YCbCr_CrBand, YCbCr_YBand, and YellowBand.
731 #*
732 sub ColorInterpretations {
733  return @COLOR_INTERPRETATIONS;
734 }
735 
736 #** @method Geo::GDAL::ColorTable ColorTable($ColorTable)
737 # Object method.
738 # Get or set the color table of this band.
739 # @param ColorTable [optional] a Geo::GDAL::ColorTable object
740 # @return A new Geo::GDAL::ColorTable object which represents the
741 # internal color table associated with this band. Returns undef this
742 # band does not have an associated color table.
743 #*
744 sub ColorTable {
745  my $self = shift;
746  SetRasterColorTable($self, $_[0]) if @_ and defined $_[0];
747  return unless defined wantarray;
748  GetRasterColorTable($self);
749 }
750 
751 #** @method ComputeBandStats($samplestep = 1)
752 # Object method.
753 # @param samplestep the row increment in computing the statistics.
754 # @note Returns uncorrected sample standard deviation.
755 #
756 # See also Geo::GDAL::Band::ComputeStatistics.
757 # @return a list (mean, stddev).
758 #*
759 sub ComputeBandStats {
760 }
761 
762 #** @method ComputeRasterMinMax($approx_ok = 0)
763 # Object method.
764 # @return arrayref MinMax = [min, max]
765 #*
766 sub ComputeRasterMinMax {
767 }
768 
769 #** @method list ComputeStatistics($approx_ok, $progress = undef, $progress_data = undef)
770 # Object method.
771 # @param approx_ok Whether it is allowed to compute the statistics
772 # based on overviews or similar.
773 # @note Returns uncorrected sample standard deviation.
774 #
775 # See also Geo::GDAL::Band::ComputeBandStats.
776 # @return a list ($min, $max, $mean, $stddev).
777 #*
778 sub ComputeStatistics {
779 }
780 
781 #** @method Geo::OGR::Layer Contours($DataSource, hashref LayerConstructor, $ContourInterval, $ContourBase, arrayref FixedLevels, $NoDataValue, $IDField, $ElevField, coderef Progress, $ProgressData)
782 # Object method.
783 # Generate contours for this raster band. This method can also be used with named parameters.
784 # @note This method is a wrapper for ContourGenerate.
785 #
786 # An example:
787 # \code
788 # use Geo::GDAL;
789 # $dem = Geo::GDAL::Open('dem.gtiff');
790 # $contours = $dem->Band->Contours(ContourInterval => 10, ElevField => 'z');
791 # $n = $contours->GetFeatureCount;
792 # \endcode
793 #
794 # @param DataSource a Geo::OGR::DataSource object, default is a Memory data source
795 # @param LayerConstructor data for Geo::OGR::DataSource::CreateLayer, default is {Name => 'contours'}
796 # @param ContourInterval default is 100
797 # @param ContourBase default is 0
798 # @param FixedLevels a reference to a list of fixed contour levels, default is []
799 # @param NoDataValue default is undef
800 # @param IDField default is '', i.e., no field (the field is created if this is given)
801 # @param ElevField default is '', i.e., no field (the field is created if this is given)
802 # @param progress [optional] a reference to a subroutine, which will
803 # be called with parameters (number progress, string msg, progress_data)
804 # @param progress_data [optional]
805 # @return
806 #*
807 sub Contours {
808  my $self = shift;
809  my $p = named_parameters(\@_,
810  DataSource => undef,
811  LayerConstructor => {Name => 'contours'},
812  ContourInterval => 100,
813  ContourBase => 0,
814  FixedLevels => [],
815  NoDataValue => undef,
816  IDField => -1,
817  ElevField => -1,
818  Progress => undef,
819  ProgressData => undef);
820  $p->{datasource} //= Geo::OGR::GetDriver('Memory')->CreateDataSource('ds');
821  $p->{layerconstructor}->{Schema} //= {};
822  $p->{layerconstructor}->{Schema}{Fields} //= [];
823  my %fields;
824  unless ($p->{idfield} =~ /^[+-]?\d+$/ or $fields{$p->{idfield}}) {
825  push @{$p->{layerconstructor}->{Schema}{Fields}}, {Name => $p->{idfield}, Type => 'Integer'};
826  }
827  unless ($p->{elevfield} =~ /^[+-]?\d+$/ or $fields{$p->{elevfield}}) {
828  my $type = $self->DataType() =~ /Float/ ? 'Real' : 'Integer';
829  push @{$p->{layerconstructor}->{Schema}{Fields}}, {Name => $p->{elevfield}, Type => $type};
830  }
831  my $layer = $p->{datasource}->CreateLayer($p->{layerconstructor});
832  my $schema = $layer->GetLayerDefn;
833  for ('idfield', 'elevfield') {
834  $p->{$_} = $schema->GetFieldIndex($p->{$_}) unless $p->{$_} =~ /^[+-]?\d+$/;
835  }
836  $p->{progressdata} = 1 if $p->{progress} and not defined $p->{progressdata};
837  ContourGenerate($self, $p->{contourinterval}, $p->{contourbase}, $p->{fixedlevels},
838  $p->{nodatavalue}, $layer, $p->{idfield}, $p->{elevfield},
839  $p->{progress}, $p->{progressdata});
840  return $layer;
841 }
842 
843 #** @method CreateMaskBand(@flags)
844 # Object method.
845 # @note May invalidate any previous mask band obtained with Geo::GDAL::Band::GetMaskBand.
846 #
847 # @param flags one or more mask flags. The flags are Geo::GDAL::Band::MaskFlags.
848 #*
849 sub CreateMaskBand {
850  my $self = shift;
851  my $f = 0;
852  if (@_ and $_[0] =~ /^\d$/) {
853  $f = shift;
854  } else {
855  for my $flag (@_) {
856  carp "Unknown mask flag: '$flag'." unless $MASK_FLAGS{$flag};
857  $f |= $MASK_FLAGS{$flag};
858  }
859  }
860  $self->_CreateMaskBand($f);
861 }
862 
863 #** @method scalar DataType()
864 # Object method.
865 # @return The data type of this band. One of Geo::GDAL::DataTypes.
866 #*
867 sub DataType {
868  my $self = shift;
869  return i2s(data_type => $self->{DataType});
870 }
871 
872 #** @method Geo::GDAL::Dataset Dataset()
873 # Object method.
874 # @return The dataset which this band belongs to.
875 #*
876 sub Dataset {
877  my $self = shift;
878  parent($self);
879 }
880 
881 #** @method scalar DeleteNoDataValue()
882 # Object method.
883 #*
884 sub DeleteNoDataValue {
885 }
886 
887 #** @method Geo::GDAL::Band Distance(%params)
888 # Object method.
889 # Compute distances to specific cells of this raster.
890 # @param params Named parameters:
891 # - \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.
892 # - \a Options Hash of options. Options are:
893 # - \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.
894 # - \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.
895 # - \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.
896 # - \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).
897 # - \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.
898 # - \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.
899 # - \a DataType The data type for the result if it is not given.
900 # - \a Progress Progress function.
901 # - \a ProgressData Additional parameter for the progress function.
902 #
903 # @note This GDAL function behind this API is called GDALComputeProximity.
904 #
905 # @return The distance raster.
906 #*
907 sub Distance {
908  my $self = shift;
909  my $p = named_parameters(\@_, Distance => undef, Options => undef, Progress => undef, ProgressData => undef);
910  for my $key (keys %{$p->{options}}) {
911  $p->{options}{uc($key)} = $p->{options}{$key};
912  }
913  $p->{options}{TYPE} //= $p->{options}{DATATYPE} //= 'Float32';
914  unless ($p->{distance}) {
915  my ($w, $h) = $self->Size;
916  $p->{distance} = Geo::GDAL::Driver('MEM')->Create(Name => 'distance', Width => $w, Height => $h, Type => $p->{options}{TYPE})->Band;
917  }
918  Geo::GDAL::ComputeProximity($self, $p->{distance}, $p->{options}, $p->{progress}, $p->{progressdata});
919  return $p->{distance};
920 }
921 
922 #** @method Domains()
923 #*
924 sub Domains {
925  return @DOMAINS;
926 }
927 
928 #** @method Fill($real_part, $imag_part = 0.0)
929 # Object method.
930 # Fill the band with a constant value.
931 # @param real_part Real component of fill value.
932 # @param imag_part Imaginary component of fill value.
933 #
934 #*
935 sub Fill {
936 }
937 
938 #** @method FillNoData($mask, $max_search_dist, $smoothing_iterations, $options, coderef progress, $progress_data)
939 # Object method.
940 # Interpolate values for cells in this raster. The cells to fill
941 # should be marked in the mask band with zero.
942 #
943 # @param mask [optional] a mask band indicating cells to be interpolated (zero valued) (default is to get it with Geo::GDAL::Band::GetMaskBand).
944 # @param max_search_dist [optional] the maximum number of cells to
945 # search in all directions to find values to interpolate from (default is 10).
946 # @param smoothing_iterations [optional] the number of 3x3 smoothing filter passes to run (0 or more) (default is 0).
947 # @param options [optional] A reference to a hash. No options have been defined so far for this algorithm (default is {}).
948 # @param progress [optional] a reference to a subroutine, which will
949 # be called with parameters (number progress, string msg, progress_data) (default is undef).
950 # @param progress_data [optional] (default is undef).
951 #
952 # <a href="http://www.gdal.org/gdal__alg_8h.html">Documentation for GDAL algorithms</a>
953 #*
954 sub FillNoData {
955 }
956 
957 #** @method FlushCache()
958 # Object method.
959 # Write cached data to disk. There is usually no need to call this
960 # method.
961 #*
962 sub FlushCache {
963 }
964 
965 #** @method scalar GetBandNumber()
966 # Object method.
967 # @return The index of this band in the parent dataset list of bands.
968 #*
969 sub GetBandNumber {
970 }
971 
972 #** @method GetBlockSize()
973 #*
974 sub GetBlockSize {
975 }
976 
977 #** @method list GetDefaultHistogram($force = 1, coderef progress = undef, $progress_data = undef)
978 # Object method.
979 # @param force true to force the computation
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]
983 # @note See Note in Geo::GDAL::Band::GetHistogram.
984 # @return a list: ($min, $max, arrayref histogram).
985 #*
986 sub GetDefaultHistogram {
987 }
988 
989 #** @method list GetHistogram(%parameters)
990 # Object method.
991 # Compute histogram from the raster.
992 # @param parameters Named parameters:
993 # - \a Min the lower bound, default is -0.5
994 # - \a Max the upper bound, default is 255.5
995 # - \a Buckets the number of buckets in the histogram, default is 256
996 # - \a IncludeOutOfRange whether to use the first and last values in the returned list
997 # for out of range values, default is false;
998 # the bucket size is (Max-Min) / Buckets if this is false and
999 # (Max-Min) / (Buckets-2) if this is true
1000 # - \a ApproxOK if histogram can be computed from overviews, default is false
1001 # - \a Progress an optional progress function, the default is undef
1002 # - \a ProgressData data for the progress function, the default is undef
1003 # @note Histogram counts are treated as strings in the bindings to be
1004 # able to use large integers (if GUIntBig is larger than Perl IV). In
1005 # practice this is only important if you have a 32 bit machine and
1006 # very large bucket counts. In those cases it may also be necessary to
1007 # use Math::BigInt.
1008 # @return a list which contains the count of values in each bucket
1009 #*
1010 sub GetHistogram {
1011  my $self = shift;
1012  my $p = named_parameters(\@_,
1013  Min => -0.5,
1014  Max => 255.5,
1015  Buckets => 256,
1016  IncludeOutOfRange => 0,
1017  ApproxOK => 0,
1018  Progress => undef,
1019  ProgressData => undef);
1020  $p->{progressdata} = 1 if $p->{progress} and not defined $p->{progressdata};
1021  _GetHistogram($self, $p->{min}, $p->{max}, $p->{buckets},
1022  $p->{includeoutofrange}, $p->{approxok},
1023  $p->{progress}, $p->{progressdata});
1024 }
1025 
1026 #** @method Geo::GDAL::Band GetMaskBand()
1027 # Object method.
1028 # @return the mask band associated with this
1029 # band.
1030 #*
1031 sub GetMaskBand {
1032  my $self = shift;
1033  my $band = _GetMaskBand($self);
1034  keep($band, $self);
1035 }
1036 
1037 #** @method list GetMaskFlags()
1038 # Object method.
1039 # @return the mask flags of the mask band associated with this
1040 # band. The flags are one or more of Geo::GDAL::Band::MaskFlags.
1041 #*
1042 sub GetMaskFlags {
1043  my $self = shift;
1044  my $f = $self->_GetMaskFlags;
1045  my @f;
1046  for my $flag (keys %MASK_FLAGS) {
1047  push @f, $flag if $f & $MASK_FLAGS{$flag};
1048  }
1049  return wantarray ? @f : $f;
1050 }
1051 
1052 #** @method scalar GetMaximum()
1053 # Object method.
1054 # @note Call Geo::GDAL::Band::ComputeStatistics before calling
1055 # GetMaximum to make sure the value is computed.
1056 #
1057 # @return statistical minimum of the band or undef if statistics are
1058 # not kept or computed in scalar context. In list context returns the
1059 # maximum value or a (kind of) maximum value supported by the data
1060 # type and a boolean value, which indicates which is the case (true is
1061 # first, false is second).
1062 #*
1063 sub GetMaximum {
1064 }
1065 
1066 #** @method scalar GetMinimum()
1067 # Object method.
1068 # @note Call Geo::GDAL::Band::ComputeStatistics before calling
1069 # GetMinimum to make sure the value is computed.
1070 #
1071 # @return statistical minimum of the band or undef if statistics are
1072 # not kept or computed in scalar context. In list context returns the
1073 # minimum value or a (kind of) minimum value supported by the data
1074 # type and a boolean value, which indicates which is the case (true is
1075 # first, false is second).
1076 #*
1077 sub GetMinimum {
1078 }
1079 
1080 #** @method Geo::GDAL::Band GetOverview($index)
1081 # Object method.
1082 # @param index 0..GetOverviewCount-1
1083 # @return a Geo::GDAL::Band object, which represents the internal
1084 # overview band, or undef. if the index is out of bounds.
1085 #*
1086 sub GetOverview {
1087  my ($self, $index) = @_;
1088  my $band = _GetOverview($self, $index);
1089  keep($band, $self);
1090 }
1091 
1092 #** @method scalar GetOverviewCount()
1093 # Object method.
1094 # @return the number of overviews available of the band.
1095 #*
1096 sub GetOverviewCount {
1097 }
1098 
1099 #** @method list GetStatistics($approx_ok, $force)
1100 # Object method.
1101 # @param approx_ok Whether it is allowed to compute the statistics
1102 # based on overviews or similar.
1103 # @param force Whether to force scanning of the whole raster.
1104 # @note Uses Geo::GDAL::Band::ComputeStatistics internally.
1105 #
1106 # @return a list ($min, $max, $mean, $stddev).
1107 #*
1108 sub GetStatistics {
1109 }
1110 
1111 #** @method HasArbitraryOverviews()
1112 # Object method.
1113 # @return true or false.
1114 #*
1115 sub HasArbitraryOverviews {
1116 }
1117 
1118 #** @method list MaskFlags()
1119 # Package subroutine.
1120 # @return the list of mask flags. These are
1121 # - \a AllValid: There are no invalid cell, all mask values will be 255.
1122 # When used this will normally be the only flag set.
1123 # - \a PerDataset: The mask band is shared between all bands on the dataset.
1124 # - \a Alpha: The mask band is actually an alpha band and may have values
1125 # other than 0 and 255.
1126 # - \a NoData: Indicates the mask is actually being generated from NoData values.
1127 # (mutually exclusive of Alpha).
1128 #*
1129 sub MaskFlags {
1130  my @f = sort {$MASK_FLAGS{$a} <=> $MASK_FLAGS{$b}} keys %MASK_FLAGS;
1131  return @f;
1132 }
1133 
1134 #** @method scalar NoDataValue($NoDataValue)
1135 # Object method.
1136 # Get or set the "no data" value.
1137 # @param NoDataValue [optional]
1138 # @note $band->NoDataValue(undef) sets the NoData value to the
1139 # Posix floating point maximum. Use Geo::GDAL::Band::DeleteNoDataValue
1140 # to stop this band using a NoData value.
1141 # @return The NoData value or undef in scalar context. An undef
1142 # value indicates that there is no NoData value associated with this
1143 # band.
1144 #*
1145 sub NoDataValue {
1146  my $self = shift;
1147  if (@_ > 0) {
1148  if (defined $_[0]) {
1149  SetNoDataValue($self, $_[0]);
1150  } else {
1151  SetNoDataValue($self, POSIX::FLT_MAX); # hopefully an "out of range" value
1152  }
1153  }
1154  GetNoDataValue($self);
1155 }
1156 
1157 #** @method scalar PackCharacter()
1158 # Object method.
1159 # @return The character to use in Perl pack and unpack for the data of this band.
1160 #*
1161 sub PackCharacter {
1162  my $self = shift;
1163  return Geo::GDAL::PackCharacter($self->DataType);
1164 }
1165 
1166 #** @method Piddle($piddle, $xoff = 0, $yoff = 0, $xsize = <width>, $ysize = <height>, $xdim, $ydim)
1167 # Object method.
1168 # Read or write band data from/into a piddle.
1169 #
1170 # \note The PDL module must be available for this method to work. Also, you
1171 # should 'use PDL' in the code that you use this method.
1172 #
1173 # @param piddle [only when writing] The piddle from which to read the data to be written into the band.
1174 # @param xoff, yoff The offset for data in the band, default is top left (0, 0).
1175 # @param xsize, ysize [optional] The size of the window in the band.
1176 # @param xdim, ydim [optional, only when reading from a band] The size of the piddle to create.
1177 # @return A new piddle when reading from a band (no not use when writing into a band).
1178 #*
1179 sub Piddle {
1180  # TODO: add Piddle sub to dataset too to make Width x Height x Bands piddles
1181  error("PDL is not available.") unless $Geo::GDAL::HAVE_PDL;
1182  my $self = shift;
1183  my $t = $self->{DataType};
1184  unless (defined wantarray) {
1185  my $pdl = shift;
1186  error("The datatype of the Piddle and the band do not match.")
1187  unless $PDL2DATATYPE{$pdl->get_datatype} == $t;
1188  my ($xoff, $yoff, $xsize, $ysize) = @_;
1189  $xoff //= 0;
1190  $yoff //= 0;
1191  my $data = $pdl->get_dataref();
1192  my ($xdim, $ydim) = $pdl->dims();
1193  if ($xdim > $self->{XSize} - $xoff) {
1194  warn "Piddle XSize too large ($xdim) for this raster band (width = $self->{XSize}, offset = $xoff).";
1195  $xdim = $self->{XSize} - $xoff;
1196  }
1197  if ($ydim > $self->{YSize} - $yoff) {
1198  $ydim = $self->{YSize} - $yoff;
1199  warn "Piddle YSize too large ($ydim) for this raster band (height = $self->{YSize}, offset = $yoff).";
1200  }
1201  $xsize //= $xdim;
1202  $ysize //= $ydim;
1203  $self->_WriteRaster($xoff, $yoff, $xsize, $ysize, $data, $xdim, $ydim, $t, 0, 0);
1204  return;
1205  }
1206  my ($xoff, $yoff, $xsize, $ysize, $xdim, $ydim, $alg) = @_;
1207  $xoff //= 0;
1208  $yoff //= 0;
1209  $xsize //= $self->{XSize} - $xoff;
1210  $ysize //= $self->{YSize} - $yoff;
1211  $xdim //= $xsize;
1212  $ydim //= $ysize;
1213  $alg //= 'NearestNeighbour';
1214  $alg = s2i(rio_resampling => $alg);
1215  my $buf = $self->_ReadRaster($xoff, $yoff, $xsize, $ysize, $xdim, $ydim, $t, 0, 0, $alg);
1216  my $pdl = PDL->new;
1217  my $datatype = $DATATYPE2PDL{$t};
1218  error("The band datatype is not supported by PDL.") if $datatype < 0;
1219  $pdl->set_datatype($datatype);
1220  $pdl->setdims([$xdim, $ydim]);
1221  my $data = $pdl->get_dataref();
1222  $$data = $buf;
1223  $pdl->upd_data;
1224  # FIXME: we want approximate equality since no data value can be very large floating point value
1225  my $bad = GetNoDataValue($self);
1226  return $pdl->setbadif($pdl == $bad) if defined $bad;
1227  return $pdl;
1228 }
1229 
1230 #** @method Geo::OGR::Layer Polygonize(%params)
1231 # Object method.
1232 # Polygonize this raster band.
1233 #
1234 # @param params Named parameters:
1235 # - \a Mask A raster band, which is used as a mask to select polygonized areas. Default is undef.
1236 # - \a OutLayer A vector layer into which the polygons are written. If not given, an in-memory layer 'polygonized' is created and returned.
1237 # - \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'.
1238 # - \a Options Hash or list of options. Connectedness can be set to 8
1239 # to use 8-connectedness, otherwise 4-connectedness is
1240 # used. ForceIntPixel can be set to 1 to force using a 32 bit int buffer
1241 # for cell values in the process. If this is not set and the data type
1242 # of this raster does not fit into a 32 bit int buffer, a 32 bit float
1243 # buffer is used.
1244 # - \a Progress Progress function.
1245 # - \a ProgressData Additional parameter for the progress function.
1246 #
1247 # @return Output vector layer.
1248 #*
1249 sub Polygonize {
1250  my $self = shift;
1251  my $p = named_parameters(\@_, Mask => undef, OutLayer => undef, PixValField => 'val', Options => undef, Progress => undef, ProgressData => undef);
1252  my %known_options = (Connectedness => 1, ForceIntPixel => 1, DATASET_FOR_GEOREF => 1, '8CONNECTED' => 1);
1253  for my $option (keys %{$p->{options}}) {
1254  error(1, $option, \%known_options) unless exists $known_options{$option};
1255  }
1256  my $dt = $self->DataType;
1257  my %leInt32 = (Byte => 1, Int16 => 1, Int32 => 1, UInt16 => 1);
1258  my $leInt32 = $leInt32{$dt};
1259  $dt = $dt =~ /Float/ ? 'Real' : 'Integer';
1260  $p->{outlayer} //= Geo::OGR::Driver('Memory')->Create()->
1261  CreateLayer(Name => 'polygonized',
1262  Fields => [{Name => 'val', Type => $dt},
1263  {Name => 'geom', Type => 'Polygon'}]);
1264  $p->{pixvalfield} = $p->{outlayer}->GetLayerDefn->GetFieldIndex($p->{pixvalfield});
1265  $p->{options}{'8CONNECTED'} = 1 if $p->{options}{Connectedness} && $p->{options}{Connectedness} == 8;
1266  if ($leInt32 || $p->{options}{ForceIntPixel}) {
1267  Geo::GDAL::_Polygonize($self, $p->{mask}, $p->{outlayer}, $p->{pixvalfield}, $p->{options}, $p->{progress}, $p->{progressdata});
1268  } else {
1269  Geo::GDAL::FPolygonize($self, $p->{mask}, $p->{outlayer}, $p->{pixvalfield}, $p->{options}, $p->{progress}, $p->{progressdata});
1270  }
1271  set the srs of the outlayer if it was created here
1272  return $p->{outlayer};
1273 }
1274 
1275 #** @method RasterAttributeTable()
1276 #*
1278 }
1279 
1280 #** @method scalar ReadRaster(%params)
1281 # Object method.
1282 # Read data from the band.
1283 #
1284 # @param params Named parameters:
1285 # - \a XOff x offset (cell coordinates) (default is 0)
1286 # - \a YOff y offset (cell coordinates) (default is 0)
1287 # - \a XSize width of the area to read (default is the width of the band)
1288 # - \a YSize height of the area to read (default is the height of the band)
1289 # - \a BufXSize (default is undef, i.e., the same as XSize)
1290 # - \a BufYSize (default is undef, i.e., the same as YSize)
1291 # - \a BufType data type of the buffer (default is the data type of the band)
1292 # - \a BufPixelSpace (default is 0)
1293 # - \a BufLineSpace (default is 0)
1294 # - \a ResampleAlg one of Geo::GDAL::RIOResamplingTypes (default is 'NearestNeighbour'),
1295 # - \a Progress reference to a progress function (default is undef)
1296 # - \a ProgressData (default is undef)
1297 #
1298 # <a href="http://www.gdal.org/classGDALDataset.html">Entry in GDAL docs (method RasterIO)</a>
1299 # @return a buffer, open the buffer with \a unpack function of Perl. See Geo::GDAL::Band::PackCharacter.
1300 #*
1301 sub ReadRaster {
1302  my $self = shift;
1303  my ($width, $height) = $self->Size;
1304  my ($type) = $self->DataType;
1305  my $p = named_parameters(\@_,
1306  XOff => 0,
1307  YOff => 0,
1308  XSize => $width,
1309  YSize => $height,
1310  BufXSize => undef,
1311  BufYSize => undef,
1312  BufType => $type,
1313  BufPixelSpace => 0,
1314  BufLineSpace => 0,
1315  ResampleAlg => 'NearestNeighbour',
1316  Progress => undef,
1317  ProgressData => undef
1318  );
1319  $p->{resamplealg} = s2i(rio_resampling => $p->{resamplealg});
1320  $p->{buftype} = s2i(data_type => $p->{buftype}, 1);
1321  $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});
1322 }
1323 
1324 #** @method array reference ReadTile($xoff = 0, $yoff = 0, $xsize = <width>, $ysize = <height>)
1325 # Object method.
1326 # Read band data into a Perl array.
1327 #
1328 # \note Accessing band data in this way is slow. Consider using PDL and Geo::GDAL::Band::Piddle.
1329 #
1330 # Usage example (print the data from a band):
1331 # \code
1332 # print "@$_\n" for ( @{ $band->ReadTile() } );
1333 # \endcode
1334 # Another usage example (process the data of a large dataset that has one band):
1335 # \code
1336 # my($W,$H) = $dataset->Band()->Size();
1337 # my($xoff,$yoff,$w,$h) = (0,0,200,200);
1338 # while (1) {
1339 # if ($xoff >= $W) {
1340 # $xoff = 0;
1341 # $yoff += $h;
1342 # last if $yoff >= $H;
1343 # }
1344 # my $data = $dataset->Band(1)->ReadTile($xoff,$yoff,min($W-$xoff,$w),min($H-$yoff,$h));
1345 # # add your data processing code here
1346 # $dataset->Band(1)->WriteTile($data,$xoff,$yoff);
1347 # $xoff += $w;
1348 # }
1349 #
1350 # sub min {
1351 # return $_[0] < $_[1] ? $_[0] : $_[1];
1352 # }
1353 # \endcode
1354 # @param xoff Number of cell to skip before starting to read from a row. Pixels are read from left to right.
1355 # @param yoff Number of cells to skip before starting to read from a column. Pixels are read from top to bottom.
1356 # @param xsize Number of cells to read from each row.
1357 # @param ysize Number of cells to read from each column.
1358 # @return a two-dimensional Perl array, organizes as data->[y][x], y =
1359 # 0..height-1, x = 0..width-1. I.e., y is row and x is column.
1360 #*
1361 sub ReadTile {
1362  my($self, $xoff, $yoff, $xsize, $ysize, $w_tile, $h_tile, $alg) = @_;
1363  $xoff //= 0;
1364  $yoff //= 0;
1365  $xsize //= $self->{XSize} - $xoff;
1366  $ysize //= $self->{YSize} - $yoff;
1367  $w_tile //= $xsize;
1368  $h_tile //= $ysize;
1369  $alg //= 'NearestNeighbour';
1370  $alg = s2i(rio_resampling => $alg);
1371  my $t = $self->{DataType};
1372  my $buf = $self->_ReadRaster($xoff, $yoff, $xsize, $ysize, $w_tile, $h_tile, $t, 0, 0, $alg);
1373  my $pc = Geo::GDAL::PackCharacter($t);
1374  my $w = $w_tile * Geo::GDAL::GetDataTypeSize($t)/8;
1375  my $offset = 0;
1376  my @data;
1377  for my $y (0..$h_tile-1) {
1378  my @d = unpack($pc."[$w_tile]", substr($buf, $offset, $w));
1379  push @data, \@d;
1380  $offset += $w;
1381  }
1382  return \@data;
1383 }
1384 
1385 #** @method Reclassify($classifier, $progress = undef, $progress_data = undef)
1386 # Object method.
1387 # Reclassify the cells in the band.
1388 # @note NoData values in integer rasters are reclassified if
1389 # explicitly specified in the hash classifier. However, they are not
1390 # reclassified to the default value, if one is specified. In real
1391 # valued rasters nodata cells are not reclassified.
1392 # @note If the subroutine is user terminated or the classifier is
1393 # incorrect, already reclassified cells will stay reclassified but an
1394 # error is raised.
1395 # @param classifier For integer rasters an anonymous hash, which
1396 # contains old class values as keys and new class values as values, or
1397 # an array classifier as in Geo::GDAL::Band::ClassCounts. In a hash
1398 # classifier a special key '*' (star) can be used as default, to act
1399 # as a fallback new class value. For real valued rasters the
1400 # classifier is as in Geo::GDAL::Band::ClassCounts.
1401 #*
1402 sub Reclassify {
1403 }
1404 
1405 #** @method RegenerateOverview(Geo::GDAL::Band overview, $resampling, coderef progress, $progress_data)
1406 # Object method.
1407 # @param overview a Geo::GDAL::Band object for the overview.
1408 # @param resampling [optional] the resampling method (one of Geo::GDAL::RIOResamplingTypes) (default is Average).
1409 # @param progress [optional] a reference to a subroutine, which will
1410 # be called with parameters (number progress, string msg, progress_data)
1411 # @param progress_data [optional]
1412 #*
1413 sub RegenerateOverview {
1414  my $self = shift;
1415  #Geo::GDAL::Band overview, scalar resampling, subref callback, scalar callback_data
1416  my @p = @_;
1417  Geo::GDAL::RegenerateOverview($self, @p);
1418 }
1419 
1420 #** @method RegenerateOverviews(arrayref overviews, $resampling, coderef progress, $progress_data)
1421 # Object method.
1422 # @todo This is not yet available
1423 #
1424 # @param overviews a list of Geo::GDAL::Band objects for the overviews.
1425 # @param resampling [optional] the resampling method (one of Geo::GDAL::RIOResamplingTypes) (default is Average).
1426 # @param progress [optional] a reference to a subroutine, which will
1427 # be called with parameters (number progress, string msg, progress_data)
1428 # @param progress_data [optional]
1429 #*
1430 sub RegenerateOverviews {
1431  my $self = shift;
1432  #arrayref overviews, scalar resampling, subref callback, scalar callback_data
1433  my @p = @_;
1434  Geo::GDAL::RegenerateOverviews($self, @p);
1435 }
1436 
1437 #** @method ScaleAndOffset($scale, $offset)
1438 # Object method.
1439 # Scale and offset are used to transform raw cell values into the
1440 # units returned by GetUnits(). The conversion function is:
1441 # \code
1442 # Units value = (raw value * scale) + offset
1443 # \endcode
1444 # @return a list ($scale, $offset), the values are undefined if they
1445 # are not set.
1446 # @since version 1.9 of the bindings.
1447 #*
1448 sub ScaleAndOffset {
1449  my $self = shift;
1450  SetScale($self, $_[0]) if @_ > 0 and defined $_[0];
1451  SetOffset($self, $_[1]) if @_ > 1 and defined $_[1];
1452  return unless defined wantarray;
1453  my $scale = GetScale($self);
1454  my $offset = GetOffset($self);
1455  return ($scale, $offset);
1456 }
1457 
1458 #** @method list SetDefaultHistogram($min, $max, $histogram)
1459 # Object method.
1460 # @param min
1461 # @param max
1462 # @note See Note in Geo::GDAL::Band::GetHistogram.
1463 # @param histogram reference to an array containing the histogram
1464 #*
1465 sub SetDefaultHistogram {
1467 
1468 #** @method SetStatistics($min, $max, $mean, $stddev)
1469 # Object method.
1470 # Save the statistics of the band if possible (the format can save
1471 # arbitrary metadata).
1472 # @param min
1473 # @param max
1474 # @param mean
1475 # @param stddev
1476 #*
1477 sub SetStatistics {
1478 }
1479 
1480 #** @method Geo::GDAL::Band Sieve(%params)
1481 # Object method.
1482 # Remove small areas by merging them into the largest neighbour area.
1483 # @param params Named parameters:
1484 # - \a Mask A raster band, which is used as a mask to select sieved areas. Default is undef.
1485 # - \a Dest A raster band into which the result is written. If not given, an new in-memory raster band is created and returned.
1486 # - \a Threshold The smallest area size (in number of cells) which are not sieved away.
1487 # - \a Options Hash or list of options. {Connectedness => 4} can be specified to use 4-connectedness, otherwise 8-connectedness is used.
1488 # - \a Progress Progress function.
1489 # - \a ProgressData Additional parameter for the progress function.
1490 #
1491 # @return The filtered raster band.
1492 #*
1493 sub Sieve {
1494  my $self = shift;
1495  my $p = named_parameters(\@_, Mask => undef, Dest => undef, Threshold => 10, Options => undef, Progress => undef, ProgressData => undef);
1496  unless ($p->{dest}) {
1497  my ($w, $h) = $self->Size;
1498  $p->{dest} = Geo::GDAL::Driver('MEM')->Create(Name => 'sieved', Width => $w, Height => $h, Type => $self->DataType)->Band;
1499  }
1500  my $c = 8;
1501  if ($p->{options}{Connectedness}) {
1502  $c = $p->{options}{Connectedness};
1503  delete $p->{options}{Connectedness};
1504  }
1505  Geo::GDAL::SieveFilter($self, $p->{mask}, $p->{dest}, $p->{threshold}, $c, $p->{options}, $p->{progress}, $p->{progressdata});
1506  return $p->{dest};
1507 }
1508 
1509 #** @method list Size()
1510 # Object method.
1511 # @return The size of the band as a list (width, height).
1512 #*
1513 sub Size {
1514  my $self = shift;
1515  return ($self->{XSize}, $self->{YSize});
1516 }
1517 
1518 #** @method Unit($type)
1519 # Object method.
1520 # @param type [optional] the unit (a string).
1521 # @note $band->Unit(undef) sets the unit value to an empty string.
1522 # @return the unit (a string).
1523 # @since version 1.9 of the bindings.
1524 #*
1525 sub Unit {
1526  my $self = shift;
1527  if (@_ > 0) {
1528  my $unit = shift;
1529  $unit //= '';
1530  SetUnitType($self, $unit);
1531  }
1532  return unless defined wantarray;
1533  GetUnitType($self);
1534 }
1535 
1536 #** @method WriteRaster(%params)
1537 # Object method.
1538 # Write data into the band.
1539 #
1540 # @param params Named parameters:
1541 # - \a XOff x offset (cell coordinates) (default is 0)
1542 # - \a YOff y offset (cell coordinates) (default is 0)
1543 # - \a XSize width of the area to write (default is the width of the band)
1544 # - \a YSize height of the area to write (default is the height of the band)
1545 # - \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.
1546 # - \a BufXSize (default is undef, i.e., the same as XSize)
1547 # - \a BufYSize (default is undef, i.e., the same as YSize)
1548 # - \a BufType data type of the buffer (default is the data type of the band)
1549 # - \a BufPixelSpace (default is 0)
1550 # - \a BufLineSpace (default is 0)
1551 #
1552 # <a href="http://www.gdal.org/classGDALDataset.html">Entry in GDAL docs (method RasterIO)</a>
1553 #*
1554 sub WriteRaster {
1555  my $self = shift;
1556  my ($width, $height) = $self->Size;
1557  my ($type) = $self->DataType;
1558  my $p = named_parameters(\@_,
1559  XOff => 0,
1560  YOff => 0,
1561  XSize => $width,
1562  YSize => $height,
1563  Buf => undef,
1564  BufXSize => undef,
1565  BufYSize => undef,
1566  BufType => $type,
1567  BufPixelSpace => 0,
1568  BufLineSpace => 0
1569  );
1570  confess "Usage: \$band->WriteRaster( Buf => \$data, ... )" unless defined $p->{buf};
1571  $p->{buftype} = s2i(data_type => $p->{buftype}, 1);
1572  $self->_WriteRaster($p->{xoff},$p->{yoff},$p->{xsize},$p->{ysize},$p->{buf},$p->{bufxsize},$p->{bufysize},$p->{buftype},$p->{bufpixelspace},$p->{buflinespace});
1573 }
1574 
1575 #** @method WriteTile($data, $xoff = 0, $yoff = 0)
1576 # Object method.
1577 # Write band data from a Perl array.
1578 #
1579 # \note Accessing band data in this way is slow. Consider using PDL and Geo::GDAL::Band::Piddle.
1580 #
1581 # @param data A two-dimensional Perl array, organizes as data->[y][x], y =
1582 # 0..height-1, x = 0..width-1.
1583 # @param xoff
1584 # @param yoff
1585 #
1586 #*
1587 sub WriteTile {
1588  my($self, $data, $xoff, $yoff) = @_;
1589  $xoff //= 0;
1590  $yoff //= 0;
1591  error('The data must be in a two-dimensional array') unless ref $data eq 'ARRAY' && ref $data->[0] eq 'ARRAY';
1592  my $xsize = @{$data->[0]};
1593  if ($xsize > $self->{XSize} - $xoff) {
1594  warn "Buffer XSize too large ($xsize) for this raster band (width = $self->{XSize}, offset = $xoff).";
1595  $xsize = $self->{XSize} - $xoff;
1596  }
1597  my $ysize = @{$data};
1598  if ($ysize > $self->{YSize} - $yoff) {
1599  $ysize = $self->{YSize} - $yoff;
1600  warn "Buffer YSize too large ($ysize) for this raster band (height = $self->{YSize}, offset = $yoff).";
1601  }
1602  my $pc = Geo::GDAL::PackCharacter($self->{DataType});
1603  for my $i (0..$ysize-1) {
1604  my $scanline = pack($pc."[$xsize]", @{$data->[$i]});
1605  $self->WriteRaster( $xoff, $yoff+$i, $xsize, 1, $scanline );
1606  }
1607 }
1608 
1609 #** @class Geo::GDAL::ColorTable
1610 # @brief A color table from a raster band or a color table, which can be used for a band.
1611 # @details
1612 #*
1613 package Geo::GDAL::ColorTable;
1614 
1615 use base qw(Geo::GDAL)
1616 
1617 #** @method Geo::GDAL::ColorTable Clone()
1618 # Object method.
1619 # Clone an existing color table.
1620 # @return a new Geo::GDAL::ColorTable object
1621 #*
1622 sub Clone {
1623 }
1624 
1625 #** @method list Color($index, @color)
1626 # Object method.
1627 # Get or set a color in this color table.
1628 # @param index The index of the color in the table. Note that the
1629 # color table may expand if the index is larger than the current max
1630 # index of this table and a color is given. An attempt to retrieve a
1631 # color out of the current size of the table causes an error.
1632 # @param color [optional] The color, either a list or a reference to a
1633 # list. If the list is too short or has undef values, the undef values
1634 # are taken as 0 except for alpha, which is taken as 255.
1635 # @note A color is an array of four integers having a value between 0
1636 # and 255: (gray, red, cyan or hue; green, magenta, or lightness;
1637 # blue, yellow, or saturation; alpha or blackband)
1638 # @return A color, in list context a list and in scalar context a reference to an anonymous array.
1639 #*
1640 sub Color {
1641 }
1642 
1643 #** @method list Colors(@colors)
1644 # Object method.
1645 # Get or set the colors in this color table.
1646 # @note The color table will expand to the size of the input list but
1647 # it will not shrink.
1648 # @param colors [optional] A list of all colors (a list of lists) for this color table.
1649 # @return A list of colors (a list of lists).
1650 #*
1651 sub Colors {
1652 }
1653 
1654 #** @method CreateColorRamp($start_index, arrayref start_color, $end_index, arrayref end_color)
1655 # Object method.
1656 # @param start_index
1657 # @param start_color
1658 # @param end_index
1659 # @param end_color
1660 #*
1661 sub CreateColorRamp {
1662 }
1663 
1664 #** @method scalar GetCount()
1665 # Object method.
1666 # @return The number of colors in this color table.
1667 #*
1668 sub GetCount {
1669 }
1670 
1671 #** @method scalar GetPaletteInterpretation()
1672 # Object method.
1673 # @return palette interpretation (string)
1674 #*
1675 sub GetPaletteInterpretation {
1676  my $self = shift;
1677  return i2s(palette_interpretation => GetPaletteInterpretation($self));
1678 }
1679 
1680 #** @method Geo::GDAL::ColorTable new($GDALPaletteInterp = 'RGB')
1681 # Class method.
1682 # Create a new empty color table.
1683 # @return a new Geo::GDAL::ColorTable object
1684 #*
1685 sub new {
1686  my($pkg, $pi) = @_;
1687  $pi //= 'RGB';
1688  $pi = s2i(palette_interpretation => $pi);
1689  my $self = Geo::GDALc::new_ColorTable($pi);
1690  bless $self, $pkg if defined($self);
1691 }
1692 
1693 #** @class Geo::GDAL::Dataset
1694 # @brief A set of associated raster bands or vector layer source.
1695 # @details
1696 #*
1697 package Geo::GDAL::Dataset;
1698 
1699 use base qw(Geo::GDAL::MajorObject Geo::GDAL)
1700 
1701 #** @attr $RasterCount
1702 # scalar (access as $dataset->{RasterCount})
1703 #*
1704 
1705 #** @attr $RasterXSize
1706 # scalar (access as $dataset->{RasterXSize})
1707 #*
1708 
1709 #** @attr $RasterYSize
1710 # scalar (access as $dataset->{RasterYSize})
1711 #*
1712 
1713 #** @method AddBand($datatype = 'Byte', hashref options = {})
1714 # Object method.
1715 # Add a new band to the dataset. The driver must support the action.
1716 # @param datatype GDAL raster cell data type (one of those listed by Geo::GDAL::DataTypes).
1717 # @param options reference to a hash of format specific options.
1718 # @return The added band.
1719 #*
1720 sub AddBand {
1721  my ($self, $type, $options) = @_;
1722  $type //= 'Byte';
1723  $type = s2i(data_type => $type);
1724  $self->_AddBand($type, $options);
1725  return unless defined wantarray;
1726  return $self->GetRasterBand($self->{RasterCount});
1727 }
1728 
1729 #** @method AdviseRead()
1730 #*
1731 sub AdviseRead {
1732 }
1733 
1734 #** @method Geo::GDAL::Band Band($index)
1735 # Object method.
1736 # Create a band object for the band within the dataset.
1737 # @note a.k.a. GetRasterBand
1738 # @param index 1...RasterCount, default is 1.
1739 # @return a new Geo::GDAL::Band object
1740 #*
1741 sub Band {
1742 }
1743 
1744 #** @method list Bands()
1745 # Object method.
1746 # @return a list of new Geo::GDAL::Band objects
1747 #*
1748 sub Bands {
1749  my $self = shift;
1750  my @bands;
1751  for my $i (1..$self->{RasterCount}) {
1752  push @bands, GetRasterBand($self, $i);
1753  }
1754  return @bands;
1755 }
1756 
1757 #** @method BuildOverviews($resampling, arrayref overviews, coderef progress, $progress_data)
1758 # Object method.
1759 # @param resampling the resampling method, one of Geo::GDAL::RIOResamplingTypes.
1760 # @param overviews The list of overview decimation factors to
1761 # build. For example [2,4,8].
1762 # @param progress [optional] a reference to a subroutine, which will
1763 # be called with parameters (number progress, string msg, progress_data)
1764 # @param progress_data [optional]
1765 #*
1766 sub BuildOverviews {
1767  my $self = shift;
1768  my @p = @_;
1769  $p[0] = uc($p[0]) if $p[0];
1770  eval {
1771  $self->_BuildOverviews(@p);
1772  };
1773  confess(last_error()) if $@;
1774 }
1775 
1776 #** @method Geo::GDAL::Dataset BuildVRT($Dest, arrayref Sources, hashref Options, coderef progress, $progress_data)
1777 # Object method.
1778 # Build a virtual dataset from a set of datasets.
1779 # @param Dest Destination raster dataset definition string (typically
1780 # filename), or an object, which implements write and close.
1781 # @param Sources A list of filenames of input datasets or a list of
1782 # dataset objects.
1783 # @param Options See section \ref index_processing_options.
1784 # @return Dataset object
1785 #
1786 # @note This subroutine is imported into the main namespace if Geo::GDAL
1787 # is use'd with qw/:all/.
1788 #*
1789 sub BuildVRT {
1790  my ($dest, $sources, $options, $progress, $progress_data) = @_;
1791  $options = Geo::GDAL::GDALBuildVRTOptions->new(make_processing_options($options));
1792  error("Usage: Geo::GDAL::DataSet::BuildVRT(\$vrt_file_name, \\\@sources)")
1793  unless ref $sources eq 'ARRAY' && defined $sources->[0];
1794  unless (blessed($dest)) {
1795  if (blessed($sources->[0])) {
1796  return Geo::GDAL::wrapper_GDALBuildVRT_objects($dest, $sources, $options, $progress, $progress_data);
1797  } else {
1798  return Geo::GDAL::wrapper_GDALBuildVRT_names($dest, $sources, $options, $progress, $progress_data);
1799  }
1800  } else {
1801  if (blessed($sources->[0])) {
1802  return stdout_redirection_wrapper(
1803  $sources, $dest,
1804  \&Geo::GDAL::wrapper_GDALBuildVRT_objects,
1805  $options, $progress, $progress_data);
1806  } else {
1807  return stdout_redirection_wrapper(
1808  $sources, $dest,
1809  \&Geo::GDAL::wrapper_GDALBuildVRT_names,
1810  $options, $progress, $progress_data);
1811  }
1812  }
1813 }
1814 
1815 #** @method CommitTransaction()
1816 #*
1817 sub CommitTransaction {
1818 }
1819 
1820 #** @method Geo::GDAL::ColorTable ComputeColorTable(%params)
1821 # Object method.
1822 # Compute a color table from an RGB image
1823 # @param params Named parameters:
1824 # - \a Red The red band, the default is to use the red band of this dataset.
1825 # - \a Green The green band, the default is to use the green band of this dataset.
1826 # - \a Blue The blue band, the default is to use the blue band of this dataset.
1827 # - \a NumColors The number of colors in the computed color table. Default is 256.
1828 # - \a Progress reference to a progress function (default is undef)
1829 # - \a ProgressData (default is undef)
1830 # - \a Method The computation method. The default and currently only option is the median cut algorithm.
1831 #
1832 # @return a new color table object.
1833 #*
1834 sub ComputeColorTable {
1835  my $self = shift;
1836  my $p = named_parameters(\@_,
1837  Red => undef,
1838  Green => undef,
1839  Blue => undef,
1840  NumColors => 256,
1841  Progress => undef,
1842  ProgressData => undef,
1843  Method => 'MedianCut');
1844  for my $b ($self->Bands) {
1845  for my $cion ($b->ColorInterpretation) {
1846  if ($cion eq 'RedBand') { $p->{red} //= $b; last; }
1847  if ($cion eq 'GreenBand') { $p->{green} //= $b; last; }
1848  if ($cion eq 'BlueBand') { $p->{blue} //= $b; last; }
1849  }
1850  }
1851  my $ct = Geo::GDAL::ColorTable->new;
1852  Geo::GDAL::ComputeMedianCutPCT($p->{red},
1853  $p->{green},
1854  $p->{blue},
1855  $p->{numcolors},
1856  $ct, $p->{progress},
1857  $p->{progressdata});
1858  return $ct;
1859 }
1860 
1861 #** @method Geo::OGR::Layer CopyLayer($layer, $name, hashref options = undef)
1862 # Object method.
1863 # @param layer A Geo::OGR::Layer object to be copied.
1864 # @param name A name for the new layer.
1865 # @param options A ref to a hash of format specific options.
1866 # @return a new Geo::OGR::Layer object.
1867 #*
1868 sub CopyLayer {
1869 }
1870 
1871 #** @method Geo::OGR::Layer CreateLayer(%params)
1872 # Object method.
1873 # @brief Create a new vector layer into this dataset.
1874 #
1875 # @param %params Named parameters:
1876 # - \a Name (scalar) name for the new layer.
1877 # - \a Fields (array reference) a list of (scalar and geometry) field definitions as in
1878 # Geo::OGR::Layer::CreateField.
1879 # - \a ApproxOK (boolean value, default is true) a flag, which is forwarded to Geo::OGR::Layer::CreateField.
1880 # - \a Options (hash reference) driver specific hash of layer creation options.
1881 # - \a Schema (hash reference, deprecated, use \a Fields and \a Name) may contain keys Name, Fields, GeomFields, GeometryType.
1882 # - \a SRS (scalar) the spatial reference for the default geometry field.
1883 # - \a GeometryType (scalar) the type of the default geometry field
1884 # (if only one geometry field). Default is 'Unknown'.
1885 #
1886 # @note If Fields or Schema|Fields is not given, a default geometry
1887 # field (Name => '', GeometryType => 'Unknown') is created. If it is
1888 # given and it contains spatial fields, both GeometryType and SRS are
1889 # ignored. The type can be also set with the named parameter.
1890 #
1891 # Example:
1892 # \code
1893 # my $roads = Geo::OGR::Driver('Memory')->Create('road')->
1894 # CreateLayer(
1895 # Fields => [ { Name => 'class',
1896 # Type => 'Integer' },
1897 # { Name => 'geom',
1898 # Type => 'LineString25D' } ] );
1899 # \endcode
1900 #
1901 # @note Many formats allow only one spatial field, which currently
1902 # requires the use of GeometryType.
1903 #
1904 # @return a new Geo::OGR::Layer object.
1905 #*
1906 sub CreateLayer {
1907  my $self = shift;
1908  my $p = named_parameters(\@_,
1909  Name => 'unnamed',
1910  SRS => undef,
1911  GeometryType => 'Unknown',
1912  Options => {},
1913  Schema => undef,
1914  Fields => undef,
1915  ApproxOK => 1);
1916  error("The 'Fields' argument must be an array reference.") if $p->{fields} && ref($p->{fields}) ne 'ARRAY';
1917  if (defined $p->{schema}) {
1918  my $s = $p->{schema};
1919  $p->{geometrytype} = $s->{GeometryType} if exists $s->{GeometryType};
1920  $p->{fields} = $s->{Fields} if exists $s->{Fields};
1921  $p->{name} = $s->{Name} if exists $s->{Name};
1922  }
1923  $p->{fields} = [] unless ref($p->{fields}) eq 'ARRAY';
1924  # if fields contains spatial fields, then do not create default one
1925  for my $f (@{$p->{fields}}) {
1926  error("Field definitions must be hash references.") unless ref $f eq 'HASH';
1927  if ($f->{GeometryType} || ($f->{Type} && s_exists(geometry_type => $f->{Type}))) {
1928  $p->{geometrytype} = 'None';
1929  last;
1930  }
1931  }
1932  my $gt = s2i(geometry_type => $p->{geometrytype});
1933  my $layer = _CreateLayer($self, $p->{name}, $p->{srs}, $gt, $p->{options});
1934  for my $f (@{$p->{fields}}) {
1935  $layer->CreateField($f);
1936  }
1937  keep($layer, $self);
1938 }
1939 
1940 #** @method CreateMaskBand()
1941 # Object method.
1942 # Add a mask band to the dataset.
1943 #*
1944 sub CreateMaskBand {
1945  return _CreateMaskBand(@_);
1946 }
1947 
1948 #** @method Geo::GDAL::Dataset DEMProcessing($Dest, $Processing, $ColorFilename, hashref Options, coderef progress, $progress_data)
1949 # Object method.
1950 # Apply a DEM processing to this dataset.
1951 # @param Dest Destination raster dataset definition string (typically filename) or an object, which implements write and close.
1952 # @param Processing Processing to apply, one of "hillshade", "slope", "aspect", "color-relief", "TRI", "TPI", or "Roughness".
1953 # @param ColorFilename The color palette for color-relief.
1954 # @param Options See section \ref index_processing_options.
1955 # @param progress [optional] A reference to a subroutine, which will
1956 # be called with parameters (number progress, string msg, progress_data).
1957 # @param progress_data [optional]
1958 #
1959 #*
1960 sub DEMProcessing {
1961  my ($self, $dest, $Processing, $ColorFilename, $options, $progress, $progress_data) = @_;
1962  $options = Geo::GDAL::GDALDEMProcessingOptions->new(make_processing_options($options));
1963  return $self->stdout_redirection_wrapper(
1964  $dest,
1965  \&Geo::GDAL::wrapper_GDALDEMProcessing,
1966  $Processing, $ColorFilename, $options, $progress, $progress_data
1967  );
1968 }
1969 
1970 #** @method Dataset()
1971 #*
1972 sub Dataset {
1973  my $self = shift;
1974  parent($self);
1975 }
1976 
1977 #** @method DeleteLayer($name)
1978 # Object method.
1979 # Deletes a layer from the data source. Note that if there is a layer
1980 # object for the deleted layer, it becomes unusable.
1981 # @param name name of the layer to delete.
1982 #*
1983 sub DeleteLayer {
1984  my ($self, $name) = @_;
1985  my $index;
1986  for my $i (0..$self->GetLayerCount-1) {
1987  my $layer = GetLayerByIndex($self, $i);
1988  $index = $i, last if $layer->GetName eq $name;
1989  }
1990  error(2, $name, 'Layer') unless defined $index;
1991  _DeleteLayer($self, $index);
1992 }
1993 
1994 #** @method Geo::GDAL::Band Dither(%params)
1995 # Object method.
1996 # Compute one band with color table image from an RGB image
1997 # @params params Named parameters:
1998 # - \a Red The red band, the default is to use the red band of this dataset.
1999 # - \a Green The green band, the default is to use the green band of this dataset.
2000 # - \a Blue The blue band, the default is to use the blue band of this dataset.
2001 # - \a Dest The destination band. If this is not defined, a new in-memory band (and a dataset) will be created.
2002 # - \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.
2003 # - \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.
2004 # - \a ProgressData (default is undef)
2005 #
2006 # @return the destination band.
2007 #
2008 # Usage example. This code converts an RGB JPEG image into a one band PNG image with a color table.
2009 # \code
2010 # my $d = Geo::GDAL::Open('pic.jpg');
2011 # Geo::GDAL::Driver('PNG')->Copy(Name => 'test.png', Src => $d->Dither->Dataset);
2012 # \endcode
2013 #*
2014 sub Dither {
2015  my $self = shift;
2016  my $p = named_parameters(\@_,
2017  Red => undef,
2018  Green => undef,
2019  Blue => undef,
2020  Dest => undef,
2021  ColorTable => undef,
2022  Progress => undef,
2023  ProgressData => undef);
2024  for my $b ($self->Bands) {
2025  for my $cion ($b->ColorInterpretation) {
2026  if ($cion eq 'RedBand') { $p->{red} //= $b; last; }
2027  if ($cion eq 'GreenBand') { $p->{green} //= $b; last; }
2028  if ($cion eq 'BlueBand') { $p->{blue} //= $b; last; }
2029  }
2030  }
2031  my ($w, $h) = $self->Size;
2032  $p->{dest} //= Geo::GDAL::Driver('MEM')->Create(Name => 'dithered',
2033  Width => $w,
2034  Height => $h,
2035  Type => 'Byte')->Band;
2036  $p->{colortable}
2037  //= $p->{dest}->ColorTable
2038  // $self->ComputeColorTable(Red => $p->{red},
2039  Green => $p->{green},
2040  Blue => $p->{blue},
2041  Progress => $p->{progress},
2042  ProgressData => $p->{progressdata});
2043  Geo::GDAL::DitherRGB2PCT($p->{red},
2044  $p->{green},
2045  $p->{blue},
2046  $p->{dest},
2047  $p->{colortable},
2048  $p->{progress},
2049  $p->{progressdata});
2050  $p->{dest}->ColorTable($p->{colortable});
2051  return $p->{dest};
2052 }
2053 
2054 #** @method Domains()
2055 #*
2056 sub Domains {
2057  return @DOMAINS;
2058 }
2059 
2060 #** @method Geo::GDAL::Driver Driver()
2061 # Object method.
2062 # @note a.k.a. GetDriver
2063 # @return a Geo::GDAL::Driver object that was used to open or create this dataset.
2064 #*
2065 sub Driver {
2066 }
2067 
2068 #** @method Geo::OGR::Layer ExecuteSQL($statement, $geom = undef, $dialect = "")
2069 # Object method.
2070 # @param statement A SQL statement.
2071 # @param geom A Geo::OGR::Geometry object.
2072 # @param dialect
2073 # @return a new Geo::OGR::Layer object. The data source object will
2074 # exist as long as the layer object exists.
2075 #*
2076 sub ExecuteSQL {
2077  my $self = shift;
2078  my $layer = $self->_ExecuteSQL(@_);
2079  note($layer, "is result set");
2080  keep($layer, $self);
2081 }
2082 
2083 #** @method Geo::GDAL::Extent Extent(@params)
2084 # Object method.
2085 # @param params nothing, or a list ($xoff, $yoff, $w, $h)
2086 # @return A new Geo::GDAL::Extent object that represents the area that
2087 # this raster or the specified tile covers.
2088 #*
2089 sub Extent {
2090  my $self = shift;
2091  my $t = $self->GeoTransform;
2092  my $extent = $t->Extent($self->Size);
2093  if (@_) {
2094  my ($xoff, $yoff, $w, $h) = @_;
2095  my ($x, $y) = $t->Apply([$xoff, $xoff+$w, $xoff+$w, $xoff], [$yoff, $yoff, $yoff+$h, $yoff+$h]);
2096  my $xmin = shift @$x;
2097  my $xmax = $xmin;
2098  for my $x (@$x) {
2099  $xmin = $x if $x < $xmin;
2100  $xmax = $x if $x > $xmax;
2101  }
2102  my $ymin = shift @$y;
2103  my $ymax = $ymin;
2104  for my $y (@$y) {
2105  $ymin = $y if $y < $ymin;
2106  $ymax = $y if $y > $ymax;
2107  }
2108  $extent = Geo::GDAL::Extent->new($xmin, $ymin, $xmax, $ymax);
2109  }
2110  return $extent;
2111 }
2112 
2113 #** @method list GCPs(@GCPs, Geo::OSR::SpatialReference sr)
2114 # Object method.
2115 # Get or set the GCPs and their projection.
2116 # @param GCPs [optional] a list of Geo::GDAL::GCP objects
2117 # @param sr [optional] the projection of the GCPs.
2118 # @return a list of Geo::GDAL::GCP objects followed by a Geo::OSR::SpatialReference object.
2119 #*
2120 sub GCPs {
2121  my $self = shift;
2122  if (@_ > 0) {
2123  my $proj = pop @_;
2124  $proj = $proj->Export('WKT') if $proj and ref($proj);
2125  SetGCPs($self, \@_, $proj);
2126  }
2127  return unless defined wantarray;
2128  my $proj = Geo::OSR::SpatialReference->new(GetGCPProjection($self));
2129  my $GCPs = GetGCPs($self);
2130  return (@$GCPs, $proj);
2131 }
2132 
2133 #** @method Geo::GDAL::GeoTransform GeoTransform(Geo::GDAL::GeoTransform $geo_transform)
2134 # Object method.
2135 # Transformation from cell coordinates (column,row) to projection
2136 # coordinates (x,y)
2137 # \code
2138 # x = geo_transform[0] + column*geo_transform[1] + row*geo_transform[2]
2139 # y = geo_transform[3] + column*geo_transform[4] + row*geo_transform[5]
2140 # \endcode
2141 # @param geo_transform [optional]
2142 # @return the geo transform in a non-void context.
2143 #*
2144 sub GeoTransform {
2145  my $self = shift;
2146  eval {
2147  if (@_ == 1) {
2148  SetGeoTransform($self, $_[0]);
2149  } elsif (@_ > 1) {
2150  SetGeoTransform($self, \@_);
2151  }
2152  };
2153  confess(last_error()) if $@;
2154  return unless defined wantarray;
2155  my $t = GetGeoTransform($self);
2156  if (wantarray) {
2157  return @$t;
2158  } else {
2159  return Geo::GDAL::GeoTransform->new($t);
2160  }
2161 }
2162 
2163 #** @method GetDriver()
2164 #*
2165 sub GetDriver {
2166 }
2167 
2168 #** @method list GetFileList()
2169 # Object method.
2170 # @return list of files GDAL believes to be part of this dataset.
2171 #*
2172 sub GetFileList {
2173 }
2174 
2175 #** @method scalar GetGCPProjection()
2176 # Object method.
2177 # @return projection string.
2178 #*
2179 sub GetGCPProjection {
2180 }
2181 
2182 #** @method Geo::OGR::Layer GetLayer($name)
2183 # Object method.
2184 # @param name the name of the requested layer. If not given, then
2185 # returns the first layer in the data source.
2186 # @return a new Geo::OGR::Layer object that represents the layer
2187 # in the data source.
2188 #*
2189 sub GetLayer {
2190  my($self, $name) = @_;
2191  my $layer = defined $name ? GetLayerByName($self, "$name") : GetLayerByIndex($self, 0);
2192  $name //= '';
2193  error(2, $name, 'Layer') unless $layer;
2194  keep($layer, $self);
2195 }
2196 
2197 #** @method list GetLayerNames()
2198 # Object method.
2199 # @note Delivers the functionality of undocumented method GetLayerCount.
2200 # @return a list of the names of the layers this data source provides.
2201 #*
2202 sub GetLayerNames {
2203  my $self = shift;
2204  my @names;
2205  for my $i (0..$self->GetLayerCount-1) {
2206  my $layer = GetLayerByIndex($self, $i);
2207  push @names, $layer->GetName;
2208  }
2209  return @names;
2210 }
2211 
2212 #** @method GetNextFeature()
2213 #*
2214 sub GetNextFeature {
2215 }
2216 
2217 #** @method GetStyleTable()
2218 #*
2219 sub GetStyleTable {
2220 }
2221 
2222 #** @method Geo::GDAL::Dataset Grid($Dest, hashref Options)
2223 # Object method.
2224 # Creates a regular raster grid from this data source.
2225 # This is equivalent to the gdal_grid utility.
2226 # @param Dest Destination raster dataset definition string (typically
2227 # filename) or an object, which implements write and close.
2228 # @param Options See section \ref index_processing_options.
2229 #*
2230 sub Grid {
2231  my ($self, $dest, $options, $progress, $progress_data) = @_;
2232  $options = Geo::GDAL::GDALGridOptions->new(make_processing_options($options));
2233  return $self->stdout_redirection_wrapper(
2234  $dest,
2235  \&Geo::GDAL::wrapper_GDALGrid,
2236  $options, $progress, $progress_data
2237  );
2238 }
2239 
2240 #** @method scalar Info(hashref Options)
2241 # Object method.
2242 # Information about this dataset.
2243 # @param Options See section \ref index_processing_options.
2244 #*
2245 sub Info {
2246  my ($self, $o) = @_;
2247  $o = Geo::GDAL::GDALInfoOptions->new(make_processing_options($o));
2248  return GDALInfo($self, $o);
2249 }
2250 
2251 #** @method Geo::GDAL::Dataset Nearblack($Dest, hashref Options, coderef progress, $progress_data)
2252 # Object method.
2253 # Convert nearly black/white pixels to black/white.
2254 # @param Dest Destination raster dataset definition string (typically
2255 # filename), destination dataset to which to add an alpha or mask
2256 # band, or an object, which implements write and close.
2257 # @param Options See section \ref index_processing_options.
2258 # @return Dataset if destination dataset definition string was given,
2259 # otherwise a boolean for success/fail but the method croaks if there
2260 # was an error.
2261 #*
2262 sub Nearblack {
2263  my ($self, $dest, $options, $progress, $progress_data) = @_;
2264  $options = Geo::GDAL::GDALNearblackOptions->new(make_processing_options($options));
2265  my $b = blessed($dest);
2266  if ($b && $b eq 'Geo::GDAL::Dataset') {
2267  Geo::GDAL::wrapper_GDALNearblackDestDS($dest, $self, $options, $progress, $progress_data);
2268  } else {
2269  return $self->stdout_redirection_wrapper(
2270  $dest,
2271  \&Geo::GDAL::wrapper_GDALNearblackDestName,
2272  $options, $progress, $progress_data
2273  );
2274  }
2275 }
2276 
2277 #** @method Geo::GDAL::Dataset Open()
2278 # Package subroutine.
2279 # The same as Geo::GDAL::Open
2280 #*
2281 sub Open {
2282 }
2283 
2284 #** @method Geo::GDAL::Dataset OpenShared()
2285 # Package subroutine.
2286 # The same as Geo::GDAL::OpenShared
2287 #*
2288 sub OpenShared {
2289 }
2290 
2291 #** @method Geo::GDAL::Dataset Rasterize($Dest, hashref Options, coderef progress, $progress_data)
2292 # Object method.
2293 # Render data from this data source into a raster.
2294 # @param Dest Destination raster dataset definition string (typically
2295 # filename), destination dataset, or an object, which implements write and close.
2296 # @param Options See section \ref index_processing_options.
2297 # @return Dataset if destination dataset definition string was given,
2298 # otherwise a boolean for success/fail but the method croaks if there
2299 # was an error.
2300 #
2301 #*
2302 sub Rasterize {
2303  my ($self, $dest, $options, $progress, $progress_data) = @_;
2304  $options = Geo::GDAL::GDALRasterizeOptions->new(make_processing_options($options));
2305  my $b = blessed($dest);
2306  if ($b && $b eq 'Geo::GDAL::Dataset') {
2307  Geo::GDAL::wrapper_GDALRasterizeDestDS($dest, $self, $options, $progress, $progress_data);
2308  } else {
2309  # TODO: options need to force a new raster be made, otherwise segfault
2310  return $self->stdout_redirection_wrapper(
2311  $dest,
2312  \&Geo::GDAL::wrapper_GDALRasterizeDestName,
2313  $options, $progress, $progress_data
2314  );
2315  }
2316 }
2317 
2318 #** @method scalar ReadRaster(%params)
2319 # Object method.
2320 # Read data from the dataset.
2321 #
2322 # @param params Named parameters:
2323 # - \a XOff x offset (cell coordinates) (default is 0)
2324 # - \a YOff y offset (cell coordinates) (default is 0)
2325 # - \a XSize width of the area to read (default is the width of the dataset)
2326 # - \a YSize height of the area to read (default is the height of the dataset)
2327 # - \a BufXSize (default is undef, i.e., the same as XSize)
2328 # - \a BufYSize (default is undef, i.e., the same as YSize)
2329 # - \a BufType data type of the buffer (default is the data type of the first band)
2330 # - \a BandList a reference to an array of band indices (default is [1])
2331 # - \a BufPixelSpace (default is 0)
2332 # - \a BufLineSpace (default is 0)
2333 # - \a BufBandSpace (default is 0)
2334 # - \a ResampleAlg one of Geo::GDAL::RIOResamplingTypes (default is 'NearestNeighbour'),
2335 # - \a Progress reference to a progress function (default is undef)
2336 # - \a ProgressData (default is undef)
2337 #
2338 # <a href="http://www.gdal.org/classGDALDataset.html">Entry in GDAL docs (method RasterIO)</a>
2339 # @return a buffer, open the buffer with \a unpack function of Perl. See Geo::GDAL::Band::PackCharacter.
2340 #*
2341 sub ReadRaster {
2342  my $self = shift;
2343  my ($width, $height) = $self->Size;
2344  my ($type) = $self->Band->DataType;
2345  my $p = named_parameters(\@_,
2346  XOff => 0,
2347  YOff => 0,
2348  XSize => $width,
2349  YSize => $height,
2350  BufXSize => undef,
2351  BufYSize => undef,
2352  BufType => $type,
2353  BandList => [1],
2354  BufPixelSpace => 0,
2355  BufLineSpace => 0,
2356  BufBandSpace => 0,
2357  ResampleAlg => 'NearestNeighbour',
2358  Progress => undef,
2359  ProgressData => undef
2360  );
2361  $p->{resamplealg} = s2i(rio_resampling => $p->{resamplealg});
2362  $p->{buftype} = s2i(data_type => $p->{buftype}, 1);
2363  $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});
2364 }
2365 
2366 #** @method ReadTile()
2367 #*
2368 sub ReadTile {
2369  my ($self, $xoff, $yoff, $xsize, $ysize, $w_tile, $h_tile, $alg) = @_;
2370  my @data;
2371  for my $i (0..$self->Bands-1) {
2372  $data[$i] = $self->Band($i+1)->ReadTile($xoff, $yoff, $xsize, $ysize, $w_tile, $h_tile, $alg);
2373  }
2374  return \@data;
2375 }
2376 
2377 #** @method ReleaseResultSet($layer)
2378 # Object method.
2379 # @param layer A layer the has been created with ExecuteSQL.
2380 # @note There is no need to call this method. The result set layer is
2381 # released in the destructor of the layer that was created with SQL.
2382 #*
2383 sub ReleaseResultSet {
2384  # a no-op, _ReleaseResultSet is called from Layer::DESTROY
2385 }
2386 
2387 #** @method ResetReading()
2388 #*
2389 sub ResetReading {
2390 }
2391 
2392 #** @method RollbackTransaction()
2393 #*
2394 sub RollbackTransaction {
2395 }
2396 
2397 #** @method SetStyleTable()
2398 #*
2399 sub SetStyleTable {
2400 }
2401 
2402 #** @method list Size()
2403 # Object method.
2404 # @return (width, height)
2405 #*
2406 sub Size {
2407  my $self = shift;
2408  return ($self->{RasterXSize}, $self->{RasterYSize});
2409 }
2410 
2411 #** @method Geo::OSR::SpatialReference SpatialReference(Geo::OSR::SpatialReference sr)
2412 # Object method.
2413 # Get or set the projection of this dataset.
2414 # @param sr [optional] a Geo::OSR::SpatialReference object,
2415 # which replaces the existing projection definition of this dataset.
2416 # @return a Geo::OSR::SpatialReference object, which represents the
2417 # projection of this dataset.
2418 # @note Methods GetProjection, SetProjection, and Projection return WKT strings.
2419 #*
2420 sub SpatialReference {
2421  my($self, $sr) = @_;
2422  SetProjection($self, $sr->As('WKT')) if defined $sr;
2423  if (defined wantarray) {
2424  my $p = GetProjection($self);
2425  return unless $p;
2426  return Geo::OSR::SpatialReference->new(WKT => $p);
2427  }
2428 }
2429 
2430 #** @method StartTransaction()
2431 #*
2432 sub StartTransaction {
2433 }
2434 
2435 #** @method TestCapability()
2436 #*
2437 sub TestCapability {
2438  return _TestCapability(@_);
2439 }
2440 
2441 #** @method Tile(Geo::GDAL::Extent e)
2442 # Object method.
2443 # Compute the top left cell coordinates and width and height of the
2444 # tile that covers the given extent.
2445 # @param e The extent whose tile is needed.
2446 # @note Requires that the raster is a strictly north up one.
2447 # @return A list ($xoff, $yoff, $xsize, $ysize).
2448 #*
2449 sub Tile {
2450  my ($self, $e) = @_;
2451  my ($w, $h) = $self->Size;
2452  my $t = $self->GeoTransform;
2453  confess "GeoTransform is not \"north up\"." unless $t->NorthUp;
2454  my $xoff = floor(($e->[0] - $t->[0])/$t->[1]);
2455  $xoff = 0 if $xoff < 0;
2456  my $yoff = floor(($e->[1] - $t->[3])/$t->[5]);
2457  $yoff = 0 if $yoff < 0;
2458  my $xsize = ceil(($e->[2] - $t->[0])/$t->[1]) - $xoff;
2459  $xsize = $w - $xoff if $xsize > $w - $xoff;
2460  my $ysize = ceil(($e->[3] - $t->[3])/$t->[5]) - $yoff;
2461  $ysize = $h - $yoff if $ysize > $h - $yoff;
2462  return ($xoff, $yoff, $xsize, $ysize);
2463 }
2464 
2465 #** @method Geo::GDAL::Dataset Translate($Dest, hashref Options, coderef progress, $progress_data)
2466 # Object method.
2467 # Convert this dataset into another format.
2468 # @param Dest Destination dataset definition string (typically
2469 # filename) or an object, which implements write and close.
2470 # @param Options See section \ref index_processing_options.
2471 # @return New dataset object if destination dataset definition
2472 # string was given, otherwise a boolean for success/fail but the
2473 # method croaks if there was an error.
2474 #*
2475 sub Translate {
2476  my ($self, $dest, $options, $progress, $progress_data) = @_;
2477  return $self->stdout_redirection_wrapper(
2478  $dest,
2479 }
2480 
2481 #** @method Geo::GDAL::Dataset Warp($Dest, hashref Options, coderef progress, $progress_data)
2482 # Object method.
2483 # Reproject this dataset.
2484 # @param Dest Destination raster dataset definition string (typically
2485 # filename) or an object, which implements write and close.
2486 # @param Options See section \ref index_processing_options.
2487 # @note This method can be run as a package subroutine with a list of
2488 # datasets as the first argument to mosaic several datasets.
2489 #*
2490 sub Warp {
2491  my ($self, $dest, $options, $progress, $progress_data) = @_;
2492  # can be run as object method (one dataset) and as package sub (a list of datasets)
2493  $options = Geo::GDAL::GDALWarpAppOptions->new(make_processing_options($options));
2494  my $b = blessed($dest);
2495  $self = [$self] unless ref $self eq 'ARRAY';
2496  if ($b && $b eq 'Geo::GDAL::Dataset') {
2497  Geo::GDAL::wrapper_GDALWarpDestDS($dest, $self, $options, $progress, $progress_data);
2498  } else {
2499  return stdout_redirection_wrapper(
2500  $self,
2501  $dest,
2502  \&Geo::GDAL::wrapper_GDALWarpDestName,
2503  $options, $progress, $progress_data
2504  );
2505  }
2506 }
2507 
2508 #** @method Geo::GDAL::Dataset Warped(%params)
2509 # Object method.
2510 # Create a virtual warped dataset from this dataset.
2511 #
2512 # @param params Named parameters:
2513 # - \a SrcSRS Override the spatial reference system of this dataset if there is one (default is undef).
2514 # - \a DstSRS The target spatial reference system of the result (default is undef).
2515 # - \a ResampleAlg The resampling algorithm (default is 'NearestNeighbour').
2516 # - \a MaxError Maximum error measured in input cellsize that is allowed in approximating the transformation (default is 0 for exact calculations).
2517 #
2518 # # <a href="http://www.gdal.org/gdalwarper_8h.html">Documentation for GDAL warper.</a>
2519 #
2520 # @return a new Geo::GDAL::Dataset object
2521 #*
2522 sub Warped {
2523  my $self = shift;
2524  my $p = named_parameters(\@_, SrcSRS => undef, DstSRS => undef, ResampleAlg => 'NearestNeighbour', MaxError => 0);
2525  for my $srs (qw/srcsrs dstsrs/) {
2526  $p->{$srs} = $p->{$srs}->ExportToWkt if $p->{$srs} && blessed $p->{$srs};
2527  }
2528  $p->{resamplealg} = s2i(resampling => $p->{resamplealg});
2529  my $warped = Geo::GDAL::_AutoCreateWarpedVRT($self, $p->{srcsrs}, $p->{dstsrs}, $p->{resamplealg}, $p->{maxerror});
2530  keep($warped, $self) if $warped; # self must live as long as warped
2531 }
2532 
2533 #** @method WriteRaster(%params)
2534 # Object method.
2535 # Write data into the dataset.
2536 #
2537 # @param params Named parameters:
2538 # - \a XOff x offset (cell coordinates) (default is 0)
2539 # - \a YOff y offset (cell coordinates) (default is 0)
2540 # - \a XSize width of the area to write (default is the width of the dataset)
2541 # - \a YSize height of the area to write (default is the height of the dataset)
2542 # - \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.
2543 # - \a BufXSize (default is undef, i.e., the same as XSize)
2544 # - \a BufYSize (default is undef, i.e., the same as YSize)
2545 # - \a BufType data type of the buffer (default is the data type of the first band)
2546 # - \a BandList a reference to an array of band indices (default is [1])
2547 # - \a BufPixelSpace (default is 0)
2548 # - \a BufLineSpace (default is 0)
2549 # - \a BufBandSpace (default is 0)
2550 #
2551 # <a href="http://www.gdal.org/classGDALDataset.html">Entry in GDAL docs (method RasterIO)</a>
2552 #*
2553 sub WriteRaster {
2554  my $self = shift;
2555  my ($width, $height) = $self->Size;
2556  my ($type) = $self->Band->DataType;
2557  my $p = named_parameters(\@_,
2558  XOff => 0,
2559  YOff => 0,
2560  XSize => $width,
2561  YSize => $height,
2562  Buf => undef,
2563  BufXSize => undef,
2564  BufYSize => undef,
2565  BufType => $type,
2566  BandList => [1],
2567  BufPixelSpace => 0,
2568  BufLineSpace => 0,
2569  BufBandSpace => 0
2570  );
2571  $p->{buftype} = s2i(data_type => $p->{buftype}, 1);
2572  $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});
2573 }
2574 
2575 #** @method WriteTile()
2576 #*
2577 sub WriteTile {
2578  my ($self, $data, $xoff, $yoff) = @_;
2579  $xoff //= 0;
2580  $yoff //= 0;
2581  for my $i (0..$self->Bands-1) {
2582  $self->Band($i+1)->WriteTile($data->[$i], $xoff, $yoff);
2583  }
2584 }
2585 
2586 #** @class Geo::GDAL::Driver
2587 # @brief A driver for a specific dataset format.
2588 # @details
2589 #*
2590 package Geo::GDAL::Driver;
2591 
2592 use base qw(Geo::GDAL::MajorObject Geo::GDAL)
2593 
2594 #** @attr $HelpTopic
2595 # $driver->{HelpTopic}
2596 #*
2597 
2598 #** @attr $LongName
2599 # $driver->{LongName}
2600 #*
2601 
2602 #** @attr $ShortName
2603 # $driver->{ShortName}
2604 #*
2605 
2606 #** @method list Capabilities()
2607 # Object method.
2608 # @return A list of capabilities. When executed as a package subroutine
2609 # returns a list of all potential capabilities a driver may have. When
2610 # executed as an object method returns a list of all capabilities the
2611 # driver has.
2612 #
2613 # Currently capabilities are:
2614 # CREATE, CREATECOPY, DEFAULT_FIELDS, NOTNULL_FIELDS, NOTNULL_GEOMFIELDS, OPEN, RASTER, VECTOR, and VIRTUALIO.
2615 #
2616 # Examples.
2617 # \code
2618 # @all_capabilities = Geo::GDAL::Driver::Capabilities;
2619 # @capabilities_of_the_geotiff_driver = Geo::GDAL::Driver('GTiff')->Capabilities;
2620 # \endcode
2621 #*
2622 sub Capabilities {
2623  my $self = shift;
2624  return @CAPABILITIES unless $self;
2625  my $h = $self->GetMetadata;
2626  my @cap;
2627  for my $cap (@CAPABILITIES) {
2628  my $test = $h->{'DCAP_'.uc($cap)};
2629  push @cap, $cap if defined($test) and $test eq 'YES';
2630  }
2631  return @cap;
2632 }
2633 
2634 #** @method Geo::GDAL::Dataset Copy(%params)
2635 # Object method.
2636 # Create a new raster Geo::GDAL::Dataset as a copy of an existing dataset.
2637 # @note a.k.a. CreateCopy
2638 #
2639 # @param params Named parameters:
2640 # - \a Name name for the new raster dataset.
2641 # - \a Src the source Geo::GDAL::Dataset object.
2642 # - \a Strict 1 (default) if the copy must be strictly equivalent, or 0 if the copy may adapt.
2643 # - \a Options an anonymous hash of driver specific options.
2644 # - \a Progress [optional] a reference to a subroutine, which will
2645 # be called with parameters (number progress, string msg, progress_data).
2646 # - \a ProgressData [optional]
2647 # @return a new Geo::GDAL::Dataset object.
2648 #*
2649 sub Copy {
2650  my $self = shift;
2651  my $p = named_parameters(\@_, Name => 'unnamed', Src => undef, Strict => 1, Options => {}, Progress => undef, ProgressData => undef);
2652  return $self->stdout_redirection_wrapper(
2653  $p->{name},
2654  $self->can('_CreateCopy'),
2655  $p->{src}, $p->{strict}, $p->{options}, $p->{progress}, $p->{progressdata});
2656 }
2657 
2658 #** @method CopyFiles($NewName, $OldName)
2659 # Object method.
2660 # Copy the files of a dataset.
2661 # @param NewName String.
2662 # @param OldName String.
2663 #*
2664 sub CopyFiles {
2665 }
2666 
2667 #** @method Geo::GDAL::Dataset Create(%params)
2668 # Object method.
2669 # Create a raster dataset using this driver.
2670 # @note a.k.a. CreateDataset
2671 #
2672 # @param params Named parameters:
2673 # - \a Name The name for the dataset (default is 'unnamed') or an object, which implements write and close.
2674 # - \a Width The width for the raster dataset (default is 256).
2675 # - \a Height The height for the raster dataset (default is 256).
2676 # - \a Bands The number of bands to create into the raster dataset (default is 1).
2677 # - \a Type The data type for the raster cells (default is 'Byte'). One of Geo::GDAL::Driver::CreationDataTypes.
2678 # - \a Options Driver creation options as a reference to a hash (default is {}).
2679 #
2680 # @return A new Geo::GDAL::Dataset object.
2681 #*
2682 sub Create {
2683  my $self = shift;
2684  my $p = named_parameters(\@_, Name => 'unnamed', Width => 256, Height => 256, Bands => 1, Type => 'Byte', Options => {});
2685  my $type = s2i(data_type => $p->{type});
2686  return $self->stdout_redirection_wrapper(
2687  $p->{name},
2688  $self->can('_Create'),
2689  $p->{width}, $p->{height}, $p->{bands}, $type, $p->{options}
2690  );
2691 }
2692 
2693 #** @method list CreationDataTypes()
2694 # Object method.
2695 # @return a list of data types that can be used for new datasets of this format. A subset of Geo::GDAL::DataTypes
2696 #*
2697 sub CreationDataTypes {
2698  my $self = shift;
2699  my $h = $self->GetMetadata;
2700  return split /\s+/, $h->{DMD_CREATIONDATATYPES} if $h->{DMD_CREATIONDATATYPES};
2701 }
2702 
2703 #** @method list CreationOptionList()
2704 # Object method.
2705 # @return a list of options, each option is a hashref, the keys are
2706 # name, type and description or Value. Value is a listref.
2707 #*
2708 sub CreationOptionList {
2709  my $self = shift;
2710  my @options;
2711  my $h = $self->GetMetadata->{DMD_CREATIONOPTIONLIST};
2712  if ($h) {
2713  $h = ParseXMLString($h);
2714  my($type, $value) = NodeData($h);
2715  if ($value eq 'CreationOptionList') {
2716  for my $o (Children($h)) {
2717  my %option;
2718  for my $a (Children($o)) {
2719  my(undef, $key) = NodeData($a);
2720  my(undef, $value) = NodeData(Child($a, 0));
2721  if ($key eq 'Value') {
2722  push @{$option{$key}}, $value;
2723  } else {
2724  $option{$key} = $value;
2725  }
2726  }
2727  push @options, \%option;
2728  }
2729  }
2730  }
2731  return @options;
2732 }
2733 
2734 #** @method Delete($name)
2735 # Object method.
2736 # @param name
2737 #*
2738 sub Delete {
2739 }
2740 
2741 #** @method Domains()
2742 #*
2743 sub Domains {
2744  return @DOMAINS;
2745 }
2746 
2747 #** @method scalar Extension()
2748 # Object method.
2749 # @note The returned extension does not contain a '.' prefix.
2750 # @return a suggested single extension or a list of extensions (in
2751 # list context) for datasets.
2752 #*
2753 sub Extension {
2754  my $self = shift;
2755  my $h = $self->GetMetadata;
2756  if (wantarray) {
2757  my $e = $h->{DMD_EXTENSIONS};
2758  my @e = split / /, $e;
2759  @e = split /\//, $e if $e =~ /\//; # ILWIS returns mpr/mpl
2760  for my $i (0..$#e) {
2761  $e[$i] =~ s/^\.//; # CALS returns extensions with a dot prefix
2762  }
2763  return @e;
2764  } else {
2765  my $e = $h->{DMD_EXTENSION};
2766  return '' if $e =~ /\//; # ILWIS returns mpr/mpl
2767  $e =~ s/^\.//;
2768  return $e;
2769  }
2770 }
2771 
2772 #** @method scalar MIMEType()
2773 # Object method.
2774 # @return a suggested MIME type for datasets.
2775 #*
2776 sub MIMEType {
2777  my $self = shift;
2778  my $h = $self->GetMetadata;
2779  return $h->{DMD_MIMETYPE};
2780 }
2781 
2782 #** @method scalar Name()
2783 # Object method.
2784 # @return The short name of the driver.
2785 #*
2786 sub Name {
2787  my $self = shift;
2788  return $self->{ShortName};
2789 }
2790 
2791 #** @method Open()
2792 # Object method.
2793 # The same as Geo::GDAL::Open except that only this driver is allowed.
2794 #*
2795 sub Open {
2796  my $self = shift;
2797  my @p = @_; # name, update
2798  my @flags = qw/RASTER/;
2799  push @flags, qw/READONLY/ if $p[1] eq 'ReadOnly';
2800  push @flags, qw/UPDATE/ if $p[1] eq 'Update';
2801  my $dataset = OpenEx($p[0], \@flags, [$self->Name()]);
2802  error("Failed to open $p[0]. Is it a raster dataset?") unless $dataset;
2803  return $dataset;
2804 }
2805 
2806 #** @method Rename($NewName, $OldName)
2807 # Object method.
2808 # Rename (move) a GDAL dataset.
2809 # @param NewName String.
2810 # @param OldName String.
2811 #*
2812 sub Rename {
2813 }
2814 
2815 #** @method scalar TestCapability($cap)
2816 # Object method.
2817 # Test whether the driver has the specified capability.
2818 # @param cap A capability string (one of those returned by Capabilities).
2819 # @return a boolean value.
2820 #*
2821 sub TestCapability {
2822  my($self, $cap) = @_;
2823  my $h = $self->GetMetadata->{'DCAP_'.uc($cap)};
2824  return (defined($h) and $h eq 'YES') ? 1 : undef;
2825 }
2826 
2827 #** @method stdout_redirection_wrapper()
2828 #*
2829 sub stdout_redirection_wrapper {
2830  my ($self, $name, $sub, @params) = @_;
2831  my $object = 0;
2832  if ($name && blessed $name) {
2833  $object = $name;
2834  my $ref = $object->can('write');
2835  VSIStdoutSetRedirection($ref);
2836  $name = '/vsistdout/';
2837  }
2838  my $ds;
2839  eval {
2840  $ds = $sub->($self, $name, @params);
2841  };
2842  if ($object) {
2843  if ($ds) {
2844  $Geo::GDAL::stdout_redirection{tied(%$ds)} = $object;
2845  } else {
2846  VSIStdoutUnsetRedirection();
2847  $object->close;
2848  }
2849  }
2850  confess(last_error()) if $@;
2851  confess("Failed. Use Geo::OGR::Driver for vector drivers.") unless $ds;
2852  return $ds;
2853 }
2854 
2855 #** @class Geo::GDAL::Extent
2856 # @brief A rectangular area in projection coordinates: xmin, ymin, xmax, ymax.
2857 #*
2858 package Geo::GDAL::Extent;
2859 
2860 #** @method ExpandToInclude($extent)
2861 # Package subroutine.
2862 # Extends this extent to include the other extent.
2863 # @param extent Another Geo::GDAL::Extent object.
2864 #*
2865 sub ExpandToInclude {
2866  my ($self, $e) = @_;
2867  return if $e->IsEmpty;
2868  if ($self->IsEmpty) {
2869  @$self = @$e;
2870  } else {
2871  $self->[0] = $e->[0] if $e->[0] < $self->[0];
2872  $self->[1] = $e->[1] if $e->[1] < $self->[1];
2873  $self->[2] = $e->[2] if $e->[2] > $self->[2];
2874  $self->[3] = $e->[3] if $e->[3] > $self->[3];
2875  }
2876 }
2877 
2878 #** @method IsEmpty()
2879 #*
2880 sub IsEmpty {
2881  my $self = shift;
2882  return $self->[2] < $self->[0];
2883 }
2884 
2885 #** @method scalar Overlap($extent)
2886 # Package subroutine.
2887 # @param extent Another Geo::GDAL::Extent object.
2888 # @return A new, possibly empty, Geo::GDAL::Extent object, which
2889 # represents the joint area of the two extents.
2890 #*
2891 sub Overlap {
2892  my ($self, $e) = @_;
2893  return Geo::GDAL::Extent->new() unless $self->Overlaps($e);
2894  my $ret = Geo::GDAL::Extent->new($self);
2895  $ret->[0] = $e->[0] if $self->[0] < $e->[0];
2896  $ret->[1] = $e->[1] if $self->[1] < $e->[1];
2897  $ret->[2] = $e->[2] if $self->[2] > $e->[2];
2898  $ret->[3] = $e->[3] if $self->[3] > $e->[3];
2899  return $ret;
2900 }
2901 
2902 #** @method scalar Overlaps($extent)
2903 # Package subroutine.
2904 # @param extent Another Geo::GDAL::Extent object.
2905 # @return True if this extent overlaps the other extent, false otherwise.
2906 #*
2907 sub Overlaps {
2908  my ($self, $e) = @_;
2909  return $self->[0] < $e->[2] && $self->[2] > $e->[0] && $self->[1] < $e->[3] && $self->[3] > $e->[1];
2910 }
2911 
2912 #** @method list Size()
2913 # Package subroutine.
2914 # @return A list ($width, $height).
2915 #*
2916 sub Size {
2917  my $self = shift;
2918  return (0,0) if $self->IsEmpty;
2919  return ($self->[2] - $self->[0], $self->[3] - $self->[1]);
2920 }
2921 
2922 #** @method Geo::GDAL::Extent new(@params)
2923 # Package subroutine.
2924 # @param params nothing, a list ($xmin, $ymin, $xmax, $ymax), or an Extent object
2925 # @return A new Extent object (empty if no parameters, a copy of the parameter if it is an Extent object).
2926 #*
2927 sub new {
2928  my $class = shift;
2929  my $self;
2930  if (@_ == 0) {
2931  $self = [0,0,-1,0];
2932  } elsif (ref $_[0]) {
2933  @$self = @{$_[0]};
2934  } else {
2935  @$self = @_;
2936  }
2937  bless $self, $class;
2938  return $self;
2939 }
2940 
2941 #** @class Geo::GDAL::GCP
2942 # @brief A ground control point for georeferencing rasters.
2943 # @details
2944 #*
2945 package Geo::GDAL::GCP;
2946 
2947 use base qw(Geo::GDAL)
2948 
2949 #** @attr $Column
2950 # cell x coordinate (access as $gcp->{Column})
2951 #*
2952 
2953 #** @attr $Id
2954 # unique identifier (string) (access as $gcp->{Id})
2955 #*
2956 
2957 #** @attr $Info
2958 # informational message (access as $gcp->{Info})
2959 #*
2960 
2961 #** @attr $Row
2962 # cell y coordinate (access as $gcp->{Row})
2963 #*
2964 
2965 #** @attr $X
2966 # projection coordinate (access as $gcp->{X})
2967 #*
2968 
2969 #** @attr $Y
2970 # projection coordinate (access as $gcp->{Y})
2971 #*
2972 
2973 #** @attr $Z
2974 # projection coordinate (access as $gcp->{Z})
2975 #*
2976 
2977 #** @method scalar new($x = 0.0, $y = 0.0, $z = 0.0, $column = 0.0, $row = 0.0, $info = "", $id = "")
2978 # Class method.
2979 # @param x projection coordinate
2980 # @param y projection coordinate
2981 # @param z projection coordinate
2982 # @param column cell x coordinate
2983 # @param row cell y coordinate
2984 # @param info informational message
2985 # @param id unique identifier (string)
2986 # @return a new Geo::GDAL::GCP object
2987 #*
2988 sub new {
2989  my $pkg = shift;
2990  my $self = Geo::GDALc::new_GCP(@_);
2991  bless $self, $pkg if defined($self);
2992 }
2993 
2994 #** @class Geo::GDAL::GeoTransform
2995 # @brief An array of affine transformation coefficients.
2996 # @details The geo transformation has the form
2997 # \code
2998 # x = a + column * b + row * c
2999 # y = d + column * e + row * f
3000 # \endcode
3001 # where
3002 # (column,row) is the location in cell coordinates, and
3003 # (x,y) is the location in projection coordinates, or vice versa.
3004 # A Geo::GDAL::GeoTransform object is a reference to an anonymous array [a,b,c,d,e,f].
3005 #*
3006 package Geo::GDAL::GeoTransform;
3007 
3008 #** @method Apply($x, $y)
3009 # Object method.
3010 # @param x Column or x, or a reference to an array of columns or x's
3011 # @param y Row or y, or a reference to an array of rows or y's
3012 # @return a list (x, y), where x and y are the transformed coordinates
3013 # or references to arrays of transformed coordinates.
3014 #*
3015 sub Apply {
3016  my ($self, $columns, $rows) = @_;
3017  return Geo::GDAL::ApplyGeoTransform($self, $columns, $rows) unless ref($columns) eq 'ARRAY';
3018  my (@x, @y);
3019  for my $i (0..$#$columns) {
3020  ($x[$i], $y[$i]) =
3021  Geo::GDAL::ApplyGeoTransform($self, $columns->[$i], $rows->[$i]);
3022  }
3023  return (\@x, \@y);
3024 }
3025 
3026 #** @method Inv()
3027 # Object method.
3028 # @return a new Geo::GDAL::GeoTransform object, which is the inverse
3029 # of this one (in void context changes this object).
3030 #*
3031 sub Inv {
3032  my $self = shift;
3033  my @inv = Geo::GDAL::InvGeoTransform($self);
3034  return Geo::GDAL::GeoTransform->new(@inv) if defined wantarray;
3035  @$self = @inv;
3036 }
3037 
3038 #** @method NorthUp()
3039 #*
3040 sub NorthUp {
3041  my $self = shift;
3042  return $self->[2] == 0 && $self->[4] == 0;
3043 }
3044 
3045 #** @method new(@params)
3046 # Class method.
3047 # @param params nothing, a reference to an array [a,b,c,d,e,f], a list
3048 # (a,b,c,d,e,f), or named parameters
3049 # - \a GCPs A reference to an array of Geo::GDAL::GCP objects.
3050 # - \a ApproxOK Minimize the error in the coefficients (integer, default is 1 (true), used with GCPs).
3051 # - \a Extent A Geo::GDAL::Extent object used to obtain the coordinates of the up left corner position.
3052 # - \a CellSize The cell size (width and height) (default is 1, used with Extent).
3053 #
3054 # @note When Extent is specifid, the created geo transform will be
3055 # north up, have square cells, and coefficient f will be -1 times the
3056 # cell size (image y - row - will increase downwards and projection y
3057 # will increase upwards).
3058 # @return a new Geo::GDAL::GeoTransform object.
3059 #*
3060 sub new {
3061  my $class = shift;
3062  my $self;
3063  if (@_ == 0) {
3064  $self = [0,1,0,0,0,1];
3065  } elsif (ref $_[0]) {
3066  @$self = @{$_[0]};
3067  } elsif ($_[0] =~ /^[a-zA-Z]/i) {
3068  my $p = named_parameters(\@_, GCPs => undef, ApproxOK => 1, Extent => undef, CellSize => 1);
3069  if ($p->{gcps}) {
3070  $self = Geo::GDAL::GCPsToGeoTransform($p->{gcps}, $p->{approxok});
3071  } elsif ($p->{extent}) {
3072  $self = Geo::GDAL::GeoTransform->new($p->{extent}[0], $p->{cellsize}, 0, $p->{extent}[2], 0, -$p->{cellsize});
3073  } else {
3074  error("Missing GCPs or Extent");
3075  }
3076  } else {
3077  my @a = @_;
3078  $self = \@a;
3079  }
3080  bless $self, $class;
3081 }
3082 
3083 #** @class Geo::GDAL::MajorObject
3084 # @brief An object, which holds meta data.
3085 # @details
3086 #*
3087 package Geo::GDAL::MajorObject;
3088 
3089 use base qw(Geo::GDAL)
3090 
3091 #** @method scalar Description($description)
3092 # Object method.
3093 # @param description [optional]
3094 # @return the description in a non-void context.
3095 #*
3096 sub Description {
3097  my($self, $desc) = @_;
3098  SetDescription($self, $desc) if defined $desc;
3099  GetDescription($self) if defined wantarray;
3100 }
3101 
3102 #** @method Domains()
3103 # Package subroutine.
3104 # @return the class specific DOMAINS list
3105 #*
3106 sub Domains {
3107  return @DOMAINS;
3108 }
3109 
3110 #** @method scalar GetDescription()
3111 # Object method.
3112 # @return
3113 #*
3114 sub GetDescription {
3115 }
3116 
3117 #** @method hash reference GetMetadata($domain = "")
3118 # Object method.
3119 # @note see Metadata
3120 # @param domain
3121 # @return
3122 #*
3123 sub GetMetadata {
3124 }
3125 
3126 #** @method GetMetadataDomainList()
3127 #*
3128 sub GetMetadataDomainList {
3129 }
3130 
3131 #** @method hash reference Metadata(hashref metadata = undef, $domain = '')
3132 # Object method.
3133 # @param metadata
3134 # @param domain
3135 # @return the metadata in a non-void context.
3136 #*
3137 sub Metadata {
3138  my $self = shift,
3139  my $metadata = ref $_[0] ? shift : undef;
3140  my $domain = shift // '';
3141  SetMetadata($self, $metadata, $domain) if defined $metadata;
3142  GetMetadata($self, $domain) if defined wantarray;
3143 }
3144 
3145 #** @method SetDescription($NewDesc)
3146 # Object method.
3147 # @param NewDesc
3148 #
3149 #*
3150 sub SetDescription {
3151 }
3152 
3153 #** @method SetMetadata(hashref metadata, $domain = "")
3154 # Object method.
3155 # @note see Metadata
3156 # @param metadata
3157 # @param domain
3158 #
3159 #*
3160 sub SetMetadata {
3161 }
3162 
3163 #** @class Geo::GDAL::RasterAttributeTable
3164 # @brief An attribute table in a raster band.
3165 # @details
3166 #*
3167 package Geo::GDAL::RasterAttributeTable;
3168 
3169 use base qw(Geo::GDAL)
3170 
3171 #** @method Band()
3172 #*
3173 sub Band {
3174  my $self = shift;
3175  parent($self);
3176 }
3177 
3178 #** @method ChangesAreWrittenToFile()
3179 #*
3180 sub ChangesAreWrittenToFile {
3181 }
3182 
3183 #** @method Geo::GDAL::RasterAttributeTable Clone()
3184 # Object method.
3185 # @return a new Geo::GDAL::RasterAttributeTable object
3186 #*
3187 sub Clone {
3188 }
3189 
3190 #** @method hash Columns(%columns)
3191 # Object method.
3192 # A get/set method for the columns of the RAT
3193 # @param columns optional, a the keys are column names and the values are anonymous
3194 # hashes with keys Type and Usage
3195 # @return a hash similar to the optional input parameter
3196 #*
3197 sub Columns {
3198  my $self = shift;
3199  my %columns;
3200  if (@_) { # create columns
3201  %columns = @_;
3202  for my $name (keys %columns) {
3203  $self->CreateColumn($name, $columns{$name}{Type}, $columns{$name}{Usage});
3204  }
3205  }
3206  %columns = ();
3207  for my $c (0..$self->GetColumnCount-1) {
3208  my $name = $self->GetNameOfCol($c);
3209  $columns{$name}{Type} = $self->GetTypeOfCol($c);
3210  $columns{$name}{Usage} = $self->GetUsageOfCol($c);
3211  }
3212  return %columns;
3213 }
3214 
3215 #** @method CreateColumn($name, $type, $usage)
3216 # Object method.
3217 # @param name
3218 # @param type one of FieldTypes
3219 # @param usage one of FieldUsages
3220 #*
3221 sub CreateColumn {
3222  my($self, $name, $type, $usage) = @_;
3223  for my $color (qw/Red Green Blue Alpha/) {
3224  carp "RAT column type will be 'Integer' for usage '$color'." if $usage eq $color and $type ne 'Integer';
3225  }
3226  $type = s2i(rat_field_type => $type);
3227  $usage = s2i(rat_field_usage => $usage);
3228  _CreateColumn($self, $name, $type, $usage);
3229 }
3230 
3231 #** @method DumpReadable()
3232 #*
3233 sub DumpReadable {
3234 }
3235 
3236 #** @method list FieldTypes()
3237 # Package subroutine.
3238 # @return
3239 #*
3240 sub FieldTypes {
3241  return @FIELD_TYPES;
3242 }
3243 
3244 #** @method list FieldUsages()
3245 # Package subroutine.
3246 # @return
3247 #*
3248 sub FieldUsages {
3249  return @FIELD_USAGES;
3250 }
3251 
3252 #** @method scalar GetColOfUsage($usage)
3253 # Object method.
3254 # @param usage
3255 # @return
3256 #*
3257 sub GetColOfUsage {
3258  my($self, $usage) = @_;
3259  _GetColOfUsage($self, s2i(rat_field_usage => $usage));
3260 }
3261 
3262 #** @method scalar GetColumnCount()
3263 # Object method.
3264 # @return
3265 #*
3266 sub GetColumnCount {
3267 }
3268 
3269 #** @method scalar GetNameOfCol($column)
3270 # Object method.
3271 # @param column
3272 # @return
3273 #*
3274 sub GetNameOfCol {
3275 }
3276 
3277 #** @method scalar GetRowCount()
3278 # Object method.
3279 #*
3280 sub GetRowCount {
3281 }
3282 
3283 #** @method scalar GetRowOfValue($value)
3284 # Object method.
3285 # @param value a cell value
3286 # @return row index or -1
3287 #*
3288 sub GetRowOfValue {
3289 }
3290 
3291 #** @method GetTableType()
3292 #*
3293 sub GetTableType {
3294 }
3295 
3296 #** @method scalar GetTypeOfCol($column)
3297 # Object method.
3298 # @param column
3299 # @return
3300 #*
3301 sub GetTypeOfCol {
3302  my($self, $col) = @_;
3303  i2s(rat_field_type => _GetTypeOfCol($self, $col));
3304 }
3305 
3306 #** @method scalar GetUsageOfCol($column)
3307 # Object method.
3308 # @param column
3309 # @return
3310 #*
3311 sub GetUsageOfCol {
3312  my($self, $col) = @_;
3313  i2s(rat_field_usage => _GetUsageOfCol($self, $col));
3314 }
3315 
3316 #** @method scalar GetValueAsDouble($row, $column)
3317 # Object method.
3318 # @param row
3319 # @param column
3320 # @return
3321 #*
3322 sub GetValueAsDouble {
3323 }
3324 
3325 #** @method scalar GetValueAsInt($row, $column)
3326 # Object method.
3327 # @param row
3328 # @param column
3329 # @return
3330 #*
3331 sub GetValueAsInt {
3332 }
3333 
3334 #** @method scalar GetValueAsString($row, $column)
3335 # Object method.
3336 # @param row
3337 # @param column
3338 # @return
3339 #*
3340 sub GetValueAsString {
3341 }
3342 
3343 #** @method LinearBinning($Row0MinIn, $BinSizeIn)
3344 # Object method.
3345 # @param Row0MinIn [optional] the lower bound (cell value) of the first category.
3346 # @param BinSizeIn [optional] the width of each category (in cell value units).
3347 # @return ($Row0MinIn, $BinSizeIn) or an empty list if LinearBinning is not set.
3348 #*
3349 sub LinearBinning {
3350  my $self = shift;
3351  SetLinearBinning($self, @_) if @_ > 0;
3352  return unless defined wantarray;
3353  my @a = GetLinearBinning($self);
3354  return $a[0] ? ($a[1], $a[2]) : ();
3355 }
3356 
3357 #** @method SetRowCount($count)
3358 # Object method.
3359 # @param count
3360 #
3361 #*
3362 sub SetRowCount {
3363 }
3364 
3365 #** @method SetTableType()
3366 #*
3367 sub SetTableType {
3368 }
3369 
3370 #** @method SetValueAsDouble($row, $column, $value)
3371 # Object method.
3372 # @param row
3373 # @param column
3374 # @param value
3375 #
3376 #*
3377 sub SetValueAsDouble {
3378 }
3379 
3380 #** @method SetValueAsInt($row, $column, $value)
3381 # Object method.
3382 # @param row
3383 # @param column
3384 # @param value
3385 #
3386 #*
3387 sub SetValueAsInt {
3388 }
3389 
3390 #** @method SetValueAsString($row, $column, $value)
3391 # Object method.
3392 # @param row
3393 # @param column
3394 # @param value
3395 #
3396 #*
3397 sub SetValueAsString {
3398 }
3399 
3400 #** @method scalar Value($row, $column, $value)
3401 # Object method.
3402 # @param row
3403 # @param column
3404 # @param value [optional]
3405 # @return
3406 #*
3407 sub Value {
3408  my($self, $row, $column) = @_;
3409  SetValueAsString($self, $row, $column, $_[3]) if defined $_[3];
3410  return unless defined wantarray;
3411  GetValueAsString($self, $row, $column);
3412 }
3413 
3414 #** @method Geo::GDAL::RasterAttributeTable new()
3415 # Class method.
3416 # @return a new Geo::GDAL::RasterAttributeTable object
3417 #*
3418 sub new {
3419  my $pkg = shift;
3420  my $self = Geo::GDALc::new_RasterAttributeTable(@_);
3421  bless $self, $pkg if defined($self);
3422 }
3423 
3424 #** @class Geo::GDAL::Transformer
3425 # @brief
3426 # @details This class is not yet documented for the GDAL Perl bindings.
3427 # @todo Test and document.
3428 #*
3429 package Geo::GDAL::Transformer;
3430 
3431 use base qw(Geo::GDAL)
3432 
3433 #** @method TransformGeolocations()
3434 #*
3435 sub TransformGeolocations {
3437 
3438 #** @method TransformPoint()
3439 #*
3440 sub TransformPoint {
3441 }
3442 
3443 #** @method new()
3444 #*
3445 sub new {
3446  my $pkg = shift;
3447  my $self = Geo::GDALc::new_Transformer(@_);
3448  bless $self, $pkg if defined($self);
3449 }
3450 
3451 #** @class Geo::GDAL::VSIF
3452 # @brief A GDAL virtual file system.
3453 # @details
3454 #*
3455 package Geo::GDAL::VSIF;
3456 
3457 use base qw(Exporter)
3458 
3459 #** @method Close()
3460 # Object method.
3461 #*
3462 sub Close {
3463  my ($self) = @_;
3464  Geo::GDAL::VSIFCloseL($self);
3465 }
3466 
3467 #** @method Flush()
3468 #*
3469 sub Flush {
3470  my ($self) = @_;
3471  Geo::GDAL::VSIFFlushL($self);
3472 }
3473 
3474 #** @method MkDir($path)
3475 # Package subroutine.
3476 # Make a directory.
3477 # @param path The directory to make.
3478 # @note The name of this method is VSIMkdir in GDAL.
3479 #*
3480 sub MkDir {
3481  my ($path) = @_;
3482  # mode unused in CPL
3483  Geo::GDAL::Mkdir($path, 0);
3484 }
3485 
3486 #** @method Geo::GDAL::VSIF Open($filename, $mode)
3487 # Package subroutine.
3488 # @param filename Name of the file to open. For example "/vsimem/x".
3489 # @param mode Access mode. 'r', 'r+', 'w', etc.
3490 # @return A file handle on success.
3491 #*
3492 sub Open {
3493  my ($path, $mode) = @_;
3494  my $self = Geo::GDAL::VSIFOpenL($path, $mode);
3495  bless $self, 'Geo::GDAL::VSIF';
3496 }
3497 
3498 #** @method scalar Read($count)
3499 # Object method.
3500 # @param count The number of bytes to read from the file.
3501 # @return A byte string.
3502 #*
3503 sub Read {
3504  my ($self, $count) = @_;
3505  Geo::GDAL::VSIFReadL($count, $self);
3506 }
3507 
3508 #** @method list ReadDir($dir)
3509 # Package subroutine.
3510 # @return Contents of a directory in an anonymous array or as a list.
3511 #*
3512 sub ReadDir {
3513  my ($path) = @_;
3514  Geo::GDAL::ReadDir($path);
3515 }
3516 
3517 #** @method scalar ReadDirRecursive($dir)
3518 # Package subroutine.
3519 # @note Give the directory in the form '/vsimem', i.e., without trailing '/'.
3520 # @return Contents of a directory tree in an anonymous array.
3521 #*
3522 sub ReadDirRecursive {
3523  my ($path) = @_;
3524  Geo::GDAL::ReadDirRecursive($path);
3525 }
3526 
3527 #** @method Rename($old, $new)
3528 # Package subroutine.
3529 # Rename a file.
3530 # @note The name of this method is VSIRename in GDAL.
3531 #*
3532 sub Rename {
3533  my ($old, $new) = @_;
3534  Geo::GDAL::Rename($old, $new);
3535 }
3536 
3537 #** @method RmDir($path)
3538 # Package subroutine.
3539 # Remove a directory.
3540 # @note The name of this method is VSIRmdir in GDAL.
3541 #*
3542 sub RmDir {
3543  my ($dirname, $recursive) = @_;
3544  eval {
3545  if (!$recursive) {
3546  Geo::GDAL::Rmdir($dirname);
3547  } else {
3548  for my $f (ReadDir($dirname)) {
3549  next if $f eq '..' or $f eq '.';
3550  my @s = Stat($dirname.'/'.$f);
3551  if ($s[0] eq 'f') {
3552  Unlink($dirname.'/'.$f);
3553  } elsif ($s[0] eq 'd') {
3554  Rmdir($dirname.'/'.$f, 1);
3555  Rmdir($dirname.'/'.$f);
3556  }
3557  }
3558  RmDir($dirname);
3559  }
3560  };
3561  if ($@) {
3562  my $r = $recursive ? ' recursively' : '';
3563  error("Cannot remove directory \"$dirname\"$r.");
3564  }
3565 }
3566 
3567 #** @method Seek($offset, $whence)
3568 # Object method.
3569 #*
3570 sub Seek {
3571  my ($self, $offset, $whence) = @_;
3572  Geo::GDAL::VSIFSeekL($self, $offset, $whence);
3573 }
3574 
3575 #** @method list Stat($filename)
3576 # Package subroutine.
3577 # @return ($filemode, $filesize). filemode is f for a plain file, d
3578 # for a directory, l for a symbolic link, p for a named pipe (FIFO), S
3579 # for a socket, b for a block special file, and c for a character
3580 # special file.
3581 #*
3582 sub Stat {
3583  my ($path) = @_;
3584  Geo::GDAL::Stat($path);
3585 }
3586 
3587 #** @method scalar Tell()
3588 # Object method.
3589 #*
3590 sub Tell {
3591  my ($self) = @_;
3592  Geo::GDAL::VSIFTellL($self);
3593 }
3594 
3595 #** @method Truncate($new_size)
3596 # Object method.
3597 #*
3598 sub Truncate {
3599  my ($self, $new_size) = @_;
3600  Geo::GDAL::VSIFTruncateL($self, $new_size);
3601 }
3602 
3603 #** @method Unlink($filename)
3604 # Package subroutine.
3605 # @param filename The file to delete.
3606 # @return 0 on success and -1 on an error.
3607 #*
3608 sub Unlink {
3609  my ($filename) = @_;
3610  Geo::GDAL::Unlink($filename);
3611 }
3612 
3613 #** @method Write($scalar)
3614 # Object method.
3615 # @param scalar The byte string to write to the file.
3616 # @return Number of bytes written into the file.
3617 #*
3618 sub Write {
3619  my ($self, $data) = @_;
3620  Geo::GDAL::VSIFWriteL($data, $self);
3621 }
3622 
3623 #** @class Geo::GDAL::VSILFILE
3624 #*
3625 package Geo::GDAL::VSILFILE;
3626 
3627 use base qw(Geo::GDAL)
3628 
3629 #** @class Geo::GDAL::XML
3630 # @brief A simple XML parser
3631 # @details
3632 #*
3633 package Geo::GDAL::XML;
3634 
3635 #** @method new($string)
3636 # Object method.
3637 # @param string String containing XML.
3638 # @return A new Geo::GDAL::XML object, which is a reference to an anonymous array.
3639 #*
3640 sub new {
3641  my $class = shift;
3642  my $xml = shift // '';
3643  my $self = ParseXMLString($xml);
3644  bless $self, $class;
3645  $self->traverse(sub {my $node = shift; bless $node, $class});
3646  return $self;
3647 }
3648 
3649 #** @method serialize()
3650 # Object method.
3651 # @return The XML serialized into a string.
3652 #*
3653 sub serialize {
3654  my $self = shift;
3655  return SerializeXMLTree($self);
3656 }
3657 1;
3658 # This file was automatically generated by SWIG (http://www.swig.org).
3659 # Version 2.0.12
3660 #
3661 # Do not make changes to this file unless you know what you are doing--modify
3662 # the SWIG interface file instead.
3663 }
3664 
3665 #** @method traverse(coderef subroutine)
3666 # Object method.
3667 # @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.
3668 #*
3669 sub traverse {
3670  my ($self, $sub) = @_;
3671  my $type = $self->[0];
3672  my $data = $self->[1];
3673  $type = NodeType($type);
3674  $sub->($self, $type, $data);
3675  for my $child (@{$self}[2..$#$self]) {
3676  traverse($child, $sub);
3677  }
3678 }
3679 
3680 #** @class Geo::GNM
3681 # @brief Base class for geographical networks in GDAL.
3682 # @details
3683 #*
3684 package Geo::GNM;
3685 
3686 #** @method CastToGenericNetwork()
3687 #*
3688 sub CastToGenericNetwork {
3689 }
3690 
3691 #** @method CastToNetwork()
3692 #*
3693 sub CastToNetwork {
3694 }
3695 
3696 #** @method GATConnectedComponents()
3697 #*
3698 sub GATConnectedComponents {
3699 }
3700 
3701 #** @method GATDijkstraShortestPath()
3702 #*
3703 sub GATDijkstraShortestPath {
3704 }
3705 
3706 #** @method GATKShortestPath()
3707 #*
3708 sub GATKShortestPath {
3709 }
3710 
3711 #** @method GNM_EDGE_DIR_BOTH()
3712 #*
3713 sub GNM_EDGE_DIR_BOTH {
3714 }
3715 
3716 #** @method GNM_EDGE_DIR_SRCTOTGT()
3717 #*
3718 sub GNM_EDGE_DIR_SRCTOTGT {
3719 }
3720 
3721 #** @method GNM_EDGE_DIR_TGTTOSRC()
3722 #*
3723 sub GNM_EDGE_DIR_TGTTOSRC {
3724  1;
3725 }
3726 
3727 #** @class Geo::GNM::GenericNetwork
3728 # @details
3729 #*
3730 package Geo::GNM::GenericNetwork;
3731 
3732 use base qw(Geo::GNM::Network Geo::GNM)
3733 
3734 #** @method ChangeAllBlockState()
3735 #*
3736 sub ChangeAllBlockState {
3737 }
3738 
3739 #** @method ChangeBlockState()
3740 #*
3741 sub ChangeBlockState {
3742 }
3743 
3744 #** @method ConnectFeatures()
3745 #*
3746 sub ConnectFeatures {
3747 }
3748 
3749 #** @method ConnectPointsByLines()
3750 #*
3751 sub ConnectPointsByLines {
3752 }
3753 
3754 #** @method CreateRule()
3755 #*
3756 sub CreateRule {
3757 }
3758 
3759 #** @method DeleteAllRules()
3760 #*
3761 sub DeleteAllRules {
3762 }
3763 
3764 #** @method DeleteRule()
3765 #*
3766 sub DeleteRule {
3767 }
3768 
3769 #** @method DisconnectFeatures()
3770 #*
3771 sub DisconnectFeatures {
3772 }
3773 
3774 #** @method DisconnectFeaturesWithId()
3775 #*
3776 sub DisconnectFeaturesWithId {
3777 }
3778 
3779 #** @method GetRules()
3780 #*
3781 sub GetRules {
3782 }
3783 
3784 #** @method ReconnectFeatures()
3785 #*
3786 sub ReconnectFeatures {
3787 }
3788 
3789 #** @class Geo::GNM::MajorObject
3790 # @details
3791 #*
3792 package Geo::GNM::MajorObject;
3793 
3794 #** @class Geo::GNM::Network
3795 # @details
3796 #*
3797 package Geo::GNM::Network;
3798 
3799 use base qw(Geo::GDAL::MajorObject Geo::GNM)
3800 
3801 #** @method CommitTransaction()
3802 #*
3803 sub CommitTransaction {
3804 }
3805 
3806 #** @method CopyLayer()
3807 #*
3808 sub CopyLayer {
3809 }
3810 
3811 #** @method DisconnectAll()
3812 #*
3813 sub DisconnectAll {
3814 }
3815 
3816 #** @method GetFeatureByGlobalFID()
3817 #*
3818 sub GetFeatureByGlobalFID {
3819 }
3820 
3821 #** @method GetFileList()
3822 #*
3823 sub GetFileList {
3824 }
3825 
3826 #** @method GetLayerByIndex()
3827 #*
3828 sub GetLayerByIndex {
3829 }
3830 
3831 #** @method GetLayerByName()
3832 #*
3833 sub GetLayerByName {
3834 }
3835 
3836 #** @method GetLayerCount()
3837 #*
3838 sub GetLayerCount {
3839 }
3840 
3841 #** @method GetName()
3842 #*
3843 sub GetName {
3844 }
3845 
3846 #** @method GetPath()
3847 #*
3848 sub GetPath {
3849 }
3850 
3851 #** @method GetProjection()
3852 #*
3853 sub GetProjection {
3854 }
3855 
3856 #** @method GetProjectionRef()
3857 #*
3858 sub GetProjectionRef {
3859 }
3860 
3861 #** @method GetVersion()
3862 #*
3863 sub GetVersion {
3864 }
3865 
3866 #** @method RollbackTransaction()
3867 #*
3868 sub RollbackTransaction {
3869 }
3870 
3871 #** @method StartTransaction()
3872 #*
3873 sub StartTransaction {
3874 }
3875 
3876 #** @class Geo::OGR
3877 # @brief OGR utility functions.
3878 # @details A wrapper for many OGR utility functions and a root class for all
3879 # OGR classes.
3880 #*
3881 package Geo::OGR;
3882 
3883 #** @method list ByteOrders()
3884 # Package subroutine.
3885 # @return a list of byte order types, XDR and NDR. XDR denotes
3886 # big-endian and NDR denotes little-endian.
3887 #*
3888 sub ByteOrders {
3889 }
3890 
3891 #** @method Geo::GDAL::Driver Driver($name)
3892 # Package subroutine.
3893 # A.k.a GetDriver.
3894 # @param name the short name of the driver.
3895 # @note No check is made that the driver is actually a vector driver.
3896 # @return a Geo::GDAL::Driver object.
3897 #*
3898 sub Driver {
3899  return 'Geo::GDAL::Driver' unless @_;
3900  bless Geo::GDAL::Driver(@_), 'Geo::OGR::Driver';
3901 }
3902 
3903 #** @method list DriverNames()
3904 # Package subroutine.
3905 # A.k.a GetDriverNames
3906 # \code
3907 # perl -MGeo::GDAL -e '@d=Geo::OGR::DriverNames;print "@d\n"'
3908 # \endcode
3909 # @note Use Geo::GDAL::DriverNames for raster drivers.
3910 # @return a list of the short names of all available GDAL vector drivers.
3911 #*
3912 sub DriverNames {
3913 }
3914 
3915 #** @method list Drivers()
3916 # Package subroutine.
3917 # @note Use Geo::GDAL::Drivers for raster drivers.
3918 # @return a list of all available GDAL vector drivers.
3919 #*
3920 sub Drivers {
3921  my @drivers;
3922  for my $i (0..GetDriverCount()-1) {
3923  my $driver = Geo::GDAL::GetDriver($i);
3924  push @drivers, $driver if $driver->TestCapability('VECTOR');
3925  }
3926  return @drivers;
3927 }
3928 
3929 #** @method Flatten()
3930 #*
3931 sub Flatten {
3932 }
3933 
3934 #** @method scalar GeometryTypeModify($type, $modifier)
3935 # Object method.
3936 # @param type a geometry type (one of Geo::OGR::GeometryTypes).
3937 # @param modifier one of 'flatten', 'set_Z', 'make_collection', 'make_curve', or 'make_linear'.
3938 # @return modified geometry type.
3939 #*
3940 sub GeometryTypeModify {
3941  my($type, $modifier) = @_;
3942  $type = s2i(geometry_type => $type);
3943  return i2s(geometry_type => GT_Flatten($type)) if $modifier =~ /flat/i;
3944  return i2s(geometry_type => GT_SetZ($type)) if $modifier =~ /z/i;
3945  return i2s(geometry_type => GT_GetCollection($type)) if $modifier =~ /collection/i;
3946  return i2s(geometry_type => GT_GetCurve($type)) if $modifier =~ /curve/i;
3947  return i2s(geometry_type => GT_GetLinear($type)) if $modifier =~ /linear/i;
3948  error(1, $modifier, {Flatten => 1, SetZ => 1, GetCollection => 1, GetCurve => 1, GetLinear => 1});
3949 }
3950 
3951 #** @method scalar GeometryTypeTest($type, $test, $type2)
3952 # Object method.
3953 # @param type a geometry type (one of Geo::OGR::GeometryTypes).
3954 # @param test one of 'has_z', 'is_subclass_of', 'is_curve', 'is_surface', or 'is_non_linear'.
3955 # @param type2 a geometry type (one of Geo::OGR::GeometryTypes). Required for 'is_subclass_of' test.
3956 # @return result of the test.
3957 #*
3958 sub GeometryTypeTest {
3959  my($type, $test, $type2) = @_;
3960  $type = s2i(geometry_type => $type);
3961  if (defined $type2) {
3962  $type = s2i(geometry_type => $type);
3963  } else {
3964  error("Usage: GeometryTypeTest(type1, 'is_subclass_of', type2).") if $test =~ /subclass/i;
3965  }
3966  return GT_HasZ($type) if $test =~ /z/i;
3967  return GT_IsSubClassOf($type, $type2) if $test =~ /subclass/i;
3968  return GT_IsCurve($type) if $test =~ /curve/i;
3969  return GT_IsSurface($type) if $test =~ /surface/i;
3970  return GT_IsNonLinear($type) if $test =~ /linear/i;
3971  error(1, $test, {HasZ => 1, IsSubClassOf => 1, IsCurve => 1, IsSurface => 1, IsNonLinear => 1});
3972 }
3973 
3974 #** @method list GeometryTypes()
3975 # Package subroutine.
3976 # @return a list of all geometry types, currently:
3977 # CircularString, CircularStringM, CircularStringZ, CircularStringZM, CompoundCurve, CompoundCurveM, CompoundCurveZ, CompoundCurveZM, Curve, CurveM, CurvePolygon, CurvePolygonM, CurvePolygonZ, CurvePolygonZM, CurveZ, CurveZM, GeometryCollection, GeometryCollection25D, GeometryCollectionM, GeometryCollectionZM, LineString, LineString25D, LineStringM, LineStringZM, LinearRing, MultiCurve, MultiCurveM, MultiCurveZ, MultiCurveZM, MultiLineString, MultiLineString25D, MultiLineStringM, MultiLineStringZM, MultiPoint, MultiPoint25D, MultiPointM, MultiPointZM, MultiPolygon, MultiPolygon25D, MultiPolygonM, MultiPolygonZM, MultiSurface, MultiSurfaceM, MultiSurfaceZ, MultiSurfaceZM, None, Point, Point25D, PointM, PointZM, Polygon, Polygon25D, PolygonM, PolygonZM, PolyhedralSurface, PolyhedralSurfaceM, PolyhedralSurfaceZ, PolyhedralSurfaceZM, Surface, SurfaceM, SurfaceZ, SurfaceZM, TIN, TINM, TINZ, TINZM, Triangle, TriangleM, TriangleZ, TriangleZM, and Unknown.
3978 #*
3979 sub GeometryTypes {
3980  1;
3981  # This file was automatically generated by SWIG (http://www.swig.org).
3982  # Version 2.0.12
3983  #
3984  # Do not make changes to this file unless you know what you are doing--modify
3985  # the SWIG interface file instead.
3986 }
3987 
3988 #** @method GetNonLinearGeometriesEnabledFlag()
3989 #*
3990 sub GetNonLinearGeometriesEnabledFlag {
3991 }
3992 
3993 #** @method GetOpenDSCount()
3994 #*
3995 sub GetOpenDSCount {
3996 }
3997 
3998 #** @method HasM()
3999 #*
4000 sub HasM {
4001 }
4002 
4003 #** @method HasZ()
4004 #*
4005 sub HasZ {
4006 }
4007 
4008 #** @method Geo::GDAL::Dataset Open($name, $update = 0)
4009 # Object method.
4010 # Open a vector data source.
4011 # @param name The data source string (directory, filename, etc.).
4012 # @param update Whether to open the data source in update mode (default is not).
4013 # @return a new Geo::GDAL::Dataset object.
4014 #*
4015 sub Open {
4016  my @p = @_; # name, update
4017  my @flags = qw/VECTOR/;
4018  push @flags, qw/UPDATE/ if $p[1];
4019  my $dataset = Geo::GDAL::OpenEx($p[0], \@flags);
4020  error("Failed to open $p[0]. Is it a vector dataset?") unless $dataset;
4021  return $dataset;
4022 }
4023 
4024 #** @method Geo::GDAL::Dataset OpenShared($name, $update = 0)
4025 # Object method.
4026 # Open a vector data source in shared mode.
4027 # @param name The data source string (directory, filename, etc.).
4028 # @param update Whether to open the data source in update mode.
4029 # @return a new Geo::GDAL::Dataset object.
4030 #*
4031 sub OpenShared {
4032  my @p = @_; # name, update
4033  my @flags = qw/VECTOR SHARED/;
4034  push @flags, qw/UPDATE/ if $p[1];
4035  my $dataset = Geo::GDAL::OpenEx($p[0], \@flags);
4036  error("Failed to open $p[0]. Is it a vector dataset?") unless $dataset;
4037  return $dataset;
4038 }
4039 
4040 #** @method SetGenerate_DB2_V72_BYTE_ORDER($Generate_DB2_V72_BYTE_ORDER)
4041 # Object method.
4042 # Needed only on IBM DB2.
4043 #*
4044 sub SetGenerate_DB2_V72_BYTE_ORDER {
4045 }
4046 
4047 #** @method SetNonLinearGeometriesEnabledFlag()
4048 #*
4049 sub SetNonLinearGeometriesEnabledFlag {
4050 }
4051 
4052 #** @class Geo::OGR::DataSource
4053 # @brief A vector dataset.
4054 # @details This is a legacy class which should not be
4055 # used in new code. Use Geo::GDAL::Dataset.
4056 #*
4057 package Geo::OGR::DataSource;
4058 
4059 #** @method Geo::GDAL::Dataset Open()
4060 # Package subroutine.
4061 # The same as Geo::OGR::Open
4062 #*
4063 sub Open {
4064 }
4065 
4066 #** @method Geo::GDAL::Dataset OpenShared()
4067 # Package subroutine.
4068 # The same as Geo::OGR::OpenShared
4069 #*
4070 sub OpenShared {
4071 }
4072 
4073 #** @class Geo::OGR::Driver
4074 # @brief A vector format driver.
4075 # @details This is a legacy class which
4076 # should not be used in new code. Use Geo::GDAL::Driver.
4077 #*
4078 package Geo::OGR::Driver;
4079 
4080 use base qw(Geo::GDAL::Driver)
4081 
4082 #** @method Geo::GDAL::Dataset Copy(Geo::GDAL::Dataset source, $name, arrayref options = undef)
4083 # Object method.
4084 # Copy a vector data source into a new data source with this driver.
4085 # @param source The Geo::GDAL::Dataset object to be copied.
4086 # @param name The name for the new data source.
4087 # @param options Driver specific options. In addition to options
4088 # specified in GDAL documentation the option STRICT can be set to 'NO'
4089 # for a more relaxed copy. Otherwise the STRICT is 'YES'.
4090 # @note The order of the first two parameters is different from that in Geo::GDAL::Driver::Copy.
4091 # @return a new Geo::GDAL::Dataset object.
4092 #*
4093 sub Copy {
4094  my ($self, @p) = @_; # src, name, options
4095  my $strict = 1; # the default in bindings
4096  $strict = 0 if $p[2] && $p[2]->{STRICT} eq 'NO';
4097  $self->SUPER::Copy($p[1], $p[0], $strict, @{$p[2..4]}); # path, src, strict, options, cb, cb_data
4098 }
4099 
4100 #** @method Geo::GDAL::Dataset Create($name, hashref options = undef )
4101 # Object method.
4102 # Create a new vector data source using this driver.
4103 # @param name The data source name.
4104 # @param options Driver specific dataset creation options.
4105 #*
4106 sub Create {
4107  my ($self, $name, $options) = @_; # name, options
4108  $options //= {};
4109  $self->SUPER::Create(Name => $name, Width => 0, Height => 0, Bands => 0, Type => 'Byte', Options => $options);
4110 }
4111 
4112 #** @method Open()
4113 # Object method.
4114 # The same as Geo::OGR::Open except that only this driver is allowed.
4115 #*
4116 sub Open {
4117  my $self = shift;
4118  my @p = @_; # name, update
4119  my @flags = qw/VECTOR/;
4120  push @flags, qw/UPDATE/ if $p[1];
4121  my $dataset = Geo::GDAL::OpenEx($p[0], \@flags, [$self->Name()]);
4122  error("Failed to open $p[0]. Is it a vector dataset?") unless $dataset;
4123  return $dataset;
4124 }
4125 
4126 #** @class Geo::OGR::Feature
4127 # @brief A collection of non-spatial and spatial attributes.
4128 # @details A feature is a collection of non-spatial and spatial attributes and
4129 # an id, which is a special attribute, and data records according to
4130 # this data model. Attributes are called fields and some fields are
4131 # spatial, i.e., their value is a geometry. Fields have at least a
4132 # name and a type. Features may exist within a layer or
4133 # separetely. The data model of a feature is a definition object.
4134 #*
4135 package Geo::OGR::Feature;
4136 
4137 use base qw(Geo::OGR)
4138 
4139 #** @method Geo::OGR::Feature Clone()
4140 # Object method.
4141 # @return a new Geo::OGR::Feature object
4142 #*
4143 sub Clone {
4144 }
4145 
4146 #** @method DumpReadable()
4147 # Object method.
4148 # Write the contents of this feature to stdout.
4149 #*
4150 sub DumpReadable {
4151 }
4152 
4153 #** @method scalar Equal($feature)
4154 # Object method.
4155 # @param feature a Geo::OGR::Feature object for comparison
4156 # @return boolean
4157 #*
4158 sub Equal {
4159 }
4160 
4161 #** @method scalar FID($id)
4162 # Object method.
4163 # @brief Get or set the id of this feature.
4164 # @param id [optional] the id to set for this feature.
4165 # @return integer the id of this feature.
4166 #*
4167 sub FID {
4168  my $self = shift;
4169  $self->SetFID($_[0]) if @_;
4170  return unless defined wantarray;
4171  $self->GetFID;
4172 }
4173 
4174 #** @method Field($name, $value, ...)
4175 # Object method.
4176 # @brief Get, set, or unset the field value.
4177 # @param name the name (or the index) of the field.
4178 # @param value a scalar, a list of scalars or a reference to a
4179 # list. If undef, the field is unset. If a scalar or a list of
4180 # scalars, the field is set from them.
4181 # @note Non-scalar fields (for example Date) can be set either from a
4182 # scalar, which is then assumed to be a string and parsed, or from a
4183 # list of values (for example year, month, day for Date).
4184 # @note Setting and getting Integer64 fields requires 'use bigint' if
4185 # \$Config{ivsize} is smaller than 8, i.e., in a 32 bit machine.
4186 # @return in non-void context the value of the field, which may be a
4187 # scalar or a list, depending on the field type. For unset fields the
4188 # undef value is returned.
4189 #*
4190 sub Field {
4191  my $self = shift;
4192  my $field = $self->GetFieldIndex(shift // 0);
4193  $self->SetField($field, @_) if @_;
4194  $self->GetField($field) if defined wantarray;
4195 }
4196 
4197 #** @method FillUnsetWithDefault()
4198 #*
4199 sub FillUnsetWithDefault {
4200 }
4201 
4202 #** @method Geometry($name, $geometry)
4203 # Object method.
4204 # @brief Get or set the value of a geometry field.
4205 # @note This method delivers the functionality of undocumented methods
4206 # SetGeometry($geometry), SetGeometryDirectly, SetGeomField,
4207 # SetGeomFieldDirectly, GetGeometry, GetGeometryRef.
4208 #
4209 # Set or get the geometry in the feature. When setting, does a check
4210 # against the schema (GeometryType) of the feature. If the parameter
4211 # is a geometry object, it is cloned.
4212 # @param name [optional] the name of the spatial field,
4213 # whose geometry is to be set. If not given, sets or gets the geometry
4214 # of the first (or the single) spatial field.
4215 # @param geometry [optional] a Geo::OGR::Geometry object or a
4216 # reference to a hash from which such can be created (using
4217 # Geo::OGR::Geometry::new).
4218 # @return in a non-void context the indicated geometry in the feature
4219 # as a Geo::OGR::Geometry object. The returned object contains a
4220 # reference to the actual geometry data in the feature (the geometry
4221 # is not cloned) and to the feature object, thus keeping the feature
4222 # object from being destroyed while the geometry object exists.
4223 #*
4224 sub Geometry {
4225  my $self = shift;
4226  my $field = ((@_ > 0 and ref($_[0]) eq '') or (@_ > 2 and @_ % 2 == 1)) ? shift : 0;
4227  $field = $self->GetGeomFieldIndex($field);
4228  my $geometry;
4229  if (@_ and @_ % 2 == 0) {
4230  %$geometry = @_;
4231  } else {
4232  $geometry = shift;
4233  }
4234  if ($geometry) {
4235  my $type = $self->GetDefn->GetGeomFieldDefn($field)->Type;
4236  if (blessed($geometry) and $geometry->isa('Geo::OGR::Geometry')) {
4237  my $gtype = $geometry->GeometryType;
4238  error("The type of the inserted geometry ('$gtype') is not the same as the type of the field ('$type').")
4239  if $type ne 'Unknown' and $type ne $gtype;
4240  eval {
4241  $self->SetGeomFieldDirectly($field, $geometry->Clone);
4242  };
4243  confess last_error() if $@;
4244  } elsif (ref($geometry) eq 'HASH') {
4245  $geometry->{GeometryType} //= $type;
4246  eval {
4247  $geometry = Geo::OGR::Geometry->new($geometry);
4248  };
4249  confess last_error() if $@;
4250  my $gtype = $geometry->GeometryType;
4251  error("The type of the inserted geometry ('$gtype') is not the same as the type of the field ('$type').")
4252  if $type ne 'Unknown' and $type ne $gtype;
4253  eval {
4254  $self->SetGeomFieldDirectly($field, $geometry);
4255  };
4256  confess last_error() if $@;
4257  } else {
4258  error("Usage: \$feature->Geometry([field],[geometry])");
4259  }
4260  }
4261  return unless defined wantarray;
4262  $geometry = $self->GetGeomFieldRef($field);
4263  return unless $geometry;
4264  keep($geometry, $self);
4265 }
4266 
4267 #** @method Geo::OGR::FeatureDefn GetDefn()
4268 # Object method.
4269 # @note A.k.a GetDefnRef.
4270 # @return a Geo::OGR::FeatureDefn object, which represents the definition of this feature.
4271 #*
4272 sub GetDefn {
4273  my $self = shift;
4274  my $defn = $self->GetDefnRef;
4275  keep($defn, $self);
4276 }
4277 
4278 #** @method scalar GetFID()
4279 # Object method.
4280 # @return the feature id (an integer).
4281 #*
4282 sub GetFID {
4283 }
4284 
4285 #** @method list GetField($name)
4286 # Object method.
4287 # See Field().
4288 #*
4289 sub GetField {
4290  my ($self, $field) = @_;
4291  $field = $self->GetFieldIndex($field);
4292  return unless IsFieldSet($self, $field);
4293  my $type = GetFieldType($self, $field);
4294  return GetFieldAsInteger($self, $field) if $type == $Geo::OGR::OFTInteger;
4295  return GetFieldAsInteger64($self, $field) if $type == $Geo::OGR::OFTInteger64;
4296  return GetFieldAsDouble($self, $field) if $type == $Geo::OGR::OFTReal;
4297  return GetFieldAsString($self, $field) if $type == $Geo::OGR::OFTString;
4298  if ($type == $Geo::OGR::OFTIntegerList) {
4299  my $ret = GetFieldAsIntegerList($self, $field);
4300  return wantarray ? @$ret : $ret;
4301  }
4302  if ($type == $Geo::OGR::OFTInteger64List) {
4303  my $ret = GetFieldAsInteger64List($self, $field);
4304  return wantarray ? @$ret : $ret;
4305  }
4306  if ($type == $Geo::OGR::OFTRealList) {
4307  my $ret = GetFieldAsDoubleList($self, $field);
4308  return wantarray ? @$ret : $ret;
4309  }
4310  if ($type == $Geo::OGR::OFTStringList) {
4311  my $ret = GetFieldAsStringList($self, $field);
4312  return wantarray ? @$ret : $ret;
4313  }
4314  if ($type == $Geo::OGR::OFTBinary) {
4315  return GetFieldAsBinary($self, $field);
4316  }
4317  if ($type == $Geo::OGR::OFTDate) {
4318  my @ret = GetFieldAsDateTime($self, $field);
4319  # year, month, day, hour, minute, second, timezone
4320  return wantarray ? @ret[0..2] : [@ret[0..2]];
4321  }
4322  if ($type == $Geo::OGR::OFTTime) {
4323  my @ret = GetFieldAsDateTime($self, $field);
4324  return wantarray ? @ret[3..6] : [@ret[3..6]];
4325  }
4326  if ($type == $Geo::OGR::OFTDateTime) {
4327  my @ret = GetFieldAsDateTime($self, $field);
4328  return wantarray ? @ret : [@ret];
4329  }
4330  error("Perl bindings do not support the field type '".i2s(field_type => $type)."'.");
4331 }
4332 
4333 #** @method scalar GetFieldDefn($name)
4334 # Object method.
4335 # Get the definition of a field.
4336 # @param name the name of the field.
4337 # @return a Geo::OGR::FieldDefn object.
4338 #*
4339 sub GetFieldDefn {
4340  my $self = shift;
4341  my $field = $self->GetFieldIndex(shift);
4342  return $self->GetFieldDefnRef($field);
4343 }
4344 
4345 #** @method list GetFieldNames()
4346 # Object method.
4347 # Get the names of the fields in this feature.
4348 #*
4349 sub GetFieldNames {
4350 }
4351 
4352 #** @method scalar GetGeomFieldDefn($name)
4353 # Object method.
4354 # Get the definition of a spatial field.
4355 # @param name the name of the spatial field.
4356 # @return a Geo::OGR::GeomFieldDefn object.
4357 #*
4358 sub GetGeomFieldDefn {
4359  my $self = shift;
4360  my $field = $self->GetGeomFieldIndex(shift);
4361  return $self->GetGeomFieldDefnRef($field);
4362 }
4363 
4364 #** @method GetNativeData()
4365 #*
4366 sub GetNativeData {
4367 }
4368 
4369 #** @method GetNativeMediaType()
4370 #*
4371 sub GetNativeMediaType {
4372 }
4373 
4374 #** @method hash reference GetSchema()
4375 # Object method.
4376 # @brief Get the schema of this feature.
4377 #
4378 # @return the schema as a hash whose keywords are Name, StyleIgnored
4379 # and Fields. Fields is an anonymous array of first non-spatial and
4380 # then spatial field schemas as in Geo::OGR::FieldDefn::Schema() and
4381 # Geo::OGR::GeomFieldDefn::Schema().
4382 #*
4383 sub GetSchema {
4384  my $self = shift;
4385  error("Schema of a feature cannot be set directly.") if @_;
4386  return $self->GetDefnRef->Schema;
4387 }
4388 
4389 #** @method scalar GetStyleString()
4390 # Object method.
4391 # @return a string
4392 #*
4393 sub GetStyleString {
4394 }
4395 
4396 #** @method IsFieldNull()
4397 #*
4398 sub IsFieldNull {
4399 }
4400 
4401 #** @method IsFieldSetAndNotNull()
4402 #*
4403 sub IsFieldSetAndNotNull {
4404 }
4405 
4406 #** @method Geo::OGR::Layer Layer()
4407 # Object method.
4408 # @return the layer to which this feature belongs to or undef.
4409 #*
4410 sub Layer {
4411  my $self = shift;
4412  parent($self);
4413 }
4414 
4415 #** @method hash reference Row(%row)
4416 # Object method.
4417 # @note This method discards the data the destination feature (or
4418 # layer) does not support. Changes in data due to differences between
4419 # field types may also occur.
4420 #
4421 # Get and/or set the data of the feature. The key of the (key,value)
4422 # pairs of the row is the field name. Special field names FID and
4423 # Geometry are used for feature id and (single) geometry
4424 # respectively. The geometry/ies is/are set and get using the
4425 # Geo::OGR::Feature::Geometry method. Field values are set using the
4426 # Geo::OGR::Feature::Field method.
4427 # @param row [optional] feature data in a hash.
4428 # @return a reference to feature data in a hash. Spatial fields are
4429 # returned as Geo::OGR::Geometry objects.
4430 #*
4431 sub Row {
4432  my $self = shift;
4433  my $nf = $self->GetFieldCount;
4434  my $ngf = $self->GetGeomFieldCount;
4435  if (@_) { # update
4436  my %row;
4437  if (@_ == 1 and ref($_[0]) eq 'HASH') {
4438  %row = %{$_[0]};
4439  } elsif (@_ and @_ % 2 == 0) {
4440  %row = @_;
4441  } else {
4442  error('Usage: $feature->Row(%FeatureData).');
4443  }
4444  $self->SetFID($row{FID}) if defined $row{FID};
4445  #$self->Geometry($schema, $row{Geometry}) if $row{Geometry};
4446  for my $name (keys %row) {
4447  next if $name eq 'FID';
4448  if ($name eq 'Geometry') {
4449  $self->Geometry(0, $row{$name});
4450  next;
4451  }
4452  my $f = 0;
4453  for my $i (0..$nf-1) {
4454  if ($self->GetFieldDefnRef($i)->Name eq $name) {
4455  $self->SetField($i, $row{$name});
4456  $f = 1;
4457  last;
4458  }
4459  }
4460  next if $f;
4461  for my $i (0..$ngf-1) {
4462  if ($self->GetGeomFieldDefnRef($i)->Name eq $name) {
4463  $self->Geometry($i, $row{$name});
4464  $f = 1;
4465  last;
4466  }
4467  }
4468  next if $f;
4469  carp "Unknown field: '$name'.";
4470  }
4471  }
4472  return unless defined wantarray;
4473  my %row = ();
4474  for my $i (0..$nf-1) {
4475  my $name = $self->GetFieldDefnRef($i)->Name;
4476  $row{$name} = $self->GetField($i);
4477  }
4478  for my $i (0..$ngf-1) {
4479  my $name = $self->GetGeomFieldDefnRef($i)->Name || 'Geometry';
4480  $row{$name} = $self->GetGeometry($i);
4481  }
4482  $row{FID} = $self->GetFID;
4483  return \%row;
4484 }
4485 
4486 #** @method SetFID($id)
4487 # Object method.
4488 # @param id the feature id.
4489 #*
4490 sub SetFID {
4491 }
4492 
4493 #** @method SetField($name, @Value)
4494 # Object method.
4495 # See Field().
4496 #*
4497 sub SetField {
4498  my $self = shift;
4499  my $field = $self->GetFieldIndex(shift);
4500  my $arg = $_[0];
4501  if (@_ == 0 or !defined($arg)) {
4502  _UnsetField($self, $field);
4503  return;
4504  }
4505  $arg = [@_] if @_ > 1;
4506  my $type = $self->GetFieldType($field);
4507  if (ref($arg)) {
4508  if ($type == $Geo::OGR::OFTIntegerList) {
4509  SetFieldIntegerList($self, $field, $arg);
4510  }
4511  elsif ($type == $Geo::OGR::OFTInteger64List) {
4512  SetFieldInteger64List($self, $field, $arg);
4513  }
4514  elsif ($type == $Geo::OGR::OFTRealList) {
4515  SetFieldDoubleList($self, $field, $arg);
4516  }
4517  elsif ($type == $Geo::OGR::OFTStringList) {
4518  SetFieldStringList($self, $field, $arg);
4519  }
4520  elsif ($type == $Geo::OGR::OFTDate) {
4521  _SetField($self, $field, @$arg[0..2], 0, 0, 0, 0);
4522  }
4523  elsif ($type == $Geo::OGR::OFTTime) {
4524  $arg->[3] //= 0;
4525  _SetField($self, $field, 0, 0, 0, @$arg[0..3]);
4526  }
4527  elsif ($type == $Geo::OGR::OFTDateTime) {
4528  $arg->[6] //= 0;
4529  _SetField($self, $field, @$arg[0..6]);
4530  }
4531  elsif ($type == $Geo::OGR::OFTInteger64)
4532  {
4533  SetFieldInteger64($self, $field, $arg);
4534  }
4535  else {
4536  $type = i2s(field_type => $type);
4537  my $name = $self->GetFieldDefnRef($field)->Name;
4538  error("'$arg' is not a suitable value for field $name($type).");
4539  }
4540  } else {
4541  if ($type == $Geo::OGR::OFTBinary) {
4542  #$arg = unpack('H*', $arg); # remove when SetFieldBinary is available
4543  $self->SetFieldBinary($field, $arg);
4544  }
4545  elsif ($type == $Geo::OGR::OFTInteger64)
4546  {
4547  SetFieldInteger64($self, $field, $arg);
4548  }
4549  elsif ($type == $Geo::OGR::OFTInteger or $type == $Geo::OGR::OFTReal or $type == $Geo::OGR::OFTString)
4550  {
4551  _SetField($self, $field, $arg);
4552  }
4553  else {
4554  $type = i2s(field_type => $type);
4555  my $name = $self->GetFieldDefnRef($field)->Name;
4556  error("'$arg' is not a suitable value for field $name($type).");
4557  }
4558  }
4559 }
4560 
4561 #** @method SetFieldNull()
4562 #*
4563 sub SetFieldNull {
4564 }
4565 
4566 #** @method SetFrom($other, $forgiving = 1, hashref map)
4567 # Object method.
4568 # @param other a Geo::OGR::Feature object
4569 # @param forgiving [optional] set to false if the operation should not
4570 # continue if output fields do not match some of the source fields
4571 # @param map [optional] a mapping from output field indexes to source
4572 # fields, include into the hash all field indexes of this feature
4573 # which should be set
4574 #*
4575 sub SetFrom {
4576  my($self, $other) = @_;
4577  _SetFrom($self, $other), return if @_ <= 2;
4578  my $forgiving = $_[2];
4579  _SetFrom($self, $other, $forgiving), return if @_ <= 3;
4580  my $map = $_[3];
4581  my @list;
4582  for my $i (1..GetFieldCount($self)) {
4583  push @list, ($map->{$i} || -1);
4584  }
4585  SetFromWithMap($self, $other, 1, \@list);
4586 }
4587 
4588 #** @method SetNativeData()
4589 #*
4590 sub SetNativeData {
4591 }
4592 
4593 #** @method SetNativeMediaType()
4594 #*
4595 sub SetNativeMediaType {
4596 }
4597 
4598 #** @method SetStyleString($string)
4599 # Object method.
4600 # @param string
4601 #*
4602 sub SetStyleString {
4603 }
4604 
4605 #** @method list Tuple(@tuple)
4606 # Object method.
4607 # @note This method discards the data the destination feature (or
4608 # layer) does not support. Changes in data due to differences between
4609 # field types may also occur.
4610 #
4611 # @note The schema of the tuple needs to be the same as that of the
4612 # feature.
4613 #
4614 # Get and/set the data of the feature. The expected data in the tuple
4615 # is ([feature_id,] non-spatial fields, spatial fields). The fields in
4616 # the tuple are in the order they are in the schema. Field values are
4617 # set using the Geo::OGR::Feature::Field method. Geometries are set
4618 # and get using the Geo::OGR::Feature::Geometry method.
4619 # @param tuple [optional] feature data in an array
4620 # @return feature data in an array
4621 #*
4622 sub Tuple {
4623  my $self = shift;
4624  my $nf = $self->GetFieldCount;
4625  my $ngf = $self->GetGeomFieldCount;
4626  if (@_) {
4627  my $values = ref $_[0] ? $_[0] : \@_;
4628  my $FID;
4629  $FID = shift @$values if @$values == $nf + $ngf + 1;
4630  $self->SetFID($FID) if defined $FID;
4631  if (@$values != $nf + $ngf) {
4632  my $n = $nf + $ngf;
4633  error("Too many or too few attribute values for a feature (need $n).");
4634  }
4635  my $index = 0; # index to non-geometry and geometry fields
4636  for my $i (0..$nf-1) {
4637  $self->SetField($i, $values->[$i]);
4638  }
4639  for my $i (0..$ngf-1) {
4640  $self->Geometry($i, $values->[$nf+$i]);
4641  }
4642  }
4643  return unless defined wantarray;
4644  my @ret = ($self->GetFID);
4645  for my $i (0..$nf-1) {
4646  my $v = $self->GetField($i);
4647  push @ret, $v;
4648  }
4649  for my $i (0..$ngf-1) {
4650  my $v = $self->GetGeometry($i);
4651  push @ret, $v;
4652  }
4653  return @ret;
4654 }
4655 
4656 #** @method scalar Validate(list flags)
4657 # Object method.
4658 # @param flags one of more of null, geom_type, width,
4659 # allow_null_when_default, or all.
4660 # @exception croaks with an error message if the feature is not valid.
4661 # @return integer denoting the validity of the feature object.
4662 #*
4663 sub Validate {
4664  my $self = shift;
4665  my $flags = 0;
4666  for my $flag (@_) {
4667  my $f = eval '$Geo::OGR::'.uc($flag);
4668  $flags |= $f;
4669  }
4670  _Validate($self, $flags);
4671 }
4672 
4673 #** @method Geo::OGR::Feature new(%schema)
4674 # Class method.
4675 # @brief Create a new feature.
4676 # @param Named parameters:
4677 # - \a Schema a reference to a schema hash, or a Geo::OGR::Layer,
4678 # Geo::OGR::Feature, or Geo::OGR::FeatureDefn object.
4679 # - \a Values values for the feature attributes.
4680 # - \a StyleIgnored whether the style can be omitted when fetching
4681 # features. (default is false)
4682 #
4683 # Schema is a hash with the following keys:
4684 # - \a Name name of the schema (not used).
4685 # - \a Fields a list of Geo::OGR::FieldDefn or Geo::OGR::GeomFieldDefn
4686 # objects or references to hashes from which fields can be created.
4687 # - \a GeometryType the geometry type if the feature has only one spatial field.
4688 #
4689 # @note Do not mix GeometryType and geometry fields in Fields list.
4690 # @note Old syntax where the argument is a Geo::OGR::FeatureDefn
4691 # object or Schema hash is supported.
4692 #
4693 # @return a new Geo::OGR::Feature object.
4694 #*
4695 sub new {
4696  my $pkg = shift;
4697  my $arg;
4698  if (ref $_[0]) {
4699  if (ref $_[0] eq 'HASH' && $_[0]->{Schema}) {
4700  $arg = $_[0];
4701  } else {
4702  $arg = {Schema => $_[0]};
4703  }
4704  } elsif (@_ and @_ % 2 == 0) {
4705  %$arg = @_;
4706  unless ($arg->{Schema}) {
4707  my %tmp = @_;
4708  $arg->{Schema} = \%tmp;
4709  }
4710  } else {
4711  error("The argument must be either a schema or a hash.");
4712  }
4713  error("Missing schema.") unless $arg->{Schema};
4714  my $defn;
4715  for (ref $arg->{Schema}) {
4716  (/Geo::OGR::Layer$/ || /Geo::OGR::Feature$/) && do {
4717  $defn = $arg->{Schema}->GetDefn;
4718  last;
4719  };
4720  /Geo::OGR::FeatureDefn$/ && do {
4721  $defn = $arg->{Schema};
4722  last;
4723  };
4724  $defn = Geo::OGR::FeatureDefn->new($arg->{Schema});
4725  }
4726  my $self = Geo::OGRc::new_Feature($defn);
4727  error("Feature creation failed.") unless $self;
4728  bless $self, $pkg;
4729  for (ref $arg->{Values}) {
4730  /ARRAY/ && do {
4731  $self->Tuple($arg->{Values});
4732  last;
4733  };
4734  /HASH/ && do {
4735  $self->Row($arg->{Values});
4736  last;
4737  };
4738  /Geo::OGR::Feature$/ && do {
4739  $self->Tuple($arg->{Values}->Tuple);
4740  last;
4741  };
4742  /^$/ && do {
4743  last;
4744  };
4745  error("Value parameter must be an array, hash, or another feature. Not $_.");
4746  }
4747  return $self;
4748 }
4749 
4750 #** @class Geo::OGR::FeatureDefn
4751 # @brief The schema of a feature or a layer.
4752 # @details A FeatureDefn object is a collection of field definition objects. A
4753 # read-only FeatureDefn object can be obtained from a layer
4754 # (Geo::OGR::Layer::GetDefn()) or a feature
4755 # (Geo::OGR::Feature::GetDefn()).
4756 #*
4757 package Geo::OGR::FeatureDefn;
4758 
4759 use base qw(Geo::OGR)
4760 
4761 #** @method AddField(%params)
4762 # Object method.
4763 # @param params Named parameters to create a new Geo::OGR::FieldDefn
4764 # or Geo::OGR::GeomFieldDefn object.
4765 #*
4766 sub AddField {
4767  my $self = shift;
4768  error("Read-only definition.") if parent($self);
4769  my %params;
4770  if (@_ == 0) {
4771  } elsif (ref($_[0]) eq 'HASH') {
4772  %params = %{$_[0]};
4773  } elsif (@_ % 2 == 0) {
4774  %params = @_;
4775  }
4776  $params{Type} //= '';
4777  if (s_exists(field_type => $params{Type})) {
4778  my $fd = Geo::OGR::FieldDefn->new(%params);
4779  $self->AddFieldDefn($fd);
4780  } else {
4781  my $fd = Geo::OGR::GeomFieldDefn->new(%params);
4782  $self->AddGeomFieldDefn($fd);
4783  }
4784 }
4785 
4786 #** @method DeleteField($name)
4787 # Object method.
4788 # @note Currently only geometry fields can be deleted.
4789 # @param index the index of the geometry field to be deleted.
4790 #*
4791 sub DeleteField {
4792  my ($self, $name) = @_;
4793  error("Read-only definition.") if parent($self);
4794  for my $i (0..$self->GetFieldCount-1) {
4795  error("Non-spatial fields cannot be deleted.") if $self->_GetFieldDefn($i)->Name eq $name;
4796  }
4797  for my $i (0..$self->GetGeomFieldCount-1) {
4798  $self->DeleteGeomFieldDefn($i) if $self->_GetGeomFieldDefn($i)->Name eq $name;
4799  }
4800  error(2, $name, 'Field');
4801 }
4802 
4803 #** @method Feature()
4804 #*
4805 sub Feature {
4806  my $self = shift;
4807  return parent($self);
4808 }
4809 
4810 #** @method scalar GetFieldDefn($name)
4811 # Object method.
4812 # Get the definition of a field.
4813 # @param name the name of the field.
4814 # @return a Geo::OGR::FieldDefn object.
4815 #*
4816 sub GetFieldDefn {
4817  my $self = shift;
4818  my $field = $self->GetFieldIndex(shift);
4819  return $self->_GetFieldDefn($field);
4820 }
4821 
4822 #** @method list GetFieldNames()
4823 # Object method.
4824 # The names of the fields in this layer or feature definition.
4825 # @return the list of field names.
4826 #*
4827 sub GetFieldNames {
4828  my $self = shift;
4829  my @names = ();
4830  for my $i (0..$self->GetFieldCount-1) {
4831  push @names, $self->_GetFieldDefn($i)->Name;
4832  }
4833  for my $i (0..$self->GetGeomFieldCount-1) {
4834  push @names, $self->_GetGeomFieldDefn($i)->Name;
4835  }
4836  return @names;
4837 }
4838 
4839 #** @method scalar GetGeomFieldDefn($name)
4840 # Object method.
4841 # Get the definition of a spatial field.
4842 # @param name the name of the spatial field.
4843 # @return a Geo::OGR::GeomFieldDefn object.
4844 #*
4845 sub GetGeomFieldDefn {
4846  my $self = shift;
4847  my $field = $self->GetGeomFieldIndex(shift);
4848  return $self->_GetGeomFieldDefn($field);
4849 }
4850 
4851 #** @method scalar GetName()
4852 # Object method.
4853 # @return the name of this layer or feature definition.
4854 #*
4855 sub GetName {
4856 }
4857 
4858 #** @method hash reference GetSchema()
4859 # Object method.
4860 # @brief Get the schema of this feature or layer definition.
4861 #
4862 # @return the schema as a hash whose keywords are Name, StyleIgnored
4863 # and Fields. Fields is an anonymous array of first non-spatial and
4864 # then spatial field schemas as in Geo::OGR::FieldDefn::Schema() and
4865 # Geo::OGR::GeomFieldDefn::Schema().
4866 #*
4867 sub GetSchema {
4868  my $self = shift;
4869  carp "Schema of a feature definition should not be set directly." if @_;
4870  if (@_ and @_ % 2 == 0) {
4871  my %schema = @_;
4872  if ($schema{Fields}) {
4873  for my $field (@{$schema{Fields}}) {
4874  $self->AddField($field);
4875  }
4876  }
4877  }
4878  my %schema;
4879  $schema{Name} = $self->Name();
4880  $schema{StyleIgnored} = $self->StyleIgnored();
4881  $schema{Fields} = [];
4882  for my $i (0..$self->GetFieldCount-1) {
4883  my $s = $self->_GetFieldDefn($i)->Schema;
4884  push @{$schema{Fields}}, $s;
4885  }
4886  for my $i (0..$self->GetGeomFieldCount-1) {
4887  my $s = $self->_GetGeomFieldDefn($i)->Schema;
4888  push @{$schema{Fields}}, $s;
4889  }
4890  return wantarray ? %schema : \%schema;
4891 }
4892 
4893 #** @method IsSame(Geo::OGR::FeatureDefn defn)
4894 # Object method.
4895 # @return true if this definition is similar to the other definition,
4896 # false otherwise.
4897 #*
4898 sub IsSame {
4899 }
4900 
4901 #** @method scalar IsStyleIgnored()
4902 # Object method.
4903 # Get the ignore status of style information when fetching features.
4904 # @return the ignore status of style information
4905 # @since 1.9.0
4906 #*
4907 sub IsStyleIgnored {
4908 }
4909 
4910 #** @method SetStyleIgnored($IgnoreState)
4911 # Object method.
4912 # Set the ignore status of style information when fetching features.
4913 # @since 1.9.0
4914 #*
4915 sub SetStyleIgnored {
4916 }
4917 
4918 #** @method Geo::OGR::FeatureDefn new(%schema)
4919 # Class method.
4920 # Creates a new layer or feature definition. The new definition is
4921 # either initialized to the given schema or it will contain no
4922 # non-spatial fields and one spatial field, whose Name is '' and
4923 # GeometryType is 'Unknown' or the value of the named parameter
4924 # GeometryType.
4925 # @param schema [optional] The schema for the new feature definition,
4926 # as in Geo::OGR::FeatureDefn::Schema().
4927 # @return a Geo::OGR::FeatureDefn object
4928 #
4929 # Example usage:
4930 # \code
4931 # $fd = Geo::OGR::FeatureDefn->new(
4932 # Name => "name",
4933 # Fields => [{ Name => 'field1', Type => 'String' },
4934 # { Name => 'geom', GeometryType => 'Point' }] );
4935 # \endcode
4936 #*
4937 sub new {
4938  my $pkg = shift;
4939  my %schema;
4940  if (@_ == 1 and ref($_[0]) eq 'HASH') {
4941  %schema = %{$_[0]};
4942  } elsif (@_ and @_ % 2 == 0) {
4943  %schema = @_;
4944  }
4945  my $fields = $schema{Fields};
4946  error("The 'Fields' argument must be an array reference.") if $fields and ref($fields) ne 'ARRAY';
4947  $schema{Name} //= '';
4948  my $self = Geo::OGRc::new_FeatureDefn($schema{Name});
4949  bless $self, $pkg;
4950  my $gt = $schema{GeometryType};
4951  if ($gt) {
4952  $self->GeometryType($gt);
4953  } elsif ($fields) {
4954  $self->DeleteGeomFieldDefn(0);
4955  }
4956  $self->StyleIgnored($schema{StyleIgnored}) if exists $schema{StyleIgnored};
4957  for my $fd (@{$fields}) {
4958  my $d = $fd;
4959  if (ref($fd) eq 'HASH') {
4960  # if Name and Type are missing, assume Name => Type
4961  if (!(exists $fd->{Name} && exists $fd->{Type})) {
4962  for my $key (sort keys %$fd) {
4963  if (s_exists(field_type => $fd->{$key}) ||
4964  s_exists(geometry_type => $fd->{$key}))
4965  {
4966  $fd->{Name} = $key;
4967  $fd->{Type} = $fd->{$key};
4968  delete $fd->{$key};
4969  last;
4970  }
4971  }
4972  }
4973  if ($fd->{GeometryType} or ($fd->{Type} && s_exists(geometry_type => $fd->{Type}))) {
4974  $d = Geo::OGR::GeomFieldDefn->new(%$fd);
4975  } else {
4976  $d = Geo::OGR::FieldDefn->new(%$fd);
4977  }
4978  }
4979  if (blessed($d) and $d->isa('Geo::OGR::FieldDefn')) {
4980  AddFieldDefn($self, $d);
4981  } elsif (blessed($d) and $d->isa('Geo::OGR::GeomFieldDefn')) {
4982  error("Do not mix GeometryType and geometry fields in Fields.") if $gt;
4983  AddGeomFieldDefn($self, $d);
4984  } else {
4985  error("Item in field list does not define a field.");
4986  }
4987  }
4988  return $self;
4989 }
4990 
4991 #** @class Geo::OGR::FieldDefn
4992 # @brief A definition of a non-spatial attribute.
4993 # @details
4994 #*
4995 package Geo::OGR::FieldDefn;
4996 
4997 use base qw(Geo::OGR)
4998 
4999 #** @method scalar Default($value)
5000 # Object method.
5001 # Get or set the default value for this field.
5002 # @note a.k.a. GetDefault and SetDefault
5003 # @param value [optional]
5004 # @return the default value of this field in non-void context.
5005 #*
5006 sub Default {
5007  my $self = shift;
5008  SetDefault($self, $_[0]) if @_;
5009  GetDefault($self) if defined wantarray;
5010 }
5011 
5012 #** @method GetSchema()
5013 #*
5014 sub GetSchema {
5015 }
5016 
5017 #** @method scalar Ignored($ignore)
5018 # Object method.
5019 # Get and/or set the ignore status (whether this field should be
5020 # omitted when fetching features) of this field.
5021 # @note a.k.a. IsIgnored, SetIgnored
5022 # @param ignore [optional]
5023 # @return the ignore status of this field in non-void context.
5024 # @since 1.9.0
5025 #*
5026 sub Ignored {
5027  my $self = shift;
5028  SetIgnored($self, $_[0]) if @_;
5029  IsIgnored($self) if defined wantarray;
5031 
5032 #** @method IsDefaultDriverSpecific()
5033 #*
5034 sub IsDefaultDriverSpecific {
5035 }
5036 
5037 #** @method scalar Justify($justify)
5038 # Object method.
5039 # Get and/or set the justification of this field.
5040 # @note a.k.a. GetJustify, SetJustify
5041 # @param justify [optional] One of field justify types (Geo::OGR::FieldDefn::JustifyValues).
5042 # @return the justify value of this field in non-void context.
5043 #*
5044 sub Justify {
5045  my($self, $justify) = @_;
5046  if (defined $justify) {
5047  $justify = s2i(justify => $justify);
5048  SetJustify($self, $justify);
5049  }
5050  return i2s(justify => GetJustify($self)) if defined wantarray;
5051 }
5052 
5053 #** @method list JustifyValues()
5054 # Package subroutine.
5055 # Justify values supported by GDAL. Current list is
5056 # Left, Right, and Undefined.
5057 #*
5058 sub JustifyValues {
5059  return @JUSTIFY;
5060 }
5061 
5062 #** @method scalar Name($name)
5063 # Object method.
5064 # Get and/or set the name of the field.
5065 # @note a.k.a. GetName, GetNameRef, SetName
5066 # @param name [optional]
5067 # @return the name in non-void context
5068 #*
5069 sub Name {
5070  my $self = shift;
5071  SetName($self, $_[0]) if @_;
5072  GetName($self) if defined wantarray;
5073 }
5074 
5075 #** @method scalar Nullable($nullable)
5076 # Object method.
5077 # Get or set the nullable constraint for this field.
5078 # @note a.k.a. IsNullable and SetNullable
5079 # @param nullable [optional]
5080 # @return the nullable value of this field in non-void context.
5081 #*
5082 sub Nullable {
5083  my $self = shift;
5084  SetNullable($self, $_[0]) if @_;
5085  IsNullable($self) if defined wantarray;
5086 }
5087 
5088 #** @method scalar Precision($precision)
5089 # Object method.
5090 # Get and/or set the precision of this field.
5091 # @note a.k.a. GetPrecision, SetPrecision
5092 # @param precision [optional]
5093 # @return the precision of this field in non-void context.
5094 #*
5095 sub Precision {
5096  my $self = shift;
5097  SetPrecision($self, $_[0]) if @_;
5098  GetPrecision($self) if defined wantarray;
5099 }
5100 
5101 #** @method hash reference Schema(%params)
5102 # Object method.
5103 # Get the schema or set parts of the schema
5104 # @param params [optional] as those in Geo::OGR::FieldDefn::new.
5105 # @return a reference to a hash whose keys are as those in Geo::OGR::FieldDefn::new.
5106 #*
5107 sub Schema {
5108  my $self = shift;
5109  if (@_) {
5110  my $params = @_ % 2 == 0 ? {@_} : shift;
5111  for my $key (keys %SCHEMA_KEYS) {
5112  next unless exists $params->{$key};
5113  eval "\$self->$key(\$params->{$key})";
5114  confess(last_error()) if $@;
5115  }
5116  }
5117  return unless defined wantarray;
5118  my %schema = ();
5119  for my $key (keys %SCHEMA_KEYS) {
5120  $schema{$key} = eval '$self->'.$key;
5121  }
5122  return wantarray ? %schema : \%schema;
5123 }
5124 
5125 #** @method SetSchema()
5126 #*
5127 sub SetSchema {
5128 }
5129 
5130 #** @method scalar SubType($SubType)
5131 # Object method.
5132 # @note a.k.a. GetSubType, SetSubType
5133 # @param SubType [optional] One of field sub types (Geo::OGR::FieldDefn::SubTypes).
5134 # @return the sub type of this field in non-void context.
5135 #*
5136 sub SubType {
5137  my($self, $subtype) = @_;
5138  if (defined $subtype) {
5139  $subtype = s2i(field_subtype => $subtype);
5140  SetSubType($self, $subtype);
5141  }
5142  return i2s(field_subtype => GetSubType($self)) if defined wantarray;
5143 }
5144 
5145 #** @method SubTypes()
5146 #*
5147 sub SubTypes {
5148  return @SUBTYPES;
5149 }
5150 
5151 #** @method scalar Type($type)
5152 # Object method.
5153 # Get and/or set the type of the field.
5154 # @note a.k.a. GetFieldTypeName, GetTypeName, GetType, SetType
5155 # @param type [optional] One of field types (Geo::OGR::FieldDefn::Types).
5156 # @return one of field types in non-void context.
5157 #*
5158 sub Type {
5159  my($self, $type) = @_;
5160  if (defined $type) {
5161  $type = s2i(field_type => $type);
5162  SetType($self, $type);
5163  }
5164  return i2s(field_type => GetType($self)) if defined wantarray;
5165 }
5166 
5167 #** @method list Types()
5168 # Package subroutine.
5169 # Field types supported by GDAL. Current list is
5170 # Binary, Date, DateTime, Integer, Integer64, Integer64List, IntegerList, Real, RealList, String, StringList, Time, WideString, and WideStringList.
5171 # (However, WideString is not supported.)
5172 #*
5173 sub Types {
5174  return @TYPES;
5175 }
5176 
5177 #** @method scalar Width($width)
5178 # Object method.
5179 # Get and/or set the field width.
5180 # @note a.k.a. GetWidth, SetWidth
5181 # @param width [optional]
5182 # @return the width of this field in non-void context.
5183 #*
5184 sub Width {
5185  my $self = shift;
5186  SetWidth($self, $_[0]) if @_;
5187  GetWidth($self) if defined wantarray;
5188 }
5189 
5190 #** @method Geo::OGR::FieldDefn new(%params)
5191 # Class method.
5192 # @brief Create a new field definition.
5193 #
5194 # @param Named parameters:
5195 # - \a Name Field name (default is 'unnamed').
5196 # - \a Type Field type, one of Geo::OGR::FieldDefn::Types (default is 'String').
5197 # - \a SubType Field sub type, one of Geo::OGR::FieldDefn::SubTypes.
5198 # - \a Justify Justify value, one of Geo::OGR::FieldDefn::JustifyValues
5199 # - \a Width
5200 # - \a Precision
5201 # - \a Nullable (default is true)
5202 # - \a Default
5203 # - \a Ignored (default is false)
5204 #
5205 # @note Simplified parameters Name => 'Type' are also supported.
5206 #
5207 # @return a new Geo::OGR::FieldDefn object
5208 #*
5209 sub new {
5210  my $pkg = shift;
5211  my $params = {Name => 'unnamed', Type => 'String'};
5212  if (@_ == 0) {
5213  } elsif (@_ == 1 and not ref $_[0]) {
5214  $params->{Name} = shift;
5215  } elsif (@_ == 2 and not $Geo::OGR::FieldDefn::SCHEMA_KEYS{$_[0]}) {
5216  $params->{Name} = shift;
5217  $params->{Type} = shift;
5218  } else {
5219  my $tmp = @_ % 2 == 0 ? {@_} : shift;
5220  for my $key (keys %$tmp) {
5221  if ($Geo::OGR::FieldDefn::SCHEMA_KEYS{$key}) {
5222  $params->{$key} = $tmp->{$key};
5223  } else {
5224  carp "Unknown parameter: '$key'." if $key ne 'Index';
5225  }
5226  }
5227  }
5228  $params->{Type} = s2i(field_type => $params->{Type});
5229  my $self = Geo::OGRc::new_FieldDefn($params->{Name}, $params->{Type});
5230  bless $self, $pkg;
5231  delete $params->{Name};
5232  delete $params->{Type};
5233  $self->Schema($params);
5234  return $self;
5235 }
5236 
5237 #** @class Geo::OGR::GeomFieldDefn
5238 # @brief A definition of a spatial attribute.
5239 # @details
5240 #*
5241 package Geo::OGR::GeomFieldDefn;
5242 
5243 use base qw(Geo::OGR)
5244 
5245 #** @method scalar GeometryType($type)
5246 # Object method.
5247 # @note a.k.a. GetType, SetType
5248 # @return the geometry type of the field.
5249 #*
5250 sub GeometryType {
5251 }
5252 
5253 #** @method GetSchema()
5254 #*
5255 sub GetSchema {
5256 }
5257 
5258 #** @method scalar Ignored($ignore)
5259 # Object method.
5260 # @note a.k.a. IsIgnored, SetIgnored
5261 # @return the ignore status of the field.
5262 #*
5263 sub Ignored {
5264  my $self = shift;
5265  SetIgnored($self, $_[0]) if @_;
5266  IsIgnored($self) if defined wantarray;
5267 }
5268 
5269 #** @method scalar Name($name)
5270 # Object method.
5271 # @note a.k.a. GetName, GetNameRef, SetName
5272 # @return the name of the field.
5273 #*
5274 sub Name {
5275  my $self = shift;
5276  SetName($self, $_[0]) if @_;
5277  GetName($self) if defined wantarray;
5278 }
5279 
5280 #** @method scalar Nullable($nullable)
5281 # Object method.
5282 # @note a.k.a. IsNullable, SetNullable
5283 # @return the nullable status of the field.
5284 #*
5285 sub Nullable {
5286  my $self = shift;
5287  SetNullable($self, $_[0]) if @_;
5288  IsNullable($self) if defined wantarray;
5289 }
5290 
5291 #** @method hash reference Schema(%params)
5292 # Object method.
5293 # Get the schema or set parts of the schema.
5294 # @param params [optional] as those in Geo::OGR::GeomFieldDefn::new.
5295 # @return a reference to a hash whose keys are as those in Geo::OGR::GeomFieldDefn::new.
5296 #*
5297 sub Schema {
5298  my $self = shift;
5299  if (@_) {
5300  my $params = @_ % 2 == 0 ? {@_} : shift;
5301  for my $key (keys %SCHEMA_KEYS) {
5302  next unless exists $params->{$key};
5303  eval "\$self->$key(\$params->{$key})";
5304  confess last_error() if $@;
5305  }
5306  }
5307  return unless defined wantarray;
5308  my %schema = ();
5309  for my $key (keys %SCHEMA_KEYS) {
5310  $schema{$key} = eval '$self->'.$key;
5311  }
5312  return wantarray ? %schema : \%schema;
5313 }
5314 
5315 #** @method SetSchema()
5316 #*
5317 sub SetSchema {
5318 }
5319 
5320 #** @method scalar SpatialReference($sr)
5321 # Object method.
5322 # @note a.k.a. GetSpatialRef, SetSpatialRef
5323 # @return the spatial reference of the field as a Geo::OSR::SpatialReference object.
5324 #*
5325 sub SpatialReference {
5326  my $self = shift;
5327  SetSpatialRef($self, $_[0]) if @_;
5328  GetSpatialRef($self) if defined wantarray;
5329 }
5330 
5331 #** @method Type()
5332 # Object method.
5333 # @return the type of this geometry field. One of Geo::OGR::GeomFieldDefn::Types
5334 #*
5335 sub Type {
5336  my($self, $type) = @_;
5337  if (defined $type) {
5338  $type = s2i(geometry_type => $type);
5339  SetType($self, $type);
5340  }
5341  i2s(geometry_type => GetType($self)) if defined wantarray;
5342 }
5343 
5344 #** @method Types()
5345 # Package subroutine.
5346 # @return a list of all geometry types, currently:
5347 # CircularString, CircularStringM, CircularStringZ, CircularStringZM, CompoundCurve, CompoundCurveM, CompoundCurveZ, CompoundCurveZM, Curve, CurveM, CurvePolygon, CurvePolygonM, CurvePolygonZ, CurvePolygonZM, CurveZ, CurveZM, GeometryCollection, GeometryCollection25D, GeometryCollectionM, GeometryCollectionZM, LineString, LineString25D, LineStringM, LineStringZM, LinearRing, MultiCurve, MultiCurveM, MultiCurveZ, MultiCurveZM, MultiLineString, MultiLineString25D, MultiLineStringM, MultiLineStringZM, MultiPoint, MultiPoint25D, MultiPointM, MultiPointZM, MultiPolygon, MultiPolygon25D, MultiPolygonM, MultiPolygonZM, MultiSurface, MultiSurfaceM, MultiSurfaceZ, MultiSurfaceZM, None, Point, Point25D, PointM, PointZM, Polygon, Polygon25D, PolygonM, PolygonZM, PolyhedralSurface, PolyhedralSurfaceM, PolyhedralSurfaceZ, PolyhedralSurfaceZM, Surface, SurfaceM, SurfaceZ, SurfaceZM, TIN, TINM, TINZ, TINZM, Triangle, TriangleM, TriangleZ, TriangleZM, and Unknown.
5348 #*
5349 sub Types {
5351 }
5352 
5353 #** @method Geo::OGR::GeomFieldDefn new(%params)
5354 # Class method.
5355 # @brief Create a new spatial field definition.
5356 #
5357 # @param params one or more of:
5358 # - \a Name name for the field (default is 'geom').
5359 # - \a GeometryType type for the field type, one of Geo::OGR::GeomFieldDefn::Types (default is 'Unknown').
5360 # - \a SpatialReference a Geo::OSR::SpatialReference object.
5361 # - \a Nullable (default is true)
5362 # - \a Ignored (default is false)
5363 #
5364 # @note Simplified parameters <name> => <type> is also supported.
5365 #
5366 # @return a new Geo::OGR::GeomFieldDefn object
5367 #*
5368 sub new {
5369  my $pkg = shift;
5370  my $params = {Name => 'geom', Type => 'Unknown'};
5371  if (@_ == 0) {
5372  } elsif (@_ == 1) {
5373  $params->{Name} = shift;
5374  } elsif (@_ == 2 and not $Geo::OGR::GeomFieldDefn::SCHEMA_KEYS{$_[0]}) {
5375  $params->{Name} = shift;
5376  $params->{Type} = shift;
5377  } else {
5378  my $tmp = @_ % 2 == 0 ? {@_} : shift;
5379  for my $key (keys %$tmp) {
5380  if ($Geo::OGR::GeomFieldDefn::SCHEMA_KEYS{$key}) {
5381  $params->{$key} = $tmp->{$key};
5382  } else {
5383  carp "Unknown parameter: '$key'." if $key ne 'Index' && $key ne 'GeometryType';
5384  }
5385  }
5386  $params->{Type} //= $tmp->{GeometryType};
5387  }
5388  $params->{Type} = s2i(geometry_type => $params->{Type});
5389  my $self = Geo::OGRc::new_GeomFieldDefn($params->{Name}, $params->{Type});
5390  bless $self, $pkg;
5391  delete $params->{Name};
5392  delete $params->{Type};
5393  $self->Schema($params);
5394  return $self;
5395 }
5396 
5397 #** @class Geo::OGR::Geometry
5398 # @brief Spatial data.
5399 # @details A geometry is spatial data (coordinate values, and a reference to a
5400 # spatial reference system) organized into one of the geometry
5401 # types. Geometries can be created from several type of data including
5402 # a Perl data structure. There are several methods, which modify,
5403 # compare, test, or compute values from geometries.
5404 # @note Most spatial analysis methods require <a
5405 # href="http://geos.osgeo.org/doxygen/">GEOS</a> to work rigorously.
5406 #*
5407 package Geo::OGR::Geometry;
5408 
5409 use base qw(Geo::OGR)
5410 
5411 #** @method AddGeometry($other)
5412 # Object method.
5413 # Add a copy of another geometry to a geometry collection
5414 # @param other a Geo::OGR::Geometry object
5415 #*
5416 sub AddGeometry {
5417 }
5418 
5419 #** @method AddGeometryDirectly($other)
5420 # Object method.
5421 # @param other a Geo::OGR::Geometry object
5422 #*
5423 sub AddGeometryDirectly {
5424 }
5425 
5426 #** @method AddPoint($x, $y, $z)
5427 # Object method.
5428 # Set the data of a point or add a point to a line string. Consider
5429 # using Geo::OGR::Geometry::Points. Note that the coordinate
5430 # dimension is automatically upgraded to 25D (3) if z is given.
5431 # @param x
5432 # @param y
5433 # @param z [optional]
5434 # Calls internally the 2D or 3D version depending on the number of parameters.
5435 #*
5436 sub AddPoint {
5437  my $self = shift;
5438  my $t = $self->GetGeometryType;
5439  my $has_z = HasZ($t);
5440  my $has_m = HasM($t);
5441  if (!$has_z && !$has_m) {
5442  $self->AddPoint_2D(@_[0..1]);
5443  } elsif ($has_z && !$has_m) {
5444  $self->AddPoint_3D(@_[0..2]);
5445  } elsif (!$has_z && $has_m) {
5446  $self->AddPointM(@_[0..2]);
5447  } else {
5448  $self->AddPointZM(@_[0..3]);
5449  }
5450 }
5451 
5452 #** @method AddPointM()
5453 #*
5454 sub AddPointM {
5455 }
5456 
5457 #** @method AddPointZM()
5458 #*
5459 sub AddPointZM {
5460 }
5461 
5462 #** @method AddPoint_2D($x, $y)
5463 # Object method.
5464 # Set the data of a point or add a point to a line string. Consider
5465 # using Geo::OGR::Geometry::Points.
5466 # @param x
5467 # @param y
5468 #*
5469 sub AddPoint_2D {
5470 }
5471 
5472 #** @method AddPoint_3D($x, $y, $z)
5473 # Object method.
5474 # Set the data of a point or add a point to a line string. Note that
5475 # the coordinate dimension is automatically upgraded to 25D (3). Consider
5476 # using Geo::OGR::Geometry::Points.
5477 # @param x
5478 # @param y
5479 # @param z
5480 #*
5481 sub AddPoint_3D {
5482 }
5483 
5484 #** @method Geo::OGR::Geometry ApproximateArcAngles(%params)
5485 # Package subroutine.
5486 # Create a line string, which approximates an arc.
5487 # @note All angles are in degrees.
5488 #
5489 # @param %params Named parameters:
5490 # - \a Center center point (default is [0, 0, 0])
5491 # - \a PrimaryRadius default is 1.
5492 # - \a SecondaryAxis default is 1.
5493 # - \a Rotation default is 0.
5494 # - \a StartAngle default is 0.
5495 # - \a EndAngle default is 360.
5496 # - \a MaxAngleStepSizeDegrees default is 4.
5497 # @return a new Geo::OGR::Geometry object.
5498 #*
5499 sub ApproximateArcAngles {
5500  my %p = @_;
5501  my %default = ( Center => [0,0,0],
5502  PrimaryRadius => 1,
5503  SecondaryAxis => 1,
5504  Rotation => 0,
5505  StartAngle => 0,
5506  EndAngle => 360,
5507  MaxAngleStepSizeDegrees => 4
5508  );
5509  for my $p (keys %p) {
5510  if (exists $default{$p}) {
5511  $p{$p} //= $default{$p};
5512  } else {
5513  carp "Unknown parameter: '$p'.";
5514  }
5515  }
5516  for my $p (keys %default) {
5517  $p{$p} //= $default{$p};
5518  }
5519  error("Usage: Center => [x,y,z].") unless ref($p{Center}) eq 'ARRAY';
5520  for my $i (0..2) {
5521  $p{Center}->[$i] //= 0;
5522  }
5523  return Geo::OGR::ApproximateArcAngles($p{Center}->[0], $p{Center}->[1], $p{Center}->[2], $p{PrimaryRadius}, $p{SecondaryAxis}, $p{Rotation}, $p{StartAngle}, $p{EndAngle}, $p{MaxAngleStepSizeDegrees});
5524 }
5525 
5526 #** @method scalar Area()
5527 # Object method.
5528 # @note a.k.a. GetArea
5529 # @return the area of the polygon or multipolygon
5530 #*
5531 sub Area {
5532 }
5533 
5534 #** @method scalar As(%params)
5535 # Object method.
5536 # Export the geometry into a known format.
5537 #
5538 # @param params Named parameters:
5539 # - \a Format One of
5540 # - \a WKT Well Known Text.
5541 # - <em>ISO WKT</em>
5542 # - \a Text Same as WKT.
5543 # - \a WKB Well Known Binary.
5544 # - <em>ISO WKB</em>
5545 # - \a Binary Same as WKB.
5546 # - \a HEXWKB
5547 # - \a HEXEWKB
5548 # - \a GML
5549 # - \a GeoJSON
5550 # - \a ByteOrder Byte order for binary formats. Default is 'XDR'.
5551 # - \a SRID Spatial reference id for HEXEWKB.
5552 # - \a Options GML generation options.
5553 # - \a AltitudeMode For KML.
5554 #
5555 # @return the geometry in a given format.
5556 #*
5557 sub As {
5558  my $self = shift;
5559  my $p = named_parameters(\@_, Format => undef, ByteOrder => 'XDR', SRID => undef, Options => undef, AltitudeMode => undef);
5560  my $f = $p->{format};
5561  if ($f =~ /text/i) {
5562  return $self->AsText;
5563  } elsif ($f =~ /wkt/i) {
5564  if ($f =~ /iso/i) {
5565  return $self->ExportToIsoWkt;
5566  } else {
5567  return $self->AsText;
5568  }
5569  } elsif ($f =~ /binary/i) {
5570  return $self->ExportToWkb($p->{byteorder});
5571  } elsif ($f =~ /wkb/i) {
5572  if ($f =~ /iso/i) {
5573  $p->{byteorder} = s2i(byte_order => $p->{byteorder});
5574  return $self->ExportToIsoWkb($p->{byteorder});
5575  } elsif ($f =~ /ewkb/i) {
5576  return $self->AsHEXEWKB($p->{srid});
5577  } elsif ($f =~ /hex/i) {
5578  return $self->AsHEXWKB;
5579  } else {
5580  return $self->ExportToWkb($p->{byteorder});
5581  }
5582  } elsif ($f =~ /gml/i) {
5583  return $self->ExportToGML($p->{options});
5584  } elsif ($f =~ /kml/i) {
5585  return $self->ExportToKML($p->{altitudemode});
5586  } elsif ($f =~ /json/i) {
5587  return $self->AsJSON;
5588  } else {
5589  error(1, $f, map {$_=>1} qw/Text WKT ISO_WKT ISO_WKB HEX_WKB HEX_EWKB Binary GML KML JSON/);
5590  }
5591 }
5592 
5593 #** @method scalar AsBinary()
5594 # Object method.
5595 # Export the geometry into WKB.
5596 # @sa Geo::OGR::Geometry::As
5597 # @return the geometry as WKB.
5598 #*
5599 sub AsBinary {
5600 }
5601 
5602 #** @method scalar AsText()
5603 # Object method.
5604 # Export the geometry into WKT.
5605 # @sa Geo::OGR::Geometry::As
5606 # @return the geometry as WKT.
5607 #*
5608 sub AsText {
5609 }
5610 
5611 #** @method AssignSpatialReference($srs)
5612 # Object method.
5613 # @param srs a Geo::OSR::SpatialReference object
5614 #*
5615 sub AssignSpatialReference {
5616 }
5617 
5618 #** @method Geo::OGR::Geometry Boundary()
5619 # Object method.
5620 # @note a.k.a. GetBoundary
5621 # @return the boundary of this geometry as a geometry
5622 # @since 1.8.0
5623 #*
5624 sub Boundary {
5625 }
5626 
5627 #** @method Geo::OGR::Geometry Buffer($distance, $quadsecs = 30)
5628 # Object method.
5629 # @param distance
5630 # @param quadsecs
5631 # @return a new Geo::OGR::Geometry object
5632 #*
5633 sub Buffer {
5634 }
5635 
5636 #** @method Geo::OGR::Geometry BuildPolygonFromEdges($BestEffort = 0, $AutoClose = 0, $Tolerance = 0)
5637 # Object method.
5638 # Attempt to create a polygon from a collection of lines or from a multilinestring.
5639 # @param BestEffort For future
5640 # @param AutoClose Assure the first and last points of rings are same.
5641 # @param Tolerance Snap distance.
5642 # @exception Several possibilities, some are reported, some are general errors.
5643 # @return a new Geo::OGR::Geometry object (Polygon)
5644 #*
5645 sub BuildPolygonFromEdges {
5646 }
5647 
5648 #** @method list ByteOrders()
5649 # Package subroutine.
5650 # Same as Geo::OGR::ByteOrders
5651 #*
5652 sub ByteOrders {
5653  return @BYTE_ORDER_TYPES;
5654 }
5655 
5656 #** @method Geo::OGR::Geometry Centroid()
5657 # Object method.
5658 # @return a new Geo::OGR::Geometry object
5659 # @since 1.8.0
5660 #*
5661 sub Centroid {
5662 }
5663 
5664 #** @method Geo::OGR::Geometry Clone()
5665 # Object method.
5666 # @return a new Geo::OGR::Geometry object
5667 #*
5668 sub Clone {
5669 }
5670 
5671 #** @method CloseRings()
5672 # Object method.
5673 #*
5674 sub CloseRings {
5675 }
5676 
5677 #** @method Geo::OGR::Geometry Collect(@geometries)
5678 # Object method.
5679 # Create a geometrycollection from this and possibly other geometries.
5680 # @param geometries [optional] More geometries to add to the collection.
5681 # @return a new Geo::OGR::Geometry object of type geometrycollection.
5682 #*
5683 sub Collect {
5684 }
5685 
5686 #** @method scalar Contains($other)
5687 # Object method.
5688 # @param other a Geo::OGR::Geometry object
5689 # @return true if this geometry contains the other geometry, false otherwise
5690 #*
5691 sub Contains {
5692 }
5693 
5694 #** @method Geo::OGR::Geometry ConvexHull()
5695 # Object method.
5696 # @return a new Geo::OGR::Geometry object
5697 #*
5698 sub ConvexHull {
5699 }
5700 
5701 #** @method scalar CoordinateDimension($dimension)
5702 # Object method.
5703 # @param dimension [optional]
5704 # @return 2 or 3
5705 #*
5706 sub CoordinateDimension {
5707  my $self = shift;
5708  SetCoordinateDimension($self, $_[0]) if @_;
5709  GetCoordinateDimension($self) if defined wantarray;
5710 }
5711 
5712 #** @method scalar Crosses($other)
5713 # Object method.
5714 # @param other a Geo::OGR::Geometry object
5715 # @return true if this geometry crosses the other geometry, false otherwise
5716 #*
5717 sub Crosses {
5718 }
5719 
5720 #** @method DelaunayTriangulation()
5721 #*
5722 sub DelaunayTriangulation {
5723 }
5724 
5725 #** @method Geo::OGR::Geometry Difference($other)
5726 # Object method.
5727 # @param other a Geo::OGR::Geometry object
5728 # @return a new Geo::OGR::Geometry object
5729 #*
5730 sub Difference {
5732 
5733 #** @method scalar Disjoint($other)
5734 # Object method.
5735 # @param other a Geo::OGR::Geometry object
5736 # @return true if this geometry is disjoint from the other geometry, false otherwise
5737 #*
5738 sub Disjoint {
5739 }
5741 #** @method list Dissolve()
5742 # Object method.
5743 # Dissolve a geometrycollection into separate geometries.
5744 # @return a list of new Geo::OGR::Geometry objects cloned from the collection.
5745 #*
5746 sub Dissolve {
5747  my $self = shift;
5748  my @c;
5749  my $n = $self->GetGeometryCount;
5750  if ($n > 0) {
5751  for my $i (0..$n-1) {
5752  push @c, $self->GetGeometryRef($i)->Clone;
5753  }
5754  } else {
5755  push @c, $self;
5756  }
5757  return @c;
5759 
5760 #** @method scalar Distance($other)
5761 # Object method.
5762 # @param other a Geo::OGR::Geometry object
5763 # @return the distance to the other geometry
5764 #*
5765 sub Distance {
5766 }
5767 
5768 #** @method Distance3D()
5769 #*
5770 sub Distance3D {
5771 }
5772 
5773 #** @method Empty()
5774 # Object method.
5775 # Clear geometry data, i.e., remove all points, or, for a point, set
5776 # the coordinate dimension as zero.
5777 #*
5778 sub Empty {
5779 }
5780 
5781 #** @method scalar Equals($other)
5782 # Object method.
5783 # @note a.k.a. Equal (deprecated)
5784 # @param other a Geo::OGR::Geometry object
5785 # @return true if this geometry is equivalent to the other geometry, false otherwise
5786 #*
5787 sub Equals {
5788 }
5789 
5790 #** @method Extent()
5791 #*
5792 sub Extent {
5793  my $self = shift;
5794  return Geo::GDAL::Extent->new($self->GetEnvelope);
5795 }
5796 
5797 #** @method Feature()
5798 #*
5799 sub Feature {
5800  my $self = shift;
5801  parent($self);
5802 }
5803 
5804 #** @method FlattenTo2D()
5805 # Object method.
5806 #*
5807 sub FlattenTo2D {
5809 
5810 #** @method Geo::OGR::Geometry ForceTo($type, ref options)
5811 # Object method.
5812 # Attempt to make a geometry of type 'type' out of this geometry.
5813 # @param type target geometry type. One of Geo::OGR::GeometryTypes.
5814 # @param options not used currently.
5815 # @return a new Geo::OGR::Geometry object.
5816 #*
5817 sub ForceTo {
5818  my $self = shift;
5819  my $type = shift;
5820  $type = s2i(geometry_type => $type);
5821  eval {
5822  $self = Geo::OGR::ForceTo($self, $type, @_);
5823  };
5824  confess last_error() if $@;
5825  return $self;
5826 }
5827 
5828 #** @method Geo::OGR::Geometry ForceToCollection(@geometries)
5829 # Object method.
5830 # Create a geometrycollection from the geometry.
5831 # @param geometries [optional] More geometries to add to the collection.
5832 # @return a new Geo::OGR::Geometry object of type geometrycollection.
5833 #*
5834 sub ForceToCollection {
5835  my $self = Geo::OGR::Geometry->new(GeometryType => 'GeometryCollection');
5836  for my $g (@_) {
5837  $self->AddGeometry($g);
5838  }
5839  return $self;
5840 }
5841 
5842 #** @method Geo::OGR::Geometry ForceToLineString()
5843 # Object method.
5844 # Attempt to create a line string from this geometry.
5845 # @return a new Geo::OGR::Geometry object.
5846 #*
5847 sub ForceToLineString {
5848  my $self = shift;
5849  return Geo::OGR::ForceToLineString($self);
5850 }
5851 
5852 #** @method Geo::OGR::Geometry ForceToMultiLineString(@linestrings)
5853 # Object method.
5854 # Attempt to create a multilinestring from the geometry, which must be a linestring.
5855 # @param linestrings [optional] More linestrings to add to the collection.
5856 # @return a new Geo::OGR::Geometry object of type multilinestring.
5857 #*
5858 sub ForceToMultiLineString {
5859  my $self = shift;
5860  $self = Geo::OGR::ForceToMultiLineString($self);
5861  for my $g (@_) {
5862  $self->AddGeometry($g);
5863  }
5864  return $self;
5865 }
5866 
5867 #** @method Geo::OGR::Geometry ForceToMultiPoint(@points)
5868 # Object method.
5869 # Attempt to create a multipoint from the geometry, which must be a point.
5870 # @param points [optional] More points to add to the collection.
5871 # @return a new Geo::OGR::Geometry object of type multipoint.
5872 #*
5873 sub ForceToMultiPoint {
5874  my $self = shift;
5875  $self = Geo::OGR::ForceToMultiPoint($self);
5876  for my $g (@_) {
5877  $self->AddGeometry($g);
5878  }
5879  return $self;
5880 }
5881 
5882 #** @method Geo::OGR::Geometry ForceToMultiPolygon(@polygons)
5883 # Object method.
5884 # Attempt to create a multipolygon from the geometry, which must be a polygon.
5885 # @param polygons [optional] More polygons to add to the collection.
5886 # @return a new Geo::OGR::Geometry object of type multipolygon.
5887 #*
5888 sub ForceToMultiPolygon {
5889  my $self = shift;
5890  $self = Geo::OGR::ForceToMultiPolygon($self);
5891  for my $g (@_) {
5892  $self->AddGeometry($g);
5893  }
5894  return $self;
5895 }
5896 
5897 #** @method Geo::OGR::Geometry ForceToPolygon()
5898 # Object method.
5899 # Attempt to create a polygon from this geometry.
5900 # @exception None reported. If this method fails, just a copy is returned.
5901 # @return a new Geo::OGR::Geometry object.
5902 #*
5903 sub ForceToPolygon {
5904 }
5905 
5906 #** @method scalar Geometry($n)
5907 # Object method.
5908 # Return the n:th (note zero-based index) element in this geometry or
5909 # geometry in this collection.
5910 # @note a.k.a. GetGeometryRef
5911 # @param n index to the geometry, which is a part of this geometry
5912 # @return a new Geo::OGR::Geometry object whose data is a part of the
5913 # parent geometry (this geometry is kept alive while the returned
5914 # geometry exists)
5915 #*
5916 sub Geometry {
5917 }
5918 
5919 #** @method scalar GeometryCount()
5920 # Object method.
5921 # Return the number of elements in this geometry or geometries in this collection.
5922 # @note a.k.a. GetGeometryCount
5923 # @return an integer
5924 #*
5925 sub GeometryCount {
5926 }
5927 
5928 #** @method scalar GeometryType()
5929 # Object method.
5930 #
5931 # @note The deprecated method GetGeometryType returns the
5932 # type as an integer
5933 #
5934 # @return the geometry type of this geometry (one of Geo::OGR::GeometryTypes).
5935 #*
5936 sub GeometryType {
5937  my $self = shift;
5938  return i2s(geometry_type => $self->GetGeometryType);
5939 }
5940 
5941 #** @method list GeometryTypes()
5942 # Package subroutine.
5943 # Same as Geo::OGR::GeometryTypes
5944 #*
5945 sub GeometryTypes {
5946  return @GEOMETRY_TYPES;
5947 }
5948 
5949 #** @method scalar GetCoordinateDimension()
5950 # Object method.
5951 # @return an integer
5952 #*
5953 sub GetCoordinateDimension {
5954 }
5955 
5956 #** @method GetCurveGeometry()
5957 #*
5958 sub GetCurveGeometry {
5959 }
5960 
5961 #** @method scalar GetDimension()
5962 # Object method.
5963 # @return 0, 1, or 2
5964 #*
5965 sub GetDimension {
5966 }
5967 
5968 #** @method list GetEnvelope()
5969 # Object method.
5970 # @note In scalar context returns a reference to an anonymous array
5971 # containing the envelope.
5972 # @return the envelope ($minx, $maxx, $miny, $maxy)
5973 #*
5974 sub GetEnvelope {
5975 }
5976 
5977 #** @method list GetEnvelope3D()
5978 # Object method.
5979 # @note In scalar context returns a reference to an anonymous array
5980 # containing the envelope.
5981 # @return the 3-D envelope ($minx, $maxx, $miny, $maxy, $minz, $maxz)
5982 # @since 1.9.0
5983 #*
5984 sub GetEnvelope3D {
5985 }
5986 
5987 #** @method scalar GetGeometryRef($index)
5988 # Object method.
5989 # @deprecated Use Geo::OGR::Geometry
5990 #*
5991 sub GetGeometryRef {
5992  my ($self, $i) = @_;
5993  my $ref = $self->_GetGeometryRef($i);
5994  keep($ref, $self);
5995  return $ref;
5996 }
5997 
5998 #** @method GetLinearGeometry()
5999 #*
6000 sub GetLinearGeometry {
6001 }
6002 
6003 #** @method GetM()
6004 #*
6005 sub GetM {
6006 }
6007 
6008 #** @method list GetPoint($index = 0)
6009 # Object method.
6010 # @param index
6011 # @return (x,y) or a list with more coordinates
6012 #*
6013 sub GetPoint {
6014  my($self, $i) = @_;
6015  $i //= 0;
6016  my $t = $self->GetGeometryType;
6017  my $has_z = HasZ($t);
6018  my $has_m = HasM($t);
6019  my $point;
6020  if (!$has_z && !$has_m) {
6021  $point = $self->GetPoint_2D($i);
6022  } elsif ($has_z && !$has_m) {
6023  $point = $self->GetPoint_3D($i);
6024  } elsif (!$has_z && $has_m) {
6025  $point = $self->GetPointZM($i);
6026  @$point = ($point->[0], $point->[1], $point->[3]);
6027  } else {
6028  $point = $self->GetPointZM($i);
6029  }
6030  return wantarray ? @$point : $point;
6031 }
6032 
6033 #** @method scalar GetPointCount()
6034 # Object method.
6035 # @return an integer
6036 #*
6037 sub GetPointCount {
6038 }
6039 
6040 #** @method GetPointZM()
6041 #*
6042 sub GetPointZM {
6043 }
6044 
6045 #** @method scalar GetPoint_2D($index = 0)
6046 # Object method.
6047 # @param index
6048 # @return (x,y) or a list with more coordinates
6049 #*
6050 sub GetPoint_2D {
6051 }
6052 
6053 #** @method scalar GetPoint_3D($index = 0)
6054 # Object method.
6055 # @param index
6056 # @return (x,y) or a list with more coordinates
6057 #*
6058 sub GetPoint_3D {
6059 }
6060 
6061 #** @method Geo::OSR::SpatialReference GetSpatialReference()
6062 # Object method.
6063 # @return a new Geo::OSR::SpatialReference object
6064 #*
6065 sub GetSpatialReference {
6066 }
6067 
6068 #** @method scalar GetX($index = 0)
6069 # Object method.
6070 # @param index
6071 # @return a number
6072 #*
6073 sub GetX {
6074 }
6075 
6076 #** @method scalar GetY($index = 0)
6077 # Object method.
6078 # @param index
6079 # @return a number
6080 #*
6081 sub GetY {
6082 }
6083 
6084 #** @method scalar GetZ($index = 0)
6085 # Object method.
6086 # @param index
6087 # @return a number
6088 #*
6089 sub GetZ {
6090 }
6091 
6092 #** @method HasCurveGeometry()
6093 #*
6094 sub HasCurveGeometry {
6095 }
6096 
6097 #** @method Geo::OGR::Geometry Intersection($other)
6098 # Object method.
6099 # @param other a Geo::OGR::Geometry object
6100 # @return a new Geo::OGR::Geometry object
6101 #*
6102 sub Intersection {
6103 }
6104 
6105 #** @method scalar Intersects($other)
6106 # Object method.
6107 # @note a.k.a. Intersect (deprecated)
6108 # @param other a Geo::OGR::Geometry object
6109 # @return true if this geometry intersects with the other geometry, false otherwise
6110 #*
6111 sub Intersects {
6112 }
6113 
6114 #** @method Is3D()
6115 #*
6116 sub Is3D {
6117 }
6118 
6119 #** @method scalar IsEmpty()
6120 # Object method.
6121 # Test whether the geometry is empty (has no points, or, for a point,
6122 # has coordinate dimension of zero).
6123 # @return boolean
6124 #*
6125 sub IsEmpty {
6126 }
6127 
6128 #** @method IsMeasured()
6129 #*
6130 sub IsMeasured {
6131 }
6132 
6133 #** @method scalar IsRing()
6134 # Object method.
6135 # Test if the geometry is a ring. Requires GEOS in GDAL.
6136 # @return boolean
6137 #*
6138 sub IsRing {
6139 }
6140 
6141 #** @method scalar IsSimple()
6142 # Object method.
6143 # Test the simplicity of the geometry (OGC sense). Requires GEOS in GDAL.
6144 # @return boolean
6145 #*
6146 sub IsSimple {
6148 
6149 #** @method scalar IsValid()
6150 # Object method.
6151 # Test the validity of the geometry (OGC sense). Requires GEOS in GDAL.
6152 # @return boolean
6153 #*
6154 sub IsValid {
6155 }
6156 
6157 #** @method scalar Length()
6158 # Object method.
6159 # @return the length of the linestring
6160 #*
6161 sub Length {
6162 }
6163 
6164 #** @method Move($dx, $dy, $dz)
6165 # Object method.
6166 # Move every point of the object as defined by the parameters.
6167 # @param dx
6168 # @param dy
6169 # @param dz [optional]
6170 #*
6171 sub Move {
6172 }
6173 
6174 #** @method scalar Overlaps($other)
6175 # Object method.
6176 # @param other a Geo::OGR::Geometry object
6177 # @return true if this geometry overlaps the other geometry, false otherwise
6178 #*
6179 sub Overlaps {
6180 }
6181 
6182 #** @method list Point($index, $x, $y, $z)
6183 # Object method.
6184 # Get or set the point
6185 # @param index The index of the point. Optional (ignored if given) for
6186 # Point and Point25D geometries.
6187 # @param x [optional]
6188 # @param y [optional]
6189 # @param z [optional]
6190 # @return
6191 #*
6192 sub Point {
6193  my $self = shift;
6194  my $i;
6195  if (@_) {
6196  my $t = $self->GetGeometryType;
6197  my $i;
6198  if (Flatten($t) == $Geo::OGR::wkbPoint) {
6199  my $has_z = HasZ($t);
6200  my $has_m = HasM($t);
6201  if (!$has_z && !$has_m) {
6202  shift if @_ > 2;
6203  $i = 0;
6204  } elsif ($has_z || $has_m) {
6205  shift if @_ > 3;
6206  $i = 0;
6207  } else {
6208  shift if @_ > 4;
6209  $i = 0;
6210  }
6211  }
6212  $i = shift unless defined $i;
6213  $self->SetPoint($i, @_);
6214  }
6215  return unless defined wantarray;
6216  my $point = $self->GetPoint;
6217  return wantarray ? @$point : $point;
6218 }
6219 
6220 #** @method PointOnSurface()
6221 #*
6222 sub PointOnSurface {
6223 }
6224 
6225 #** @method array reference Points(arrayref points)
6226 # Object method.
6227 # Get or set the points of the geometry. The points (vertices) are
6228 # stored in obvious lists of lists. When setting, the geometry is
6229 # first emptied. The method uses internally either AddPoint_2D or
6230 # AddPoint_3D depending on the coordinate dimension of the input data.
6231 #
6232 # @note The same structure may represent different geometries
6233 # depending on the actual geometry type of the object.
6234 #
6235 # @param points [optional] A reference to an array. A point is a reference to an
6236 # array of numbers, a linestring or a ring is a reference to an array of points,
6237 # a polygon is a reference to an array of rings, etc.
6238 #
6239 # @return A reference to an array.
6240 #*
6241 sub Points {
6242  my $self = shift;
6243  my $t = $self->GetGeometryType;
6244  my $has_z = HasZ($t);
6245  my $has_m = HasM($t);
6246  my $postfix = '';
6247  $postfix .= 'Z' if HasZ($t);
6248  $postfix .= 'M' if HasM($t);
6249  $t = i2s(geometry_type => Flatten($t));
6250  my $points = shift;
6251  if ($points) {
6252  Empty($self);
6253  if ($t eq 'Unknown' or $t eq 'None' or $t eq 'GeometryCollection') {
6254  error("Can't set points of a geometry of type '$t'.");
6255  } elsif ($t eq 'Point') {
6256  # support both "Point" as a list of one point and one point
6257  if (ref($points->[0])) {
6258  $self->AddPoint(@{$points->[0]});
6259  } else {
6260  $self->AddPoint(@$points);
6261  }
6262  } elsif ($t eq 'LineString' or $t eq 'LinearRing' or $t eq 'CircularString') {
6263  for my $p (@$points) {
6264  $self->AddPoint(@$p);
6265  }
6266  } elsif ($t eq 'Polygon') {
6267  for my $r (@$points) {
6268  my $ring = Geo::OGR::Geometry->new('LinearRing');
6269  $ring->Set3D(1) if $has_z;
6270  $ring->SetMeasured(1) if $has_m;
6271  $ring->Points($r);
6272  $self->AddGeometryDirectly($ring);
6273  }
6274  } elsif ($t eq 'MultiPoint') {
6275  for my $p (@$points) {
6276  my $point = Geo::OGR::Geometry->new('Point'.$postfix);
6277  $point->Points($p);
6278  $self->AddGeometryDirectly($point);
6279  }
6280  } elsif ($t eq 'MultiLineString') {
6281  for my $l (@$points) {
6282  my $linestring = Geo::OGR::Geometry->new('LineString'.$postfix);
6283  $linestring->Points($l);
6284  $self->AddGeometryDirectly($linestring);
6285  }
6286  } elsif ($t eq 'MultiPolygon') {
6287  for my $p (@$points) {
6288  my $polygon = Geo::OGR::Geometry->new('Polygon'.$postfix);
6289  $polygon->Points($p);
6290  $self->AddGeometryDirectly($polygon);
6291  }
6292  }
6293  }
6294  return unless defined wantarray;
6295  $self->_GetPoints();
6296 }
6297 
6298 #** @method Polygonize()
6299 #*
6300 sub Polygonize {
6301 }
6302 
6303 #** @method RemoveGeometry()
6304 #*
6305 sub RemoveGeometry {
6306 }
6307 
6308 #** @method Segmentize($MaxLength)
6309 # Object method.
6310 # Modify the geometry such it has no segment longer than the given length.
6311 # @param MaxLength the given length
6312 #*
6313 sub Segmentize {
6314 }
6315 
6316 #** @method Set3D()
6317 #*
6318 sub Set3D {
6319 }
6320 
6321 #** @method SetCoordinateDimension($dimension)
6322 # Object method.
6323 # @param dimension
6324 #*
6325 sub SetCoordinateDimension {
6326 }
6327 
6328 #** @method SetMeasured()
6329 #*
6330 sub SetMeasured {
6331 }
6332 
6333 #** @method SetPoint($index, $x, $y, $z)
6334 # Object method.
6335 # Set the data of a point or a line string. Note that the coordinate
6336 # dimension is automatically upgraded to 25D (3) if z is given.
6337 # @param index
6338 # @param x
6339 # @param y
6340 # @param z [optional]
6341 #*
6342 sub SetPoint {
6343  my $self = shift;
6344  my $t = $self->GetGeometryType;
6345  my $has_z = HasZ($t);
6346  my $has_m = HasM($t);
6347  if (!$has_z && !$has_m) {
6348  $self->SetPoint_2D(@_[0..2]);
6349  } elsif ($has_z && !$has_m) {
6350  $self->SetPoint_3D(@_[0..3]);
6351  } elsif (!$has_z && $has_m) {
6352  $self->SetPointM(@_[0..3]);
6353  } else {
6354  $self->SetPointZM(@_[0..4]);
6355  }
6356 }
6357 
6358 #** @method SetPointM()
6359 #*
6360 sub SetPointM {
6361 }
6362 
6363 #** @method SetPointZM()
6364 #*
6365 sub SetPointZM {
6366 }
6367 
6368 #** @method SetPoint_2D($index, $x, $y)
6369 # Object method.
6370 # @param index
6371 # @param x
6372 # @param y
6373 #*
6374 sub SetPoint_2D {
6375 }
6376 
6377 #** @method SetPoint_3D($index, $x, $y, $z)
6378 # Object method.
6379 # Set the data of a point or a line string. Note that the coordinate
6380 # dimension is automatically upgraded to 25D (3).
6381 # @param index
6382 # @param x
6383 # @param y
6384 # @param z
6385 #*
6386 sub SetPoint_3D {
6387 }
6388 
6389 #** @method Geo::OGR::Geometry Simplify($Tolerance)
6390 # Object method.
6391 # Simplify the geometry.
6392 # @param Tolerance the length tolerance for the simplification
6393 # @since 1.8.0
6394 # @return a new Geo::OSR::Geometry object
6395 #*
6396 sub Simplify {
6397 }
6398 
6399 #** @method SimplifyPreserveTopology()
6400 #*
6401 sub SimplifyPreserveTopology {
6402 }
6403 
6404 #** @method SwapXY()
6405 #*
6406 sub SwapXY {
6407 }
6408 
6409 #** @method Geo::OGR::Geometry SymDifference($other)
6410 # Object method.
6411 # Compute symmetric difference.
6412 # @note a.k.a. SymmetricDifference
6413 # @param other a Geo::OGR::Geometry object
6414 # @return a new Geo::OGR::Geometry object
6415 # @since 1.8.0
6416 #*
6417 sub SymDifference {
6418 }
6419 
6420 #** @method scalar Touches($other)
6421 # Object method.
6422 # @param other a Geo::OGR::Geometry object
6423 # @return true if this geometry touches the other geometry, false otherwise
6424 #*
6425 sub Touches {
6426 }
6427 
6428 #** @method Transform($trans)
6429 # Object method.
6430 # @param trans a Geo::OSR::CoordinateTransformation object
6431 #*
6432 sub Transform {
6433 }
6434 
6435 #** @method TransformTo($srs)
6436 # Object method.
6437 # @param srs a Geo::OSR::SpatialReference object
6438 #*
6439 sub TransformTo {
6440 }
6441 
6442 #** @method Geo::OGR::Geometry Union($other)
6443 # Object method.
6444 # @param other a Geo::OGR::Geometry object
6445 # @return a new Geo::OGR::Geometry object
6446 #*
6447 sub Union {
6448 }
6449 
6450 #** @method Geo::OGR::Geometry UnionCascaded()
6451 # Object method.
6452 # @return a new Geo::OGR::Geometry object
6453 # @since 1.8.0
6454 #*
6455 sub UnionCascaded {
6456 }
6457 
6458 #** @method Value()
6459 #*
6460 sub Value {
6461 }
6462 
6463 #** @method scalar Within($other)
6464 # Object method.
6465 # @param other a Geo::OGR::Geometry object
6466 # @return true if this geometry is within the other geometry, false otherwise
6467 #*
6468 sub Within {
6469 }
6470 
6471 #** @method scalar WkbSize()
6472 # Object method.
6473 # @return an integer
6474 #*
6475 sub WkbSize {
6476 }
6477 
6478 #** @method Geo::OGR::Geometry new(%params)
6479 # Class method.
6480 # @param %params A named parameter, one of:
6481 # - \a GeometryType one the supported geometry types, see Geo::OGR::GeometryTypes.
6482 # - \a WKT a well known text string, which defines a geometry.
6483 # - \a WKB a well known binary string, which defines a geometry.
6484 # - \a HEXWKB WKB in hexadecimal.
6485 # - \a HEXEWKB PostGIS extended WKB.
6486 # - \a GML geometry written in Geographic Markup Language.
6487 # - \a GeoJSON geometry written in GeoJSON (JavaScript Object Notation for Geographic data).
6488 # - \a arc a reference to a list of values defining an arc: [CenterX,
6489 # CenterY, CenterZ, PrimaryRadius, SecondaryRadius, Rotation,
6490 # StartAngle, EndAngle, MaxAngleStepSizeDegrees] (see also Geo::OGR::Geometry::ApproximateArcAngles)
6491 # - \a Points An anonymous array as in method
6492 # Geo::OGR::Geometry::Points; Note: requires also GeometryType
6493 # parameter
6494 #
6495 # @return a new Geo::OGR::Geometry object.
6496 #*
6497 sub new {
6498  my $pkg = shift;
6499  my %param;
6500  if (@_ == 1 and ref($_[0]) eq 'HASH') {
6501  %param = %{$_[0]};
6502  } elsif (@_ % 2 == 0) {
6503  %param = @_;
6504  } else {
6505  ($param{GeometryType}) = @_;
6506  }
6507  my $type = $param{GeometryType} // $param{Type} // $param{type};
6508  my $srs = $param{SRS} // $param{srs};
6509  my $wkt = $param{WKT} // $param{wkt};
6510  my $wkb = $param{WKB} // $param{wkb};
6511  my $hex = $param{HEXEWKB} // $param{HEX_EWKB} // $param{hexewkb} // $param{hex_ewkb};
6512  my $srid;
6513  if ($hex) {
6514  # EWKB contains SRID
6515  $srid = substr($hex, 10, 8);
6516  substr($hex, 10, 8) = '';
6517  } else {
6518  $hex = $param{HEXWKB} // $param{HEX_WKB} // $param{hexwkb} // $param{hex_wkb};
6519  }
6520  if ($hex) {
6521  $wkb = '';
6522  for (my $i = 0; $i < length($hex); $i+=2) {
6523  $wkb .= chr(hex(substr($hex,$i,2)));
6524  }
6525  }
6526  my $gml = $param{GML} // $param{gml};
6527  my $json = $param{GeoJSON} // $param{geojson} // $param{JSON} // $param{json};
6528  my $points = $param{Points} // $param{points};
6529  my $arc = $param{Arc} // $param{arc};
6530  my $self;
6531  if (defined $wkt) {
6532  $self = Geo::OGRc::CreateGeometryFromWkt($wkt, $srs);
6533  } elsif (defined $wkb) {
6534  $self = Geo::OGRc::CreateGeometryFromWkb($wkb, $srs);
6535  } elsif (defined $gml) {
6536  $self = Geo::OGRc::CreateGeometryFromGML($gml);
6537  } elsif (defined $json) {
6538  $self = Geo::OGRc::CreateGeometryFromJson($json);
6539  } elsif (defined $type) {
6540  $type = s2i(geometry_type => $type);
6541  $self = Geo::OGRc::new_Geometry($type); # flattens the type
6542  $self->Set3D(1) if HasZ($type);
6543  $self->SetMeasured(1) if HasM($type);
6544  } elsif (defined $arc) {
6545  $self = Geo::OGRc::ApproximateArcAngles(@$arc);
6546  } else {
6547  error(1, undef, map {$_=>1} qw/GeometryType WKT WKB HEXEWKB HEXWKB GML GeoJSON Arc/);
6548  }
6549  bless $self, $pkg if defined $self;
6550  $self->Points($points) if $points;
6551  return $self;
6552 }
6553 
6554 #** @class Geo::OGR::Layer
6555 # @brief A collection of similar features.
6556 # @details A layer object is typically obtained with a data source object. A
6557 # layer has a data model (a schema), which is maintained in a
6558 # definition object, and a set of features, which contain data
6559 # according to the data model. The schema is typically set when the
6560 # layer is created or opened, but it may be altered somewhat with
6561 # methods Geo::OGR::Layer::CreateField,
6562 # Geo::OGR::Layer::AlterFieldDefn, and
6563 # Geo::OGR::Layer::DeleteField. Features and/or their data can be
6564 # read, inserted and deleted. Reading can be filtered. Layers can be
6565 # compared to each other with methods Clip, Erase, Identity,
6566 # Intersection, SymDifference, Union, and Update.
6567 # A layer may have metadata OLMD_FID64 => 'YES' if it holds features
6568 # with 64 bit FIDs. The metadata of a layer can be obtained with
6569 # GetMetadata method.
6570 #*
6571 package Geo::OGR::Layer;
6572 
6573 use base qw(Geo::GDAL::MajorObject Geo::OGR)
6574 
6575 #** @method AlterFieldDefn($name, %params)
6576 # Object method.
6577 # @param field the name of the field to be altered.
6578 # @param params as in Geo::OGR::FieldDefn::new. Width and
6579 # Precision should be both or neither.
6580 # @note Only non-spatial fields can be altered.
6581 # @note Also the deprecated form AlterFieldDefn($field,
6582 # Geo::OGR::FieldDefn $Defn, $Flags) works.
6583 #*
6584 sub AlterFieldDefn {
6585  my $self = shift;
6586  my $index = $self->GetLayerDefn->GetFieldIndex(shift // 0);
6587  my $param = @_ % 2 == 0 ? {@_} : shift;
6588  if (blessed($param) and $param->isa('Geo::OGR::FieldDefn')) {
6589  _AlterFieldDefn($self, $index, @_);
6590  } else {
6591  my $definition = Geo::OGR::FieldDefn->new($param);
6592  my $flags = 0;
6593  $flags |= 1 if exists $param->{Name};
6594  $flags |= 2 if exists $param->{Type};
6595  $flags |= 4 if exists $param->{Width} or exists $param->{Precision};
6596  $flags |= 8 if exists $param->{Nullable};
6597  $flags |= 16 if exists $param->{Default};
6598  _AlterFieldDefn($self, $index, $definition, $flags);
6599  }
6600 }
6601 
6602 #** @method list Capabilities()
6603 # Object method.
6604 # Both a package subroutine and an object method.
6605 # @return a list of capabilities. The object method returns a list of
6606 # the capabilities the layer has. The package subroutine returns a list of
6607 # all potential capabilities a layer may have. These are currently:
6608 # AlterFieldDefn, CreateField, CreateGeomField, CurveGeometries, DeleteFeature, DeleteField, FastFeatureCount, FastGetExtent, FastSetNextByIndex, FastSpatialFilter, IgnoreFields, MeasuredGeometries, RandomRead, RandomWrite, ReorderFields, SequentialWrite, StringsAsUTF8, and Transactions.
6609 #
6610 # Examples:
6611 # \code
6612 # @cap = Geo::OGR::Layer::Capabilities(); # the package subroutine
6613 # @cap = $layer->Capabilities(); # the object method
6614 # \endcode
6615 #*
6616 sub Capabilities {
6617  return @CAPABILITIES if @_ == 0;
6618  my $self = shift;
6619  my @cap;
6620  for my $cap (@CAPABILITIES) {
6621  push @cap, $cap if _TestCapability($self, $CAPABILITIES{$cap});
6622  }
6623  return @cap;
6624 }
6625 
6626 #** @method Clip(Geo::OGR::Layer method, Geo::OGR::Layer result, hashref options, coderef callback, $callback_data)
6627 # Object method.
6628 # Clip off areas that are not covered by the method layer. The schema
6629 # of the result layer can be set before calling this method, or is
6630 # initialized to to contain all fields from
6631 # this and method layer.
6632 # @param method method layer.
6633 # @param result result layer.
6634 # @param options a reference to an options hash.
6635 # @param callback [optional] a reference to a subroutine, which will
6636 # be called with parameters (number progress, string msg, callback_data)
6637 # @param callback_data [optional]
6638 #*
6639 sub Clip {
6640 }
6641 
6642 #** @method CommitTransaction()
6643 # Object method.
6644 #*
6645 sub CommitTransaction {
6646 }
6647 
6648 #** @method CreateFeature()
6649 #*
6650 sub CreateFeature {
6651 }
6652 
6653 #** @method CreateField(%params)
6654 # Object method.
6655 # Create a field.
6656 # @param params as in Geo::OGR::FieldDefn::new or
6657 # Geo::OGR::GeomFieldDefn::new, plus ApproxOK (whose default is true).
6658 #*
6659 sub CreateField {
6660  my $self = shift;
6661  my %defaults = ( ApproxOK => 1,
6662  Type => '' );
6663  my %params;
6664  if (@_ == 0) {
6665  } elsif (ref($_[0]) eq 'HASH') {
6666  %params = %{$_[0]};
6667  } elsif (@_ % 2 == 0) {
6668  %params = @_;
6669  } else {
6670  ($params{Defn}) = @_;
6671  }
6672  for my $k (keys %defaults) {
6673  $params{$k} //= $defaults{$k};
6674  }
6675  if (blessed($params{Defn}) and $params{Defn}->isa('Geo::OGR::FieldDefn')) {
6676  $self->_CreateField($params{Defn}, $params{ApproxOK});
6677  } elsif (blessed($_[0]) and $params{Defn}->isa('Geo::OGR::GeomFieldDefn')) {
6678  $self->CreateGeomField($params{Defn}, $params{ApproxOK});
6679  } else {
6680  # if Name and Type are missing, assume Name => Type
6681  if (!(exists $params{Name} && exists $params{Type})) {
6682  for my $key (sort keys %params) {
6683  if (s_exists(field_type => $params{$key}) ||
6684  s_exists(geometry_type => $params{$key}))
6685  {
6686  $params{Name} = $key;
6687  $params{Type} = $params{$key};
6688  delete $params{$key};
6689  last;
6690  }
6691  }
6692  }
6693  my $a = $params{ApproxOK};
6694  delete $params{ApproxOK};
6695  if (exists $params{GeometryType}) {
6696  $params{Type} = $params{GeometryType};
6697  delete $params{GeometryType};
6698  }
6699  if (s_exists(field_type => $params{Type})) {
6700  my $fd = Geo::OGR::FieldDefn->new(%params);
6701  _CreateField($self, $fd, $a);
6702  } elsif (s_exists(geometry_type => $params{Type})) {
6703  my $fd = Geo::OGR::GeomFieldDefn->new(%params);
6704  CreateGeomField($self, $fd, $a);
6705  } elsif ($params{Type} ) {
6706  error("Invalid field type: $params{Type}.")
6707  } elsif ($params{Name} ) {
6708  error("Missing type for field: $params{Name}.")
6709  } else {
6710  error("Missing name and type for a field.")
6711  }
6712  }
6713 }
6714 
6715 #** @method DataSource()
6716 #*
6717 sub DataSource {
6718 }
6719 
6720 #** @method Dataset()
6721 #*
6722 sub Dataset {
6723  my $self = shift;
6724  parent($self);
6725 }
6726 
6727 #** @method DeleteFeature($fid)
6728 # Object method.
6729 # @param fid feature id
6730 #*
6731 sub DeleteFeature {
6732 }
6733 
6734 #** @method DeleteField($field)
6735 # Object method.
6736 # Delete an existing field from a layer.
6737 # @param field name (or index) of the field which is deleted
6738 # @note Only non-spatial fields can be deleted.
6739 #*
6740 sub DeleteField {
6741  my ($self, $field) = @_;
6742  my $index = $self->GetLayerDefn->GetFieldIndex($field // 0);
6743  _DeleteField($self, $index);
6744 }
6745 
6746 #** @method Erase(Geo::OGR::Layer method, Geo::OGR::Layer result, hashref options, coderef callback, $callback_data)
6747 # Object method.
6748 # The result layer contains features whose geometries represent areas
6749 # that are in the input layer but not in the method layer. The
6750 # features in the result layer have attributes from the input
6751 # layer. The schema of the result layer can be set by the user or, if
6752 # it is empty, is initialized to contain all fields in the input
6753 # layer.
6754 # @param method method layer.
6755 # @param result result layer.
6756 # @param options a reference to an options hash.
6757 # @param callback [optional] a reference to a subroutine, which will
6758 # be called with parameters (number progress, string msg, callback_data)
6759 # @param callback_data [optional]
6760 #*
6761 sub Erase {
6762 }
6763 
6764 #** @method Geo::OGR::Feature Feature($f)
6765 # Object method.
6766 #
6767 # @param f [optional] feature id, a feature, a row, or a tuple
6768 #
6769 # @note If the argument feature has a null FID (FID not set) the
6770 # feature is inserted into the layer as a new feature. If the FID is
6771 # non null, then the feature replaces the feature in the layer with
6772 # that FID.
6773 #
6774 # @return a new Geo::OGR::Feature object that represents the feature
6775 # in the layer.
6776 #*
6777 sub Feature {
6778  my $self = shift;
6779  my $x = shift;
6780  return $self->GetFeature($x) unless $x && ref $x;
6781  # Insert or Set depending on the FID
6782  my $fid;
6783  if (ref $x eq 'ARRAY') {
6784  # FID is the first item in the array
6785  $fid = $x->[0];
6786  } elsif (ref $x eq 'HASH') {
6787  # FID is FID
6788  $fid = $x->{FID};
6789  } else {
6790  $fid = $x->FID;
6791  }
6792  # OGRNullFID is -1
6793  if (!defined $fid || $fid < 0) {
6794  $self->InsertFeature($x);
6795  } else {
6796  $self->SetFeature($x);
6797  }
6798 }
6799 
6800 #** @method scalar FeatureCount($force = 1)
6801 # Object method.
6802 # A.k.a GetFeatureCount
6803 # @param force
6804 # @return integer
6805 #*
6806 sub FeatureCount {
6807 }
6808 
6809 #** @method Features()
6810 #*
6811 sub Features {
6812  my $self = shift;
6813  $self->ResetReading;
6814  return sub {
6815  return $self->GetNextFeature;
6816  }
6817 }
6818 
6819 #** @method ForFeatures($code, $in_place)
6820 # Object method.
6821 # @note experimental, the syntax may change
6822 #
6823 # Call code for all features. This is a simple wrapper for
6824 # ResetReading and while(GetNextFeature).
6825 #
6826 # Example usage:
6827 # \code
6828 # $layer->ForFeatures(sub {my $f = shift; $self->DeleteFeature($f->FID)}); # empties the layer
6829 # \endcode
6830 #
6831 # @param code a reference to a subroutine, which is called with each
6832 # feature as an argument
6833 # @param in_place if set to true, the feature is stored back to the
6834 # layer
6835 #*
6836 sub ForFeatures {
6837  my $self = shift;
6838  my $code = shift;
6839  my $in_place = shift;
6840  $self->ResetReading;
6841  while (my $f = $self->GetNextFeature) {
6842  keep($f, $self);
6843  $code->($f);
6844  $self->SetFeature($f) if $in_place;
6845  };
6846 }
6847 
6848 #** @method ForGeometries($code, $in_place)
6849 # Object method.
6850 # @note experimental, the syntax may change
6851 #
6852 # Call code for all geometries. This is a simple wrapper for
6853 # ResetReading and while(GetNextFeature).
6854 #
6855 # Example usage:
6856 # \code
6857 # my $area = 0;
6858 # $layer->ForGeometries(sub {my $g = shift; $area += $g->Area}); # computes the total area
6859 # \endcode
6860 #
6861 # @param code a reference to a subroutine, which is called with each
6862 # geometry as an argument
6863 # @param in_place if set to true, the geometry is stored back to the
6864 # layer
6865 #*
6866 sub ForGeometries {
6867  my $self = shift;
6868  my $code = shift;
6869  my $in_place = shift;
6870  $self->ResetReading;
6871  while (my $f = $self->GetNextFeature) {
6872  my $g = $f->Geometry();
6873  $code->($g);
6874  if ($in_place) {
6875  $f->Geometry($g);
6876  $self->SetFeature($f);
6877  }
6878  }
6879 }
6880 
6881 #** @method Geometries()
6882 #*
6883 sub Geometries {
6884  my $self = shift;
6885  $self->ResetReading;
6886  return sub {
6887  my $f = $self->GetNextFeature;
6888  return 0 unless $f;
6889  return $f->Geometry;
6890  }
6891 }
6892 
6893 #** @method scalar GeometryType($field)
6894 # Object method.
6895 # @param field the name or index of the spatial field.
6896 # @return the geometry type of the spatial field.
6897 #*
6898 sub GeometryType {
6899  my $self = shift;
6900  my $d = $self->GetDefn;
6901  my $field = $d->GetGeomFieldIndex(shift // 0);
6902  my $fd = $d->_GetGeomFieldDefn($field);
6903  return $fd->Type if $fd;
6904 }
6905 
6906 #** @method Geo::OGR::DataSource GetDataSource()
6907 # Object method.
6908 # @return the data source object to which this layer object belongs to.
6909 #*
6910 sub GetDataSource {
6911  my $self = shift;
6912  parent($self);
6913 }
6914 
6915 #** @method Geo::OGR::FeatureDefn GetDefn()
6916 # Object method.
6917 # A.k.a GetLayerDefn.
6918 # @return a Geo::OGR::FeatureDefn object.
6919 #*
6920 sub GetDefn {
6921  my $self = shift;
6922  my $defn = $self->GetLayerDefn;
6923  keep($defn, $self);
6924 }
6925 
6926 #** @method list GetExtent($force = 1)
6927 # Object method.
6928 # @param force compute the extent even if it is expensive
6929 # @note In scalar context returns a reference to an anonymous array
6930 # containing the extent.
6931 # @return the extent ($minx, $maxx, $miny, $maxy)
6932 # @param force
6933 # @return the extent = ($minx, $maxx, $miny, $maxy) as a listref
6934 #*
6935 sub GetExtent {
6936 }
6937 
6938 #** @method scalar GetFIDColumn()
6939 # Object method.
6940 # @return the name of the underlying database column being used as the
6941 # FID column, or "" if not supported.
6942 #*
6943 sub GetFIDColumn {
6944 }
6945 
6946 #** @method Geo::OGR::Feature GetFeature($fid)
6947 # Object method.
6948 # @param fid feature id
6949 # @return a new Geo::OGR::Feature object that represents the feature in the layer.
6950 #*
6951 sub GetFeature {
6952  my ($self, $fid) = @_;
6953  $fid //= 0;
6954  my $f = $self->_GetFeature($fid);
6955  error(2, "FID=$fid", '"Feature') unless ref $f eq 'Geo::OGR::Feature';
6956  keep($f, $self);
6957 }
6958 
6959 #** @method GetFeatureCount()
6960 #*
6961 sub GetFeatureCount {
6962 }
6963 
6964 #** @method scalar GetFeaturesRead()
6965 # Object method.
6966 # @return integer
6967 #*
6968 sub GetFeaturesRead {
6969 }
6970 
6971 #** @method scalar GetFieldDefn($name)
6972 # Object method.
6973 # Get the definition of a field.
6974 # @param name the name of the field.
6975 # @return a Geo::OGR::FieldDefn object.
6976 #*
6977 sub GetFieldDefn {
6978  my $self = shift;
6979  my $d = $self->GetDefn;
6980  my $field = $d->GetFieldIndex(shift // 0);
6981  return $d->_GetFieldDefn($field);
6982 }
6983 
6984 #** @method list GetFieldNames()
6985 # Object method.
6986 # @return a list of the names of the fields in this layer. The
6987 # non-geometry field names are first in the list and then the geometry
6988 # fields.
6989 #*
6990 sub GetFieldNames {
6991  my $self = shift;
6992  my $d = $self->GetDefn;
6993  my @ret;
6994  for (my $i = 0; $i < $d->GetFieldCount; $i++) {
6995  push @ret, $d->GetFieldDefn($i)->Name();
6996  }
6997  for (my $i = 0; $i < $d->GetGeomFieldCount; $i++) {
6998  push @ret, $d->GetGeomFieldDefn($i)->Name();
6999  }
7000  return @ret;
7001 }
7002 
7003 #** @method scalar GetGeomFieldDefn($name)
7004 # Object method.
7005 # Get the definition of a spatial field.
7006 # @param name the name of the spatial field.
7007 # @return a Geo::OGR::GeomFieldDefn object.
7008 #*
7009 sub GetGeomFieldDefn {
7010  my $self = shift;
7011  my $d = $self->GetDefn;
7012  my $field = $d->GetGeomFieldIndex(shift // 0);
7013  return $d->_GetGeomFieldDefn($field);
7014 }
7015 
7016 #** @method scalar GetName()
7017 # Object method.
7018 # @return the name of the layer.
7019 #*
7020 sub GetName {
7021 }
7022 
7023 #** @method Geo::OGR::Feature GetNextFeature()
7024 # Object method.
7025 # @return iteratively Geo::OGR::Feature objects from the layer. The
7026 # iteration obeys the spatial and the attribute filter.
7027 #*
7028 sub GetNextFeature {
7029 }
7030 
7031 #** @method hash reference GetSchema()
7032 # Object method.
7033 # @brief Get the schema of this layer.
7034 # @note The schema of a layer cannot be set with this method. If you
7035 # have a Geo::OGR::FeatureDefn object before creating the layer, use
7036 # its schema in the Geo::OGR::CreateLayer method.
7037 # @return the schema of this layer, as in Geo::OGR::FeatureDefn::Schema.
7038 #*
7039 sub GetSchema {
7040  my $self = shift;
7041  carp "Schema of a layer should not be set directly." if @_;
7042  if (@_ and @_ % 2 == 0) {
7043  my %schema = @_;
7044  if ($schema{Fields}) {
7045  for my $field (@{$schema{Fields}}) {
7046  $self->CreateField($field);
7047  }
7048  }
7049  }
7050  return $self->GetDefn->Schema;
7051 }
7052 
7053 #** @method Geo::OGR::Geometry GetSpatialFilter()
7054 # Object method.
7055 # @return a new Geo::OGR::Geometry object
7056 #*
7057 sub GetSpatialFilter {
7058 }
7059 
7060 #** @method GetStyleTable()
7061 #*
7062 sub GetStyleTable {
7063 }
7064 
7065 #** @method Identity(Geo::OGR::Layer method, Geo::OGR::Layer result, hashref options, coderef callback, $callback_data)
7066 # Object method.
7067 # The result layer contains features whose geometries represent areas
7068 # that are in the input layer. The features in the result layer have
7069 # attributes from both input and method layers. The schema of the
7070 # result layer can be set by the user or, if it is empty, is
7071 # initialized to contain all fields in input and method layers.
7072 # @param method method layer.
7073 # @param result result layer.
7074 # @param options a reference to an options hash.
7075 # @param callback [optional] a reference to a subroutine, which will
7076 # be called with parameters (number progress, string msg, callback_data)
7077 # @param callback_data [optional]
7078 #*
7079 sub Identity {
7080 }
7081 
7082 #** @method InsertFeature($feature)
7083 # Object method.
7084 # Creates a new feature which has the schema of the layer and
7085 # initializes it with data from the argument. Then inserts the feature
7086 # into the layer (using CreateFeature). Uses Geo::OGR::Feature::Row or
7087 # Geo::OGR::Feature::Tuple.
7088 # @param feature a Geo::OGR::Feature object or reference to feature
7089 # data in a hash (as in Geo::OGR::Feature::Row) or in an array (as in
7090 # Geo::OGR::Feature::Tuple)
7091 # @return the new feature.
7092 #*
7093 sub InsertFeature {
7094  my $self = shift;
7095  my $feature = shift;
7096  error("Usage: \$feature->InsertFeature(reference to a hash or array).") unless ref($feature);
7097  my $new = Geo::OGR::Feature->new(Schema => $self, Values => $feature);
7098  $self->CreateFeature($new);
7099  return unless defined wantarray;
7100  keep($new, $self);
7101 }
7102 
7103 #** @method Intersection(Geo::OGR::Layer method, Geo::OGR::Layer result, hashref options, coderef callback, $callback_data)
7104 # Object method.
7105 # The result layer contains features whose geometries represent areas
7106 # that are common between features in the input layer and in the
7107 # method layer. The schema of the result layer can be set before
7108 # calling this method, or is initialized to contain all fields from
7109 # this and method layer.
7110 # @param method method layer.
7111 # @param result result layer.
7112 # @param options a reference to an options hash.
7113 # @param callback [optional] a reference to a subroutine, which will
7114 # be called with parameters (number progress, string msg, callback_data)
7115 # @param callback_data [optional]
7116 #*
7117 sub Intersection {
7118 }
7119 
7120 #** @method ReorderField()
7121 #*
7122 sub ReorderField {
7123 }
7124 
7125 #** @method ReorderFields()
7126 #*
7127 sub ReorderFields {
7128 }
7129 
7130 #** @method ResetReading()
7131 # Object method.
7132 # Initialize the layer object for iterative reading.
7133 #*
7134 sub ResetReading {
7135 }
7136 
7137 #** @method RollbackTransaction()
7138 # Object method.
7139 #*
7140 sub RollbackTransaction {
7141 }
7142 
7143 #** @method hash reference Row(%row)
7144 # Object method.
7145 # Get and/or set the data of a feature that has the supplied feature
7146 # id (the next feature obtained with GetNextFeature is used if feature
7147 # id is not given). Calls Geo::OGR::Feature::Row.
7148 # @param row [optional] feature data
7149 # @return a reference to feature data in a hash
7150 #*
7151 sub Row {
7152  my $self = shift;
7153  my $update = @_ > 0;
7154  my %row = @_;
7155  my $feature = defined $row{FID} ? $self->GetFeature($row{FID}) : $self->GetNextFeature;
7156  return unless $feature;
7157  my $ret;
7158  if (defined wantarray) {
7159  $ret = $feature->Row(@_);
7160  } else {
7161  $feature->Row(@_);
7162  }
7163  $self->SetFeature($feature) if $update;
7164  return unless defined wantarray;
7165  return $ret;
7166 }
7167 
7168 #** @method SetAttributeFilter($filter_string)
7169 # Object method.
7170 # Set or clear the attribute filter.
7171 # @param filter_string a SQL WHERE clause or undef to clear the
7172 # filter.
7173 #*
7174 sub SetAttributeFilter {
7175 }
7176 
7177 #** @method SetFeature($feature)
7178 # Object method.
7179 # @note The feature should have the same schema as the layer.
7180 #
7181 # Replaces a feature in the layer based on the given feature's
7182 # id. Requires RandomWrite capability.
7183 # @param feature a Geo::OGR::Feature object
7184 #*
7185 sub SetFeature {
7186 }
7187 
7188 #** @method SetIgnoredFields(@fields)
7189 # Object method.
7190 # @param fields a list of field names
7191 #*
7192 sub SetIgnoredFields {
7193 }
7194 
7195 #** @method SetNextByIndex($new_index)
7196 # Object method.
7197 # @param new_index the index to which set the read cursor in the
7198 # current iteration
7199 #*
7200 sub SetNextByIndex {
7201 }
7202 
7203 #** @method SetSpatialFilter($filter)
7204 # Object method.
7205 # @param filter [optional] a Geo::OGR::Geometry object. If not given,
7206 # removes the filter if there is one.
7207 #*
7208 sub SetSpatialFilter {
7209 }
7210 
7211 #** @method SetSpatialFilterRect($minx, $miny, $maxx, $maxy)
7212 # Object method.
7213 # @param minx
7214 # @param miny
7215 # @param maxx
7216 # @param maxy
7217 #*
7218 sub SetSpatialFilterRect {
7219 }
7220 
7221 #** @method SetStyleTable()
7222 #*
7223 sub SetStyleTable {
7224 }
7225 
7226 #** @method Geo::OGR::Geometry SpatialFilter(@filter)
7227 # Object method.
7228 # @param filter [optional] a Geo::OGR::Geometry object or a string. An
7229 # undefined value removes the filter if there is one.
7230 # @return a new Geo::OGR::Geometry object
7231 # @param filter [optional] a rectangle ($minx, $miny, $maxx, $maxy).
7232 # @return a new Geo::OGR::Geometry object
7233 #*
7234 sub SpatialFilter {
7235  my $self = shift;
7236  $self->SetSpatialFilter($_[0]) if @_ == 1;
7237  $self->SetSpatialFilterRect(@_) if @_ == 4;
7238  return unless defined wantarray;
7239  $self->GetSpatialFilter;
7240 }
7241 
7242 #** @method Geo::OSR::SpatialReference SpatialReference($name, Geo::OSR::SpatialReference sr)
7243 # Object method.
7244 # @note A.k.a GetSpatialRef.
7245 # Get or set the projection of a spatial field of this layer. Gets or
7246 # sets the projection of the first field if no field name is given.
7247 # @param name [optional] a name of a spatial field in this layer.
7248 # @param sr [optional] a Geo::OSR::SpatialReference object,
7249 # which replaces the existing projection.
7250 # @return a Geo::OSR::SpatialReference object, which represents the
7251 # projection in the given spatial field.
7252 #*
7253 sub SpatialReference {
7254  my $self = shift;
7255  my $d = $self->GetDefn;
7256  my $field = @_ == 2 ? $d->GetGeomFieldIndex(shift // 0) : 0;
7257  my $sr = shift;
7258  my $d2 = $d->_GetGeomFieldDefn($field);
7259  $d2->SpatialReference($sr) if defined $sr;
7260  return $d2->SpatialReference() if defined wantarray;
7261 }
7262 
7263 #** @method StartTransaction()
7264 # Object method.
7265 #*
7266 sub StartTransaction {
7267 }
7268 
7269 #** @method SymDifference(Geo::OGR::Layer method, Geo::OGR::Layer result, hashref options, coderef callback, $callback_data)
7270 # Object method.
7271 # The result layer contains features whose geometries represent areas
7272 # that are in either in the input layer or in the method layer but not
7273 # in both. The features in the result layer have attributes from both
7274 # input and method layers. For features which represent areas that are
7275 # only in the input or in the method layer the respective attributes
7276 # have undefined values. The schema of the result layer can be set by
7277 # the user or, if it is empty, is initialized to contain all fields in
7278 # the input and method layers.
7279 # @param method method layer.
7280 # @param result result layer.
7281 # @param options a reference to an options hash.
7282 # @param callback [optional] a reference to a subroutine, which will
7283 # be called with parameters (number progress, string msg, callback_data)
7284 # @param callback_data [optional]
7285 #*
7286 sub SymDifference {
7287 }
7288 
7289 #** @method SyncToDisk()
7290 # Object method.
7291 #*
7292 sub SyncToDisk {
7293 }
7294 
7295 #** @method scalar TestCapability($cap)
7296 # Object method.
7297 # @param cap A capability string.
7298 # @return a boolean value indicating whether the layer has the
7299 # specified capability.
7300 #*
7301 sub TestCapability {
7302  my($self, $cap) = @_;
7303  return _TestCapability($self, $CAPABILITIES{$cap});
7304 }
7305 
7306 #** @method list Tuple(@tuple)
7307 # Object method.
7308 # Get and/set the data of a feature that has the supplied feature id
7309 # (the next feature obtained with GetNextFeature is used if feature id
7310 # is not given). The expected data in the tuple is: ([feature id,]
7311 # non-spatial fields, spatial fields). Calls Geo::OGR::Feature::Tuple.
7312 # @param tuple [optional] feature data
7313 # @note The schema of the tuple needs to be the same as that of the
7314 # layer.
7315 # @return a reference to feature data in an array
7316 #*
7317 sub Tuple {
7318  my $self = shift;
7319  my $FID = shift;
7320  my $feature = defined $FID ? $self->GetFeature($FID) : $self->GetNextFeature;
7321  return unless $feature;
7322  my $set = @_ > 0;
7323  unshift @_, $feature->GetFID if $set;
7324  my @ret;
7325  if (defined wantarray) {
7326  @ret = $feature->Tuple(@_);
7327  } else {
7328  $feature->Tuple(@_);
7329  }
7330  $self->SetFeature($feature) if $set;
7331  return unless defined wantarray;
7332  return @ret;
7333 }
7334 
7335 #** @method Union(Geo::OGR::Layer method, Geo::OGR::Layer result, hashref options, coderef callback, $callback_data)
7336 # Object method.
7337 # The result layer contains features whose geometries represent areas
7338 # that are in either in the input layer or in the method layer. The
7339 # schema of the result layer can be set before calling this method, or
7340 # is initialized to contain all fields from this and method layer.
7341 # @param method method layer.
7342 # @param result result layer.
7343 # @param options a reference to an options hash.
7344 # @param callback [optional] a reference to a subroutine, which will
7345 # be called with parameters (number progress, string msg, callback_data)
7346 # @param callback_data [optional]
7347 #*
7348 sub Union {
7349 }
7350 
7351 #** @method Update(Geo::OGR::Layer method, Geo::OGR::Layer result, hashref options, coderef callback, $callback_data)
7352 # Object method.
7353 # The result layer contains features whose geometries represent areas
7354 # that are either in the input layer or in the method layer. The
7355 # features in the result layer have areas of the features of the
7356 # method layer or those ares of the features of the input layer that
7357 # are not covered by the method layer. The features of the result
7358 # layer get their attributes from the input layer. The schema of the
7359 # result layer can be set by the user or, if it is empty, is
7360 # initialized to contain all fields in the input layer.
7361 # @param method method layer.
7362 # @param result result layer.
7363 # @param options a reference to an options hash.
7364 # @param callback [optional] a reference to a subroutine, which will
7365 # be called with parameters (number progress, string msg, callback_data)
7366 # @param callback_data [optional]
7367 #*
7368 sub Update {
7369 }
7370 
7371 #** @class Geo::OGR::StyleTable
7372 #*
7373 package Geo::OGR::StyleTable;
7374 
7375 use base qw(Geo::OGR)
7376 
7377 #** @method AddStyle()
7378 #*
7379 sub AddStyle {
7380 }
7381 
7382 #** @method Find()
7383 #*
7384 sub Find {
7385 }
7386 
7387 #** @method GetLastStyleName()
7388 #*
7389 sub GetLastStyleName {
7390 }
7391 
7392 #** @method GetNextStyle()
7393 #*
7394 sub GetNextStyle {
7395 }
7396 
7397 #** @method LoadStyleTable()
7398 #*
7399 sub LoadStyleTable {
7400 }
7401 
7402 #** @method ResetStyleStringReading()
7403 #*
7404 sub ResetStyleStringReading {
7405 }
7406 
7407 #** @method SaveStyleTable()
7408 #*
7409 sub SaveStyleTable {
7410 }
7411 
7412 #** @method new()
7413 #*
7414 sub new {
7415  my $pkg = shift;
7416  my $self = Geo::OGRc::new_StyleTable(@_);
7417  bless $self, $pkg if defined($self);
7418 }
7419 
7420 #** @class Geo::OSR
7421 # @brief Base class for projection related classes.
7422 # @details
7423 #*
7424 package Geo::OSR;
7425 
7426 #** @method list AngularUnits()
7427 # Package subroutine.
7428 # @return list of known angular units.
7429 #*
7430 sub AngularUnits {
7431  return keys %ANGULAR_UNITS;
7432 }
7433 
7434 #** @method CreateCoordinateTransformation()
7435 #*
7436 sub CreateCoordinateTransformation {
7437 }
7438 
7439 #** @method list Datums()
7440 # Package subroutine.
7441 # @return list of known datums.
7442 #*
7443 sub Datums {
7444  return keys %DATUMS;
7445 }
7446 
7447 #** @method list GetProjectionMethodParamInfo($projection, $parameter)
7448 # Package subroutine.
7449 # @param projection one of Geo::OSR::Projections
7450 # @param parameter one of Geo::OSR::Parameters
7451 # @return a list ($user_friendly_name, $type, $default_value).
7452 #*
7453 sub GetProjectionMethodParamInfo {
7454 }
7455 
7456 #** @method list GetProjectionMethodParameterList($projection)
7457 # Package subroutine.
7458 # @param projection one of Geo::OSR::Projections
7459 # @return a list (arrayref parameters, $projection_name).
7460 #*
7461 sub GetProjectionMethodParameterList {
7462 }
7463 
7464 #** @method array reference GetProjectionMethods()
7465 # Package subroutine.
7466 # @deprecated Use Geo::OSR::Projections.
7467 #
7468 # @return reference to an array of possible projection methods.
7469 #*
7470 sub GetProjectionMethods {
7471 }
7472 
7473 #** @method scalar GetUserInputAsWKT($name)
7474 # Package subroutine.
7475 # @param name the user input
7476 # @return a WKT string.
7477 #*
7478 sub GetUserInputAsWKT {
7479 }
7480 
7481 #** @method scalar GetWellKnownGeogCSAsWKT($name)
7482 # Package subroutine.
7483 # @brief Get well known geographic coordinate system as WKT
7484 # @param name a well known name
7485 # @return a WKT string.
7486 #*
7487 sub GetWellKnownGeogCSAsWKT {
7488 }
7489 
7490 #** @method list LinearUnits()
7491 # Package subroutine.
7492 # @return list of known linear units.
7493 #*
7494 sub LinearUnits {
7495  return keys %LINEAR_UNITS;
7496 }
7497 
7498 #** @method OAO_Down()
7499 #*
7500 sub OAO_Down {
7501 }
7502 
7503 #** @method OAO_East()
7504 #*
7505 sub OAO_East {
7506 }
7507 
7508 #** @method OAO_North()
7509 #*
7510 sub OAO_North {
7511 }
7512 
7513 #** @method OAO_Other()
7514 #*
7515 sub OAO_Other {
7516 }
7517 
7518 #** @method OAO_South()
7519 #*
7520 sub OAO_South {
7521 }
7522 
7523 #** @method OAO_Up()
7524 #*
7525 sub OAO_Up {
7526 }
7527 
7528 #** @method OAO_West()
7529 #*
7530 sub OAO_West {
7531 }
7532 
7533 #** @method list Parameters()
7534 # Package subroutine.
7535 # @return list of known projection parameters.
7536 #*
7537 sub Parameters {
7538  return keys %PARAMETERS;
7539 }
7540 
7541 #** @method list Projections()
7542 # Package subroutine.
7543 # @return list of known projections.
7544 #*
7545 sub Projections {
7546  return keys %PROJECTIONS;
7547 }
7548 
7549 #** @method SRS_PM_GREENWICH()
7550 #*
7551 sub SRS_PM_GREENWICH {
7552 }
7553 
7554 #** @method SRS_WGS84_INVFLATTENING()
7555 #*
7556 sub SRS_WGS84_INVFLATTENING {
7557 }
7558 
7559 #** @method SRS_WGS84_SEMIMAJOR()
7560 #*
7561 sub SRS_WGS84_SEMIMAJOR {
7562 }
7563 
7564 #** @method SRS_WKT_WGS84()
7565 #*
7566 sub SRS_WKT_WGS84 {
7567 }
7568 
7569 #** @class Geo::OSR::CoordinateTransformation
7570 # @brief An object for transforming from one projection to another.
7571 # @details
7572 #*
7573 package Geo::OSR::CoordinateTransformation;
7574 
7575 use base qw(Geo::OSR)
7576 
7577 #** @method array reference TransformPoint($x, $y, $z)
7578 # Object method.
7579 # @param x
7580 # @param y
7581 # @param z [optional]
7582 # @return arrayref = [$x, $y, $z]
7583 #*
7584 sub TransformPoint {
7585 }
7586 
7587 #** @method TransformPoints(arrayref points)
7588 # Object method.
7589 # @param points [in/out] a reference to a list of points (line string
7590 # or ring) that is modified in-place. A list of points is: ([x, y, z],
7591 # [x, y, z], ...), where z is optional. Supports also lists of line
7592 # strings and polygons.
7593 #*
7594 sub TransformPoints {
7595  my($self, $points) = @_;
7596  _TransformPoints($self, $points), return unless ref($points->[0]->[0]);
7597  for my $p (@$points) {
7598  TransformPoints($self, $p);
7599  }
7600 }
7601 1;
7602 # This file was automatically generated by SWIG (http://www.swig.org).
7603 # Version 2.0.12
7604 #
7605 # Do not make changes to this file unless you know what you are doing--modify
7606 # the SWIG interface file instead.
7607 }
7608 
7609 #** @method Geo::OSR::CoordinateTransformation new($src, $dst)
7610 # Class method.
7611 # @param src a Geo::OSR::SpatialReference object
7612 # @param dst a Geo::OSR::SpatialReference object
7613 # @return a new Geo::OSR::CoordinateTransformation object
7614 #*
7615 sub new {
7616  my $pkg = shift;
7617  my $self = Geo::OSRc::new_CoordinateTransformation(@_);
7618  bless $self, $pkg if defined($self);
7619 }
7620 
7621 #** @class Geo::OSR::SpatialReference
7622 # @brief A spatial reference system.
7623 # @details <a href="http://www.gdal.org/classOGRSpatialReference.html">Documentation
7624 # of the underlying C++ class at www.gdal.org</a>
7625 #*
7626 package Geo::OSR::SpatialReference;
7627 
7628 use base qw(Geo::OSR)
7629 
7630 #** @method As()
7631 #*
7632 sub As {
7633 }
7634 
7635 #** @method AutoIdentifyEPSG()
7636 # Object method.
7637 # Set EPSG authority info if possible.
7638 #*
7639 sub AutoIdentifyEPSG {
7640 }
7641 
7642 #** @method Geo::OSR::SpatialReference Clone()
7643 # Object method.
7644 # Make a duplicate of this SpatialReference object.
7645 # @return a new Geo::OSR::SpatialReference object
7646 #*
7647 sub Clone {
7648 }
7649 
7650 #** @method Geo::OSR::SpatialReference CloneGeogCS()
7651 # Object method.
7652 # Make a duplicate of the GEOGCS node of this SpatialReference object.
7653 # @return a new Geo::OSR::SpatialReference object
7654 #*
7655 sub CloneGeogCS {
7656 }
7657 
7658 #** @method ConvertToOtherProjection()
7659 #*
7660 sub ConvertToOtherProjection {
7661 }
7662 
7663 #** @method CopyGeogCSFrom($rhs)
7664 # Object method.
7665 # @param rhs Geo::OSR::SpatialReference
7666 #*
7667 sub CopyGeogCSFrom {
7668 }
7669 
7670 #** @method EPSGTreatsAsLatLong()
7671 # Object method.
7672 # Returns TRUE if EPSG feels this geographic coordinate system should be treated as having lat/long coordinate ordering.
7673 #*
7674 sub EPSGTreatsAsLatLong {
7675 }
7676 
7677 #** @method EPSGTreatsAsNorthingEasting()
7678 #*
7679 sub EPSGTreatsAsNorthingEasting {
7680 }
7681 
7682 #** @method Export($format)
7683 # Object method.
7684 # Export the spatial reference to a selected format.
7685 # @note a.k.a. As
7686 #
7687 # @param format One of the following. The return value is explained
7688 # after the format. Other arguments are explained in parenthesis.
7689 # - WKT (Text): Well Known Text string
7690 # - PrettyWKT: Well Known Text string nicely formatted (simplify)
7691 # - Proj4: PROJ.4 string
7692 # - PCI: a list: ($proj_string, $units, [$parms1, ...])
7693 # - USGS: a list: ($code, $zone, [$parms1, ...], $datum)
7694 # - GML (XML): GML based string (dialect)
7695 # - MapInfoCS (MICoordSys): MapInfo style co-ordinate system definition
7696 #
7697 # @note The named parameter syntax also works and is needed is those
7698 # cases when other arguments need or may be given. The format should
7699 # be given using key as, 'to' or 'format'.
7700 #
7701 # @note ExportTo* and AsText methods also exist but are not documented here.
7702 #
7703 # @return a scalar or a list depending on the export format
7704 #*
7705 sub Export {
7706  my $self = shift;
7707  my $format;
7708  $format = pop if @_ == 1;
7709  my %params = @_;
7710  $format //= $params{to} //= $params{format} //= $params{as} //= '';
7711  my $simplify = $params{simplify} // 0;
7712  my $dialect = $params{dialect} // '';
7713  my %converters = (
7714  WKT => sub { return ExportToWkt($self) },
7715  Text => sub { return ExportToWkt($self) },
7716  PrettyWKT => sub { return ExportToPrettyWkt($self, $simplify) },
7717  Proj4 => sub { return ExportToProj4($self) },
7718  PCI => sub { return ExportToPCI($self) },
7719  USGS => sub { return ExportToUSGS($self) },
7720  GML => sub { return ExportToXML($self, $dialect) },
7721  XML => sub { return ExportToXML($self, $dialect) },
7722  MICoordSys => sub { return ExportToMICoordSys() },
7723  MapInfoCS => sub { return ExportToMICoordSys() },
7724  );
7725  error(1, $format, \%converters) unless $converters{$format};
7726  return $converters{$format}->();
7727 }
7728 
7729 #** @method Fixup()
7730 # Object method.
7731 #*
7732 sub Fixup {
7733 }
7734 
7735 #** @method FixupOrdering()
7736 # Object method.
7737 #*
7738 sub FixupOrdering {
7739 }
7740 
7741 #** @method scalar GetAngularUnits()
7742 # Object method.
7743 # @return a number
7744 #*
7745 sub GetAngularUnits {
7747 
7748 #** @method GetAngularUnitsName()
7749 #*
7750 sub GetAngularUnitsName {
7751 }
7752 
7753 #** @method scalar GetAttrValue($name, $child = 0)
7754 # Object method.
7755 # @param name
7756 # @param child
7757 # @return string
7758 #*
7759 sub GetAttrValue {
7760 }
7761 
7762 #** @method scalar GetAuthorityCode($target_key)
7763 # Object method.
7764 # @param target_key
7765 # @return string
7766 #*
7767 sub GetAuthorityCode {
7768 }
7769 
7770 #** @method scalar GetAuthorityName($target_key)
7771 # Object method.
7772 # @param target_key
7773 # @return string
7774 #*
7775 sub GetAuthorityName {
7776 }
7777 
7778 #** @method GetAxisName()
7779 #*
7780 sub GetAxisName {
7781 }
7782 
7783 #** @method GetAxisOrientation()
7784 #*
7785 sub GetAxisOrientation {
7786 }
7787 
7788 #** @method GetInvFlattening()
7789 # Object method.
7790 #*
7791 sub GetInvFlattening {
7792 }
7793 
7794 #** @method scalar GetLinearUnits()
7795 # Object method.
7796 # @return a number
7797 #*
7798 sub GetLinearUnits {
7799 }
7800 
7801 #** @method scalar GetLinearUnitsName()
7802 # Object method.
7803 # @return string
7804 #*
7805 sub GetLinearUnitsName {
7806 }
7807 
7808 #** @method scalar GetNormProjParm($name, $default_val = 0.0)
7809 # Object method.
7810 # @param name
7811 # @param default_val
7812 # @return a number
7813 #*
7814 sub GetNormProjParm {
7815 }
7816 
7817 #** @method scalar GetProjParm($name, $default_val = 0.0)
7818 # Object method.
7819 # @param name
7820 # @param default_val
7821 # @return a number
7822 #*
7823 sub GetProjParm {
7824 }
7825 
7826 #** @method GetSemiMajor()
7827 # Object method.
7828 #*
7829 sub GetSemiMajor {
7830 }
7831 
7832 #** @method GetSemiMinor()
7833 # Object method.
7834 #*
7835 sub GetSemiMinor {
7836 }
7837 
7838 #** @method GetTOWGS84()
7839 # Object method.
7840 # @return array = ($p1, $p2, $p3, $p4, $p5, $p6, $p7)
7841 #*
7842 sub GetTOWGS84 {
7843 }
7844 
7845 #** @method GetTargetLinearUnits()
7846 #*
7847 sub GetTargetLinearUnits {
7848 }
7849 
7850 #** @method GetUTMZone()
7851 # Object method.
7852 # Get UTM zone information.
7853 # @return The UTM zone (integer). In scalar context the returned value
7854 # is negative for southern hemisphere zones. In list context returns
7855 # two values ($zone, $north), where $zone is always non-negative and
7856 # $north is true or false.
7857 #*
7858 sub GetUTMZone {
7859  my $self = shift;
7860  my $zone = _GetUTMZone($self);
7861  if (wantarray) {
7862  my $north = 1;
7863  if ($zone < 0) {
7864  $zone *= -1;
7865  $north = 0;
7866  }
7867  return ($zone, $north);
7868  } else {
7869  return $zone;
7870  }
7871 }
7872 
7873 #** @method ImportFromOzi()
7874 #*
7875 sub ImportFromOzi {
7876 }
7877 
7878 #** @method scalar IsCompound()
7879 # Object method.
7880 # @return boolean
7881 #*
7882 sub IsCompound {
7883 }
7884 
7885 #** @method scalar IsGeocentric()
7886 # Object method.
7887 # @return boolean
7888 #*
7889 sub IsGeocentric {
7890 }
7891 
7892 #** @method scalar IsGeographic()
7893 # Object method.
7894 # @return boolean
7895 #*
7896 sub IsGeographic {
7897 }
7898 
7899 #** @method scalar IsLocal()
7900 # Object method.
7901 # @return boolean
7902 #*
7903 sub IsLocal {
7904 }
7905 
7906 #** @method scalar IsProjected()
7907 # Object method.
7908 # @return boolean
7909 #*
7910 sub IsProjected {
7911 }
7912 
7913 #** @method scalar IsSame($rs)
7914 # Object method.
7915 # @param rs a Geo::OSR::SpatialReference object
7916 # @return boolean
7917 #*
7918 sub IsSame {
7919 }
7920 
7921 #** @method scalar IsSameGeogCS($rs)
7922 # Object method.
7923 # @param rs a Geo::OSR::SpatialReference object
7924 # @return boolean
7925 #*
7926 sub IsSameGeogCS {
7927 }
7928 
7929 #** @method scalar IsSameVertCS($rs)
7930 # Object method.
7931 # @param rs a Geo::OSR::SpatialReference object
7932 # @return boolean
7933 #*
7934 sub IsSameVertCS {
7935 }
7936 
7937 #** @method scalar IsVertical()
7938 # Object method.
7939 # @return boolean
7940 #*
7941 sub IsVertical {
7942 }
7943 
7944 #** @method MorphFromESRI()
7945 # Object method.
7946 #*
7947 sub MorphFromESRI {
7948 }
7949 
7950 #** @method MorphToESRI()
7951 # Object method.
7952 #*
7953 sub MorphToESRI {
7954 }
7955 
7956 #** @method Set(%params)
7957 # Object method.
7958 # Set a parameter or parameters in the spatial reference object.
7959 # @param params Named parameters. Recognized keys and respective
7960 # values are the following.
7961 # - Authority: authority name (give also TargetKey, Node and Code)
7962 # - TargetKey:
7963 # - Node: partial or complete path to the target node (Node and Value together sets an attribute value)
7964 # - Code: code for value with an authority
7965 # - Value: value to be assigned to a node, a projection parameter or an object
7966 # - AngularUnits: angular units for the geographic coordinate system (give also Value) (one of Geo::OSR::LinearUnits)
7967 # - LinearUnits: linear units for the target node or the object (give also Value and optionally Node) (one of Geo::OSR::LinearUnits)
7968 # - Parameter: projection parameter to set (give also Value and Normalized) (one of Geo::OSR::Parameters)
7969 # - Normalized: set to true to indicate that the Value argument is in "normalized" form
7970 # - Name: a well known name of a geographic coordinate system (e.g. WGS84)
7971 # - GuessFrom: arbitrary text that specifies a projection ("user input")
7972 # - LOCAL_CS: name of a local coordinate system
7973 # - GeocentricCS: name of a geocentric coordinate system
7974 # - VerticalCS: name of a vertical coordinate system (give also Datum and optionally VertDatumType [default is 2005])
7975 # - Datum: a known (OGC or EPSG) name (or(?) one of Geo::OSR::Datums)
7976 # - CoordinateSystem: 'WGS', 'UTM', 'State Plane', or a user visible name (give optionally also Parameters, Zone, North, NAD83, UnitName, UnitConversionFactor, Datum, Spheroid, HorizontalCS, and/or VerticalCS
7977 # - Parameters: a reference to a list containing the coordinate system or projection parameters
7978 # - Zone: zone for setting up UTM or State Plane coordinate systems (State Plane zone in USGS numbering scheme)
7979 # - North: set false for southern hemisphere
7980 # - NAD83: set false if the NAD27 zone definition should be used instead of NAD83
7981 # - UnitName: to override the legal definition for a zone
7982 # - UnitConversionFactor: to override the legal definition for a zone
7983 # - Spheroid: user visible name
7984 # - HorizontalCS: Horizontal coordinate system name
7985 # - Projection: name of a projection, one of Geo::OSR::Projections (give also optionally Parameters and Variant)
7986 #
7987 # @note Numerous Set* methods also exist but are not documented here.
7988 #*
7989 sub Set {
7990  my($self, %params) = @_;
7991  if (exists $params{Authority} and exists $params{TargetKey} and exists $params{Node} and exists $params{Code}) {
7992  SetAuthority($self, $params{TargetKey}, $params{Authority}, $params{Code});
7993  } elsif (exists $params{Node} and exists $params{Value}) {
7994  SetAttrValue($self, $params{Node}, $params{Value});
7995  } elsif (exists $params{AngularUnits} and exists $params{Value}) {
7996  SetAngularUnits($self, $params{AngularUnits}, $params{Value});
7997  } elsif (exists $params{LinearUnits} and exists $params{Node} and exists $params{Value}) {
7998  SetTargetLinearUnits($self, $params{Node}, $params{LinearUnits}, $params{Value});
7999  } elsif (exists $params{LinearUnits} and exists $params{Value}) {
8000  SetLinearUnitsAndUpdateParameters($self, $params{LinearUnits}, $params{Value});
8001  } elsif ($params{Parameter} and exists $params{Value}) {
8002  error(1, $params{Parameter}, \%Geo::OSR::PARAMETERS) unless exists $Geo::OSR::PARAMETERS{$params{Parameter}};
8003  $params{Normalized} ?
8004  SetNormProjParm($self, $params{Parameter}, $params{Value}) :
8005  SetProjParm($self, $params{Parameter}, $params{Value});
8006  } elsif (exists $params{Name}) {
8007  SetWellKnownGeogCS($self, $params{Name});
8008  } elsif (exists $params{GuessFrom}) {
8009  SetFromUserInput($self, $params{GuessFrom});
8010  } elsif (exists $params{LOCAL_CS}) {
8011  SetLocalCS($self, $params{LOCAL_CS});
8012  } elsif (exists $params{GeocentricCS}) {
8013  SetGeocCS($self, $params{GeocentricCS});
8014  } elsif (exists $params{VerticalCS} and $params{Datum}) {
8015  my $type = $params{VertDatumType} || 2005;
8016  SetVertCS($self, $params{VerticalCS}, $params{Datum}, $type);
8017  } elsif (exists $params{CoordinateSystem}) {
8018  my @parameters = ();
8019  @parameters = @{$params{Parameters}} if ref($params{Parameters});
8020  if ($params{CoordinateSystem} eq 'State Plane' and exists $params{Zone}) {
8021  my $NAD83 = exists $params{NAD83} ? $params{NAD83} : 1;
8022  my $name = exists $params{UnitName} ? $params{UnitName} : undef;
8023  my $c = exists $params{UnitConversionFactor} ? $params{UnitConversionFactor} : 0.0;
8024  SetStatePlane($self, $params{Zone}, $NAD83, $name, $c);
8025  } elsif ($params{CoordinateSystem} eq 'UTM' and exists $params{Zone} and exists $params{North}) {
8026  my $north = exists $params{North} ? $params{North} : 1;
8027  SetUTM($self, $params{Zone}, $north);
8028  } elsif ($params{CoordinateSystem} eq 'WGS') {
8029  SetTOWGS84($self, @parameters);
8030  } elsif ($params{CoordinateSystem} and $params{Datum} and $params{Spheroid}) {
8031  SetGeogCS($self, $params{CoordinateSystem}, $params{Datum}, $params{Spheroid}, @parameters);
8032  } elsif ($params{CoordinateSystem} and $params{HorizontalCS} and $params{VerticalCS}) {
8033  SetCompoundCS($self, $params{CoordinateSystem}, $params{HorizontalCS}, $params{VerticalCS});
8034  } else {
8035  SetProjCS($self, $params{CoordinateSystem});
8036  }
8037  } elsif (exists $params{Projection}) {
8038  error(1, $params{Projection}, \%Geo::OSR::PROJECTIONS) unless exists $Geo::OSR::PROJECTIONS{$params{Projection}};
8039  my @parameters = ();
8040  @parameters = @{$params{Parameters}} if ref($params{Parameters});
8041  if ($params{Projection} eq 'Albers_Conic_Equal_Area') {
8042  SetACEA($self, @parameters);
8043  } elsif ($params{Projection} eq 'Azimuthal_Equidistant') {
8044  SetAE($self, @parameters);
8045  } elsif ($params{Projection} eq 'Bonne') {
8046  SetBonne($self, @parameters);
8047  } elsif ($params{Projection} eq 'Cylindrical_Equal_Area') {
8048  SetCEA($self, @parameters);
8049  } elsif ($params{Projection} eq 'Cassini_Soldner') {
8050  SetCS($self, @parameters);
8051  } elsif ($params{Projection} eq 'Equidistant_Conic') {
8052  SetEC($self, @parameters);
8053  # Eckert_I, Eckert_II, Eckert_III, Eckert_V ?
8054  } elsif ($params{Projection} eq 'Eckert_IV') {
8055  SetEckertIV($self, @parameters);
8056  } elsif ($params{Projection} eq 'Eckert_VI') {
8057  SetEckertVI($self, @parameters);
8058  } elsif ($params{Projection} eq 'Equirectangular') {
8059  @parameters == 4 ?
8060  SetEquirectangular($self, @parameters) :
8061  SetEquirectangular2($self, @parameters);
8062  } elsif ($params{Projection} eq 'Gauss_Schreiber_Transverse_Mercator') {
8063  SetGaussSchreiberTMercator($self, @parameters);
8064  } elsif ($params{Projection} eq 'Gall_Stereographic') {
8065  SetGS($self, @parameters);
8066  } elsif ($params{Projection} eq 'Goode_Homolosine') {
8067  SetGH($self, @parameters);
8068  } elsif ($params{Projection} eq 'Interrupted_Goode_Homolosine') {
8069  SetIGH($self);
8070  } elsif ($params{Projection} eq 'Geostationary_Satellite') {
8071  SetGEOS($self, @parameters);
8072  } elsif ($params{Projection} eq 'Gnomonic') {
8073  SetGnomonic($self, @parameters);
8074  } elsif ($params{Projection} eq 'Hotine_Oblique_Mercator') {
8075  # Hotine_Oblique_Mercator_Azimuth_Center ?
8076  SetHOM($self, @parameters);
8077  } elsif ($params{Projection} eq 'Hotine_Oblique_Mercator_Two_Point_Natural_Origin') {
8078  SetHOM2PNO($self, @parameters);
8079  } elsif ($params{Projection} eq 'Krovak') {
8080  SetKrovak($self, @parameters);
8081  } elsif ($params{Projection} eq 'Lambert_Azimuthal_Equal_Area') {
8082  SetLAEA($self, @parameters);
8083  } elsif ($params{Projection} eq 'Lambert_Conformal_Conic_2SP') {
8084  SetLCC($self, @parameters);
8085  } elsif ($params{Projection} eq 'Lambert_Conformal_Conic_1SP') {
8086  SetLCC1SP($self, @parameters);
8087  } elsif ($params{Projection} eq 'Lambert_Conformal_Conic_2SP_Belgium') {
8088  SetLCCB($self, @parameters);
8089  } elsif ($params{Projection} eq 'miller_cylindrical') {
8090  SetMC($self, @parameters);
8091  } elsif ($params{Projection} =~ /^Mercator/) {
8092  # Mercator_1SP, Mercator_2SP, Mercator_Auxiliary_Sphere ?
8093  # variant is in Variant (or Name)
8094  SetMercator($self, @parameters);
8095  } elsif ($params{Projection} eq 'Mollweide') {
8096  SetMollweide($self, @parameters);
8097  } elsif ($params{Projection} eq 'New_Zealand_Map_Grid') {
8098  SetNZMG($self, @parameters);
8099  } elsif ($params{Projection} eq 'Oblique_Stereographic') {
8100  SetOS($self, @parameters);
8101  } elsif ($params{Projection} eq 'Orthographic') {
8102  SetOrthographic($self, @parameters);
8103  } elsif ($params{Projection} eq 'Polyconic') {
8104  SetPolyconic($self, @parameters);
8105  } elsif ($params{Projection} eq 'Polar_Stereographic') {
8106  SetPS($self, @parameters);
8107  } elsif ($params{Projection} eq 'Robinson') {
8108  SetRobinson($self, @parameters);
8109  } elsif ($params{Projection} eq 'Sinusoidal') {
8110  SetSinusoidal($self, @parameters);
8111  } elsif ($params{Projection} eq 'Stereographic') {
8112  SetStereographic($self, @parameters);
8113  } elsif ($params{Projection} eq 'Swiss_Oblique_Cylindrical') {
8114  SetSOC($self, @parameters);
8115  } elsif ($params{Projection} eq 'Transverse_Mercator_South_Orientated') {
8116  SetTMSO($self, @parameters);
8117  } elsif ($params{Projection} =~ /^Transverse_Mercator/) {
8118  my($variant) = $params{Projection} =~ /^Transverse_Mercator_(\w+)/;
8119  $variant //= $params{Variant} //= $params{Name};
8120  $variant ?
8121  SetTMVariant($self, $variant, @parameters) :
8122  SetTM($self, @parameters);
8123  } elsif ($params{Projection} eq 'Tunisia_Mining_Grid') {
8124  SetTMG($self, @parameters);
8125  } elsif ($params{Projection} eq 'VanDerGrinten') {
8126  SetVDG($self, @parameters);
8127  } else {
8128  # Aitoff, Craster_Parabolic, International_Map_of_the_World_Polyconic, Laborde_Oblique_Mercator
8129  # Loximuthal, Miller_Cylindrical, Quadrilateralized_Spherical_Cube, Quartic_Authalic, Two_Point_Equidistant
8130  # Wagner_I, Wagner_II, Wagner_III, Wagner_IV, Wagner_V, Wagner_VI, Wagner_VII
8131  # Winkel_I, Winkel_II, Winkel_Tripel
8132  # ?
8133  SetProjection($self, $params{Projection});
8134  }
8135  } else {
8136  error("Not enough information to create a spatial reference object.");
8137  }
8138 }
8139 
8140 #** @method SetMercator2SP()
8141 #*
8142 sub SetMercator2SP {
8143 }
8144 
8145 #** @method StripCTParms()
8146 # Object method.
8147 #*
8148 sub StripCTParms {
8149 }
8150 
8151 #** @method Validate()
8152 # Object method.
8153 #*
8154 sub Validate {
8155 }
8156 
8157 #** @method Geo::OSR::SpatialReference new(%params)
8158 # Class method.
8159 # Create a new spatial reference object using a named parameter. This
8160 # constructor recognizes the following key words (alternative in
8161 # parenthesis): WKT (Text), Proj4, ESRI, EPSG, EPSGA, PCI, USGS, GML
8162 # (XML), URL, ERMapper (ERM), MapInfoCS (MICoordSys). The value
8163 # depends on the key.
8164 # - WKT: Well Known Text string
8165 # - Proj4: PROJ.4 string
8166 # - ESRI: reference to a list of strings (contents of ESRI .prj file)
8167 # - EPSG: EPSG code number
8168 # - EPSGA: EPSG code number (the resulting CS will have EPSG preferred axis ordering)
8169 # - PCI: listref: [PCI_projection_string, Grid_units_code, [17 cs parameters]]
8170 # - USGS: listref: [Projection_system_code, Zone, [15 cs parameters], Datum_code, Format_flag]
8171 # - GML: GML string
8172 # - URL: URL for downloading the spatial reference from
8173 # - ERMapper: listref: [Projection, Datum, Units]
8174 # - MapInfoCS: MapInfo style co-ordinate system definition
8175 #
8176 # For more information, consult the import methods in <a href="http://www.gdal.org/classOGRSpatialReference.html">OGR documentation</a>.
8177 #
8178 # @note ImportFrom* methods also exist but are not documented here.
8179 #
8180 # Usage:
8181 # \code
8182 # $sr = Geo::OSR::SpatialReference->new( key => value );
8183 # \endcode
8184 # @return a new Geo::OSR::SpatialReference object
8185 #*
8186 sub new {
8187  my $pkg = shift;
8188  my %param = @_;
8189  my $self = Geo::OSRc::new_SpatialReference();
8190  if (exists $param{WKT}) {
8191  ImportFromWkt($self, $param{WKT});
8192  } elsif (exists $param{Text}) {
8193  ImportFromWkt($self, $param{Text});
8194  } elsif (exists $param{Proj4}) {
8195  ImportFromProj4($self, $param{Proj4});
8196  } elsif (exists $param{ESRI}) {
8197  ImportFromESRI($self, @{$param{ESRI}});
8198  } elsif (exists $param{EPSG}) {
8199  ImportFromEPSG($self, $param{EPSG});
8200  } elsif (exists $param{EPSGA}) {
8201  ImportFromEPSGA($self, $param{EPSGA});
8202  } elsif (exists $param{PCI}) {
8203  ImportFromPCI($self, @{$param{PCI}});
8204  } elsif (exists $param{USGS}) {
8205  ImportFromUSGS($self, @{$param{USGS}});
8206  } elsif (exists $param{XML}) {
8207  ImportFromXML($self, $param{XML});
8208  } elsif (exists $param{GML}) {
8209  ImportFromGML($self, $param{GML});
8210  } elsif (exists $param{URL}) {
8211  ImportFromUrl($self, $param{URL});
8212  } elsif (exists $param{ERMapper}) {
8213  ImportFromERM($self, @{$param{ERMapper}});
8214  } elsif (exists $param{ERM}) {
8215  ImportFromERM($self, @{$param{ERM}});
8216  } elsif (exists $param{MICoordSys}) {
8217  ImportFromMICoordSys($self, $param{MICoordSys});
8218  } elsif (exists $param{MapInfoCS}) {
8219  ImportFromMICoordSys($self, $param{MapInfoCS});
8220  } elsif (exists $param{WGS}) {
8221  eval {
8222  SetWellKnownGeogCS($self, 'WGS'.$param{WGS});
8223  };
8224  confess last_error() if $@;
8225  } else {
8226  error("Unrecognized/missing parameters: @_.");
8227  }
8228  bless $self, $pkg if defined $self;
8229 }
8230 
public Geo::GDAL::Extent new(array params)
public Geo::GDAL::ColorTable ColorTable(scalar ColorTable)
public method IsEmpty()
A definition of a non-spatial attribute.
Definition: all.pm:10078
The schema of a feature or a layer.
Definition: all.pm:9668
public Geo::OGR::Geometry new(hash params)
public Geo::GDAL::Dataset OpenEx(hash params)
public Geo::GDAL::ColorTable new(scalar GDALPaletteInterp='RGB')
A set of associated raster bands or vector layer source.
Definition: all.pm:3408
public Geo::GDAL::Band Band(scalar index)
public scalar Overlaps(scalar extent)
A driver for a specific dataset format.
Definition: all.pm:5020
An attribute table in a raster band.
Definition: all.pm:6147
public Geo::GDAL::Dataset Create(hash params)
public method new(array params)
public method AddGeometry(scalar other)
public Geo::OGR::FieldDefn new(hash params)
Create a new field definition.
A simple XML parser
Definition: all.pm:7259
public Geo::OSR::SpatialReference new(hash params)
public method VSIFFlushL()
public Geo::GDAL::Driver Driver(scalar Name)
public scalar GeometryType()
public Geo::OGR::GeomFieldDefn new(hash params)
Create a new spatial field definition.
Spatial data.
Definition: all.pm:10890
public list GeometryTypes()
A color table from a raster band or a color table, which can be used for a band. ...
Definition: all.pm:3222
public Geo::OGR::Feature new(hash schema)
Create a new feature.
public Geo::OGR::FeatureDefn new(hash schema)
public list Tuple(array tuple)
public array reference Points(arrayref points)
A raster band.
Definition: all.pm:1455
public method Set3D()
A rectangular area in projection coordinates: xmin, ymin, xmax, ymax.
Definition: all.pm:5517
An object, which holds meta data.
Definition: all.pm:5951
A collection of similar features.
Definition: all.pm:13500
public scalar GetDataTypeSize(scalar DataType)
A spatial reference system.
Definition: all.pm:15826
public scalar PackCharacter(scalar DataType)
An array of affine transformation coefficients.
Definition: all.pm:5808
A collection of non-spatial and spatial attributes.
Definition: all.pm:8608
A definition of a spatial attribute.
Definition: all.pm:10566