2 # @brief GDAL utility functions and a root class for raster classes.
3 # @details Geo::GDAL wraps many GDAL utility functions and is as a root class
4 # for all GDAL raster classes. A "raster" is an object, whose core is
5 # a rectagular grid of cells, called a "band" in GDAL. Each cell
6 # contains a numeric value of a specific data type.
10 #** @method ApplyVerticalShiftGrid()
12 sub ApplyVerticalShiftGrid {
15 #** @method BuildVRT()
18 for (keys %Geo::GDAL::Const::) {
20 push(@DATA_TYPES, $1), next
if /^GDT_(\w+)/;
21 push(@OPEN_FLAGS, $1), next
if /^OF_(\w+)/;
22 push(@RESAMPLING_TYPES, $1), next
if /^GRA_(\w+)/;
23 push(@RIO_RESAMPLING_TYPES, $1), next
if /^GRIORA_(\w+)/;
24 push(@NODE_TYPES, $1), next
if /^CXT_(\w+)/;
26 for my $string (@DATA_TYPES) {
27 my $int = eval
"\$Geo::GDAL::Const::GDT_$string";
28 $S2I{data_type}{$string} = $int;
29 $I2S{data_type}{$int} = $string;
31 for my $string (@OPEN_FLAGS) {
32 my $int = eval
"\$Geo::GDAL::Const::OF_$string";
33 $S2I{open_flag}{$string} = $int;
35 for my $string (@RESAMPLING_TYPES) {
36 my $int = eval
"\$Geo::GDAL::Const::GRA_$string";
37 $S2I{resampling}{$string} = $int;
38 $I2S{resampling}{$int} = $string;
40 for my $string (@RIO_RESAMPLING_TYPES) {
41 my $int = eval
"\$Geo::GDAL::Const::GRIORA_$string";
42 $S2I{rio_resampling}{$string} = $int;
43 $I2S{rio_resampling}{$int} = $string;
45 for my $string (@NODE_TYPES) {
46 my $int = eval
"\$Geo::GDAL::Const::CXT_$string";
47 $S2I{node_type}{$string} = $int;
48 $I2S{node_type}{$int} = $string;
52 $HAVE_PDL = 1 unless $@;
55 #** @method CPLBinaryToHex()
60 #** @method CPLHexToBinary()
65 #** @method CreatePansharpenedVRT()
67 sub CreatePansharpenedVRT {
70 #** @method scalar DataTypeIsComplex($DataType)
72 # @param DataType A GDAL raster cell data type (one of those listed by Geo::GDAL::DataTypes).
73 # @return true if the data type is a complex number.
75 sub DataTypeIsComplex {
76 return _DataTypeIsComplex(s2i(data_type => shift));
79 #** @method list DataTypeValueRange($DataType)
81 # @param DataType Data type (one of those listed by Geo::GDAL::DataTypes).
82 # @note Some returned values are inaccurate.
84 # @return the minimum, maximum range of the data type.
86 sub DataTypeValueRange {
89 # these values are from gdalrasterband.cpp
90 return (0,255)
if $t =~ /Byte/;
91 return (0,65535)
if $t =~/UInt16/;
92 return (-32768,32767)
if $t =~/Int16/;
93 return (0,4294967295)
if $t =~/UInt32/;
94 return (-2147483648,2147483647)
if $t =~/Int32/;
95 return (-4294967295.0,4294967295.0)
if $t =~/Float32/;
96 return (-4294967295.0,4294967295.0)
if $t =~/Float64/;
99 #** @method list DataTypes()
100 # Package subroutine.
101 # @return a list of GDAL raster cell data types. These are currently:
102 # Byte, CFloat32, CFloat64, CInt16, CInt32, Float32, Float64, Int16, Int32, UInt16, UInt32, and Unknown.
108 #** @method scalar DecToDMS($angle, $axis, $precision=2)
109 # Package subroutine.
110 # Convert decimal degrees to degrees, minutes, and seconds string
111 # @param angle A number
112 # @param axis A string specifying latitude or longitude ('Long').
114 # @return a string nndnn'nn.nn'"L where n is a number and L is either
120 #** @method scalar DecToPackedDMS($dec)
121 # Package subroutine.
122 # @param dec Decimal degrees
123 # @return packed DMS, i.e., a number DDDMMMSSS.SS
128 #** @method DontUseExceptions()
129 # Package subroutine.
130 # Do not use the Perl exception mechanism for GDAL messages. Instead
131 # the messages are printed to standard error.
133 sub DontUseExceptions {
136 #** @method Geo::GDAL::Driver Driver($Name)
137 # Package subroutine.
138 # Access a format driver.
139 # @param Name The short name of the driver. One of
140 # Geo::GDAL::DriverNames or Geo::OGR::DriverNames.
141 # @note This subroutine is imported into the main namespace if Geo::GDAL
142 # is used with qw/:all/.
143 # @return a Geo::GDAL::Driver object.
146 return 'Geo::GDAL::Driver' unless @_;
148 my $driver = GetDriver($name);
149 error(
"Driver \"$name\" not found. Is it built in? Check with Geo::GDAL::Drivers or Geo::OGR::Drivers.")
154 #** @method list DriverNames()
155 # Package subroutine.
156 # Available raster format drivers.
158 # perl -MGeo::GDAL -e '@d=Geo::GDAL::DriverNames;print "@d\n"'
160 # @note Use Geo::OGR::DriverNames for vector drivers.
161 # @return a list of the short names of all available GDAL raster drivers.
166 #** @method list Drivers()
167 # Package subroutine.
168 # @note Use Geo::OGR::Drivers for vector drivers.
169 # @return a list of all available GDAL raster drivers.
173 for my $i (0..GetDriverCount()-1) {
174 my $driver = GetDriver($i);
175 push @drivers, $driver
if $driver->TestCapability(
'RASTER');
180 #** @method EscapeString()
185 #** @method scalar FindFile($basename)
186 # Package subroutine.
187 # Search for GDAL support files.
192 # $a = Geo::GDAL::FindFile('pcs.csv');
193 # print STDERR "$a\n";
195 # Prints (for example):
197 # c:\msys\1.0\local\share\gdal\pcs.csv
200 # @param basename The name of the file to search for. For example
202 # @return the path to the searched file or undef.
212 #** @method FinderClean()
213 # Package subroutine.
214 # Clear the set of support file search paths.
219 #** @method GOA2GetAccessToken()
221 sub GOA2GetAccessToken {
224 #** @method GOA2GetAuthorizationURL()
226 sub GOA2GetAuthorizationURL {
229 #** @method GOA2GetRefreshToken()
231 sub GOA2GetRefreshToken {
234 #** @method scalar GetCacheMax()
235 # Package subroutine.
236 # @return maximum amount of memory (as bytes) for caching within GDAL.
241 #** @method scalar GetCacheUsed()
242 # Package subroutine.
243 # @return the amount of memory currently used for caching within GDAL.
248 #** @method scalar GetConfigOption($key)
249 # Package subroutine.
250 # @param key A GDAL config option. Consult <a
251 # href="https://trac.osgeo.org/gdal/wiki/ConfigOptions">the GDAL
252 # documentation</a> for available options and their use.
253 # @return the value of the GDAL config option.
255 sub GetConfigOption {
258 #** @method scalar GetDataTypeSize($DataType)
259 # Package subroutine.
260 # @param DataType A GDAL raster cell data type (one of those listed by Geo::GDAL::DataTypes).
261 # @return the size as the number of bits.
263 sub GetDataTypeSize {
264 return _GetDataTypeSize(s2i(data_type => shift, 1));
267 #** @method GetJPEG2000StructureAsString()
269 sub GetJPEG2000StructureAsString {
272 #** @method Geo::GDAL::Driver IdentifyDriver($path, $siblings)
273 # Package subroutine.
274 # @param path a dataset path.
275 # @param siblings [optional] A list of names of files that belong to the data format.
276 # @return a Geo::GDAL::Driver.
281 #** @method IdentifyDriverEx()
283 sub IdentifyDriverEx {
286 #** @method Geo::GDAL::Dataset Open(%params)
287 # Package subroutine.
289 # An example, which opens an existing raster dataset for editing:
291 # use Geo::GDAL qw/:all/;
292 # $ds = Open(Name => 'existing.tiff', Access => 'Update');
294 # @param params Named parameters:
295 # - \a Name Dataset string (typically a filename). Default is '.'.
296 # - \a Access Access type, either 'ReadOnly' or 'Update'. Default is 'ReadOnly'.
297 # - \a Type Dataset type, either 'Raster', 'Vector', or 'Any'. Default is 'Any'.
298 # - \a Options A hash of GDAL open options passed to candidate drivers. Default is {}.
299 # - \a Files A list of names of files that are auxiliary to the main file. Default is [].
301 # @note This subroutine is imported into the main namespace if Geo::GDAL
302 # is use'd with qw/:all/.
304 # @note Some datasets / dataset strings do not explicitly imply the
305 # dataset type (for example a PostGIS database). If the type is not
306 # specified in such a case the returned dataset may be of either type.
308 # @return a new Geo::GDAL::Dataset object if success.
311 my $p = named_parameters(\@_, Name =>
'.', Access =>
'ReadOnly', Type =>
'Any', Options => {}, Files => []);
313 my %o = (READONLY => 1, UPDATE => 1);
314 error(1, $p->{access}, \%o) unless $o{uc($p->{access})};
315 push @flags, uc($p->{access});
316 %o = (RASTER => 1, VECTOR => 1, ANY => 1);
317 error(1, $p->{type}, \%o) unless $o{uc($p->{type})};
318 push @flags, uc($p->{type}) unless uc($p->{type}) eq
'ANY';
319 my $dataset = OpenEx(Name => $p->{name}, Flags => \@flags, Options => $p->{options}, Files => $p->{files});
321 my $t =
"Failed to open $p->{name}.";
322 $t .=
" Is it a ".lc($p->{type}).
" dataset?" unless uc($p->{type}) eq
'ANY';
328 #** @method Geo::GDAL::Dataset OpenEx(%params)
329 # Package subroutine.
330 # The generic dataset open method, used internally by all Open and OpenShared methods.
331 # @param params Named parameters:
332 # - \a Name The name of the data set or source to open. (Default is '.')
333 # - \a Flags A list of access mode flags. Available flags are listed by Geo::GDAL::OpenFlags(). (Default is [])
334 # - \a Drivers A list of short names of drivers that may be used. Empty list means all. (Default is [])
335 # - \a Options A hash of GDAL open options passed to candidate drivers. (Default is {})
336 # - \a Files A list of names of files that are auxiliary to the main file. (Default is [])
340 # $ds = Geo::GDAL::OpenEx(Name => 'existing.tiff', Flags => [qw/RASTER UPDATE/]);
342 # @return a new Geo::GDAL::Dataset object.
345 my $p = named_parameters(\@_, Name =>
'.', Flags => [], Drivers => [], Options => {}, Files => []);
349 $p = {name => $name, flags => \@flags, drivers => [], options => {}, files => []};
353 for my $flag (@{$p->{flags}}) {
354 $f |= s2i(open_flag => $flag);
358 return _OpenEx($p->{name}, $p->{flags}, $p->{drivers}, $p->{options}, $p->{files});
361 #** @method list OpenFlags()
362 # Package subroutine.
363 # @return a list of GDAL data set open modes. These are currently:
364 # ALL, GNM, RASTER, READONLY, SHARED, UPDATE, VECTOR, and VERBOSE_ERROR.
370 #** @method scalar PackCharacter($DataType)
371 # Package subroutine.
372 # Get the character that is needed for Perl's pack and unpack when
373 # they are used with Geo::GDAL::Band::ReadRaster and
374 # Geo::GDAL::Band::WriteRaster. Note that Geo::GDAL::Band::ReadTile
375 # and Geo::GDAL::Band::WriteTile have simpler interfaces that do not
376 # require pack and unpack.
377 # @param DataType A GDAL raster cell data type, typically from $band->DataType.
378 # @return a character which can be used in Perl's pack and unpack.
382 $t = i2s(data_type => $t);
383 s2i(data_type => $t); # test
384 my $is_big_endian = unpack(
"h*", pack(
"s", 1)) =~ /01/; # from Programming Perl
385 return 'C' if $t =~ /^Byte$/;
386 return ($is_big_endian ?
'n':
'v')
if $t =~ /^UInt16$/;
387 return 's' if $t =~ /^Int16$/;
388 return ($is_big_endian ?
'N' :
'V')
if $t =~ /^UInt32$/;
389 return 'l' if $t =~ /^Int32$/;
390 return 'f' if $t =~ /^Float32$/;
391 return 'd' if $t =~ /^Float64$/;
394 #** @method scalar PackedDMSToDec($packed)
395 # Package subroutine.
396 # @param packed DMS as a number DDDMMMSSS.SS
397 # @return decimal degrees
402 #** @method PopFinderLocation()
403 # Package subroutine.
404 # Remove the latest addition from the set of support file search
405 # paths. Note that calling this subroutine may remove paths GDAL put
408 sub PopFinderLocation {
411 #** @method PushFinderLocation($path)
412 # Package subroutine.
413 # Add a path to the set of paths from where GDAL support files are
414 # sought. Note that GDAL puts initially into the finder the current
415 # directory and value of GDAL_DATA environment variable (if it
416 # exists), installation directory (prepended with '/share/gdal' or
417 # '/Resources/gdal'), or '/usr/local/share/gdal'. It is usually only
418 # needed to add paths to the finder if using an alternate set of data
419 # files or a non-installed GDAL is used (as in testing).
421 sub PushFinderLocation {
424 #** @method RELEASE_PARENT()
429 #** @method list RIOResamplingTypes()
430 # Package subroutine.
431 # @return a list of GDAL raster IO resampling methods. These are currently:
432 # Average, Bilinear, Cubic, CubicSpline, Gauss, Lanczos, Mode, and NearestNeighbour.
434 sub RIOResamplingTypes {
435 return @RIO_RESAMPLING_TYPES;
438 #** @method list ResamplingTypes()
439 # Package subroutine.
440 # @return a list of GDAL resampling methods. These are currently:
441 # Average, Bilinear, Cubic, CubicSpline, Lanczos, Mode, and NearestNeighbour.
443 sub ResamplingTypes {
444 return @RESAMPLING_TYPES;
447 #** @method SetCacheMax($Bytes)
448 # Package subroutine.
449 # @param Bytes New maximum amount of memory for caching within GDAL.
454 #** @method SetConfigOption($key, $value)
455 # Package subroutine.
456 # @param key A GDAL config option. Consult <a
457 # href="https://trac.osgeo.org/gdal/wiki/ConfigOptions">the GDAL
458 # documentation</a> for available options and their use.
459 # @param value A value for the option, typically 'YES', 'NO',
460 # undef, path, numeric value, or a filename.
462 sub SetConfigOption {
465 #** @method UseExceptions()
466 # Package subroutine.
467 # Use the Perl exception mechanism for GDAL messages (failures are
468 # confessed and warnings are warned) and collect the messages
469 # into \@Geo::GDAL::error. This is the default.
474 #** @method VSIFOpenExL()
479 #** @method VSIGetLastErrorMsg()
481 sub VSIGetLastErrorMsg {
484 #** @method VSIGetLastErrorNo()
486 sub VSIGetLastErrorNo {
489 #** @method scalar VersionInfo($request = 'VERSION_NUM')
490 # Package subroutine.
491 # @param request A string specifying the request. Currently either
492 # "VERSION_NUM", "RELEASE_DATE", "RELEASE_NAME", or
493 # "--version". Default is "VERSION_NUM".
494 # @return Requested information.
499 #** @method scalar errstr()
500 # Package subroutine.
501 # Clear the error stack and return all generated GDAL error messages in one (possibly multiline) string.
502 # @return the chomped error stack joined with newlines.
508 return join(
"\n", @stack);
510 # usage: named_parameters(\@_, key value list of default parameters);
511 # returns parameters in a hash with low-case-without-_ keys
517 my ($class, $int) = @_;
518 return $I2S{$class}{$int}
if exists $I2S{$class}{$int};
525 my ($child, $parent) = @_;
526 $keeper{tied(%$child)} = $parent;
529 # this is called from RELEASE_PARENT, so the child is already the tied one
535 my ($object, $note) = @_;
536 if (defined wantarray) {
537 return unless $note{$object};
538 return $notes{$object}{$note};
540 $notes{$object}{$note} = 1;
547 $child = tied(%$child) if $child->isa('HASH');
548 return $keeper{$child};
554 my ($class, $string, $backwards, $default) = @_;
555 $string = $default
if defined $default && !defined $string;
556 return unless defined $string;
557 return $string
if $backwards && exists $I2S{$class}{$string};
558 error(1, $string, $S2I{$class}) unless exists $S2I{$class}{$string};
559 $S2I{$class}{$string};
562 #** @method s_exists()
565 my ($class, $string) = @_;
566 return exists $S2I{$class}{$string};
573 delete $keeper{$child};
579 my ($object, $note) = @_;
581 delete $notes{$object}{$note};
583 delete $notes{$object};
587 #** @class Geo::GDAL::AsyncReader
588 # @brief Enable asynchronous requests.
589 # @details This class is not yet documented nor tested in the GDAL Perl wrappers
590 # @todo Test and document.
592 package Geo::GDAL::AsyncReader;
596 #** @method GetNextUpdatedRegion()
598 sub GetNextUpdatedRegion {
601 #** @method LockBuffer()
606 #** @method UnlockBuffer()
611 #** @class Geo::GDAL::Band
612 # @brief A raster band.
615 package Geo::GDAL::Band;
621 # scalar (access as $band->{XSize})
626 # scalar (access as $band->{YSize})
629 #** @method Geo::GDAL::RasterAttributeTable AttributeTable($AttributeTable)
631 # @param AttributeTable [optional] A Geo::GDAL::RasterAttributeTable object.
632 # @return a new Geo::GDAL::RasterAttributeTable object, whose data is
633 # contained within the band.
637 SetDefaultRAT($self, $_[0]) if @_ and defined $_[0];
638 return unless defined wantarray;
639 my $r = GetDefaultRAT($self);
640 keep($r, $self) if $r;
643 #** @method list BlockSize()
646 # @return The size of a preferred i/o raster block size as a list
652 #** @method list CategoryNames(@names)
654 # @param names [optional]
659 SetRasterCategoryNames($self, \@_) if @_;
660 return unless defined wantarray;
661 my $n = GetRasterCategoryNames($self);
665 #** @method scalar Checksum($xoff = 0, $yoff = 0, $xsize = undef, $ysize = undef)
667 # Computes a checksum from the raster or a part of it.
672 # @return the checksum.
677 #** @method hashref ClassCounts($classifier, $progress = undef, $progress_data = undef)
679 # Compute the counts of cell values or number of cell values in ranges.
680 # @note Classifier is required only for float bands. Do not specify
681 # one for integer bands.
682 # @note NoData values are counted similar to other values.
684 # @param classifier Anonymous array of format [ $comparison,
685 # $classifier ], where $comparison is a string '<', '<=', '>', or '>='
686 # and $classifier is an anonymous array of format [ $value,
687 # $value|$classifier, $value|$classifier ], where $value is numeric
688 # value against which the reclassified value is compared to.
689 # @note Numeric value requires decimal point.
691 # In the example below, the real line is divided into ranges
692 # [-inf..3), [3..5), and [5..inf], i.e., three ranges with indexes 0,
695 # $classifier = [ '<', [5.0, [3.0, 1.0, 2.0], 3.0] ];
697 # @return a reference to an anonymous hash, which contains the class
698 # values (indexes) as keys and the number of cells with that value or
699 # in that range as values. If the subroutine is user terminated an
705 #** @method scalar ColorInterpretation($color_interpretation)
707 # @note a.k.a. GetRasterColorInterpretation and GetColorInterpretation
708 # (get only and returns an integer), SetRasterColorInterpretation and
709 # SetColorInterpretation (set only and requires an integer)
710 # @param color_interpretation [optional] new color interpretation, one
711 # of Geo::GDAL::Band::ColorInterpretations.
712 # @return The color interpretation of this band. One of Geo::GDAL::Band::ColorInterpretations.
714 sub ColorInterpretation {
717 $ci = s2i(color_interpretation => $ci);
718 SetRasterColorInterpretation($self, $ci);
720 return unless defined wantarray;
721 i2s(color_interpretation => GetRasterColorInterpretation($self));
724 #** @method ColorInterpretations()
725 # Package subroutine.
726 # @return a list of types of color interpretation for raster
727 # bands. These are currently:
728 # AlphaBand, BlackBand, BlueBand, CyanBand, GrayIndex, GreenBand, HueBand, LightnessBand, MagentaBand, PaletteIndex, RedBand, SaturationBand, Undefined, YCbCr_CbBand, YCbCr_CrBand, YCbCr_YBand, and YellowBand.
730 sub ColorInterpretations {
731 return @COLOR_INTERPRETATIONS;
734 #** @method Geo::GDAL::ColorTable ColorTable($ColorTable)
736 # Get or set the color table of this band.
737 # @param ColorTable [optional] a Geo::GDAL::ColorTable object
738 # @return A new Geo::GDAL::ColorTable object which represents the
739 # internal color table associated with this band. Returns undef this
740 # band does not have an associated color table.
744 SetRasterColorTable($self, $_[0]) if @_ and defined $_[0];
745 return unless defined wantarray;
746 GetRasterColorTable($self);
749 #** @method ComputeBandStats($samplestep = 1)
751 # @param samplestep the row increment in computing the statistics.
752 # @note Returns uncorrected sample standard deviation.
754 # See also Geo::GDAL::Band::ComputeStatistics.
755 # @return a list (mean, stddev).
757 sub ComputeBandStats {
760 #** @method ComputeRasterMinMax($approx_ok = 0)
762 # @return arrayref MinMax = [min, max]
764 sub ComputeRasterMinMax {
767 #** @method list ComputeStatistics($approx_ok, $progress = undef, $progress_data = undef)
769 # @param approx_ok Whether it is allowed to compute the statistics
770 # based on overviews or similar.
771 # @note Returns uncorrected sample standard deviation.
773 # See also Geo::GDAL::Band::ComputeBandStats.
774 # @return a list ($min, $max, $mean, $stddev).
776 sub ComputeStatistics {
779 #** @method Geo::OGR::Layer Contours($DataSource, hashref LayerConstructor, $ContourInterval, $ContourBase, arrayref FixedLevels, $NoDataValue, $IDField, $ElevField, coderef Progress, $ProgressData)
781 # Generate contours for this raster band. This method can also be used with named parameters.
782 # @note This method is a wrapper for ContourGenerate.
787 # $dem = Geo::GDAL::Open('dem.gtiff');
788 # $contours = $dem->Band->Contours(ContourInterval => 10, ElevField => 'z');
789 # $n = $contours->GetFeatureCount;
792 # @param DataSource a Geo::OGR::DataSource object, default is a Memory data source
793 # @param LayerConstructor data for Geo::OGR::DataSource::CreateLayer, default is {Name => 'contours'}
794 # @param ContourInterval default is 100
795 # @param ContourBase default is 0
796 # @param FixedLevels a reference to a list of fixed contour levels, default is []
797 # @param NoDataValue default is undef
798 # @param IDField default is '', i.e., no field (the field is created if this is given)
799 # @param ElevField default is '', i.e., no field (the field is created if this is given)
800 # @param progress [optional] a reference to a subroutine, which will
801 # be called with parameters (number progress, string msg, progress_data)
802 # @param progress_data [optional]
807 my $p = named_parameters(\@_,
809 LayerConstructor => {Name =>
'contours'},
810 ContourInterval => 100,
813 NoDataValue => undef,
817 ProgressData => undef);
819 $p->{layerconstructor}->{Schema}
820 $p->{layerconstructor}->{Schema}{Fields}
822 unless ($p->{idfield} =~ /^[+-]?\d+$/ or $fields{$p->{idfield}}) {
823 push @{$p->{layerconstructor}->{Schema}{Fields}}, {Name => $p->{idfield}, Type =>
'Integer'};
825 unless ($p->{elevfield} =~ /^[+-]?\d+$/ or $fields{$p->{elevfield}}) {
826 my $type = $self->DataType() =~ /Float/ ?
'Real' :
'Integer';
827 push @{$p->{layerconstructor}->{Schema}{Fields}}, {Name => $p->{elevfield}, Type => $type};
829 my $layer = $p->{datasource}->CreateLayer($p->{layerconstructor});
830 my $schema = $layer->GetLayerDefn;
831 for (
'idfield',
'elevfield') {
832 $p->{$_} = $schema->GetFieldIndex($p->{$_}) unless $p->{$_} =~ /^[+-]?\d+$/;
834 $p->{progressdata} = 1
if $p->{progress} and not defined $p->{progressdata};
835 ContourGenerate($self, $p->{contourinterval}, $p->{contourbase}, $p->{fixedlevels},
836 $p->{nodatavalue}, $layer, $p->{idfield}, $p->{elevfield},
837 $p->{progress}, $p->{progressdata});
841 #** @method CreateMaskBand(@flags)
843 # @note May invalidate any previous mask band obtained with Geo::GDAL::Band::GetMaskBand.
845 # @param flags one or more mask flags. The flags are Geo::GDAL::Band::MaskFlags.
850 if (@_ and $_[0] =~ /^\d$/) {
854 carp
"Unknown mask flag: '$flag'." unless $MASK_FLAGS{$flag};
855 $f |= $MASK_FLAGS{$flag};
858 $self->_CreateMaskBand($f);
861 #** @method scalar DataType()
863 # @return The data type of this band. One of Geo::GDAL::DataTypes.
867 return i2s(data_type => $self->{DataType});
870 #** @method Geo::GDAL::Dataset Dataset()
872 # @return The dataset which this band belongs to.
879 #** @method scalar DeleteNoDataValue()
882 sub DeleteNoDataValue {
885 #** @method Geo::GDAL::Band Distance(%params)
887 # Compute distances to specific cells of this raster.
888 # @param params Named parameters:
889 # - \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.
890 # - \a Options Hash of options. Options are:
891 # - \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.
892 # - \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.
893 # - \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.
894 # - \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).
895 # - \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.
896 # - \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.
897 # - \a DataType The data type for the result if it is not given.
898 # - \a Progress Progress function.
899 # - \a ProgressData Additional parameter for the progress function.
901 # @note This GDAL function behind this API is called GDALComputeProximity.
903 # @return The distance raster.
907 my $p = named_parameters(\@_, Distance => undef, Options => undef, Progress => undef, ProgressData => undef);
908 for my $key (keys %{$p->{options}}) {
909 $p->{options}{uc($key)} = $p->{options}{$key};
912 unless ($p->{distance}) {
913 my ($w, $h) = $self->Size;
914 $p->{distance} =
Geo::GDAL::Driver(
'MEM')->
Create(Name =>
'distance', Width => $w, Height => $h, Type => $p->{options}{TYPE})->Band;
916 Geo::GDAL::ComputeProximity($self, $p->{distance}, $p->{options}, $p->{progress}, $p->{progressdata});
917 return $p->{distance};
920 #** @method Domains()
926 #** @method Fill($real_part, $imag_part = 0.0)
928 # Fill the band with a constant value.
929 # @param real_part Real component of fill value.
930 # @param imag_part Imaginary component of fill value.
936 #** @method FillNoData($mask, $max_search_dist, $smoothing_iterations, $options, coderef progress, $progress_data)
938 # Interpolate values for cells in this raster. The cells to fill
939 # should be marked in the mask band with zero.
941 # @param mask [optional] a mask band indicating cells to be interpolated (zero valued) (default is to get it with Geo::GDAL::Band::GetMaskBand).
942 # @param max_search_dist [optional] the maximum number of cells to
943 # search in all directions to find values to interpolate from (default is 10).
944 # @param smoothing_iterations [optional] the number of 3x3 smoothing filter passes to run (0 or more) (default is 0).
945 # @param options [optional] A reference to a hash. No options have been defined so far for this algorithm (default is {}).
946 # @param progress [optional] a reference to a subroutine, which will
947 # be called with parameters (number progress, string msg, progress_data) (default is undef).
948 # @param progress_data [optional] (default is undef).
950 # <a href="http://www.gdal.org/gdal__alg_8h.html">Documentation for GDAL algorithms</a>
955 #** @method FlushCache()
957 # Write cached data to disk. There is usually no need to call this
963 #** @method scalar GetBandNumber()
965 # @return The index of this band in the parent dataset list of bands.
970 #** @method GetBlockSize()
975 #** @method list GetDefaultHistogram($force = 1, coderef progress = undef, $progress_data = undef)
977 # @param force true to force the computation
978 # @param progress [optional] a reference to a subroutine, which will
979 # be called with parameters (number progress, string msg, progress_data)
980 # @param progress_data [optional]
981 # @note See Note in Geo::GDAL::Band::GetHistogram.
982 # @return a list: ($min, $max, arrayref histogram).
984 sub GetDefaultHistogram {
987 #** @method list GetHistogram(%parameters)
989 # Compute histogram from the raster.
990 # @param parameters Named parameters:
991 # - \a Min the lower bound, default is -0.5
992 # - \a Max the upper bound, default is 255.5
993 # - \a Buckets the number of buckets in the histogram, default is 256
994 # - \a IncludeOutOfRange whether to use the first and last values in the returned list
995 # for out of range values, default is false;
996 # the bucket size is (Max-Min) / Buckets if this is false and
997 # (Max-Min) / (Buckets-2) if this is true
998 # - \a ApproxOK if histogram can be computed from overviews, default is false
999 # - \a Progress an optional progress function, the default is undef
1000 # - \a ProgressData data for the progress function, the default is undef
1001 # @note Histogram counts are treated as strings in the bindings to be
1002 # able to use large integers (if GUIntBig is larger than Perl IV). In
1003 # practice this is only important if you have a 32 bit machine and
1004 # very large bucket counts. In those cases it may also be necessary to
1006 # @return a list which contains the count of values in each bucket
1010 my $p = named_parameters(\@_,
1014 IncludeOutOfRange => 0,
1017 ProgressData => undef);
1018 $p->{progressdata} = 1
if $p->{progress} and not defined $p->{progressdata};
1019 _GetHistogram($self, $p->{min}, $p->{max}, $p->{buckets},
1020 $p->{includeoutofrange}, $p->{approxok},
1021 $p->{progress}, $p->{progressdata});
1024 #** @method Geo::GDAL::Band GetMaskBand()
1026 # @return the mask band associated with this
1031 my $band = _GetMaskBand($self);
1035 #** @method list GetMaskFlags()
1037 # @return the mask flags of the mask band associated with this
1038 # band. The flags are one or more of Geo::GDAL::Band::MaskFlags.
1042 my $f = $self->_GetMaskFlags;
1044 for my $flag (keys %MASK_FLAGS) {
1045 push @f, $flag
if $f & $MASK_FLAGS{$flag};
1047 return wantarray ? @f : $f;
1050 #** @method scalar GetMaximum()
1052 # @note Call Geo::GDAL::Band::ComputeStatistics before calling
1053 # GetMaximum to make sure the value is computed.
1055 # @return statistical minimum of the band or undef if statistics are
1056 # not kept or computed in scalar context. In list context returns the
1057 # maximum value or a (kind of) maximum value supported by the data
1058 # type and a boolean value, which indicates which is the case (true is
1059 # first, false is second).
1064 #** @method scalar GetMinimum()
1066 # @note Call Geo::GDAL::Band::ComputeStatistics before calling
1067 # GetMinimum to make sure the value is computed.
1069 # @return statistical minimum of the band or undef if statistics are
1070 # not kept or computed in scalar context. In list context returns the
1071 # minimum value or a (kind of) minimum value supported by the data
1072 # type and a boolean value, which indicates which is the case (true is
1073 # first, false is second).
1078 #** @method Geo::GDAL::Band GetOverview($index)
1080 # @param index 0..GetOverviewCount-1
1081 # @return a Geo::GDAL::Band object, which represents the internal
1082 # overview band, or undef. if the index is out of bounds.
1085 my ($self, $index) = @_;
1086 my $band = _GetOverview($self, $index);
1090 #** @method scalar GetOverviewCount()
1092 # @return the number of overviews available of the band.
1094 sub GetOverviewCount {
1097 #** @method list GetStatistics($approx_ok, $force)
1099 # @param approx_ok Whether it is allowed to compute the statistics
1100 # based on overviews or similar.
1101 # @param force Whether to force scanning of the whole raster.
1102 # @note Uses Geo::GDAL::Band::ComputeStatistics internally.
1104 # @return a list ($min, $max, $mean, $stddev).
1109 #** @method HasArbitraryOverviews()
1111 # @return true or false.
1113 sub HasArbitraryOverviews {
1116 #** @method list MaskFlags()
1117 # Package subroutine.
1118 # @return the list of mask flags. These are
1119 # - \a AllValid: There are no invalid cell, all mask values will be 255.
1120 # When used this will normally be the only flag set.
1121 # - \a PerDataset: The mask band is shared between all bands on the dataset.
1122 # - \a Alpha: The mask band is actually an alpha band and may have values
1123 # other than 0 and 255.
1124 # - \a NoData: Indicates the mask is actually being generated from NoData values.
1125 # (mutually exclusive of Alpha).
1128 my @f = sort {$MASK_FLAGS{$a} <=> $MASK_FLAGS{$b}} keys %MASK_FLAGS;
1132 #** @method scalar NoDataValue($NoDataValue)
1134 # Get or set the "no data" value.
1135 # @param NoDataValue [optional]
1136 # @note $band->NoDataValue(undef) sets the NoData value to the
1137 # Posix floating point maximum. Use Geo::GDAL::Band::DeleteNoDataValue
1138 # to stop this band using a NoData value.
1139 # @return The NoData value or undef in scalar context. An undef
1140 # value indicates that there is no NoData value associated with this
1146 if (defined $_[0]) {
1147 SetNoDataValue($self, $_[0]);
1149 SetNoDataValue($self, POSIX::FLT_MAX); # hopefully an
"out of range" value
1152 GetNoDataValue($self);
1155 #** @method scalar PackCharacter()
1157 # @return The character to use in Perl pack and unpack for the data of this band.
1164 #** @method Piddle($piddle, $xoff = 0, $yoff = 0, $xsize = <width>, $ysize = <height>, $xdim, $ydim)
1166 # Read or write band data from/into a piddle.
1168 # \note The PDL module must be available for this method to work. Also, you
1169 # should 'use PDL' in the code that you use this method.
1171 # @param piddle [only when writing] The piddle from which to read the data to be written into the band.
1172 # @param xoff, yoff The offset for data in the band, default is top left (0, 0).
1173 # @param xsize, ysize [optional] The size of the window in the band.
1174 # @param xdim, ydim [optional, only when reading from a band] The size of the piddle to create.
1175 # @return A new piddle when reading from a band (no not use when writing into a band).
1178 # TODO: add Piddle sub to dataset too to make Width x Height x Bands piddles
1179 error(
"PDL is not available.") unless $Geo::GDAL::HAVE_PDL;
1181 my $t = $self->{DataType};
1182 unless (defined wantarray) {
1184 error(
"The datatype of the Piddle and the band do not match.")
1185 unless $PDL2DATATYPE{$pdl->get_datatype} == $t;
1186 my ($xoff, $yoff, $xsize, $ysize) = @_;
1189 my $data = $pdl->get_dataref();
1190 my ($xdim, $ydim) = $pdl->dims();
1191 if ($xdim > $self->{XSize} - $xoff) {
1192 warn
"Piddle XSize too large ($xdim) for this raster band (width = $self->{XSize}, offset = $xoff).";
1193 $xdim = $self->{XSize} - $xoff;
1195 if ($ydim > $self->{YSize} - $yoff) {
1196 $ydim = $self->{YSize} - $yoff;
1197 warn
"Piddle YSize too large ($ydim) for this raster band (height = $self->{YSize}, offset = $yoff).";
1201 $self->_WriteRaster($xoff, $yoff, $xsize, $ysize, $data, $xdim, $ydim, $t, 0, 0);
1204 my ($xoff, $yoff, $xsize, $ysize, $xdim, $ydim, $alg) = @_;
1212 $alg = s2i(rio_resampling => $alg);
1213 my $buf = $self->_ReadRaster($xoff, $yoff, $xsize, $ysize, $xdim, $ydim, $t, 0, 0, $alg);
1215 my $datatype = $DATATYPE2PDL{$t};
1216 error(
"The band datatype is not supported by PDL.") if $datatype < 0;
1217 $pdl->set_datatype($datatype);
1218 $pdl->setdims([$xdim, $ydim]);
1219 my $data = $pdl->get_dataref();
1222 # FIXME: we want approximate equality since no data value can be very large floating point value
1223 my $bad = GetNoDataValue($self);
1224 return $pdl->setbadif($pdl == $bad)
if defined $bad;
1228 #** @method Geo::OGR::Layer Polygonize(%params)
1230 # Polygonize this raster band.
1232 # @param params Named parameters:
1233 # - \a Mask A raster band, which is used as a mask to select polygonized areas. Default is undef.
1234 # - \a OutLayer A vector layer into which the polygons are written. If not given, an in-memory layer 'polygonized' is created and returned.
1235 # - \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'.
1236 # - \a Options Hash or list of options. Connectedness can be set to 8
1237 # to use 8-connectedness, otherwise 4-connectedness is
1238 # used. ForceIntPixel can be set to 1 to force using a 32 bit int buffer
1239 # for cell values in the process. If this is not set and the data type
1240 # of this raster does not fit into a 32 bit int buffer, a 32 bit float
1242 # - \a Progress Progress function.
1243 # - \a ProgressData Additional parameter for the progress function.
1245 # @return Output vector layer.
1249 my $p = named_parameters(\@_, Mask => undef, OutLayer => undef, PixValField =>
'val', Options => undef, Progress => undef, ProgressData => undef);
1250 my %known_options = (Connectedness => 1, ForceIntPixel => 1, DATASET_FOR_GEOREF => 1,
'8CONNECTED' => 1);
1251 for my $option (keys %{$p->{options}}) {
1252 error(1, $option, \%known_options) unless exists $known_options{$option};
1254 my $dt = $self->DataType;
1255 my %leInt32 = (Byte => 1, Int16 => 1, Int32 => 1, UInt16 => 1);
1256 my $leInt32 = $leInt32{$dt};
1257 $dt = $dt =~ /Float/ ?
'Real' :
'Integer';
1259 CreateLayer(Name =>
'polygonized',
1260 Fields => [{Name =>
'val', Type => $dt},
1261 {Name =>
'geom', Type =>
'Polygon'}]);
1262 $p->{pixvalfield} = $p->{outlayer}->GetLayerDefn->GetFieldIndex($p->{pixvalfield});
1263 $p->{options}{
'8CONNECTED'} = 1
if $p->{options}{Connectedness} && $p->{options}{Connectedness} == 8;
1264 if ($leInt32 || $p->{options}{ForceIntPixel}) {
1265 Geo::GDAL::_Polygonize($self, $p->{mask}, $p->{outlayer}, $p->{pixvalfield}, $p->{options}, $p->{progress}, $p->{progressdata});
1267 Geo::GDAL::FPolygonize($self, $p->{mask}, $p->{outlayer}, $p->{pixvalfield}, $p->{options}, $p->{progress}, $p->{progressdata});
1269 set the srs of the outlayer
if it was created here
1270 return $p->{outlayer};
1273 #** @method RELEASE_PARENT()
1275 sub RELEASE_PARENT {
1280 #** @method RasterAttributeTable()
1282 sub RasterAttributeTable {
1285 #** @method scalar ReadRaster(%params)
1287 # Read data from the band.
1289 # @param params Named parameters:
1290 # - \a XOff x offset (cell coordinates) (default is 0)
1291 # - \a YOff y offset (cell coordinates) (default is 0)
1292 # - \a XSize width of the area to read (default is the width of the band)
1293 # - \a YSize height of the area to read (default is the height of the band)
1294 # - \a BufXSize (default is undef, i.e., the same as XSize)
1295 # - \a BufYSize (default is undef, i.e., the same as YSize)
1296 # - \a BufType data type of the buffer (default is the data type of the band)
1297 # - \a BufPixelSpace (default is 0)
1298 # - \a BufLineSpace (default is 0)
1299 # - \a ResampleAlg one of Geo::GDAL::RIOResamplingTypes (default is 'NearestNeighbour'),
1300 # - \a Progress reference to a progress function (default is undef)
1301 # - \a ProgressData (default is undef)
1303 # <a href="http://www.gdal.org/classGDALDataset.html">Entry in GDAL docs (method RasterIO)</a>
1304 # @return a buffer, open the buffer with \a unpack function of Perl. See Geo::GDAL::Band::PackCharacter.
1308 my ($width, $height) = $self->Size;
1309 my ($type) = $self->DataType;
1310 my $p = named_parameters(\@_,
1320 ResampleAlg =>
'NearestNeighbour',
1322 ProgressData => undef
1324 $p->{resamplealg} = s2i(rio_resampling => $p->{resamplealg});
1325 $p->{buftype} = s2i(data_type => $p->{buftype}, 1);
1326 $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});
1329 #** @method array reference ReadTile($xoff = 0, $yoff = 0, $xsize = <width>, $ysize = <height>)
1331 # Read band data into a Perl array.
1333 # \note Accessing band data in this way is slow. Consider using PDL and Geo::GDAL::Band::Piddle.
1335 # Usage example (print the data from a band):
1337 # print "@$_\n" for ( @{ $band->ReadTile() } );
1339 # Another usage example (process the data of a large dataset that has one band):
1341 # my($W,$H) = $dataset->Band()->Size();
1342 # my($xoff,$yoff,$w,$h) = (0,0,200,200);
1344 # if ($xoff >= $W) {
1347 # last if $yoff >= $H;
1349 # my $data = $dataset->Band(1)->ReadTile($xoff,$yoff,min($W-$xoff,$w),min($H-$yoff,$h));
1350 # # add your data processing code here
1351 # $dataset->Band(1)->WriteTile($data,$xoff,$yoff);
1356 # return $_[0] < $_[1] ? $_[0] : $_[1];
1359 # @param xoff Number of cell to skip before starting to read from a row. Pixels are read from left to right.
1360 # @param yoff Number of cells to skip before starting to read from a column. Pixels are read from top to bottom.
1361 # @param xsize Number of cells to read from each row.
1362 # @param ysize Number of cells to read from each column.
1363 # @return a two-dimensional Perl array, organizes as data->[y][x], y =
1364 # 0..height-1, x = 0..width-1. I.e., y is row and x is column.
1367 my($self, $xoff, $yoff, $xsize, $ysize, $w_tile, $h_tile, $alg) = @_;
1375 $alg = s2i(rio_resampling => $alg);
1376 my $t = $self->{DataType};
1377 my $buf = $self->_ReadRaster($xoff, $yoff, $xsize, $ysize, $w_tile, $h_tile, $t, 0, 0, $alg);
1382 for my $y (0..$h_tile-1) {
1383 my @d = unpack($pc.
"[$w_tile]", substr($buf, $offset, $w));
1390 #** @method Reclassify($classifier, $progress = undef, $progress_data = undef)
1392 # Reclassify the cells in the band.
1393 # @note This method is defined only for integer bands.
1394 # @note NoData values are reclassified if explicitly specified in the
1395 # map. However, they are not reclassified to the default value, if one
1397 # @note If the subroutine is user terminated or the classifier is
1398 # incorrect, already reclassified cells will stay reclassified but an
1400 # @param classifier For integer rasters an anonymous hash, which
1401 # contains old class values as keys and new class values as values. A
1402 # special key '*' (star) can be used as default, to act as a fallback
1403 # new class value. For float rasters as in Geo::GDAL::Band::ClassCounts.
1408 #** @method RegenerateOverview(Geo::GDAL::Band overview, $resampling, coderef progress, $progress_data)
1410 # @param overview a Geo::GDAL::Band object for the overview.
1411 # @param resampling [optional] the resampling method (one of Geo::GDAL::RIOResamplingTypes) (default is Average).
1412 # @param progress [optional] a reference to a subroutine, which will
1413 # be called with parameters (number progress, string msg, progress_data)
1414 # @param progress_data [optional]
1416 sub RegenerateOverview {
1418 #Geo::GDAL::Band overview, scalar resampling, subref callback, scalar callback_data
1420 Geo::GDAL::RegenerateOverview($self, @p);
1423 #** @method RegenerateOverviews(arrayref overviews, $resampling, coderef progress, $progress_data)
1425 # @todo This is not yet available
1427 # @param overviews a list of Geo::GDAL::Band objects for the overviews.
1428 # @param resampling [optional] the resampling method (one of Geo::GDAL::RIOResamplingTypes) (default is Average).
1429 # @param progress [optional] a reference to a subroutine, which will
1430 # be called with parameters (number progress, string msg, progress_data)
1431 # @param progress_data [optional]
1433 sub RegenerateOverviews {
1435 #arrayref overviews, scalar resampling, subref callback, scalar callback_data
1437 Geo::GDAL::RegenerateOverviews($self, @p);
1440 #** @method ScaleAndOffset($scale, $offset)
1442 # Scale and offset are used to transform raw cell values into the
1443 # units returned by GetUnits(). The conversion function is:
1445 # Units value = (raw value * scale) + offset
1447 # @return a list ($scale, $offset), the values are undefined if they
1449 # @since version 1.9 of the bindings.
1451 sub ScaleAndOffset {
1453 SetScale($self, $_[0]) if @_ > 0 and defined $_[0];
1454 SetOffset($self, $_[1]) if @_ > 1 and defined $_[1];
1455 return unless defined wantarray;
1456 my $scale = GetScale($self);
1457 my $offset = GetOffset($self);
1458 return ($scale, $offset);
1461 #** @method list SetDefaultHistogram($min, $max, $histogram)
1465 # @note See Note in Geo::GDAL::Band::GetHistogram.
1466 # @param histogram reference to an array containing the histogram
1468 sub SetDefaultHistogram {
1471 #** @method SetStatistics($min, $max, $mean, $stddev)
1473 # Save the statistics of the band if possible (the format can save
1474 # arbitrary metadata).
1483 #** @method Geo::GDAL::Band Sieve(%params)
1485 # Remove small areas by merging them into the largest neighbour area.
1486 # @param params Named parameters:
1487 # - \a Mask A raster band, which is used as a mask to select sieved areas. Default is undef.
1488 # - \a Dest A raster band into which the result is written. If not given, an new in-memory raster band is created and returned.
1489 # - \a Threshold The smallest area size (in number of cells) which are not sieved away.
1490 # - \a Options Hash or list of options. {Connectedness => 4} can be specified to use 4-connectedness, otherwise 8-connectedness is used.
1491 # - \a Progress Progress function.
1492 # - \a ProgressData Additional parameter for the progress function.
1494 # @return The filtered raster band.
1498 my $p = named_parameters(\@_, Mask => undef, Dest => undef, Threshold => 10, Options => undef, Progress => undef, ProgressData => undef);
1499 unless ($p->{dest}) {
1500 my ($w, $h) = $self->Size;
1504 if ($p->{options}{Connectedness}) {
1505 $c = $p->{options}{Connectedness};
1506 delete $p->{options}{Connectedness};
1508 Geo::GDAL::SieveFilter($self, $p->{mask}, $p->{dest}, $p->{threshold}, $c, $p->{options}, $p->{progress}, $p->{progressdata});
1512 #** @method list Size()
1514 # @return The size of the band as a list (width, height).
1518 return ($self->{XSize}, $self->{YSize});
1521 #** @method Unit($type)
1523 # @param type [optional] the unit (a string).
1524 # @note $band->Unit(undef) sets the unit value to an empty string.
1525 # @return the unit (a string).
1526 # @since version 1.9 of the bindings.
1533 SetUnitType($self, $unit);
1535 return unless defined wantarray;
1539 #** @method WriteRaster(%params)
1541 # Write data into the band.
1543 # @param params Named parameters:
1544 # - \a XOff x offset (cell coordinates) (default is 0)
1545 # - \a YOff y offset (cell coordinates) (default is 0)
1546 # - \a XSize width of the area to write (default is the width of the band)
1547 # - \a YSize height of the area to write (default is the height of the band)
1548 # - \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.
1549 # - \a BufXSize (default is undef, i.e., the same as XSize)
1550 # - \a BufYSize (default is undef, i.e., the same as YSize)
1551 # - \a BufType data type of the buffer (default is the data type of the band)
1552 # - \a BufPixelSpace (default is 0)
1553 # - \a BufLineSpace (default is 0)
1555 # <a href="http://www.gdal.org/classGDALDataset.html">Entry in GDAL docs (method RasterIO)</a>
1559 my ($width, $height) = $self->Size;
1560 my ($type) = $self->DataType;
1561 my $p = named_parameters(\@_,
1573 confess
"Usage: \$band->WriteRaster( Buf => \$data, ... )" unless defined $p->{buf};
1574 $p->{buftype} = s2i(data_type => $p->{buftype}, 1);
1575 $self->_WriteRaster($p->{xoff},$p->{yoff},$p->{xsize},$p->{ysize},$p->{buf},$p->{bufxsize},$p->{bufysize},$p->{buftype},$p->{bufpixelspace},$p->{buflinespace});
1578 #** @method WriteTile($data, $xoff = 0, $yoff = 0)
1580 # Write band data from a Perl array.
1582 # \note Accessing band data in this way is slow. Consider using PDL and Geo::GDAL::Band::Piddle.
1584 # @param data A two-dimensional Perl array, organizes as data->[y][x], y =
1585 # 0..height-1, x = 0..width-1.
1591 my($self, $data, $xoff, $yoff) = @_;
1594 error(
'The data must be in a two-dimensional array') unless ref $data eq 'ARRAY' && ref $data->[0] eq 'ARRAY';
1595 my $xsize = @{$data->[0]};
1596 if ($xsize > $self->{XSize} - $xoff) {
1597 warn
"Buffer XSize too large ($xsize) for this raster band (width = $self->{XSize}, offset = $xoff).";
1598 $xsize = $self->{XSize} - $xoff;
1600 my $ysize = @{$data};
1601 if ($ysize > $self->{YSize} - $yoff) {
1602 $ysize = $self->{YSize} - $yoff;
1603 warn
"Buffer YSize too large ($ysize) for this raster band (height = $self->{YSize}, offset = $yoff).";
1606 for my $i (0..$ysize-1) {
1607 my $scanline = pack($pc.
"[$xsize]", @{$data->[$i]});
1608 $self->WriteRaster( $xoff, $yoff+$i, $xsize, 1, $scanline );
1612 #** @class Geo::GDAL::ColorTable
1613 # @brief A color table from a raster band or a color table, which can be used for a band.
1616 package Geo::GDAL::ColorTable;
1620 #** @method Geo::GDAL::ColorTable Clone()
1622 # Clone an existing color table.
1623 # @return a new Geo::GDAL::ColorTable object
1628 #** @method list Color($index, @color)
1630 # Get or set a color in this color table.
1631 # @param index The index of the color in the table. Note that the
1632 # color table may expand if the index is larger than the current max
1633 # index of this table and a color is given. An attempt to retrieve a
1634 # color out of the current size of the table causes an error.
1635 # @param color [optional] The color, either a list or a reference to a
1636 # list. If the list is too short or has undef values, the undef values
1637 # are taken as 0 except for alpha, which is taken as 255.
1638 # @note A color is an array of four integers having a value between 0
1639 # and 255: (gray, red, cyan or hue; green, magenta, or lightness;
1640 # blue, yellow, or saturation; alpha or blackband)
1641 # @return A color, in list context a list and in scalar context a reference to an anonymous array.
1646 #** @method list Colors(@colors)
1648 # Get or set the colors in this color table.
1649 # @note The color table will expand to the size of the input list but
1650 # it will not shrink.
1651 # @param colors [optional] A list of all colors (a list of lists) for this color table.
1652 # @return A list of colors (a list of lists).
1657 #** @method CreateColorRamp($start_index, arrayref start_color, $end_index, arrayref end_color)
1659 # @param start_index
1660 # @param start_color
1664 sub CreateColorRamp {
1667 #** @method scalar GetCount()
1669 # @return The number of colors in this color table.
1674 #** @method scalar GetPaletteInterpretation()
1676 # @return palette interpretation (string)
1678 sub GetPaletteInterpretation {
1680 return i2s(palette_interpretation => GetPaletteInterpretation($self));
1683 #** @method Geo::GDAL::ColorTable new($GDALPaletteInterp = 'RGB')
1685 # Create a new empty color table.
1686 # @return a new Geo::GDAL::ColorTable object
1691 $pi = s2i(palette_interpretation => $pi);
1692 my $self = Geo::GDALc::new_ColorTable($pi);
1693 bless $self, $pkg
if defined($self);
1696 #** @class Geo::GDAL::Dataset
1697 # @brief A set of associated raster bands or vector layer source.
1700 package Geo::GDAL::Dataset;
1704 #** @attr $RasterCount
1705 # scalar (access as $dataset->{RasterCount})
1708 #** @attr $RasterXSize
1709 # scalar (access as $dataset->{RasterXSize})
1712 #** @attr $RasterYSize
1713 # scalar (access as $dataset->{RasterYSize})
1716 #** @method AddBand($datatype = 'Byte', hashref options = {})
1718 # Add a new band to the dataset. The driver must support the action.
1719 # @param datatype GDAL raster cell data type (one of those listed by Geo::GDAL::DataTypes).
1720 # @param options reference to a hash of format specific options.
1721 # @return The added band.
1724 my ($self, $type, $options) = @_;
1726 $type = s2i(data_type => $type);
1727 $self->_AddBand($type, $options);
1728 return unless defined wantarray;
1729 return $self->GetRasterBand($self->{RasterCount});
1732 #** @method Geo::GDAL::Band Band($index)
1734 # Create a band object for the band within the dataset.
1735 # @note a.k.a. GetRasterBand
1736 # @param index 1...RasterCount, default is 1.
1737 # @return a new Geo::GDAL::Band object
1742 #** @method list Bands()
1744 # @return a list of new Geo::GDAL::Band objects
1749 for my $i (1..$self->{RasterCount}) {
1750 push @bands, GetRasterBand($self, $i);
1755 #** @method BuildOverviews($resampling, arrayref overviews, coderef progress, $progress_data)
1757 # @param resampling the resampling method, one of Geo::GDAL::RIOResamplingTypes.
1758 # @param overviews The list of overview decimation factors to
1759 # build. For example [2,4,8].
1760 # @param progress [optional] a reference to a subroutine, which will
1761 # be called with parameters (number progress, string msg, progress_data)
1762 # @param progress_data [optional]
1764 sub BuildOverviews {
1767 $p[0] = uc($p[0]) if $p[0];
1769 $self->_BuildOverviews(@p);
1771 confess(last_error()) if $@;
1774 #** @method Geo::GDAL::Dataset BuildVRT($Dest, arrayref Sources, hashref Options, coderef progress, $progress_data)
1776 # Build a virtual dataset from a set of datasets.
1777 # @param Dest Destination raster dataset definition string (typically
1778 # filename), or an object, which implements write and close.
1779 # @param Sources A list of filenames of input datasets or a list of
1781 # @param Options See section \ref index_processing_options.
1782 # @return Dataset object
1784 # @note This subroutine is imported into the main namespace if Geo::GDAL
1785 # is use'd with qw/:all/.
1788 my ($dest, $sources, $options, $progress, $progress_data) = @_;
1789 $options = Geo::GDAL::GDALBuildVRTOptions->new(make_processing_options($options));
1790 error(
"Usage: Geo::GDAL::DataSet::BuildVRT(\$vrt_file_name, \\\@sources)")
1791 unless ref $sources eq 'ARRAY' && defined $sources->[0];
1792 unless (blessed($dest)) {
1793 if (blessed($sources->[0])) {
1794 return Geo::GDAL::wrapper_GDALBuildVRT_objects($dest, $sources, $options, $progress, $progress_data);
1796 return Geo::GDAL::wrapper_GDALBuildVRT_names($dest, $sources, $options, $progress, $progress_data);
1799 if (blessed($sources->[0])) {
1800 return stdout_redirection_wrapper(
1802 \&Geo::GDAL::wrapper_GDALBuildVRT_objects,
1803 $options, $progress, $progress_data);
1805 return stdout_redirection_wrapper(
1807 \&Geo::GDAL::wrapper_GDALBuildVRT_names,
1808 $options, $progress, $progress_data);
1813 #** @method CommitTransaction()
1815 sub CommitTransaction {
1818 #** @method Geo::GDAL::ColorTable ComputeColorTable(%params)
1820 # Compute a color table from an RGB image
1821 # @param params Named parameters:
1822 # - \a Red The red band, the default is to use the red band of this dataset.
1823 # - \a Green The green band, the default is to use the green band of this dataset.
1824 # - \a Blue The blue band, the default is to use the blue band of this dataset.
1825 # - \a NumColors The number of colors in the computed color table. Default is 256.
1826 # - \a Progress reference to a progress function (default is undef)
1827 # - \a ProgressData (default is undef)
1828 # - \a Method The computation method. The default and currently only option is the median cut algorithm.
1830 # @return a new color table object.
1832 sub ComputeColorTable {
1834 my $p = named_parameters(\@_,
1840 ProgressData => undef,
1841 Method =>
'MedianCut');
1842 for my $b ($self->Bands) {
1843 for my $cion ($b->ColorInterpretation) {
1844 if ($cion eq
'RedBand') { $p->{red}
1845 if ($cion eq
'GreenBand') { $p->{green}
1846 if ($cion eq
'BlueBand') { $p->{blue}
1850 Geo::GDAL::ComputeMedianCutPCT($p->{red},
1854 $ct, $p->{progress},
1855 $p->{progressdata});
1859 #** @method Geo::OGR::Layer CopyLayer($layer, $name, hashref options = undef)
1861 # @param layer A Geo::OGR::Layer object to be copied.
1862 # @param name A name for the new layer.
1863 # @param options A ref to a hash of format specific options.
1864 # @return a new Geo::OGR::Layer object.
1869 #** @method Geo::OGR::Layer CreateLayer(%params)
1871 # @brief Create a new vector layer into this dataset.
1873 # @param %params Named parameters:
1874 # - \a Name (scalar) name for the new layer.
1875 # - \a Fields (array reference) a list of (scalar and geometry) field definitions as in
1876 # Geo::OGR::Layer::CreateField.
1877 # - \a ApproxOK (boolean value, default is true) a flag, which is forwarded to Geo::OGR::Layer::CreateField.
1878 # - \a Options (hash reference) driver specific hash of layer creation options.
1879 # - \a Schema (hash reference, deprecated, use \a Fields and \a Name) may contain keys Name, Fields, GeomFields, GeometryType.
1880 # - \a SRS (scalar) the spatial reference for the default geometry field.
1881 # - \a GeometryType (scalar) the type of the default geometry field
1882 # (if only one geometry field). Default is 'Unknown'.
1884 # @note If Fields or Schema|Fields is not given, a default geometry
1885 # field (Name => '', GeometryType => 'Unknown') is created. If it is
1886 # given and it contains spatial fields, GeometryType is ignored. The
1887 # type can be also set with the named parameter.
1891 # my $roads = Geo::OGR::Driver('Memory')->Create('road')->
1893 # Fields => [ { Name => 'class',
1894 # Type => 'Integer' },
1896 # Type => 'LineString25D' } ] );
1899 # @note Many formats allow only one spatial field, which currently
1900 # requires the use of GeometryType.
1902 # @return a new Geo::OGR::Layer object.
1906 my $p = named_parameters(\@_,
1909 GeometryType =>
'Unknown',
1914 error(
"The 'Fields' argument must be an array reference.") if $p->{fields} && ref($p->{fields}) ne
'ARRAY';
1915 if (defined $p->{schema}) {
1916 my $s = $p->{schema};
1917 $p->{geometrytype} = $s->{GeometryType}
if exists $s->{GeometryType};
1918 $p->{fields} = $s->{Fields}
if exists $s->{Fields};
1919 $p->{name} = $s->{Name}
if exists $s->{Name};
1921 $p->{fields} = [] unless ref($p->{fields}) eq
'ARRAY';
1922 # if fields contains spatial fields, then do not create default one
1923 for my $f (@{$p->{fields}}) {
1924 error(
"Field definitions must be hash references.") unless ref $f eq 'HASH';
1925 if ($f->{GeometryType} || ($f->{Type} && s_exists(geometry_type => $f->{Type}))) {
1926 $p->{geometrytype} =
'None';
1930 my $gt = s2i(geometry_type => $p->{geometrytype});
1931 my $layer = _CreateLayer($self, $p->{name}, $p->{srs}, $gt, $p->{options});
1932 for my $f (@{$p->{fields}}) {
1933 $layer->CreateField($f);
1935 keep($layer, $self);
1938 #** @method CreateMaskBand()
1940 # Add a mask band to the dataset.
1942 sub CreateMaskBand {
1943 return _CreateMaskBand(@_);
1946 #** @method Geo::GDAL::Dataset DEMProcessing($Dest, $Processing, $ColorFilename, hashref Options, coderef progress, $progress_data)
1948 # Apply a DEM processing to this dataset.
1949 # @param Dest Destination raster dataset definition string (typically filename) or an object, which implements write and close.
1950 # @param Processing Processing to apply, one of "hillshade", "slope", "aspect", "color-relief", "TRI", "TPI", or "Roughness".
1951 # @param ColorFilename The color palette for color-relief.
1952 # @param Options See section \ref index_processing_options.
1953 # @param progress [optional] A reference to a subroutine, which will
1954 # be called with parameters (number progress, string msg, progress_data).
1955 # @param progress_data [optional]
1959 my ($self, $dest, $Processing, $ColorFilename, $options, $progress, $progress_data) = @_;
1960 $options = Geo::GDAL::GDALDEMProcessingOptions->new(make_processing_options($options));
1961 return $self->stdout_redirection_wrapper(
1963 \&Geo::GDAL::wrapper_GDALDEMProcessing,
1964 $Processing, $ColorFilename, $options, $progress, $progress_data
1968 #** @method Dataset()
1975 #** @method DeleteLayer($name)
1977 # Deletes a layer from the data source. Note that if there is a layer
1978 # object for the deleted layer, it becomes unusable.
1979 # @param name name of the layer to delete.
1982 my ($self, $name) = @_;
1984 for my $i (0..$self->GetLayerCount-1) {
1985 my $layer = GetLayerByIndex($self, $i);
1986 $index = $i, last
if $layer->GetName eq $name;
1988 error(2, $name,
'Layer') unless defined $index;
1989 _DeleteLayer($self, $index);
1992 #** @method Geo::GDAL::Band Dither(%params)
1994 # Compute one band with color table image from an RGB image
1995 # @params params Named parameters:
1996 # - \a Red The red band, the default is to use the red band of this dataset.
1997 # - \a Green The green band, the default is to use the green band of this dataset.
1998 # - \a Blue The blue band, the default is to use the blue band of this dataset.
1999 # - \a Dest The destination band. If this is not defined, a new in-memory band (and a dataset) will be created.
2000 # - \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.
2001 # - \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.
2002 # - \a ProgressData (default is undef)
2004 # @return the destination band.
2006 # Usage example. This code converts an RGB JPEG image into a one band PNG image with a color table.
2008 # my $d = Geo::GDAL::Open('pic.jpg');
2009 # Geo::GDAL::Driver('PNG')->Copy(Name => 'test.png', Src => $d->Dither->Dataset);
2014 my $p = named_parameters(\@_,
2019 ColorTable => undef,
2021 ProgressData => undef);
2022 for my $b ($self->Bands) {
2023 for my $cion ($b->ColorInterpretation) {
2024 if ($cion eq
'RedBand') { $p->{red}
2025 if ($cion eq
'GreenBand') { $p->{green}
2026 if ($cion eq
'BlueBand') { $p->{blue}
2029 my ($w, $h) = $self->Size;
2033 Type =>
'Byte')->Band;
2037 Green => $p->{green},
2039 Progress => $p->{progress},
2040 ProgressData => $p->{progressdata});
2041 Geo::GDAL::DitherRGB2PCT($p->{red},
2047 $p->{progressdata});
2048 $p->{dest}->ColorTable($p->{colortable});
2052 #** @method Domains()
2058 #** @method Geo::GDAL::Driver Driver()
2060 # @note a.k.a. GetDriver
2061 # @return a Geo::GDAL::Driver object that was used to open or create this dataset.
2066 #** @method Geo::OGR::Layer ExecuteSQL($statement, $geom = undef, $dialect = "")
2068 # @param statement A SQL statement.
2069 # @param geom A Geo::OGR::Geometry object.
2071 # @return a new Geo::OGR::Layer object. The data source object will
2072 # exist as long as the layer object exists.
2076 my $layer = $self->_ExecuteSQL(@_);
2077 note($layer,
"is result set");
2078 keep($layer, $self);
2081 #** @method Geo::GDAL::Extent Extent(@params)
2083 # @param params nothing, or a list ($xoff, $yoff, $w, $h)
2084 # @return A new Geo::GDAL::Extent object that represents the area that
2085 # this raster or the specified tile covers.
2089 my $t = $self->GeoTransform;
2090 my $extent = $t->Extent($self->Size);
2092 my ($xoff, $yoff, $w, $h) = @_;
2093 my ($x, $y) = $t->Apply([$xoff, $xoff+$w, $xoff+$w, $xoff], [$yoff, $yoff, $yoff+$h, $yoff+$h]);
2094 my $xmin = shift @$x;
2097 $xmin = $x
if $x < $xmin;
2098 $xmax = $x
if $x > $xmax;
2100 my $ymin = shift @$y;
2103 $ymin = $y
if $y < $ymin;
2104 $ymax = $y
if $y > $ymax;
2111 #** @method list GCPs(@GCPs, Geo::OSR::SpatialReference sr)
2113 # Get or set the GCPs and their projection.
2114 # @param GCPs [optional] a list of Geo::GDAL::GCP objects
2115 # @param sr [optional] the projection of the GCPs.
2116 # @return a list of Geo::GDAL::GCP objects followed by a Geo::OSR::SpatialReference object.
2122 $proj = $proj->Export(
'WKT')
if $proj and ref($proj);
2123 SetGCPs($self, \@_, $proj);
2125 return unless defined wantarray;
2127 my $GCPs = GetGCPs($self);
2128 return (@$GCPs, $proj);
2131 #** @method Geo::GDAL::GeoTransform GeoTransform(Geo::GDAL::GeoTransform $geo_transform)
2133 # Transformation from cell coordinates (column,row) to projection
2136 # x = geo_transform[0] + column*geo_transform[1] + row*geo_transform[2]
2137 # y = geo_transform[3] + column*geo_transform[4] + row*geo_transform[5]
2139 # @param geo_transform [optional]
2140 # @return the geo transform in a non-void context.
2146 SetGeoTransform($self, $_[0]);
2148 SetGeoTransform($self, \@_);
2151 confess(last_error()) if $@;
2152 return unless defined wantarray;
2153 my $t = GetGeoTransform($self);
2161 #** @method GetDriver()
2166 #** @method list GetFileList()
2168 # @return list of files GDAL believes to be part of this dataset.
2173 #** @method scalar GetGCPProjection()
2175 # @return projection string.
2177 sub GetGCPProjection {
2180 #** @method Geo::OGR::Layer GetLayer($name)
2182 # @param name the name of the requested layer. If not given, then
2183 # returns the first layer in the data source.
2184 # @return a new Geo::OGR::Layer object that represents the layer
2185 # in the data source.
2188 my($self, $name) = @_;
2189 my $layer = defined $name ? GetLayerByName($self,
"$name") : GetLayerByIndex($self, 0);
2191 error(2, $name,
'Layer') unless $layer;
2192 keep($layer, $self);
2195 #** @method list GetLayerNames()
2197 # @note Delivers the functionality of undocumented method GetLayerCount.
2198 # @return a list of the names of the layers this data source provides.
2203 for my $i (0..$self->GetLayerCount-1) {
2204 my $layer = GetLayerByIndex($self, $i);
2205 push @names, $layer->GetName;
2210 #** @method GetNextFeature()
2212 sub GetNextFeature {
2215 #** @method GetStyleTable()
2220 #** @method Geo::GDAL::Dataset Grid($Dest, hashref Options)
2222 # Creates a regular raster grid from this data source.
2223 # This is equivalent to the gdal_grid utility.
2224 # @param Dest Destination raster dataset definition string (typically
2225 # filename) or an object, which implements write and close.
2226 # @param Options See section \ref index_processing_options.
2229 my ($self, $dest, $options, $progress, $progress_data) = @_;
2230 $options = Geo::GDAL::GDALGridOptions->new(make_processing_options($options));
2231 return $self->stdout_redirection_wrapper(
2233 \&Geo::GDAL::wrapper_GDALGrid,
2234 $options, $progress, $progress_data
2238 #** @method scalar Info(hashref Options)
2240 # Information about this dataset.
2241 # @param Options See section \ref index_processing_options.
2244 my ($self, $o) = @_;
2245 $o = Geo::GDAL::GDALInfoOptions->new(make_processing_options($o));
2246 return GDALInfo($self, $o);
2249 #** @method Geo::GDAL::Dataset Nearblack($Dest, hashref Options, coderef progress, $progress_data)
2251 # Convert nearly black/white pixels to black/white.
2252 # @param Dest Destination raster dataset definition string (typically
2253 # filename), destination dataset to which to add an alpha or mask
2254 # band, or an object, which implements write and close.
2255 # @param Options See section \ref index_processing_options.
2256 # @return Dataset if destination dataset definition string was given,
2257 # otherwise a boolean for success/fail but the method croaks if there
2261 my ($self, $dest, $options, $progress, $progress_data) = @_;
2262 $options = Geo::GDAL::GDALNearblackOptions->new(make_processing_options($options));
2263 my $b = blessed($dest);
2264 if ($b && $b eq
'Geo::GDAL::Dataset') {
2265 Geo::GDAL::wrapper_GDALNearblackDestDS($dest, $self, $options, $progress, $progress_data);
2267 return $self->stdout_redirection_wrapper(
2269 \&Geo::GDAL::wrapper_GDALNearblackDestName,
2270 $options, $progress, $progress_data
2275 #** @method Geo::GDAL::Dataset Open()
2276 # Package subroutine.
2277 # The same as Geo::GDAL::Open
2282 #** @method Geo::GDAL::Dataset OpenShared()
2283 # Package subroutine.
2284 # The same as Geo::GDAL::OpenShared
2289 #** @method RELEASE_PARENT()
2291 sub RELEASE_PARENT {
2296 #** @method Geo::GDAL::Dataset Rasterize($Dest, hashref Options, coderef progress, $progress_data)
2298 # Render data from this data source into a raster.
2299 # @param Dest Destination raster dataset definition string (typically
2300 # filename), destination dataset, or an object, which implements write and close.
2301 # @param Options See section \ref index_processing_options.
2302 # @return Dataset if destination dataset definition string was given,
2303 # otherwise a boolean for success/fail but the method croaks if there
2308 my ($self, $dest, $options, $progress, $progress_data) = @_;
2309 $options = Geo::GDAL::GDALRasterizeOptions->new(make_processing_options($options));
2310 my $b = blessed($dest);
2311 if ($b && $b eq
'Geo::GDAL::Dataset') {
2312 Geo::GDAL::wrapper_GDALRasterizeDestDS($dest, $self, $options, $progress, $progress_data);
2314 # TODO: options need to force a new raster be made, otherwise segfault
2315 return $self->stdout_redirection_wrapper(
2317 \&Geo::GDAL::wrapper_GDALRasterizeDestName,
2318 $options, $progress, $progress_data
2323 #** @method scalar ReadRaster(%params)
2325 # Read data from the dataset.
2327 # @param params Named parameters:
2328 # - \a XOff x offset (cell coordinates) (default is 0)
2329 # - \a YOff y offset (cell coordinates) (default is 0)
2330 # - \a XSize width of the area to read (default is the width of the dataset)
2331 # - \a YSize height of the area to read (default is the height of the dataset)
2332 # - \a BufXSize (default is undef, i.e., the same as XSize)
2333 # - \a BufYSize (default is undef, i.e., the same as YSize)
2334 # - \a BufType data type of the buffer (default is the data type of the first band)
2335 # - \a BandList a reference to an array of band indices (default is [1])
2336 # - \a BufPixelSpace (default is 0)
2337 # - \a BufLineSpace (default is 0)
2338 # - \a BufBandSpace (default is 0)
2339 # - \a ResampleAlg one of Geo::GDAL::RIOResamplingTypes (default is 'NearestNeighbour'),
2340 # - \a Progress reference to a progress function (default is undef)
2341 # - \a ProgressData (default is undef)
2343 # <a href="http://www.gdal.org/classGDALDataset.html">Entry in GDAL docs (method RasterIO)</a>
2344 # @return a buffer, open the buffer with \a unpack function of Perl. See Geo::GDAL::Band::PackCharacter.
2348 my ($width, $height) = $self->Size;
2349 my ($type) = $self->Band->DataType;
2350 my $p = named_parameters(\@_,
2362 ResampleAlg =>
'NearestNeighbour',
2364 ProgressData => undef
2366 $p->{resamplealg} = s2i(rio_resampling => $p->{resamplealg});
2367 $p->{buftype} = s2i(data_type => $p->{buftype}, 1);
2368 $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});
2371 #** @method ReadTile()
2374 my ($self, $xoff, $yoff, $xsize, $ysize, $w_tile, $h_tile, $alg) = @_;
2376 for my $i (0..$self->Bands-1) {
2377 $data[$i] = $self->Band($i+1)->ReadTile($xoff, $yoff, $xsize, $ysize, $w_tile, $h_tile, $alg);
2382 #** @method ReleaseResultSet($layer)
2384 # @param layer A layer the has been created with ExecuteSQL.
2385 # @note There is no need to call this method. The result set layer is
2386 # released in the destructor of the layer that was created with SQL.
2388 sub ReleaseResultSet {
2389 # a no-op, _ReleaseResultSet is called from Layer::DESTROY
2392 #** @method ResetReading()
2397 #** @method RollbackTransaction()
2399 sub RollbackTransaction {
2402 #** @method SetStyleTable()
2407 #** @method list Size()
2409 # @return (width, height)
2413 return ($self->{RasterXSize}, $self->{RasterYSize});
2416 #** @method Geo::OSR::SpatialReference SpatialReference(Geo::OSR::SpatialReference sr)
2418 # Get or set the projection of this dataset.
2419 # @param sr [optional] a Geo::OSR::SpatialReference object,
2420 # which replaces the existing projection definition of this dataset.
2421 # @return a Geo::OSR::SpatialReference object, which represents the
2422 # projection of this dataset.
2423 # @note Methods GetProjection, SetProjection, and Projection return WKT strings.
2425 sub SpatialReference {
2426 my($self, $sr) = @_;
2427 SetProjection($self, $sr->As(
'WKT'))
if defined $sr;
2428 if (defined wantarray) {
2429 my $p = GetProjection($self);
2435 #** @method StartTransaction()
2437 sub StartTransaction {
2440 #** @method TestCapability()
2442 sub TestCapability {
2443 return _TestCapability(@_);
2446 #** @method Tile(Geo::GDAL::Extent e)
2448 # Compute the top left cell coordinates and width and height of the
2449 # tile that covers the given extent.
2450 # @param e The extent whose tile is needed.
2451 # @note Requires that the raster is a strictly north up one.
2452 # @return A list ($xoff, $yoff, $xsize, $ysize).
2455 my ($self, $e) = @_;
2456 my ($w, $h) = $self->Size;
2457 my $t = $self->GeoTransform;
2458 confess
"GeoTransform is not \"north up\"." unless $t->NorthUp;
2459 my $xoff = floor(($e->[0] - $t->[0])/$t->[1]);
2460 $xoff = 0
if $xoff < 0;
2461 my $yoff = floor(($e->[1] - $t->[3])/$t->[5]);
2462 $yoff = 0
if $yoff < 0;
2463 my $xsize = ceil(($e->[2] - $t->[0])/$t->[1]) - $xoff;
2464 $xsize = $w - $xoff
if $xsize > $w - $xoff;
2465 my $ysize = ceil(($e->[3] - $t->[3])/$t->[5]) - $yoff;
2466 $ysize = $h - $yoff
if $ysize > $h - $yoff;
2467 return ($xoff, $yoff, $xsize, $ysize);
2470 #** @method Geo::GDAL::Dataset Translate($Dest, hashref Options, coderef progress, $progress_data)
2472 # Convert this dataset into another format.
2473 # @param Dest Destination dataset definition string (typically
2474 # filename) or an object, which implements write and close.
2475 # @param Options See section \ref index_processing_options.
2476 # @return New dataset object if destination dataset definition
2477 # string was given, otherwise a boolean for success/fail but the
2478 # method croaks if there was an error.
2481 my ($self, $dest, $options, $progress, $progress_data) = @_;
2482 return $self->stdout_redirection_wrapper(
2486 #** @method
Geo::GDAL::Dataset Warp($Dest, hashref Options, coderef progress, $progress_data)
2488 # Reproject
this dataset.
2489 # @param Dest Destination raster dataset definition string (typically
2490 # filename) or an
object, which implements write and close.
2491 # @param Options See section \ref index_processing_options.
2492 # @note This method can be run as a package subroutine with a list of
2493 # datasets as the first argument to mosaic several datasets.
2496 my ($self, $dest, $options, $progress, $progress_data) = @_;
2497 # can be run as object method (one dataset) and as package sub (a list of datasets)
2498 $options = Geo::GDAL::GDALWarpAppOptions->new(make_processing_options($options));
2499 my $b = blessed($dest);
2500 $self = [$self] unless ref $self eq
'ARRAY';
2501 if ($b && $b eq
'Geo::GDAL::Dataset') {
2502 Geo::GDAL::wrapper_GDALWarpDestDS($dest, $self, $options, $progress, $progress_data);
2504 return stdout_redirection_wrapper(
2507 \&Geo::GDAL::wrapper_GDALWarpDestName,
2508 $options, $progress, $progress_data
2513 #** @method Geo::GDAL::Dataset Warped(%params)
2515 # Create a virtual warped dataset from this dataset.
2517 # @param params Named parameters:
2518 # - \a SrcSRS Override the spatial reference system of this dataset if there is one (default is undef).
2519 # - \a DstSRS The target spatial reference system of the result (default is undef).
2520 # - \a ResampleAlg The resampling algorithm (default is 'NearestNeighbour').
2521 # - \a MaxError Maximum error measured in input cellsize that is allowed in approximating the transformation (default is 0 for exact calculations).
2523 # # <a href="http://www.gdal.org/gdalwarper_8h.html">Documentation for GDAL warper.</a>
2525 # @return a new Geo::GDAL::Dataset object
2529 my $p = named_parameters(\@_, SrcSRS => undef, DstSRS => undef, ResampleAlg =>
'NearestNeighbour', MaxError => 0);
2530 for my $srs (qw/srcsrs dstsrs/) {
2531 $p->{$srs} = $p->{$srs}->ExportToWkt
if $p->{$srs} && blessed $p->{$srs};
2533 $p->{resamplealg} = s2i(resampling => $p->{resamplealg});
2534 my $warped = Geo::GDAL::_AutoCreateWarpedVRT($self, $p->{srcsrs}, $p->{dstsrs}, $p->{resamplealg}, $p->{maxerror});
2535 keep($warped, $self) if $warped;
# self must live as long as warped
2538 #** @method WriteRaster(%params)
2540 # Write data into the dataset.
2542 # @param params Named parameters:
2543 # - \a XOff x offset (cell coordinates) (default is 0)
2544 # - \a YOff y offset (cell coordinates) (default is 0)
2545 # - \a XSize width of the area to write (default is the width of the dataset)
2546 # - \a YSize height of the area to write (default is the height of the dataset)
2547 # - \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.
2548 # - \a BufXSize (default is undef, i.e., the same as XSize)
2549 # - \a BufYSize (default is undef, i.e., the same as YSize)
2550 # - \a BufType data type of the buffer (default is the data type of the first band)
2551 # - \a BandList a reference to an array of band indices (default is [1])
2552 # - \a BufPixelSpace (default is 0)
2553 # - \a BufLineSpace (default is 0)
2554 # - \a BufBandSpace (default is 0)
2556 # <a href="http://www.gdal.org/classGDALDataset.html">Entry in GDAL docs (method RasterIO)</a>
2560 my ($width, $height) = $self->Size;
2561 my ($type) = $self->Band->DataType;
2562 my $p = named_parameters(\@_,
2576 $p->{buftype} = s2i(data_type => $p->{buftype}, 1);
2577 $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});
2580 #** @method WriteTile()
2583 my ($self, $data, $xoff, $yoff) = @_;
2586 for my $i (0..$self->Bands-1) {
2587 $self->Band($i+1)->WriteTile($data->[$i], $xoff, $yoff);
2591 #** @class Geo::GDAL::Driver
2592 # @brief A driver for a specific dataset format.
2595 package Geo::GDAL::Driver;
2599 #** @attr $HelpTopic
2600 # $driver->{HelpTopic}
2604 # $driver->{LongName}
2607 #** @attr $ShortName
2608 # $driver->{ShortName}
2611 #** @method list Capabilities()
2613 # @return A list of capabilities. When executed as a package subroutine
2614 # returns a list of all potential capabilities a driver may have. When
2615 # executed as an object method returns a list of all capabilities the
2618 # Currently capabilities are:
2619 # CREATE, CREATECOPY, DEFAULT_FIELDS, NOTNULL_FIELDS, NOTNULL_GEOMFIELDS, OPEN, RASTER, VECTOR, and VIRTUALIO.
2623 # @all_capabilities = Geo::GDAL::Driver::Capabilities;
2624 # @capabilities_of_the_geotiff_driver = Geo::GDAL::Driver('GTiff')->Capabilities;
2629 return @CAPABILITIES unless $self;
2630 my $h = $self->GetMetadata;
2632 for my $cap (@CAPABILITIES) {
2633 my $test = $h->{
'DCAP_'.uc($cap)};
2634 push @cap, $cap
if defined($test) and $test eq 'YES';
2639 #** @method Geo::GDAL::Dataset Copy(%params)
2641 # Create a new raster Geo::GDAL::Dataset as a copy of an existing dataset.
2642 # @note a.k.a. CreateCopy
2644 # @param params Named parameters:
2645 # - \a Name name for the new raster dataset.
2646 # - \a Src the source Geo::GDAL::Dataset object.
2647 # - \a Strict 1 (default) if the copy must be strictly equivalent, or 0 if the copy may adapt.
2648 # - \a Options an anonymous hash of driver specific options.
2649 # - \a Progress [optional] a reference to a subroutine, which will
2650 # be called with parameters (number progress, string msg, progress_data).
2651 # - \a ProgressData [optional]
2652 # @return a new Geo::GDAL::Dataset object.
2656 my $p = named_parameters(\@_, Name =>
'unnamed', Src => undef, Strict => 1, Options => {}, Progress => undef, ProgressData => undef);
2657 return $self->stdout_redirection_wrapper(
2659 $self->can(
'_CreateCopy'),
2660 $p->{src}, $p->{strict}, $p->{options}, $p->{progress}, $p->{progressdata});
2663 #** @method CopyFiles($NewName, $OldName)
2665 # Copy the files of a dataset.
2666 # @param NewName String.
2667 # @param OldName String.
2672 #** @method Geo::GDAL::Dataset Create(%params)
2674 # Create a raster dataset using this driver.
2675 # @note a.k.a. CreateDataset
2677 # @param params Named parameters:
2678 # - \a Name The name for the dataset (default is 'unnamed') or an object, which implements write and close.
2679 # - \a Width The width for the raster dataset (default is 256).
2680 # - \a Height The height for the raster dataset (default is 256).
2681 # - \a Bands The number of bands to create into the raster dataset (default is 1).
2682 # - \a Type The data type for the raster cells (default is 'Byte'). One of Geo::GDAL::Driver::CreationDataTypes.
2683 # - \a Options Driver creation options as a reference to a hash (default is {}).
2685 # @return A new Geo::GDAL::Dataset object.
2689 my $p = named_parameters(\@_, Name =>
'unnamed', Width => 256, Height => 256, Bands => 1, Type =>
'Byte', Options => {});
2690 my $type = s2i(data_type => $p->{type});
2691 return $self->stdout_redirection_wrapper(
2693 $self->can(
'_Create'),
2694 $p->{width}, $p->{height}, $p->{bands}, $type, $p->{options}
2698 #** @method list CreationDataTypes()
2700 # @return a list of data types that can be used for new datasets of this format. A subset of Geo::GDAL::DataTypes
2702 sub CreationDataTypes {
2704 my $h = $self->GetMetadata;
2705 return split /\s+/, $h->{DMD_CREATIONDATATYPES}
if $h->{DMD_CREATIONDATATYPES};
2708 #** @method list CreationOptionList()
2710 # @return a list of options, each option is a hashref, the keys are
2711 # name, type and description or Value. Value is a listref.
2713 sub CreationOptionList {
2716 my $h = $self->GetMetadata->{DMD_CREATIONOPTIONLIST};
2718 $h = ParseXMLString($h);
2719 my($type, $value) = NodeData($h);
2720 if ($value eq
'CreationOptionList') {
2721 for my $o (Children($h)) {
2723 for my $a (Children($o)) {
2724 my(undef, $key) = NodeData($a);
2725 my(undef, $value) = NodeData(Child($a, 0));
2726 if ($key eq
'Value') {
2727 push @{$option{$key}}, $value;
2729 $option{$key} = $value;
2732 push @options, \%option;
2739 #** @method Delete($name)
2746 #** @method Domains()
2752 #** @method scalar Extension()
2754 # @note The returned extension does not contain a '.' prefix.
2755 # @return a suggested single extension or a list of extensions (in
2756 # list context) for datasets.
2760 my $h = $self->GetMetadata;
2762 my $e = $h->{DMD_EXTENSIONS};
2763 my @e = split / /, $e;
2765 for my $i (0..$#e) {
2770 my $e = $h->{DMD_EXTENSION};
2771 return '' if $e =~ /\
2777 #** @method scalar MIMEType()
2779 # @return a suggested MIME type for datasets.
2783 my $h = $self->GetMetadata;
2784 return $h->{DMD_MIMETYPE};
2787 #** @method scalar Name()
2789 # @return The short name of the driver.
2793 return $self->{ShortName};
2798 # The same as Geo::GDAL::Open except that only this driver is allowed.
2802 my @p = @_; # name, update
2803 my @flags = qw/RASTER/;
2804 push @flags, qw/READONLY/
if $p[1] eq
'ReadOnly';
2805 push @flags, qw/UPDATE/
if $p[1] eq
'Update';
2806 my $dataset = OpenEx($p[0], \@flags, [$self->Name()]);
2807 error(
"Failed to open $p[0]. Is it a raster dataset?") unless $dataset;
2811 #** @method Rename($NewName, $OldName)
2813 # Rename (move) a GDAL dataset.
2814 # @param NewName String.
2815 # @param OldName String.
2820 #** @method scalar TestCapability($cap)
2822 # Test whether the driver has the specified capability.
2823 # @param cap A capability string (one of those returned by Capabilities).
2824 # @return a boolean value.
2826 sub TestCapability {
2827 my($self, $cap) = @_;
2828 my $h = $self->GetMetadata->{
'DCAP_'.uc($cap)};
2829 return (defined($h) and $h eq
'YES') ? 1 : undef;
2832 #** @method stdout_redirection_wrapper()
2834 sub stdout_redirection_wrapper {
2835 my ($self, $name, $sub, @params) = @_;
2837 if ($name && blessed $name) {
2839 my $ref = $object->can(
'write');
2840 VSIStdoutSetRedirection($ref);
2841 $name =
'/vsistdout/';
2845 $ds = $sub->($self, $name, @params);
2849 $Geo::GDAL::stdout_redirection{tied(%$ds)} = $object;
2851 VSIStdoutUnsetRedirection();
2855 confess(last_error()) if $@;
2856 confess("Failed. Use Geo::OGR::Driver for vector drivers.") unless $ds;
2860 #** @class Geo::GDAL::Extent
2861 # @brief A rectangular area in projection coordinates: xmin, ymin, xmax, ymax.
2863 package Geo::GDAL::Extent;
2865 #** @method ExpandToInclude($extent)
2866 # Package subroutine.
2867 # Extends this extent to include the other extent.
2868 # @param extent Another Geo::GDAL::Extent object.
2870 sub ExpandToInclude {
2871 my ($self, $e) = @_;
2872 return if $e->IsEmpty;
2873 if ($self->IsEmpty) {
2876 $self->[0] = $e->[0]
if $e->[0] < $self->[0];
2877 $self->[1] = $e->[1]
if $e->[1] < $self->[1];
2878 $self->[2] = $e->[2]
if $e->[2] > $self->[2];
2879 $self->[3] = $e->[3]
if $e->[3] > $self->[3];
2883 #** @method IsEmpty()
2887 return $self->[2] < $self->[0];
2890 #** @method scalar Overlap($extent)
2891 # Package subroutine.
2892 # @param extent Another Geo::GDAL::Extent object.
2893 # @return A new, possibly empty, Geo::GDAL::Extent object, which
2894 # represents the joint area of the two extents.
2897 my ($self, $e) = @_;
2900 $ret->[0] = $e->[0]
if $self->[0] < $e->[0];
2901 $ret->[1] = $e->[1]
if $self->[1] < $e->[1];
2902 $ret->[2] = $e->[2]
if $self->[2] > $e->[2];
2903 $ret->[3] = $e->[3]
if $self->[3] > $e->[3];
2907 #** @method scalar Overlaps($extent)
2908 # Package subroutine.
2909 # @param extent Another Geo::GDAL::Extent object.
2910 # @return True if this extent overlaps the other extent, false otherwise.
2913 my ($self, $e) = @_;
2914 return $self->[0] < $e->[2] && $self->[2] > $e->[0] && $self->[1] < $e->[3] && $self->[3] > $e->[1];
2917 #** @method list Size()
2918 # Package subroutine.
2919 # @return A list ($width, $height).
2923 return (0,0)
if $self->
IsEmpty;
2924 return ($self->[2] - $self->[0], $self->[3] - $self->[1]);
2927 #** @method Geo::GDAL::Extent new(@params)
2928 # Package subroutine.
2929 # @param params nothing, a list ($xmin, $ymin, $xmax, $ymax), or an Extent object
2930 # @return A new Extent object (empty if no parameters, a copy of the parameter if it is an Extent object).
2937 } elsif (ref $_[0]) {
2942 bless $self, $class;
2946 #** @class Geo::GDAL::GCP
2947 # @brief A ground control point for georeferencing rasters.
2950 package Geo::GDAL::GCP;
2955 # cell x coordinate (access as $gcp->{Column})
2959 # unique identifier (string) (access as $gcp->{Id})
2963 # informational message (access as $gcp->{Info})
2967 # cell y coordinate (access as $gcp->{Row})
2971 # projection coordinate (access as $gcp->{X})
2975 # projection coordinate (access as $gcp->{Y})
2979 # projection coordinate (access as $gcp->{Z})
2982 #** @method scalar new($x = 0.0, $y = 0.0, $z = 0.0, $column = 0.0, $row = 0.0, $info = "", $id = "")
2984 # @param x projection coordinate
2985 # @param y projection coordinate
2986 # @param z projection coordinate
2987 # @param column cell x coordinate
2988 # @param row cell y coordinate
2989 # @param info informational message
2990 # @param id unique identifier (string)
2991 # @return a new Geo::GDAL::GCP object
2995 my $self = Geo::GDALc::new_GCP(@_);
2996 bless $self, $pkg
if defined($self);
2999 #** @class Geo::GDAL::GeoTransform
3000 # @brief An array of affine transformation coefficients.
3001 # @details The geo transformation has the form
3003 # x = a + column * b + row * c
3004 # y = d + column * e + row * f
3007 # (column,row) is the location in cell coordinates, and
3008 # (x,y) is the location in projection coordinates, or vice versa.
3009 # A Geo::GDAL::GeoTransform object is a reference to an anonymous array [a,b,c,d,e,f].
3011 package Geo::GDAL::GeoTransform;
3013 #** @method Apply($x, $y)
3015 # @param x Column or x, or a reference to an array of columns or x's
3016 # @param y Row or y, or a reference to an array of rows or y's
3017 # @return a list (x, y), where x and y are the transformed coordinates
3018 # or references to arrays of transformed coordinates.
3021 my ($self, $columns, $rows) = @_;
3022 return Geo::GDAL::ApplyGeoTransform($self, $columns, $rows) unless ref($columns) eq 'ARRAY';
3024 for my $i (0..$
#$columns) {
3026 Geo::GDAL::ApplyGeoTransform($self, $columns->[$i], $rows->[$i]);
3033 # @return a new Geo::GDAL::GeoTransform object, which is the inverse
3034 # of this one (in void context changes this object).
3038 my @inv = Geo::GDAL::InvGeoTransform($self);
3043 #** @method NorthUp()
3047 return $self->[2] == 0 && $self->[4] == 0;
3050 #** @method new(@params)
3052 # @param params nothing, a reference to an array [a,b,c,d,e,f], a list
3053 # (a,b,c,d,e,f), or named parameters
3054 # - \a GCPs A reference to an array of Geo::GDAL::GCP objects.
3055 # - \a ApproxOK Minimize the error in the coefficients (integer, default is 1 (true), used with GCPs).
3056 # - \a Extent A Geo::GDAL::Extent object used to obtain the coordinates of the up left corner position.
3057 # - \a CellSize The cell size (width and height) (default is 1, used with Extent).
3059 # @note When Extent is specifid, the created geo transform will be
3060 # north up, have square cells, and coefficient f will be -1 times the
3061 # cell size (image y - row - will increase downwards and projection y
3062 # will increase upwards).
3063 # @return a new Geo::GDAL::GeoTransform object.
3069 $self = [0,1,0,0,0,1];
3070 } elsif (ref $_[0]) {
3072 } elsif ($_[0] =~ /^[a-zA-Z]/i) {
3073 my $p = named_parameters(\@_, GCPs => undef, ApproxOK => 1,
Extent => undef, CellSize => 1);
3075 $self = Geo::GDAL::GCPsToGeoTransform($p->{gcps}, $p->{approxok});
3076 } elsif ($p->{extent}) {
3079 error(
"Missing GCPs or Extent");
3085 bless $self, $class;
3088 #** @class Geo::GDAL::MajorObject
3089 # @brief An object, which holds meta data.
3092 package Geo::GDAL::MajorObject;
3096 #** @method scalar Description($description)
3098 # @param description [optional]
3099 # @return the description in a non-void context.
3102 my($self, $desc) = @_;
3103 SetDescription($self, $desc) if defined $desc;
3104 GetDescription($self) if defined wantarray;
3107 #** @method Domains()
3108 # Package subroutine.
3109 # @return the class specific DOMAINS list
3115 #** @method scalar GetDescription()
3119 sub GetDescription {
3122 #** @method hash reference GetMetadata($domain = "")
3124 # @note see Metadata
3131 #** @method GetMetadataDomainList()
3133 sub GetMetadataDomainList {
3136 #** @method hash reference Metadata(hashref metadata = undef, $domain = '')
3140 # @return the metadata in a non-void context.
3144 my $metadata = ref $_[0] ? shift : undef;
3146 SetMetadata($self, $metadata, $domain) if defined $metadata;
3147 GetMetadata($self, $domain) if defined wantarray;
3150 #** @method SetDescription($NewDesc)
3155 sub SetDescription {
3158 #** @method SetMetadata(hashref metadata, $domain = "")
3160 # @note see Metadata
3168 #** @class Geo::GDAL::RasterAttributeTable
3169 # @brief An attribute table in a raster band.
3172 package Geo::GDAL::RasterAttributeTable;
3183 #** @method ChangesAreWrittenToFile()
3185 sub ChangesAreWrittenToFile {
3188 #** @method Geo::GDAL::RasterAttributeTable Clone()
3190 # @return a new Geo::GDAL::RasterAttributeTable object
3195 #** @method hash Columns(%columns)
3197 # A get/set method for the columns of the RAT
3198 # @param columns optional, a the keys are column names and the values are anonymous
3199 # hashes with keys Type and Usage
3200 # @return a hash similar to the optional input parameter
3205 if (@_) { # create columns
3207 for my $name (keys %columns) {
3208 $self->CreateColumn($name, $columns{$name}{Type}, $columns{$name}{Usage});
3212 for my $c (0..$self->GetColumnCount-1) {
3213 my $name = $self->GetNameOfCol($c);
3214 $columns{$name}{Type} = $self->GetTypeOfCol($c);
3215 $columns{$name}{Usage} = $self->GetUsageOfCol($c);
3220 #** @method CreateColumn($name, $type, $usage)
3223 # @param type one of FieldTypes
3224 # @param usage one of FieldUsages
3227 my($self, $name, $type, $usage) = @_;
3228 for my $color (qw/Red Green Blue Alpha/) {
3229 carp
"RAT column type will be 'Integer' for usage '$color'." if $usage eq $color and $type ne
'Integer';
3231 $type = s2i(rat_field_type => $type);
3232 $usage = s2i(rat_field_usage => $usage);
3233 _CreateColumn($self, $name, $type, $usage);
3236 #** @method DumpReadable()
3241 #** @method list FieldTypes()
3242 # Package subroutine.
3246 return @FIELD_TYPES;
3249 #** @method list FieldUsages()
3250 # Package subroutine.
3254 return @FIELD_USAGES;
3257 #** @method scalar GetColOfUsage($usage)
3263 my($self, $usage) = @_;
3264 _GetColOfUsage($self, s2i(rat_field_usage => $usage));
3267 #** @method scalar GetColumnCount()
3271 sub GetColumnCount {
3274 #** @method scalar GetNameOfCol($column)
3282 #** @method scalar GetRowCount()
3288 #** @method scalar GetRowOfValue($value)
3290 # @param value a cell value
3291 # @return row index or -1
3296 #** @method scalar GetTypeOfCol($column)
3302 my($self, $col) = @_;
3303 i2s(rat_field_type => _GetTypeOfCol($self, $col));
3306 #** @method scalar GetUsageOfCol($column)
3312 my($self, $col) = @_;
3313 i2s(rat_field_usage => _GetUsageOfCol($self, $col));
3316 #** @method scalar GetValueAsDouble($row, $column)
3322 sub GetValueAsDouble {
3325 #** @method scalar GetValueAsInt($row, $column)
3334 #** @method scalar GetValueAsString($row, $column)
3340 sub GetValueAsString {
3343 #** @method LinearBinning($Row0MinIn, $BinSizeIn)
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.
3351 SetLinearBinning($self, @_) if @_ > 0;
3352 return unless defined wantarray;
3353 my @a = GetLinearBinning($self);
3354 return $a[0] ? ($a[1], $a[2]) : ();
3357 #** @method RELEASE_PARENT()
3359 sub RELEASE_PARENT {
3364 #** @method SetRowCount($count)
3372 #** @method SetValueAsDouble($row, $column, $value)
3379 sub SetValueAsDouble {
3382 #** @method SetValueAsInt($row, $column, $value)
3392 #** @method SetValueAsString($row, $column, $value)
3399 sub SetValueAsString {
3402 #** @method scalar Value($row, $column, $value)
3406 # @param value [optional]
3410 my($self, $row, $column) = @_;
3411 SetValueAsString($self, $row, $column, $_[3]) if defined $_[3];
3412 return unless defined wantarray;
3413 GetValueAsString($self, $row, $column);
3416 #** @method Geo::GDAL::RasterAttributeTable new()
3418 # @return a new Geo::GDAL::RasterAttributeTable object
3422 my $self = Geo::GDALc::new_RasterAttributeTable(@_);
3423 bless $self, $pkg
if defined($self);
3426 #** @class Geo::GDAL::Transformer
3428 # @details This class is not yet documented for the GDAL Perl bindings.
3429 # @todo Test and document.
3431 package Geo::GDAL::Transformer;
3435 #** @method TransformGeolocations()
3437 sub TransformGeolocations {
3440 #** @method TransformPoint()
3442 sub TransformPoint {
3449 my $self = Geo::GDALc::new_Transformer(@_);
3450 bless $self, $pkg
if defined($self);
3453 #** @class Geo::GDAL::VSIF
3454 # @brief A GDAL virtual file system.
3457 package Geo::GDAL::VSIF;
3459 use base qw(
our Exporter)
3465 my ($self, $data) = @_;
3466 Geo::GDAL::VSIFCloseL($self);
3469 #** @method MkDir($path)
3470 # Package subroutine.
3472 # @param path The directory to make.
3473 # @note The name of this method is VSIMkdir in GDAL.
3477 # mode unused in CPL
3478 Geo::GDAL::Mkdir($path, 0);
3481 #** @method Geo::GDAL::VSIF Open($filename, $mode)
3482 # Package subroutine.
3483 # @param filename Name of the file to open. For example "/vsimem/x".
3484 # @param mode Access mode. 'r', 'r+', 'w', etc.
3485 # @return A file handle on success.
3488 my ($path, $mode) = @_;
3489 my $self = Geo::GDAL::VSIFOpenL($path, $mode);
3490 bless $self,
'Geo::GDAL::VSIF';
3493 #** @method scalar Read($count)
3495 # @param count The number of bytes to read from the file.
3496 # @return A byte string.
3499 my ($self, $count) = @_;
3500 Geo::GDAL::VSIFReadL($count, $self);
3503 #** @method list ReadDir($dir)
3504 # Package subroutine.
3505 # @return Contents of a directory in an anonymous array or as a list.
3509 Geo::GDAL::ReadDir($path);
3512 #** @method scalar ReadDirRecursive($dir)
3513 # Package subroutine.
3514 # @note Give the directory in the form '/vsimem', i.e., without trailing '/'.
3515 # @return Contents of a directory tree in an anonymous array.
3517 sub ReadDirRecursive {
3519 Geo::GDAL::ReadDirRecursive($path);
3522 #** @method Rename($old, $new)
3523 # Package subroutine.
3525 # @note The name of this method is VSIRename in GDAL.
3528 my ($old, $new) = @_;
3529 Geo::GDAL::Rename($old, $new);
3532 #** @method RmDir($path)
3533 # Package subroutine.
3534 # Remove a directory.
3535 # @note The name of this method is VSIRmdir in GDAL.
3538 my ($dirname, $recursive) = @_;
3541 Geo::GDAL::Rmdir($dirname);
3543 for my $f (ReadDir($dirname)) {
3544 next
if $f eq
'..' or $f eq
'.';
3545 my @s = Stat($dirname.
'/'.$f);
3547 Unlink($dirname.
'/'.$f);
3548 } elsif ($s[0] eq
'd') {
3549 Rmdir($dirname.
'/'.$f, 1);
3550 Rmdir($dirname.
'/'.$f);
3557 my $r = $recursive ?
' recursively' :
'';
3558 error(
"Cannot remove directory \"$dirname\"$r.");
3562 #** @method Seek($offset, $whence)
3566 my ($self, $offset, $whence) = @_;
3567 Geo::GDAL::VSIFSeekL($self, $offset, $whence);
3570 #** @method list Stat($filename)
3571 # Package subroutine.
3572 # @return ($filemode, $filesize). filemode is f for a plain file, d
3573 # for a directory, l for a symbolic link, p for a named pipe (FIFO), S
3574 # for a socket, b for a block special file, and c for a character
3579 Geo::GDAL::Stat($path);
3582 #** @method scalar Tell()
3587 Geo::GDAL::VSIFTellL($self);
3590 #** @method Truncate($new_size)
3594 my ($self, $new_size) = @_;
3595 Geo::GDAL::VSIFTruncateL($self, $new_size);
3598 #** @method Unlink($filename)
3599 # Package subroutine.
3600 # @param filename The file to delete.
3601 # @return 0 on success and -1 on an error.
3604 my ($filename) = @_;
3605 Geo::GDAL::Unlink($filename);
3608 #** @method Write($scalar)
3610 # @param scalar The byte string to write to the file.
3611 # @return Number of bytes written into the file.
3614 my ($self, $data) = @_;
3615 Geo::GDAL::VSIFWriteL($data, $self);
3618 #** @class Geo::GDAL::XML
3619 # @brief A simple XML parser
3622 package Geo::GDAL::XML;
3624 #** @method new($string)
3626 # @param string String containing XML.
3627 # @return A new Geo::GDAL::XML object, which is a reference to an anonymous array.
3632 my $self = ParseXMLString($xml);
3633 bless $self, $class;
3634 $self->traverse(sub {my $node = shift; bless $node, $class});
3638 #** @method serialize()
3640 # @return The XML serialized into a string.
3644 return SerializeXMLTree($self);
3647 # This file was automatically generated by SWIG (http://www.swig.org).
3650 # Do not make changes to this file unless you know what you are doing--modify
3651 # the SWIG interface file instead.
3654 #** @method traverse(coderef subroutine)
3656 # @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.
3659 my ($self, $sub) = @_;
3660 my $type = $self->[0];
3661 my $data = $self->[1];
3662 $type = NodeType($type);
3663 $sub->($self, $type, $data);
3664 for my $child (@{$self}[2..$#$self]) {
3665 traverse($child, $sub);
3670 # @brief Base class for geographical networks in GDAL.
3675 #** @method CastToGenericNetwork()
3677 sub CastToGenericNetwork {
3680 #** @method CastToNetwork()
3685 #** @method GATConnectedComponents()
3687 sub GATConnectedComponents {
3690 #** @method GATDijkstraShortestPath()
3692 sub GATDijkstraShortestPath {
3695 #** @method GATKShortestPath()
3697 sub GATKShortestPath {
3700 #** @method GNM_EDGE_DIR_BOTH()
3702 sub GNM_EDGE_DIR_BOTH {
3705 #** @method GNM_EDGE_DIR_SRCTOTGT()
3707 sub GNM_EDGE_DIR_SRCTOTGT {
3710 #** @method GNM_EDGE_DIR_TGTTOSRC()
3712 sub GNM_EDGE_DIR_TGTTOSRC {
3716 #** @class Geo::GNM::GenericNetwork
3719 package Geo::GNM::GenericNetwork;
3723 #** @method ChangeAllBlockState()
3725 sub ChangeAllBlockState {
3728 #** @method ChangeBlockState()
3730 sub ChangeBlockState {
3733 #** @method ConnectFeatures()
3735 sub ConnectFeatures {
3738 #** @method ConnectPointsByLines()
3740 sub ConnectPointsByLines {
3743 #** @method CreateRule()
3748 #** @method DeleteAllRules()
3750 sub DeleteAllRules {
3753 #** @method DeleteRule()
3758 #** @method DisconnectFeatures()
3760 sub DisconnectFeatures {
3763 #** @method DisconnectFeaturesWithId()
3765 sub DisconnectFeaturesWithId {
3768 #** @method GetRules()
3773 #** @method ReconnectFeatures()
3775 sub ReconnectFeatures {
3778 #** @class Geo::GNM::MajorObject
3781 package Geo::GNM::MajorObject;
3783 #** @class Geo::GNM::Network
3786 package Geo::GNM::Network;
3790 #** @method CommitTransaction()
3792 sub CommitTransaction {
3795 #** @method CopyLayer()
3800 #** @method DisconnectAll()
3805 #** @method GetFeatureByGlobalFID()
3807 sub GetFeatureByGlobalFID {
3810 #** @method GetFileList()
3815 #** @method GetLayerByIndex()
3817 sub GetLayerByIndex {
3820 #** @method GetLayerByName()
3822 sub GetLayerByName {
3825 #** @method GetLayerCount()
3830 #** @method GetName()
3835 #** @method GetPath()
3840 #** @method GetProjection()
3845 #** @method GetProjectionRef()
3847 sub GetProjectionRef {
3850 #** @method GetVersion()
3855 #** @method RollbackTransaction()
3857 sub RollbackTransaction {
3860 #** @method StartTransaction()
3862 sub StartTransaction {
3866 # @brief OGR utility functions.
3867 # @details A wrapper for many OGR utility functions and a root class for all
3872 #** @method list ByteOrders()
3873 # Package subroutine.
3874 # @return a list of byte order types, XDR and NDR. XDR denotes
3875 # big-endian and NDR denotes little-endian.
3880 #** @method Geo::GDAL::Driver Driver($name)
3881 # Package subroutine.
3883 # @param name the short name of the driver.
3884 # @note No check is made that the driver is actually a vector driver.
3885 # @return a Geo::GDAL::Driver object.
3888 return 'Geo::GDAL::Driver' unless @_;
3892 #** @method list DriverNames()
3893 # Package subroutine.
3894 # A.k.a GetDriverNames
3896 # perl -MGeo::GDAL -e '@d=Geo::OGR::DriverNames;print "@d\n"'
3898 # @note Use Geo::GDAL::DriverNames for raster drivers.
3899 # @return a list of the short names of all available GDAL vector drivers.
3904 #** @method list Drivers()
3905 # Package subroutine.
3906 # @note Use Geo::GDAL::Drivers for raster drivers.
3907 # @return a list of all available GDAL vector drivers.
3911 for my $i (0..GetDriverCount()-1) {
3912 my $driver = Geo::GDAL::GetDriver($i);
3913 push @drivers, $driver
if $driver->TestCapability(
'VECTOR');
3918 #** @method Flatten()
3923 #** @method scalar GeometryTypeModify($type, $modifier)
3925 # @param type a geometry type (one of Geo::OGR::GeometryTypes).
3926 # @param modifier one of 'flatten', 'set_Z', 'make_collection', 'make_curve', or 'make_linear'.
3927 # @return modified geometry type.
3929 sub GeometryTypeModify {
3930 my($type, $modifier) = @_;
3931 $type = s2i(geometry_type => $type);
3932 return i2s(geometry_type => GT_Flatten($type)) if $modifier =~ /flat/i;
3933 return i2s(geometry_type => GT_SetZ($type)) if $modifier =~ /z/i;
3934 return i2s(geometry_type => GT_GetCollection($type)) if $modifier =~ /collection/i;
3935 return i2s(geometry_type => GT_GetCurve($type)) if $modifier =~ /curve/i;
3936 return i2s(geometry_type => GT_GetLinear($type)) if $modifier =~ /linear/i;
3937 error(1, $modifier, {Flatten => 1, SetZ => 1, GetCollection => 1, GetCurve => 1, GetLinear => 1});
3940 #** @method scalar GeometryTypeTest($type, $test, $type2)
3942 # @param type a geometry type (one of Geo::OGR::GeometryTypes).
3943 # @param test one of 'has_z', 'is_subclass_of', 'is_curve', 'is_surface', or 'is_non_linear'.
3944 # @param type2 a geometry type (one of Geo::OGR::GeometryTypes). Required for 'is_subclass_of' test.
3945 # @return result of the test.
3947 sub GeometryTypeTest {
3948 my($type, $test, $type2) = @_;
3949 $type = s2i(geometry_type => $type);
3950 if (defined $type2) {
3951 $type = s2i(geometry_type => $type);
3953 error(
"Usage: GeometryTypeTest(type1, 'is_subclass_of', type2).") if $test =~ /subclass/i;
3955 return GT_HasZ($type) if $test =~ /z/i;
3956 return GT_IsSubClassOf($type, $type2) if $test =~ /subclass/i;
3957 return GT_IsCurve($type) if $test =~ /curve/i;
3958 return GT_IsSurface($type) if $test =~ /surface/i;
3959 return GT_IsNonLinear($type) if $test =~ /linear/i;
3960 error(1, $test, {HasZ => 1, IsSubClassOf => 1, IsCurve => 1, IsSurface => 1, IsNonLinear => 1});
3963 #** @method list GeometryTypes()
3964 # Package subroutine.
3965 # @return a list of all geometry types, currently:
3966 # 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.
3970 # This file was automatically generated by SWIG (http://www.swig.org).
3973 # Do not make changes to this file unless you know what you are doing--modify
3974 # the SWIG interface file instead.
3977 #** @method GetNonLinearGeometriesEnabledFlag()
3979 sub GetNonLinearGeometriesEnabledFlag {
3982 #** @method GetOpenDSCount()
3984 sub GetOpenDSCount {
3997 #** @method Geo::GDAL::Dataset Open($name, $update = 0)
3999 # Open a vector data source.
4000 # @param name The data source string (directory, filename, etc.).
4001 # @param update Whether to open the data source in update mode (default is not).
4002 # @return a new Geo::GDAL::Dataset object.
4005 my @p = @_; # name, update
4006 my @flags = qw/VECTOR/;
4007 push @flags, qw/UPDATE/
if $p[1];
4009 error(
"Failed to open $p[0]. Is it a vector dataset?") unless $dataset;
4013 #** @method Geo::GDAL::Dataset OpenShared($name, $update = 0)
4015 # Open a vector data source in shared mode.
4016 # @param name The data source string (directory, filename, etc.).
4017 # @param update Whether to open the data source in update mode.
4018 # @return a new Geo::GDAL::Dataset object.
4021 my @p = @_; # name, update
4022 my @flags = qw/VECTOR SHARED/;
4023 push @flags, qw/UPDATE/
if $p[1];
4025 error(
"Failed to open $p[0]. Is it a vector dataset?") unless $dataset;
4029 #** @method RELEASE_PARENT()
4031 sub RELEASE_PARENT {
4034 #** @method SetGenerate_DB2_V72_BYTE_ORDER($Generate_DB2_V72_BYTE_ORDER)
4036 # Needed only on IBM DB2.
4038 sub SetGenerate_DB2_V72_BYTE_ORDER {
4041 #** @method SetNonLinearGeometriesEnabledFlag()
4043 sub SetNonLinearGeometriesEnabledFlag {
4046 #** @class Geo::OGR::DataSource
4047 # @brief A vector dataset.
4048 # @details This is a legacy class which should not be
4049 # used in new code. Use Geo::GDAL::Dataset.
4051 package Geo::OGR::DataSource;
4053 #** @method Geo::GDAL::Dataset Open()
4054 # Package subroutine.
4055 # The same as Geo::OGR::Open
4060 #** @method Geo::GDAL::Dataset OpenShared()
4061 # Package subroutine.
4062 # The same as Geo::OGR::OpenShared
4067 #** @class Geo::OGR::Driver
4068 # @brief A vector format driver.
4069 # @details This is a legacy class which
4070 # should not be used in new code. Use Geo::GDAL::Driver.
4072 package Geo::OGR::Driver;
4076 #** @method Geo::GDAL::Dataset Copy(Geo::GDAL::Dataset source, $name, arrayref options = undef)
4078 # Copy a vector data source into a new data source with this driver.
4079 # @param source The Geo::GDAL::Dataset object to be copied.
4080 # @param name The name for the new data source.
4081 # @param options Driver specific options. In addition to options
4082 # specified in GDAL documentation the option STRICT can be set to 'NO'
4083 # for a more relaxed copy. Otherwise the STRICT is 'YES'.
4084 # @note The order of the first two parameters is different from that in Geo::GDAL::Driver::Copy.
4085 # @return a new Geo::GDAL::Dataset object.
4088 my ($self, @p) = @_; # src, name, options
4089 my $strict = 1; # the
default in bindings
4090 $strict = 0
if $p[2] && $p[2]->{STRICT} eq
'NO';
4091 $self->SUPER::Copy($p[1], $p[0], $strict, @{$p[2..4]}); # path, src, strict, options, cb, cb_data
4094 #** @method Geo::GDAL::Dataset Create($name, hashref options = undef )
4096 # Create a new vector data source using this driver.
4097 # @param name The data source name.
4098 # @param options Driver specific dataset creation options.
4101 my ($self, $name, $options) = @_; # name, options
4103 $self->SUPER::Create(Name => $name, Width => 0, Height => 0, Bands => 0, Type =>
'Byte', Options => $options);
4108 # The same as Geo::OGR::Open except that only this driver is allowed.
4112 my @p = @_; # name, update
4113 my @flags = qw/VECTOR/;
4114 push @flags, qw/UPDATE/
if $p[1];
4116 error(
"Failed to open $p[0]. Is it a vector dataset?") unless $dataset;
4120 #** @class Geo::OGR::Feature
4121 # @brief A collection of non-spatial and spatial attributes.
4122 # @details A feature is a collection of non-spatial and spatial attributes and
4123 # an id, which is a special attribute, and data records according to
4124 # this data model. Attributes are called fields and some fields are
4125 # spatial, i.e., their value is a geometry. Fields have at least a
4126 # name and a type. Features may exist within a layer or
4127 # separetely. The data model of a feature is a definition object.
4129 package Geo::OGR::Feature;
4133 #** @method Geo::OGR::Feature Clone()
4135 # @return a new Geo::OGR::Feature object
4140 #** @method DumpReadable()
4142 # Write the contents of this feature to stdout.
4147 #** @method scalar Equal($feature)
4149 # @param feature a Geo::OGR::Feature object for comparison
4155 #** @method scalar FID($id)
4157 # @brief Get or set the id of this feature.
4158 # @param id [optional] the id to set for this feature.
4159 # @return integer the id of this feature.
4163 $self->SetFID($_[0])
if @_;
4164 return unless defined wantarray;
4168 #** @method Field($name, $value, ...)
4170 # @brief Get, set, or unset the field value.
4171 # @param name the name (or the index) of the field.
4172 # @param value a scalar, a list of scalars or a reference to a
4173 # list. If undef, the field is unset. If a scalar or a list of
4174 # scalars, the field is set from them.
4175 # @note Non-scalar fields (for example Date) can be set either from a
4176 # scalar, which is then assumed to be a string and parsed, or from a
4177 # list of values (for example year, month, day for Date).
4178 # @note Setting and getting Integer64 fields requires 'use bigint' if
4179 # \$Config{ivsize} is smaller than 8, i.e., in a 32 bit machine.
4180 # @return in non-void context the value of the field, which may be a
4181 # scalar or a list, depending on the field type. For unset fields the
4182 # undef value is returned.
4186 my $field = $self->GetFieldIndex(shift
4187 $self->SetField($field, @_)
if @_;
4188 $self->GetField($field)
if defined wantarray;
4191 #** @method FillUnsetWithDefault()
4193 sub FillUnsetWithDefault {
4196 #** @method Geometry($name, $geometry)
4198 # @brief Get or set the value of a geometry field.
4199 # @note This method delivers the functionality of undocumented methods
4200 # SetGeometry($geometry), SetGeometryDirectly, SetGeomField,
4201 # SetGeomFieldDirectly, GetGeometry, GetGeometryRef.
4203 # Set or get the geometry in the feature. When setting, does a check
4204 # against the schema (GeometryType) of the feature. If the parameter
4205 # is a geometry object, it is cloned.
4206 # @param name [optional] the name of the spatial field,
4207 # whose geometry is to be set. If not given, sets or gets the geometry
4208 # of the first (or the single) spatial field.
4209 # @param geometry [optional] a Geo::OGR::Geometry object or a
4210 # reference to a hash from which such can be created (using
4211 # Geo::OGR::Geometry::new).
4212 # @return in a non-void context the indicated geometry in the feature
4213 # as a Geo::OGR::Geometry object. The returned object contains a
4214 # reference to the actual geometry data in the feature (the geometry
4215 # is not cloned) and to the feature object, thus keeping the feature
4216 # object from being destroyed while the geometry object exists.
4220 my $field = ((@_ > 0 and ref($_[0]) eq '') or (@_ > 2 and @_ % 2 == 1)) ? shift : 0;
4221 $field = $self->GetGeomFieldIndex($field);
4223 if (@_ and @_ % 2 == 0) {
4229 my $type = $self->GetDefn->GetGeomFieldDefn($field)->Type;
4230 if (blessed($geometry) and $geometry->isa(
'Geo::OGR::Geometry')) {
4231 my $gtype = $geometry->GeometryType;
4232 error(
"The type of the inserted geometry ('$gtype') is not the same as the type of the field ('$type').")
4233 if $type ne 'Unknown' and $type ne $gtype;
4235 $self->SetGeomFieldDirectly($field, $geometry->Clone);
4237 confess last_error() if $@;
4238 } elsif (ref($geometry) eq 'HASH') {
4239 $geometry->{GeometryType}
4244 error(
"The type of the inserted geometry ('$gtype') is not the same as the type of the field ('$type').")
4245 if $type ne 'Unknown' and $type ne $gtype;
4247 $self->SetGeomFieldDirectly($field, $geometry);
4249 confess last_error() if $@;
4251 error(
"Usage: \$feature->Geometry([field],[geometry])");
4254 return unless defined wantarray;
4255 $geometry = $self->GetGeomFieldRef($field);
4256 return unless $geometry;
4257 keep($geometry, $self);
4260 #** @method Geo::OGR::FeatureDefn GetDefn()
4262 # @note A.k.a GetDefnRef.
4263 # @return a Geo::OGR::FeatureDefn object, which represents the definition of this feature.
4267 my $defn = $self->GetDefnRef;
4271 #** @method scalar GetFID()
4273 # @return the feature id (an integer).
4278 #** @method list GetField($name)
4283 my ($self, $field) = @_;
4284 $field = $self->GetFieldIndex($field);
4285 return unless IsFieldSet($self, $field);
4286 my $type = GetFieldType($self, $field);
4287 return GetFieldAsInteger($self, $field) if $type == $Geo::OGR::OFTInteger;
4288 return GetFieldAsInteger64($self, $field) if $type == $Geo::OGR::OFTInteger64;
4289 return GetFieldAsDouble($self, $field) if $type == $Geo::OGR::OFTReal;
4290 return GetFieldAsString($self, $field) if $type == $Geo::OGR::OFTString;
4291 if ($type == $Geo::OGR::OFTIntegerList) {
4292 my $ret = GetFieldAsIntegerList($self, $field);
4293 return wantarray ? @$ret : $ret;
4295 if ($type == $Geo::OGR::OFTInteger64List) {
4296 my $ret = GetFieldAsInteger64List($self, $field);
4297 return wantarray ? @$ret : $ret;
4299 if ($type == $Geo::OGR::OFTRealList) {
4300 my $ret = GetFieldAsDoubleList($self, $field);
4301 return wantarray ? @$ret : $ret;
4303 if ($type == $Geo::OGR::OFTStringList) {
4304 my $ret = GetFieldAsStringList($self, $field);
4305 return wantarray ? @$ret : $ret;
4307 if ($type == $Geo::OGR::OFTBinary) {
4308 return GetFieldAsBinary($self, $field);
4310 if ($type == $Geo::OGR::OFTDate) {
4311 my @ret = GetFieldAsDateTime($self, $field);
4312 # year, month, day, hour, minute, second, timezone
4313 return wantarray ? @ret[0..2] : [@ret[0..2]];
4315 if ($type == $Geo::OGR::OFTTime) {
4316 my @ret = GetFieldAsDateTime($self, $field);
4317 return wantarray ? @ret[3..6] : [@ret[3..6]];
4319 if ($type == $Geo::OGR::OFTDateTime) {
4320 my @ret = GetFieldAsDateTime($self, $field);
4321 return wantarray ? @ret : [@ret];
4323 error(
"Perl bindings do not support the field type '".i2s(field_type => $type).
"'.");
4326 #** @method scalar GetFieldDefn($name)
4328 # Get the definition of a field.
4329 # @param name the name of the field.
4330 # @return a Geo::OGR::FieldDefn object.
4334 my $field = $self->GetFieldIndex(shift);
4335 return $self->GetFieldDefnRef($field);
4338 #** @method list GetFieldNames()
4340 # Get the names of the fields in this feature.
4345 #** @method scalar GetGeomFieldDefn($name)
4347 # Get the definition of a spatial field.
4348 # @param name the name of the spatial field.
4349 # @return a Geo::OGR::GeomFieldDefn object.
4351 sub GetGeomFieldDefn {
4353 my $field = $self->GetGeomFieldIndex(shift);
4354 return $self->GetGeomFieldDefnRef($field);
4357 #** @method GetNativeData()
4362 #** @method GetNativeMediaType()
4364 sub GetNativeMediaType {
4367 #** @method hash reference GetSchema()
4369 # @brief Get the schema of this feature.
4371 # @return the schema as a hash whose keywords are Name, StyleIgnored
4372 # and Fields. Fields is an anonymous array of first non-spatial and
4373 # then spatial field schemas as in Geo::OGR::FieldDefn::Schema() and
4374 # Geo::OGR::GeomFieldDefn::Schema().
4378 error(
"Schema of a feature cannot be set directly.") if @_;
4379 return $self->GetDefnRef->Schema;
4382 #** @method scalar GetStyleString()
4386 sub GetStyleString {
4389 #** @method IsFieldNull()
4394 #** @method IsFieldSetAndNotNull()
4396 sub IsFieldSetAndNotNull {
4399 #** @method Geo::OGR::Layer Layer()
4401 # @return the layer to which this feature belongs to or undef.
4408 #** @method RELEASE_PARENT()
4410 sub RELEASE_PARENT {
4415 #** @method hash reference Row(%row)
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.
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.
4433 my $nf = $self->GetFieldCount;
4434 my $ngf = $self->GetGeomFieldCount;
4437 if (@_ == 1 and ref($_[0]) eq
'HASH') {
4439 } elsif (@_ and @_ % 2 == 0) {
4442 error(
'Usage: $feature->Row(%FeatureData).');
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});
4453 for my $i (0..$nf-1) {
4454 if ($self->GetFieldDefnRef($i)->Name eq $name) {
4455 $self->SetField($i, $row{$name});
4461 for my $i (0..$ngf-1) {
4462 if ($self->GetGeomFieldDefnRef($i)->Name eq $name) {
4463 $self->Geometry($i, $row{$name});
4469 carp
"Unknown field: '$name'.";
4472 return unless defined wantarray;
4474 for my $i (0..$nf-1) {
4475 my $name = $self->GetFieldDefnRef($i)->Name;
4476 $row{$name} = $self->GetField($i);
4478 for my $i (0..$ngf-1) {
4479 my $name = $self->GetGeomFieldDefnRef($i)->Name ||
'Geometry';
4480 $row{$name} = $self->GetGeometry($i);
4482 $row{FID} = $self->GetFID;
4486 #** @method SetFID($id)
4488 # @param id the feature id.
4493 #** @method SetField($name, @Value)
4499 my $field = $self->GetFieldIndex(shift);
4501 if (@_ == 0 or !defined($arg)) {
4502 _UnsetField($self, $field);
4505 $arg = [@_]
if @_ > 1;
4506 my $type = $self->GetFieldType($field);
4508 if ($type == $Geo::OGR::OFTIntegerList) {
4509 SetFieldIntegerList($self, $field, $arg);
4511 elsif ($type == $Geo::OGR::OFTInteger64List) {
4512 SetFieldInteger64List($self, $field, $arg);
4514 elsif ($type == $Geo::OGR::OFTRealList) {
4515 SetFieldDoubleList($self, $field, $arg);
4517 elsif ($type == $Geo::OGR::OFTStringList) {
4518 SetFieldStringList($self, $field, $arg);
4520 elsif ($type == $Geo::OGR::OFTDate) {
4521 _SetField($self, $field, @$arg[0..2], 0, 0, 0, 0);
4523 elsif ($type == $Geo::OGR::OFTTime) {
4525 _SetField($self, $field, 0, 0, 0, @$arg[0..3]);
4527 elsif ($type == $Geo::OGR::OFTDateTime) {
4529 _SetField($self, $field, @$arg[0..6]);
4531 elsif ($type == $Geo::OGR::OFTInteger64)
4533 SetFieldInteger64($self, $field, $arg);
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).");
4541 if ($type == $Geo::OGR::OFTBinary) {
4542 #$arg = unpack('H*', $arg); # remove when SetFieldBinary is available
4543 $self->SetFieldBinary($field, $arg);
4545 elsif ($type == $Geo::OGR::OFTInteger64)
4547 SetFieldInteger64($self, $field, $arg);
4549 elsif ($type == $Geo::OGR::OFTInteger or $type == $Geo::OGR::OFTReal or $type == $Geo::OGR::OFTString)
4551 _SetField($self, $field, $arg);
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).");
4561 #** @method SetFieldNull()
4566 #** @method SetFrom($other, $forgiving = 1, hashref map)
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
4576 my($self, $other) = @_;
4577 _SetFrom($self, $other),
return if @_ <= 2;
4578 my $forgiving = $_[2];
4579 _SetFrom($self, $other, $forgiving),
return if @_ <= 3;
4582 for my $i (1..GetFieldCount($self)) {
4583 push @list, ($map->{$i} || -1);
4585 SetFromWithMap($self, $other, 1, \@list);
4588 #** @method SetNativeData()
4593 #** @method SetNativeMediaType()
4595 sub SetNativeMediaType {
4598 #** @method SetStyleString($string)
4602 sub SetStyleString {
4605 #** @method list Tuple(@tuple)
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.
4611 # @note The schema of the tuple needs to be the same as that of the
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
4624 my $nf = $self->GetFieldCount;
4625 my $ngf = $self->GetGeomFieldCount;
4627 my $values = ref $_[0] ? $_[0] : \@_;
4629 $FID = shift @$values
if @$values == $nf + $ngf + 1;
4630 $self->SetFID($FID)
if defined $FID;
4631 if (@$values != $nf + $ngf) {
4633 error(
"Too many or too few attribute values for a feature (need $n).");
4635 my $index = 0; # index to non-geometry and geometry fields
4636 for my $i (0..$nf-1) {
4637 $self->SetField($i, $values->[$i]);
4639 for my $i (0..$ngf-1) {
4640 $self->Geometry($i, $values->[$nf+$i]);
4643 return unless defined wantarray;
4644 my @ret = ($self->GetFID);
4645 for my $i (0..$nf-1) {
4646 my $v = $self->GetField($i);
4649 for my $i (0..$ngf-1) {
4650 my $v = $self->GetGeometry($i);
4656 #** @method scalar Validate(list flags)
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.
4667 my $f = eval
'$Geo::OGR::'.uc($flag);
4670 _Validate($self, $flags);
4673 #** @method Geo::OGR::Feature new(%schema)
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)
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.
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.
4693 # @return a new Geo::OGR::Feature object.
4699 if (ref $_[0] eq
'HASH' && $_[0]->{Schema}) {
4702 $arg = {Schema => $_[0]};
4704 } elsif (@_ and @_ % 2 == 0) {
4706 unless ($arg->{Schema}) {
4708 $arg->{Schema} = \%tmp;
4711 error(
"The argument must be either a schema or a hash.");
4713 error(
"Missing schema.") unless $arg->{Schema};
4715 for (ref $arg->{Schema}) {
4717 $defn = $arg->{Schema}->GetDefn;
4721 $defn = $arg->{Schema};
4726 my $self = Geo::OGRc::new_Feature($defn);
4727 error(
"Feature creation failed.") unless $self;
4729 for (ref $arg->{Values}) {
4731 $self->Tuple($arg->{Values});
4735 $self->Row($arg->{Values});
4739 $self->
Tuple($arg->{Values}->Tuple);
4745 error(
"Value parameter must be an array, hash, or another feature. Not $_.");
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()).
4757 package Geo::OGR::FeatureDefn;
4761 #** @method AddField(%params)
4763 # @param params Named parameters to create a new Geo::OGR::FieldDefn
4764 # or Geo::OGR::GeomFieldDefn object.
4768 error(
"Read-only definition.") if parent($self);
4771 } elsif (ref($_[0]) eq
'HASH') {
4773 } elsif (@_ % 2 == 0) {
4777 if (s_exists(field_type => $params{Type})) {
4779 $self->AddFieldDefn($fd);
4782 $self->AddGeomFieldDefn($fd);
4786 #** @method DeleteField($name)
4788 # @note Currently only geometry fields can be deleted.
4789 # @param index the index of the geometry field to be deleted.
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;
4797 for my $i (0..$self->GetGeomFieldCount-1) {
4798 $self->DeleteGeomFieldDefn($i)
if $self->_GetGeomFieldDefn($i)->Name eq $name;
4800 error(2, $name,
'Field');
4803 #** @method Feature()
4807 return parent($self);
4810 #** @method scalar GetFieldDefn($name)
4812 # Get the definition of a field.
4813 # @param name the name of the field.
4814 # @return a Geo::OGR::FieldDefn object.
4818 my $field = $self->GetFieldIndex(shift);
4819 return $self->_GetFieldDefn($field);
4822 #** @method list GetFieldNames()
4824 # The names of the fields in this layer or feature definition.
4825 # @return the list of field names.
4830 for my $i (0..$self->GetFieldCount-1) {
4831 push @names, $self->_GetFieldDefn($i)->Name;
4833 for my $i (0..$self->GetGeomFieldCount-1) {
4834 push @names, $self->_GetGeomFieldDefn($i)->Name;
4839 #** @method scalar GetGeomFieldDefn($name)
4841 # Get the definition of a spatial field.
4842 # @param name the name of the spatial field.
4843 # @return a Geo::OGR::GeomFieldDefn object.
4845 sub GetGeomFieldDefn {
4847 my $field = $self->GetGeomFieldIndex(shift);
4848 return $self->_GetGeomFieldDefn($field);
4851 #** @method scalar GetName()
4853 # @return the name of this layer or feature definition.
4858 #** @method hash reference GetSchema()
4860 # @brief Get the schema of this feature or layer definition.
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().
4869 carp
"Schema of a feature definition should not be set directly." if @_;
4870 if (@_ and @_ % 2 == 0) {
4872 if ($schema{Fields}) {
4873 for my $field (@{$schema{Fields}}) {
4874 $self->AddField($field);
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;
4886 for my $i (0..$self->GetGeomFieldCount-1) {
4887 my $s = $self->_GetGeomFieldDefn($i)->Schema;
4888 push @{$schema{Fields}}, $s;
4890 return wantarray ? %schema : \%schema;
4893 #** @method IsSame(Geo::OGR::FeatureDefn defn)
4895 # @return true if this definition is similar to the other definition,
4901 #** @method scalar IsStyleIgnored()
4903 # Get the ignore status of style information when fetching features.
4904 # @return the ignore status of style information
4907 sub IsStyleIgnored {
4910 #** @method RELEASE_PARENT()
4912 sub RELEASE_PARENT {
4917 #** @method SetStyleIgnored($IgnoreState)
4919 # Set the ignore status of style information when fetching features.
4922 sub SetStyleIgnored {
4925 #** @method Geo::OGR::FeatureDefn new(%schema)
4927 # Creates a new layer or feature definition. The new definition is
4928 # either initialized to the given schema or it will contain no
4929 # non-spatial fields and one spatial field, whose Name is '' and
4930 # GeometryType is 'Unknown' or the value of the named parameter
4932 # @param schema [optional] The schema for the new feature definition,
4933 # as in Geo::OGR::FeatureDefn::Schema().
4934 # @return a Geo::OGR::FeatureDefn object
4938 # $fd = Geo::OGR::FeatureDefn->new(
4940 # Fields => [{ Name => 'field1', Type => 'String' },
4941 # { Name => 'geom', GeometryType => 'Point' }] );
4947 if (@_ == 1 and ref($_[0]) eq
'HASH') {
4949 } elsif (@_ and @_ % 2 == 0) {
4952 my $fields = $schema{Fields};
4953 error(
"The 'Fields' argument must be an array reference.") if $fields and ref($fields) ne 'ARRAY';
4955 my $self = Geo::OGRc::new_FeatureDefn($schema{Name});
4957 my $gt = $schema{GeometryType};
4959 $self->GeometryType($gt);
4961 $self->DeleteGeomFieldDefn(0);
4963 $self->StyleIgnored($schema{StyleIgnored})
if exists $schema{StyleIgnored};
4964 for my $fd (@{$fields}) {
4966 if (ref($fd) eq
'HASH') {
4967 # if Name and Type are missing, assume Name => Type
4968 if (!(exists $fd->{Name} && exists $fd->{Type})) {
4969 for my $key (sort keys %$fd) {
4970 if (s_exists(field_type => $fd->{$key}) ||
4971 s_exists(geometry_type => $fd->{$key}))
4974 $fd->{Type} = $fd->{$key};
4980 if ($fd->{GeometryType} or ($fd->{Type} && s_exists(geometry_type => $fd->{Type}))) {
4986 if (blessed($d) and $d->isa(
'Geo::OGR::FieldDefn')) {
4987 AddFieldDefn($self, $d);
4988 } elsif (blessed($d) and $d->isa(
'Geo::OGR::GeomFieldDefn')) {
4989 error(
"Do not mix GeometryType and geometry fields in Fields.") if $gt;
4990 AddGeomFieldDefn($self, $d);
4992 error(
"Item in field list does not define a field.");
4998 #** @class Geo::OGR::FieldDefn
4999 # @brief A definition of a non-spatial attribute.
5002 package Geo::OGR::FieldDefn;
5006 #** @method scalar Default($value)
5008 # Get or set the default value for this field.
5009 # @note a.k.a. GetDefault and SetDefault
5010 # @param value [optional]
5011 # @return the default value of this field in non-void context.
5015 SetDefault($self, $_[0]) if @_;
5016 GetDefault($self) if defined wantarray;
5019 #** @method GetSchema()
5024 #** @method scalar Ignored($ignore)
5026 # Get and/or set the ignore status (whether this field should be
5027 # omitted when fetching features) of this field.
5028 # @note a.k.a. IsIgnored, SetIgnored
5029 # @param ignore [optional]
5030 # @return the ignore status of this field in non-void context.
5035 SetIgnored($self, $_[0]) if @_;
5036 IsIgnored($self) if defined wantarray;
5039 #** @method IsDefaultDriverSpecific()
5041 sub IsDefaultDriverSpecific {
5044 #** @method scalar Justify($justify)
5046 # Get and/or set the justification of this field.
5047 # @note a.k.a. GetJustify, SetJustify
5048 # @param justify [optional] One of field justify types (Geo::OGR::FieldDefn::JustifyValues).
5049 # @return the justify value of this field in non-void context.
5052 my($self, $justify) = @_;
5053 if (defined $justify) {
5054 $justify = s2i(justify => $justify);
5055 SetJustify($self, $justify);
5057 return i2s(justify => GetJustify($self)) if defined wantarray;
5060 #** @method list JustifyValues()
5061 # Package subroutine.
5062 # Justify values supported by GDAL. Current list is
5063 # Left, Right, and Undefined.
5069 #** @method scalar Name($name)
5071 # Get and/or set the name of the field.
5072 # @note a.k.a. GetName, GetNameRef, SetName
5073 # @param name [optional]
5074 # @return the name in non-void context
5078 SetName($self, $_[0]) if @_;
5079 GetName($self) if defined wantarray;
5082 #** @method scalar Nullable($nullable)
5084 # Get or set the nullable constraint for this field.
5085 # @note a.k.a. IsNullable and SetNullable
5086 # @param nullable [optional]
5087 # @return the nullable value of this field in non-void context.
5091 SetNullable($self, $_[0]) if @_;
5092 IsNullable($self) if defined wantarray;
5095 #** @method scalar Precision($precision)
5097 # Get and/or set the precision of this field.
5098 # @note a.k.a. GetPrecision, SetPrecision
5099 # @param precision [optional]
5100 # @return the precision of this field in non-void context.
5104 SetPrecision($self, $_[0]) if @_;
5105 GetPrecision($self) if defined wantarray;
5108 #** @method hash reference Schema(%params)
5110 # Get the schema or set parts of the schema
5111 # @param params [optional] as those in Geo::OGR::FieldDefn::new.
5112 # @return a reference to a hash whose keys are as those in Geo::OGR::FieldDefn::new.
5117 my $params = @_ % 2 == 0 ? {@_} : shift;
5118 for my $key (keys %SCHEMA_KEYS) {
5119 next unless exists $params->{$key};
5120 eval
"\$self->$key(\$params->{$key})";
5121 confess(last_error()) if $@;
5124 return unless defined wantarray;
5126 for my $key (keys %SCHEMA_KEYS) {
5127 $schema{$key} = eval
'$self->'.$key;
5129 return wantarray ? %schema : \%schema;
5132 #** @method SetSchema()
5137 #** @method scalar SubType($SubType)
5139 # @note a.k.a. GetSubType, SetSubType
5140 # @param SubType [optional] One of field sub types (Geo::OGR::FieldDefn::SubTypes).
5141 # @return the sub type of this field in non-void context.
5144 my($self, $subtype) = @_;
5145 if (defined $subtype) {
5146 $subtype = s2i(field_subtype => $subtype);
5147 SetSubType($self, $subtype);
5149 return i2s(field_subtype => GetSubType($self)) if defined wantarray;
5152 #** @method SubTypes()
5158 #** @method scalar Type($type)
5160 # Get and/or set the type of the field.
5161 # @note a.k.a. GetFieldTypeName, GetTypeName, GetType, SetType
5162 # @param type [optional] One of field types (Geo::OGR::FieldDefn::Types).
5163 # @return one of field types in non-void context.
5166 my($self, $type) = @_;
5167 if (defined $type) {
5168 $type = s2i(field_type => $type);
5169 SetType($self, $type);
5171 return i2s(field_type => GetType($self)) if defined wantarray;
5174 #** @method list Types()
5175 # Package subroutine.
5176 # Field types supported by GDAL. Current list is
5177 # Binary, Date, DateTime, Integer, Integer64, Integer64List, IntegerList, Real, RealList, String, StringList, Time, WideString, and WideStringList.
5178 # (However, WideString is not supported.)
5184 #** @method scalar Width($width)
5186 # Get and/or set the field width.
5187 # @note a.k.a. GetWidth, SetWidth
5188 # @param width [optional]
5189 # @return the width of this field in non-void context.
5193 SetWidth($self, $_[0]) if @_;
5194 GetWidth($self) if defined wantarray;
5197 #** @method Geo::OGR::FieldDefn new(%params)
5199 # @brief Create a new field definition.
5201 # @param Named parameters:
5202 # - \a Name Field name (default is 'unnamed').
5203 # - \a Type Field type, one of Geo::OGR::FieldDefn::Types (default is 'String').
5204 # - \a SubType Field sub type, one of Geo::OGR::FieldDefn::SubTypes.
5205 # - \a Justify Justify value, one of Geo::OGR::FieldDefn::JustifyValues
5208 # - \a Nullable (default is true)
5210 # - \a Ignored (default is false)
5212 # @note Simplified parameters <name> => <type> is also supported.
5214 # @return a new Geo::OGR::FieldDefn object
5218 my $params = {Name =>
'unnamed', Type =>
'String'};
5220 } elsif (@_ == 1 and not ref $_[0]) {
5221 $params->{Name} = shift;
5222 } elsif (@_ == 2 and not $Geo::OGR::FieldDefn::SCHEMA_KEYS{$_[0]}) {
5223 $params->{Name} = shift;
5224 $params->{Type} = shift;
5226 my $tmp = @_ % 2 == 0 ? {@_} : shift;
5227 for my $key (keys %$tmp) {
5228 if ($Geo::OGR::FieldDefn::SCHEMA_KEYS{$key}) {
5229 $params->{$key} = $tmp->{$key};
5231 carp
"Unknown parameter: '$key'." if $key ne
'Index';
5235 $params->{Type} = s2i(field_type => $params->{Type});
5236 my $self = Geo::OGRc::new_FieldDefn($params->{Name}, $params->{Type});
5238 delete $params->{Name};
5239 delete $params->{Type};
5240 $self->Schema($params);
5244 #** @class Geo::OGR::GeomFieldDefn
5245 # @brief A definition of a spatial attribute.
5248 package Geo::OGR::GeomFieldDefn;
5252 #** @method scalar GeometryType($type)
5254 # @note a.k.a. GetType, SetType
5255 # @return the geometry type of the field.
5260 #** @method GetSchema()
5265 #** @method scalar Ignored($ignore)
5267 # @note a.k.a. IsIgnored, SetIgnored
5268 # @return the ignore status of the field.
5272 SetIgnored($self, $_[0])
if @_;
5273 IsIgnored($self)
if defined wantarray;
5276 #** @method scalar Name($name)
5278 # @note a.k.a. GetName, GetNameRef, SetName
5279 # @return the name of the field.
5283 SetName($self, $_[0]) if @_;
5284 GetName($self) if defined wantarray;
5287 #** @method scalar Nullable($nullable)
5289 # @note a.k.a. IsNullable, SetNullable
5290 # @return the nullable status of the field.
5294 SetNullable($self, $_[0]) if @_;
5295 IsNullable($self) if defined wantarray;
5298 #** @method hash reference Schema(%params)
5300 # Get the schema or set parts of the schema.
5301 # @param params [optional] as those in Geo::OGR::GeomFieldDefn::new.
5302 # @return a reference to a hash whose keys are as those in Geo::OGR::GeomFieldDefn::new.
5307 my $params = @_ % 2 == 0 ? {@_} : shift;
5308 for my $key (keys %SCHEMA_KEYS) {
5309 next unless exists $params->{$key};
5310 eval
"\$self->$key(\$params->{$key})";
5311 confess last_error() if $@;
5314 return unless defined wantarray;
5316 for my $key (keys %SCHEMA_KEYS) {
5317 $schema{$key} = eval
'$self->'.$key;
5319 return wantarray ? %schema : \%schema;
5322 #** @method SetSchema()
5327 #** @method scalar SpatialReference($sr)
5329 # @note a.k.a. GetSpatialRef, SetSpatialRef
5330 # @return the spatial reference of the field as a Geo::OSR::SpatialReference object.
5332 sub SpatialReference {
5334 SetSpatialRef($self, $_[0]) if @_;
5335 GetSpatialRef($self) if defined wantarray;
5340 # @return the type of this geometry field. One of Geo::OGR::GeomFieldDefn::Types
5343 my($self, $type) = @_;
5344 if (defined $type) {
5345 $type = s2i(geometry_type => $type);
5346 SetType($self, $type);
5348 i2s(geometry_type => GetType($self)) if defined wantarray;
5352 # Package subroutine.
5353 # @return a list of all geometry types, currently:
5354 # 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.
5360 #** @method Geo::OGR::GeomFieldDefn new(%params)
5362 # @brief Create a new spatial field definition.
5364 # @param params one or more of:
5365 # - \a Name name for the field (default is 'geom').
5366 # - \a GeometryType type for the field type, one of Geo::OGR::GeomFieldDefn::Types (default is 'Unknown').
5367 # - \a SpatialReference a Geo::OSR::SpatialReference object.
5368 # - \a Nullable (default is true)
5369 # - \a Ignored (default is false)
5371 # @note Simplified parameters <name> => <type> is also supported.
5373 # @return a new Geo::OGR::GeomFieldDefn object
5377 my $params = {Name =>
'geom', Type =>
'Unknown'};
5380 $params->{Name} = shift;
5381 } elsif (@_ == 2 and not $Geo::OGR::GeomFieldDefn::SCHEMA_KEYS{$_[0]}) {
5382 $params->{Name} = shift;
5383 $params->{Type} = shift;
5385 my $tmp = @_ % 2 == 0 ? {@_} : shift;
5386 for my $key (keys %$tmp) {
5387 if ($Geo::OGR::GeomFieldDefn::SCHEMA_KEYS{$key}) {
5388 $params->{$key} = $tmp->{$key};
5390 carp
"Unknown parameter: '$key'." if $key ne
'Index' && $key ne
'GeometryType';
5395 $params->{Type} = s2i(geometry_type => $params->{Type});
5396 my $self = Geo::OGRc::new_GeomFieldDefn($params->{Name}, $params->{Type});
5398 delete $params->{Name};
5399 delete $params->{Type};
5400 $self->Schema($params);
5404 #** @class Geo::OGR::Geometry
5405 # @brief Spatial data.
5406 # @details A geometry is spatial data (coordinate values, and a reference to a
5407 # spatial reference system) organized into one of the geometry
5408 # types. Geometries can be created from several type of data including
5409 # a Perl data structure. There are several methods, which modify,
5410 # compare, test, or compute values from geometries.
5411 # @note Most spatial analysis methods require <a
5412 # href="http://geos.osgeo.org/doxygen/">GEOS</a> to work rigorously.
5414 package Geo::OGR::Geometry;
5418 #** @method AddGeometry($other)
5420 # Add a copy of another geometry to a geometry collection
5421 # @param other a Geo::OGR::Geometry object
5426 #** @method AddGeometryDirectly($other)
5428 # @param other a Geo::OGR::Geometry object
5430 sub AddGeometryDirectly {
5433 #** @method AddPoint($x, $y, $z)
5435 # Set the data of a point or add a point to a line string. Consider
5436 # using Geo::OGR::Geometry::Points. Note that the coordinate
5437 # dimension is automatically upgraded to 25D (3) if z is given.
5440 # @param z [optional]
5441 # Calls internally the 2D or 3D version depending on the number of parameters.
5445 my $t = $self->GetGeometryType;
5446 my $has_z = HasZ($t);
5447 my $has_m = HasM($t);
5448 if (!$has_z && !$has_m) {
5449 $self->AddPoint_2D(@_[0..1]);
5450 } elsif ($has_z && !$has_m) {
5451 $self->AddPoint_3D(@_[0..2]);
5452 } elsif (!$has_z && $has_m) {
5453 $self->AddPointM(@_[0..2]);
5455 $self->AddPointZM(@_[0..3]);
5459 #** @method AddPointM()
5464 #** @method AddPointZM()
5469 #** @method AddPoint_2D($x, $y)
5471 # Set the data of a point or add a point to a line string. Consider
5472 # using Geo::OGR::Geometry::Points.
5479 #** @method AddPoint_3D($x, $y, $z)
5481 # Set the data of a point or add a point to a line string. Note that
5482 # the coordinate dimension is automatically upgraded to 25D (3). Consider
5483 # using Geo::OGR::Geometry::Points.
5491 #** @method Geo::OGR::Geometry ApproximateArcAngles(%params)
5492 # Package subroutine.
5493 # Create a line string, which approximates an arc.
5494 # @note All angles are in degrees.
5496 # @param %params Named parameters:
5497 # - \a Center center point (default is [0, 0, 0])
5498 # - \a PrimaryRadius default is 1.
5499 # - \a SecondaryAxis default is 1.
5500 # - \a Rotation default is 0.
5501 # - \a StartAngle default is 0.
5502 # - \a EndAngle default is 360.
5503 # - \a MaxAngleStepSizeDegrees default is 4.
5504 # @return a new Geo::OGR::Geometry object.
5506 sub ApproximateArcAngles {
5508 my %
default = ( Center => [0,0,0],
5514 MaxAngleStepSizeDegrees => 4
5516 for my $p (keys %p) {
5517 if (exists $default{$p}) {
5520 carp
"Unknown parameter: '$p'.";
5523 for my $p (keys %
default) {
5526 error(
"Usage: Center => [x,y,z].") unless ref($p{Center}) eq
'ARRAY';
5530 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});
5533 #** @method scalar Area()
5535 # @note a.k.a. GetArea
5536 # @return the area of the polygon or multipolygon
5541 #** @method scalar As(%params)
5543 # Export the geometry into a known format.
5545 # @param params Named parameters:
5546 # - \a Format One of
5547 # - \a WKT Well Known Text.
5548 # - <em>ISO WKT</em>
5549 # - \a Text Same as WKT.
5550 # - \a WKB Well Known Binary.
5551 # - <em>ISO WKB</em>
5552 # - \a Binary Same as WKB.
5557 # - \a ByteOrder Byte order for binary formats. Default is 'XDR'.
5558 # - \a SRID Spatial reference id for HEXEWKB.
5559 # - \a Options GML generation options.
5560 # - \a AltitudeMode For KML.
5562 # @return the geometry in a given format.
5566 my $p = named_parameters(\@_, Format => undef, ByteOrder =>
'XDR', SRID => undef, Options => undef, AltitudeMode => undef);
5567 my $f = $p->{format};
5568 if ($f =~ /text/i) {
5569 return $self->AsText;
5570 } elsif ($f =~ /wkt/i) {
5572 return $self->ExportToIsoWkt;
5574 return $self->AsText;
5576 } elsif ($f =~ /binary/i) {
5577 return $self->ExportToWkb($p->{byteorder});
5578 } elsif ($f =~ /wkb/i) {
5580 $p->{byteorder} = s2i(byte_order => $p->{byteorder});
5581 return $self->ExportToIsoWkb($p->{byteorder});
5582 } elsif ($f =~ /ewkb/i) {
5583 return $self->AsHEXEWKB($p->{srid});
5584 } elsif ($f =~ /hex/i) {
5585 return $self->AsHEXWKB;
5587 return $self->ExportToWkb($p->{byteorder});
5589 } elsif ($f =~ /gml/i) {
5590 return $self->ExportToGML($p->{options});
5591 } elsif ($f =~ /kml/i) {
5592 return $self->ExportToKML($p->{altitudemode});
5593 } elsif ($f =~ /json/i) {
5594 return $self->AsJSON;
5596 error(1, $f, map {$_=>1} qw/Text WKT ISO_WKT ISO_WKB HEX_WKB HEX_EWKB Binary GML KML JSON/);
5600 #** @method AssignSpatialReference($srs)
5602 # @param srs a Geo::OSR::SpatialReference object
5604 sub AssignSpatialReference {
5607 #** @method Geo::OGR::Geometry Boundary()
5609 # @note a.k.a. GetBoundary
5610 # @return the boundary of this geometry as a geometry
5616 #** @method Geo::OGR::Geometry Buffer($distance, $quadsecs = 30)
5620 # @return a new Geo::OGR::Geometry object
5625 #** @method Geo::OGR::Geometry BuildPolygonFromEdges($BestEffort = 0, $AutoClose = 0, $Tolerance = 0)
5627 # Attempt to create a polygon from a collection of lines or from a multilinestring.
5628 # @param BestEffort For future
5629 # @param AutoClose Assure the first and last points of rings are same.
5630 # @param Tolerance Snap distance.
5631 # @exception Several possibilities, some are reported, some are general errors.
5632 # @return a new Geo::OGR::Geometry object (Polygon)
5634 sub BuildPolygonFromEdges {
5637 #** @method list ByteOrders()
5638 # Package subroutine.
5639 # Same as Geo::OGR::ByteOrders
5642 return @BYTE_ORDER_TYPES;
5645 #** @method Geo::OGR::Geometry Centroid()
5647 # @return a new Geo::OGR::Geometry object
5653 #** @method Geo::OGR::Geometry Clone()
5655 # @return a new Geo::OGR::Geometry object
5660 #** @method CloseRings()
5666 #** @method Geo::OGR::Geometry Collect(@geometries)
5668 # Create a geometrycollection from this and possibly other geometries.
5669 # @param geometries [optional] More geometries to add to the collection.
5670 # @return a new Geo::OGR::Geometry object of type geometrycollection.
5675 #** @method scalar Contains($other)
5677 # @param other a Geo::OGR::Geometry object
5678 # @return true if this geometry contains the other geometry, false otherwise
5683 #** @method Geo::OGR::Geometry ConvexHull()
5685 # @return a new Geo::OGR::Geometry object
5690 #** @method scalar CoordinateDimension($dimension)
5692 # @param dimension [optional]
5695 sub CoordinateDimension {
5697 SetCoordinateDimension($self, $_[0]) if @_;
5698 GetCoordinateDimension($self) if defined wantarray;
5701 #** @method scalar Crosses($other)
5703 # @param other a Geo::OGR::Geometry object
5704 # @return true if this geometry crosses the other geometry, false otherwise
5709 #** @method DelaunayTriangulation()
5711 sub DelaunayTriangulation {
5714 #** @method Geo::OGR::Geometry Difference($other)
5716 # @param other a Geo::OGR::Geometry object
5717 # @return a new Geo::OGR::Geometry object
5722 #** @method scalar Disjoint($other)
5724 # @param other a Geo::OGR::Geometry object
5725 # @return true if this geometry is disjoint from the other geometry, false otherwise
5730 #** @method list Dissolve()
5732 # Dissolve a geometrycollection into separate geometries.
5733 # @return a list of new Geo::OGR::Geometry objects cloned from the collection.
5738 my $n = $self->GetGeometryCount;
5740 for my $i (0..$n-1) {
5741 push @c, $self->GetGeometryRef($i)->Clone;
5749 #** @method scalar Distance($other)
5751 # @param other a Geo::OGR::Geometry object
5752 # @return the distance to the other geometry
5757 #** @method Distance3D()
5764 # Clear geometry data, i.e., remove all points, or, for a point, set
5765 # the coordinate dimension as zero.
5770 #** @method scalar Equals($other)
5772 # @note a.k.a. Equal (deprecated)
5773 # @param other a Geo::OGR::Geometry object
5774 # @return true if this geometry is equivalent to the other geometry, false otherwise
5779 #** @method Extent()
5786 #** @method Feature()
5793 #** @method FlattenTo2D()
5799 #** @method Geo::OGR::Geometry ForceTo($type, ref options)
5801 # Attempt to make a geometry of type 'type' out of this geometry.
5802 # @param type target geometry type. One of Geo::OGR::GeometryTypes.
5803 # @param options not used currently.
5804 # @return a new Geo::OGR::Geometry object.
5809 $type = s2i(geometry_type => $type);
5811 $self = Geo::OGR::ForceTo($self, $type, @_);
5813 confess last_error() if $@;
5817 #** @method Geo::OGR::Geometry ForceToCollection(@geometries)
5819 # Create a geometrycollection from the geometry.
5820 # @param geometries [optional] More geometries to add to the collection.
5821 # @return a new Geo::OGR::Geometry object of type geometrycollection.
5823 sub ForceToCollection {
5831 #** @method Geo::OGR::Geometry ForceToLineString()
5833 # Attempt to create a line string from this geometry.
5834 # @return a new Geo::OGR::Geometry object.
5836 sub ForceToLineString {
5838 return Geo::OGR::ForceToLineString($self);
5841 #** @method Geo::OGR::Geometry ForceToMultiLineString(@linestrings)
5843 # Attempt to create a multilinestring from the geometry, which must be a linestring.
5844 # @param linestrings [optional] More linestrings to add to the collection.
5845 # @return a new Geo::OGR::Geometry object of type multilinestring.
5847 sub ForceToMultiLineString {
5849 $self = Geo::OGR::ForceToMultiLineString($self);
5851 $self->AddGeometry($g);
5856 #** @method Geo::OGR::Geometry ForceToMultiPoint(@points)
5858 # Attempt to create a multipoint from the geometry, which must be a point.
5859 # @param points [optional] More points to add to the collection.
5860 # @return a new Geo::OGR::Geometry object of type multipoint.
5862 sub ForceToMultiPoint {
5864 $self = Geo::OGR::ForceToMultiPoint($self);
5866 $self->AddGeometry($g);
5871 #** @method Geo::OGR::Geometry ForceToMultiPolygon(@polygons)
5873 # Attempt to create a multipolygon from the geometry, which must be a polygon.
5874 # @param polygons [optional] More polygons to add to the collection.
5875 # @return a new Geo::OGR::Geometry object of type multipolygon.
5877 sub ForceToMultiPolygon {
5879 $self = Geo::OGR::ForceToMultiPolygon($self);
5881 $self->AddGeometry($g);
5886 #** @method Geo::OGR::Geometry ForceToPolygon()
5888 # Attempt to create a polygon from this geometry.
5889 # @exception None reported. If this method fails, just a copy is returned.
5890 # @return a new Geo::OGR::Geometry object.
5892 sub ForceToPolygon {
5895 #** @method scalar GeometryType()
5897 # @return the geometry type of this geometry (one of Geo::OGR::GeometryTypes).
5901 return i2s(geometry_type => $self->GetGeometryType);
5904 #** @method list GeometryTypes()
5905 # Package subroutine.
5906 # Same as Geo::OGR::GeometryTypes
5909 return @GEOMETRY_TYPES;
5912 #** @method scalar GetCoordinateDimension()
5914 # @return an integer
5916 sub GetCoordinateDimension {
5919 #** @method GetCurveGeometry()
5921 sub GetCurveGeometry {
5924 #** @method scalar GetDimension()
5926 # @return 0, 1, or 2
5931 #** @method list GetEnvelope()
5933 # @note In scalar context returns a reference to an anonymous array
5934 # containing the envelope.
5935 # @return the envelope ($minx, $maxx, $miny, $maxy)
5940 #** @method list GetEnvelope3D()
5942 # @note In scalar context returns a reference to an anonymous array
5943 # containing the envelope.
5944 # @return the 3-D envelope ($minx, $maxx, $miny, $maxy, $minz, $maxz)
5950 #** @method scalar GetGeometryCount()
5952 # @return an integer
5954 sub GetGeometryCount {
5957 #** @method scalar GetGeometryName()
5959 # @deprecated use Geo::OGR::Geometry::GeometryType.
5963 sub GetGeometryName {
5966 #** @method scalar GetGeometryRef($index)
5968 # @param index index to the geometry, which is a part of this geometry
5969 # @return a new Geo::OGR::Geometry object whose data is a part of the
5972 sub GetGeometryRef {
5975 #** @method scalar GetGeometryType()
5977 # @deprecated use Geo::OGR::Geometry::GeometryType, which returns the
5980 # @return type as an integer
5982 sub GetGeometryType {
5985 #** @method GetLinearGeometry()
5987 sub GetLinearGeometry {
5995 #** @method list GetPoint($index = 0)
5998 # @return (x,y) or a list with more coordinates
6003 my $t = $self->GetGeometryType;
6004 my $has_z = HasZ($t);
6005 my $has_m = HasM($t);
6007 if (!$has_z && !$has_m) {
6008 $point = $self->GetPoint_2D($i);
6009 } elsif ($has_z && !$has_m) {
6010 $point = $self->GetPoint_3D($i);
6011 } elsif (!$has_z && $has_m) {
6012 $point = $self->GetPointZM($i);
6013 @$point = ($point->[0], $point->[1], $point->[3]);
6015 $point = $self->GetPointZM($i);
6017 return wantarray ? @$point : $point;
6020 #** @method scalar GetPointCount()
6022 # @return an integer
6027 #** @method GetPointZM()
6032 #** @method scalar GetPoint_2D($index = 0)
6035 # @return (x,y) or a list with more coordinates
6040 #** @method scalar GetPoint_3D($index = 0)
6043 # @return (x,y) or a list with more coordinates
6048 #** @method Geo::OSR::SpatialReference GetSpatialReference()
6050 # @return a new Geo::OSR::SpatialReference object
6052 sub GetSpatialReference {
6055 #** @method scalar GetX($index = 0)
6063 #** @method scalar GetY($index = 0)
6071 #** @method scalar GetZ($index = 0)
6079 #** @method HasCurveGeometry()
6081 sub HasCurveGeometry {
6084 #** @method Geo::OGR::Geometry Intersection($other)
6086 # @param other a Geo::OGR::Geometry object
6087 # @return a new Geo::OGR::Geometry object
6092 #** @method scalar Intersects($other)
6094 # @note a.k.a. Intersect (deprecated)
6095 # @param other a Geo::OGR::Geometry object
6096 # @return true if this geometry intersects with the other geometry, false otherwise
6106 #** @method scalar IsEmpty()
6108 # Test whether the geometry is empty (has no points, or, for a point,
6109 # has coordinate dimension of zero).
6115 #** @method IsMeasured()
6120 #** @method scalar IsRing()
6122 # Test if the geometry is a ring. Requires GEOS in GDAL.
6128 #** @method scalar IsSimple()
6130 # Test the simplicity of the geometry (OGC sense). Requires GEOS in GDAL.
6136 #** @method scalar IsValid()
6138 # Test the validity of the geometry (OGC sense). Requires GEOS in GDAL.
6144 #** @method scalar Length()
6146 # @return the length of the linestring
6151 #** @method Move($dx, $dy, $dz)
6153 # Move every point of the object as defined by the parameters.
6156 # @param dz [optional]
6161 #** @method scalar Overlaps($other)
6163 # @param other a Geo::OGR::Geometry object
6164 # @return true if this geometry overlaps the other geometry, false otherwise
6169 #** @method list Point($index, $x, $y, $z)
6171 # Get or set the point
6172 # @param index The index of the point. Optional (ignored if given) for
6173 # Point and Point25D geometries.
6174 # @param x [optional]
6175 # @param y [optional]
6176 # @param z [optional]
6183 my $t = $self->GetGeometryType;
6185 if (Flatten($t) == $Geo::OGR::wkbPoint) {
6186 my $has_z = HasZ($t);
6187 my $has_m = HasM($t);
6188 if (!$has_z && !$has_m) {
6191 } elsif ($has_z || $has_m) {
6199 $i = shift unless defined $i;
6200 $self->SetPoint($i, @_);
6202 return unless defined wantarray;
6203 my $point = $self->GetPoint;
6204 return wantarray ? @$point : $point;
6207 #** @method PointOnSurface()
6209 sub PointOnSurface {
6212 #** @method array reference Points(arrayref points)
6214 # Get or set the points of the geometry. The points (vertices) are
6215 # stored in obvious lists of lists. When setting, the geometry is
6216 # first emptied. The method uses internally either AddPoint_2D or
6217 # AddPoint_3D depending on the coordinate dimension of the input data.
6219 # @note The same structure may represent different geometries
6220 # depending on the actual geometry type of the object.
6222 # @param points [optional] A reference to an array. A point is a reference to an
6223 # array of numbers, a linestring or a ring is a reference to an array of points,
6224 # a polygon is a reference to an array of rings, etc.
6226 # @return A reference to an array.
6230 my $t = $self->GetGeometryType;
6231 my $has_z = HasZ($t);
6232 my $has_m = HasM($t);
6234 $postfix .=
'Z' if HasZ($t);
6235 $postfix .=
'M' if HasM($t);
6236 $t = i2s(geometry_type => Flatten($t));
6240 if ($t eq
'Unknown' or $t eq
'None' or $t eq
'GeometryCollection') {
6241 error(
"Can't set points of a geometry of type '$t'.");
6242 } elsif ($t eq
'Point') {
6243 # support both "Point" as a list of one point and one point
6244 if (ref($points->[0])) {
6245 $self->AddPoint(@{$points->[0]});
6247 $self->AddPoint(@$points);
6249 } elsif ($t eq
'LineString' or $t eq
'LinearRing' or $t eq
'CircularString') {
6250 for my $p (@$points) {
6251 $self->AddPoint(@$p);
6253 } elsif ($t eq
'Polygon') {
6254 for my $r (@$points) {
6256 $ring->
Set3D(1)
if $has_z;
6257 $ring->SetMeasured(1)
if $has_m;
6259 $self->AddGeometryDirectly($ring);
6261 } elsif ($t eq
'MultiPoint') {
6262 for my $p (@$points) {
6265 $self->AddGeometryDirectly($point);
6267 } elsif ($t eq
'MultiLineString') {
6268 for my $l (@$points) {
6271 $self->AddGeometryDirectly($linestring);
6273 } elsif ($t eq
'MultiPolygon') {
6274 for my $p (@$points) {
6277 $self->AddGeometryDirectly($polygon);
6281 return unless defined wantarray;
6282 $self->_GetPoints();
6285 #** @method RELEASE_PARENT()
6287 sub RELEASE_PARENT {
6292 #** @method Segmentize($MaxLength)
6294 # Modify the geometry such it has no segment longer than the given length.
6295 # @param MaxLength the given length
6305 #** @method SetCoordinateDimension($dimension)
6309 sub SetCoordinateDimension {
6312 #** @method SetMeasured()
6317 #** @method SetPoint($index, $x, $y, $z)
6319 # Set the data of a point or a line string. Note that the coordinate
6320 # dimension is automatically upgraded to 25D (3) if z is given.
6324 # @param z [optional]
6328 my $t = $self->GetGeometryType;
6329 my $has_z = HasZ($t);
6330 my $has_m = HasM($t);
6331 if (!$has_z && !$has_m) {
6332 $self->SetPoint_2D(@_[0..2]);
6333 } elsif ($has_z && !$has_m) {
6334 $self->SetPoint_3D(@_[0..3]);
6335 } elsif (!$has_z && $has_m) {
6336 $self->SetPointM(@_[0..3]);
6338 $self->SetPointZM(@_[0..4]);
6342 #** @method SetPointM()
6347 #** @method SetPointZM()
6352 #** @method SetPoint_2D($index, $x, $y)
6361 #** @method SetPoint_3D($index, $x, $y, $z)
6363 # Set the data of a point or a line string. Note that the coordinate
6364 # dimension is automatically upgraded to 25D (3).
6373 #** @method Geo::OGR::Geometry Simplify($Tolerance)
6375 # Simplify the geometry.
6376 # @param Tolerance the length tolerance for the simplification
6378 # @return a new Geo::OSR::Geometry object
6383 #** @method SimplifyPreserveTopology()
6385 sub SimplifyPreserveTopology {
6388 #** @method Geo::OGR::Geometry SymDifference($other)
6390 # Compute symmetric difference.
6391 # @note a.k.a. SymmetricDifference
6392 # @param other a Geo::OGR::Geometry object
6393 # @return a new Geo::OGR::Geometry object
6399 #** @method scalar Touches($other)
6401 # @param other a Geo::OGR::Geometry object
6402 # @return true if this geometry touches the other geometry, false otherwise
6407 #** @method Transform($trans)
6409 # @param trans a Geo::OSR::CoordinateTransformation object
6414 #** @method TransformTo($srs)
6416 # @param srs a Geo::OSR::SpatialReference object
6421 #** @method Geo::OGR::Geometry Union($other)
6423 # @param other a Geo::OGR::Geometry object
6424 # @return a new Geo::OGR::Geometry object
6429 #** @method Geo::OGR::Geometry UnionCascaded()
6431 # @return a new Geo::OGR::Geometry object
6442 #** @method scalar Within($other)
6444 # @param other a Geo::OGR::Geometry object
6445 # @return true if this geometry is within the other geometry, false otherwise
6450 #** @method scalar WkbSize()
6452 # @return an integer
6457 #** @method Geo::OGR::Geometry new(%params)
6459 # @param %params A named parameter, one of:
6460 # - \a GeometryType one the supported geometry types, see Geo::OGR::GeometryTypes.
6461 # - \a WKT a well known text string, which defines a geometry.
6462 # - \a WKB a well known binary string, which defines a geometry.
6463 # - \a HEXWKB WKB in hexadecimal.
6464 # - \a HEXEWKB PostGIS extended WKB.
6465 # - \a GML geometry written in Geographic Markup Language.
6466 # - \a GeoJSON geometry written in GeoJSON (JavaScript Object Notation for Geographic data).
6467 # - \a arc a reference to a list of values defining an arc: [CenterX,
6468 # CenterY, CenterZ, PrimaryRadius, SecondaryRadius, Rotation,
6469 # StartAngle, EndAngle, MaxAngleStepSizeDegrees] (see also Geo::OGR::Geometry::ApproximateArcAngles)
6470 # - \a Points An anonymous array as in method
6471 # Geo::OGR::Geometry::Points; Note: requires also GeometryType
6474 # @return a new Geo::OGR::Geometry object.
6479 if (@_ == 1 and ref($_[0]) eq
'HASH') {
6481 } elsif (@_ % 2 == 0) {
6484 ($param{GeometryType}) = @_;
6486 my $type = $param{GeometryType}
6487 my $srs = $param{SRS}
6488 my $wkt = $param{WKT}
6489 my $wkb = $param{WKB}
6490 my $hex = $param{HEXEWKB}
6493 # EWKB contains SRID
6494 $srid = substr($hex, 10, 8);
6495 substr($hex, 10, 8) =
'';
6497 $hex = $param{HEXWKB}
6501 for (my $i = 0; $i < length($hex); $i+=2) {
6502 $wkb .= chr(hex(substr($hex,$i,2)));
6505 my $gml = $param{GML}
6506 my $json = $param{GeoJSON}
6507 my $points = $param{Points}
6508 my $arc = $param{Arc}
6511 $self = Geo::OGRc::CreateGeometryFromWkt($wkt, $srs);
6512 } elsif (defined $wkb) {
6513 $self = Geo::OGRc::CreateGeometryFromWkb($wkb, $srs);
6514 } elsif (defined $gml) {
6515 $self = Geo::OGRc::CreateGeometryFromGML($gml);
6516 } elsif (defined $json) {
6517 $self = Geo::OGRc::CreateGeometryFromJson($json);
6518 } elsif (defined $type) {
6519 $type = s2i(geometry_type => $type);
6520 $self = Geo::OGRc::new_Geometry($type); # flattens the type
6521 $self->Set3D(1)
if HasZ($type);
6522 $self->SetMeasured(1)
if HasM($type);
6523 } elsif (defined $arc) {
6524 $self = Geo::OGRc::ApproximateArcAngles(@$arc);
6526 error(1, undef, map {$_=>1} qw/GeometryType WKT WKB HEXEWKB HEXWKB GML GeoJSON Arc/);
6528 bless $self, $pkg
if defined $self;
6529 $self->Points($points)
if $points;
6533 #** @class Geo::OGR::Layer
6534 # @brief A collection of similar features.
6535 # @details A layer object is typically obtained with a data source object. A
6536 # layer has a data model (a schema), which is maintained in a
6537 # definition object, and a set of features, which contain data
6538 # according to the data model. The schema is typically set when the
6539 # layer is created or opened, but it may be altered somewhat with
6540 # methods Geo::OGR::Layer::CreateField,
6541 # Geo::OGR::Layer::AlterFieldDefn, and
6542 # Geo::OGR::Layer::DeleteField. Features and/or their data can be
6543 # read, inserted and deleted. Reading can be filtered. Layers can be
6544 # compared to each other with methods Clip, Erase, Identity,
6545 # Intersection, SymDifference, Union, and Update.
6546 # A layer may have metadata OLMD_FID64 => 'YES' if it holds features
6547 # with 64 bit FIDs. The metadata of a layer can be obtained with
6548 # GetMetadata method.
6550 package Geo::OGR::Layer;
6554 #** @method AlterFieldDefn($name, %params)
6556 # @param field the name of the field to be altered.
6557 # @param params as in Geo::OGR::FieldDefn::new. Width and
6558 # Precision should be both or neither.
6559 # @note Only non-spatial fields can be altered.
6560 # @note Also the deprecated form AlterFieldDefn($field,
6561 # Geo::OGR::FieldDefn $Defn, $Flags) works.
6563 sub AlterFieldDefn {
6565 my $index = $self->GetLayerDefn->GetFieldIndex(shift
6566 my $param = @_ % 2 == 0 ? {@_} : shift;
6567 if (blessed($param) and $param->isa(
'Geo::OGR::FieldDefn')) {
6568 _AlterFieldDefn($self, $index, @_);
6572 $flags |= 1
if exists $param->{Name};
6573 $flags |= 2
if exists $param->{Type};
6574 $flags |= 4
if exists $param->{Width} or exists $param->{Precision};
6575 $flags |= 8
if exists $param->{Nullable};
6576 $flags |= 16
if exists $param->{Default};
6577 _AlterFieldDefn($self, $index, $definition, $flags);
6581 #** @method list Capabilities()
6583 # Both a package subroutine and an object method.
6584 # @return a list of capabilities. The object method returns a list of
6585 # the capabilities the layer has. The package subroutine returns a list of
6586 # all potential capabilities a layer may have. These are currently:
6587 # AlterFieldDefn, CreateField, CreateGeomField, CurveGeometries, DeleteFeature, DeleteField, FastFeatureCount, FastGetExtent, FastSetNextByIndex, FastSpatialFilter, IgnoreFields, MeasuredGeometries, RandomRead, RandomWrite, ReorderFields, SequentialWrite, StringsAsUTF8, and Transactions.
6591 # @cap = Geo::OGR::Layer::Capabilities(); # the package subroutine
6592 # @cap = $layer->Capabilities(); # the object method
6596 return @CAPABILITIES
if @_ == 0;
6599 for my $cap (@CAPABILITIES) {
6600 push @cap, $cap
if _TestCapability($self, $CAPABILITIES{$cap});
6605 #** @method Clip(Geo::OGR::Layer method, Geo::OGR::Layer result, hashref options, coderef callback, $callback_data)
6607 # Clip off areas that are not covered by the method layer. The schema
6608 # of the result layer can be set before calling this method, or is
6609 # initialized to to contain all fields from
6610 # this and method layer.
6611 # @param method method layer.
6612 # @param result result layer.
6613 # @param options a reference to an options hash.
6614 # @param callback [optional] a reference to a subroutine, which will
6615 # be called with parameters (number progress, string msg, callback_data)
6616 # @param callback_data [optional]
6621 #** @method CommitTransaction()
6624 sub CommitTransaction {
6627 #** @method CreateFeature()
6632 #** @method CreateField(%params)
6635 # @param params as in Geo::OGR::FieldDefn::new or
6636 # Geo::OGR::GeomFieldDefn::new, plus ApproxOK (whose default is true).
6640 my %defaults = ( ApproxOK => 1,
6644 } elsif (ref($_[0]) eq
'HASH') {
6646 } elsif (@_ % 2 == 0) {
6649 ($params{Defn}) = @_;
6651 for my $k (keys %defaults) {
6654 if (blessed($params{Defn}) and $params{Defn}->isa(
'Geo::OGR::FieldDefn')) {
6655 $self->_CreateField($params{Defn}, $params{ApproxOK});
6656 } elsif (blessed($_[0]) and $params{Defn}->isa(
'Geo::OGR::GeomFieldDefn')) {
6657 $self->CreateGeomField($params{Defn}, $params{ApproxOK});
6659 # if Name and Type are missing, assume Name => Type
6660 if (!(exists $params{Name} && exists $params{Type})) {
6661 for my $key (sort keys %params) {
6662 if (s_exists(field_type => $params{$key}) ||
6663 s_exists(geometry_type => $params{$key}))
6665 $params{Name} = $key;
6666 $params{Type} = $params{$key};
6667 delete $params{$key};
6672 my $a = $params{ApproxOK};
6673 delete $params{ApproxOK};
6674 if (exists $params{GeometryType}) {
6675 $params{Type} = $params{GeometryType};
6676 delete $params{GeometryType};
6678 if (s_exists(field_type => $params{Type})) {
6680 _CreateField($self, $fd, $a);
6681 } elsif (s_exists(geometry_type => $params{Type})) {
6683 CreateGeomField($self, $fd, $a);
6684 } elsif ($params{Type} ) {
6685 error(
"Invalid field type: $params{Type}.")
6686 } elsif ($params{Name} ) {
6687 error(
"Missing type for field: $params{Name}.")
6689 error(
"Missing name and type for a field.")
6694 #** @method DataSource()
6699 #** @method Dataset()
6706 #** @method DeleteFeature($fid)
6708 # @param fid feature id
6713 #** @method DeleteField($field)
6715 # Delete an existing field from a layer.
6716 # @param field name (or index) of the field which is deleted
6717 # @note Only non-spatial fields can be deleted.
6720 my ($self, $field) = @_;
6721 my $index = $self->GetLayerDefn->GetFieldIndex($field
6722 _DeleteField($self, $index);
6725 #** @method Erase(Geo::OGR::Layer method, Geo::OGR::Layer result, hashref options, coderef callback, $callback_data)
6727 # The result layer contains features whose geometries represent areas
6728 # that are in the input layer but not in the method layer. The
6729 # features in the result layer have attributes from the input
6730 # layer. The schema of the result layer can be set by the user or, if
6731 # it is empty, is initialized to contain all fields in the input
6733 # @param method method layer.
6734 # @param result result layer.
6735 # @param options a reference to an options hash.
6736 # @param callback [optional] a reference to a subroutine, which will
6737 # be called with parameters (number progress, string msg, callback_data)
6738 # @param callback_data [optional]
6743 #** @method Geo::OGR::Feature Feature($f)
6746 # @param f [optional] feature id, a feature, a row, or a tuple
6748 # @note If the argument feature has a null FID (FID not set) the
6749 # feature is inserted into the layer as a new feature. If the FID is
6750 # non null, then the feature replaces the feature in the layer with
6753 # @return a new Geo::OGR::Feature object that represents the feature
6759 return $self->GetFeature($x) unless $x && ref $x;
6760 # Insert or Set depending on the FID
6762 if (ref $x eq
'ARRAY') {
6763 # FID is the first item in the array
6765 } elsif (ref $x eq
'HASH') {
6772 if (!defined $fid || $fid < 0) {
6773 $self->InsertFeature($x);
6775 $self->SetFeature($x);
6779 #** @method scalar FeatureCount($force = 1)
6781 # A.k.a GetFeatureCount
6788 #** @method ForFeatures($code, $in_place)
6790 # @note experimental, the syntax may change
6792 # Call code for all features. This is a simple wrapper for
6793 # ResetReading and while(GetNextFeature).
6797 # $layer->ForFeatures(sub {my $f = shift; $self->DeleteFeature($f->FID)}); # empties the layer
6800 # @param code a reference to a subroutine, which is called with each
6801 # feature as an argument
6802 # @param in_place if set to true, the feature is stored back to the
6808 my $in_place = shift;
6809 $self->ResetReading;
6810 while (my $f = $self->GetNextFeature) {
6813 $self->SetFeature($f)
if $in_place;
6817 #** @method ForGeometries($code, $in_place)
6819 # @note experimental, the syntax may change
6821 # Call code for all geometries. This is a simple wrapper for
6822 # ResetReading and while(GetNextFeature).
6827 # $layer->ForGeometries(sub {my $g = shift; $area += $g->Area}); # computes the total area
6830 # @param code a reference to a subroutine, which is called with each
6831 # geometry as an argument
6832 # @param in_place if set to true, the geometry is stored back to the
6838 my $in_place = shift;
6839 $self->ResetReading;
6840 while (my $f = $self->GetNextFeature) {
6841 my $g = $f->Geometry();
6845 $self->SetFeature($f);
6850 #** @method scalar GeometryType($field)
6852 # @param field the name or index of the spatial field.
6853 # @return the geometry type of the spatial field.
6857 my $d = $self->GetDefn;
6858 my $field = $d->GetGeomFieldIndex(shift
6859 my $fd = $d->_GetGeomFieldDefn($field);
6860 return $fd->Type
if $fd;
6863 #** @method Geo::OGR::DataSource GetDataSource()
6865 # @return the data source object to which this layer object belongs to.
6872 #** @method Geo::OGR::FeatureDefn GetDefn()
6874 # A.k.a GetLayerDefn.
6875 # @return a Geo::OGR::FeatureDefn object.
6879 my $defn = $self->GetLayerDefn;
6883 #** @method list GetExtent($force = 1)
6885 # @param force compute the extent even if it is expensive
6886 # @note In scalar context returns a reference to an anonymous array
6887 # containing the extent.
6888 # @return the extent ($minx, $maxx, $miny, $maxy)
6890 # @return the extent = ($minx, $maxx, $miny, $maxy) as a listref
6895 #** @method scalar GetFIDColumn()
6897 # @return the name of the underlying database column being used as the
6898 # FID column, or "" if not supported.
6903 #** @method Geo::OGR::Feature GetFeature($fid)
6905 # @param fid feature id
6906 # @return a new Geo::OGR::Feature object that represents the feature in the layer.
6909 my ($self, $fid) = @_;
6911 my $f = $self->_GetFeature($fid);
6912 error(2,
"FID=$fid",
'"Feature') unless ref $f eq 'Geo::
OGR::Feature';
6916 #** @method GetFeatureCount()
6918 sub GetFeatureCount {
6921 #** @method scalar GetFeaturesRead()
6925 sub GetFeaturesRead {
6928 #** @method scalar GetFieldDefn($name)
6930 # Get the definition of a field.
6931 # @param name the name of the field.
6932 # @return a Geo::OGR::FieldDefn object.
6936 my $d = $self->GetDefn;
6937 my $field = $d->GetFieldIndex(shift
6938 return $d->_GetFieldDefn($field);
6941 #** @method list GetFieldNames()
6943 # @return a list of the names of the fields in this layer. The
6944 # non-geometry field names are first in the list and then the geometry
6949 my $d = $self->GetDefn;
6951 for (my $i = 0; $i < $d->GetFieldCount; $i++) {
6952 push @ret, $d->GetFieldDefn($i)->Name();
6954 for (my $i = 0; $i < $d->GetGeomFieldCount; $i++) {
6955 push @ret, $d->GetGeomFieldDefn($i)->Name();
6960 #** @method scalar GetGeomFieldDefn($name)
6962 # Get the definition of a spatial field.
6963 # @param name the name of the spatial field.
6964 # @return a Geo::OGR::GeomFieldDefn object.
6966 sub GetGeomFieldDefn {
6968 my $d = $self->GetDefn;
6969 my $field = $d->GetGeomFieldIndex(shift
6970 return $d->_GetGeomFieldDefn($field);
6973 #** @method scalar GetName()
6975 # @return the name of the layer.
6980 #** @method Geo::OGR::Feature GetNextFeature()
6982 # @return iteratively Geo::OGR::Feature objects from the layer. The
6983 # iteration obeys the spatial and the attribute filter.
6985 sub GetNextFeature {
6988 #** @method hash reference GetSchema()
6990 # @brief Get the schema of this layer.
6991 # @note The schema of a layer cannot be set with this method. If you
6992 # have a Geo::OGR::FeatureDefn object before creating the layer, use
6993 # its schema in the Geo::OGR::CreateLayer method.
6994 # @return the schema of this layer, as in Geo::OGR::FeatureDefn::Schema.
6998 carp
"Schema of a layer should not be set directly." if @_;
6999 if (@_ and @_ % 2 == 0) {
7001 if ($schema{Fields}) {
7002 for my $field (@{$schema{Fields}}) {
7003 $self->CreateField($field);
7007 return $self->GetDefn->Schema;
7010 #** @method Geo::OGR::Geometry GetSpatialFilter()
7012 # @return a new Geo::OGR::Geometry object
7014 sub GetSpatialFilter {
7017 #** @method GetStyleTable()
7022 #** @method Identity(Geo::OGR::Layer method, Geo::OGR::Layer result, hashref options, coderef callback, $callback_data)
7024 # The result layer contains features whose geometries represent areas
7025 # that are in the input layer. The features in the result layer have
7026 # attributes from both input and method layers. The schema of the
7027 # result layer can be set by the user or, if it is empty, is
7028 # initialized to contain all fields in input and method layers.
7029 # @param method method layer.
7030 # @param result result layer.
7031 # @param options a reference to an options hash.
7032 # @param callback [optional] a reference to a subroutine, which will
7033 # be called with parameters (number progress, string msg, callback_data)
7034 # @param callback_data [optional]
7039 #** @method InsertFeature($feature)
7041 # Creates a new feature which has the schema of the layer and
7042 # initializes it with data from the argument. Then inserts the feature
7043 # into the layer (using CreateFeature). Uses Geo::OGR::Feature::Row or
7044 # Geo::OGR::Feature::Tuple.
7045 # @param feature a Geo::OGR::Feature object or reference to feature
7046 # data in a hash (as in Geo::OGR::Feature::Row) or in an array (as in
7047 # Geo::OGR::Feature::Tuple)
7048 # @return the new feature.
7052 my $feature = shift;
7053 error(
"Usage: \$feature->InsertFeature(reference to a hash or array).") unless ref($feature);
7054 my $new = Geo::OGR::Feature->new(Schema => $self, Values => $feature);
7055 $self->CreateFeature($new);
7056 return unless defined wantarray;
7060 #** @method Intersection(Geo::OGR::Layer method, Geo::OGR::Layer result, hashref options, coderef callback, $callback_data)
7062 # The result layer contains features whose geometries represent areas
7063 # that are common between features in the input layer and in the
7064 # method layer. The schema of the result layer can be set before
7065 # calling this method, or is initialized to contain all fields from
7066 # this and method layer.
7067 # @param method method layer.
7068 # @param result result layer.
7069 # @param options a reference to an options hash.
7070 # @param callback [optional] a reference to a subroutine, which will
7071 # be called with parameters (number progress, string msg, callback_data)
7072 # @param callback_data [optional]
7077 #** @method RELEASE_PARENT()
7079 sub RELEASE_PARENT {
7084 #** @method ReorderField()
7089 #** @method ReorderFields()
7094 #** @method ResetReading()
7096 # Initialize the layer object for iterative reading.
7101 #** @method RollbackTransaction()
7104 sub RollbackTransaction {
7107 #** @method hash reference Row(%row)
7109 # Get and/or set the data of a feature that has the supplied feature
7110 # id (the next feature obtained with GetNextFeature is used if feature
7111 # id is not given). Calls Geo::OGR::Feature::Row.
7112 # @param row [optional] feature data
7113 # @return a reference to feature data in a hash
7117 my $update = @_ > 0;
7119 my $feature = defined $row{FID} ? $self->GetFeature($row{FID}) : $self->GetNextFeature;
7120 return unless $feature;
7122 if (defined wantarray) {
7123 $ret = $feature->Row(@_);
7127 $self->SetFeature($feature)
if $update;
7128 return unless defined wantarray;
7132 #** @method SetAttributeFilter($filter_string)
7134 # Set or clear the attribute filter.
7135 # @param filter_string a SQL WHERE clause or undef to clear the
7138 sub SetAttributeFilter {
7141 #** @method SetFeature($feature)
7143 # @note The feature should have the same schema as the layer.
7145 # Replaces a feature in the layer based on the given feature's
7146 # id. Requires RandomWrite capability.
7147 # @param feature a Geo::OGR::Feature object
7152 #** @method SetIgnoredFields(@fields)
7154 # @param fields a list of field names
7156 sub SetIgnoredFields {
7159 #** @method SetNextByIndex($new_index)
7161 # @param new_index the index to which set the read cursor in the
7164 sub SetNextByIndex {
7167 #** @method SetSpatialFilter($filter)
7169 # @param filter [optional] a Geo::OGR::Geometry object. If not given,
7170 # removes the filter if there is one.
7172 sub SetSpatialFilter {
7175 #** @method SetSpatialFilterRect($minx, $miny, $maxx, $maxy)
7182 sub SetSpatialFilterRect {
7185 #** @method SetStyleTable()
7190 #** @method Geo::OGR::Geometry SpatialFilter(@filter)
7192 # @param filter [optional] a Geo::OGR::Geometry object or a string. An
7193 # undefined value removes the filter if there is one.
7194 # @return a new Geo::OGR::Geometry object
7195 # @param filter [optional] a rectangle ($minx, $miny, $maxx, $maxy).
7196 # @return a new Geo::OGR::Geometry object
7200 $self->SetSpatialFilter($_[0])
if @_ == 1;
7201 $self->SetSpatialFilterRect(@_)
if @_ == 4;
7202 return unless defined wantarray;
7203 $self->GetSpatialFilter;
7206 #** @method Geo::OSR::SpatialReference SpatialReference($name, Geo::OSR::SpatialReference sr)
7208 # @note A.k.a GetSpatialRef.
7209 # Get or set the projection of a spatial field of this layer. Gets or
7210 # sets the projection of the first field if no field name is given.
7211 # @param name [optional] a name of a spatial field in this layer.
7212 # @param sr [optional] a Geo::OSR::SpatialReference object,
7213 # which replaces the existing projection.
7214 # @return a Geo::OSR::SpatialReference object, which represents the
7215 # projection in the given spatial field.
7217 sub SpatialReference {
7219 my $d = $self->GetDefn;
7220 my $field = @_ == 2 ? $d->GetGeomFieldIndex(shift
7222 my $d2 = $d->_GetGeomFieldDefn($field);
7223 $d2->SpatialReference($sr)
if defined $sr;
7224 return $d2->SpatialReference()
if defined wantarray;
7227 #** @method StartTransaction()
7230 sub StartTransaction {
7233 #** @method SymDifference(Geo::OGR::Layer method, Geo::OGR::Layer result, hashref options, coderef callback, $callback_data)
7235 # The result layer contains features whose geometries represent areas
7236 # that are in either in the input layer or in the method layer but not
7237 # in both. The features in the result layer have attributes from both
7238 # input and method layers. For features which represent areas that are
7239 # only in the input or in the method layer the respective attributes
7240 # have undefined values. The schema of the result layer can be set by
7241 # the user or, if it is empty, is initialized to contain all fields in
7242 # the input and method layers.
7243 # @param method method layer.
7244 # @param result result layer.
7245 # @param options a reference to an options hash.
7246 # @param callback [optional] a reference to a subroutine, which will
7247 # be called with parameters (number progress, string msg, callback_data)
7248 # @param callback_data [optional]
7253 #** @method SyncToDisk()
7259 #** @method scalar TestCapability($cap)
7261 # @param cap A capability string.
7262 # @return a boolean value indicating whether the layer has the
7263 # specified capability.
7265 sub TestCapability {
7266 my($self, $cap) = @_;
7267 return _TestCapability($self, $CAPABILITIES{$cap});
7270 #** @method list Tuple(@tuple)
7272 # Get and/set the data of a feature that has the supplied feature id
7273 # (the next feature obtained with GetNextFeature is used if feature id
7274 # is not given). The expected data in the tuple is: ([feature id,]
7275 # non-spatial fields, spatial fields). Calls Geo::OGR::Feature::Tuple.
7276 # @param tuple [optional] feature data
7277 # @note The schema of the tuple needs to be the same as that of the
7279 # @return a reference to feature data in an array
7284 my $feature = defined $FID ? $self->GetFeature($FID) : $self->GetNextFeature;
7285 return unless $feature;
7287 unshift @_, $feature->GetFID
if $set;
7289 if (defined wantarray) {
7290 @ret = $feature->Tuple(@_);
7292 $feature->Tuple(@_);
7294 $self->SetFeature($feature)
if $set;
7295 return unless defined wantarray;
7299 #** @method Union(Geo::OGR::Layer method, Geo::OGR::Layer result, hashref options, coderef callback, $callback_data)
7301 # The result layer contains features whose geometries represent areas
7302 # that are in either in the input layer or in the method layer. The
7303 # schema of the result layer can be set before calling this method, or
7304 # is initialized to contain all fields from this and method layer.
7305 # @param method method layer.
7306 # @param result result layer.
7307 # @param options a reference to an options hash.
7308 # @param callback [optional] a reference to a subroutine, which will
7309 # be called with parameters (number progress, string msg, callback_data)
7310 # @param callback_data [optional]
7315 #** @method Update(Geo::OGR::Layer method, Geo::OGR::Layer result, hashref options, coderef callback, $callback_data)
7317 # The result layer contains features whose geometries represent areas
7318 # that are either in the input layer or in the method layer. The
7319 # features in the result layer have areas of the features of the
7320 # method layer or those ares of the features of the input layer that
7321 # are not covered by the method layer. The features of the result
7322 # layer get their attributes from the input layer. The schema of the
7323 # result layer can be set by the user or, if it is empty, is
7324 # initialized to contain all fields in the input layer.
7325 # @param method method layer.
7326 # @param result result layer.
7327 # @param options a reference to an options hash.
7328 # @param callback [optional] a reference to a subroutine, which will
7329 # be called with parameters (number progress, string msg, callback_data)
7330 # @param callback_data [optional]
7335 #** @class Geo::OGR::StyleTable
7337 package Geo::OGR::StyleTable;
7341 #** @method AddStyle()
7351 #** @method GetLastStyleName()
7353 sub GetLastStyleName {
7356 #** @method GetNextStyle()
7361 #** @method LoadStyleTable()
7363 sub LoadStyleTable {
7366 #** @method ResetStyleStringReading()
7368 sub ResetStyleStringReading {
7371 #** @method SaveStyleTable()
7373 sub SaveStyleTable {
7380 my $self = Geo::OGRc::new_StyleTable(@_);
7381 bless $self, $pkg
if defined($self);
7385 # @brief Base class for projection related classes.
7390 #** @method list AngularUnits()
7391 # Package subroutine.
7392 # @return list of known angular units.
7395 return keys %ANGULAR_UNITS;
7398 #** @method CreateCoordinateTransformation()
7400 sub CreateCoordinateTransformation {
7403 #** @method list Datums()
7404 # Package subroutine.
7405 # @return list of known datums.
7408 return keys %DATUMS;
7411 #** @method list GetProjectionMethodParamInfo($projection, $parameter)
7412 # Package subroutine.
7413 # @param projection one of Geo::OSR::Projections
7414 # @param parameter one of Geo::OSR::Parameters
7415 # @return a list ($user_friendly_name, $type, $default_value).
7417 sub GetProjectionMethodParamInfo {
7420 #** @method list GetProjectionMethodParameterList($projection)
7421 # Package subroutine.
7422 # @param projection one of Geo::OSR::Projections
7423 # @return a list (arrayref parameters, $projection_name).
7425 sub GetProjectionMethodParameterList {
7428 #** @method array reference GetProjectionMethods()
7429 # Package subroutine.
7430 # @deprecated Use Geo::OSR::Projections.
7432 # @return reference to an array of possible projection methods.
7434 sub GetProjectionMethods {
7437 #** @method scalar GetUserInputAsWKT($name)
7438 # Package subroutine.
7439 # @param name the user input
7440 # @return a WKT string.
7442 sub GetUserInputAsWKT {
7445 #** @method scalar GetWellKnownGeogCSAsWKT($name)
7446 # Package subroutine.
7447 # @brief Get well known geographic coordinate system as WKT
7448 # @param name a well known name
7449 # @return a WKT string.
7451 sub GetWellKnownGeogCSAsWKT {
7454 #** @method list LinearUnits()
7455 # Package subroutine.
7456 # @return list of known linear units.
7459 return keys %LINEAR_UNITS;
7462 #** @method OAO_Down()
7467 #** @method OAO_East()
7472 #** @method OAO_North()
7477 #** @method OAO_Other()
7482 #** @method OAO_South()
7487 #** @method OAO_Up()
7492 #** @method OAO_West()
7497 #** @method list Parameters()
7498 # Package subroutine.
7499 # @return list of known projection parameters.
7502 return keys %PARAMETERS;
7505 #** @method list Projections()
7506 # Package subroutine.
7507 # @return list of known projections.
7510 return keys %PROJECTIONS;
7513 #** @method RELEASE_PARENT()
7515 sub RELEASE_PARENT {
7518 #** @method SRS_PM_GREENWICH()
7520 sub SRS_PM_GREENWICH {
7523 #** @method SRS_WGS84_INVFLATTENING()
7525 sub SRS_WGS84_INVFLATTENING {
7528 #** @method SRS_WGS84_SEMIMAJOR()
7530 sub SRS_WGS84_SEMIMAJOR {
7533 #** @method SRS_WKT_WGS84()
7538 #** @class Geo::OSR::CoordinateTransformation
7539 # @brief An object for transforming from one projection to another.
7542 package Geo::OSR::CoordinateTransformation;
7546 #** @method array reference TransformPoint($x, $y, $z)
7550 # @param z [optional]
7551 # @return arrayref = [$x, $y, $z]
7553 sub TransformPoint {
7556 #** @method TransformPoints(arrayref points)
7558 # @param points [in/out] a reference to a list of points (line string
7559 # or ring) that is modified in-place. A list of points is: ([x, y, z],
7560 # [x, y, z], ...), where z is optional. Supports also lists of line
7561 # strings and polygons.
7563 sub TransformPoints {
7564 my($self, $points) = @_;
7565 _TransformPoints($self, $points),
return unless ref($points->[0]->[0]);
7566 for my $p (@$points) {
7567 TransformPoints($self, $p);
7571 # This file was automatically generated by SWIG (http://www.swig.org).
7574 # Do not make changes to this file unless you know what you are doing--modify
7575 # the SWIG interface file instead.
7578 #** @method Geo::OSR::CoordinateTransformation new($src, $dst)
7580 # @param src a Geo::OSR::SpatialReference object
7581 # @param dst a Geo::OSR::SpatialReference object
7582 # @return a new Geo::OSR::CoordinateTransformation object
7586 my $self = Geo::OSRc::new_CoordinateTransformation(@_);
7587 bless $self, $pkg
if defined($self);
7590 #** @class Geo::OSR::SpatialReference
7591 # @brief A spatial reference system.
7592 # @details <a href="http://www.gdal.org/classOGRSpatialReference.html">Documentation
7593 # of the underlying C++ class at www.gdal.org</a>
7595 package Geo::OSR::SpatialReference;
7604 #** @method AutoIdentifyEPSG()
7606 # Set EPSG authority info if possible.
7608 sub AutoIdentifyEPSG {
7611 #** @method Geo::OSR::SpatialReference Clone()
7613 # Make a duplicate of this SpatialReference object.
7614 # @return a new Geo::OSR::SpatialReference object
7619 #** @method Geo::OSR::SpatialReference CloneGeogCS()
7621 # Make a duplicate of the GEOGCS node of this SpatialReference object.
7622 # @return a new Geo::OSR::SpatialReference object
7627 #** @method CopyGeogCSFrom($rhs)
7629 # @param rhs Geo::OSR::SpatialReference
7631 sub CopyGeogCSFrom {
7634 #** @method EPSGTreatsAsLatLong()
7636 # Returns TRUE if EPSG feels this geographic coordinate system should be treated as having lat/long coordinate ordering.
7638 sub EPSGTreatsAsLatLong {
7641 #** @method EPSGTreatsAsNorthingEasting()
7643 sub EPSGTreatsAsNorthingEasting {
7646 #** @method Export($format)
7648 # Export the spatial reference to a selected format.
7651 # @param format One of the following. The return value is explained
7652 # after the format. Other arguments are explained in parenthesis.
7653 # - WKT (Text): Well Known Text string
7654 # - PrettyWKT: Well Known Text string nicely formatted (simplify)
7655 # - Proj4: PROJ.4 string
7656 # - PCI: a list: ($proj_string, $units, [$parms1, ...])
7657 # - USGS: a list: ($code, $zone, [$parms1, ...], $datum)
7658 # - GML (XML): GML based string (dialect)
7659 # - MapInfoCS (MICoordSys): MapInfo style co-ordinate system definition
7661 # @note The named parameter syntax also works and is needed is those
7662 # cases when other arguments need or may be given. The format should
7663 # be given using key as, 'to' or 'format'.
7665 # @note ExportTo* and AsText methods also exist but are not documented here.
7667 # @return a scalar or a list depending on the export format
7672 $format = pop
if @_ == 1;
7675 my $simplify = $params{simplify}
7676 my $dialect = $params{dialect}
7678 WKT => sub {
return ExportToWkt($self) },
7679 Text => sub {
return ExportToWkt($self) },
7680 PrettyWKT => sub {
return ExportToPrettyWkt($self, $simplify) },
7681 Proj4 => sub {
return ExportToProj4($self) },
7682 PCI => sub {
return ExportToPCI($self) },
7683 USGS => sub {
return ExportToUSGS($self) },
7684 GML => sub {
return ExportToXML($self, $dialect) },
7685 XML => sub {
return ExportToXML($self, $dialect) },
7686 MICoordSys => sub {
return ExportToMICoordSys() },
7687 MapInfoCS => sub {
return ExportToMICoordSys() },
7689 error(1, $format, \%converters) unless $converters{$format};
7690 return $converters{$format}->();
7699 #** @method FixupOrdering()
7705 #** @method scalar GetAngularUnits()
7709 sub GetAngularUnits {
7712 #** @method GetAngularUnitsName()
7714 sub GetAngularUnitsName {
7717 #** @method scalar GetAttrValue($name, $child = 0)
7726 #** @method scalar GetAuthorityCode($target_key)
7731 sub GetAuthorityCode {
7734 #** @method scalar GetAuthorityName($target_key)
7739 sub GetAuthorityName {
7742 #** @method GetAxisName()
7747 #** @method GetAxisOrientation()
7749 sub GetAxisOrientation {
7752 #** @method GetInvFlattening()
7755 sub GetInvFlattening {
7758 #** @method scalar GetLinearUnits()
7762 sub GetLinearUnits {
7765 #** @method scalar GetLinearUnitsName()
7769 sub GetLinearUnitsName {
7772 #** @method scalar GetNormProjParm($name, $default_val = 0.0)
7775 # @param default_val
7778 sub GetNormProjParm {
7781 #** @method scalar GetProjParm($name, $default_val = 0.0)
7784 # @param default_val
7790 #** @method GetSemiMajor()
7796 #** @method GetSemiMinor()
7802 #** @method GetTOWGS84()
7804 # @return array = ($p1, $p2, $p3, $p4, $p5, $p6, $p7)
7809 #** @method GetTargetLinearUnits()
7811 sub GetTargetLinearUnits {
7814 #** @method GetUTMZone()
7816 # Get UTM zone information.
7817 # @return The UTM zone (integer). In scalar context the returned value
7818 # is negative for southern hemisphere zones. In list context returns
7819 # two values ($zone, $north), where $zone is always non-negative and
7820 # $north is true or false.
7824 my $zone = _GetUTMZone($self);
7831 return ($zone, $north);
7837 #** @method ImportFromOzi()
7842 #** @method scalar IsCompound()
7849 #** @method scalar IsGeocentric()
7856 #** @method scalar IsGeographic()
7863 #** @method scalar IsLocal()
7870 #** @method scalar IsProjected()
7877 #** @method scalar IsSame($rs)
7879 # @param rs a Geo::OSR::SpatialReference object
7885 #** @method scalar IsSameGeogCS($rs)
7887 # @param rs a Geo::OSR::SpatialReference object
7893 #** @method scalar IsSameVertCS($rs)
7895 # @param rs a Geo::OSR::SpatialReference object
7901 #** @method scalar IsVertical()
7908 #** @method MorphFromESRI()
7914 #** @method MorphToESRI()
7920 #** @method Set(%params)
7922 # Set a parameter or parameters in the spatial reference object.
7923 # @param params Named parameters. Recognized keys and respective
7924 # values are the following.
7925 # - Authority: authority name (give also TargetKey, Node and Code)
7927 # - Node: partial or complete path to the target node (Node and Value together sets an attribute value)
7928 # - Code: code for value with an authority
7929 # - Value: value to be assigned to a node, a projection parameter or an object
7930 # - AngularUnits: angular units for the geographic coordinate system (give also Value) (one of Geo::OSR::LinearUnits)
7931 # - LinearUnits: linear units for the target node or the object (give also Value and optionally Node) (one of Geo::OSR::LinearUnits)
7932 # - Parameter: projection parameter to set (give also Value and Normalized) (one of Geo::OSR::Parameters)
7933 # - Normalized: set to true to indicate that the Value argument is in "normalized" form
7934 # - Name: a well known name of a geographic coordinate system (e.g. WGS84)
7935 # - GuessFrom: arbitrary text that specifies a projection ("user input")
7936 # - LOCAL_CS: name of a local coordinate system
7937 # - GeocentricCS: name of a geocentric coordinate system
7938 # - VerticalCS: name of a vertical coordinate system (give also Datum and optionally VertDatumType [default is 2005])
7939 # - Datum: a known (OGC or EPSG) name (or(?) one of Geo::OSR::Datums)
7940 # - 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
7941 # - Parameters: a reference to a list containing the coordinate system or projection parameters
7942 # - Zone: zone for setting up UTM or State Plane coordinate systems (State Plane zone in USGS numbering scheme)
7943 # - North: set false for southern hemisphere
7944 # - NAD83: set false if the NAD27 zone definition should be used instead of NAD83
7945 # - UnitName: to override the legal definition for a zone
7946 # - UnitConversionFactor: to override the legal definition for a zone
7947 # - Spheroid: user visible name
7948 # - HorizontalCS: Horizontal coordinate system name
7949 # - Projection: name of a projection, one of Geo::OSR::Projections (give also optionally Parameters and Variant)
7951 # @note Numerous Set* methods also exist but are not documented here.
7954 my($self, %params) = @_;
7955 if (exists $params{Authority} and exists $params{TargetKey} and exists $params{Node} and exists $params{Code}) {
7956 SetAuthority($self, $params{TargetKey}, $params{Authority}, $params{Code});
7957 } elsif (exists $params{Node} and exists $params{Value}) {
7958 SetAttrValue($self, $params{Node}, $params{Value});
7959 } elsif (exists $params{AngularUnits} and exists $params{Value}) {
7960 SetAngularUnits($self, $params{AngularUnits}, $params{Value});
7961 } elsif (exists $params{LinearUnits} and exists $params{Node} and exists $params{Value}) {
7962 SetTargetLinearUnits($self, $params{Node}, $params{LinearUnits}, $params{Value});
7963 } elsif (exists $params{LinearUnits} and exists $params{Value}) {
7964 SetLinearUnitsAndUpdateParameters($self, $params{LinearUnits}, $params{Value});
7965 } elsif ($params{Parameter} and exists $params{Value}) {
7966 error(1, $params{Parameter}, \%Geo::OSR::PARAMETERS) unless exists $Geo::OSR::PARAMETERS{$params{Parameter}};
7967 $params{Normalized} ?
7968 SetNormProjParm($self, $params{Parameter}, $params{Value}) :
7969 SetProjParm($self, $params{Parameter}, $params{Value});
7970 } elsif (exists $params{Name}) {
7971 SetWellKnownGeogCS($self, $params{Name});
7972 } elsif (exists $params{GuessFrom}) {
7973 SetFromUserInput($self, $params{GuessFrom});
7974 } elsif (exists $params{LOCAL_CS}) {
7975 SetLocalCS($self, $params{LOCAL_CS});
7976 } elsif (exists $params{GeocentricCS}) {
7977 SetGeocCS($self, $params{GeocentricCS});
7978 } elsif (exists $params{VerticalCS} and $params{Datum}) {
7979 my $type = $params{VertDatumType} || 2005;
7980 SetVertCS($self, $params{VerticalCS}, $params{Datum}, $type);
7981 } elsif (exists $params{CoordinateSystem}) {
7982 my @parameters = ();
7983 @parameters = @{$params{Parameters}}
if ref($params{Parameters});
7984 if ($params{CoordinateSystem} eq
'State Plane' and exists $params{Zone}) {
7985 my $NAD83 = exists $params{NAD83} ? $params{NAD83} : 1;
7986 my $name = exists $params{UnitName} ? $params{UnitName} : undef;
7987 my $c = exists $params{UnitConversionFactor} ? $params{UnitConversionFactor} : 0.0;
7988 SetStatePlane($self, $params{Zone}, $NAD83, $name, $c);
7989 } elsif ($params{CoordinateSystem} eq
'UTM' and exists $params{Zone} and exists $params{North}) {
7990 my $north = exists $params{North} ? $params{North} : 1;
7991 SetUTM($self, $params{Zone}, $north);
7992 } elsif ($params{CoordinateSystem} eq
'WGS') {
7993 SetTOWGS84($self, @parameters);
7994 } elsif ($params{CoordinateSystem} and $params{Datum} and $params{Spheroid}) {
7995 SetGeogCS($self, $params{CoordinateSystem}, $params{Datum}, $params{Spheroid}, @parameters);
7996 } elsif ($params{CoordinateSystem} and $params{HorizontalCS} and $params{VerticalCS}) {
7997 SetCompoundCS($self, $params{CoordinateSystem}, $params{HorizontalCS}, $params{VerticalCS});
7999 SetProjCS($self, $params{CoordinateSystem});
8001 } elsif (exists $params{Projection}) {
8002 error(1, $params{Projection}, \%Geo::OSR::PROJECTIONS) unless exists $Geo::OSR::PROJECTIONS{$params{Projection}};
8003 my @parameters = ();
8004 @parameters = @{$params{Parameters}}
if ref($params{Parameters});
8005 if ($params{Projection} eq
'Albers_Conic_Equal_Area') {
8006 SetACEA($self, @parameters);
8007 } elsif ($params{Projection} eq
'Azimuthal_Equidistant') {
8008 SetAE($self, @parameters);
8009 } elsif ($params{Projection} eq
'Bonne') {
8010 SetBonne($self, @parameters);
8011 } elsif ($params{Projection} eq
'Cylindrical_Equal_Area') {
8012 SetCEA($self, @parameters);
8013 } elsif ($params{Projection} eq
'Cassini_Soldner') {
8014 SetCS($self, @parameters);
8015 } elsif ($params{Projection} eq
'Equidistant_Conic') {
8016 SetEC($self, @parameters);
8017 # Eckert_I, Eckert_II, Eckert_III, Eckert_V ?
8018 } elsif ($params{Projection} eq
'Eckert_IV') {
8019 SetEckertIV($self, @parameters);
8020 } elsif ($params{Projection} eq
'Eckert_VI') {
8021 SetEckertVI($self, @parameters);
8022 } elsif ($params{Projection} eq
'Equirectangular') {
8024 SetEquirectangular($self, @parameters) :
8025 SetEquirectangular2($self, @parameters);
8026 } elsif ($params{Projection} eq
'Gauss_Schreiber_Transverse_Mercator') {
8027 SetGaussSchreiberTMercator($self, @parameters);
8028 } elsif ($params{Projection} eq
'Gall_Stereographic') {
8029 SetGS($self, @parameters);
8030 } elsif ($params{Projection} eq
'Goode_Homolosine') {
8031 SetGH($self, @parameters);
8032 } elsif ($params{Projection} eq
'Interrupted_Goode_Homolosine') {
8034 } elsif ($params{Projection} eq
'Geostationary_Satellite') {
8035 SetGEOS($self, @parameters);
8036 } elsif ($params{Projection} eq
'Gnomonic') {
8037 SetGnomonic($self, @parameters);
8038 } elsif ($params{Projection} eq
'Hotine_Oblique_Mercator') {
8039 # Hotine_Oblique_Mercator_Azimuth_Center ?
8040 SetHOM($self, @parameters);
8041 } elsif ($params{Projection} eq
'Hotine_Oblique_Mercator_Two_Point_Natural_Origin') {
8042 SetHOM2PNO($self, @parameters);
8043 } elsif ($params{Projection} eq
'Krovak') {
8044 SetKrovak($self, @parameters);
8045 } elsif ($params{Projection} eq
'Lambert_Azimuthal_Equal_Area') {
8046 SetLAEA($self, @parameters);
8047 } elsif ($params{Projection} eq
'Lambert_Conformal_Conic_2SP') {
8048 SetLCC($self, @parameters);
8049 } elsif ($params{Projection} eq
'Lambert_Conformal_Conic_1SP') {
8050 SetLCC1SP($self, @parameters);
8051 } elsif ($params{Projection} eq
'Lambert_Conformal_Conic_2SP_Belgium') {
8052 SetLCCB($self, @parameters);
8053 } elsif ($params{Projection} eq
'miller_cylindrical') {
8054 SetMC($self, @parameters);
8055 } elsif ($params{Projection} =~ /^Mercator/) {
8056 # Mercator_1SP, Mercator_2SP, Mercator_Auxiliary_Sphere ?
8057 # variant is in Variant (or Name)
8058 SetMercator($self, @parameters);
8059 } elsif ($params{Projection} eq
'Mollweide') {
8060 SetMollweide($self, @parameters);
8061 } elsif ($params{Projection} eq
'New_Zealand_Map_Grid') {
8062 SetNZMG($self, @parameters);
8063 } elsif ($params{Projection} eq
'Oblique_Stereographic') {
8064 SetOS($self, @parameters);
8065 } elsif ($params{Projection} eq
'Orthographic') {
8066 SetOrthographic($self, @parameters);
8067 } elsif ($params{Projection} eq
'Polyconic') {
8068 SetPolyconic($self, @parameters);
8069 } elsif ($params{Projection} eq
'Polar_Stereographic') {
8070 SetPS($self, @parameters);
8071 } elsif ($params{Projection} eq
'Robinson') {
8072 SetRobinson($self, @parameters);
8073 } elsif ($params{Projection} eq
'Sinusoidal') {
8074 SetSinusoidal($self, @parameters);
8075 } elsif ($params{Projection} eq
'Stereographic') {
8076 SetStereographic($self, @parameters);
8077 } elsif ($params{Projection} eq
'Swiss_Oblique_Cylindrical') {
8078 SetSOC($self, @parameters);
8079 } elsif ($params{Projection} eq
'Transverse_Mercator_South_Orientated') {
8080 SetTMSO($self, @parameters);
8081 } elsif ($params{Projection} =~ /^Transverse_Mercator/) {
8082 my($variant) = $params{Projection} =~ /^Transverse_Mercator_(\w+)/;
8085 SetTMVariant($self, $variant, @parameters) :
8086 SetTM($self, @parameters);
8087 } elsif ($params{Projection} eq
'Tunisia_Mining_Grid') {
8088 SetTMG($self, @parameters);
8089 } elsif ($params{Projection} eq
'VanDerGrinten') {
8090 SetVDG($self, @parameters);
8092 # Aitoff, Craster_Parabolic, International_Map_of_the_World_Polyconic, Laborde_Oblique_Mercator
8093 # Loximuthal, Miller_Cylindrical, Quadrilateralized_Spherical_Cube, Quartic_Authalic, Two_Point_Equidistant
8094 # Wagner_I, Wagner_II, Wagner_III, Wagner_IV, Wagner_V, Wagner_VI, Wagner_VII
8095 # Winkel_I, Winkel_II, Winkel_Tripel
8097 SetProjection($self, $params{Projection});
8100 error(
"Not enough information to create a spatial reference object.");
8104 #** @method StripCTParms()
8110 #** @method Validate()
8116 #** @method Geo::OSR::SpatialReference new(%params)
8118 # Create a new spatial reference object using a named parameter. This
8119 # constructor recognizes the following key words (alternative in
8120 # parenthesis): WKT (Text), Proj4, ESRI, EPSG, EPSGA, PCI, USGS, GML
8121 # (XML), URL, ERMapper (ERM), MapInfoCS (MICoordSys). The value
8122 # depends on the key.
8123 # - WKT: Well Known Text string
8124 # - Proj4: PROJ.4 string
8125 # - ESRI: reference to a list of strings (contents of ESRI .prj file)
8126 # - EPSG: EPSG code number
8127 # - EPSGA: EPSG code number (the resulting CS will have EPSG preferred axis ordering)
8128 # - PCI: listref: [PCI_projection_string, Grid_units_code, [17 cs parameters]]
8129 # - USGS: listref: [Projection_system_code, Zone, [15 cs parameters], Datum_code, Format_flag]
8131 # - URL: URL for downloading the spatial reference from
8132 # - ERMapper: listref: [Projection, Datum, Units]
8133 # - MapInfoCS: MapInfo style co-ordinate system definition
8135 # For more information, consult the import methods in <a href="http://www.gdal.org/classOGRSpatialReference.html">OGR documentation</a>.
8137 # @note ImportFrom* methods also exist but are not documented here.
8141 # $sr = Geo::OSR::SpatialReference->new( key => value );
8143 # @return a new Geo::OSR::SpatialReference object
8148 my $self = Geo::OSRc::new_SpatialReference();
8149 if (exists $param{WKT}) {
8150 ImportFromWkt($self, $param{WKT});
8151 } elsif (exists $param{Text}) {
8152 ImportFromWkt($self, $param{Text});
8153 } elsif (exists $param{Proj4}) {
8154 ImportFromProj4($self, $param{Proj4});
8155 } elsif (exists $param{ESRI}) {
8156 ImportFromESRI($self, @{$param{ESRI}});
8157 } elsif (exists $param{EPSG}) {
8158 ImportFromEPSG($self, $param{EPSG});
8159 } elsif (exists $param{EPSGA}) {
8160 ImportFromEPSGA($self, $param{EPSGA});
8161 } elsif (exists $param{PCI}) {
8162 ImportFromPCI($self, @{$param{PCI}});
8163 } elsif (exists $param{USGS}) {
8164 ImportFromUSGS($self, @{$param{USGS}});
8165 } elsif (exists $param{XML}) {
8166 ImportFromXML($self, $param{XML});
8167 } elsif (exists $param{GML}) {
8168 ImportFromGML($self, $param{GML});
8169 } elsif (exists $param{URL}) {
8170 ImportFromUrl($self, $param{URL});
8171 } elsif (exists $param{ERMapper}) {
8172 ImportFromERM($self, @{$param{ERMapper}});
8173 } elsif (exists $param{ERM}) {
8174 ImportFromERM($self, @{$param{ERM}});
8175 } elsif (exists $param{MICoordSys}) {
8176 ImportFromMICoordSys($self, $param{MICoordSys});
8177 } elsif (exists $param{MapInfoCS}) {
8178 ImportFromMICoordSys($self, $param{MapInfoCS});
8179 } elsif (exists $param{WGS}) {
8181 SetWellKnownGeogCS($self,
'WGS'.$param{WGS});
8183 confess last_error() if $@;
8185 error(
"Unrecognized/missing parameters: @_.");
8187 bless $self, $pkg
if defined $self;