2 # @brief GDAL utility functions and a root class for raster classes.
4 # Geo::GDAL wraps many GDAL utility functions and is as a root class
5 # for all GDAL raster classes. A "raster" is an object, whose core is
6 # a rectagular grid of cells, called a "band" in GDAL. Each cell
7 # contains a numeric value of a specific data type.
11 #** @method BuildVRT()
14 for (keys %Geo::GDAL::Const::) {
16 push(@DATA_TYPES, $1), next
if /^GDT_(\w+)/;
17 push(@OPEN_FLAGS, $1), next
if /^OF_(\w+)/;
18 push(@RESAMPLING_TYPES, $1), next
if /^GRA_(\w+)/;
19 push(@RIO_RESAMPLING_TYPES, $1), next
if /^GRIORA_(\w+)/;
20 push(@NODE_TYPES, $1), next
if /^CXT_(\w+)/;
22 for my $string (@DATA_TYPES) {
23 my $int = eval
"\$Geo::GDAL::Const::GDT_$string";
24 $TYPE_STRING2INT{$string} = $int;
25 $TYPE_INT2STRING{$int} = $string;
27 for my $string (@OPEN_FLAGS) {
28 my $int = eval
"\$Geo::GDAL::Const::OF_$string";
29 $OF_STRING2INT{$string} = $int;
31 for my $string (@RESAMPLING_TYPES) {
32 my $int = eval
"\$Geo::GDAL::Const::GRA_$string";
33 $RESAMPLING_STRING2INT{$string} = $int;
34 $RESAMPLING_INT2STRING{$int} = $string;
36 for my $string (@RIO_RESAMPLING_TYPES) {
37 my $int = eval
"\$Geo::GDAL::Const::GRIORA_$string";
38 $RIO_RESAMPLING_STRING2INT{$string} = $int;
39 $RIO_RESAMPLING_INT2STRING{$int} = $string;
41 for my $string (@NODE_TYPES) {
42 my $int = eval
"\$Geo::GDAL::Const::CXT_$string";
43 $NODE_TYPE_STRING2INT{$string} = $int;
44 $NODE_TYPE_INT2STRING{$int} = $string;
47 #** @method CPLBinaryToHex()
52 #** @method CPLHexToBinary()
57 #** @method CreatePansharpenedVRT()
59 sub CreatePansharpenedVRT {
62 #** @method scalar DataTypeIsComplex($DataType)
64 # @param DataType A GDAL raster cell data type (one of those listed by Geo::GDAL::DataTypes).
65 # @return true if the data type is a complex number.
67 sub DataTypeIsComplex {
68 return _DataTypeIsComplex(string2int(shift, \%TYPE_STRING2INT));
71 #** @method list DataTypeValueRange($DataType)
73 # @param DataType Data type (one of those listed by Geo::GDAL::DataTypes).
74 # @note Some returned values are inaccurate.
76 # @return the minimum, maximum range of the data type.
78 sub DataTypeValueRange {
80 Geo::GDAL::error(1, $t, \%TYPE_STRING2INT) unless exists $TYPE_STRING2INT{$t};
81 # these values are from gdalrasterband.cpp
82 return (0,255)
if $t =~ /Byte/;
83 return (0,65535)
if $t =~/UInt16/;
84 return (-32768,32767)
if $t =~/Int16/;
85 return (0,4294967295)
if $t =~/UInt32/;
86 return (-2147483648,2147483647)
if $t =~/Int32/;
87 return (-4294967295.0,4294967295.0)
if $t =~/Float32/;
88 return (-4294967295.0,4294967295.0)
if $t =~/Float64/;
91 #** @method list DataTypes()
93 # @return a list of GDAL raster cell data types. These are currently:
94 # Byte, CFloat32, CFloat64, CInt16, CInt32, Float32, Float64, Int16, Int32, UInt16, UInt32, and Unknown.
100 #** @method scalar DecToDMS($angle, $axis, $precision=2)
101 # Package subroutine.
102 # Convert decimal degrees to degrees, minutes, and seconds string
103 # @param angle A number
104 # @param axis A string specifying latitude or longitude ('Long').
106 # @return a string nndnn'nn.nn'"L where n is a number and L is either
112 #** @method scalar DecToPackedDMS($dec)
113 # Package subroutine.
114 # @param dec Decimal degrees
115 # @return packed DMS, i.e., a number DDDMMMSSS.SS
120 #** @method DontUseExceptions()
121 # Package subroutine.
122 # Do not use the Perl exception mechanism for GDAL messages. Instead
123 # the messages are printed to standard error.
125 sub DontUseExceptions {
128 #** @method Geo::GDAL::Driver Driver($Name)
129 # Package subroutine.
130 # Access a format driver.
131 # @param Name The short name of the driver. One of
132 # Geo::GDAL::DriverNames or Geo::OGR::DriverNames.
133 # @note This subroutine is imported into the main namespace if Geo::GDAL
134 # is used with qw/:all/.
135 # @return a Geo::GDAL::Driver object.
138 return 'Geo::GDAL::Driver' unless @_;
139 return GetDriver(@_);
142 #** @method list DriverNames()
143 # Package subroutine.
144 # Available raster format drivers.
145 # @note Use Geo::OGR::DriverNames for vector drivers.
146 # @return a list of the short names of all available GDAL raster drivers.
151 #** @method list Drivers()
152 # Package subroutine.
153 # @note Use Geo::OGR::Drivers for vector drivers.
154 # @return a list of all available GDAL raster drivers.
158 for my $i (0..GetDriverCount()-1) {
159 my $driver = GetDriver($i);
160 push @drivers, $driver
if $driver->TestCapability(
'RASTER');
165 #** @method EscapeString()
170 #** @method scalar FindFile($basename)
171 # Package subroutine.
172 # Search for GDAL support files.
177 # $a = Geo::GDAL::FindFile('pcs.csv');
178 # print STDERR "$a\n";
180 # Prints (for example):
182 # c:\msys\1.0\local\share\gdal\pcs.csv
185 # @param basename The name of the file to search for. For example
187 # @return the path to the searched file or undef.
197 #** @method FinderClean()
198 # Package subroutine.
199 # Clear the set of support file search paths.
204 #** @method GOA2GetAccessToken()
206 sub GOA2GetAccessToken {
209 #** @method GOA2GetAuthorizationURL()
211 sub GOA2GetAuthorizationURL {
214 #** @method GOA2GetRefreshToken()
216 sub GOA2GetRefreshToken {
219 #** @method scalar GetCacheMax()
220 # Package subroutine.
221 # @return maximum amount of memory (as bytes) for caching within GDAL.
226 #** @method scalar GetCacheUsed()
227 # Package subroutine.
228 # @return the amount of memory currently used for caching within GDAL.
233 #** @method scalar GetConfigOption($key)
234 # Package subroutine.
235 # @param key A GDAL config option. Consult <a
236 # href="https://trac.osgeo.org/gdal/wiki/ConfigOptions">the GDAL
237 # documentation</a> for available options and their use.
238 # @return the value of the GDAL config option.
240 sub GetConfigOption {
243 #** @method scalar GetDataTypeSize($DataType)
244 # Package subroutine.
245 # @param DataType A GDAL raster cell data type (one of those listed by Geo::GDAL::DataTypes).
246 # @return the size as the number of bits.
248 sub GetDataTypeSize {
249 return _GetDataTypeSize(string2int(shift, \%TYPE_STRING2INT, \%TYPE_INT2STRING));
252 #** @method GetJPEG2000StructureAsString()
254 sub GetJPEG2000StructureAsString {
257 #** @method Geo::GDAL::Driver IdentifyDriver($path, $siblings)
258 # Package subroutine.
259 # @param path a dataset path.
260 # @param siblings [optional] A list of names of files that belong to the data format.
261 # @return a Geo::GDAL::Driver.
266 #** @method Geo::GDAL::Dataset Open(%params)
267 # Package subroutine.
269 # An example, which opens an existing raster dataset for editing:
271 # use Geo::GDAL qw/:all/;
272 # $ds = Open(Name => 'existing.tiff', Access => 'Update');
274 # @param params Named parameters:
275 # - \a Name Dataset string (typically a filename). Default is '.'.
276 # - \a Access Access type, either 'ReadOnly' or 'Update'. Default is 'ReadOnly'.
277 # - \a Type Dataset type, either 'Raster', 'Vector', or 'Any'. Default is 'Any'.
278 # - \a Options A hash of GDAL open options passed to candidate drivers. Default is {}.
279 # - \a Files A list of names of files that are auxiliary to the main file. Default is [].
281 # @note This subroutine is imported into the main namespace if Geo::GDAL
282 # is use'd with qw/:all/.
284 # @note Some datasets / dataset strings do not explicitly imply the
285 # dataset type (for example a PostGIS database). If the type is not
286 # specified in such a case the returned dataset may be of either type.
288 # @return a new Geo::GDAL::Dataset object if success.
291 my $p = Geo::GDAL::named_parameters(\@_, Name =>
'.', Access =>
'ReadOnly', Type =>
'Any', Options => {}, Files => []);
293 my %o = (READONLY => 1, UPDATE => 1);
294 Geo::GDAL::error(1, $p->{access}, \%o) unless $o{uc($p->{access})};
295 push @flags, uc($p->{access});
296 %o = (RASTER => 1, VECTOR => 1, ANY => 1);
297 Geo::GDAL::error(1, $p->{type}, \%o) unless $o{uc($p->{type})};
298 push @flags, uc($p->{type}) unless uc($p->{type}) eq
'ANY';
299 my $dataset = OpenEx(Name => $p->{name}, Flags => \@flags, Options => $p->{options}, Files => $p->{files});
301 my $t =
"Failed to open $p->{name}.";
302 $t .=
" Is it a ".lc($p->{type}).
" dataset?" unless uc($p->{type}) eq
'ANY';
308 #** @method Geo::GDAL::Dataset OpenEx(%params)
309 # Package subroutine.
310 # The generic dataset open method, used internally by all Open and OpenShared methods.
311 # @param params Named parameters:
312 # - \a Name The name of the data set or source to open. (Default is '.')
313 # - \a Flags A list of access mode flags. Available flags are listed by Geo::GDAL::OpenFlags(). (Default is [])
314 # - \a Drivers A list of short names of drivers that may be used. Empty list means all. (Default is [])
315 # - \a Options A hash of GDAL open options passed to candidate drivers. (Default is {})
316 # - \a Files A list of names of files that are auxiliary to the main file. (Default is [])
320 # $ds = Geo::GDAL::OpenEx(Name => 'existing.tiff', Flags => [qw/RASTER UPDATE/]);
322 # @return a new Geo::GDAL::Dataset object.
325 my $p = Geo::GDAL::named_parameters(\@_, Name =>
'.', Flags => [], Drivers => [], Options => {}, Files => []);
329 $p = {name => $name, flags => \@flags, drivers => [], options => {}, files => []};
333 for my $flag (@{$p->{flags}}) {
334 Geo::GDAL::error(1, $flag, \%OF_STRING2INT) unless exists $OF_STRING2INT{$flag};
335 $f |= $Geo::GDAL::OF_STRING2INT{$flag};
339 return _OpenEx($p->{name}, $p->{flags}, $p->{drivers}, $p->{options}, $p->{files});
342 #** @method list OpenFlags()
343 # Package subroutine.
344 # @return a list of GDAL data set open modes. These are currently:
345 # ALL, GNM, RASTER, READONLY, SHARED, UPDATE, VECTOR, and VERBOSE_ERROR.
351 #** @method Geo::GDAL::Dataset OpenShared($name, $access = 'ReadOnly')
352 # Package subroutine.
353 # Open a raster dataset in shared mode.
354 # @param name Raster dataset string (typically a filename).
355 # @param access Access type, either 'ReadOnly' (the default) or 'Update'.
356 # @return a new Geo::GDAL::Dataset object or undef.
359 my @p = @_; # name, update
360 my @flags = qw/RASTER SHARED/;
362 Geo::GDAL::error(1, $p[1], {ReadOnly => 1, Update => 1}) unless ($p[1] eq
'ReadOnly' or $p[1] eq
'Update');
363 push @flags, qw/READONLY/
if $p[1] eq
'ReadOnly';
364 push @flags, qw/UPDATE/
if $p[1] eq
'Update';
365 my $dataset = OpenEx($p[0], \@flags);
366 error(
"Failed to open $p[0]. Is it a raster dataset?") unless $dataset;
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 = $TYPE_INT2STRING{$t}
if exists $TYPE_INT2STRING{$t};
383 Geo::GDAL::error(1, $t, \%TYPE_STRING2INT) unless exists $TYPE_STRING2INT{$t};
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 list RIOResamplingTypes()
425 # Package subroutine.
426 # @return a list of GDAL raster IO resampling methods. These are currently:
427 # Average, Bilinear, Cubic, CubicSpline, Gauss, Lanczos, Mode, and NearestNeighbour.
429 sub RIOResamplingTypes {
430 return @RIO_RESAMPLING_TYPES;
433 #** @method list ResamplingTypes()
434 # Package subroutine.
435 # @return a list of GDAL resampling methods. These are currently:
436 # Average, Bilinear, Cubic, CubicSpline, Lanczos, Mode, and NearestNeighbour.
438 sub ResamplingTypes {
439 return @RESAMPLING_TYPES;
442 #** @method SetCacheMax($Bytes)
443 # Package subroutine.
444 # @param Bytes New maximum amount of memory for caching within GDAL.
449 #** @method SetConfigOption($key, $value)
450 # Package subroutine.
451 # @param key A GDAL config option. Consult <a
452 # href="https://trac.osgeo.org/gdal/wiki/ConfigOptions">the GDAL
453 # documentation</a> for available options and their use.
454 # @param value A value for the option, typically 'YES', 'NO',
455 # undef, path, numeric value, or a filename.
457 sub SetConfigOption {
460 #** @method UseExceptions()
461 # Package subroutine.
462 # Use the Perl exception mechanism for GDAL messages (failures are
463 # confessed and warnings are warned) and collect the messages
464 # into \@Geo::GDAL::error. This is the default.
469 #** @method VSIFOpenExL()
474 #** @method VSIGetLastErrorMsg()
476 sub VSIGetLastErrorMsg {
479 #** @method VSIGetLastErrorNo()
481 sub VSIGetLastErrorNo {
484 #** @method scalar VersionInfo($request = 'VERSION_NUM')
485 # Package subroutine.
486 # @param request A string specifying the request. Currently either
487 # "VERSION_NUM", "RELEASE_DATE", "RELEASE_NAME", or
488 # "--version". Default is "VERSION_NUM".
489 # @return Requested information.
494 #** @method scalar errstr()
495 # Package subroutine.
496 # Clear the error stack and return all generated GDAL error messages in one (possibly multiline) string.
497 # @return the chomped error stack joined with newlines.
503 return join(
"\n", @stack);
505 # usage: named_parameters(\@_, key value list of default parameters);
506 # returns parameters in a hash with low-case-without-_ keys
509 #** @class Geo::GDAL::AsyncReader
510 # @brief Enable asynchronous requests.
511 # @todo Test and document.
513 # This class is not yet documented nor tested in the GDAL Perl wrappers
515 package Geo::GDAL::AsyncReader;
519 #** @method GetNextUpdatedRegion()
521 sub GetNextUpdatedRegion {
524 #** @method LockBuffer()
529 #** @method UnlockBuffer()
534 #** @class Geo::GDAL::Band
535 # @brief A raster band.
537 package Geo::GDAL::Band;
543 # scalar (access as $band->{XSize})
548 # scalar (access as $band->{YSize})
551 #** @method Geo::GDAL::RasterAttributeTable AttributeTable($AttributeTable)
553 # @param AttributeTable [optional] A Geo::GDAL::RasterAttributeTable object.
554 # @return a new Geo::GDAL::RasterAttributeTable object, whose data is
555 # contained within the band.
559 SetDefaultRAT($self, $_[0]) if @_ and defined $_[0];
560 return unless defined wantarray;
561 my $r = GetDefaultRAT($self);
562 $RATS{tied(%$r)} = $self
if $r;
566 #** @method list CategoryNames(@names)
568 # @param names [optional]
573 SetRasterCategoryNames($self, \@_) if @_;
574 return unless defined wantarray;
575 my $n = GetRasterCategoryNames($self);
579 #** @method scalar Checksum($xoff = 0, $yoff = 0, $xsize = undef, $ysize = undef)
581 # Computes a checksum from the raster or a part of it.
586 # @return the checksum.
591 #** @method scalar ColorInterpretation($color_interpretation)
593 # @note a.k.a. GetRasterColorInterpretation and GetColorInterpretation
594 # (get only and returns an integer), SetRasterColorInterpretation and
595 # SetColorInterpretation (set only and requires an integer)
596 # @param color_interpretation [optional] new color interpretation, one
597 # of Geo::GDAL::Band::ColorInterpretations.
598 # @return The color interpretation of this band. One of Geo::GDAL::Band::ColorInterpretations.
600 sub ColorInterpretation {
603 $ci = Geo::GDAL::string2int($ci, \%COLOR_INTERPRETATION_STRING2INT);
604 SetRasterColorInterpretation($self, $ci);
606 return unless defined wantarray;
607 $COLOR_INTERPRETATION_INT2STRING{GetRasterColorInterpretation($self)};
610 #** @method ColorInterpretations()
611 # Package subroutine.
612 # @return a list of types of color interpretation for raster
613 # bands. These are currently:
614 # AlphaBand, BlackBand, BlueBand, CyanBand, GrayIndex, GreenBand, HueBand, LightnessBand, MagentaBand, PaletteIndex, RedBand, SaturationBand, Undefined, YCbCr_CbBand, YCbCr_CrBand, YCbCr_YBand, and YellowBand.
616 sub ColorInterpretations {
617 return @COLOR_INTERPRETATIONS;
620 #** @method Geo::GDAL::ColorTable ColorTable($ColorTable)
622 # Get or set the color table of this band.
623 # @param ColorTable [optional] a Geo::GDAL::ColorTable object
624 # @return A new Geo::GDAL::ColorTable object which represents the
625 # internal color table associated with this band. Returns undef this
626 # band does not have an associated color table.
630 SetRasterColorTable($self, $_[0]) if @_ and defined $_[0];
631 return unless defined wantarray;
632 GetRasterColorTable($self);
635 #** @method ComputeBandStats($samplestep = 1)
637 # @param samplestep the row increment in computing the statistics.
638 # @note Returns uncorrected sample standard deviation.
640 # See also Geo::GDAL::Band::ComputeStatistics.
641 # @return a list (mean, stddev).
643 sub ComputeBandStats {
646 #** @method ComputeRasterMinMax($approx_ok = 0)
648 # @return arrayref MinMax = [min, max]
650 sub ComputeRasterMinMax {
653 #** @method list ComputeStatistics($approx_ok, $progress = undef, $progress_data = undef)
655 # @param approx_ok Whether it is allowed to compute the statistics
656 # based on overviews or similar.
657 # @note Returns uncorrected sample standard deviation.
659 # See also Geo::GDAL::Band::ComputeBandStats.
660 # @return a list ($min, $max, $mean, $stddev).
662 sub ComputeStatistics {
665 #** @method Geo::OGR::Layer Contours($DataSource, hashref LayerConstructor, $ContourInterval, $ContourBase, arrayref FixedLevels, $NoDataValue, $IDField, $ElevField, coderef Progress, $ProgressData)
667 # Generate contours for this raster band. This method can also be used with named parameters.
668 # @note This method is a wrapper for ContourGenerate.
673 # $dem = Geo::GDAL::Open('dem.gtiff');
674 # $contours = $dem->Band->Contours(ContourInterval => 10, ElevField => 'z');
675 # $n = $contours->GetFeatureCount;
678 # @param DataSource a Geo::OGR::DataSource object, default is a Memory data source
679 # @param LayerConstructor data for Geo::OGR::DataSource::CreateLayer, default is {Name => 'contours'}
680 # @param ContourInterval default is 100
681 # @param ContourBase default is 0
682 # @param FixedLevels a reference to a list of fixed contour levels, default is []
683 # @param NoDataValue default is undef
684 # @param IDField default is '', i.e., no field (the field is created if this is given)
685 # @param ElevField default is '', i.e., no field (the field is created if this is given)
686 # @param progress [optional] a reference to a subroutine, which will
687 # be called with parameters (number progress, string msg, progress_data)
688 # @param progress_data [optional]
693 my $p = Geo::GDAL::named_parameters(\@_,
695 LayerConstructor => {Name =>
'contours'},
696 ContourInterval => 100,
699 NoDataValue => undef,
703 ProgressData => undef);
705 $p->{layerconstructor}->{Schema}
706 $p->{layerconstructor}->{Schema}{Fields}
708 unless ($p->{idfield} =~ /^[+-]?\d+$/ or $fields{$p->{idfield}}) {
709 push @{$p->{layerconstructor}->{Schema}{Fields}}, {Name => $p->{idfield}, Type =>
'Integer'};
711 unless ($p->{elevfield} =~ /^[+-]?\d+$/ or $fields{$p->{elevfield}}) {
712 my $type = $self->DataType() =~ /Float/ ?
'Real' :
'Integer';
713 push @{$p->{layerconstructor}->{Schema}{Fields}}, {Name => $p->{elevfield}, Type => $type};
715 my $layer = $p->{datasource}->CreateLayer($p->{layerconstructor});
716 my $schema = $layer->GetLayerDefn;
717 for (
'idfield',
'elevfield') {
718 $p->{$_} = $schema->GetFieldIndex($p->{$_}) unless $p->{$_} =~ /^[+-]?\d+$/;
720 $p->{progressdata} = 1
if $p->{progress} and not defined $p->{progressdata};
721 ContourGenerate($self, $p->{contourinterval}, $p->{contourbase}, $p->{fixedlevels},
722 $p->{nodatavalue}, $layer, $p->{idfield}, $p->{elevfield},
723 $p->{progress}, $p->{progressdata});
727 #** @method CreateMaskBand(@flags)
729 # @note May invalidate any previous mask band obtained with Geo::GDAL::Band::GetMaskBand.
731 # @param flags one or more mask flags. The flags are Geo::GDAL::Band::MaskFlags.
736 if (@_ and $_[0] =~ /^\d$/) {
740 carp
"Unknown mask flag: '$flag'." unless $MASK_FLAGS{$flag};
741 $f |= $MASK_FLAGS{$flag};
744 $self->_CreateMaskBand($f);
747 #** @method scalar DataType()
749 # @return The data type of this band. One of Geo::GDAL::DataTypes.
753 return $Geo::GDAL::TYPE_INT2STRING{$self->{DataType}};
756 #** @method Geo::GDAL::Dataset Dataset()
758 # @return The dataset which this band belongs to.
762 return $Geo::GDAL::Dataset::BANDS{tied(%{$self})};
765 #** @method scalar DeleteNoDataValue()
768 sub DeleteNoDataValue {
771 #** @method Geo::GDAL::Band Distance(%params)
773 # Compute distances to specific cells of this raster.
774 # @param params Named parameters:
775 # - \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.
776 # - \a Options Hash of options. Options are:
777 # - \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.
778 # - \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.
779 # - \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.
780 # - \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).
781 # - \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.
782 # - \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.
783 # - \a DataType The data type for the result if it is not given.
784 # - \a Progress Progress function.
785 # - \a ProgressData Additional parameter for the progress function.
787 # @note This GDAL function behind this API is called GDALComputeProximity.
789 # @return The distance raster.
793 my $p = Geo::GDAL::named_parameters(\@_, Distance => undef, Options => undef, Progress => undef, ProgressData => undef);
794 for my $key (keys %{$p->{options}}) {
795 $p->{options}{uc($key)} = $p->{options}{$key};
798 unless ($p->{distance}) {
799 my ($w, $h) = $self->Size;
800 $p->{distance} =
Geo::GDAL::Driver(
'MEM')->
Create(Name =>
'distance', Width => $w, Height => $h, Type => $p->{options}{TYPE})->Band;
802 Geo::GDAL::ComputeProximity($self, $p->{distance}, $p->{options}, $p->{progress}, $p->{progressdata});
803 return $p->{distance};
806 #** @method Domains()
812 #** @method Fill($real_part, $imag_part = 0.0)
814 # Fill the band with a constant value.
815 # @param real_part Real component of fill value.
816 # @param imag_part Imaginary component of fill value.
822 #** @method FillNoData($mask, $max_search_dist, $smoothing_iterations, $options, coderef progress, $progress_data)
824 # Interpolate values for cells in this raster. The cells to fill
825 # should be marked in the mask band with zero.
827 # @param mask [optional] a mask band indicating cells to be interpolated (zero valued) (default is to get it with Geo::GDAL::Band::GetMaskBand).
828 # @param max_search_dist [optional] the maximum number of cells to
829 # search in all directions to find values to interpolate from (default is 10).
830 # @param smoothing_iterations [optional] the number of 3x3 smoothing filter passes to run (0 or more) (default is 0).
831 # @param options [optional] A reference to a hash. No options have been defined so far for this algorithm (default is {}).
832 # @param progress [optional] a reference to a subroutine, which will
833 # be called with parameters (number progress, string msg, progress_data) (default is undef).
834 # @param progress_data [optional] (default is undef).
836 # <a href="http://www.gdal.org/gdal__alg_8h.html">Documentation for GDAL algorithms</a>
841 #** @method FlushCache()
843 # Write cached data to disk. There is usually no need to call this
849 #** @method scalar GetBandNumber()
851 # @return The index of this band in the parent dataset list of bands.
856 #** @method list GetBlockSize()
858 # @return The size of a preferred i/o raster blocks as a list (width,
864 #** @method list GetDefaultHistogram($force = 1, coderef progress = undef, $progress_data = undef)
866 # @param force true to force the computation
867 # @param progress [optional] a reference to a subroutine, which will
868 # be called with parameters (number progress, string msg, progress_data)
869 # @param progress_data [optional]
870 # @note See Note in Geo::GDAL::Band::GetHistogram.
871 # @return a list: ($min, $max, arrayref histogram).
873 sub GetDefaultHistogram {
876 #** @method list GetHistogram(%parameters)
878 # Compute histogram from the raster.
879 # @param parameters Named parameters:
880 # - \a Min the lower bound, default is -0.5
881 # - \a Max the upper bound, default is 255.5
882 # - \a Buckets the number of buckets in the histogram, default is 256
883 # - \a IncludeOutOfRange whether to use the first and last values in the returned list
884 # for out of range values, default is false;
885 # the bucket size is (Max-Min) / Buckets if this is false and
886 # (Max-Min) / (Buckets-2) if this is true
887 # - \a ApproxOK if histogram can be computed from overviews, default is false
888 # - \a Progress an optional progress function, the default is undef
889 # - \a ProgressData data for the progress function, the default is undef
890 # @note Histogram counts are treated as strings in the bindings to be
891 # able to use large integers (if GUIntBig is larger than Perl IV). In
892 # practice this is only important if you have a 32 bit machine and
893 # very large bucket counts. In those cases it may also be necessary to
895 # @return a list which contains the count of values in each bucket
899 my $p = Geo::GDAL::named_parameters(\@_,
903 IncludeOutOfRange => 0,
906 ProgressData => undef);
907 $p->{progressdata} = 1
if $p->{progress} and not defined $p->{progressdata};
908 _GetHistogram($self, $p->{min}, $p->{max}, $p->{buckets},
909 $p->{includeoutofrange}, $p->{approxok},
910 $p->{progress}, $p->{progressdata});
913 #** @method Geo::GDAL::Band GetMaskBand()
915 # @return the mask band associated with this
920 my $band = _GetMaskBand($self);
921 $Geo::GDAL::Dataset::BANDS{tied(%{$band})} = $self;
925 #** @method list GetMaskFlags()
927 # @return the mask flags of the mask band associated with this
928 # band. The flags are one or more of Geo::GDAL::Band::MaskFlags.
932 my $f = $self->_GetMaskFlags;
934 for my $flag (keys %MASK_FLAGS) {
935 push @f, $flag
if $f & $MASK_FLAGS{$flag};
937 return wantarray ? @f : $f;
940 #** @method scalar GetMaximum()
942 # @note Call Geo::GDAL::Band::ComputeStatistics before calling
943 # GetMaximum to make sure the value is computed.
945 # @return statistical minimum of the band or undef if statistics are
946 # not kept or computed in scalar context. In list context returns the
947 # maximum value or a (kind of) maximum value supported by the data
948 # type and a boolean value, which indicates which is the case (true is
949 # first, false is second).
954 #** @method scalar GetMinimum()
956 # @note Call Geo::GDAL::Band::ComputeStatistics before calling
957 # GetMinimum to make sure the value is computed.
959 # @return statistical minimum of the band or undef if statistics are
960 # not kept or computed in scalar context. In list context returns the
961 # minimum value or a (kind of) minimum value supported by the data
962 # type and a boolean value, which indicates which is the case (true is
963 # first, false is second).
968 #** @method Geo::GDAL::Band GetOverview($index)
970 # @param index 0..GetOverviewCount-1
971 # @return a Geo::GDAL::Band object, which represents the internal
972 # overview band, or undef. if the index is out of bounds.
975 my ($self, $index) = @_;
976 my $band = _GetOverview($self, $index);
977 $Geo::GDAL::Dataset::BANDS{tied(%{$band})} = $self;
981 #** @method scalar GetOverviewCount()
983 # @return the number of overviews available of the band.
985 sub GetOverviewCount {
988 #** @method list GetStatistics($approx_ok, $force)
990 # @param approx_ok Whether it is allowed to compute the statistics
991 # based on overviews or similar.
992 # @param force Whether to force scanning of the whole raster.
993 # @note Uses Geo::GDAL::Band::ComputeStatistics internally.
995 # @return a list ($min, $max, $mean, $stddev).
1000 #** @method HasArbitraryOverviews()
1002 # @return true or false.
1004 sub HasArbitraryOverviews {
1007 #** @method list MaskFlags()
1008 # Package subroutine.
1009 # @return the list of mask flags. These are
1010 # - \a AllValid: There are no invalid cell, all mask values will be 255.
1011 # When used this will normally be the only flag set.
1012 # - \a PerDataset: The mask band is shared between all bands on the dataset.
1013 # - \a Alpha: The mask band is actually an alpha band and may have values
1014 # other than 0 and 255.
1015 # - \a NoData: Indicates the mask is actually being generated from nodata values.
1016 # (mutually exclusive of Alpha).
1019 my @f = sort {$MASK_FLAGS{$a} <=> $MASK_FLAGS{$b}} keys %MASK_FLAGS;
1023 #** @method scalar NoDataValue($NoDataValue)
1025 # Remove no data value from this band.
1026 # @param NoDataValue [optional]
1027 # Get or set the "no data" value.
1028 # @note $band->NoDataValue(undef) sets the "no data" value to the
1029 # Posix floating point maximum. Use Geo::GDAL::Band::DeleteNoDataValue
1030 # to remove no data value from this band.
1031 # @return The "no data" value or undef in scalar context. An undef
1032 # value indicates that there is no no data value associated with this
1038 if (defined $_[0]) {
1039 SetNoDataValue($self, $_[0]);
1041 SetNoDataValue($self, POSIX::FLT_MAX); # hopefully an
"out of range" value
1044 GetNoDataValue($self);
1047 #** @method scalar PackCharacter()
1049 # @return The character to use in Perl pack and unpack for the data of this band.
1056 #** @method Piddle()
1059 my $self = shift; # should use named parameters
for read raster and band
1060 # add Piddle sub to dataset too to make N x M x n piddles
1061 my ($w, $h) = $self->Size;
1062 my $data = $self->ReadRaster;
1077 my $datatype = $map{$self->DataType};
1078 croak
"there is no direct mapping between the band datatype and PDL" if $datatype < 0;
1079 $pdl->set_datatype($datatype);
1080 $pdl->setdims([1,$w,$h]);
1081 my $dref = $pdl->get_dataref();
1087 #** @method Geo::OGR::Layer Polygonize(%params)
1089 # Polygonize this raster band.
1091 # @param params Named parameters:
1092 # - \a Mask A raster band, which is used as a mask to select polygonized areas. Default is undef.
1093 # - \a OutLayer A vector layer into which the polygons are written. If not given, an in-memory layer 'polygonized' is created and returned.
1094 # - \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'.
1095 # - \a Options Hash or list of options. Connectedness can be set to 4 to use 4-connectedness, otherwise 8-connectedness is used. ForceIntPixel can be set to 1 to force using a 32 bit int buffer for cell values in the process. If this is not set and the data type of this raster does not fit into a 32 bit int buffer, a 32 bit float buffer is used.
1096 # - \a Progress Progress function.
1097 # - \a ProgressData Additional parameter for the progress function.
1099 # @return Output vector layer.
1103 my $p = Geo::GDAL::named_parameters(\@_, Mask => undef, OutLayer => undef, PixValField =>
'val', Options => undef, Progress => undef, ProgressData => undef);
1104 my $dt = $self->DataType;
1105 my %leInt32 = (Byte => 1, Int16 => 1, Int32 => 1, UInt16 => 1);
1106 my $leInt32 = $leInt32{$dt};
1107 $dt = $dt =~ /Float/ ?
'Real' :
'Integer';
1109 CreateLayer(Name =>
'polygonized',
1110 Fields => [{Name =>
'val', Type => $dt},
1111 {Name =>
'geom', Type =>
'Polygon'}]);
1112 $p->{pixvalfield} = $p->{outlayer}->GetLayerDefn->GetFieldIndex($p->{pixvalfield});
1113 $p->{options}{
'8CONNECTED'} = $p->{options}{Connectedness}
if $p->{options}{Connectedness};
1114 if ($leInt32 || $p->{options}{ForceIntPixel}) {
1115 Geo::GDAL::_Polygonize($self, $p->{mask}, $p->{outlayer}, $p->{pixvalfield}, $p->{options}, $p->{progress}, $p->{progressdata});
1117 Geo::GDAL::FPolygonize($self, $p->{mask}, $p->{outlayer}, $p->{pixvalfield}, $p->{options}, $p->{progress}, $p->{progressdata});
1119 set the srs of the outlayer
if it was created here
1120 return $p->{outlayer};
1123 #** @method RasterAttributeTable()
1125 sub RasterAttributeTable {
1128 #** @method scalar ReadRaster(%params)
1130 # Read data from the band.
1132 # @param params Named parameters:
1133 # - \a XOff x offset (cell coordinates) (default is 0)
1134 # - \a YOff y offset (cell coordinates) (default is 0)
1135 # - \a XSize width of the area to read (default is the width of the band)
1136 # - \a YSize height of the area to read (default is the height of the band)
1137 # - \a BufXSize (default is undef, i.e., the same as XSize)
1138 # - \a BufYSize (default is undef, i.e., the same as YSize)
1139 # - \a BufType data type of the buffer (default is the data type of the band)
1140 # - \a BufPixelSpace (default is 0)
1141 # - \a BufLineSpace (default is 0)
1142 # - \a ResampleAlg one of Geo::GDAL::RIOResamplingTypes (default is 'NearestNeighbour'),
1143 # - \a Progress reference to a progress function (default is undef)
1144 # - \a ProgressData (default is undef)
1146 # <a href="http://www.gdal.org/classGDALDataset.html">Entry in GDAL docs (method RasterIO)</a>
1147 # @return a buffer, open the buffer with \a unpack function of Perl. See Geo::GDAL::Band::PackCharacter.
1151 my ($width, $height) = $self->Size;
1152 my ($type) = $self->DataType;
1153 my $p = Geo::GDAL::named_parameters(\@_,
1163 ResampleAlg =>
'NearestNeighbour',
1165 ProgressData => undef
1167 $p->{resamplealg} = Geo::GDAL::string2int($p->{resamplealg}, \%Geo::GDAL::RIO_RESAMPLING_STRING2INT);
1168 $p->{buftype} = Geo::GDAL::string2int($p->{buftype}, \%Geo::GDAL::TYPE_STRING2INT, \%Geo::GDAL::TYPE_INT2STRING);
1169 $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});
1172 #** @method array reference ReadTile($xoff = 0, $yoff = 0, $xsize = <width>, $ysize = <height>)
1175 # Usage example (print the data from a band):
1177 # print "@$_\n" for ( @{ $band->ReadTile() } );
1179 # Another usage example (process the data of a large dataset that has one band):
1181 # my($W,$H) = $dataset->Band(1)->Size();
1182 # my($xoff,$yoff,$w,$h) = (0,0,200,200);
1184 # . if ($xoff >= $W) {
1187 # . last if $yoff >= $H;
1189 # . my $data = $dataset->Band(1)->ReadTile($xoff,$yoff,min($W-$xoff,$w),min($H-$yoff,$h));
1190 # . # add your data processing code here
1191 # . $dataset->Band(1)->WriteTile($data,$xoff,$yoff);
1196 # . return $_[0] < $_[1] ? $_[0] : $_[1];
1199 # @param xoff Number of cell to skip before starting to read from a row. Pixels are read from left to right.
1200 # @param yoff Number of cells to skip before starting to read from a column. Pixels are read from top to bottom.
1201 # @param xsize Number of cells to read from each row.
1202 # @param ysize Number of cells to read from each column.
1203 # @return a two-dimensional Perl array, organizes as data->[y][x], y =
1204 # 0..height-1, x = 0..width-1. I.e., y is row and x is column.
1207 my($self, $xoff, $yoff, $xsize, $ysize, $w_tile, $h_tile, $alg) = @_;
1215 my $t = $self->{DataType};
1216 $alg = Geo::GDAL::string2int($alg, \%Geo::GDAL::RIO_RESAMPLING_STRING2INT);
1217 my $buf = $self->_ReadRaster($xoff, $yoff, $xsize, $ysize, $w_tile, $h_tile, $t, 0, 0, $alg);
1222 for my $y (0..$h_tile-1) {
1223 my @d = unpack($pc.
"[$w_tile]", substr($buf, $offset, $w));
1230 #** @method RegenerateOverview(Geo::GDAL::Band overview, $resampling, coderef progress, $progress_data)
1232 # @param overview a Geo::GDAL::Band object for the overview.
1233 # @param resampling [optional] the resampling method (one of Geo::GDAL::RIOResamplingTypes) (default is Average).
1234 # @param progress [optional] a reference to a subroutine, which will
1235 # be called with parameters (number progress, string msg, progress_data)
1236 # @param progress_data [optional]
1238 sub RegenerateOverview {
1240 #Geo::GDAL::Band overview, scalar resampling, subref callback, scalar callback_data
1242 Geo::GDAL::RegenerateOverview($self, @p);
1245 #** @method RegenerateOverviews(arrayref overviews, $resampling, coderef progress, $progress_data)
1247 # @todo This is not yet available
1249 # @param overviews a list of Geo::GDAL::Band objects for the overviews.
1250 # @param resampling [optional] the resampling method (one of Geo::GDAL::RIOResamplingTypes) (default is Average).
1251 # @param progress [optional] a reference to a subroutine, which will
1252 # be called with parameters (number progress, string msg, progress_data)
1253 # @param progress_data [optional]
1255 sub RegenerateOverviews {
1257 #arrayref overviews, scalar resampling, subref callback, scalar callback_data
1259 Geo::GDAL::RegenerateOverviews($self, @p);
1262 #** @method ScaleAndOffset($scale, $offset)
1264 # Scale and offset are used to transform raw cell values into the
1265 # units returned by GetUnits(). The conversion function is:
1267 # Units value = (raw value * scale) + offset
1269 # @return a list ($scale, $offset), the values are undefined if they
1271 # @since version 1.9 of the bindings.
1273 sub ScaleAndOffset {
1275 SetScale($self, $_[0]) if @_ > 0 and defined $_[0];
1276 SetOffset($self, $_[1]) if @_ > 1 and defined $_[1];
1277 return unless defined wantarray;
1278 my $scale = GetScale($self);
1279 my $offset = GetOffset($self);
1280 return ($scale, $offset);
1283 #** @method list SetDefaultHistogram($min, $max, $histogram)
1287 # @note See Note in Geo::GDAL::Band::GetHistogram.
1288 # @param histogram reference to an array containing the histogram
1290 sub SetDefaultHistogram {
1293 #** @method SetStatistics($min, $max, $mean, $stddev)
1295 # Save the statistics of the band if possible (the format can save
1296 # arbitrary metadata).
1305 #** @method Geo::GDAL::Band Sieve(%params)
1307 # Remove small areas by merging them into the largest neighbour area.
1308 # @param params Named parameters:
1309 # - \a Mask A raster band, which is used as a mask to select sieved areas. Default is undef.
1310 # - \a Dest A raster band into which the result is written. If not given, an new in-memory raster band is created and returned.
1311 # - \a Threshold The smallest area size (in number of cells) which are not sieved away.
1312 # - \a Options Hash or list of options. {Connectedness => 4} can be specified to use 4-connectedness, otherwise 8-connectedness is used.
1313 # - \a Progress Progress function.
1314 # - \a ProgressData Additional parameter for the progress function.
1316 # @return The filtered raster band.
1320 my $p = Geo::GDAL::named_parameters(\@_, Mask => undef, Dest => undef, Threshold => 10, Options => undef, Progress => undef, ProgressData => undef);
1321 unless ($p->{dest}) {
1322 my ($w, $h) = $self->Size;
1326 if ($p->{options}{Connectedness}) {
1327 $c = $p->{options}{Connectedness};
1328 delete $p->{options}{Connectedness};
1330 Geo::GDAL::SieveFilter($self, $p->{mask}, $p->{dest}, $p->{threshold}, $c, $p->{options}, $p->{progress}, $p->{progressdata});
1334 #** @method list Size()
1336 # @return The size of the band as a list (width, height).
1340 return ($self->{XSize}, $self->{YSize});
1343 #** @method Unit($type)
1345 # @param type [optional] the unit (a string).
1346 # @note $band->Unit(undef) sets the unit value to an empty string.
1347 # @return the unit (a string).
1348 # @since version 1.9 of the bindings.
1355 SetUnitType($self, $unit);
1357 return unless defined wantarray;
1361 #** @method WriteRaster(%params)
1363 # Write data into the band.
1365 # @param params Named parameters:
1366 # - \a XOff x offset (cell coordinates) (default is 0)
1367 # - \a YOff y offset (cell coordinates) (default is 0)
1368 # - \a XSize width of the area to write (default is the width of the band)
1369 # - \a YSize height of the area to write (default is the height of the band)
1370 # - \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.
1371 # - \a BufXSize (default is undef, i.e., the same as XSize)
1372 # - \a BufYSize (default is undef, i.e., the same as YSize)
1373 # - \a BufType data type of the buffer (default is the data type of the band)
1374 # - \a BufPixelSpace (default is 0)
1375 # - \a BufLineSpace (default is 0)
1377 # <a href="http://www.gdal.org/classGDALDataset.html">Entry in GDAL docs (method RasterIO)</a>
1381 my ($width, $height) = $self->Size;
1382 my ($type) = $self->DataType;
1383 my $p = Geo::GDAL::named_parameters(\@_,
1395 confess
"Usage: \$band->WriteRaster( Buf => \$data, ... )" unless defined $p->{buf};
1396 $p->{buftype} = Geo::GDAL::string2int($p->{buftype}, \%Geo::GDAL::TYPE_STRING2INT, \%Geo::GDAL::TYPE_INT2STRING);
1397 $self->_WriteRaster($p->{xoff},$p->{yoff},$p->{xsize},$p->{ysize},$p->{buf},$p->{bufxsize},$p->{bufysize},$p->{buftype},$p->{bufpixelspace},$p->{buflinespace});
1400 #** @method WriteTile($data, $xoff = 0, $yoff = 0)
1402 # @param data A two-dimensional Perl array, organizes as data->[y][x], y =
1403 # 0..height-1, x = 0..width-1.
1409 my($self, $data, $xoff, $yoff) = @_;
1412 my $xsize = @{$data->[0]};
1413 if ($xsize > $self->{XSize} - $xoff) {
1414 warn
"Buffer XSize too large ($xsize) for this raster band (width = $self->{XSize}, offset = $xoff).";
1415 $xsize = $self->{XSize} - $xoff;
1417 my $ysize = @{$data};
1418 if ($ysize > $self->{YSize} - $yoff) {
1419 $ysize = $self->{YSize} - $yoff;
1420 warn
"Buffer YSize too large ($ysize) for this raster band (height = $self->{YSize}, offset = $yoff).";
1423 for my $i (0..$ysize-1) {
1424 my $scanline = pack($pc.
"[$xsize]", @{$data->[$i]});
1425 $self->WriteRaster( $xoff, $yoff+$i, $xsize, 1, $scanline );
1429 #** @class Geo::GDAL::ColorTable
1430 # @brief A color table from a raster band or a color table, which can be used for a band.
1432 package Geo::GDAL::ColorTable;
1436 #** @method Geo::GDAL::ColorTable Clone()
1438 # Clone an existing color table.
1439 # @return a new Geo::GDAL::ColorTable object
1444 #** @method list Color($index, @color)
1446 # Get or set a color in this color table.
1447 # @param index The index of the color in the table. Note that the
1448 # color table may expand if the index is larger than the current max
1449 # index of this table and a color is given. An attempt to retrieve a
1450 # color out of the current size of the table causes an error.
1451 # @param color [optional] The color, either a list or a reference to a
1452 # list. If the list is too short or has undef values, the undef values
1453 # are taken as 0 except for alpha, which is taken as 255.
1454 # @note A color is an array of four integers having a value between 0
1455 # and 255: (gray, red, cyan or hue; green, magenta, or lightness;
1456 # blue, yellow, or saturation; alpha or blackband)
1457 # @return A color, in list context a list and in scalar context a reference to an anonymous array.
1462 #** @method list Colors(@colors)
1464 # Get or set the colors in this color table.
1465 # @note The color table will expand to the size of the input list but
1466 # it will not shrink.
1467 # @param colors [optional] A list of all colors (a list of lists) for this color table.
1468 # @return A list of colors (a list of lists).
1473 #** @method CreateColorRamp($start_index, arrayref start_color, $end_index, arrayref end_color)
1475 # @param start_index
1476 # @param start_color
1480 sub CreateColorRamp {
1483 #** @method scalar GetCount()
1485 # @return The number of colors in this color table.
1490 #** @method scalar GetPaletteInterpretation()
1492 # @return palette interpretation (string)
1494 sub GetPaletteInterpretation {
1496 return $PALETTE_INTERPRETATION_INT2STRING{GetPaletteInterpretation($self)};
1499 #** @method Geo::GDAL::ColorTable new($GDALPaletteInterp = 'RGB')
1501 # Create a new empty color table.
1502 # @return a new Geo::GDAL::ColorTable object
1507 $pi = Geo::GDAL::string2int($pi, \%PALETTE_INTERPRETATION_STRING2INT);
1508 my $self = Geo::GDALc::new_ColorTable($pi);
1509 bless $self, $pkg
if defined($self);
1512 #** @class Geo::GDAL::Dataset
1513 # @brief A set of associated raster bands or vector layer source.
1515 package Geo::GDAL::Dataset;
1519 #** @attr $RasterCount
1520 # scalar (access as $dataset->{RasterCount})
1523 #** @attr $RasterXSize
1524 # scalar (access as $dataset->{RasterXSize})
1527 #** @attr $RasterYSize
1528 # scalar (access as $dataset->{RasterYSize})
1531 #** @method AddBand($datatype = 'Byte', hashref options = {})
1533 # Add a new band to the dataset. The driver must support the action.
1534 # @param datatype GDAL raster cell data type (one of those listed by Geo::GDAL::DataTypes).
1535 # @param options reference to a hash of format specific options.
1536 # @return The added band.
1539 my ($self, $type, $options) = @_;
1541 $type = Geo::GDAL::string2int($type, \%Geo::GDAL::TYPE_STRING2INT);
1542 $self->_AddBand($type, $options);
1543 return unless defined wantarray;
1544 return $self->GetRasterBand($self->{RasterCount});
1547 #** @method Geo::GDAL::Band Band($index)
1549 # Create a band object for the band within the dataset.
1550 # @note a.k.a. GetRasterBand
1551 # @param index 1...RasterCount
1552 # @return a new Geo::GDAL::Band object
1557 #** @method list Bands()
1559 # @return a list of new Geo::GDAL::Band objects
1564 for my $i (1..$self->{RasterCount}) {
1565 push @bands, GetRasterBand($self, $i);
1570 #** @method BuildOverviews($resampling, arrayref overviews, coderef progress, $progress_data)
1572 # @param resampling the resampling method, one of Geo::GDAL::RIOResamplingTypes.
1573 # @param overviews The list of overview decimation factors to
1574 # build. For example [2,4,8].
1575 # @param progress [optional] a reference to a subroutine, which will
1576 # be called with parameters (number progress, string msg, progress_data)
1577 # @param progress_data [optional]
1579 sub BuildOverviews {
1582 $p[0] = uc($p[0]) if $p[0];
1584 $self->_BuildOverviews(@p);
1586 confess(Geo::GDAL->last_error) if $@;
1589 #** @method Geo::GDAL::Dataset BuildVRT($Dest, arrayref Sources, $Options, coderef progress, $progress_data)
1591 # Build a virtual dataset from a set of datasets.
1592 # @param Dest Destination raster dataset definition string (typically
1593 # filename), or an object, which implements write and close.
1594 # @param Sources A list of filenames of input datasets or a list of
1596 # @param Options A reference to a hash or list of options. For a hash
1597 # the keys are without the prefix '-' and the values must be
1598 # strings. For example give { r => 'cubic' } to select a resampling
1599 # algorithm. For a list the options are given as for the command line
1601 # href="http://www.gdal.org/gdalbuildvrt.html">gdalbuildvrt</a> for a
1602 # complete list of options.
1603 # @return Dataset object
1605 # @note This subroutine is imported into the main namespace if Geo::GDAL
1606 # is use'd with qw/:all/.
1609 my ($dest, $sources, $options, $progress, $progress_data) = @_;
1610 $options = Geo::GDAL::GDALBuildVRTOptions->new(Geo::GDAL::make_processing_options($options));
1611 Geo::GDAL::error(
"Usage: Geo::GDAL::DataSet::BuildVRT(\$vrt_file_name, \\\@sources)")
1612 unless ref $sources eq 'ARRAY' && defined $sources->[0];
1613 unless (blessed($dest)) {
1614 if (blessed($sources->[0])) {
1615 return Geo::GDAL::wrapper_GDALBuildVRT_objects($dest, $sources, $options, $progress, $progress_data);
1617 return Geo::GDAL::wrapper_GDALBuildVRT_names($dest, $sources, $options, $progress, $progress_data);
1620 if (blessed($sources->[0])) {
1621 return stdout_redirection_wrapper(
1623 \&Geo::GDAL::wrapper_GDALBuildVRT_objects,
1624 $options, $progress, $progress_data);
1626 return stdout_redirection_wrapper(
1628 \&Geo::GDAL::wrapper_GDALBuildVRT_names,
1629 $options, $progress, $progress_data);
1634 #** @method CommitTransaction()
1636 sub CommitTransaction {
1639 #** @method Geo::GDAL::ColorTable ComputeColorTable(%params)
1641 # Compute a color table from an RGB image
1642 # @param params Named parameters:
1643 # - \a Red The red band, the default is to use the red band of this dataset.
1644 # - \a Green The green band, the default is to use the green band of this dataset.
1645 # - \a Blue The blue band, the default is to use the blue band of this dataset.
1646 # - \a NumColors The number of colors in the computed color table. Default is 256.
1647 # - \a Progress reference to a progress function (default is undef)
1648 # - \a ProgressData (default is undef)
1649 # - \a Method The computation method. The default and currently only option is the median cut algorithm.
1651 # @return a new color table object.
1653 sub ComputeColorTable {
1655 my $p = Geo::GDAL::named_parameters(\@_,
1661 ProgressData => undef,
1662 Method =>
'MedianCut');
1663 for my $b ($self->Bands) {
1664 for my $cion ($b->ColorInterpretation) {
1665 if ($cion eq
'RedBand') { $p->{red}
1666 if ($cion eq
'GreenBand') { $p->{green}
1667 if ($cion eq
'BlueBand') { $p->{blue}
1671 Geo::GDAL::ComputeMedianCutPCT($p->{red},
1675 $ct, $p->{progress},
1676 $p->{progressdata});
1680 #** @method Geo::OGR::Layer CopyLayer($layer, $name, hashref options = undef)
1682 # @param layer A Geo::OGR::Layer object to be copied.
1683 # @param name A name for the new layer.
1684 # @param options A ref to a hash of format specific options.
1685 # @return a new Geo::OGR::Layer object.
1690 #** @method Geo::OGR::Layer CreateLayer(%params)
1692 # @brief Create a new vector layer into this dataset.
1694 # @param %params Named parameters:
1695 # - \a Name (scalar) name for the new layer.
1696 # - \a Fields (array reference) a list of (scalar and geometry) field definitions as in
1697 # Geo::OGR::Layer::CreateField.
1698 # - \a ApproxOK (boolean value, default is true) a flag, which is forwarded to Geo::OGR::Layer::CreateField.
1699 # - \a Options (hash reference) driver specific hash of layer creation options.
1700 # - \a Schema (hash reference, deprecated, use \a Fields and \a Name) may contain keys Name, Fields, GeomFields, GeometryType.
1701 # - \a SRS (scalar, deprecated) the spatial reference for the default geometry field.
1702 # - \a GeometryType (scalar) the type of the default geometry field
1703 # (if only one geometry field). Default is 'Unknown'.
1705 # @note If Fields or Schema|Fields is not given, a default geometry
1706 # field (Name => '', GeometryType => 'Unknown') is created. If it is
1707 # given and it contains spatial fields, GeometryType is ignored. The
1708 # type can be also set with the named parameter.
1712 # my $roads = Geo::OGR::Driver('Memory')->Create('road')->
1714 # . Fields => [ { Name => 'class',
1715 # . Type => 'Integer' },
1716 # . { Name => 'geom',
1717 # . Type => 'LineString25D' } ] );
1720 # @note Many formats allow only one spatial field, which currently
1721 # requires the use of GeometryType.
1723 # @return a new Geo::OGR::Layer object.
1727 my $p = Geo::GDAL::named_parameters(\@_,
1730 GeometryType =>
'Unknown',
1735 Geo::GDAL::error(
"The 'Fields' argument must be an array reference.") if $p->{fields} && ref($p->{fields}) ne
'ARRAY';
1736 if (defined $p->{schema}) {
1737 my $s = $p->{schema};
1738 $p->{geometrytype} = $s->{GeometryType}
if exists $s->{GeometryType};
1739 $p->{fields} = $s->{Fields}
if exists $s->{Fields};
1740 $p->{name} = $s->{Name}
if exists $s->{Name};
1742 $p->{fields} = [] unless ref($p->{fields}) eq
'ARRAY';
1743 # if fields contains spatial fields, then do not create default one
1744 for my $f (@{$p->{fields}}) {
1745 if ($f->{GeometryType} or exists $Geo::OGR::Geometry::TYPE_STRING2INT{$f->{Type}}) {
1746 $p->{geometrytype} =
'None';
1750 my $gt = Geo::GDAL::string2int($p->{geometrytype}, \%Geo::OGR::Geometry::TYPE_STRING2INT);
1751 my $layer = _CreateLayer($self, $p->{name}, $p->{srs}, $gt, $p->{options});
1752 $LAYERS{tied(%$layer)} = $self;
1753 for my $f (@{$p->{fields}}) {
1754 $layer->CreateField($f);
1759 #** @method CreateMaskBand()
1761 # Add a mask band to the dataset.
1763 sub CreateMaskBand {
1764 return _CreateMaskBand(@_);
1767 #** @method Geo::GDAL::Dataset DEMProcessing($Dest, $Processing, $ColorFilename, $Options, coderef progress, $progress_data)
1769 # Apply a DEM processing to this dataset.
1770 # @param Dest Destination raster dataset definition string (typically filename) or an object, which implements write and close.
1771 # @param Processing Processing to apply, one of "hillshade", "slope", "aspect", "color-relief", "TRI", "TPI", or "Roughness".
1772 # @param ColorFilename The color palette for color-relief.
1773 # @param Options A reference to a hash or list of options. For a hash
1774 # the keys are without the prefix '-'. For example give { of => 'PNG'
1775 # } to set the output format. For a list the options are given as for
1776 # the command line utility. See <a
1777 # href="http://www.gdal.org/gdaldem.html">gdaldem</a> for all options.
1778 # @param progress [optional] A reference to a subroutine, which will
1779 # be called with parameters (number progress, string msg, progress_data).
1780 # @param progress_data [optional]
1784 my ($self, $dest, $Processing, $ColorFilename, $options, $progress, $progress_data) = @_;
1785 $options = Geo::GDAL::GDALDEMProcessingOptions->new(Geo::GDAL::make_processing_options($options));
1786 return $self->stdout_redirection_wrapper(
1788 \&Geo::GDAL::wrapper_GDALDEMProcessing,
1789 $Processing, $ColorFilename, $options, $progress, $progress_data
1793 #** @method Dataset()
1797 return $BANDS{tied(%$self)};
1800 #** @method DeleteLayer($name)
1802 # Deletes a layer from the data source. Note that if there is a layer
1803 # object for the deleted layer, it becomes unusable.
1804 # @param name name of the layer to delete.
1807 my ($self, $name) = @_;
1809 for my $i (0..$self->GetLayerCount-1) {
1810 my $layer = GetLayerByIndex($self, $i);
1811 $index = $i, last
if $layer->GetName eq $name;
1813 Geo::GDAL::error(2, $name,
'Layer') unless defined $index;
1814 _DeleteLayer($self, $index);
1817 #** @method Geo::GDAL::Band Dither(%params)
1819 # Compute one band with color table image from an RGB image
1820 # @params params Named parameters:
1821 # - \a Red The red band, the default is to use the red band of this dataset.
1822 # - \a Green The green band, the default is to use the green band of this dataset.
1823 # - \a Blue The blue band, the default is to use the blue band of this dataset.
1824 # - \a Dest The destination band. If this is not defined, a new in-memory band (and a dataset) will be created.
1825 # - \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.
1826 # - \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.
1827 # - \a ProgressData (default is undef)
1829 # @return the destination band.
1831 # Usage example. This code converts an RGB JPEG image into a one band PNG image with a color table.
1833 # my $d = Geo::GDAL::Open('pic.jpg');
1834 # Geo::GDAL::Driver('PNG')->Copy(Name => 'test.png', Src => $d->Dither->Dataset);
1839 my $p = Geo::GDAL::named_parameters(\@_,
1844 ColorTable => undef,
1846 ProgressData => undef);
1847 for my $b ($self->Bands) {
1848 for my $cion ($b->ColorInterpretation) {
1849 if ($cion eq
'RedBand') { $p->{red}
1850 if ($cion eq
'GreenBand') { $p->{green}
1851 if ($cion eq
'BlueBand') { $p->{blue}
1854 my ($w, $h) = $self->Size;
1858 Type =>
'Byte')->Band;
1862 Green => $p->{green},
1864 Progress => $p->{progress},
1865 ProgressData => $p->{progressdata});
1866 Geo::GDAL::DitherRGB2PCT($p->{red},
1872 $p->{progressdata});
1873 $p->{dest}->ColorTable($p->{colortable});
1877 #** @method Domains()
1883 #** @method Geo::OGR::Layer ExecuteSQL($statement, $geom = undef, $dialect = "")
1885 # @param statement A SQL statement.
1886 # @param geom A Geo::OGR::Geometry object.
1888 # @return a new Geo::OGR::Layer object. The data source object will
1889 # exist as long as the layer object exists.
1893 my $layer = $self->_ExecuteSQL(@_);
1894 $LAYERS{tied(%$layer)} = $self;
1895 $RESULT_SET{tied(%$layer)} = 1;
1899 #** @method Extent()
1903 return $self->GeoTransform->Extent($self->Size);
1906 #** @method list GCPs(@GCPs, Geo::OSR::SpatialReference sr)
1908 # Get or set the GCPs and their projection.
1909 # @param GCPs [optional] a list of Geo::GDAL::GCP objects
1910 # @param sr [optional] the projection of the GCPs.
1911 # @return a list of Geo::GDAL::GCP objects followed by a Geo::OSR::SpatialReference object.
1917 $proj = $proj->Export(
'WKT')
if $proj and ref($proj);
1918 SetGCPs($self, \@_, $proj);
1920 return unless defined wantarray;
1922 my $GCPs = GetGCPs($self);
1923 return (@$GCPs, $proj);
1926 #** @method Geo::GDAL::GeoTransform GeoTransform(Geo::GDAL::GeoTransform $geo_transform)
1928 # Transformation from cell coordinates (column,row) to projection
1931 # x = geo_transform[0] + column*geo_transform[1] + row*geo_transform[2]
1932 # y = geo_transform[3] + column*geo_transform[4] + row*geo_transform[5]
1934 # @param geo_transform [optional]
1935 # @return the geo transform in a non-void context.
1941 SetGeoTransform($self, $_[0]);
1943 SetGeoTransform($self, \@_);
1947 return unless defined wantarray;
1948 my $t = GetGeoTransform($self);
1956 #** @method Geo::GDAL::Driver GetDriver()
1958 # @return a Geo::GDAL::Driver object that was used to open or create this dataset.
1963 #** @method list GetFileList()
1965 # @return list of files GDAL believes to be part of this dataset.
1970 #** @method scalar GetGCPProjection()
1972 # @return projection string.
1974 sub GetGCPProjection {
1977 #** @method Geo::OGR::Layer GetLayer($name)
1979 # @param name the name of the requested layer. If not given, then
1980 # returns the first layer in the data source.
1981 # @return a new Geo::OGR::Layer object that represents the layer
1982 # in the data source.
1985 my($self, $name) = @_;
1986 my $layer = defined $name ? GetLayerByName($self,
"$name") : GetLayerByIndex($self, 0);
1988 Geo::GDAL::error(2, $name,
'Layer') unless $layer;
1989 $LAYERS{tied(%$layer)} = $self;
1993 #** @method list GetLayerNames()
1995 # @note Delivers the functionality of undocumented method GetLayerCount.
1996 # @return a list of the names of the layers this data source provides.
2001 for my $i (0..$self->GetLayerCount-1) {
2002 my $layer = GetLayerByIndex($self, $i);
2003 push @names, $layer->GetName;
2008 #** @method GetStyleTable()
2013 #** @method Geo::GDAL::Dataset Grid($Dest, $Options)
2015 # Creates a regular raster grid from this data source.
2016 # This is equivalent to the gdal_grid utility.
2017 # @param Dest Destination raster dataset definition string (typically filename) or an object, which implements write and close.
2018 # @param Options A reference to a hash or list of options. For a
2019 # hash the keys are without the prefix '-'. For example give { of =>
2020 # 'PNG' } to set the output format. You must specify at least layer
2021 # name (key = l) or SQL to create a layer (key = sql). For a list the
2022 # options are given as for the command line utility. See
2023 # <a href="http://www.gdal.org/gdal_grid.html">gdal_grid</a> for a
2024 # complete list of options.
2028 my ($self, $dest, $options, $progress, $progress_data) = @_;
2029 $options = Geo::GDAL::GDALGridOptions->new(Geo::GDAL::make_processing_options($options));
2030 return $self->stdout_redirection_wrapper(
2032 \&Geo::GDAL::wrapper_GDALGrid,
2033 $options, $progress, $progress_data
2037 #** @method scalar Info($Options)
2039 # Information about this dataset.
2040 # @param Options A reference to a hash or list of options. For a hash
2041 # the keys are without the prefix '-'. For example give { JSON => 1 }
2042 # to set the output format to JSON. For a list the options are given
2043 # as for the command line utility. See <a
2044 # href="http://www.gdal.org/gdalinfo.html">gdalinfo</a> for all
2048 my ($self, $o) = @_;
2049 $o = Geo::GDAL::GDALInfoOptions->new(Geo::GDAL::make_processing_options($o));
2050 return Geo::GDAL::GDALInfo($self, $o);
2053 #** @method Geo::GDAL::Dataset Nearblack($Dest, $Options, coderef progress, $progress_data)
2055 # Convert nearly black/white pixels to black/white.
2056 # @param Dest Destination raster dataset definition string (typically
2057 # filename), destination dataset to which to add an alpha or mask
2058 # band, or an object, which implements write and close.
2059 # @param Options A reference to a hash or list of options. For a hash
2060 # the keys are without the prefix '-'. For example give { of => 'PNG'
2061 # } to set the output format. For a list the options are given as for
2062 # the command line utility. See <a
2063 # href="http://www.gdal.org/nearblack.html">nearblack</a> for all
2065 # @return Dataset if destination dataset definition string was given,
2066 # otherwise a boolean for success/fail but the method croaks if there
2070 my ($self, $dest, $options, $progress, $progress_data) = @_;
2071 $options = Geo::GDAL::GDALNearblackOptions->new(Geo::GDAL::make_processing_options($options));
2072 my $b = blessed($dest);
2073 if ($b && $b eq
'Geo::GDAL::Dataset') {
2074 Geo::GDAL::wrapper_GDALNearblackDestDS($dest, $self, $options, $progress, $progress_data);
2076 return $self->stdout_redirection_wrapper(
2078 \&Geo::GDAL::wrapper_GDALNearblackDestName,
2079 $options, $progress, $progress_data
2084 #** @method Geo::GDAL::Dataset Open()
2085 # Package subroutine.
2086 # The same as Geo::GDAL::Open
2091 #** @method Geo::GDAL::Dataset OpenShared()
2092 # Package subroutine.
2093 # The same as Geo::GDAL::OpenShared
2098 #** @method Geo::GDAL::Dataset Rasterize($Dest, $Options, coderef progress, $progress_data)
2100 # Render data from this data source into a raster.
2101 # @param Dest Destination raster dataset definition string (typically
2102 # filename), destination dataset, or an object, which implements write and close.
2103 # @param Options A reference to a hash or list of options. For a hash the keys
2104 # are without the prefix '-' and the values must be strings. For
2105 # example give { of => 'PNG' } to set the output format. You must
2106 # specify at least layer name (key = l) or SQL to create a layer (key
2107 # = sql). To create a new raster, you need to specify either target
2108 # resolution (tr => xres,yres) or target file size (ts =>
2109 # width,height). For a list the options are given as for the command
2110 # line utility.See <a href="http://www.gdal.org/gdal_rasterize.html">gdal_rasterize</a> for a
2111 # complete list of options.
2112 # @return Dataset if destination dataset definition string was given,
2113 # otherwise a boolean for success/fail but the method croaks if there
2118 my ($self, $dest, $options, $progress, $progress_data) = @_;
2119 $options = Geo::GDAL::GDALRasterizeOptions->new(Geo::GDAL::make_processing_options($options));
2120 my $b = blessed($dest);
2121 if ($b && $b eq
'Geo::GDAL::Dataset') {
2122 Geo::GDAL::wrapper_GDALRasterizeDestDS($dest, $self, $options, $progress, $progress_data);
2124 return $self->stdout_redirection_wrapper(
2126 \&Geo::GDAL::wrapper_GDALRasterizeDestName,
2127 $options, $progress, $progress_data
2132 #** @method scalar ReadRaster(%params)
2134 # Read data from the dataset.
2136 # @param params Named parameters:
2137 # - \a XOff x offset (cell coordinates) (default is 0)
2138 # - \a YOff y offset (cell coordinates) (default is 0)
2139 # - \a XSize width of the area to read (default is the width of the dataset)
2140 # - \a YSize height of the area to read (default is the height of the dataset)
2141 # - \a BufXSize (default is undef, i.e., the same as XSize)
2142 # - \a BufYSize (default is undef, i.e., the same as YSize)
2143 # - \a BufType data type of the buffer (default is the data type of the first band)
2144 # - \a BandList a reference to an array of band indices (default is [1])
2145 # - \a BufPixelSpace (default is 0)
2146 # - \a BufLineSpace (default is 0)
2147 # - \a BufBandSpace (default is 0)
2148 # - \a ResampleAlg one of Geo::GDAL::RIOResamplingTypes (default is 'NearestNeighbour'),
2149 # - \a Progress reference to a progress function (default is undef)
2150 # - \a ProgressData (default is undef)
2152 # <a href="http://www.gdal.org/classGDALDataset.html">Entry in GDAL docs (method RasterIO)</a>
2153 # @return a buffer, open the buffer with \a unpack function of Perl. See Geo::GDAL::Band::PackCharacter.
2157 my ($width, $height) = $self->Size;
2158 my ($type) = $self->Band->DataType;
2159 my $p = Geo::GDAL::named_parameters(\@_,
2171 ResampleAlg =>
'NearestNeighbour',
2173 ProgressData => undef
2175 $p->{resamplealg} = Geo::GDAL::string2int($p->{resamplealg}, \%Geo::GDAL::RIO_RESAMPLING_STRING2INT);
2176 $p->{buftype} = Geo::GDAL::string2int($p->{buftype}, \%Geo::GDAL::TYPE_STRING2INT, \%Geo::GDAL::TYPE_INT2STRING);
2177 $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});
2180 #** @method ReadTile()
2183 my ($self, $xoff, $yoff, $xsize, $ysize, $w_tile, $h_tile, $alg) = @_;
2185 for my $i (0..$self->Bands-1) {
2186 $data[$i] = $self->Band($i+1)->ReadTile($xoff, $yoff, $xsize, $ysize, $w_tile, $h_tile, $alg);
2191 #** @method ReleaseResultSet($layer)
2193 # @param layer A layer the has been created with ExecuteSQL.
2194 # @note There is no need to call this method. The result set layer is
2195 # released in the destructor of the layer that was created with SQL.
2197 sub ReleaseResultSet {
2198 # a no-op, _ReleaseResultSet is called from Layer::DESTROY
2201 #** @method RollbackTransaction()
2203 sub RollbackTransaction {
2206 #** @method SetStyleTable()
2211 #** @method list Size()
2213 # @return (width, height)
2217 return ($self->{RasterXSize}, $self->{RasterYSize});
2220 #** @method Geo::OSR::SpatialReference SpatialReference(Geo::OSR::SpatialReference sr)
2222 # Get or set the projection of this dataset.
2223 # @param sr [optional] a Geo::OSR::SpatialReference object,
2224 # which replaces the existing projection definition of this dataset.
2225 # @return a Geo::OSR::SpatialReference object, which represents the
2226 # projection of this dataset.
2227 # @note Methods GetProjection, SetProjection, and Projection return WKT strings.
2229 sub SpatialReference {
2230 my($self, $sr) = @_;
2231 SetProjection($self, $sr->As(
'WKT'))
if defined $sr;
2232 if (defined wantarray) {
2233 my $p = GetProjection($self);
2239 #** @method StartTransaction()
2241 sub StartTransaction {
2244 #** @method TestCapability()
2246 sub TestCapability {
2247 return _TestCapability(@_);
2253 my ($self, $e) = @_;
2254 my ($w, $h) = $self->Size;
2255 #print "sz $w $h\n";
2256 my $gt = $self->GeoTransform;
2258 confess
"GeoTransform is not \"north up\"." unless $gt->NorthUp;
2259 my $x = $gt->Extent($w, $h);
2260 my $xoff = floor(($e->[0] - $gt->[0])/$gt->[1]);
2261 $xoff = 0
if $xoff < 0;
2262 my $yoff = floor(($gt->[3] - $e->[3])/(-$gt->[5]));
2263 $yoff = 0
if $yoff < 0;
2264 my $xsize = ceil(($e->[2] - $gt->[0])/$gt->[1]) - $xoff;
2265 $xsize = $w - $xoff
if $xsize > $w - $xoff;
2266 my $ysize = ceil(($gt->[3] - $e->[1])/(-$gt->[5])) - $yoff;
2267 $ysize = $h - $yoff
if $ysize > $h - $yoff;
2268 return ($xoff, $yoff, $xsize, $ysize);
2271 #** @method Geo::GDAL::Dataset Translate($Dest, $Options, coderef progress, $progress_data)
2273 # Convert this dataset into another format.
2274 # @param Dest Destination dataset definition string (typically
2275 # filename) or an object, which implements write and close.
2276 # @param Options A reference to a hash or list of options. For a hash
2277 # the keys are without the prefix '-'. For example give { of => 'PNG'
2278 # } to set the output format. For a list the options are given as for
2279 # the command line utility. See <a
2280 # href="http://www.gdal.org/gdal_translate.html">gdal_translate</a>
2281 # and <a href="http://www.gdal.org/ogr2ogr.html">ogr2ogr</a> for all
2283 # @return New dataset object if destination dataset definition
2284 # string was given, otherwise a boolean for success/fail but the
2285 # method croaks if there was an error.
2288 my ($self, $dest, $options, $progress, $progress_data) = @_;
2289 return $self->stdout_redirection_wrapper(
2293 #** @method
Geo::GDAL::Dataset Warp($Dest, $Options, coderef progress, $progress_data)
2295 # Reproject
this dataset.
2296 # @param Dest Destination raster dataset definition string (typically
2297 # filename) or an
object, which implements write and close.
2298 # @param Options A reference to a hash or list of options. For a hash
2299 # the keys are without the prefix
'-'. For example give { of =>
'PNG'
2300 # } to set the output format. For a list the options are given as
for
2301 # the command line utility. See <a
2302 # href="http://www.gdal.org/gdalwarp.html">gdalwarp</a> for
2306 my ($self, $dest, $options, $progress, $progress_data) = @_;
2307 $options = Geo::GDAL::GDALWarpAppOptions->new(Geo::GDAL::make_processing_options($options));
2308 my $b = blessed($dest);
2309 if ($b && $b eq
'Geo::GDAL::Dataset') {
2310 Geo::GDAL::wrapper_GDALWarpDestDS($dest, $self, $options, $progress, $progress_data);
2312 return $self->stdout_redirection_wrapper(
2314 \&Geo::GDAL::wrapper_GDALWarpDestName,
2315 $options, $progress, $progress_data
2320 #** @method Geo::GDAL::Dataset Warped(%params)
2322 # Create a virtual warped dataset from this dataset.
2324 # @param params Named parameters:
2325 # - \a SrcSRS Override the spatial reference system of this dataset if there is one (default is undef).
2326 # - \a DstSRS The target spatial reference system of the result (default is undef).
2327 # - \a ResampleAlg The resampling algorithm (default is 'NearestNeighbour').
2328 # - \a MaxError Maximum error measured in input cellsize that is allowed in approximating the transformation (default is 0 for exact calculations).
2330 # # <a href="http://www.gdal.org/gdalwarper_8h.html">Documentation for GDAL warper.</a>
2332 # @return a new Geo::GDAL::Dataset object
2336 my $p = Geo::GDAL::named_parameters(\@_, SrcSRS => undef, DstSRS => undef, ResampleAlg =>
'NearestNeighbour', MaxError => 0);
2337 for my $srs (qw/srcsrs dstsrs/) {
2338 $p->{$srs} = $p->{$srs}->ExportToWkt
if $p->{$srs} && blessed $p->{$srs};
2340 $p->{resamplealg} = Geo::GDAL::string2int($p->{resamplealg}, \%Geo::GDAL::RESAMPLING_STRING2INT);
2341 my $warped = Geo::GDAL::_AutoCreateWarpedVRT($self, $p->{srcsrs}, $p->{dstsrs}, $p->{resamplealg}, $p->{maxerror});
2342 $BANDS{tied(%{$warped})} = $self
if $warped; #
self must live as
long as warped
2346 #** @method WriteRaster(%params)
2348 # Write data into the dataset.
2350 # @param params Named parameters:
2351 # - \a XOff x offset (cell coordinates) (default is 0)
2352 # - \a YOff y offset (cell coordinates) (default is 0)
2353 # - \a XSize width of the area to write (default is the width of the dataset)
2354 # - \a YSize height of the area to write (default is the height of the dataset)
2355 # - \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.
2356 # - \a BufXSize (default is undef, i.e., the same as XSize)
2357 # - \a BufYSize (default is undef, i.e., the same as YSize)
2358 # - \a BufType data type of the buffer (default is the data type of the first band)
2359 # - \a BandList a reference to an array of band indices (default is [1])
2360 # - \a BufPixelSpace (default is 0)
2361 # - \a BufLineSpace (default is 0)
2362 # - \a BufBandSpace (default is 0)
2364 # <a href="http://www.gdal.org/classGDALDataset.html">Entry in GDAL docs (method RasterIO)</a>
2368 my ($width, $height) = $self->Size;
2369 my ($type) = $self->Band->DataType;
2370 my $p = Geo::GDAL::named_parameters(\@_,
2384 $p->{buftype} = Geo::GDAL::string2int($p->{buftype}, \%Geo::GDAL::TYPE_STRING2INT, \%Geo::GDAL::TYPE_INT2STRING);
2385 $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});
2388 #** @method WriteTile()
2391 my ($self, $data, $xoff, $yoff) = @_;
2394 for my $i (0..$self->Bands-1) {
2395 $self->Band($i+1)->WriteTile($data->[$i], $xoff, $yoff);
2399 #** @class Geo::GDAL::Driver
2400 # @brief A driver for a specific dataset format.
2402 package Geo::GDAL::Driver;
2406 #** @attr $HelpTopic
2407 # $driver->{HelpTopic}
2411 # $driver->{LongName}
2414 #** @attr $ShortName
2415 # $driver->{ShortName}
2418 #** @method list Capabilities()
2420 # @return A list of capabilities. When executed as a package subroutine
2421 # returns a list of all potential capabilities a driver may have. When
2422 # executed as an object method returns a list of all capabilities the
2425 # Currently capabilities are:
2426 # CREATE, CREATECOPY, DEFAULT_FIELDS, NOTNULL_FIELDS, NOTNULL_GEOMFIELDS, OPEN, RASTER, VECTOR, and VIRTUALIO.
2430 # @all_capabilities = Geo::GDAL::Driver::Capabilities;
2431 # @capabilities_of_the_geotiff_driver = Geo::GDAL::Driver('GTiff')->Capabilities;
2436 return @CAPABILITIES unless $self;
2437 my $h = $self->GetMetadata;
2439 for my $cap (@CAPABILITIES) {
2440 my $test = $h->{
'DCAP_'.uc($cap)};
2441 push @cap, $cap
if defined($test) and $test eq 'YES';
2446 #** @method Geo::GDAL::Dataset Copy(%params)
2448 # Create a new raster Geo::GDAL::Dataset as a copy of an existing dataset.
2449 # @note a.k.a. CreateCopy
2451 # @param params Named parameters:
2452 # - \a Name name for the new raster dataset.
2453 # - \a Src the source Geo::GDAL::Dataset object.
2454 # - \a Strict 1 (default) if the copy must be strictly equivalent, or 0 if the copy may adapt.
2455 # - \a Options an anonymous hash of driver specific options.
2456 # - \a Progress [optional] a reference to a subroutine, which will
2457 # be called with parameters (number progress, string msg, progress_data).
2458 # - \a ProgressData [optional]
2459 # @return a new Geo::GDAL::Dataset object.
2463 my $p = Geo::GDAL::named_parameters(\@_, Name =>
'unnamed', Src => undef, Strict => 1, Options => {}, Progress => undef, ProgressData => undef);
2464 return $self->stdout_redirection_wrapper(
2466 $self->can(
'_CreateCopy'),
2467 $p->{src}, $p->{strict}, $p->{options}, $p->{progress}, $p->{progressdata});
2470 #** @method CopyFiles($NewName, $OldName)
2472 # Copy the files of a dataset.
2473 # @param NewName String.
2474 # @param OldName String.
2479 #** @method Geo::GDAL::Dataset Create(%params)
2481 # Create a raster dataset using this driver.
2482 # @note a.k.a. CreateDataset
2484 # @param params Named parameters:
2485 # - \a Name The name for the dataset (default is 'unnamed') or an object, which implements write and close.
2486 # - \a Width The width for the raster dataset (default is 256).
2487 # - \a Height The height for the raster dataset (default is 256).
2488 # - \a Bands The number of bands to create into the raster dataset (default is 1).
2489 # - \a Type The data type for the raster cells (default is 'Byte'). One of Geo::GDAL::Driver::CreationDataTypes.
2490 # - \a Options Driver creation options as a reference to a hash (default is {}).
2492 # @return A new Geo::GDAL::Dataset object.
2496 my $p = Geo::GDAL::named_parameters(\@_, Name =>
'unnamed', Width => 256, Height => 256, Bands => 1, Type =>
'Byte', Options => {});
2497 my $type = Geo::GDAL::string2int($p->{type}, \%Geo::GDAL::TYPE_STRING2INT);
2498 return $self->stdout_redirection_wrapper(
2500 $self->can(
'_Create'),
2501 $p->{width}, $p->{height}, $p->{bands}, $type, $p->{options}
2505 #** @method list CreationDataTypes()
2507 # @return a list of data types that can be used for new datasets of this format. A subset of Geo::GDAL::DataTypes
2509 sub CreationDataTypes {
2511 my $h = $self->GetMetadata;
2512 return split /\s+/, $h->{DMD_CREATIONDATATYPES}
if $h->{DMD_CREATIONDATATYPES};
2515 #** @method list CreationOptionList()
2517 # @return a list of options, each option is a hashref, the keys are
2518 # name, type and description or Value. Value is a listref.
2520 sub CreationOptionList {
2523 my $h = $self->GetMetadata->{DMD_CREATIONOPTIONLIST};
2525 $h = Geo::GDAL::ParseXMLString($h);
2526 my($type, $value) = Geo::GDAL::NodeData($h);
2527 if ($value eq
'CreationOptionList') {
2528 for my $o (Geo::GDAL::Children($h)) {
2530 for my $a (Geo::GDAL::Children($o)) {
2531 my(undef, $key) = Geo::GDAL::NodeData($a);
2532 my(undef, $value) = Geo::GDAL::NodeData(Geo::GDAL::Child($a, 0));
2533 if ($key eq
'Value') {
2534 push @{$option{$key}}, $value;
2536 $option{$key} = $value;
2539 push @options, \%option;
2546 #** @method Delete($name)
2553 #** @method Domains()
2559 #** @method scalar Extension()
2561 # @return a suggested extension or extensions (e.g., ext1/ext2) for
2566 my $h = $self->GetMetadata;
2567 return $h->{DMD_EXTENSION};
2570 #** @method scalar MIMEType()
2572 # @return a suggested MIME type for datasets.
2576 my $h = $self->GetMetadata;
2577 return $h->{DMD_MIMETYPE};
2580 #** @method scalar Name()
2582 # @return The short name of the driver.
2586 return $self->{ShortName};
2591 # The same as Geo::GDAL::Open except that only this driver is allowed.
2595 my @p = @_; # name, update
2596 my @flags = qw/RASTER/;
2597 push @flags, qw/READONLY/
if $p[1] eq
'ReadOnly';
2598 push @flags, qw/UPDATE/
if $p[1] eq
'Update';
2600 Geo::GDAL::error(
"Failed to open $p[0]. Is it a raster dataset?") unless $dataset;
2604 #** @method Rename($NewName, $OldName)
2606 # Rename (move) a GDAL dataset.
2607 # @param NewName String.
2608 # @param OldName String.
2613 #** @method scalar TestCapability($cap)
2615 # Test whether the driver has the specified capability.
2616 # @param cap A capability string (one of those returned by Capabilities).
2617 # @return a boolean value.
2619 sub TestCapability {
2620 my($self, $cap) = @_;
2622 return (defined($h) and $h eq
'YES') ? 1 : undef;
2625 #** @method stdout_redirection_wrapper()
2627 sub stdout_redirection_wrapper {
2628 my ($self, $name, $sub, @params) = @_;
2630 if ($name && blessed $name) {
2632 my $ref = $object->can(
'write');
2633 Geo::GDAL::VSIStdoutSetRedirection($ref);
2634 $name =
'/vsistdout/';
2638 $ds = $sub->($self, $name, @params);
2642 $Geo::GDAL::stdout_redirection{tied(%$ds)} = $object;
2644 Geo::GDAL::VSIStdoutUnsetRedirection();
2649 confess("Failed. Use Geo::OGR::Driver for vector drivers.") unless $ds;
2653 #** @class Geo::GDAL::Extent
2655 package Geo::GDAL::Extent;
2657 #** @method ExpandToInclude()
2659 sub ExpandToInclude {
2660 my ($self, $e) = @_;
2661 $self->[0] = $e->[0]
if $e->[0] < $self->[0];
2662 $self->[1] = $e->[1]
if $e->[1] < $self->[1];
2663 $self->[2] = $e->[2]
if $e->[2] > $self->[2];
2664 $self->[3] = $e->[3]
if $e->[3] > $self->[3];
2667 #** @method Overlap()
2670 my ($self, $e) = @_;
2671 return undef unless $self->Overlaps($e);
2673 $ret->[0] = $e->[0]
if $self->[0] < $e->[0];
2674 $ret->[1] = $e->[1]
if $self->[1] < $e->[1];
2675 $ret->[2] = $e->[2]
if $self->[2] > $e->[2];
2676 $ret->[3] = $e->[3]
if $self->[3] > $e->[3];
2680 #** @method Overlaps()
2683 my ($self, $e) = @_;
2684 return $self->[0] < $e->[2] && $self->[2] > $e->[0] && $self->[1] < $e->[3] && $self->[3] > $e->[1];
2691 return ($self->[2] - $self->[0], $self->[3] - $self->[1]);
2701 } elsif (ref $_[0]) {
2706 bless $self, $class;
2710 #** @class Geo::GDAL::GCP
2711 # @brief A ground control point for georeferencing rasters.
2713 package Geo::GDAL::GCP;
2718 # cell x coordinate (access as $gcp->{Column})
2722 # unique identifier (string) (access as $gcp->{Id})
2726 # informational message (access as $gcp->{Info})
2730 # cell y coordinate (access as $gcp->{Row})
2734 # projection coordinate (access as $gcp->{X})
2738 # projection coordinate (access as $gcp->{Y})
2742 # projection coordinate (access as $gcp->{Z})
2745 #** @method scalar new($x = 0.0, $y = 0.0, $z = 0.0, $column = 0.0, $row = 0.0, $info = "", $id = "")
2747 # @param x projection coordinate
2748 # @param y projection coordinate
2749 # @param z projection coordinate
2750 # @param column cell x coordinate
2751 # @param row cell y coordinate
2752 # @param info informational message
2753 # @param id unique identifier (string)
2754 # @return a new Geo::GDAL::GCP object
2758 my $self = Geo::GDALc::new_GCP(@_);
2759 bless $self, $pkg
if defined($self);
2762 #** @class Geo::GDAL::GeoTransform
2763 # @brief An array of affine transformation coefficients.
2765 # The geo transformation has the form
2767 # x = a + column * b + row * c
2768 # y = d + column * e + row * f
2771 # (column,row) is the location in cell coordinates<br/>
2772 # (x,y) is the location in projection coordinates<br/>
2774 # A Geo::GDAL::GeoTransform object is a reference to an anonymous array [a,b,c,d,e,f].
2776 package Geo::GDAL::GeoTransform;
2778 #** @method Apply(array reference x, array reference y)
2780 # @return a list (x, y), where x and y are references to arrays of
2781 # transformed coordinates.
2784 my ($self, $columns, $rows) = @_;
2786 for my $i (0..$#$columns) {
2788 Geo::GDAL::ApplyGeoTransform($self, $columns->[$i], $rows->[$i]);
2793 #** @method Extent()
2796 my ($self, $w, $h) = @_;
2798 for my $x ($self->[0] + $self->[1]*$w, $self->[0] + $self->[2]*$h, $self->[0] + $self->[1]*$w + $self->[2]*$h) {
2799 $e->[0] = $x
if $x < $e->[0];
2800 $e->[2] = $x
if $x > $e->[2];
2802 for my $y ($self->[3] + $self->[4]*$w, $self->[3] + $self->[5]*$h, $self->[3] + $self->[4]*$w + $self->[5]*$h) {
2803 $e->[1] = $y
if $y < $e->[1];
2804 $e->[3] = $y
if $y > $e->[3];
2809 #** @method FromGCPs(@GCPs, $ApproxOK)
2811 # Compute transformation coefficients from a list of Geo::GDAL::GCP
2813 # @param GCPs A list of Geo::GDAL::GCP objects.
2814 # @param ApproxOK [optional] Minimize the error in the coefficient (integer, default is true).
2815 # @return a new Geo::GDAL::GeoTransform object.
2820 if (ref $p eq
'ARRAY') {
2824 while ($p && blessed $p) {
2829 my $approx_ok = shift
2830 Geo::GDAL::error(
'Usage: Geo::GDAL::GeoTransform::FromGCPs(\@gcps, $approx_ok)') unless @$gcps;
2831 my $self = Geo::GDAL::GCPsToGeoTransform($gcps, $approx_ok);
2832 bless $self, 'Geo::GDAL::GetTransform';
2838 # @return a new Geo::GDAL::GeoTransform object, which is the inverse
2839 # of this one (in void context changes this object).
2843 my @inv = Geo::GDAL::InvGeoTransform($self);
2844 return new(@inv)
if defined wantarray;
2848 #** @method NorthUp()
2852 return $self->[2] == 0 && $self->[4] == 0;
2855 #** @method new(@coeffs)
2857 # @return a new Geo::GDAL::GeoTransform object.
2863 $self = [0,1,0,0,0,1];
2870 bless $self, $class;
2874 #** @class Geo::GDAL::MajorObject
2875 # @brief An object, which holds meta data.
2877 package Geo::GDAL::MajorObject;
2881 #** @method scalar Description($description)
2883 # @param description [optional]
2884 # @return the description in a non-void context.
2887 my($self, $desc) = @_;
2888 SetDescription($self, $desc) if defined $desc;
2889 GetDescription($self) if defined wantarray;
2892 #** @method Domains()
2893 # Package subroutine.
2894 # @return the class specific DOMAINS list
2900 #** @method scalar GetDescription()
2904 sub GetDescription {
2907 #** @method hash reference GetMetadata($domain = "")
2909 # @note see Metadata
2916 #** @method GetMetadataDomainList()
2918 sub GetMetadataDomainList {
2921 #** @method hash reference Metadata(hashref metadata = undef, $domain = '')
2925 # @return the metadata in a non-void context.
2929 my $metadata = ref $_[0] ? shift : undef;
2931 SetMetadata($self, $metadata, $domain)
if defined $metadata;
2932 GetMetadata($self, $domain)
if defined wantarray;
2935 #** @method SetDescription($NewDesc)
2940 sub SetDescription {
2943 #** @method SetMetadata(hashref metadata, $domain = "")
2945 # @note see Metadata
2953 #** @class Geo::GDAL::RasterAttributeTable
2954 # @brief An attribute table in a raster band.
2956 package Geo::GDAL::RasterAttributeTable;
2964 return $Geo::GDAL::Band::RATS{tied(%$self)};
2967 #** @method ChangesAreWrittenToFile()
2969 sub ChangesAreWrittenToFile {
2972 #** @method Geo::GDAL::RasterAttributeTable Clone()
2974 # @return a new Geo::GDAL::RasterAttributeTable object
2979 #** @method hash Columns(%columns)
2981 # A get/set method for the columns of the RAT
2982 # @param columns optional, a the keys are column names and the values are anonymous
2983 # hashes with keys Type and Usage
2984 # @return a hash similar to the optional input parameter
2989 if (@_) { # create columns
2991 for my $name (keys %columns) {
2992 $self->CreateColumn($name, $columns{$name}{Type}, $columns{$name}{Usage});
2996 for my $c (0..$self->GetColumnCount-1) {
2997 my $name = $self->GetNameOfCol($c);
2998 $columns{$name}{Type} = $self->GetTypeOfCol($c);
2999 $columns{$name}{Usage} = $self->GetUsageOfCol($c);
3004 #** @method CreateColumn($name, $type, $usage)
3007 # @param type one of FieldTypes
3008 # @param usage one of FieldUsages
3011 my($self, $name, $type, $usage) = @_;
3012 for my $color (qw/Red Green Blue Alpha/) {
3013 carp
"RAT column type will be 'Integer' for usage '$color'." if $usage eq $color and $type ne
'Integer';
3015 $type = Geo::GDAL::string2int($type, \%FIELD_TYPE_STRING2INT);
3016 $usage = Geo::GDAL::string2int($usage, \%FIELD_USAGE_STRING2INT);
3017 _CreateColumn($self, $name, $type, $usage);
3020 #** @method DumpReadable()
3025 #** @method list FieldTypes()
3026 # Package subroutine.
3030 return @FIELD_TYPES;
3033 #** @method list FieldUsages()
3034 # Package subroutine.
3038 return @FIELD_USAGES;
3041 #** @method scalar GetColOfUsage($usage)
3047 my($self, $usage) = @_;
3048 _GetColOfUsage($self, $FIELD_USAGE_STRING2INT{$usage});
3051 #** @method scalar GetColumnCount()
3055 sub GetColumnCount {
3058 #** @method scalar GetNameOfCol($column)
3066 #** @method scalar GetRowCount()
3072 #** @method scalar GetRowOfValue($value)
3074 # @param value a cell value
3075 # @return row index or -1
3080 #** @method scalar GetTypeOfCol($column)
3086 my($self, $col) = @_;
3087 $FIELD_TYPE_INT2STRING{_GetTypeOfCol($self, $col)};
3090 #** @method scalar GetUsageOfCol($column)
3096 my($self, $col) = @_;
3097 $FIELD_USAGE_INT2STRING{_GetUsageOfCol($self, $col)};
3100 #** @method scalar GetValueAsDouble($row, $column)
3106 sub GetValueAsDouble {
3109 #** @method scalar GetValueAsInt($row, $column)
3118 #** @method scalar GetValueAsString($row, $column)
3124 sub GetValueAsString {
3127 #** @method LinearBinning($Row0MinIn, $BinSizeIn)
3129 # @param Row0MinIn [optional] the lower bound (cell value) of the first category.
3130 # @param BinSizeIn [optional] the width of each category (in cell value units).
3131 # @return ($Row0MinIn, $BinSizeIn) or an empty list if LinearBinning is not set.
3135 SetLinearBinning($self, @_) if @_ > 0;
3136 return unless defined wantarray;
3137 my @a = GetLinearBinning($self);
3138 return $a[0] ? ($a[1], $a[2]) : ();
3141 #** @method SetRowCount($count)
3149 #** @method SetValueAsDouble($row, $column, $value)
3156 sub SetValueAsDouble {
3159 #** @method SetValueAsInt($row, $column, $value)
3169 #** @method SetValueAsString($row, $column, $value)
3176 sub SetValueAsString {
3179 #** @method scalar Value($row, $column, $value)
3183 # @param value [optional]
3187 my($self, $row, $column) = @_;
3188 SetValueAsString($self, $row, $column, $_[3]) if defined $_[3];
3189 return unless defined wantarray;
3190 GetValueAsString($self, $row, $column);
3193 #** @method Geo::GDAL::RasterAttributeTable new()
3195 # @return a new Geo::GDAL::RasterAttributeTable object
3199 my $self = Geo::GDALc::new_RasterAttributeTable(@_);
3200 bless $self, $pkg
if defined($self);
3203 #** @class Geo::GDAL::Transformer
3206 # This class is not yet documented for the GDAL Perl bindings.
3207 # @todo Test and document.
3209 package Geo::GDAL::Transformer;
3213 #** @method TransformGeolocations()
3215 sub TransformGeolocations {
3218 #** @method TransformPoint()
3220 sub TransformPoint {
3227 my $self = Geo::GDALc::new_Transformer(@_);
3228 bless $self, $pkg
if defined($self);
3231 #** @class Geo::GDAL::VSIF
3232 # @brief A GDAL virtual file system.
3234 package Geo::GDAL::VSIF;
3236 use base qw(
our Exporter)
3242 my ($self, $data) = @_;
3243 Geo::GDAL::VSIFCloseL($self);
3246 #** @method MkDir($path)
3247 # Package subroutine.
3249 # @param path The directory to make.
3250 # @note The name of this method is VSIMkdir in GDAL.
3254 # mode unused in CPL
3255 Geo::GDAL::Mkdir($path, 0);
3258 #** @method Geo::GDAL::VSIF Open($filename, $mode)
3259 # Package subroutine.
3260 # @param filename Name of the file to open. For example "/vsimem/x".
3261 # @param mode Access mode. 'r', 'r+', 'w', etc.
3262 # @return A file handle on success.
3265 my ($path, $mode) = @_;
3266 my $self = Geo::GDAL::VSIFOpenL($path, $mode);
3267 bless $self,
'Geo::GDAL::VSIF';
3270 #** @method scalar Read($count)
3272 # @param count The number of bytes to read from the file.
3273 # @return A byte string.
3276 my ($self, $count) = @_;
3277 Geo::GDAL::VSIFReadL($count, $self);
3280 #** @method list ReadDir($dir)
3281 # Package subroutine.
3282 # @return Contents of a directory in an anonymous array or as a list.
3286 Geo::GDAL::ReadDir($path);
3289 #** @method scalar ReadDirRecursive($dir)
3290 # Package subroutine.
3291 # @note Give the directory in the form '/vsimem', i.e., without trailing '/'.
3292 # @return Contents of a directory tree in an anonymous array.
3294 sub ReadDirRecursive {
3296 Geo::GDAL::ReadDirRecursive($path);
3299 #** @method Rename($old, $new)
3300 # Package subroutine.
3302 # @note The name of this method is VSIRename in GDAL.
3305 my ($old, $new) = @_;
3306 Geo::GDAL::Rename($old, $new);
3309 #** @method RmDir($path)
3310 # Package subroutine.
3311 # Remove a directory.
3312 # @note The name of this method is VSIRmdir in GDAL.
3315 my ($dirname, $recursive) = @_;
3318 Geo::GDAL::Rmdir($dirname);
3320 for my $f (ReadDir($dirname)) {
3321 next
if $f eq
'..' or $f eq
'.';
3322 my @s = Stat($dirname.
'/'.$f);
3324 Unlink($dirname.
'/'.$f);
3325 } elsif ($s[0] eq
'd') {
3326 Rmdir($dirname.
'/'.$f, 1);
3327 Rmdir($dirname.
'/'.$f);
3334 my $r = $recursive ?
' recursively' :
'';
3335 Geo::GDAL::error(
"Cannot remove directory \"$dirname\"$r.");
3339 #** @method Seek($offset, $whence)
3343 my ($self, $offset, $whence) = @_;
3344 Geo::GDAL::VSIFSeekL($self, $offset, $whence);
3347 #** @method list Stat($filename)
3348 # Package subroutine.
3349 # @return ($filemode, $filesize). filemode is f for a plain file, d
3350 # for a directory, l for a symbolic link, p for a named pipe (FIFO), S
3351 # for a socket, b for a block special file, and c for a character
3356 Geo::GDAL::Stat($path);
3359 #** @method scalar Tell()
3364 Geo::GDAL::VSIFTellL($self);
3367 #** @method Truncate($new_size)
3371 my ($self, $new_size) = @_;
3372 Geo::GDAL::VSIFTruncateL($self, $new_size);
3375 #** @method Unlink($filename)
3376 # Package subroutine.
3377 # @param filename The file to delete.
3378 # @return 0 on success and -1 on an error.
3381 my ($filename) = @_;
3382 Geo::GDAL::Unlink($filename);
3385 #** @method Write($scalar)
3387 # @param scalar The byte string to write to the file.
3388 # @return Number of bytes written into the file.
3391 my ($self, $data) = @_;
3392 Geo::GDAL::VSIFWriteL($data, $self);
3395 #** @class Geo::GDAL::XML
3396 # @brief A simple XML parser
3398 package Geo::GDAL::XML;
3400 #** @method new($string)
3402 # @param string String containing XML.
3403 # @return A new Geo::GDAL::XML object, which is a reference to an anonymous array.
3408 my $self = Geo::GDAL::ParseXMLString($xml);
3409 bless $self, $class;
3410 $self->traverse(sub {my $node = shift; bless $node, $class});
3414 #** @method serialize()
3416 # @return The XML serialized into a string.
3420 return Geo::GDAL::SerializeXMLTree($self);
3423 # This file was automatically generated by SWIG (http://www.swig.org).
3426 # Do not make changes to this file unless you know what you are doing--modify
3427 # the SWIG interface file instead.
3430 #** @method traverse(coderef subroutine)
3432 # @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.
3435 my ($self, $sub) = @_;
3436 my $type = $self->[0];
3437 my $data = $self->[1];
3438 $type = Geo::GDAL::NodeType($type);
3439 $sub->($self, $type, $data);
3440 for my $child (@{$self}[2..$#$self]) {
3441 traverse($child, $sub);
3446 # @brief Base class for geographical networks in GDAL.
3450 #** @method CastToGenericNetwork()
3452 sub CastToGenericNetwork {
3455 #** @method CastToNetwork()
3460 #** @method GATConnectedComponents()
3462 sub GATConnectedComponents {
3465 #** @method GATDijkstraShortestPath()
3467 sub GATDijkstraShortestPath {
3470 #** @method GATKShortestPath()
3472 sub GATKShortestPath {
3475 #** @method GNM_EDGE_DIR_BOTH()
3477 sub GNM_EDGE_DIR_BOTH {
3480 #** @method GNM_EDGE_DIR_SRCTOTGT()
3482 sub GNM_EDGE_DIR_SRCTOTGT {
3485 #** @method GNM_EDGE_DIR_TGTTOSRC()
3487 sub GNM_EDGE_DIR_TGTTOSRC {
3491 #** @class Geo::GNM::GenericNetwork
3493 package Geo::GNM::GenericNetwork;
3497 #** @method ChangeAllBlockState()
3499 sub ChangeAllBlockState {
3502 #** @method ChangeBlockState()
3504 sub ChangeBlockState {
3507 #** @method ConnectFeatures()
3509 sub ConnectFeatures {
3512 #** @method ConnectPointsByLines()
3514 sub ConnectPointsByLines {
3517 #** @method CreateRule()
3522 #** @method DeleteAllRules()
3524 sub DeleteAllRules {
3527 #** @method DeleteRule()
3532 #** @method DisconnectFeatures()
3534 sub DisconnectFeatures {
3537 #** @method DisconnectFeaturesWithId()
3539 sub DisconnectFeaturesWithId {
3542 #** @method GetRules()
3547 #** @method ReconnectFeatures()
3549 sub ReconnectFeatures {
3552 #** @class Geo::GNM::MajorObject
3554 package Geo::GNM::MajorObject;
3556 use base qw(Geo::GNM)
3558 #** @method GetDescription()
3560 sub GetDescription {
3563 #** @method GetMetadataDomainList()
3565 sub GetMetadataDomainList {
3568 #** @method GetMetadataItem()
3570 sub GetMetadataItem {
3573 #** @method GetMetadata_Dict()
3575 sub GetMetadata_Dict {
3578 #** @method GetMetadata_List()
3580 sub GetMetadata_List {
3583 #** @method SetDescription()
3585 sub SetDescription {
3588 #** @method SetMetadata()
3593 #** @method SetMetadataItem()
3595 sub SetMetadataItem {
3598 #** @class Geo::GNM::Network
3600 package Geo::GNM::Network;
3604 #** @method CommitTransaction()
3606 sub CommitTransaction {
3609 #** @method CopyLayer()
3614 #** @method CreateLayer()
3619 #** @method DeleteLayer()
3624 #** @method DisconnectAll()
3629 #** @method GetFeatureByGlobalFID()
3631 sub GetFeatureByGlobalFID {
3634 #** @method GetFileList()
3639 #** @method GetLayerByIndex()
3641 sub GetLayerByIndex {
3644 #** @method GetLayerByName()
3646 sub GetLayerByName {
3649 #** @method GetLayerCount()
3654 #** @method GetName()
3659 #** @method GetPath()
3664 #** @method GetProjection()
3669 #** @method GetProjectionRef()
3671 sub GetProjectionRef {
3674 #** @method GetVersion()
3679 #** @method ReleaseResultSet()
3681 sub ReleaseResultSet {
3684 #** @method RollbackTransaction()
3686 sub RollbackTransaction {
3689 #** @method StartTransaction()
3691 sub StartTransaction {
3694 #** @method TestCapability()
3696 sub TestCapability {
3700 # @brief OGR utility functions.
3702 # A wrapper for many OGR utility functions and a root class for all
3707 #** @method list ByteOrders()
3708 # Package subroutine.
3709 # @return a list of byte order types, XDR and NDR. XDR denotes
3710 # big-endian and NDR denotes little-endian.
3715 #** @method Geo::GDAL::Driver Driver($name)
3716 # Package subroutine.
3718 # @param name the short name of the driver.
3719 # @note No check is made that the driver is actually a vector driver.
3720 # @return a Geo::GDAL::Driver object.
3723 return 'Geo::GDAL::Driver' unless @_;
3727 #** @method list DriverNames()
3728 # Package subroutine.
3729 # A.k.a GetDriverNames
3730 # @note Use Geo::GDAL::DriverNames for raster drivers.
3731 # @return a list of the short names of all available GDAL vector drivers.
3736 #** @method list Drivers()
3737 # Package subroutine.
3738 # @note Use Geo::GDAL::Drivers for raster drivers.
3739 # @return a list of all available GDAL vector drivers.
3743 for my $i (0..GetDriverCount()-1) {
3744 my $driver = Geo::GDAL::GetDriver($i);
3745 push @drivers, $driver
if $driver->TestCapability(
'VECTOR');
3750 #** @method scalar GeometryTypeModify($type, $modifier)
3752 # @param type a geometry type (one of Geo::OGR::GeometryTypes).
3753 # @param modifier one of 'flatten', 'set_Z', 'make_collection', 'make_curve', or 'make_linear'.
3754 # @return modified geometry type.
3756 sub GeometryTypeModify {
3757 my($type, $modifier) = @_;
3758 Geo::GDAL::error(1, $type, \%Geo::OGR::Geometry::TYPE_STRING2INT) unless exists $Geo::OGR::Geometry::TYPE_STRING2INT{$type};
3759 $type = $Geo::OGR::Geometry::TYPE_STRING2INT{$type};
3760 return $Geo::OGR::Geometry::TYPE_INT2STRING{GT_Flatten($type)}
if $modifier =~ /flat/i;
3761 return $Geo::OGR::Geometry::TYPE_INT2STRING{GT_SetZ($type)}
if $modifier =~ /z/i;
3762 return $Geo::OGR::Geometry::TYPE_INT2STRING{GT_GetCollection($type)}
if $modifier =~ /collection/i;
3763 return $Geo::OGR::Geometry::TYPE_INT2STRING{GT_GetCurve($type)}
if $modifier =~ /curve/i;
3764 return $Geo::OGR::Geometry::TYPE_INT2STRING{GT_GetLinear($type)}
if $modifier =~ /linear/i;
3765 Geo::GDAL::error(1, $modifier, {Flatten => 1, SetZ => 1, GetCollection => 1, GetCurve => 1, GetLinear => 1});
3768 #** @method scalar GeometryTypeTest($type, $test, $type2)
3770 # @param type a geometry type (one of Geo::OGR::GeometryTypes).
3771 # @param test one of 'has_z', 'is_subclass_of', 'is_curve', 'is_surface', or 'is_non_linear'.
3772 # @param type2 a geometry type (one of Geo::OGR::GeometryTypes). Required for 'is_subclass_of' test.
3773 # @return result of the test.
3775 sub GeometryTypeTest {
3776 my($type, $test, $type2) = @_;
3777 Geo::GDAL::error(1, $type, \%Geo::OGR::Geometry::TYPE_STRING2INT) unless exists $Geo::OGR::Geometry::TYPE_STRING2INT{$type};
3778 $type = $Geo::OGR::Geometry::TYPE_STRING2INT{$type};
3779 if (defined $type2) {
3780 Geo::GDAL::error(1, $type2, \%Geo::OGR::Geometry::TYPE_STRING2INT) unless exists $Geo::OGR::Geometry::TYPE_STRING2INT{$type2};
3781 $type2 = $Geo::OGR::Geometry::TYPE_STRING2INT{$type2};
3783 Geo::GDAL::error(
"Usage: GeometryTypeTest(type1, 'is_subclass_of', type2).") if $test =~ /subclass/i;
3785 return GT_HasZ($type) if $test =~ /z/i;
3786 return GT_IsSubClassOf($type, $type2) if $test =~ /subclass/i;
3787 return GT_IsCurve($type) if $test =~ /curve/i;
3788 return GT_IsSurface($type) if $test =~ /surface/i;
3789 return GT_IsNonLinear($type) if $test =~ /linear/i;
3790 Geo::GDAL::error(1, $test, {HasZ => 1, IsSubClassOf => 1, IsCurve => 1, IsSurface => 1, IsNonLinear => 1});
3793 #** @method list GeometryTypes()
3794 # Package subroutine.
3795 # @return a list of all geometry types, currently:
3796 # 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, and Unknown.
3800 # This file was automatically generated by SWIG (http://www.swig.org).
3803 # Do not make changes to this file unless you know what you are doing--modify
3804 # the SWIG interface file instead.
3807 #** @method GetNonLinearGeometriesEnabledFlag()
3809 sub GetNonLinearGeometriesEnabledFlag {
3812 #** @method GetOpenDSCount()
3814 sub GetOpenDSCount {
3817 #** @method Geo::GDAL::Dataset Open($name, $update = 0)
3819 # Open a vector data source.
3820 # @param name The data source string (directory, filename, etc.).
3821 # @param update Whether to open the data source in update mode (default is not).
3822 # @return a new Geo::GDAL::Dataset object.
3825 my @p = @_; # name, update
3826 my @flags = qw/VECTOR/;
3827 push @flags, qw/UPDATE/
if $p[1];
3829 Geo::GDAL::error(
"Failed to open $p[0]. Is it a vector dataset?") unless $dataset;
3833 #** @method Geo::GDAL::Dataset OpenShared($name, $update = 0)
3835 # Open a vector data source in shared mode.
3836 # @param name The data source string (directory, filename, etc.).
3837 # @param update Whether to open the data source in update mode.
3838 # @return a new Geo::GDAL::Dataset object.
3841 my @p = @_; # name, update
3842 my @flags = qw/VECTOR SHARED/;
3843 push @flags, qw/UPDATE/
if $p[1];
3845 Geo::GDAL::error(
"Failed to open $p[0]. Is it a vector dataset?") unless $dataset;
3849 #** @method SetGenerate_DB2_V72_BYTE_ORDER($Generate_DB2_V72_BYTE_ORDER)
3851 # Needed only on IBM DB2.
3853 sub SetGenerate_DB2_V72_BYTE_ORDER {
3856 #** @method SetNonLinearGeometriesEnabledFlag()
3858 sub SetNonLinearGeometriesEnabledFlag {
3861 #** @class Geo::OGR::DataSource
3862 # @brief A vector dataset. This is a legacy class which should not be
3863 # used in new code. Use Geo::GDAL::Dataset.
3865 package Geo::OGR::DataSource;
3867 #** @method Geo::GDAL::Dataset Open()
3868 # Package subroutine.
3869 # The same as Geo::OGR::Open
3874 #** @method Geo::GDAL::Dataset OpenShared()
3875 # Package subroutine.
3876 # The same as Geo::OGR::OpenShared
3881 #** @class Geo::OGR::Driver
3882 # @brief A vector format driver. This is a legacy class which
3883 # should not be used in new code. Use Geo::GDAL::Driver.
3885 package Geo::OGR::Driver;
3889 #** @method Geo::GDAL::Dataset Copy(Geo::GDAL::Dataset source, $name, arrayref options = undef)
3891 # Copy a vector data source into a new data source with this driver.
3892 # @param source The Geo::GDAL::Dataset object to be copied.
3893 # @param name The name for the new data source.
3894 # @param options Driver specific options. In addition to options
3895 # specified in GDAL documentation the option STRICT can be set to 'NO'
3896 # for a more relaxed copy. Otherwise the STRICT is 'YES'.
3897 # @note The order of the first two parameters is different from that in Geo::GDAL::Driver::Copy.
3898 # @return a new Geo::GDAL::Dataset object.
3901 my ($self, @p) = @_; # src, name, options
3902 my $strict = 1; # the
default in bindings
3903 $strict = 0
if $p[2] && $p[2]->{STRICT} eq
'NO';
3904 $self->SUPER::Copy($p[1], $p[0], $strict, @{$p[2..4]}); # path, src, strict, options, cb, cb_data
3907 #** @method Geo::GDAL::Dataset Create($name, hashref options = undef )
3909 # Create a new vector data source using this driver.
3910 # @param name The data source name.
3911 # @param options Driver specific dataset creation options.
3914 my ($self, $name, $options) = @_; # name, options
3916 $self->SUPER::Create(Name => $name, Width => 0, Height => 0, Bands => 0, Type =>
'Byte', Options => $options);
3921 # The same as Geo::OGR::Open except that only this driver is allowed.
3925 my @p = @_; # name, update
3926 my @flags = qw/VECTOR/;
3927 push @flags, qw/UPDATE/
if $p[1];
3929 Geo::GDAL::error(
"Failed to open $p[0]. Is it a vector dataset?") unless $dataset;
3933 #** @class Geo::OGR::Feature
3934 # @brief A collection of non-spatial and spatial attributes.
3936 # A feature is a collection of non-spatial and spatial attributes and
3937 # an id, which is a special attribute, and data records according to
3938 # this data model. Attributes are called fields and some fields are
3939 # spatial, i.e., their value is a geometry. Fields have at least a
3940 # name and a type. Features may exist within a layer or
3941 # separetely. The data model of a feature is a definition object.
3943 package Geo::OGR::Feature;
3947 #** @method Geo::OGR::Feature Clone()
3949 # @return a new Geo::OGR::Feature object
3954 #** @method DumpReadable()
3956 # Write the contents of this feature to stdout.
3961 #** @method scalar Equal($feature)
3963 # @param feature a Geo::OGR::Feature object for comparison
3969 #** @method scalar FID($id)
3971 # @brief Get or set the id of this feature.
3972 # @param id [optional] the id to set for this feature.
3973 # @return integer the id of this feature.
3977 $self->SetFID($_[0])
if @_;
3978 return unless defined wantarray;
3982 #** @method Field($name, $value, ...)
3984 # @brief Get, set, or unset the field value.
3985 # @param name the name (or the index) of the field.
3986 # @param value a scalar, a list of scalars or a reference to a
3987 # list. If undef, the field is unset. If a scalar or a list of
3988 # scalars, the field is set from them.
3989 # @note Non-scalar fields (for example Date) can be set either from a
3990 # scalar, which is then assumed to be a string and parsed, or from a
3991 # list of values (for example year, month, day for Date).
3992 # @return in non-void context the value of the field, which may be a
3993 # scalar or a list, depending on the field type. For unset fields the
3994 # undef value is returned.
3999 $self->SetField($field, @_)
if @_;
4000 $self->GetField($field)
if defined wantarray;
4003 #** @method FillUnsetWithDefault()
4005 sub FillUnsetWithDefault {
4008 #** @method Geometry($name, $geometry)
4010 # @brief Get or set the value of a geometry field.
4011 # @note This method delivers the functionality of undocumented methods
4012 # SetGeometry($geometry), SetGeometryDirectly, SetGeomField,
4013 # SetGeomFieldDirectly, GetGeometry, GetGeometryRef.
4015 # Set or get the geometry in the feature. When setting, does a check
4016 # against the schema (GeometryType) of the feature. If the parameter
4017 # is a geometry object, it is cloned.
4018 # @param name [optional] the name of the spatial field,
4019 # whose geometry is to be set. If not given, sets or gets the geometry
4020 # of the first (or the single) spatial field.
4021 # @param geometry [optional] a Geo::OGR::Geometry object or a
4022 # reference to a hash from which such can be created (using
4023 # Geo::OGR::Geometry::new).
4024 # @return in a non-void context the indicated geometry in the feature
4025 # as a Geo::OGR::Geometry object. The returned object contains a
4026 # reference to the actual geometry data in the feature (the geometry
4027 # is not cloned) and to the feature object, thus keeping the feature
4028 # object from being destroyed while the geometry object exists.
4032 my $field = ((@_ > 0 and ref($_[0]) eq '') or (@_ > 2 and @_ % 2 == 1)) ? shift : 0;
4034 if (@_ and @_ % 2 == 0) {
4040 my $type = $self->GetDefn->GetGeomFieldDefn($field)->Type;
4041 if (blessed($geometry) and $geometry->isa(
'Geo::OGR::Geometry')) {
4042 my $gtype = $geometry->GeometryType;
4043 Geo::GDAL::error(
"The type of the inserted geometry ('$gtype') is not the same as the type of the field ('$type').")
4044 if $type ne 'Unknown' and $type ne $gtype;
4046 $self->SetGeomFieldDirectly($field, $geometry->Clone);
4049 } elsif (ref($geometry) eq
'HASH') {
4050 $geometry->{GeometryType}
4055 Geo::GDAL::error(
"The type of the inserted geometry ('$gtype') is not the same as the type of the field ('$type').")
4056 if $type ne 'Unknown' and $type ne $gtype;
4058 $self->SetGeomFieldDirectly($field, $geometry);
4062 Geo::GDAL::error(
"Usage: \$feature->Geometry([field],[geometry])");
4065 return unless defined wantarray;
4066 $geometry = $self->GetGeomFieldRef($field);
4067 return unless $geometry;
4068 $GEOMETRIES{tied(%$geometry)} = $self;
4072 #** @method Geo::OGR::FeatureDefn GetDefn()
4074 # @note A.k.a GetDefnRef.
4075 # @return a Geo::OGR::FeatureDefn object, which represents the definition of this feature.
4079 my $defn = $self->GetDefnRef;
4080 $DEFNS{tied(%$defn)} = $self;
4084 #** @method scalar GetFID()
4086 # @return the feature id (an integer).
4091 #** @method list GetField($name)
4096 my($self, $field) = @_;
4097 return unless IsFieldSet($self, $field);
4098 my $type = GetFieldType($self, $field);
4099 if ($type == $Geo::OGR::OFTInteger) {
4100 return GetFieldAsInteger($self, $field);
4102 if ($type == $Geo::OGR::OFTInteger64) {
4103 return GetFieldAsInteger64($self, $field);
4105 if ($type == $Geo::OGR::OFTReal) {
4106 return GetFieldAsDouble($self, $field);
4108 if ($type == $Geo::OGR::OFTString) {
4109 return GetFieldAsString($self, $field);
4111 if ($type == $Geo::OGR::OFTIntegerList) {
4112 my $ret = GetFieldAsIntegerList($self, $field);
4113 return wantarray ? @$ret : $ret;
4115 if ($type == $Geo::OGR::OFTInteger64List) {
4116 my $ret = GetFieldAsInteger64List($self, $field);
4117 return wantarray ? @$ret : $ret;
4119 if ($type == $Geo::OGR::OFTRealList) {
4120 my $ret = GetFieldAsDoubleList($self, $field);
4121 return wantarray ? @$ret : $ret;
4123 if ($type == $Geo::OGR::OFTStringList) {
4124 my $ret = GetFieldAsStringList($self, $field);
4125 return wantarray ? @$ret : $ret;
4127 if ($type == $Geo::OGR::OFTBinary) {
4128 return GetFieldAsBinary($self, $field);
4130 if ($type == $Geo::OGR::OFTDate) {
4131 my @ret = GetFieldAsDateTime($self, $field);
4132 # year, month, day, hour, minute, second, timezone
4133 return wantarray ? @ret[0..2] : [@ret[0..2]];
4135 if ($type == $Geo::OGR::OFTTime) {
4136 my @ret = GetFieldAsDateTime($self, $field);
4137 return wantarray ? @ret[3..6] : [@ret[3..6]];
4139 if ($type == $Geo::OGR::OFTDateTime) {
4140 my @ret = GetFieldAsDateTime($self, $field);
4141 return wantarray ? @ret : [@ret];
4143 Geo::GDAL::error(
"Perl bindings do not support field type '$Geo::OGR::FieldDefn::TYPE_INT2STRING{$type}'.");
4146 #** @method Geo::OGR::FieldDefn GetFieldDefn($name)
4148 # @note A.k.a GetFieldDefnRef
4149 # @param name the name of the field.
4150 # @return a new Geo::OGR::FieldDefn object that represents the field
4156 #** @method list GetFieldNames()
4158 # Get the names of the fields in this feature.
4163 #** @method GetGeomFieldDefn()
4165 sub GetGeomFieldDefn {
4168 #** @method GetNativeData()
4173 #** @method GetNativeMediaType()
4175 sub GetNativeMediaType {
4178 #** @method hash reference GetSchema()
4180 # @brief Get the schema of this feature.
4182 # @return the schema as a hash whose keywords are Name, StyleIgnored
4183 # and Fields. Fields is an anonymous array of first non-spatial and
4184 # then spatial field schemas as in Geo::OGR::FieldDefn::Schema() and
4185 # Geo::OGR::GeomFieldDefn::Schema().
4189 Geo::GDAL::error(
"Schema of a feature cannot be set directly.") if @_;
4190 return $self->GetDefnRef->Schema;
4193 #** @method scalar GetStyleString()
4197 sub GetStyleString {
4200 #** @method Geo::OGR::Layer Layer()
4202 # @return the layer to which this feature belongs to or undef.
4206 return $Geo::OGR::Layer::FEATURES{tied(%$self)};
4209 #** @method hash reference Row(%row)
4211 # @note This method discards the data the destination feature (or
4212 # layer) does not support. Changes in data due to differences between
4213 # field types may also occur.
4215 # Get and/or set the data of the feature. The key of the (key,value)
4216 # pairs of the row is the field name. Special field names FID and
4217 # Geometry are used for feature id and (single) geometry
4218 # respectively. The geometry/ies is/are set and get using the
4219 # Geo::OGR::Feature::Geometry method. Field values are set using the
4220 # Geo::OGR::Feature::Field method.
4221 # @param row [optional] feature data in a hash.
4222 # @return a reference to feature data in a hash. Spatial fields are
4223 # returned as Geo::OGR::Geometry objects.
4227 my $nf = $self->GetFieldCount;
4228 my $ngf = $self->GetGeomFieldCount;
4231 if (@_ == 1 and ref($_[0]) eq
'HASH') {
4233 } elsif (@_ and @_ % 2 == 0) {
4236 Geo::GDAL::error(
'Usage: $feature->Row(%FeatureData).');
4238 $self->SetFID($row{FID})
if defined $row{FID};
4239 #$self->Geometry($schema, $row{Geometry}) if $row{Geometry};
4240 for my $name (keys %row) {
4241 next
if $name eq
'FID';
4242 if ($name eq
'Geometry') {
4243 $self->Geometry(0, $row{$name});
4247 for my $i (0..$nf-1) {
4248 if ($self->GetFieldDefnRef($i)->Name eq $name) {
4249 $self->SetField($i, $row{$name});
4255 for my $i (0..$ngf-1) {
4256 if ($self->GetGeomFieldDefnRef($i)->Name eq $name) {
4257 $self->Geometry($i, $row{$name});
4263 carp
"Unknown field: '$name'.";
4266 return unless defined wantarray;
4268 for my $i (0..$nf-1) {
4269 my $name = $self->GetFieldDefnRef($i)->Name;
4270 $row{$name} = $self->GetField($i);
4272 for my $i (0..$ngf-1) {
4273 my $name = $self->GetGeomFieldDefnRef($i)->Name ||
'Geometry';
4274 $row{$name} = $self->GetGeometry($i);
4276 $row{FID} = $self->GetFID;
4280 #** @method SetFID($id)
4282 # @param id the feature id.
4287 #** @method SetField($name, @Value)
4295 if (@_ == 0 or !defined($arg)) {
4296 _UnsetField($self, $field);
4299 $arg = [@_]
if @_ > 1;
4300 my $type = $self->GetFieldType($field);
4302 if ($type == $Geo::OGR::OFTIntegerList) {
4303 SetFieldIntegerList($self, $field, $arg);
4305 elsif ($type == $Geo::OGR::OFTInteger64List) {
4306 SetFieldInteger64List($self, $field, $arg);
4308 elsif ($type == $Geo::OGR::OFTRealList) {
4309 SetFieldDoubleList($self, $field, $arg);
4311 elsif ($type == $Geo::OGR::OFTStringList) {
4312 SetFieldStringList($self, $field, $arg);
4314 elsif ($type == $Geo::OGR::OFTDate) {
4315 _SetField($self, $field, @$arg[0..2], 0, 0, 0, 0);
4317 elsif ($type == $Geo::OGR::OFTTime) {
4319 _SetField($self, $field, 0, 0, 0, @$arg[0..3]);
4321 elsif ($type == $Geo::OGR::OFTDateTime) {
4323 _SetField($self, $field, @$arg[0..6]);
4326 _SetField($self, $field, @$arg);
4329 if ($type == $Geo::OGR::OFTBinary) {
4330 #$arg = unpack('H*', $arg); # remove when SetFieldBinary is available
4331 $self->SetFieldBinary($field, $arg);
4333 _SetField($self, $field, $arg);
4338 #** @method SetFrom($other, $forgiving = 1, hashref map)
4340 # @param other a Geo::OGR::Feature object
4341 # @param forgiving [optional] set to false if the operation should not
4342 # continue if output fields do not match some of the source fields
4343 # @param map [optional] a mapping from output field indexes to source
4344 # fields, include into the hash all field indexes of this feature
4345 # which should be set
4348 my($self, $other) = @_;
4349 _SetFrom($self, $other),
return if @_ <= 2;
4350 my $forgiving = $_[2];
4351 _SetFrom($self, $other, $forgiving),
return if @_ <= 3;
4354 for my $i (1..GetFieldCount($self)) {
4355 push @list, ($map->{$i} || -1);
4357 SetFromWithMap($self, $other, 1, \@list);
4360 #** @method SetNativeData()
4365 #** @method SetNativeMediaType()
4367 sub SetNativeMediaType {
4370 #** @method SetStyleString($string)
4374 sub SetStyleString {
4377 #** @method list Tuple(@tuple)
4379 # @note This method discards the data the destination feature (or
4380 # layer) does not support. Changes in data due to differences between
4381 # field types may also occur.
4383 # @note The schema of the tuple needs to be the same as that of the
4386 # Get and/set the data of the feature. The expected data in the tuple
4387 # is ([feature_id,] non-spatial fields, spatial fields). The fields in
4388 # the tuple are in the order they are in the schema. Field values are
4389 # set using the Geo::OGR::Feature::Field method. Geometries are set
4390 # and get using the Geo::OGR::Feature::Geometry method.
4391 # @param tuple [optional] feature data in an array
4392 # @return feature data in an array
4396 my $nf = $self->GetFieldCount;
4397 my $ngf = $self->GetGeomFieldCount;
4400 $FID = shift
if @_ == $nf + $ngf + 1;
4401 $self->SetFID($FID)
if defined $FID;
4403 if (@$values != $nf + $ngf) {
4405 Geo::GDAL::error(
"Too many or too few attribute values for a feature (need $n).");
4407 my $index = 0; # index to non-geometry and geometry fields
4408 for my $i (0..$nf-1) {
4409 $self->SetField($i, $values->[$i]);
4411 for my $i (0..$ngf-1) {
4412 $self->Geometry($i, $values->[$nf+$i]);
4415 return unless defined wantarray;
4416 my @ret = ($self->GetFID);
4417 for my $i (0..$nf-1) {
4418 my $v = $self->GetField($i);
4421 for my $i (0..$ngf-1) {
4422 my $v = $self->GetGeometry($i);
4428 #** @method scalar Validate(list flags)
4430 # @param flags one of more of null, geom_type, width,
4431 # allow_null_when_default, or all.
4432 # @exception croaks with an error message if the feature is not valid.
4433 # @return integer denoting the validity of the feature object.
4439 my $f = eval
'$Geo::OGR::'.uc($flag);
4442 _Validate($self, $flags);
4445 #** @method Geo::OGR::Feature new(%schema)
4447 # @brief Create a new feature.
4448 # @param A Geo::OGR::FeatureDefn object or named parameters to create one:
4450 # - \a Fields a list of Geo::OGR::FieldDefn or Geo::OGR::GeomFieldDefn
4451 # objects or anonymous hashes from which such can be created.
4452 # - \a GeometryType the geometry type if the feature has only one spatial field.
4453 # - \a StyleIgnored whether the style can be omitted when fetching features. (default is false)
4455 # @note Do not mix GeometryType and geometry fields in Fields list.
4457 # @return a new Geo::OGR::Feature object.
4461 my $arg = blessed($_[0]);
4463 if ($arg && $arg eq
'Geo::OGR::FeatureDefn') {
4468 my $self = Geo::OGRc::new_Feature($defn);
4469 bless $self, $pkg
if defined($self);
4472 #** @class Geo::OGR::FeatureDefn
4473 # @brief The schema of a feature or a layer.
4475 # A FeatureDefn object is a collection of field definition objects. A
4476 # read-only FeatureDefn object can be obtained from a layer
4477 # (Geo::OGR::Layer::GetDefn()) or a feature
4478 # (Geo::OGR::Feature::GetDefn()).
4480 package Geo::OGR::FeatureDefn;
4484 #** @method AddField(%params)
4486 # @param params Named parameters to create a new Geo::OGR::FieldDefn
4487 # or Geo::OGR::GeomFieldDefn object.
4491 Geo::GDAL::error(
"Read-only definition.") if $Geo::OGR::Feature::DEFNS{tied(%$self)} || $Geo::OGR::Layer::DEFNS{tied(%$self)};
4494 } elsif (ref($_[0]) eq
'HASH') {
4496 } elsif (@_ % 2 == 0) {
4500 if (exists $Geo::OGR::FieldDefn::TYPE_STRING2INT{$params{Type}}) {
4502 $self->AddFieldDefn($fd);
4505 $self->AddGeomFieldDefn($fd);
4509 #** @method DeleteField($name)
4511 # @note Currently only geometry fields can be deleted.
4512 # @param index the index of the geometry field to be deleted.
4515 my ($self, $name) = @_;
4516 Geo::GDAL::error(
"Read-only definition.") if $Geo::OGR::Feature::DEFNS{tied(%$self)} || $Geo::OGR::Layer::DEFNS{tied(%$self)};
4517 for my $i (0..$self->GetFieldCount-1) {
4518 Geo::GDAL::error(
"Non-geometry fields cannot be deleted.") if $self->GetFieldDefn($i)->Name eq $name;
4520 for my $i (0..$self->GetGeomFieldCount-1) {
4521 $self->DeleteGeomFieldDefn($i)
if $self->GetGeomFieldDefn($i)->
Name eq $name;
4523 Geo::GDAL::error(2, $name,
'Field');
4526 #** @method Feature()
4530 return $Geo::OGR::Feature::DEFNS{tied(%$self)};
4533 #** @method object GetFieldDefn($name)
4535 # @param name the name of the field.
4536 # @return either a Geo::OGR::FieldDefn or Geo::OGR::GeomFieldDefn
4537 # object that represents the field in question.
4540 my ($self, $name) = @_;
4541 for my $i (0..$self->GetFieldCount-1) {
4542 my $fd = $self->GetFieldDefn($i);
4543 return $fd
if $fd->Name eq $name;
4545 for my $i (0..$self->GetGeomFieldCount-1) {
4546 my $fd = $self->GetGeomFieldDefn($i);
4547 return $fd
if $fd->Name eq $name;
4549 Geo::GDAL::error(2, $name,
'Field');
4552 #** @method list GetFieldNames()
4554 # The names of the fields in this layer or feature definition.
4555 # @return the list of field names.
4560 for my $i (0..$self->GetFieldCount-1) {
4561 push @names, $self->GetFieldDefn($i)->Name;
4563 for my $i (0..$self->GetGeomFieldCount-1) {
4564 push @names, $self->GetGeomFieldDefn($i)->Name;
4569 #** @method scalar GetName()
4571 # @return the name of this layer or feature definition.
4576 #** @method hash reference GetSchema()
4578 # @brief Get the schema of this feature or layer definition.
4580 # @return the schema as a hash whose keywords are Name, StyleIgnored
4581 # and Fields. Fields is an anonymous array of first non-spatial and
4582 # then spatial field schemas as in Geo::OGR::FieldDefn::Schema() and
4583 # Geo::OGR::GeomFieldDefn::Schema().
4587 carp
"Schema of a feature definition should not be set directly." if @_;
4588 if (@_ and @_ % 2 == 0) {
4590 if ($schema{Fields}) {
4591 for my $field (@{$schema{Fields}}) {
4592 $self->AddField($field);
4597 $schema{Name} = $self->Name();
4598 $schema{StyleIgnored} = $self->StyleIgnored();
4599 $schema{Fields} = [];
4600 for my $i (0..$self->GetFieldCount-1) {
4601 my $s = $self->GetFieldDefn($i)->Schema;
4602 push @{$schema{Fields}}, $s;
4604 for my $i (0..$self->GetGeomFieldCount-1) {
4605 my $s = $self->GetGeomFieldDefn($i)->Schema;
4606 push @{$schema{Fields}}, $s;
4608 return wantarray ? %schema : \%schema;
4611 #** @method IsSame(Geo::OGR::FeatureDefn defn)
4613 # @return true if this definition is similar to the other definition,
4619 #** @method scalar IsStyleIgnored()
4621 # Get the ignore status of style information when fetching features.
4622 # @return the ignore status of style information
4625 sub IsStyleIgnored {
4628 #** @method SetStyleIgnored($IgnoreState)
4630 # Set the ignore status of style information when fetching features.
4633 sub SetStyleIgnored {
4636 #** @method Geo::OGR::FeatureDefn new(%schema)
4638 # Creates a new layer or feature definition. The new definition is
4639 # either initialized to the given schema or it will contain no
4640 # non-spatial fields and one spatial field, whose Name is '' and
4641 # GeometryType is 'Unknown' or the value of the named parameter
4643 # @param schema [optional] The schema for the new feature definition,
4644 # as in Geo::OGR::FeatureDefn::Schema().
4645 # @return a Geo::OGR::FeatureDefn object
4649 # $fd = Geo::OGR::FeatureDefn->new(
4651 # Fields => [{ Name => 'field1', Type => 'String' },
4652 # { Name => 'geom', GeometryType => 'Point' }] );
4658 if (@_ == 1 and ref($_[0]) eq
'HASH') {
4660 } elsif (@_ and @_ % 2 == 0) {
4663 my $fields = $schema{Fields};
4664 Geo::GDAL::error(
"The 'Fields' argument must be an array reference.") if $fields and ref($fields) ne 'ARRAY';
4666 my $self = Geo::OGRc::new_FeatureDefn($schema{Name});
4668 my $gt = $schema{GeometryType};
4670 $self->GeometryType($gt);
4672 $self->DeleteGeomFieldDefn(0);
4674 $self->StyleIgnored($schema{StyleIgnored})
if exists $schema{StyleIgnored};
4675 for my $fd (@{$fields}) {
4677 if (ref($fd) eq
'HASH') {
4678 if ($fd->{GeometryType} or exists $Geo::OGR::Geometry::TYPE_STRING2INT{$fd->{Type}}) {
4684 if (blessed($d) and $d->isa(
'Geo::OGR::FieldDefn')) {
4685 AddFieldDefn($self, $d);
4686 } elsif (blessed($d) and $d->isa(
'Geo::OGR::GeomFieldDefn')) {
4687 Geo::GDAL::error(
"Do not mix GeometryType and geometry fields in Fields.") if $gt;
4688 AddGeomFieldDefn($self, $d);
4690 Geo::GDAL::error(
"Item in field list does not define a field.");
4696 #** @class Geo::OGR::FieldDefn
4697 # @brief A definition of a non-spatial attribute.
4699 package Geo::OGR::FieldDefn;
4703 #** @method scalar Default($value)
4705 # Get or set the default value for this field.
4706 # @note a.k.a. GetDefault and SetDefault
4707 # @param value [optional]
4708 # @return the default value of this field in non-void context.
4712 SetDefault($self, $_[0]) if @_;
4713 GetDefault($self) if defined wantarray;
4716 #** @method GetSchema()
4721 #** @method scalar Ignored($ignore)
4723 # Get and/or set the ignore status (whether this field should be
4724 # omitted when fetching features) of this field.
4725 # @note a.k.a. IsIgnored, SetIgnored
4726 # @param ignore [optional]
4727 # @return the ignore status of this field in non-void context.
4732 SetIgnored($self, $_[0]) if @_;
4733 IsIgnored($self) if defined wantarray;
4736 #** @method IsDefaultDriverSpecific()
4738 sub IsDefaultDriverSpecific {
4741 #** @method scalar Justify($justify)
4743 # Get and/or set the justification of this field.
4744 # @note a.k.a. GetJustify, SetJustify
4745 # @param justify [optional] One of field justify types (Geo::OGR::FieldDefn::JustifyValues).
4746 # @return the justify value of this field in non-void context.
4749 my($self, $justify) = @_;
4750 if (defined $justify) {
4751 Geo::GDAL::error(1, $justify, \%JUSTIFY_STRING2INT) unless exists $JUSTIFY_STRING2INT{$justify};
4752 $justify = $JUSTIFY_STRING2INT{$justify}
if exists $JUSTIFY_STRING2INT{$justify};
4753 SetJustify($self, $justify);
4755 return $JUSTIFY_INT2STRING{GetJustify($self)}
if defined wantarray;
4758 #** @method list JustifyValues()
4759 # Package subroutine.
4760 # Justify values supported by GDAL. Current list is
4761 # Left, Right, and Undefined.
4764 return @JUSTIFY_VALUES;
4767 #** @method scalar Name($name)
4769 # Get and/or set the name of the field.
4770 # @note a.k.a. GetName, GetNameRef, SetName
4771 # @param name [optional]
4772 # @return the name in non-void context
4776 SetName($self, $_[0]) if @_;
4777 GetName($self) if defined wantarray;
4780 #** @method scalar Nullable($nullable)
4782 # Get or set the nullable constraint for this field.
4783 # @note a.k.a. IsNullable and SetNullable
4784 # @param nullable [optional]
4785 # @return the nullable value of this field in non-void context.
4789 SetNullable($self, $_[0]) if @_;
4790 IsNullable($self) if defined wantarray;
4793 #** @method scalar Precision($precision)
4795 # Get and/or set the precision of this field.
4796 # @note a.k.a. GetPrecision, SetPrecision
4797 # @param precision [optional]
4798 # @return the precision of this field in non-void context.
4802 SetPrecision($self, $_[0]) if @_;
4803 GetPrecision($self) if defined wantarray;
4806 #** @method hash reference Schema(%params)
4808 # Get the schema or set parts of the schema
4809 # @param params [optional] as those in Geo::OGR::FieldDefn::new.
4810 # @return a reference to a hash whose keys are as those in Geo::OGR::FieldDefn::new.
4815 my $params = @_ % 2 == 0 ? {@_} : shift;
4816 for my $key (keys %SCHEMA_KEYS) {
4817 next unless exists $params->{$key};
4818 eval
"\$self->$key(\$params->{$key})";
4822 return unless defined wantarray;
4824 for my $key (keys %SCHEMA_KEYS) {
4825 $schema{$key} = eval
'$self->'.$key;
4827 return wantarray ? %schema : \%schema;
4830 #** @method SetSchema()
4835 #** @method scalar SubType($SubType)
4837 # @note a.k.a. GetSubType, SetSubType
4838 # @param SubType [optional] One of field sub types (Geo::OGR::FieldDefn::SubTypes).
4839 # @return the sub type of this field in non-void context.
4842 my($self, $sub_type) = @_;
4843 if (defined $sub_type) {
4844 Geo::GDAL::error(1, $sub_type, \%SUB_TYPE_STRING2INT) unless exists $SUB_TYPE_STRING2INT{$sub_type};
4845 $sub_type = $SUB_TYPE_STRING2INT{$sub_type};
4846 SetSubType($self, $sub_type);
4848 return $SUB_TYPE_INT2STRING{GetSubType($self)}
if defined wantarray;
4851 #** @method SubTypes()
4857 #** @method scalar Type($type)
4859 # Get and/or set the type of the field.
4860 # @note a.k.a. GetFieldTypeName, GetTypeName, GetType, SetType
4861 # @param type [optional] One of field types (Geo::OGR::FieldDefn::Types).
4862 # @return one of field types in non-void context.
4865 my($self, $type) = @_;
4866 if (defined $type) {
4867 Geo::GDAL::error(1, $type, \%TYPE_STRING2INT) unless exists $TYPE_STRING2INT{$type};
4868 $type = $TYPE_STRING2INT{$type};
4869 SetType($self, $type);
4871 return $TYPE_INT2STRING{GetType($self)}
if defined wantarray;
4874 #** @method list Types()
4875 # Package subroutine.
4876 # Field types supported by GDAL. Current list is
4877 # Binary, Date, DateTime, Integer, Integer64, Integer64List, IntegerList, Real, RealList, String, StringList, Time, WideString, and WideStringList.
4878 # (However, WideString is not supported.)
4884 #** @method scalar Width($width)
4886 # Get and/or set the field width.
4887 # @note a.k.a. GetWidth, SetWidth
4888 # @param width [optional]
4889 # @return the width of this field in non-void context.
4893 SetWidth($self, $_[0]) if @_;
4894 GetWidth($self) if defined wantarray;
4897 #** @method Geo::OGR::FieldDefn new(%params)
4899 # @brief Create a new field definition.
4901 # @param Named parameters:
4902 # - \a Name Field name (default is 'unnamed').
4903 # - \a Type Field type, one of Geo::OGR::FieldDefn::Types (default is 'String').
4904 # - \a SubType Field sub type, one of Geo::OGR::FieldDefn::SubTypes.
4905 # - \a Justify Justify value, one of Geo::OGR::FieldDefn::JustifyValues
4908 # - \a Nullable (default is true)
4910 # - \a Ignored (default is false)
4911 # @return a new Geo::OGR::FieldDefn object
4915 my $params = {Name =>
'unnamed', Type =>
'String'};
4917 } elsif (@_ == 1 and not ref $_[0]) {
4918 $params->{Name} = shift;
4919 } elsif (@_ == 2 and not $Geo::OGR::FieldDefn::SCHEMA_KEYS{$_[0]}) {
4920 $params->{Name} = shift;
4921 $params->{Type} = shift;
4923 my $tmp = @_ % 2 == 0 ? {@_} : shift;
4924 for my $key (keys %$tmp) {
4925 if ($Geo::OGR::FieldDefn::SCHEMA_KEYS{$key}) {
4926 $params->{$key} = $tmp->{$key};
4928 carp
"Unknown parameter: '$key'." if $key ne
'Index';
4932 $params->{Type} = Geo::GDAL::string2int($params->{Type}, \%Geo::OGR::FieldDefn::TYPE_STRING2INT);
4933 my $self = Geo::OGRc::new_FieldDefn($params->{Name}, $params->{Type});
4935 delete $params->{Name};
4936 delete $params->{Type};
4937 $self->Schema($params);
4941 #** @class Geo::OGR::GeomFieldDefn
4942 # @brief A definition of a spatial attribute.
4944 package Geo::OGR::GeomFieldDefn;
4948 #** @method scalar GeometryType($type)
4950 # @note a.k.a. GetType, SetType
4951 # @return the geometry type of the field.
4956 #** @method GetSchema()
4961 #** @method scalar Ignored($ignore)
4963 # @note a.k.a. IsIgnored, SetIgnored
4964 # @return the ignore status of the field.
4968 SetIgnored($self, $_[0]) if @_;
4969 IsIgnored($self) if defined wantarray;
4972 #** @method scalar Name($name)
4974 # @note a.k.a. GetName, GetNameRef, SetName
4975 # @return the name of the field.
4979 SetName($self, $_[0]) if @_;
4980 GetName($self) if defined wantarray;
4983 #** @method scalar Nullable($nullable)
4985 # @note a.k.a. IsNullable, SetNullable
4986 # @return the nullable status of the field.
4990 SetNullable($self, $_[0]) if @_;
4991 IsNullable($self) if defined wantarray;
4994 #** @method hash reference Schema(%params)
4996 # Get the schema or set parts of the schema.
4997 # @param params [optional] as those in Geo::OGR::GeomFieldDefn::new.
4998 # @return a reference to a hash whose keys are as those in Geo::OGR::GeomFieldDefn::new.
5003 my $params = @_ % 2 == 0 ? {@_} : shift;
5004 for my $key (keys %SCHEMA_KEYS) {
5005 next unless exists $params->{$key};
5006 eval
"\$self->$key(\$params->{$key})";
5010 return unless defined wantarray;
5012 for my $key (keys %SCHEMA_KEYS) {
5013 $schema{$key} = eval
'$self->'.$key;
5015 return wantarray ? %schema : \%schema;
5018 #** @method SetSchema()
5023 #** @method scalar SpatialReference($sr)
5025 # @note a.k.a. GetSpatialRef, SetSpatialRef
5026 # @return the spatial reference of the field as a Geo::OSR::SpatialReference object.
5028 sub SpatialReference {
5030 SetSpatialRef($self, $_[0])
if @_;
5031 GetSpatialRef($self)
if defined wantarray;
5036 # @return the type of this geometry field. One of Geo::OGR::GeomFieldDefn::Types
5039 my($self, $type) = @_;
5040 if (defined $type) {
5041 $type = Geo::GDAL::string2int($type, \%Geo::OGR::Geometry::TYPE_STRING2INT);
5042 SetType($self, $type);
5044 $Geo::OGR::Geometry::TYPE_INT2STRING{GetType($self)}
if defined wantarray;
5048 # Package subroutine.
5049 # @return a list of all geometry types, currently:
5050 # 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, and Unknown.
5053 return @Geo::OGR::Geometry::GEOMETRY_TYPES;
5056 #** @method Geo::OGR::GeomFieldDefn new(%params)
5058 # @brief Create a new spatial field definition.
5060 # @param params one or more of:
5061 # - \a Name name for the field (default is 'geom').
5062 # - \a GeometryType type for the field type, one of Geo::OGR::GeomFieldDefn::Types (default is 'Unknown').
5063 # - \a SpatialReference a Geo::OSR::SpatialReference object.
5064 # - \a Nullable (default is true)
5065 # - \a Ignored (default is false)
5066 # @return a new Geo::OGR::GeomFieldDefn object
5070 my $params = {Name =>
'geom', Type =>
'Unknown'};
5073 $params->{Name} = shift;
5074 } elsif (@_ == 2 and not $Geo::OGR::GeomFieldDefn::SCHEMA_KEYS{$_[0]}) {
5075 $params->{Name} = shift;
5076 $params->{Type} = shift;
5078 my $tmp = @_ % 2 == 0 ? {@_} : shift;
5079 for my $key (keys %$tmp) {
5080 if ($Geo::OGR::GeomFieldDefn::SCHEMA_KEYS{$key}) {
5081 $params->{$key} = $tmp->{$key};
5083 carp
"Unknown parameter: '$key'." if $key ne
'Index' && $key ne
'GeometryType';
5088 $params->{Type} = Geo::GDAL::string2int($params->{Type}, \%Geo::OGR::Geometry::TYPE_STRING2INT);
5089 my $self = Geo::OGRc::new_GeomFieldDefn($params->{Name}, $params->{Type});
5091 delete $params->{Name};
5092 delete $params->{Type};
5093 $self->Schema($params);
5097 #** @class Geo::OGR::Geometry
5098 # @brief Spatial data.
5100 # A geometry is spatial data (coordinate values, and a reference to a
5101 # spatial reference system) organized into one of the geometry
5102 # types. Geometries can be created from several type of data including
5103 # a Perl data structure. There are several methods, which modify,
5104 # compare, test, or compute values from geometries.
5105 # @note Most spatial analysis methods require <a
5106 # href="http://geos.osgeo.org/doxygen/">GEOS</a> to work rigorously.
5108 package Geo::OGR::Geometry;
5112 #** @method AddGeometry($other)
5114 # Add a copy of another geometry to a geometry collection
5115 # @param other a Geo::OGR::Geometry object
5120 #** @method AddGeometryDirectly($other)
5122 # @param other a Geo::OGR::Geometry object
5124 sub AddGeometryDirectly {
5127 #** @method AddPoint($x, $y, $z)
5129 # Set the data of a point or add a point to a line string. Consider
5130 # using Geo::OGR::Geometry::Points. Note that the coordinate
5131 # dimension is automatically upgraded to 25D (3) if z is given.
5134 # @param z [optional]
5135 # Calls internally the 2D or 3D version depending on the number of parameters.
5139 my $t = $self->GetGeometryType;
5140 my $has_z = Geo::OGR::GT_HasZ($t);
5141 my $has_m = Geo::OGR::GT_HasM($t);
5142 if (!$has_z && !$has_m) {
5143 $self->AddPoint_2D(@_[0..1]);
5144 } elsif ($has_z && !$has_m) {
5145 $self->AddPoint_3D(@_[0..2]);
5146 } elsif (!$has_z && $has_m) {
5147 $self->AddPointM(@_[0..2]);
5149 $self->AddPointZM(@_[0..3]);
5153 #** @method AddPointM()
5158 #** @method AddPointZM()
5163 #** @method AddPoint_2D($x, $y)
5165 # Set the data of a point or add a point to a line string. Consider
5166 # using Geo::OGR::Geometry::Points.
5173 #** @method AddPoint_3D($x, $y, $z)
5175 # Set the data of a point or add a point to a line string. Note that
5176 # the coordinate dimension is automatically upgraded to 25D (3). Consider
5177 # using Geo::OGR::Geometry::Points.
5185 #** @method Geo::OGR::Geometry ApproximateArcAngles(%params)
5186 # Package subroutine.
5187 # Create a line string, which approximates an arc.
5188 # @note All angles are in degrees.
5190 # @param %params Named parameters:
5191 # - \a Center center point (default is [0, 0, 0])
5192 # - \a PrimaryRadius default is 1.
5193 # - \a SecondaryAxis default is 1.
5194 # - \a Rotation default is 0.
5195 # - \a StartAngle default is 0.
5196 # - \a EndAngle default is 360.
5197 # - \a MaxAngleStepSizeDegrees default is 4.
5198 # @return a new Geo::OGR::Geometry object.
5200 sub ApproximateArcAngles {
5202 my %
default = ( Center => [0,0,0],
5208 MaxAngleStepSizeDegrees => 4
5210 for my $p (keys %p) {
5211 if (exists $default{$p}) {
5214 carp
"Unknown parameter: '$p'.";
5217 for my $p (keys %
default) {
5220 Geo::GDAL::error(
"Usage: Center => [x,y,z].") unless ref($p{Center}) eq
'ARRAY';
5224 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});
5227 #** @method scalar Area()
5229 # @note a.k.a. GetArea
5230 # @return the area of the polygon or multipolygon
5235 #** @method scalar As(%params)
5237 # Export the geometry into a known format.
5239 # @param params Named parameters:
5240 # - \a Format One of
5241 # - \a WKT Well Known Text.
5242 # - <em>ISO WKT</em>
5243 # - \a Text Same as WKT.
5244 # - \a WKB Well Known Binary.
5245 # - <em>ISO WKB</em>
5246 # - \a Binary Same as WKB.
5251 # - \a ByteOrder Byte order for binary formats. Default is 'XDR'.
5252 # - \a SRID Spatial reference id for HEXEWKB.
5253 # - \a Options GML generation options.
5254 # - \a AltitudeMode For KML.
5256 # @return the geometry in a given format.
5260 my $p = Geo::GDAL::named_parameters(\@_, Format => undef, ByteOrder =>
'XDR', SRID => undef, Options => undef, AltitudeMode => undef);
5261 my $f = $p->{format};
5262 if ($f =~ /text/i) {
5263 return $self->AsText;
5264 } elsif ($f =~ /wkt/i) {
5266 return $self->ExportToIsoWkt;
5268 return $self->AsText;
5270 } elsif ($f =~ /binary/i) {
5271 return $self->ExportToWkb($p->{byteorder});
5272 } elsif ($f =~ /wkb/i) {
5274 $p->{byteorder} = Geo::GDAL::string2int($p->{byteorder}, \%Geo::OGR::Geometry::BYTE_ORDER_STRING2INT);
5275 return $self->ExportToIsoWkb($p->{byteorder});
5276 } elsif ($f =~ /ewkb/i) {
5277 return $self->AsHEXEWKB($p->{srid});
5278 } elsif ($f =~ /hex/i) {
5279 return $self->AsHEXWKB;
5281 return $self->ExportToWkb($p->{byteorder});
5283 } elsif ($f =~ /gml/i) {
5284 return $self->ExportToGML($p->{options});
5285 } elsif ($f =~ /kml/i) {
5286 return $self->ExportToKML($p->{altitudemode});
5287 } elsif ($f =~ /json/i) {
5288 return $self->AsJSON;
5290 Geo::GDAL::error(1, $f, map {$_=>1} qw/Text WKT ISO_WKT ISO_WKB HEX_WKB HEX_EWKB Binary GML KML JSON/);
5294 #** @method AssignSpatialReference($srs)
5296 # @param srs a Geo::OSR::SpatialReference object
5298 sub AssignSpatialReference {
5301 #** @method Geo::OGR::Geometry Boundary()
5303 # @note a.k.a. GetBoundary
5304 # @return the boundary of this geometry as a geometry
5310 #** @method Geo::OGR::Geometry Buffer($distance, $quadsecs = 30)
5314 # @return a new Geo::OGR::Geometry object
5319 #** @method Geo::OGR::Geometry BuildPolygonFromEdges($BestEffort = 0, $AutoClose = 0, $Tolerance = 0)
5321 # Attempt to create a polygon from a collection of lines or from a multilinestring.
5322 # @param BestEffort For future
5323 # @param AutoClose Assure the first and last points of rings are same.
5324 # @param Tolerance Snap distance.
5325 # @exception Several possibilities, some are reported, some are general errors.
5326 # @return a new Geo::OGR::Geometry object (Polygon)
5328 sub BuildPolygonFromEdges {
5331 #** @method list ByteOrders()
5332 # Package subroutine.
5333 # Same as Geo::OGR::ByteOrders
5336 return @BYTE_ORDER_TYPES;
5339 #** @method Geo::OGR::Geometry Centroid()
5341 # @return a new Geo::OGR::Geometry object
5347 #** @method Geo::OGR::Geometry Clone()
5349 # @return a new Geo::OGR::Geometry object
5354 #** @method CloseRings()
5360 #** @method Geo::OGR::Geometry Collect(@geometries)
5362 # Create a geometrycollection from this and possibly other geometries.
5363 # @param geometries [optional] More geometries to add to the collection.
5364 # @return a new Geo::OGR::Geometry object of type geometrycollection.
5369 #** @method scalar Contains($other)
5371 # @param other a Geo::OGR::Geometry object
5372 # @return true if this geometry contains the other geometry, false otherwise
5377 #** @method Geo::OGR::Geometry ConvexHull()
5379 # @return a new Geo::OGR::Geometry object
5384 #** @method scalar CoordinateDimension($dimension)
5386 # @param dimension [optional]
5389 sub CoordinateDimension {
5391 SetCoordinateDimension($self, $_[0]) if @_;
5392 GetCoordinateDimension($self) if defined wantarray;
5395 #** @method scalar Crosses($other)
5397 # @param other a Geo::OGR::Geometry object
5398 # @return true if this geometry crosses the other geometry, false otherwise
5403 #** @method DelaunayTriangulation()
5405 sub DelaunayTriangulation {
5408 #** @method Geo::OGR::Geometry Difference($other)
5410 # @param other a Geo::OGR::Geometry object
5411 # @return a new Geo::OGR::Geometry object
5416 #** @method scalar Disjoint($other)
5418 # @param other a Geo::OGR::Geometry object
5419 # @return true if this geometry is disjoint from the other geometry, false otherwise
5424 #** @method list Dissolve()
5426 # Dissolve a geometrycollection into separate geometries.
5427 # @return a list of new Geo::OGR::Geometry objects cloned from the collection.
5432 my $n = $self->GetGeometryCount;
5434 for my $i (0..$n-1) {
5435 push @c, $self->GetGeometryRef($i)->Clone;
5443 #** @method scalar Distance($other)
5445 # @param other a Geo::OGR::Geometry object
5446 # @return the distance to the other geometry
5453 # Clear geometry data, i.e., remove all points, or, for a point, set
5454 # the coordinate dimension as zero.
5459 #** @method scalar Equals($other)
5461 # @note a.k.a. Equal (deprecated)
5462 # @param other a Geo::OGR::Geometry object
5463 # @return true if this geometry is equivalent to the other geometry, false otherwise
5468 #** @method Extent()
5475 #** @method Feature()
5479 return $Geo::OGR::Feature::GEOMETRIES{tied(%$self)};
5482 #** @method FlattenTo2D()
5488 #** @method Geo::OGR::Geometry ForceTo($type, ref options)
5490 # Attempt to make a geometry of type 'type' out of this geometry.
5491 # @param type target geometry type. One of Geo::OGR::GeometryTypes.
5492 # @param options not used currently.
5493 # @return a new Geo::OGR::Geometry object.
5498 $type = Geo::GDAL::string2int($type, \%TYPE_STRING2INT);
5500 $self = Geo::OGR::ForceTo($self, $type, @_);
5506 #** @method Geo::OGR::Geometry ForceToCollection(@geometries)
5508 # Create a geometrycollection from the geometry.
5509 # @param geometries [optional] More geometries to add to the collection.
5510 # @return a new Geo::OGR::Geometry object of type geometrycollection.
5512 sub ForceToCollection {
5520 #** @method Geo::OGR::Geometry ForceToLineString()
5522 # Attempt to create a line string from this geometry.
5523 # @return a new Geo::OGR::Geometry object.
5525 sub ForceToLineString {
5527 return Geo::OGR::ForceToLineString($self);
5530 #** @method Geo::OGR::Geometry ForceToMultiLineString(@linestrings)
5532 # Attempt to create a multilinestring from the geometry, which must be a linestring.
5533 # @param linestrings [optional] More linestrings to add to the collection.
5534 # @return a new Geo::OGR::Geometry object of type multilinestring.
5536 sub ForceToMultiLineString {
5538 $self = Geo::OGR::ForceToMultiLineString($self);
5540 $self->AddGeometry($g);
5545 #** @method Geo::OGR::Geometry ForceToMultiPoint(@points)
5547 # Attempt to create a multipoint from the geometry, which must be a point.
5548 # @param points [optional] More points to add to the collection.
5549 # @return a new Geo::OGR::Geometry object of type multipoint.
5551 sub ForceToMultiPoint {
5553 $self = Geo::OGR::ForceToMultiPoint($self);
5555 $self->AddGeometry($g);
5560 #** @method Geo::OGR::Geometry ForceToMultiPolygon(@polygons)
5562 # Attempt to create a multipolygon from the geometry, which must be a polygon.
5563 # @param polygons [optional] More polygons to add to the collection.
5564 # @return a new Geo::OGR::Geometry object of type multipolygon.
5566 sub ForceToMultiPolygon {
5568 $self = Geo::OGR::ForceToMultiPolygon($self);
5570 $self->AddGeometry($g);
5575 #** @method Geo::OGR::Geometry ForceToPolygon()
5577 # Attempt to create a polygon from this geometry.
5578 # @exception None reported. If this method fails, just a copy is returned.
5579 # @return a new Geo::OGR::Geometry object.
5581 sub ForceToPolygon {
5584 #** @method scalar GeometryType()
5586 # @return the geometry type of this geometry (one of Geo::OGR::GeometryTypes).
5590 return $TYPE_INT2STRING{$self->GetGeometryType};
5593 #** @method list GeometryTypes()
5594 # Package subroutine.
5595 # Same as Geo::OGR::GeometryTypes
5598 return @GEOMETRY_TYPES;
5601 #** @method scalar GetCoordinateDimension()
5603 # @return an integer
5605 sub GetCoordinateDimension {
5608 #** @method GetCurveGeometry()
5610 sub GetCurveGeometry {
5613 #** @method scalar GetDimension()
5615 # @return 0, 1, or 2
5620 #** @method list GetEnvelope()
5622 # @note In scalar context returns a reference to an anonymous array
5623 # containing the envelope.
5624 # @return the envelope ($minx, $maxx, $miny, $maxy)
5629 #** @method list GetEnvelope3D()
5631 # @note In scalar context returns a reference to an anonymous array
5632 # containing the envelope.
5633 # @return the 3-D envelope ($minx, $maxx, $miny, $maxy, $minz, $maxz)
5639 #** @method scalar GetGeometryCount()
5641 # @return an integer
5643 sub GetGeometryCount {
5646 #** @method scalar GetGeometryName()
5648 # @deprecated use Geo::OGR::Geometry::GeometryType.
5652 sub GetGeometryName {
5655 #** @method scalar GetGeometryRef($index)
5657 # @param index index to the geometry, which is a part of this geometry
5658 # @return a new Geo::OGR::Geometry object whose data is a part of the
5661 sub GetGeometryRef {
5664 #** @method scalar GetGeometryType()
5666 # @deprecated use Geo::OGR::Geometry::GeometryType, which returns the
5669 # @return type as an integer
5671 sub GetGeometryType {
5674 #** @method GetLinearGeometry()
5676 sub GetLinearGeometry {
5684 #** @method list GetPoint($index = 0)
5687 # @return (x,y) or a list with more coordinates
5692 my $t = $self->GetGeometryType;
5693 my $has_z = Geo::OGR::GT_HasZ($t);
5694 my $has_m = Geo::OGR::GT_HasM($t);
5696 if (!$has_z && !$has_m) {
5697 $point = $self->GetPoint_2D($i);
5698 } elsif ($has_z && !$has_m) {
5699 $point = $self->GetPoint_3D($i);
5700 } elsif (!$has_z && $has_m) {
5701 $point = $self->GetPointZM($i);
5702 @$point = ($point->[0], $point->[1], $point->[3]);
5704 $point = $self->GetPointZM($i);
5706 return wantarray ? @$point : $point;
5709 #** @method scalar GetPointCount()
5711 # @return an integer
5716 #** @method GetPointZM()
5721 #** @method scalar GetPoint_2D($index = 0)
5724 # @return (x,y) or a list with more coordinates
5729 #** @method scalar GetPoint_3D($index = 0)
5732 # @return (x,y) or a list with more coordinates
5737 #** @method Geo::OSR::SpatialReference GetSpatialReference()
5739 # @return a new Geo::OSR::SpatialReference object
5741 sub GetSpatialReference {
5744 #** @method scalar GetX($index = 0)
5752 #** @method scalar GetY($index = 0)
5760 #** @method scalar GetZ($index = 0)
5768 #** @method HasCurveGeometry()
5770 sub HasCurveGeometry {
5773 #** @method Geo::OGR::Geometry Intersection($other)
5775 # @param other a Geo::OGR::Geometry object
5776 # @return a new Geo::OGR::Geometry object
5781 #** @method scalar Intersects($other)
5783 # @note a.k.a. Intersect (deprecated)
5784 # @param other a Geo::OGR::Geometry object
5785 # @return true if this geometry intersects with the other geometry, false otherwise
5795 #** @method scalar IsEmpty()
5797 # Test whether the geometry is empty (has no points, or, for a point,
5798 # has coordinate dimension of zero).
5804 #** @method IsMeasured()
5809 #** @method scalar IsRing()
5811 # Test if the geometry is a ring. Requires GEOS in GDAL.
5817 #** @method scalar IsSimple()
5819 # Test the simplicity of the geometry (OGC sense). Requires GEOS in GDAL.
5825 #** @method scalar IsValid()
5827 # Test the validity of the geometry (OGC sense). Requires GEOS in GDAL.
5833 #** @method scalar Length()
5835 # @return the length of the linestring
5840 #** @method Move($dx, $dy, $dz)
5842 # Move every point of the object as defined by the parameters.
5845 # @param dz [optional]
5850 #** @method scalar Overlaps($other)
5852 # @param other a Geo::OGR::Geometry object
5853 # @return true if this geometry overlaps the other geometry, false otherwise
5858 #** @method list Point($index, $x, $y, $z)
5860 # Get or set the point
5861 # @param index The index of the point. Optional (ignored if given) for
5862 # Point and Point25D geometries.
5863 # @param x [optional]
5864 # @param y [optional]
5865 # @param z [optional]
5872 my $t = $self->GetGeometryType;
5874 if (Geo::OGR::GT_Flatten($t) == $Geo::OGR::wkbPoint) {
5875 my $has_z = Geo::OGR::GT_HasZ($t);
5876 my $has_m = Geo::OGR::GT_HasM($t);
5877 if (!$has_z && !$has_m) {
5880 } elsif ($has_z || $has_m) {
5888 $i = shift unless defined $i;
5889 $self->SetPoint($i, @_);
5891 return unless defined wantarray;
5892 my $point = $self->GetPoint;
5893 return wantarray ? @$point : $point;
5896 #** @method PointOnSurface()
5898 sub PointOnSurface {
5901 #** @method array reference Points(arrayref points)
5903 # Get or set the points of the geometry. The points (vertices) are
5904 # stored in obvious lists of lists. When setting, the geometry is
5905 # first emptied. The method uses internally either AddPoint_2D or
5906 # AddPoint_3D depending on the coordinate dimension of the input data.
5908 # @note The same structure may represent different geometries
5909 # depending on the actual geometry type of the object.
5911 # @param points [optional] A reference to an array. A point is a reference to an
5912 # array of numbers, a linestring or a ring is a reference to an array of points,
5913 # a polygon is a reference to an array of rings, etc.
5915 # @return A reference to an array.
5919 my $t = $self->GetGeometryType;
5920 my $has_z = Geo::OGR::GT_HasZ($t);
5921 my $has_m = Geo::OGR::GT_HasM($t);
5923 $postfix .=
'Z' if Geo::OGR::GT_HasZ($t);
5924 $postfix .=
'M' if Geo::OGR::GT_HasM($t);
5925 $t = $TYPE_INT2STRING{Geo::OGR::GT_Flatten($t)};
5929 if ($t eq
'Unknown' or $t eq
'None' or $t eq
'GeometryCollection') {
5930 Geo::GDAL::error(
"Can't set points of a geometry of type '$t'.");
5931 } elsif ($t eq
'Point') {
5932 # support both "Point" as a list of one point and one point
5933 if (ref($points->[0])) {
5934 $self->AddPoint(@{$points->[0]});
5936 $self->AddPoint(@$points);
5938 } elsif ($t eq
'LineString' or $t eq
'LinearRing' or $t eq
'CircularString') {
5939 for my $p (@$points) {
5940 $self->AddPoint(@$p);
5942 } elsif ($t eq
'Polygon') {
5943 for my $r (@$points) {
5945 $ring->
Set3D(1)
if $has_z;
5946 $ring->SetMeasured(1)
if $has_m;
5948 $self->AddGeometryDirectly($ring);
5950 } elsif ($t eq
'MultiPoint') {
5951 for my $p (@$points) {
5954 $self->AddGeometryDirectly($point);
5956 } elsif ($t eq
'MultiLineString') {
5957 for my $l (@$points) {
5960 $self->AddGeometryDirectly($linestring);
5962 } elsif ($t eq
'MultiPolygon') {
5963 for my $p (@$points) {
5966 $self->AddGeometryDirectly($polygon);
5970 return unless defined wantarray;
5971 $self->_GetPoints();
5974 #** @method Segmentize($MaxLength)
5976 # Modify the geometry such it has no segment longer than the given length.
5977 # @param MaxLength the given length
5987 #** @method SetCoordinateDimension($dimension)
5991 sub SetCoordinateDimension {
5994 #** @method SetMeasured()
5999 #** @method SetPoint($index, $x, $y, $z)
6001 # Set the data of a point or a line string. Note that the coordinate
6002 # dimension is automatically upgraded to 25D (3) if z is given.
6006 # @param z [optional]
6010 my $t = $self->GetGeometryType;
6011 my $has_z = Geo::OGR::GT_HasZ($t);
6012 my $has_m = Geo::OGR::GT_HasM($t);
6013 if (!$has_z && !$has_m) {
6014 $self->SetPoint_2D(@_[0..2]);
6015 } elsif ($has_z && !$has_m) {
6016 $self->SetPoint_3D(@_[0..3]);
6017 } elsif (!$has_z && $has_m) {
6018 $self->SetPointM(@_[0..3]);
6020 $self->SetPointZM(@_[0..4]);
6024 #** @method SetPointM()
6029 #** @method SetPointZM()
6034 #** @method SetPoint_2D($index, $x, $y)
6043 #** @method SetPoint_3D($index, $x, $y, $z)
6045 # Set the data of a point or a line string. Note that the coordinate
6046 # dimension is automatically upgraded to 25D (3).
6055 #** @method Geo::OGR::Geometry Simplify($Tolerance)
6057 # Simplify the geometry.
6058 # @param Tolerance the length tolerance for the simplification
6060 # @return a new Geo::OSR::Geometry object
6065 #** @method SimplifyPreserveTopology()
6067 sub SimplifyPreserveTopology {
6070 #** @method Geo::OGR::Geometry SymDifference($other)
6072 # Compute symmetric difference.
6073 # @note a.k.a. SymmetricDifference
6074 # @param other a Geo::OGR::Geometry object
6075 # @return a new Geo::OGR::Geometry object
6081 #** @method scalar Touches($other)
6083 # @param other a Geo::OGR::Geometry object
6084 # @return true if this geometry touches the other geometry, false otherwise
6089 #** @method Transform($trans)
6091 # @param trans a Geo::OSR::CoordinateTransformation object
6096 #** @method TransformTo($srs)
6098 # @param srs a Geo::OSR::SpatialReference object
6103 #** @method Geo::OGR::Geometry Union($other)
6105 # @param other a Geo::OGR::Geometry object
6106 # @return a new Geo::OGR::Geometry object
6111 #** @method Geo::OGR::Geometry UnionCascaded()
6113 # @return a new Geo::OGR::Geometry object
6124 #** @method scalar Within($other)
6126 # @param other a Geo::OGR::Geometry object
6127 # @return true if this geometry is within the other geometry, false otherwise
6132 #** @method scalar WkbSize()
6134 # @return an integer
6139 #** @method Geo::OGR::Geometry new(%params)
6141 # @param %params A named parameter, one of:
6142 # - \a GeometryType one the supported geometry types, see Geo::OGR::GeometryTypes.
6143 # - \a WKT a well known text string, which defines a geometry.
6144 # - \a WKB a well known binary string, which defines a geometry.
6145 # - \a HEXWKB WKB in hexadecimal.
6146 # - \a HEXEWKB PostGIS extended WKB.
6147 # - \a GML geometry written in Geographic Markup Language.
6148 # - \a GeoJSON geometry written in GeoJSON (JavaScript Object Notation for Geographic data).
6149 # - \a arc a reference to a list of values defining an arc: [CenterX,
6150 # CenterY, CenterZ, PrimaryRadius, SecondaryRadius, Rotation,
6151 # StartAngle, EndAngle, MaxAngleStepSizeDegrees] (see also Geo::OGR::Geometry::ApproximateArcAngles)
6152 # - \a Points An anonymous array as in method
6153 # Geo::OGR::Geometry::Points; Note: requires also GeometryType
6156 # @return a new Geo::OGR::Geometry object.
6161 if (@_ == 1 and ref($_[0]) eq
'HASH') {
6163 } elsif (@_ % 2 == 0) {
6166 ($param{GeometryType}) = @_;
6168 my $type = $param{GeometryType}
6169 my $srs = $param{SRS}
6170 my $wkt = $param{WKT}
6171 my $wkb = $param{WKB}
6172 my $hex = $param{HEXEWKB}
6175 # EWKB contains SRID
6176 $srid = substr($hex, 10, 8);
6177 substr($hex, 10, 8) =
'';
6179 $hex = $param{HEXWKB}
6183 for (my $i = 0; $i < length($hex); $i+=2) {
6184 $wkb .= chr(hex(substr($hex,$i,2)));
6187 my $gml = $param{GML}
6188 my $json = $param{GeoJSON}
6189 my $points = $param{Points}
6190 my $arc = $param{Arc}
6193 $self = Geo::OGRc::CreateGeometryFromWkt($wkt, $srs);
6194 } elsif (defined $wkb) {
6195 $self = Geo::OGRc::CreateGeometryFromWkb($wkb, $srs);
6196 } elsif (defined $gml) {
6197 $self = Geo::OGRc::CreateGeometryFromGML($gml);
6198 } elsif (defined $json) {
6199 $self = Geo::OGRc::CreateGeometryFromJson($json);
6200 } elsif (defined $type) {
6201 $type = Geo::GDAL::string2int($type, \%Geo::OGR::Geometry::TYPE_STRING2INT);
6202 $self = Geo::OGRc::new_Geometry($type); # flattens the type
6203 $self->Set3D(1)
if Geo::OGR::GT_HasZ($type);
6204 $self->SetMeasured(1)
if Geo::OGR::GT_HasM($type);
6205 } elsif (defined $arc) {
6206 $self = Geo::OGRc::ApproximateArcAngles(@$arc);
6208 Geo::GDAL::error(1, undef, map {$_=>1} qw/GeometryType WKT WKB HEXEWKB HEXWKB GML GeoJSON Arc/);
6210 bless $self, $pkg
if defined $self;
6211 $self->Points($points)
if $points;
6215 #** @class Geo::OGR::Layer
6216 # @brief A collection of similar features.
6218 # A layer object is typically obtained with a data source object. A
6219 # layer has a data model (a schema), which is maintained in a
6220 # definition object, and a set of features, which contain data
6221 # according to the data model. The schema is typically set when the
6222 # layer is created or opened, but it may be altered somewhat with
6223 # methods Geo::OGR::Layer::CreateField,
6224 # Geo::OGR::Layer::AlterFieldDefn, and
6225 # Geo::OGR::Layer::DeleteField. Features and/or their data can be
6226 # read, inserted and deleted. Reading can be filtered. Layers can be
6227 # compared to each other with methods Clip, Erase, Identity,
6228 # Intersection, SymDifference, Union, and Update.
6230 # A layer may have metadata OLMD_FID64 => 'YES' if it holds features
6231 # with 64 bit FIDs. The metadata of a layer can be obtained with
6232 # GetMetadata method.
6234 package Geo::OGR::Layer;
6238 #** @method AlterFieldDefn($name, %params)
6240 # @param field the name of the field to be altered.
6241 # @param params as in Geo::OGR::FieldDefn::new. Width and
6242 # Precision should be both or neither.
6243 # @note Only non-spatial fields can be altered.
6244 # @note Also the deprecated form AlterFieldDefn($field,
6245 # Geo::OGR::FieldDefn $Defn, $Flags) works.
6247 sub AlterFieldDefn {
6250 my $index = $self->GetLayerDefn->GetFieldIndex($field);
6251 if (blessed($_[0]) and $_[0]->isa(
'Geo::OGR::FieldDefn')) {
6252 _AlterFieldDefn($self, $index, @_);
6254 my $params = @_ % 2 == 0 ? {@_} : shift;
6257 $flags |= 1
if exists $params->{Name};
6258 $flags |= 2
if exists $params->{Type};
6259 $flags |= 4
if exists $params->{Width} or exists $params->{Precision};
6260 $flags |= 8
if exists $params->{Nullable};
6261 $flags |= 16
if exists $params->{Default};
6262 _AlterFieldDefn($self, $index, $definition, $flags);
6266 #** @method list Capabilities()
6268 # Both a package subroutine and an object method.
6269 # @return a list of capabilities. The object method returns a list of
6270 # the capabilities the layer has. The package subroutine returns a list of
6271 # all potential capabilities a layer may have. These are currently:
6272 # AlterFieldDefn, CreateField, CreateGeomField, CurveGeometries, DeleteFeature, DeleteField, FastFeatureCount, FastGetExtent, FastSetNextByIndex, FastSpatialFilter, IgnoreFields, MeasuredGeometries, RandomRead, RandomWrite, ReorderFields, SequentialWrite, StringsAsUTF8, and Transactions.
6276 # @cap = Geo::OGR::Layer::Capabilities(); # the package subroutine
6277 # @cap = $layer->Capabilities(); # the object method
6281 return @CAPABILITIES
if @_ == 0;
6284 for my $cap (@CAPABILITIES) {
6285 push @cap, $cap
if _TestCapability($self, $CAPABILITIES{$cap});
6290 #** @method Clip(Geo::OGR::Layer method, Geo::OGR::Layer result, hashref options, coderef callback, $callback_data)
6292 # Clip off areas that are not covered by the method layer. The schema
6293 # of the result layer can be set before calling this method, or is
6294 # initialized to to contain all fields from
6295 # this and method layer.
6296 # @param method method layer.
6297 # @param result result layer.
6298 # @param options a reference to an options hash.
6299 # @param callback [optional] a reference to a subroutine, which will
6300 # be called with parameters (number progress, string msg, callback_data)
6301 # @param callback_data [optional]
6306 #** @method CommitTransaction()
6309 sub CommitTransaction {
6312 #** @method CreateFeature($feature)
6314 # @deprecated use Geo::OGR::Layer::InsertFeature which accepts Perl
6315 # data and checks for geometry type and attribute data
6317 # @note The feature should have the same schema as the layer.
6319 # Inserts a feature into the layer. The given feature's id may change.
6320 # @param feature a Geo::OGR::Feature object
6325 #** @method CreateField(%params)
6328 # @param params as in Geo::OGR::FieldDefn::new or
6329 # Geo::OGR::GeomFieldDefn::new, plus ApproxOK (whose default is true).
6333 my %defaults = ( ApproxOK => 1,
6337 } elsif (ref($_[0]) eq
'HASH') {
6339 } elsif (@_ % 2 == 0) {
6342 ($params{Defn}) = @_;
6344 for my $k (keys %defaults) {
6347 if (blessed($params{Defn}) and $params{Defn}->isa(
'Geo::OGR::FieldDefn')) {
6348 $self->_CreateField($params{Defn}, $params{ApproxOK});
6349 } elsif (blessed($_[0]) and $params{Defn}->isa(
'Geo::OGR::GeomFieldDefn')) {
6350 $self->CreateGeomField($params{Defn}, $params{ApproxOK});
6352 my $a = $params{ApproxOK};
6353 delete $params{ApproxOK};
6354 if (exists $params{GeometryType}) {
6355 $params{Type} = $params{GeometryType};
6356 delete $params{GeometryType};
6358 if (exists $Geo::OGR::FieldDefn::TYPE_STRING2INT{$params{Type}}) {
6360 _CreateField($self, $fd, $a);
6361 } elsif (exists $Geo::OGR::Geometry::TYPE_STRING2INT{$params{Type}}) {
6363 CreateGeomField($self, $fd, $a);
6365 Geo::GDAL::error(
"Invalid field type: $params{Type}.")
6370 #** @method DataSource()
6375 #** @method Dataset()
6379 return $Geo::GDAL::Dataset::LAYERS{tied(%$self)};
6382 #** @method DeleteFeature($fid)
6384 # @param fid feature id
6389 #** @method DeleteField($field)
6391 # Delete an existing field from a layer.
6392 # @param field name (or index) of the field which is deleted
6393 # @note Only non-spatial fields can be deleted.
6396 my($self, $field) = @_;
6397 my $index = $self->GetLayerDefn->GetFieldIndex($field);
6398 _DeleteField($self, $index);
6401 #** @method Erase(Geo::OGR::Layer method, Geo::OGR::Layer result, hashref options, coderef callback, $callback_data)
6403 # The result layer contains features whose geometries represent areas
6404 # that are in the input layer but not in the method layer. The
6405 # features in the result layer have attributes from the input
6406 # layer. The schema of the result layer can be set by the user or, if
6407 # it is empty, is initialized to contain all fields in the input
6409 # @param method method layer.
6410 # @param result result layer.
6411 # @param options a reference to an options hash.
6412 # @param callback [optional] a reference to a subroutine, which will
6413 # be called with parameters (number progress, string msg, callback_data)
6414 # @param callback_data [optional]
6419 #** @method ForFeatures($code, $in_place)
6421 # @note experimental, the syntax may change
6423 # Call code for all features. This is a simple wrapper for
6424 # ResetReading and while(GetNextFeature).
6428 # $layer->ForFeatures(sub {my $f = shift; $self->DeleteFeature($f->FID)}); # empties the layer
6431 # @param code a reference to a subroutine, which is called with each
6432 # feature as an argument
6433 # @param in_place if set to true, the feature is stored back to the
6439 my $in_place = shift;
6440 $self->ResetReading;
6441 while (my $f = $self->GetNextFeature) {
6442 $FEATURES{tied(%$f)} = $self;
6444 $self->SetFeature($f)
if $in_place;
6448 #** @method ForGeometries($code, $in_place)
6450 # @note experimental, the syntax may change
6452 # Call code for all geometries. This is a simple wrapper for
6453 # ResetReading and while(GetNextFeature).
6458 # $layer->ForGeometries(sub {my $g = shift; $area += $g->Area}); # computes the total area
6461 # @param code a reference to a subroutine, which is called with each
6462 # geometry as an argument
6463 # @param in_place if set to true, the geometry is stored back to the
6469 my $in_place = shift;
6470 $self->ResetReading;
6471 while (my $f = $self->GetNextFeature) {
6472 my $g = $f->Geometry();
6476 $self->SetFeature($f);
6481 #** @method scalar GeometryType($field)
6483 # @param field the name or index of the spatial field.
6484 # @return the geometry type of the spatial field.
6490 my $fd = $self->GetDefn->GetGeomFieldDefn($field);
6491 return $fd->Type
if $fd;
6494 #** @method Geo::OGR::DataSource GetDataSource()
6496 # @return the data source object to which this layer object belongs to.
6500 return $Geo::GDAL::Dataset::LAYERS{tied(%$self)};
6503 #** @method Geo::OGR::FeatureDefn GetDefn()
6505 # A.k.a GetLayerDefn.
6506 # @return a Geo::OGR::FeatureDefn object.
6510 my $defn = $self->GetLayerDefn;
6511 $DEFNS{tied(%$defn)} = $self;
6515 #** @method list GetExtent($force = 1)
6517 # @param force compute the extent even if it is expensive
6518 # @note In scalar context returns a reference to an anonymous array
6519 # containing the extent.
6520 # @return the extent ($minx, $maxx, $miny, $maxy)
6522 # @return the extent = ($minx, $maxx, $miny, $maxy) as a listref
6527 #** @method scalar GetFIDColumn()
6529 # @return the name of the underlying database column being used as the
6530 # FID column, or "" if not supported.
6535 #** @method Geo::OGR::Feature GetFeature($fid)
6537 # @param fid feature id
6538 # @return a new Geo::OGR::Feature object that represents the feature in the layer.
6541 my ($self, $fid) = @_;
6543 my $f = $self->_GetFeature($fid);
6544 $FEATURES{tied(%$f)} = $self;
6548 #** @method scalar GetFeatureCount($force = 1)
6553 sub GetFeatureCount {
6556 #** @method scalar GetFeaturesRead()
6560 sub GetFeaturesRead {
6563 #** @method hash GetFieldDefn($name)
6565 # Get the definition of a field.
6566 # @param name the name of the field.
6567 # @return the field definition object, either Geo::OGR::FieldDefn or
6568 # Geo::OGR::GeomFieldDefn.
6571 my ($self, $name) = @_;
6572 my $d = $self->GetDefn;
6573 for (my $i = 0; $i < $d->GetFieldCount; $i++) {
6574 my $fd = $d->GetFieldDefn($i);
6575 return $fd
if $fd->Name eq $name;
6577 for (my $i = 0; $i < $d->GetGeomFieldCount; $i++) {
6578 my $fd = $d->GetGeomFieldDefn($i);
6579 return $fd
if $fd->Name eq $name;
6581 Geo::GDAL::error(2, $name,
'Field');
6584 #** @method list GetFieldNames()
6586 # @return a list of the names of the fields in this layer. The
6587 # non-geometry field names are first in the list and then the geometry
6592 my $d = $self->GetDefn;
6594 for (my $i = 0; $i < $d->GetFieldCount; $i++) {
6595 push @ret, $d->GetFieldDefn($i)->Name();
6597 for (my $i = 0; $i < $d->GetGeomFieldCount; $i++) {
6598 push @ret, $d->GetGeomFieldDefn($i)->Name();
6603 #** @method scalar GetName()
6605 # @return the name of the layer.
6610 #** @method Geo::OGR::Feature GetNextFeature()
6612 # @return iteratively Geo::OGR::Feature objects from the layer. The
6613 # iteration obeys the spatial and the attribute filter.
6615 sub GetNextFeature {
6618 #** @method hash reference GetSchema()
6620 # @brief Get the schema of this layer.
6621 # @note The schema of a layer cannot be set with this method. If you
6622 # have a Geo::OGR::FeatureDefn object before creating the layer, use
6623 # its schema in the Geo::OGR::CreateLayer method.
6624 # @return the schema of this layer, as in Geo::OGR::FeatureDefn::Schema.
6628 carp
"Schema of a layer should not be set directly." if @_;
6629 if (@_ and @_ % 2 == 0) {
6631 if ($schema{Fields}) {
6632 for my $field (@{$schema{Fields}}) {
6633 $self->CreateField($field);
6637 return $self->GetDefn->Schema;
6640 #** @method Geo::OGR::Geometry GetSpatialFilter()
6642 # @return a new Geo::OGR::Geometry object
6644 sub GetSpatialFilter {
6647 #** @method GetStyleTable()
6652 #** @method Identity(Geo::OGR::Layer method, Geo::OGR::Layer result, hashref options, coderef callback, $callback_data)
6654 # The result layer contains features whose geometries represent areas
6655 # that are in the input layer. The features in the result layer have
6656 # attributes from both input and method layers. The schema of the
6657 # result layer can be set by the user or, if it is empty, is
6658 # initialized to contain all fields in input and method layers.
6659 # @param method method layer.
6660 # @param result result layer.
6661 # @param options a reference to an options hash.
6662 # @param callback [optional] a reference to a subroutine, which will
6663 # be called with parameters (number progress, string msg, callback_data)
6664 # @param callback_data [optional]
6669 #** @method InsertFeature($feature)
6671 # Creates a new feature which has the schema of the layer and
6672 # initializes it with data from the argument. Then inserts the feature
6673 # into the layer (using CreateFeature). Uses Geo::OGR::Feature::Row or
6674 # Geo::OGR::Feature::Tuple.
6675 # @param feature a Geo::OGR::Feature object or reference to feature
6676 # data in a hash (as in Geo::OGR::Feature::Row) or in an array (as in
6677 # Geo::OGR::Feature::Tuple)
6678 # @return the new feature.
6682 my $feature = shift;
6683 Geo::GDAL::error(
"Usage: \$feature->InsertFeature(reference to a hash or array).") unless ref($feature);
6684 my $new = Geo::OGR::Feature->new($self->GetDefn);
6685 if (ref($feature) eq 'HASH') {
6686 $new->Row(%$feature);
6687 } elsif (ref($feature) eq
'ARRAY') {
6688 $new->Tuple(@$feature);
6689 } elsif (blessed($feature) and $feature->isa(
'Geo::OGR::Feature')) {
6690 $new->Row($feature->Row);
6692 $self->CreateFeature($new);
6693 return unless defined wantarray;
6694 $FEATURES{tied(%$new)} = $self;
6698 #** @method Intersection(Geo::OGR::Layer method, Geo::OGR::Layer result, hashref options, coderef callback, $callback_data)
6700 # The result layer contains features whose geometries represent areas
6701 # that are common between features in the input layer and in the
6702 # method layer. The schema of the result layer can be set before
6703 # calling this method, or is initialized to contain all fields from
6704 # this and method layer.
6705 # @param method method layer.
6706 # @param result result layer.
6707 # @param options a reference to an options hash.
6708 # @param callback [optional] a reference to a subroutine, which will
6709 # be called with parameters (number progress, string msg, callback_data)
6710 # @param callback_data [optional]
6715 #** @method ReorderField()
6720 #** @method ReorderFields()
6725 #** @method ResetReading()
6727 # Initialize the layer object for iterative reading.
6732 #** @method RollbackTransaction()
6735 sub RollbackTransaction {
6738 #** @method hash reference Row(%row)
6740 # Get and/or set the data of a feature that has the supplied feature
6741 # id (the next feature obtained with GetNextFeature is used if feature
6742 # id is not given). Calls Geo::OGR::Feature::Row.
6743 # @param row [optional] feature data
6744 # @return a reference to feature data in a hash
6748 my $update = @_ > 0;
6750 my $feature = defined $row{FID} ? $self->GetFeature($row{FID}) : $self->GetNextFeature;
6751 return unless $feature;
6753 if (defined wantarray) {
6754 $ret = $feature->Row(@_);
6758 $self->SetFeature($feature)
if $update;
6759 return unless defined wantarray;
6763 #** @method SetAttributeFilter($filter_string)
6765 # Set or clear the attribute filter.
6766 # @param filter_string a SQL WHERE clause or undef to clear the
6769 sub SetAttributeFilter {
6772 #** @method SetFeature($feature)
6774 # @note The feature should have the same schema as the layer.
6776 # Replaces a feature in the layer based on the given feature's
6777 # id. Requires RandomWrite capability.
6778 # @param feature a Geo::OGR::Feature object
6783 #** @method SetIgnoredFields(@fields)
6785 # @param fields a list of field names
6787 sub SetIgnoredFields {
6790 #** @method SetNextByIndex($new_index)
6792 # @param new_index the index to which set the read cursor in the
6795 sub SetNextByIndex {
6798 #** @method SetSpatialFilter($filter)
6800 # @param filter [optional] a Geo::OGR::Geometry object. If not given,
6801 # removes the filter if there is one.
6803 sub SetSpatialFilter {
6806 #** @method SetSpatialFilterRect($minx, $miny, $maxx, $maxy)
6813 sub SetSpatialFilterRect {
6816 #** @method SetStyleTable()
6821 #** @method Geo::OGR::Geometry SpatialFilter(@filter)
6823 # @param filter [optional] a Geo::OGR::Geometry object or a string. An
6824 # undefined value removes the filter if there is one.
6825 # @return a new Geo::OGR::Geometry object
6826 # @param filter [optional] a rectangle ($minx, $miny, $maxx, $maxy).
6827 # @return a new Geo::OGR::Geometry object
6831 $self->SetSpatialFilter($_[0])
if @_ == 1;
6832 $self->SetSpatialFilterRect(@_)
if @_ == 4;
6833 return unless defined wantarray;
6834 $self->GetSpatialFilter;
6837 #** @method Geo::OSR::SpatialReference SpatialReference($name, Geo::OSR::SpatialReference sr)
6839 # @note A.k.a GetSpatialRef.
6840 # Get or set the projection of a spatial field of this layer. Gets or
6841 # sets the projection of the first field if no field name is given.
6842 # @param name [optional] a name of a spatial field in this layer.
6843 # @param sr [optional] a Geo::OSR::SpatialReference object,
6844 # which replaces the existing projection.
6845 # @return a Geo::OSR::SpatialReference object, which represents the
6846 # projection in the given spatial field.
6848 sub SpatialReference {
6849 my($self, $field, $sr) = @_;
6850 my $d = $self->GetDefn;
6852 if (not defined $field or (blessed($field) and $field->isa(
'Geo::OSR::SpatialReference'))) {
6855 $i = $d->GetGeomFieldIndex($field);
6857 my $d2 = $d->GetGeomFieldDefn($i);
6858 $d2->SpatialReference($sr)
if defined $sr;
6859 return $d2->SpatialReference()
if defined wantarray;
6862 #** @method StartTransaction()
6865 sub StartTransaction {
6868 #** @method SymDifference(Geo::OGR::Layer method, Geo::OGR::Layer result, hashref options, coderef callback, $callback_data)
6870 # The result layer contains features whose geometries represent areas
6871 # that are in either in the input layer or in the method layer but not
6872 # in both. The features in the result layer have attributes from both
6873 # input and method layers. For features which represent areas that are
6874 # only in the input or in the method layer the respective attributes
6875 # have undefined values. The schema of the result layer can be set by
6876 # the user or, if it is empty, is initialized to contain all fields in
6877 # the input and method layers.
6878 # @param method method layer.
6879 # @param result result layer.
6880 # @param options a reference to an options hash.
6881 # @param callback [optional] a reference to a subroutine, which will
6882 # be called with parameters (number progress, string msg, callback_data)
6883 # @param callback_data [optional]
6888 #** @method SyncToDisk()
6894 #** @method scalar TestCapability($cap)
6896 # @param cap A capability string.
6897 # @return a boolean value indicating whether the layer has the
6898 # specified capability.
6900 sub TestCapability {
6901 my($self, $cap) = @_;
6902 return _TestCapability($self, $CAPABILITIES{$cap});
6905 #** @method list Tuple(@tuple)
6907 # Get and/set the data of a feature that has the supplied feature id
6908 # (the next feature obtained with GetNextFeature is used if feature id
6909 # is not given). The expected data in the tuple is: ([feature id,]
6910 # non-spatial fields, spatial fields). Calls Geo::OGR::Feature::Tuple.
6911 # @param tuple [optional] feature data
6912 # @note The schema of the tuple needs to be the same as that of the
6914 # @return a reference to feature data in an array
6919 my $feature = defined $FID ? $self->GetFeature($FID) : $self->GetNextFeature;
6920 return unless $feature;
6922 unshift @_, $feature->GetFID
if $set;
6924 if (defined wantarray) {
6925 @ret = $feature->Tuple(@_);
6927 $feature->Tuple(@_);
6929 $self->SetFeature($feature)
if $set;
6930 return unless defined wantarray;
6934 #** @method Union(Geo::OGR::Layer method, Geo::OGR::Layer result, hashref options, coderef callback, $callback_data)
6936 # The result layer contains features whose geometries represent areas
6937 # that are in either in the input layer or in the method layer. The
6938 # schema of the result layer can be set before calling this method, or
6939 # is initialized to contain all fields from this and method layer.
6940 # @param method method layer.
6941 # @param result result layer.
6942 # @param options a reference to an options hash.
6943 # @param callback [optional] a reference to a subroutine, which will
6944 # be called with parameters (number progress, string msg, callback_data)
6945 # @param callback_data [optional]
6950 #** @method Update(Geo::OGR::Layer method, Geo::OGR::Layer result, hashref options, coderef callback, $callback_data)
6952 # The result layer contains features whose geometries represent areas
6953 # that are either in the input layer or in the method layer. The
6954 # features in the result layer have areas of the features of the
6955 # method layer or those ares of the features of the input layer that
6956 # are not covered by the method layer. The features of the result
6957 # layer get their attributes from the input layer. The schema of the
6958 # result layer can be set by the user or, if it is empty, is
6959 # initialized to contain all fields in the input layer.
6960 # @param method method layer.
6961 # @param result result layer.
6962 # @param options a reference to an options hash.
6963 # @param callback [optional] a reference to a subroutine, which will
6964 # be called with parameters (number progress, string msg, callback_data)
6965 # @param callback_data [optional]
6970 #** @class Geo::OGR::StyleTable
6972 package Geo::OGR::StyleTable;
6976 #** @method AddStyle()
6986 #** @method GetLastStyleName()
6988 sub GetLastStyleName {
6991 #** @method GetNextStyle()
6996 #** @method LoadStyleTable()
6998 sub LoadStyleTable {
7001 #** @method ResetStyleStringReading()
7003 sub ResetStyleStringReading {
7006 #** @method SaveStyleTable()
7008 sub SaveStyleTable {
7015 my $self = Geo::OGRc::new_StyleTable(@_);
7016 bless $self, $pkg
if defined($self);
7020 # @brief Base class for projection related classes.
7024 #** @method list AngularUnits()
7025 # Package subroutine.
7026 # @return list of known angular units.
7029 return keys %ANGULAR_UNITS;
7032 #** @method CreateCoordinateTransformation()
7034 sub CreateCoordinateTransformation {
7037 #** @method list Datums()
7038 # Package subroutine.
7039 # @return list of known datums.
7042 return keys %DATUMS;
7045 #** @method list GetProjectionMethodParamInfo($projection, $parameter)
7046 # Package subroutine.
7047 # @param projection one of Geo::OSR::Projections
7048 # @param parameter one of Geo::OSR::Parameters
7049 # @return a list ($user_friendly_name, $type, $default_value).
7051 sub GetProjectionMethodParamInfo {
7054 #** @method list GetProjectionMethodParameterList($projection)
7055 # Package subroutine.
7056 # @param projection one of Geo::OSR::Projections
7057 # @return a list (arrayref parameters, $projection_name).
7059 sub GetProjectionMethodParameterList {
7062 #** @method array reference GetProjectionMethods()
7063 # Package subroutine.
7064 # @deprecated Use Geo::OSR::Projections.
7066 # @return reference to an array of possible projection methods.
7068 sub GetProjectionMethods {
7071 #** @method scalar GetUserInputAsWKT($name)
7072 # Package subroutine.
7073 # @param name the user input
7074 # @return a WKT string.
7076 sub GetUserInputAsWKT {
7079 #** @method scalar GetWellKnownGeogCSAsWKT($name)
7080 # Package subroutine.
7081 # @brief Get well known geographic coordinate system as WKT
7082 # @param name a well known name
7083 # @return a WKT string.
7085 sub GetWellKnownGeogCSAsWKT {
7088 #** @method list LinearUnits()
7089 # Package subroutine.
7090 # @return list of known linear units.
7093 return keys %LINEAR_UNITS;
7096 #** @method OAO_Down()
7101 #** @method OAO_East()
7106 #** @method OAO_North()
7111 #** @method OAO_Other()
7116 #** @method OAO_South()
7121 #** @method OAO_Up()
7126 #** @method OAO_West()
7131 #** @method list Parameters()
7132 # Package subroutine.
7133 # @return list of known projection parameters.
7136 return keys %PARAMETERS;
7139 #** @method list Projections()
7140 # Package subroutine.
7141 # @return list of known projections.
7144 return keys %PROJECTIONS;
7147 #** @method SRS_PM_GREENWICH()
7149 sub SRS_PM_GREENWICH {
7152 #** @method SRS_WGS84_INVFLATTENING()
7154 sub SRS_WGS84_INVFLATTENING {
7157 #** @method SRS_WGS84_SEMIMAJOR()
7159 sub SRS_WGS84_SEMIMAJOR {
7162 #** @method SRS_WKT_WGS84()
7167 #** @class Geo::OSR::CoordinateTransformation
7168 # @brief An object for transforming from one projection to another.
7170 package Geo::OSR::CoordinateTransformation;
7174 #** @method array reference TransformPoint($x, $y, $z)
7178 # @param z [optional]
7179 # @return arrayref = [$x, $y, $z]
7181 sub TransformPoint {
7184 #** @method TransformPoints(arrayref points)
7186 # @param points [in/out] a reference to a list of points (line string
7187 # or ring) that is modified in-place. A list of points is: ([x, y, z],
7188 # [x, y, z], ...), where z is optional. Supports also lists of line
7189 # strings and polygons.
7191 sub TransformPoints {
7192 my($self, $points) = @_;
7193 _TransformPoints($self, $points),
return unless ref($points->[0]->[0]);
7194 for my $p (@$points) {
7195 TransformPoints($self, $p);
7199 # This file was automatically generated by SWIG (http://www.swig.org).
7202 # Do not make changes to this file unless you know what you are doing--modify
7203 # the SWIG interface file instead.
7206 #** @method Geo::OSR::CoordinateTransformation new($src, $dst)
7208 # @param src a Geo::OSR::SpatialReference object
7209 # @param dst a Geo::OSR::SpatialReference object
7210 # @return a new Geo::OSR::CoordinateTransformation object
7214 my $self = Geo::OSRc::new_CoordinateTransformation(@_);
7215 bless $self, $pkg
if defined($self);
7218 #** @class Geo::OSR::SpatialReference
7219 # @brief A spatial reference system.
7221 # <a href="http://www.gdal.org/classOGRSpatialReference.html">Documentation
7222 # of the underlying C++ class at www.gdal.org</a>
7224 package Geo::OSR::SpatialReference;
7233 #** @method AutoIdentifyEPSG()
7235 # Set EPSG authority info if possible.
7237 sub AutoIdentifyEPSG {
7240 #** @method Geo::OSR::SpatialReference Clone()
7242 # Make a duplicate of this SpatialReference object.
7243 # @return a new Geo::OSR::SpatialReference object
7248 #** @method Geo::OSR::SpatialReference CloneGeogCS()
7250 # Make a duplicate of the GEOGCS node of this SpatialReference object.
7251 # @return a new Geo::OSR::SpatialReference object
7256 #** @method CopyGeogCSFrom($rhs)
7258 # @param rhs Geo::OSR::SpatialReference
7260 sub CopyGeogCSFrom {
7263 #** @method EPSGTreatsAsLatLong()
7265 # Returns TRUE if EPSG feels this geographic coordinate system should be treated as having lat/long coordinate ordering.
7267 sub EPSGTreatsAsLatLong {
7270 #** @method EPSGTreatsAsNorthingEasting()
7272 sub EPSGTreatsAsNorthingEasting {
7275 #** @method Export($format)
7277 # Export the spatial reference to a selected format.
7280 # @param format One of the following. The return value is explained
7281 # after the format. Other arguments are explained in parenthesis.
7282 # - WKT (Text): Well Known Text string
7283 # - PrettyWKT: Well Known Text string nicely formatted (simplify)
7284 # - Proj4: PROJ.4 string
7285 # - PCI: a list: ($proj_string, $units, [$parms1, ...])
7286 # - USGS: a list: ($code, $zone, [$parms1, ...], $datum)
7287 # - GML (XML): GML based string (dialect)
7288 # - MapInfoCS (MICoordSys): MapInfo style co-ordinate system definition
7290 # @note The named parameter syntax also works and is needed is those
7291 # cases when other arguments need or may be given. The format should
7292 # be given using key as, 'to' or 'format'.
7294 # @note ExportTo* and AsText methods also exist but are not documented here.
7296 # @return a scalar or a list depending on the export format
7301 $format = pop
if @_ == 1;
7304 my $simplify = $params{simplify}
7305 my $dialect = $params{dialect}
7307 WKT => sub {
return ExportToWkt($self) },
7308 Text => sub {
return ExportToWkt($self) },
7309 PrettyWKT => sub {
return ExportToPrettyWkt($self, $simplify) },
7310 Proj4 => sub {
return ExportToProj4($self) },
7311 PCI => sub {
return ExportToPCI($self) },
7312 USGS => sub {
return ExportToUSGS($self) },
7313 GML => sub {
return ExportToXML($self, $dialect) },
7314 XML => sub {
return ExportToXML($self, $dialect) },
7315 MICoordSys => sub {
return ExportToMICoordSys() },
7316 MapInfoCS => sub {
return ExportToMICoordSys() },
7318 Geo::GDAL::error(1, $format, \%converters) unless $converters{$format};
7319 return $converters{$format}->();
7328 #** @method FixupOrdering()
7334 #** @method scalar GetAngularUnits()
7338 sub GetAngularUnits {
7341 #** @method GetAngularUnitsName()
7343 sub GetAngularUnitsName {
7346 #** @method scalar GetAttrValue($name, $child = 0)
7355 #** @method scalar GetAuthorityCode($target_key)
7360 sub GetAuthorityCode {
7363 #** @method scalar GetAuthorityName($target_key)
7368 sub GetAuthorityName {
7371 #** @method GetAxisName()
7376 #** @method GetAxisOrientation()
7378 sub GetAxisOrientation {
7381 #** @method GetInvFlattening()
7384 sub GetInvFlattening {
7387 #** @method scalar GetLinearUnits()
7391 sub GetLinearUnits {
7394 #** @method scalar GetLinearUnitsName()
7398 sub GetLinearUnitsName {
7401 #** @method scalar GetNormProjParm($name, $default_val = 0.0)
7404 # @param default_val
7407 sub GetNormProjParm {
7410 #** @method scalar GetProjParm($name, $default_val = 0.0)
7413 # @param default_val
7419 #** @method GetSemiMajor()
7425 #** @method GetSemiMinor()
7431 #** @method GetTOWGS84()
7433 # @return array = ($p1, $p2, $p3, $p4, $p5, $p6, $p7)
7438 #** @method GetUTMZone()
7440 # Get UTM zone information.
7441 # @return The UTM zone (integer). In scalar context the returned value
7442 # is negative for southern hemisphere zones. In list context returns
7443 # two values ($zone, $north), where $zone is always non-negative and
7444 # $north is true or false.
7448 my $zone = _GetUTMZone($self);
7455 return ($zone, $north);
7461 #** @method ImportFromOzi()
7466 #** @method scalar IsCompound()
7473 #** @method scalar IsGeocentric()
7480 #** @method scalar IsGeographic()
7487 #** @method scalar IsLocal()
7494 #** @method scalar IsProjected()
7501 #** @method scalar IsSame($rs)
7503 # @param rs a Geo::OSR::SpatialReference object
7509 #** @method scalar IsSameGeogCS($rs)
7511 # @param rs a Geo::OSR::SpatialReference object
7517 #** @method scalar IsSameVertCS($rs)
7519 # @param rs a Geo::OSR::SpatialReference object
7525 #** @method scalar IsVertical()
7532 #** @method MorphFromESRI()
7538 #** @method MorphToESRI()
7544 #** @method Set(%params)
7546 # Set a parameter or parameters in the spatial reference object.
7547 # @param params Named parameters. Recognized keys and respective
7548 # values are the following.
7549 # - Authority: authority name (give also TargetKey, Node and Code)
7551 # - Node: partial or complete path to the target node (Node and Value together sets an attribute value)
7552 # - Code: code for value with an authority
7553 # - Value: value to be assigned to a node, a projection parameter or an object
7554 # - AngularUnits: angular units for the geographic coordinate system (give also Value) (one of Geo::OSR::LinearUnits)
7555 # - LinearUnits: linear units for the target node or the object (give also Value and optionally Node) (one of Geo::OSR::LinearUnits)
7556 # - Parameter: projection parameter to set (give also Value and Normalized) (one of Geo::OSR::Parameters)
7557 # - Normalized: set to true to indicate that the Value argument is in "normalized" form
7558 # - Name: a well known name of a geographic coordinate system (e.g. WGS84)
7559 # - GuessFrom: arbitrary text that specifies a projection ("user input")
7560 # - LOCAL_CS: name of a local coordinate system
7561 # - GeocentricCS: name of a geocentric coordinate system
7562 # - VerticalCS: name of a vertical coordinate system (give also Datum and optionally VertDatumType [default is 2005])
7563 # - Datum: a known (OGC or EPSG) name (or(?) one of Geo::OSR::Datums)
7564 # - 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
7565 # - Parameters: a reference to a list containing the coordinate system or projection parameters
7566 # - Zone: zone for setting up UTM or State Plane coordinate systems (State Plane zone in USGS numbering scheme)
7567 # - North: set false for southern hemisphere
7568 # - NAD83: set false if the NAD27 zone definition should be used instead of NAD83
7569 # - UnitName: to override the legal definition for a zone
7570 # - UnitConversionFactor: to override the legal definition for a zone
7571 # - Spheroid: user visible name
7572 # - HorizontalCS: Horizontal coordinate system name
7573 # - Projection: name of a projection, one of Geo::OSR::Projections (give also optionally Parameters and Variant)
7575 # @note Numerous Set* methods also exist but are not documented here.
7578 my($self, %params) = @_;
7579 if (exists $params{Authority} and exists $params{TargetKey} and exists $params{Node} and exists $params{Code}) {
7580 SetAuthority($self, $params{TargetKey}, $params{Authority}, $params{Code});
7581 } elsif (exists $params{Node} and exists $params{Value}) {
7582 SetAttrValue($self, $params{Node}, $params{Value});
7583 } elsif (exists $params{AngularUnits} and exists $params{Value}) {
7584 SetAngularUnits($self, $params{AngularUnits}, $params{Value});
7585 } elsif (exists $params{LinearUnits} and exists $params{Node} and exists $params{Value}) {
7586 SetTargetLinearUnits($self, $params{Node}, $params{LinearUnits}, $params{Value});
7587 } elsif (exists $params{LinearUnits} and exists $params{Value}) {
7588 SetLinearUnitsAndUpdateParameters($self, $params{LinearUnits}, $params{Value});
7589 } elsif ($params{Parameter} and exists $params{Value}) {
7590 Geo::GDAL::error(1, $params{Parameter}, \%Geo::OSR::PARAMETERS) unless exists $Geo::OSR::PARAMETERS{$params{Parameter}};
7591 $params{Normalized} ?
7592 SetNormProjParm($self, $params{Parameter}, $params{Value}) :
7593 SetProjParm($self, $params{Parameter}, $params{Value});
7594 } elsif (exists $params{Name}) {
7595 SetWellKnownGeogCS($self, $params{Name});
7596 } elsif (exists $params{GuessFrom}) {
7597 SetFromUserInput($self, $params{GuessFrom});
7598 } elsif (exists $params{LOCAL_CS}) {
7599 SetLocalCS($self, $params{LOCAL_CS});
7600 } elsif (exists $params{GeocentricCS}) {
7601 SetGeocCS($self, $params{GeocentricCS});
7602 } elsif (exists $params{VerticalCS} and $params{Datum}) {
7603 my $type = $params{VertDatumType} || 2005;
7604 SetVertCS($self, $params{VerticalCS}, $params{Datum}, $type);
7605 } elsif (exists $params{CoordinateSystem}) {
7606 my @parameters = ();
7607 @parameters = @{$params{Parameters}}
if ref($params{Parameters});
7608 if ($params{CoordinateSystem} eq
'State Plane' and exists $params{Zone}) {
7609 my $NAD83 = exists $params{NAD83} ? $params{NAD83} : 1;
7610 my $name = exists $params{UnitName} ? $params{UnitName} : undef;
7611 my $c = exists $params{UnitConversionFactor} ? $params{UnitConversionFactor} : 0.0;
7612 SetStatePlane($self, $params{Zone}, $NAD83, $name, $c);
7613 } elsif ($params{CoordinateSystem} eq
'UTM' and exists $params{Zone} and exists $params{North}) {
7614 my $north = exists $params{North} ? $params{North} : 1;
7615 SetUTM($self, $params{Zone}, $north);
7616 } elsif ($params{CoordinateSystem} eq
'WGS') {
7617 SetTOWGS84($self, @parameters);
7618 } elsif ($params{CoordinateSystem} and $params{Datum} and $params{Spheroid}) {
7619 SetGeogCS($self, $params{CoordinateSystem}, $params{Datum}, $params{Spheroid}, @parameters);
7620 } elsif ($params{CoordinateSystem} and $params{HorizontalCS} and $params{VerticalCS}) {
7621 SetCompoundCS($self, $params{CoordinateSystem}, $params{HorizontalCS}, $params{VerticalCS});
7623 SetProjCS($self, $params{CoordinateSystem});
7625 } elsif (exists $params{Projection}) {
7626 Geo::GDAL::error(1, $params{Projection}, \%Geo::OSR::PROJECTIONS) unless exists $Geo::OSR::PROJECTIONS{$params{Projection}};
7627 my @parameters = ();
7628 @parameters = @{$params{Parameters}}
if ref($params{Parameters});
7629 if ($params{Projection} eq
'Albers_Conic_Equal_Area') {
7630 SetACEA($self, @parameters);
7631 } elsif ($params{Projection} eq
'Azimuthal_Equidistant') {
7632 SetAE($self, @parameters);
7633 } elsif ($params{Projection} eq
'Bonne') {
7634 SetBonne($self, @parameters);
7635 } elsif ($params{Projection} eq
'Cylindrical_Equal_Area') {
7636 SetCEA($self, @parameters);
7637 } elsif ($params{Projection} eq
'Cassini_Soldner') {
7638 SetCS($self, @parameters);
7639 } elsif ($params{Projection} eq
'Equidistant_Conic') {
7640 SetEC($self, @parameters);
7641 # Eckert_I, Eckert_II, Eckert_III, Eckert_V ?
7642 } elsif ($params{Projection} eq
'Eckert_IV') {
7643 SetEckertIV($self, @parameters);
7644 } elsif ($params{Projection} eq
'Eckert_VI') {
7645 SetEckertVI($self, @parameters);
7646 } elsif ($params{Projection} eq
'Equirectangular') {
7648 SetEquirectangular($self, @parameters) :
7649 SetEquirectangular2($self, @parameters);
7650 } elsif ($params{Projection} eq
'Gauss_Schreiber_Transverse_Mercator') {
7651 SetGaussSchreiberTMercator($self, @parameters);
7652 } elsif ($params{Projection} eq
'Gall_Stereographic') {
7653 SetGS($self, @parameters);
7654 } elsif ($params{Projection} eq
'Goode_Homolosine') {
7655 SetGH($self, @parameters);
7656 } elsif ($params{Projection} eq
'Interrupted_Goode_Homolosine') {
7658 } elsif ($params{Projection} eq
'Geostationary_Satellite') {
7659 SetGEOS($self, @parameters);
7660 } elsif ($params{Projection} eq
'Gnomonic') {
7661 SetGnomonic($self, @parameters);
7662 } elsif ($params{Projection} eq
'Hotine_Oblique_Mercator') {
7663 # Hotine_Oblique_Mercator_Azimuth_Center ?
7664 SetHOM($self, @parameters);
7665 } elsif ($params{Projection} eq
'Hotine_Oblique_Mercator_Two_Point_Natural_Origin') {
7666 SetHOM2PNO($self, @parameters);
7667 } elsif ($params{Projection} eq
'Krovak') {
7668 SetKrovak($self, @parameters);
7669 } elsif ($params{Projection} eq
'Lambert_Azimuthal_Equal_Area') {
7670 SetLAEA($self, @parameters);
7671 } elsif ($params{Projection} eq
'Lambert_Conformal_Conic_2SP') {
7672 SetLCC($self, @parameters);
7673 } elsif ($params{Projection} eq
'Lambert_Conformal_Conic_1SP') {
7674 SetLCC1SP($self, @parameters);
7675 } elsif ($params{Projection} eq
'Lambert_Conformal_Conic_2SP_Belgium') {
7676 SetLCCB($self, @parameters);
7677 } elsif ($params{Projection} eq
'miller_cylindrical') {
7678 SetMC($self, @parameters);
7679 } elsif ($params{Projection} =~ /^Mercator/) {
7680 # Mercator_1SP, Mercator_2SP, Mercator_Auxiliary_Sphere ?
7681 # variant is in Variant (or Name)
7682 SetMercator($self, @parameters);
7683 } elsif ($params{Projection} eq
'Mollweide') {
7684 SetMollweide($self, @parameters);
7685 } elsif ($params{Projection} eq
'New_Zealand_Map_Grid') {
7686 SetNZMG($self, @parameters);
7687 } elsif ($params{Projection} eq
'Oblique_Stereographic') {
7688 SetOS($self, @parameters);
7689 } elsif ($params{Projection} eq
'Orthographic') {
7690 SetOrthographic($self, @parameters);
7691 } elsif ($params{Projection} eq
'Polyconic') {
7692 SetPolyconic($self, @parameters);
7693 } elsif ($params{Projection} eq
'Polar_Stereographic') {
7694 SetPS($self, @parameters);
7695 } elsif ($params{Projection} eq
'Robinson') {
7696 SetRobinson($self, @parameters);
7697 } elsif ($params{Projection} eq
'Sinusoidal') {
7698 SetSinusoidal($self, @parameters);
7699 } elsif ($params{Projection} eq
'Stereographic') {
7700 SetStereographic($self, @parameters);
7701 } elsif ($params{Projection} eq
'Swiss_Oblique_Cylindrical') {
7702 SetSOC($self, @parameters);
7703 } elsif ($params{Projection} eq
'Transverse_Mercator_South_Orientated') {
7704 SetTMSO($self, @parameters);
7705 } elsif ($params{Projection} =~ /^Transverse_Mercator/) {
7706 my($variant) = $params{Projection} =~ /^Transverse_Mercator_(\w+)/;
7709 SetTMVariant($self, $variant, @parameters) :
7710 SetTM($self, @parameters);
7711 } elsif ($params{Projection} eq
'Tunisia_Mining_Grid') {
7712 SetTMG($self, @parameters);
7713 } elsif ($params{Projection} eq
'VanDerGrinten') {
7714 SetVDG($self, @parameters);
7716 # Aitoff, Craster_Parabolic, International_Map_of_the_World_Polyconic, Laborde_Oblique_Mercator
7717 # Loximuthal, Miller_Cylindrical, Quadrilateralized_Spherical_Cube, Quartic_Authalic, Two_Point_Equidistant
7718 # Wagner_I, Wagner_II, Wagner_III, Wagner_IV, Wagner_V, Wagner_VI, Wagner_VII
7719 # Winkel_I, Winkel_II, Winkel_Tripel
7721 SetProjection($self, $params{Projection});
7724 Geo::GDAL::error(
"Not enough information to create a spatial reference object.");
7728 #** @method StripCTParms()
7734 #** @method Validate()
7740 #** @method Geo::OSR::SpatialReference new(%params)
7742 # Create a new spatial reference object using a named parameter. This
7743 # constructor recognizes the following key words (alternative in
7744 # parenthesis): WKT (Text), Proj4, ESRI, EPSG, EPSGA, PCI, USGS, GML
7745 # (XML), URL, ERMapper (ERM), MapInfoCS (MICoordSys). The value
7746 # depends on the key.
7747 # - WKT: Well Known Text string
7748 # - Proj4: PROJ.4 string
7749 # - ESRI: reference to a list of strings (contents of ESRI .prj file)
7750 # - EPSG: EPSG code number
7751 # - EPSGA: EPSG code number (the resulting CS will have EPSG preferred axis ordering)
7752 # - PCI: listref: [PCI_projection_string, Grid_units_code, [17 cs parameters]]
7753 # - USGS: listref: [Projection_system_code, Zone, [15 cs parameters], Datum_code, Format_flag]
7755 # - URL: URL for downloading the spatial reference from
7756 # - ERMapper: listref: [Projection, Datum, Units]
7757 # - MapInfoCS: MapInfo style co-ordinate system definition
7759 # For more information, consult the import methods in <a href="http://www.gdal.org/classOGRSpatialReference.html">OGR documentation</a>.
7761 # @note ImportFrom* methods also exist but are not documented here.
7765 # $sr = Geo::OSR::SpatialReference->new( key => value );
7767 # @return a new Geo::OSR::SpatialReference object
7772 my $self = Geo::OSRc::new_SpatialReference();
7773 if (exists $param{WKT}) {
7774 ImportFromWkt($self, $param{WKT});
7775 } elsif (exists $param{Text}) {
7776 ImportFromWkt($self, $param{Text});
7777 } elsif (exists $param{Proj4}) {
7778 ImportFromProj4($self, $param{Proj4});
7779 } elsif (exists $param{ESRI}) {
7780 ImportFromESRI($self, @{$param{ESRI}});
7781 } elsif (exists $param{EPSG}) {
7782 ImportFromEPSG($self, $param{EPSG});
7783 } elsif (exists $param{EPSGA}) {
7784 ImportFromEPSGA($self, $param{EPSGA});
7785 } elsif (exists $param{PCI}) {
7786 ImportFromPCI($self, @{$param{PCI}});
7787 } elsif (exists $param{USGS}) {
7788 ImportFromUSGS($self, @{$param{USGS}});
7789 } elsif (exists $param{XML}) {
7790 ImportFromXML($self, $param{XML});
7791 } elsif (exists $param{GML}) {
7792 ImportFromGML($self, $param{GML});
7793 } elsif (exists $param{URL}) {
7794 ImportFromUrl($self, $param{URL});
7795 } elsif (exists $param{ERMapper}) {
7796 ImportFromERM($self, @{$param{ERMapper}});
7797 } elsif (exists $param{ERM}) {
7798 ImportFromERM($self, @{$param{ERM}});
7799 } elsif (exists $param{MICoordSys}) {
7800 ImportFromMICoordSys($self, $param{MICoordSys});
7801 } elsif (exists $param{MapInfoCS}) {
7802 ImportFromMICoordSys($self, $param{MapInfoCS});
7803 } elsif (exists $param{WGS}) {
7805 SetWellKnownGeogCS($self,
'WGS'.$param{WGS});
7809 Geo::GDAL::error(
"Unrecognized/missing parameters: @_.");
7811 bless $self, $pkg
if defined $self;
A definition of a non-spatial attribute.
The schema of a feature or a layer.
public Geo::OGR::Geometry new(hash params)
public Geo::GDAL::Dataset OpenEx(hash params)
A set of associated raster bands or vector layer source.
public Geo::GDAL::Band Band(scalar index)
A driver for a specific dataset format.
public Geo::GDAL::Dataset Create(hash params)
public method AddGeometry(scalar other)
public Geo::OGR::FieldDefn new(hash params)
Create a new field definition.
public Geo::OSR::SpatialReference new(hash params)
public hash reference GetMetadata(scalar domain="")
public Geo::GDAL::Driver Driver(scalar Name)
public scalar GeometryType()
public Geo::OGR::GeomFieldDefn new(hash params)
Create a new spatial field definition.
A color table from a raster band or a color table, which can be used for a band.
GDAL utility functions and a root class for raster classes.
public Geo::OGR::FeatureDefn new(hash schema)
public array reference Points(arrayref points)
An object, which holds meta data.
public scalar GetDataTypeSize(scalar DataType)
Base class for projection related classes.
A spatial reference system.
public scalar PackCharacter(scalar DataType)
public scalar Name(scalar name)
public Geo::GDAL::ColorTable new(scalar GDALPaletteInterp= 'RGB')
Base class for geographical networks in GDAL.
A definition of a spatial attribute.