2 # @brief GDAL utility functions and a root class for raster classes. 3 # @details Geo::GDAL wraps many GDAL utility functions and is as a root class 4 # for all GDAL raster classes. A "raster" is an object, whose core is 5 # a rectagular grid of cells, called a "band" in GDAL. Each cell 6 # contains a numeric value of a specific data type. 10 #** @method ApplyVerticalShiftGrid() 12 sub ApplyVerticalShiftGrid {
15 #** @method BuildVRT() 20 push(@DATA_TYPES, $1), next
if /^GDT_(\w+)/;
21 push(@OPEN_FLAGS, $1), next
if /^OF_(\w+)/;
22 push(@RESAMPLING_TYPES, $1), next
if /^GRA_(\w+)/;
23 push(@RIO_RESAMPLING_TYPES, $1), next
if /^GRIORA_(\w+)/;
24 push(@NODE_TYPES, $1), next
if /^CXT_(\w+)/;
26 for my $string (@DATA_TYPES) {
27 my $int = eval
"\$Geo::GDAL::Const::GDT_$string";
28 $S2I{data_type}{$string} = $int;
29 $I2S{data_type}{$int} = $string;
31 for my $string (@OPEN_FLAGS) {
32 my $int = eval
"\$Geo::GDAL::Const::OF_$string";
33 $S2I{open_flag}{$string} = $int;
35 for my $string (@RESAMPLING_TYPES) {
36 my $int = eval
"\$Geo::GDAL::Const::GRA_$string";
37 $S2I{resampling}{$string} = $int;
38 $I2S{resampling}{$int} = $string;
40 for my $string (@RIO_RESAMPLING_TYPES) {
41 my $int = eval
"\$Geo::GDAL::Const::GRIORA_$string";
42 $S2I{rio_resampling}{$string} = $int;
43 $I2S{rio_resampling}{$int} = $string;
45 for my $string (@NODE_TYPES) {
46 my $int = eval
"\$Geo::GDAL::Const::CXT_$string";
47 $S2I{node_type}{$string} = $int;
48 $I2S{node_type}{$int} = $string;
52 $HAVE_PDL = 1 unless $@;
55 #** @method CPLBinaryToHex() 60 #** @method CPLHexToBinary() 65 #** @method ContourGenerateEx() 67 sub ContourGenerateEx {
70 #** @method CreatePansharpenedVRT() 72 sub CreatePansharpenedVRT {
75 #** @method scalar DataTypeIsComplex($DataType) 77 # @param DataType A GDAL raster cell data type (one of those listed by Geo::GDAL::DataTypes). 78 # @return true if the data type is a complex number. 80 sub DataTypeIsComplex {
81 return _DataTypeIsComplex(s2i(data_type => shift));
84 #** @method list DataTypeValueRange($DataType) 86 # @param DataType Data type (one of those listed by Geo::GDAL::DataTypes). 87 # @note Some returned values are inaccurate. 89 # @return the minimum, maximum range of the data type. 91 sub DataTypeValueRange {
94 # these values are from gdalrasterband.cpp 95 return (0,255)
if $t =~ /Byte/;
96 return (0,65535)
if $t =~/UInt16/;
97 return (-32768,32767)
if $t =~/Int16/;
98 return (0,4294967295)
if $t =~/UInt32/;
99 return (-2147483648,2147483647)
if $t =~/Int32/;
100 return (-4294967295.0,4294967295.0)
if $t =~/Float32/;
101 return (-4294967295.0,4294967295.0)
if $t =~/Float64/;
104 #** @method list DataTypes() 105 # Package subroutine. 106 # @return a list of GDAL raster cell data types. These are currently: 107 # Byte, CFloat32, CFloat64, CInt16, CInt32, Float32, Float64, Int16, Int32, UInt16, UInt32, and Unknown. 113 #** @method scalar DecToDMS($angle, $axis, $precision=2) 114 # Package subroutine. 115 # Convert decimal degrees to degrees, minutes, and seconds string 116 # @param angle A number 117 # @param axis A string specifying latitude or longitude ('Long'). 119 # @return a string nndnn'nn.nn'"L where n is a number and L is either 125 #** @method scalar DecToPackedDMS($dec) 126 # Package subroutine. 127 # @param dec Decimal degrees 128 # @return packed DMS, i.e., a number DDDMMMSSS.SS 133 #** @method DontUseExceptions() 134 # Package subroutine. 135 # Do not use the Perl exception mechanism for GDAL messages. Instead 136 # the messages are printed to standard error. 138 sub DontUseExceptions {
141 #** @method Geo::GDAL::Driver Driver($Name) 142 # Package subroutine. 143 # Access a format driver. 144 # @param Name The short name of the driver. One of 145 # Geo::GDAL::DriverNames or Geo::OGR::DriverNames. 146 # @note This subroutine is imported into the main namespace if Geo::GDAL 147 # is used with qw/:all/. 148 # @return a Geo::GDAL::Driver object. 151 return 'Geo::GDAL::Driver' unless @_;
153 my $driver = GetDriver($name);
154 error(
"Driver \"$name\" not found. Is it built in? Check with Geo::GDAL::Drivers or Geo::OGR::Drivers.")
159 #** @method list DriverNames() 160 # Package subroutine. 161 # Available raster format drivers. 163 # perl -MGeo::GDAL -e '@d=Geo::GDAL::DriverNames;print "@d\n"' 165 # @note Use Geo::OGR::DriverNames for vector drivers. 166 # @return a list of the short names of all available GDAL raster drivers. 171 #** @method list Drivers() 172 # Package subroutine. 173 # @note Use Geo::OGR::Drivers for vector drivers. 174 # @return a list of all available GDAL raster drivers. 178 for my $i (0..GetDriverCount()-1) {
179 my $driver = GetDriver($i);
180 push @drivers, $driver
if $driver->TestCapability(
'RASTER');
185 #** @method EscapeString() 190 #** @method scalar FindFile($basename) 191 # Package subroutine. 192 # Search for GDAL support files. 197 # $a = Geo::GDAL::FindFile('pcs.csv'); 198 # print STDERR "$a\n"; 200 # Prints (for example): 202 # c:\msys\1.0\local\share\gdal\pcs.csv 205 # @param basename The name of the file to search for. For example 207 # @return the path to the searched file or undef. 217 #** @method FinderClean() 218 # Package subroutine. 219 # Clear the set of support file search paths. 224 #** @method GOA2GetAccessToken() 226 sub GOA2GetAccessToken {
229 #** @method GOA2GetAuthorizationURL() 231 sub GOA2GetAuthorizationURL {
234 #** @method GOA2GetRefreshToken() 236 sub GOA2GetRefreshToken {
239 #** @method GetActualURL() 244 #** @method scalar GetCacheMax() 245 # Package subroutine. 246 # @return maximum amount of memory (as bytes) for caching within GDAL. 251 #** @method scalar GetCacheUsed() 252 # Package subroutine. 253 # @return the amount of memory currently used for caching within GDAL. 258 #** @method scalar GetConfigOption($key) 259 # Package subroutine. 260 # @param key A GDAL config option. Consult <a 261 # href="https://trac.osgeo.org/gdal/wiki/ConfigOptions">the GDAL 262 # documentation</a> for available options and their use. 263 # @return the value of the GDAL config option. 265 sub GetConfigOption {
268 #** @method scalar GetDataTypeSize($DataType) 269 # Package subroutine. 270 # @param DataType A GDAL raster cell data type (one of those listed by Geo::GDAL::DataTypes). 271 # @return the size as the number of bits. 273 sub GetDataTypeSize {
274 return _GetDataTypeSize(s2i(data_type => shift, 1));
277 #** @method GetErrorCounter() 279 sub GetErrorCounter {
282 #** @method GetFileSystemOptions() 284 sub GetFileSystemOptions {
287 #** @method GetFileSystemsPrefixes() 289 sub GetFileSystemsPrefixes {
292 #** @method GetJPEG2000StructureAsString() 294 sub GetJPEG2000StructureAsString {
297 #** @method GetSignedURL() 302 #** @method Geo::GDAL::Driver IdentifyDriver($path, $siblings) 303 # Package subroutine. 304 # @param path a dataset path. 305 # @param siblings [optional] A list of names of files that belong to the data format. 306 # @return a Geo::GDAL::Driver. 311 #** @method IdentifyDriverEx() 313 sub IdentifyDriverEx {
316 #** @method MkdirRecursive() 321 #** @method Geo::GDAL::Dataset Open(%params) 322 # Package subroutine. 324 # An example, which opens an existing raster dataset for editing: 326 # use Geo::GDAL qw/:all/; 327 # $ds = Open(Name => 'existing.tiff', Access => 'Update'); 329 # @param params Named parameters: 330 # - \a Name Dataset string (typically a filename). Default is '.'. 331 # - \a Access Access type, either 'ReadOnly' or 'Update'. Default is 'ReadOnly'. 332 # - \a Type Dataset type, either 'Raster', 'Vector', or 'Any'. Default is 'Any'. 333 # - \a Options A hash of GDAL open options passed to candidate drivers. Default is {}. 334 # - \a Files A list of names of files that are auxiliary to the main file. Default is []. 336 # @note This subroutine is imported into the main namespace if Geo::GDAL 337 # is use'd with qw/:all/. 339 # @note Some datasets / dataset strings do not explicitly imply the 340 # dataset type (for example a PostGIS database). If the type is not 341 # specified in such a case the returned dataset may be of either type. 343 # @return a new Geo::GDAL::Dataset object if success. 346 my $p = named_parameters(\@_, Name =>
'.', Access =>
'ReadOnly', Type =>
'Any', Options => {}, Files => []);
348 my %o = (READONLY => 1, UPDATE => 1);
349 error(1, $p->{access}, \%o) unless $o{uc($p->{access})};
350 push @flags, uc($p->{access});
351 %o = (RASTER => 1, VECTOR => 1, ANY => 1);
352 error(1, $p->{type}, \%o) unless $o{uc($p->{type})};
353 push @flags, uc($p->{type}) unless uc($p->{type}) eq
'ANY';
354 my $dataset = OpenEx(Name => $p->{name}, Flags => \@flags, Options => $p->{options}, Files => $p->{files});
356 my $t =
"Failed to open $p->{name}.";
357 $t .=
" Is it a ".lc($p->{type}).
" dataset?" unless uc($p->{type}) eq
'ANY';
363 #** @method Geo::GDAL::Dataset OpenEx(%params) 364 # Package subroutine. 365 # The generic dataset open method, used internally by all Open and OpenShared methods. 366 # @param params Named parameters: 367 # - \a Name The name of the data set or source to open. (Default is '.') 368 # - \a Flags A list of access mode flags. Available flags are listed by Geo::GDAL::OpenFlags(). (Default is []) 369 # - \a Drivers A list of short names of drivers that may be used. Empty list means all. (Default is []) 370 # - \a Options A hash of GDAL open options passed to candidate drivers. (Default is {}) 371 # - \a Files A list of names of files that are auxiliary to the main file. (Default is []) 375 # $ds = Geo::GDAL::OpenEx(Name => 'existing.tiff', Flags => [qw/RASTER UPDATE/]); 377 # @return a new Geo::GDAL::Dataset object. 380 my $p = named_parameters(\@_, Name =>
'.', Flags => [], Drivers => [], Options => {}, Files => []);
384 $p = {name => $name, flags => \@flags, drivers => [], options => {}, files => []};
388 for my $flag (@{$p->{flags}}) {
389 $f |= s2i(open_flag => $flag);
393 return _OpenEx($p->{name}, $p->{flags}, $p->{drivers}, $p->{options}, $p->{files});
396 #** @method list OpenFlags() 397 # Package subroutine. 398 # @return a list of GDAL data set open modes. These are currently: 399 # ALL, GNM, RASTER, READONLY, SHARED, UPDATE, VECTOR, and VERBOSE_ERROR. 405 #** @method scalar PackCharacter($DataType) 406 # Package subroutine. 407 # Get the character that is needed for Perl's pack and unpack when 408 # they are used with Geo::GDAL::Band::ReadRaster and 409 # Geo::GDAL::Band::WriteRaster. Note that Geo::GDAL::Band::ReadTile 410 # and Geo::GDAL::Band::WriteTile have simpler interfaces that do not 411 # require pack and unpack. 412 # @param DataType A GDAL raster cell data type, typically from $band->DataType. 413 # @return a character which can be used in Perl's pack and unpack. 417 $t = i2s(data_type => $t);
418 s2i(data_type => $t); # test
419 my $is_big_endian = unpack(
"h*", pack(
"s", 1)) =~ /01/; # from Programming Perl
420 return 'C' if $t =~ /^Byte$/;
421 return ($is_big_endian ?
'n':
'v')
if $t =~ /^UInt16$/;
422 return 's' if $t =~ /^Int16$/;
423 return ($is_big_endian ?
'N' :
'V')
if $t =~ /^UInt32$/;
424 return 'l' if $t =~ /^Int32$/;
425 return 'f' if $t =~ /^Float32$/;
426 return 'd' if $t =~ /^Float64$/;
429 #** @method scalar PackedDMSToDec($packed) 430 # Package subroutine. 431 # @param packed DMS as a number DDDMMMSSS.SS 432 # @return decimal degrees 437 #** @method PopFinderLocation() 438 # Package subroutine. 439 # Remove the latest addition from the set of support file search 440 # paths. Note that calling this subroutine may remove paths GDAL put 443 sub PopFinderLocation {
446 #** @method PushFinderLocation($path) 447 # Package subroutine. 448 # Add a path to the set of paths from where GDAL support files are 449 # sought. Note that GDAL puts initially into the finder the current 450 # directory and value of GDAL_DATA environment variable (if it 451 # exists), installation directory (prepended with '/share/gdal' or 452 # '/Resources/gdal'), or '/usr/local/share/gdal'. It is usually only 453 # needed to add paths to the finder if using an alternate set of data 454 # files or a non-installed GDAL is used (as in testing). 456 sub PushFinderLocation {
459 #** @method list RIOResamplingTypes() 460 # Package subroutine. 461 # @return a list of GDAL raster IO resampling methods. These are currently: 462 # Average, Bilinear, Cubic, CubicSpline, Gauss, Lanczos, Mode, and NearestNeighbour. 464 sub RIOResamplingTypes {
465 return @RIO_RESAMPLING_TYPES;
468 #** @method list ResamplingTypes() 469 # Package subroutine. 470 # @return a list of GDAL resampling methods. These are currently: 471 # Average, Bilinear, Cubic, CubicSpline, Lanczos, Max, Med, Min, Mode, NearestNeighbour, Q1, and Q3. 473 sub ResamplingTypes {
474 return @RESAMPLING_TYPES;
477 #** @method RmdirRecursive() 482 #** @method SetCacheMax($Bytes) 483 # Package subroutine. 484 # @param Bytes New maximum amount of memory for caching within GDAL. 489 #** @method SetConfigOption($key, $value) 490 # Package subroutine. 491 # @param key A GDAL config option. Consult <a 492 # href="https://trac.osgeo.org/gdal/wiki/ConfigOptions">the GDAL 493 # documentation</a> for available options and their use. 494 # @param value A value for the option, typically 'YES', 'NO', 495 # undef, path, numeric value, or a filename. 497 sub SetConfigOption {
500 #** @method UseExceptions() 501 # Package subroutine. 502 # Use the Perl exception mechanism for GDAL messages (failures are 503 # confessed and warnings are warned) and collect the messages 504 # into \@Geo::GDAL::error. This is the default. 509 #** @method VSICurlClearCache() 511 sub VSICurlClearCache {
514 #** @method VSICurlPartialClearCache() 516 sub VSICurlPartialClearCache {
519 #** @method VSIErrorReset() 524 #** @method VSIFEofL() 529 #** @method VSIFFlushL() 534 #** @method VSIFOpenExL() 539 #** @method VSIGetLastErrorMsg() 541 sub VSIGetLastErrorMsg {
544 #** @method VSIGetLastErrorNo() 546 sub VSIGetLastErrorNo {
549 #** @method scalar VersionInfo($request = 'VERSION_NUM') 550 # Package subroutine. 551 # @param request A string specifying the request. Currently either 552 # "VERSION_NUM", "RELEASE_DATE", "RELEASE_NAME", or 553 # "--version". Default is "VERSION_NUM". 554 # @return Requested information. 559 #** @method scalar errstr() 560 # Package subroutine. 561 # Clear the error stack and return all generated GDAL error messages in one (possibly multiline) string. 562 # @return the chomped error stack joined with newlines. 568 return join(
"\n", @stack);
570 # usage: named_parameters(\@_, key value list of default parameters); 571 # returns parameters in a hash with low-case-without-_ keys 574 #** @class Geo::GDAL::AsyncReader 575 # @brief Enable asynchronous requests. 576 # @details This class is not yet documented nor tested in the GDAL Perl wrappers 577 # @todo Test and document. 579 package Geo::GDAL::AsyncReader;
583 #** @method GetNextUpdatedRegion() 585 sub GetNextUpdatedRegion {
588 #** @method LockBuffer() 593 #** @method UnlockBuffer() 598 #** @class Geo::GDAL::Band 599 # @brief A raster band. 602 package Geo::GDAL::Band;
608 # scalar (access as $band->{XSize}) 613 # scalar (access as $band->{YSize}) 616 #** @method AdviseRead() 621 #** @method Geo::GDAL::RasterAttributeTable AttributeTable($AttributeTable) 623 # @param AttributeTable [optional] A Geo::GDAL::RasterAttributeTable object. 624 # @return a new Geo::GDAL::RasterAttributeTable object, whose data is 625 # contained within the band. 629 SetDefaultRAT($self, $_[0])
if @_ and defined $_[0];
630 return unless defined wantarray;
631 my $r = GetDefaultRAT($self);
632 keep($r, $self)
if $r;
635 #** @method list BlockSize() 638 # @return The size of a preferred i/o raster block size as a list 644 #** @method list CategoryNames(@names) 646 # @param names [optional] 651 SetRasterCategoryNames($self, \@_)
if @_;
652 return unless defined wantarray;
653 my $n = GetRasterCategoryNames($self);
657 #** @method scalar Checksum($xoff = 0, $yoff = 0, $xsize = undef, $ysize = undef) 659 # Computes a checksum from the raster or a part of it. 664 # @return the checksum. 669 #** @method hashref ClassCounts($classifier, $progress = undef, $progress_data = undef) 671 # Compute the counts of cell values or number of cell values in ranges. 672 # @note Classifier is required only for float bands. 673 # @note NoData values are counted similar to other values when 674 # classifier is not defined for integer rasters. 676 # @param classifier Anonymous array of format [ $comparison, 677 # $classifier ], where $comparison is a string '<', '<=', '>', or '>=' 678 # and $classifier is an anonymous array of format [ $value, 679 # $value|$classifier, $value|$classifier ], where $value is a numeric 680 # value against which the reclassified value is compared to. If the 681 # comparison returns true, then the second $value or $classifier is 682 # applied, and if not then the third $value or $classifier. 684 # In the example below, the line is divided into ranges 685 # [-inf..3), [3..5), and [5..inf], i.e., three ranges with class 686 # indexes 0, 1, and 2. Note that the indexes are used as keys for 687 # class counts and not the class values (here 1.0, 2.0, and 3.0), 688 # which are used in Geo::GDAL::Band::Reclassify. 690 # $classifier = [ '<', [5.0, [3.0, 1.0, 2.0], 3.0] ]; 691 # # Howto create this $classifier from @class_boundaries: 692 # my $classifier = ['<=']; 693 # my $tree = [$class_boundaries[0], 0, 1]; 694 # for my $i (1 .. $#class_boundaries) { 695 # $tree = [$class_boundaries[$i], [@$tree], $i+1]; 697 # push @$classifier, $tree; 699 # @return a reference to an anonymous hash, which contains the class 700 # values (indexes) as keys and the number of cells with that value or 701 # in that range as values. If the subroutine is user terminated an 707 #** @method scalar ColorInterpretation($color_interpretation) 709 # @note a.k.a. GetRasterColorInterpretation and GetColorInterpretation 710 # (get only and returns an integer), SetRasterColorInterpretation and 711 # SetColorInterpretation (set only and requires an integer) 712 # @param color_interpretation [optional] new color interpretation, one 713 # of Geo::GDAL::Band::ColorInterpretations. 714 # @return The color interpretation of this band. One of Geo::GDAL::Band::ColorInterpretations. 716 sub ColorInterpretation {
719 $ci = s2i(color_interpretation => $ci);
720 SetRasterColorInterpretation($self, $ci);
722 return unless defined wantarray;
723 i2s(color_interpretation => GetRasterColorInterpretation($self));
726 #** @method ColorInterpretations() 727 # Package subroutine. 728 # @return a list of types of color interpretation for raster 729 # bands. These are currently: 730 # AlphaBand, BlackBand, BlueBand, CyanBand, GrayIndex, GreenBand, HueBand, LightnessBand, MagentaBand, PaletteIndex, RedBand, SaturationBand, Undefined, YCbCr_CbBand, YCbCr_CrBand, YCbCr_YBand, and YellowBand. 732 sub ColorInterpretations {
733 return @COLOR_INTERPRETATIONS;
736 #** @method Geo::GDAL::ColorTable ColorTable($ColorTable) 738 # Get or set the color table of this band. 739 # @param ColorTable [optional] a Geo::GDAL::ColorTable object 740 # @return A new Geo::GDAL::ColorTable object which represents the 741 # internal color table associated with this band. Returns undef this 742 # band does not have an associated color table. 746 SetRasterColorTable($self, $_[0])
if @_ and defined $_[0];
747 return unless defined wantarray;
748 GetRasterColorTable($self);
751 #** @method ComputeBandStats($samplestep = 1) 753 # @param samplestep the row increment in computing the statistics. 754 # @note Returns uncorrected sample standard deviation. 756 # See also Geo::GDAL::Band::ComputeStatistics. 757 # @return a list (mean, stddev). 759 sub ComputeBandStats {
762 #** @method ComputeRasterMinMax($approx_ok = 0) 764 # @return arrayref MinMax = [min, max] 766 sub ComputeRasterMinMax {
769 #** @method list ComputeStatistics($approx_ok, $progress = undef, $progress_data = undef) 771 # @param approx_ok Whether it is allowed to compute the statistics 772 # based on overviews or similar. 773 # @note Returns uncorrected sample standard deviation. 775 # See also Geo::GDAL::Band::ComputeBandStats. 776 # @return a list ($min, $max, $mean, $stddev). 778 sub ComputeStatistics {
781 #** @method Geo::OGR::Layer Contours($DataSource, hashref LayerConstructor, $ContourInterval, $ContourBase, arrayref FixedLevels, $NoDataValue, $IDField, $ElevField, coderef Progress, $ProgressData) 783 # Generate contours for this raster band. This method can also be used with named parameters. 784 # @note This method is a wrapper for ContourGenerate. 789 # $dem = Geo::GDAL::Open('dem.gtiff'); 790 # $contours = $dem->Band->Contours(ContourInterval => 10, ElevField => 'z'); 791 # $n = $contours->GetFeatureCount; 794 # @param DataSource a Geo::OGR::DataSource object, default is a Memory data source 795 # @param LayerConstructor data for Geo::OGR::DataSource::CreateLayer, default is {Name => 'contours'} 796 # @param ContourInterval default is 100 797 # @param ContourBase default is 0 798 # @param FixedLevels a reference to a list of fixed contour levels, default is [] 799 # @param NoDataValue default is undef 800 # @param IDField default is '', i.e., no field (the field is created if this is given) 801 # @param ElevField default is '', i.e., no field (the field is created if this is given) 802 # @param progress [optional] a reference to a subroutine, which will 803 # be called with parameters (number progress, string msg, progress_data) 804 # @param progress_data [optional] 809 my $p = named_parameters(\@_,
811 LayerConstructor => {Name =>
'contours'},
812 ContourInterval => 100,
815 NoDataValue => undef,
819 ProgressData => undef);
821 $p->{layerconstructor}->{Schema}
822 $p->{layerconstructor}->{Schema}{Fields}
824 unless ($p->{idfield} =~ /^[+-]?\d+$/ or $fields{$p->{idfield}}) {
825 push @{$p->{layerconstructor}->{Schema}{Fields}}, {Name => $p->{idfield}, Type =>
'Integer'};
827 unless ($p->{elevfield} =~ /^[+-]?\d+$/ or $fields{$p->{elevfield}}) {
828 my $type = $self->DataType() =~ /Float/ ?
'Real' :
'Integer';
829 push @{$p->{layerconstructor}->{Schema}{Fields}}, {Name => $p->{elevfield}, Type => $type};
831 my $layer = $p->{datasource}->CreateLayer($p->{layerconstructor});
832 my $schema = $layer->GetLayerDefn;
833 for (
'idfield',
'elevfield') {
834 $p->{$_} = $schema->GetFieldIndex($p->{$_}) unless $p->{$_} =~ /^[+-]?\d+$/;
836 $p->{progressdata} = 1
if $p->{progress} and not defined $p->{progressdata};
837 ContourGenerate($self, $p->{contourinterval}, $p->{contourbase}, $p->{fixedlevels},
838 $p->{nodatavalue}, $layer, $p->{idfield}, $p->{elevfield},
839 $p->{progress}, $p->{progressdata});
843 #** @method CreateMaskBand(@flags) 845 # @note May invalidate any previous mask band obtained with Geo::GDAL::Band::GetMaskBand. 847 # @param flags one or more mask flags. The flags are Geo::GDAL::Band::MaskFlags. 852 if (@_ and $_[0] =~ /^\d$/) {
856 carp
"Unknown mask flag: '$flag'." unless $MASK_FLAGS{$flag};
857 $f |= $MASK_FLAGS{$flag};
860 $self->_CreateMaskBand($f);
863 #** @method scalar DataType() 865 # @return The data type of this band. One of Geo::GDAL::DataTypes. 869 return i2s(data_type => $self->{DataType});
872 #** @method Geo::GDAL::Dataset Dataset() 874 # @return The dataset which this band belongs to. 881 #** @method scalar DeleteNoDataValue() 884 sub DeleteNoDataValue {
887 #** @method Geo::GDAL::Band Distance(%params) 889 # Compute distances to specific cells of this raster. 890 # @param params Named parameters: 891 # - \a Distance A raster band, into which the distances are computed. If not given, a not given, a new in-memory raster band is created and returned. The data type of the raster can be given in the options. 892 # - \a Options Hash of options. Options are: 893 # - \a Values A list of cell values in this band to measure the distance from. If this option is not provided, the distance will be computed to non-zero pixel values. Currently pixel values are internally processed as integers. 894 # - \a DistUnits=PIXEL|GEO Indicates whether distances will be computed in cells or in georeferenced units. The default is pixel units. This also determines the interpretation of MaxDist. 895 # - \a MaxDist=n The maximum distance to search. Distances greater than this value will not be computed. Instead output cells will be set to a NoData value. 896 # - \a NoData=n The NoData value to use on the distance band for cells that are beyond MaxDist. If not provided, the distance band will be queried for a NoData value. If one is not found, 65535 will be used (255 if the type is Byte). 897 # - \a Use_Input_NoData=YES|NO If this option is set, the NoData value of this band will be respected. Leaving NoData cells in the input as NoData pixels in the distance raster. 898 # - \a Fixed_Buf_Val=n If this option is set, all cells within the MaxDist threshold are set to this value instead of the distance value. 899 # - \a DataType The data type for the result if it is not given. 900 # - \a Progress Progress function. 901 # - \a ProgressData Additional parameter for the progress function. 903 # @note This GDAL function behind this API is called GDALComputeProximity. 905 # @return The distance raster. 909 my $p = named_parameters(\@_, Distance => undef, Options => undef, Progress => undef, ProgressData => undef);
910 for my $key (keys %{$p->{options}}) {
911 $p->{options}{uc($key)} = $p->{options}{$key};
914 unless ($p->{distance}) {
915 my ($w, $h) = $self->Size;
916 $p->{distance} =
Geo::GDAL::Driver(
'MEM')->
Create(Name =>
'distance', Width => $w, Height => $h, Type => $p->{options}{TYPE})->
Band;
918 Geo::GDAL::ComputeProximity($self, $p->{distance}, $p->{options}, $p->{progress}, $p->{progressdata});
919 return $p->{distance};
922 #** @method Domains() 928 #** @method Fill($real_part, $imag_part = 0.0) 930 # Fill the band with a constant value. 931 # @param real_part Real component of fill value. 932 # @param imag_part Imaginary component of fill value. 938 #** @method FillNoData($mask, $max_search_dist, $smoothing_iterations, $options, coderef progress, $progress_data) 940 # Interpolate values for cells in this raster. The cells to fill 941 # should be marked in the mask band with zero. 943 # @param mask [optional] a mask band indicating cells to be interpolated (zero valued) (default is to get it with Geo::GDAL::Band::GetMaskBand). 944 # @param max_search_dist [optional] the maximum number of cells to 945 # search in all directions to find values to interpolate from (default is 10). 946 # @param smoothing_iterations [optional] the number of 3x3 smoothing filter passes to run (0 or more) (default is 0). 947 # @param options [optional] A reference to a hash. No options have been defined so far for this algorithm (default is {}). 948 # @param progress [optional] a reference to a subroutine, which will 949 # be called with parameters (number progress, string msg, progress_data) (default is undef). 950 # @param progress_data [optional] (default is undef). 952 # <a href="http://www.gdal.org/gdal__alg_8h.html">Documentation for GDAL algorithms</a> 957 #** @method FlushCache() 959 # Write cached data to disk. There is usually no need to call this 965 #** @method scalar GetBandNumber() 967 # @return The index of this band in the parent dataset list of bands. 972 #** @method GetBlockSize() 977 #** @method list GetDefaultHistogram($force = 1, coderef progress = undef, $progress_data = undef) 979 # @param force true to force the computation 980 # @param progress [optional] a reference to a subroutine, which will 981 # be called with parameters (number progress, string msg, progress_data) 982 # @param progress_data [optional] 983 # @note See Note in Geo::GDAL::Band::GetHistogram. 984 # @return a list: ($min, $max, arrayref histogram). 986 sub GetDefaultHistogram {
989 #** @method list GetHistogram(%parameters) 991 # Compute histogram from the raster. 992 # @param parameters Named parameters: 993 # - \a Min the lower bound, default is -0.5 994 # - \a Max the upper bound, default is 255.5 995 # - \a Buckets the number of buckets in the histogram, default is 256 996 # - \a IncludeOutOfRange whether to use the first and last values in the returned list 997 # for out of range values, default is false; 998 # the bucket size is (Max-Min) / Buckets if this is false and 999 # (Max-Min) / (Buckets-2) if this is true 1000 # - \a ApproxOK if histogram can be computed from overviews, default is false 1001 # - \a Progress an optional progress function, the default is undef 1002 # - \a ProgressData data for the progress function, the default is undef 1003 # @note Histogram counts are treated as strings in the bindings to be 1004 # able to use large integers (if GUIntBig is larger than Perl IV). In 1005 # practice this is only important if you have a 32 bit machine and 1006 # very large bucket counts. In those cases it may also be necessary to 1008 # @return a list which contains the count of values in each bucket 1012 my $p = named_parameters(\@_,
1016 IncludeOutOfRange => 0,
1019 ProgressData => undef);
1020 $p->{progressdata} = 1
if $p->{progress} and not defined $p->{progressdata};
1021 _GetHistogram($self, $p->{min}, $p->{max}, $p->{buckets},
1022 $p->{includeoutofrange}, $p->{approxok},
1023 $p->{progress}, $p->{progressdata});
1026 #** @method Geo::GDAL::Band GetMaskBand() 1028 # @return the mask band associated with this 1033 my $band = _GetMaskBand($self);
1037 #** @method list GetMaskFlags() 1039 # @return the mask flags of the mask band associated with this 1040 # band. The flags are one or more of Geo::GDAL::Band::MaskFlags. 1044 my $f = $self->_GetMaskFlags;
1046 for my $flag (keys %MASK_FLAGS) {
1047 push @f, $flag
if $f & $MASK_FLAGS{$flag};
1049 return wantarray ? @f : $f;
1052 #** @method scalar GetMaximum() 1054 # @note Call Geo::GDAL::Band::ComputeStatistics before calling 1055 # GetMaximum to make sure the value is computed. 1057 # @return statistical minimum of the band or undef if statistics are 1058 # not kept or computed in scalar context. In list context returns the 1059 # maximum value or a (kind of) maximum value supported by the data 1060 # type and a boolean value, which indicates which is the case (true is 1061 # first, false is second). 1066 #** @method scalar GetMinimum() 1068 # @note Call Geo::GDAL::Band::ComputeStatistics before calling 1069 # GetMinimum to make sure the value is computed. 1071 # @return statistical minimum of the band or undef if statistics are 1072 # not kept or computed in scalar context. In list context returns the 1073 # minimum value or a (kind of) minimum value supported by the data 1074 # type and a boolean value, which indicates which is the case (true is 1075 # first, false is second). 1080 #** @method Geo::GDAL::Band GetOverview($index) 1082 # @param index 0..GetOverviewCount-1 1083 # @return a Geo::GDAL::Band object, which represents the internal 1084 # overview band, or undef. if the index is out of bounds. 1087 my ($self, $index) = @_;
1088 my $band = _GetOverview($self, $index);
1092 #** @method scalar GetOverviewCount() 1094 # @return the number of overviews available of the band. 1096 sub GetOverviewCount {
1099 #** @method list GetStatistics($approx_ok, $force) 1101 # @param approx_ok Whether it is allowed to compute the statistics 1102 # based on overviews or similar. 1103 # @param force Whether to force scanning of the whole raster. 1104 # @note Uses Geo::GDAL::Band::ComputeStatistics internally. 1106 # @return a list ($min, $max, $mean, $stddev). 1111 #** @method HasArbitraryOverviews() 1113 # @return true or false. 1115 sub HasArbitraryOverviews {
1118 #** @method list MaskFlags() 1119 # Package subroutine. 1120 # @return the list of mask flags. These are 1121 # - \a AllValid: There are no invalid cell, all mask values will be 255. 1122 # When used this will normally be the only flag set. 1123 # - \a PerDataset: The mask band is shared between all bands on the dataset. 1124 # - \a Alpha: The mask band is actually an alpha band and may have values 1125 # other than 0 and 255. 1126 # - \a NoData: Indicates the mask is actually being generated from NoData values. 1127 # (mutually exclusive of Alpha). 1130 my @f = sort {$MASK_FLAGS{$a} <=> $MASK_FLAGS{$b}} keys %MASK_FLAGS;
1134 #** @method scalar NoDataValue($NoDataValue) 1136 # Get or set the "no data" value. 1137 # @param NoDataValue [optional] 1138 # @note $band->NoDataValue(undef) sets the NoData value to the 1139 # Posix floating point maximum. Use Geo::GDAL::Band::DeleteNoDataValue 1140 # to stop this band using a NoData value. 1141 # @return The NoData value or undef in scalar context. An undef 1142 # value indicates that there is no NoData value associated with this 1148 if (defined $_[0]) {
1149 SetNoDataValue($self, $_[0]);
1151 SetNoDataValue($self, POSIX::FLT_MAX); # hopefully an
"out of range" value
1154 GetNoDataValue($self);
1157 #** @method scalar PackCharacter() 1159 # @return The character to use in Perl pack and unpack for the data of this band. 1166 #** @method Piddle($piddle, $xoff = 0, $yoff = 0, $xsize = <width>, $ysize = <height>, $xdim, $ydim) 1168 # Read or write band data from/into a piddle. 1170 # \note The PDL module must be available for this method to work. Also, you 1171 # should 'use PDL' in the code that you use this method. 1173 # @param piddle [only when writing] The piddle from which to read the data to be written into the band. 1174 # @param xoff, yoff The offset for data in the band, default is top left (0, 0). 1175 # @param xsize, ysize [optional] The size of the window in the band. 1176 # @param xdim, ydim [optional, only when reading from a band] The size of the piddle to create. 1177 # @return A new piddle when reading from a band (no not use when writing into a band). 1180 # TODO: add Piddle sub to dataset too to make Width x Height x Bands piddles 1181 error(
"PDL is not available.") unless $Geo::GDAL::HAVE_PDL;
1183 my $t = $self->{DataType};
1184 unless (defined wantarray) {
1186 error(
"The datatype of the Piddle and the band do not match.")
1187 unless $PDL2DATATYPE{$pdl->get_datatype} == $t;
1188 my ($xoff, $yoff, $xsize, $ysize) = @_;
1191 my $data = $pdl->get_dataref();
1192 my ($xdim, $ydim) = $pdl->dims();
1193 if ($xdim > $self->{XSize} - $xoff) {
1194 warn
"Piddle XSize too large ($xdim) for this raster band (width = $self->{XSize}, offset = $xoff).";
1195 $xdim = $self->{XSize} - $xoff;
1197 if ($ydim > $self->{YSize} - $yoff) {
1198 $ydim = $self->{YSize} - $yoff;
1199 warn
"Piddle YSize too large ($ydim) for this raster band (height = $self->{YSize}, offset = $yoff).";
1203 $self->_WriteRaster($xoff, $yoff, $xsize, $ysize, $data, $xdim, $ydim, $t, 0, 0);
1206 my ($xoff, $yoff, $xsize, $ysize, $xdim, $ydim, $alg) = @_;
1214 $alg = s2i(rio_resampling => $alg);
1215 my $buf = $self->_ReadRaster($xoff, $yoff, $xsize, $ysize, $xdim, $ydim, $t, 0, 0, $alg);
1217 my $datatype = $DATATYPE2PDL{$t};
1218 error(
"The band datatype is not supported by PDL.")
if $datatype < 0;
1219 $pdl->set_datatype($datatype);
1220 $pdl->setdims([$xdim, $ydim]);
1221 my $data = $pdl->get_dataref();
1224 # FIXME: we want approximate equality since no data value can be very large floating point value 1225 my $bad = GetNoDataValue($self);
1226 return $pdl->setbadif($pdl == $bad)
if defined $bad;
1230 #** @method Geo::OGR::Layer Polygonize(%params) 1232 # Polygonize this raster band. 1234 # @param params Named parameters: 1235 # - \a Mask A raster band, which is used as a mask to select polygonized areas. Default is undef. 1236 # - \a OutLayer A vector layer into which the polygons are written. If not given, an in-memory layer 'polygonized' is created and returned. 1237 # - \a PixValField The name of the field in the output layer into which the cell value of the polygon area is stored. Default is 'val'. 1238 # - \a Options Hash or list of options. Connectedness can be set to 8 1239 # to use 8-connectedness, otherwise 4-connectedness is 1240 # used. ForceIntPixel can be set to 1 to force using a 32 bit int buffer 1241 # for cell values in the process. If this is not set and the data type 1242 # of this raster does not fit into a 32 bit int buffer, a 32 bit float 1244 # - \a Progress Progress function. 1245 # - \a ProgressData Additional parameter for the progress function. 1247 # @return Output vector layer. 1251 my $p = named_parameters(\@_, Mask => undef, OutLayer => undef, PixValField =>
'val', Options => undef, Progress => undef, ProgressData => undef);
1252 my %known_options = (Connectedness => 1, ForceIntPixel => 1, DATASET_FOR_GEOREF => 1,
'8CONNECTED' => 1);
1253 for my $option (keys %{$p->{options}}) {
1254 error(1, $option, \%known_options) unless exists $known_options{$option};
1256 my $dt = $self->DataType;
1257 my %leInt32 = (Byte => 1, Int16 => 1, Int32 => 1, UInt16 => 1);
1258 my $leInt32 = $leInt32{$dt};
1259 $dt = $dt =~ /Float/ ?
'Real' :
'Integer';
1261 CreateLayer(Name =>
'polygonized',
1262 Fields => [{Name =>
'val', Type => $dt},
1263 {Name =>
'geom', Type =>
'Polygon'}]);
1264 $p->{pixvalfield} = $p->{outlayer}->GetLayerDefn->GetFieldIndex($p->{pixvalfield});
1265 $p->{options}{
'8CONNECTED'} = 1
if $p->{options}{Connectedness} && $p->{options}{Connectedness} == 8;
1266 if ($leInt32 || $p->{options}{ForceIntPixel}) {
1267 Geo::GDAL::_Polygonize($self, $p->{mask}, $p->{outlayer}, $p->{pixvalfield}, $p->{options}, $p->{progress}, $p->{progressdata});
1269 Geo::GDAL::FPolygonize($self, $p->{mask}, $p->{outlayer}, $p->{pixvalfield}, $p->{options}, $p->{progress}, $p->{progressdata});
1271 set the srs of the outlayer
if it was created here
1272 return $p->{outlayer};
1275 #** @method RasterAttributeTable() 1280 #** @method scalar ReadRaster(%params) 1282 # Read data from the band. 1284 # @param params Named parameters: 1285 # - \a XOff x offset (cell coordinates) (default is 0) 1286 # - \a YOff y offset (cell coordinates) (default is 0) 1287 # - \a XSize width of the area to read (default is the width of the band) 1288 # - \a YSize height of the area to read (default is the height of the band) 1289 # - \a BufXSize (default is undef, i.e., the same as XSize) 1290 # - \a BufYSize (default is undef, i.e., the same as YSize) 1291 # - \a BufType data type of the buffer (default is the data type of the band) 1292 # - \a BufPixelSpace (default is 0) 1293 # - \a BufLineSpace (default is 0) 1294 # - \a ResampleAlg one of Geo::GDAL::RIOResamplingTypes (default is 'NearestNeighbour'), 1295 # - \a Progress reference to a progress function (default is undef) 1296 # - \a ProgressData (default is undef) 1298 # <a href="http://www.gdal.org/classGDALDataset.html">Entry in GDAL docs (method RasterIO)</a> 1299 # @return a buffer, open the buffer with \a unpack function of Perl. See Geo::GDAL::Band::PackCharacter. 1303 my ($width, $height) = $self->Size;
1304 my ($type) = $self->DataType;
1305 my $p = named_parameters(\@_,
1315 ResampleAlg =>
'NearestNeighbour',
1317 ProgressData => undef
1319 $p->{resamplealg} = s2i(rio_resampling => $p->{resamplealg});
1320 $p->{buftype} = s2i(data_type => $p->{buftype}, 1);
1321 $self->_ReadRaster($p->{xoff},$p->{yoff},$p->{xsize},$p->{ysize},$p->{bufxsize},$p->{bufysize},$p->{buftype},$p->{bufpixelspace},$p->{buflinespace},$p->{resamplealg},$p->{progress},$p->{progressdata});
1324 #** @method array reference ReadTile($xoff = 0, $yoff = 0, $xsize = <width>, $ysize = <height>) 1326 # Read band data into a Perl array. 1328 # \note Accessing band data in this way is slow. Consider using PDL and Geo::GDAL::Band::Piddle. 1330 # Usage example (print the data from a band): 1332 # print "@$_\n" for ( @{ $band->ReadTile() } ); 1334 # Another usage example (process the data of a large dataset that has one band): 1336 # my($W,$H) = $dataset->Band()->Size(); 1337 # my($xoff,$yoff,$w,$h) = (0,0,200,200); 1339 # if ($xoff >= $W) { 1342 # last if $yoff >= $H; 1344 # my $data = $dataset->Band(1)->ReadTile($xoff,$yoff,min($W-$xoff,$w),min($H-$yoff,$h)); 1345 # # add your data processing code here 1346 # $dataset->Band(1)->WriteTile($data,$xoff,$yoff); 1351 # return $_[0] < $_[1] ? $_[0] : $_[1]; 1354 # @param xoff Number of cell to skip before starting to read from a row. Pixels are read from left to right. 1355 # @param yoff Number of cells to skip before starting to read from a column. Pixels are read from top to bottom. 1356 # @param xsize Number of cells to read from each row. 1357 # @param ysize Number of cells to read from each column. 1358 # @return a two-dimensional Perl array, organizes as data->[y][x], y = 1359 # 0..height-1, x = 0..width-1. I.e., y is row and x is column. 1362 my($self, $xoff, $yoff, $xsize, $ysize, $w_tile, $h_tile, $alg) = @_;
1370 $alg = s2i(rio_resampling => $alg);
1371 my $t = $self->{DataType};
1372 my $buf = $self->_ReadRaster($xoff, $yoff, $xsize, $ysize, $w_tile, $h_tile, $t, 0, 0, $alg);
1377 for my $y (0..$h_tile-1) {
1378 my @d = unpack($pc.
"[$w_tile]", substr($buf, $offset, $w));
1385 #** @method Reclassify($classifier, $progress = undef, $progress_data = undef) 1387 # Reclassify the cells in the band. 1388 # @note NoData values in integer rasters are reclassified if 1389 # explicitly specified in the hash classifier. However, they are not 1390 # reclassified to the default value, if one is specified. In real 1391 # valued rasters nodata cells are not reclassified. 1392 # @note If the subroutine is user terminated or the classifier is 1393 # incorrect, already reclassified cells will stay reclassified but an 1395 # @param classifier For integer rasters an anonymous hash, which 1396 # contains old class values as keys and new class values as values, or 1397 # an array classifier as in Geo::GDAL::Band::ClassCounts. In a hash 1398 # classifier a special key '*' (star) can be used as default, to act 1399 # as a fallback new class value. For real valued rasters the 1400 # classifier is as in Geo::GDAL::Band::ClassCounts. 1405 #** @method RegenerateOverview(Geo::GDAL::Band overview, $resampling, coderef progress, $progress_data) 1407 # @param overview a Geo::GDAL::Band object for the overview. 1408 # @param resampling [optional] the resampling method (one of Geo::GDAL::RIOResamplingTypes) (default is Average). 1409 # @param progress [optional] a reference to a subroutine, which will 1410 # be called with parameters (number progress, string msg, progress_data) 1411 # @param progress_data [optional] 1413 sub RegenerateOverview {
1415 #Geo::GDAL::Band overview, scalar resampling, subref callback, scalar callback_data 1417 Geo::GDAL::RegenerateOverview($self, @p);
1420 #** @method RegenerateOverviews(arrayref overviews, $resampling, coderef progress, $progress_data) 1422 # @todo This is not yet available 1424 # @param overviews a list of Geo::GDAL::Band objects for the overviews. 1425 # @param resampling [optional] the resampling method (one of Geo::GDAL::RIOResamplingTypes) (default is Average). 1426 # @param progress [optional] a reference to a subroutine, which will 1427 # be called with parameters (number progress, string msg, progress_data) 1428 # @param progress_data [optional] 1430 sub RegenerateOverviews {
1432 #arrayref overviews, scalar resampling, subref callback, scalar callback_data 1434 Geo::GDAL::RegenerateOverviews($self, @p);
1437 #** @method ScaleAndOffset($scale, $offset) 1439 # Scale and offset are used to transform raw cell values into the 1440 # units returned by GetUnits(). The conversion function is: 1442 # Units value = (raw value * scale) + offset 1444 # @return a list ($scale, $offset), the values are undefined if they 1446 # @since version 1.9 of the bindings. 1448 sub ScaleAndOffset {
1450 SetScale($self, $_[0])
if @_ > 0 and defined $_[0];
1451 SetOffset($self, $_[1])
if @_ > 1 and defined $_[1];
1452 return unless defined wantarray;
1453 my $scale = GetScale($self);
1454 my $offset = GetOffset($self);
1455 return ($scale, $offset);
1458 #** @method list SetDefaultHistogram($min, $max, $histogram) 1462 # @note See Note in Geo::GDAL::Band::GetHistogram. 1463 # @param histogram reference to an array containing the histogram 1465 sub SetDefaultHistogram {
1468 #** @method SetStatistics($min, $max, $mean, $stddev) 1470 # Save the statistics of the band if possible (the format can save 1471 # arbitrary metadata). 1480 #** @method Geo::GDAL::Band Sieve(%params) 1482 # Remove small areas by merging them into the largest neighbour area. 1483 # @param params Named parameters: 1484 # - \a Mask A raster band, which is used as a mask to select sieved areas. Default is undef. 1485 # - \a Dest A raster band into which the result is written. If not given, an new in-memory raster band is created and returned. 1486 # - \a Threshold The smallest area size (in number of cells) which are not sieved away. 1487 # - \a Options Hash or list of options. {Connectedness => 4} can be specified to use 4-connectedness, otherwise 8-connectedness is used. 1488 # - \a Progress Progress function. 1489 # - \a ProgressData Additional parameter for the progress function. 1491 # @return The filtered raster band. 1495 my $p = named_parameters(\@_, Mask => undef, Dest => undef, Threshold => 10, Options => undef, Progress => undef, ProgressData => undef);
1496 unless ($p->{dest}) {
1497 my ($w, $h) = $self->Size;
1501 if ($p->{options}{Connectedness}) {
1502 $c = $p->{options}{Connectedness};
1503 delete $p->{options}{Connectedness};
1505 Geo::GDAL::SieveFilter($self, $p->{mask}, $p->{dest}, $p->{threshold}, $c, $p->{options}, $p->{progress}, $p->{progressdata});
1509 #** @method list Size() 1511 # @return The size of the band as a list (width, height). 1515 return ($self->{XSize}, $self->{YSize});
1518 #** @method Unit($type) 1520 # @param type [optional] the unit (a string). 1521 # @note $band->Unit(undef) sets the unit value to an empty string. 1522 # @return the unit (a string). 1523 # @since version 1.9 of the bindings. 1530 SetUnitType($self, $unit);
1532 return unless defined wantarray;
1536 #** @method WriteRaster(%params) 1538 # Write data into the band. 1540 # @param params Named parameters: 1541 # - \a XOff x offset (cell coordinates) (default is 0) 1542 # - \a YOff y offset (cell coordinates) (default is 0) 1543 # - \a XSize width of the area to write (default is the width of the band) 1544 # - \a YSize height of the area to write (default is the height of the band) 1545 # - \a Buf a buffer (or a reference to a buffer) containing the data. Create the buffer with \a pack function of Perl. See Geo::GDAL::Band::PackCharacter. 1546 # - \a BufXSize (default is undef, i.e., the same as XSize) 1547 # - \a BufYSize (default is undef, i.e., the same as YSize) 1548 # - \a BufType data type of the buffer (default is the data type of the band) 1549 # - \a BufPixelSpace (default is 0) 1550 # - \a BufLineSpace (default is 0) 1552 # <a href="http://www.gdal.org/classGDALDataset.html">Entry in GDAL docs (method RasterIO)</a> 1556 my ($width, $height) = $self->Size;
1557 my ($type) = $self->DataType;
1558 my $p = named_parameters(\@_,
1570 confess
"Usage: \$band->WriteRaster( Buf => \$data, ... )" unless defined $p->{buf};
1571 $p->{buftype} = s2i(data_type => $p->{buftype}, 1);
1572 $self->_WriteRaster($p->{xoff},$p->{yoff},$p->{xsize},$p->{ysize},$p->{buf},$p->{bufxsize},$p->{bufysize},$p->{buftype},$p->{bufpixelspace},$p->{buflinespace});
1575 #** @method WriteTile($data, $xoff = 0, $yoff = 0) 1577 # Write band data from a Perl array. 1579 # \note Accessing band data in this way is slow. Consider using PDL and Geo::GDAL::Band::Piddle. 1581 # @param data A two-dimensional Perl array, organizes as data->[y][x], y = 1582 # 0..height-1, x = 0..width-1. 1588 my($self, $data, $xoff, $yoff) = @_;
1591 error(
'The data must be in a two-dimensional array') unless ref $data eq
'ARRAY' && ref $data->[0] eq
'ARRAY';
1592 my $xsize = @{$data->[0]};
1593 if ($xsize > $self->{XSize} - $xoff) {
1594 warn
"Buffer XSize too large ($xsize) for this raster band (width = $self->{XSize}, offset = $xoff).";
1595 $xsize = $self->{XSize} - $xoff;
1597 my $ysize = @{$data};
1598 if ($ysize > $self->{YSize} - $yoff) {
1599 $ysize = $self->{YSize} - $yoff;
1600 warn
"Buffer YSize too large ($ysize) for this raster band (height = $self->{YSize}, offset = $yoff).";
1603 for my $i (0..$ysize-1) {
1604 my $scanline = pack($pc.
"[$xsize]", @{$data->[$i]});
1605 $self->WriteRaster( $xoff, $yoff+$i, $xsize, 1, $scanline );
1609 #** @class Geo::GDAL::ColorTable 1610 # @brief A color table from a raster band or a color table, which can be used for a band. 1613 package Geo::GDAL::ColorTable;
1617 #** @method Geo::GDAL::ColorTable Clone() 1619 # Clone an existing color table. 1620 # @return a new Geo::GDAL::ColorTable object 1625 #** @method list Color($index, @color) 1627 # Get or set a color in this color table. 1628 # @param index The index of the color in the table. Note that the 1629 # color table may expand if the index is larger than the current max 1630 # index of this table and a color is given. An attempt to retrieve a 1631 # color out of the current size of the table causes an error. 1632 # @param color [optional] The color, either a list or a reference to a 1633 # list. If the list is too short or has undef values, the undef values 1634 # are taken as 0 except for alpha, which is taken as 255. 1635 # @note A color is an array of four integers having a value between 0 1636 # and 255: (gray, red, cyan or hue; green, magenta, or lightness; 1637 # blue, yellow, or saturation; alpha or blackband) 1638 # @return A color, in list context a list and in scalar context a reference to an anonymous array. 1643 #** @method list Colors(@colors) 1645 # Get or set the colors in this color table. 1646 # @note The color table will expand to the size of the input list but 1647 # it will not shrink. 1648 # @param colors [optional] A list of all colors (a list of lists) for this color table. 1649 # @return A list of colors (a list of lists). 1654 #** @method CreateColorRamp($start_index, arrayref start_color, $end_index, arrayref end_color) 1656 # @param start_index 1657 # @param start_color 1661 sub CreateColorRamp {
1664 #** @method scalar GetCount() 1666 # @return The number of colors in this color table. 1671 #** @method scalar GetPaletteInterpretation() 1673 # @return palette interpretation (string) 1675 sub GetPaletteInterpretation {
1677 return i2s(palette_interpretation => GetPaletteInterpretation($self));
1680 #** @method Geo::GDAL::ColorTable new($GDALPaletteInterp = 'RGB') 1682 # Create a new empty color table. 1683 # @return a new Geo::GDAL::ColorTable object 1688 $pi = s2i(palette_interpretation => $pi);
1689 my $self = Geo::GDALc::new_ColorTable($pi);
1690 bless $self, $pkg
if defined($self);
1693 #** @class Geo::GDAL::Dataset 1694 # @brief A set of associated raster bands or vector layer source. 1697 package Geo::GDAL::Dataset;
1701 #** @attr $RasterCount 1702 # scalar (access as $dataset->{RasterCount}) 1705 #** @attr $RasterXSize 1706 # scalar (access as $dataset->{RasterXSize}) 1709 #** @attr $RasterYSize 1710 # scalar (access as $dataset->{RasterYSize}) 1713 #** @method AddBand($datatype = 'Byte', hashref options = {}) 1715 # Add a new band to the dataset. The driver must support the action. 1716 # @param datatype GDAL raster cell data type (one of those listed by Geo::GDAL::DataTypes). 1717 # @param options reference to a hash of format specific options. 1718 # @return The added band. 1721 my ($self, $type, $options) = @_;
1723 $type = s2i(data_type => $type);
1724 $self->_AddBand($type, $options);
1725 return unless defined wantarray;
1726 return $self->GetRasterBand($self->{RasterCount});
1729 #** @method AdviseRead() 1734 #** @method Geo::GDAL::Band Band($index) 1736 # Create a band object for the band within the dataset. 1737 # @note a.k.a. GetRasterBand 1738 # @param index 1...RasterCount, default is 1. 1739 # @return a new Geo::GDAL::Band object 1744 #** @method list Bands() 1746 # @return a list of new Geo::GDAL::Band objects 1751 for my $i (1..$self->{RasterCount}) {
1752 push @bands, GetRasterBand($self, $i);
1757 #** @method BuildOverviews($resampling, arrayref overviews, coderef progress, $progress_data) 1759 # @param resampling the resampling method, one of Geo::GDAL::RIOResamplingTypes. 1760 # @param overviews The list of overview decimation factors to 1761 # build. For example [2,4,8]. 1762 # @param progress [optional] a reference to a subroutine, which will 1763 # be called with parameters (number progress, string msg, progress_data) 1764 # @param progress_data [optional] 1766 sub BuildOverviews {
1769 $p[0] = uc($p[0])
if $p[0];
1771 $self->_BuildOverviews(@p);
1773 confess(last_error())
if $@;
1776 #** @method Geo::GDAL::Dataset BuildVRT($Dest, arrayref Sources, hashref Options, coderef progress, $progress_data) 1778 # Build a virtual dataset from a set of datasets. 1779 # @param Dest Destination raster dataset definition string (typically 1780 # filename), or an object, which implements write and close. 1781 # @param Sources A list of filenames of input datasets or a list of 1783 # @param Options See section \ref index_processing_options. 1784 # @return Dataset object 1786 # @note This subroutine is imported into the main namespace if Geo::GDAL 1787 # is use'd with qw/:all/. 1790 my ($dest, $sources, $options, $progress, $progress_data) = @_;
1791 $options = Geo::GDAL::GDALBuildVRTOptions->new(make_processing_options($options));
1792 error(
"Usage: Geo::GDAL::DataSet::BuildVRT(\$vrt_file_name, \\\@sources)")
1793 unless ref $sources eq
'ARRAY' && defined $sources->[0];
1794 unless (blessed($dest)) {
1795 if (blessed($sources->[0])) {
1796 return Geo::GDAL::wrapper_GDALBuildVRT_objects($dest, $sources, $options, $progress, $progress_data);
1798 return Geo::GDAL::wrapper_GDALBuildVRT_names($dest, $sources, $options, $progress, $progress_data);
1801 if (blessed($sources->[0])) {
1802 return stdout_redirection_wrapper(
1804 \&Geo::GDAL::wrapper_GDALBuildVRT_objects,
1805 $options, $progress, $progress_data);
1807 return stdout_redirection_wrapper(
1809 \&Geo::GDAL::wrapper_GDALBuildVRT_names,
1810 $options, $progress, $progress_data);
1815 #** @method CommitTransaction() 1817 sub CommitTransaction {
1820 #** @method Geo::GDAL::ColorTable ComputeColorTable(%params) 1822 # Compute a color table from an RGB image 1823 # @param params Named parameters: 1824 # - \a Red The red band, the default is to use the red band of this dataset. 1825 # - \a Green The green band, the default is to use the green band of this dataset. 1826 # - \a Blue The blue band, the default is to use the blue band of this dataset. 1827 # - \a NumColors The number of colors in the computed color table. Default is 256. 1828 # - \a Progress reference to a progress function (default is undef) 1829 # - \a ProgressData (default is undef) 1830 # - \a Method The computation method. The default and currently only option is the median cut algorithm. 1832 # @return a new color table object. 1834 sub ComputeColorTable {
1836 my $p = named_parameters(\@_,
1842 ProgressData => undef,
1843 Method =>
'MedianCut');
1844 for my $b ($self->Bands) {
1845 for my $cion ($b->ColorInterpretation) {
1846 if ($cion eq
'RedBand') { $p->{red}
1847 if ($cion eq
'GreenBand') { $p->{green}
1848 if ($cion eq
'BlueBand') { $p->{blue}
1852 Geo::GDAL::ComputeMedianCutPCT($p->{red},
1856 $ct, $p->{progress},
1857 $p->{progressdata});
1861 #** @method Geo::OGR::Layer CopyLayer($layer, $name, hashref options = undef) 1863 # @param layer A Geo::OGR::Layer object to be copied. 1864 # @param name A name for the new layer. 1865 # @param options A ref to a hash of format specific options. 1866 # @return a new Geo::OGR::Layer object. 1871 #** @method Geo::OGR::Layer CreateLayer(%params) 1873 # @brief Create a new vector layer into this dataset. 1875 # @param %params Named parameters: 1876 # - \a Name (scalar) name for the new layer. 1877 # - \a Fields (array reference) a list of (scalar and geometry) field definitions as in 1878 # Geo::OGR::Layer::CreateField. 1879 # - \a ApproxOK (boolean value, default is true) a flag, which is forwarded to Geo::OGR::Layer::CreateField. 1880 # - \a Options (hash reference) driver specific hash of layer creation options. 1881 # - \a Schema (hash reference, deprecated, use \a Fields and \a Name) may contain keys Name, Fields, GeomFields, GeometryType. 1882 # - \a SRS (scalar) the spatial reference for the default geometry field. 1883 # - \a GeometryType (scalar) the type of the default geometry field 1884 # (if only one geometry field). Default is 'Unknown'. 1886 # @note If Fields or Schema|Fields is not given, a default geometry 1887 # field (Name => '', GeometryType => 'Unknown') is created. If it is 1888 # given and it contains spatial fields, both GeometryType and SRS are 1889 # ignored. The type can be also set with the named parameter. 1893 # my $roads = Geo::OGR::Driver('Memory')->Create('road')-> 1895 # Fields => [ { Name => 'class', 1896 # Type => 'Integer' }, 1898 # Type => 'LineString25D' } ] ); 1901 # @note Many formats allow only one spatial field, which currently 1902 # requires the use of GeometryType. 1904 # @return a new Geo::OGR::Layer object. 1908 my $p = named_parameters(\@_,
1911 GeometryType =>
'Unknown',
1916 error(
"The 'Fields' argument must be an array reference.")
if $p->{fields} && ref($p->{fields}) ne
'ARRAY';
1917 if (defined $p->{schema}) {
1918 my $s = $p->{schema};
1919 $p->{geometrytype} = $s->{GeometryType}
if exists $s->{GeometryType};
1920 $p->{fields} = $s->{Fields}
if exists $s->{Fields};
1921 $p->{name} = $s->{Name}
if exists $s->{Name};
1923 $p->{fields} = [] unless ref($p->{fields}) eq
'ARRAY';
1924 # if fields contains spatial fields, then do not create default one 1925 for my $f (@{$p->{fields}}) {
1926 error(
"Field definitions must be hash references.") unless ref $f eq
'HASH';
1927 if ($f->{GeometryType} || ($f->{Type} && s_exists(geometry_type => $f->{Type}))) {
1928 $p->{geometrytype} =
'None';
1932 my $gt = s2i(geometry_type => $p->{geometrytype});
1933 my $layer = _CreateLayer($self, $p->{name}, $p->{srs}, $gt, $p->{options});
1934 for my $f (@{$p->{fields}}) {
1935 $layer->CreateField($f);
1937 keep($layer, $self);
1940 #** @method CreateMaskBand() 1942 # Add a mask band to the dataset. 1944 sub CreateMaskBand {
1945 return _CreateMaskBand(@_);
1948 #** @method Geo::GDAL::Dataset DEMProcessing($Dest, $Processing, $ColorFilename, hashref Options, coderef progress, $progress_data) 1950 # Apply a DEM processing to this dataset. 1951 # @param Dest Destination raster dataset definition string (typically filename) or an object, which implements write and close. 1952 # @param Processing Processing to apply, one of "hillshade", "slope", "aspect", "color-relief", "TRI", "TPI", or "Roughness". 1953 # @param ColorFilename The color palette for color-relief. 1954 # @param Options See section \ref index_processing_options. 1955 # @param progress [optional] A reference to a subroutine, which will 1956 # be called with parameters (number progress, string msg, progress_data). 1957 # @param progress_data [optional] 1961 my ($self, $dest, $Processing, $ColorFilename, $options, $progress, $progress_data) = @_;
1962 $options = Geo::GDAL::GDALDEMProcessingOptions->new(make_processing_options($options));
1963 return $self->stdout_redirection_wrapper(
1965 \&Geo::GDAL::wrapper_GDALDEMProcessing,
1966 $Processing, $ColorFilename, $options, $progress, $progress_data
1970 #** @method Dataset() 1977 #** @method DeleteLayer($name) 1979 # Deletes a layer from the data source. Note that if there is a layer 1980 # object for the deleted layer, it becomes unusable. 1981 # @param name name of the layer to delete. 1984 my ($self, $name) = @_;
1986 for my $i (0..$self->GetLayerCount-1) {
1987 my $layer = GetLayerByIndex($self, $i);
1988 $index = $i, last
if $layer->GetName eq $name;
1990 error(2, $name,
'Layer') unless defined $index;
1991 _DeleteLayer($self, $index);
1994 #** @method Geo::GDAL::Band Dither(%params) 1996 # Compute one band with color table image from an RGB image 1997 # @params params Named parameters: 1998 # - \a Red The red band, the default is to use the red band of this dataset. 1999 # - \a Green The green band, the default is to use the green band of this dataset. 2000 # - \a Blue The blue band, the default is to use the blue band of this dataset. 2001 # - \a Dest The destination band. If this is not defined, a new in-memory band (and a dataset) will be created. 2002 # - \a ColorTable The color table for the result. If this is not defined, and the destination band does not contain one, it will be computed with the ComputeColorTable method. 2003 # - \a Progress Reference to a progress function (default is undef). Note that if ColorTable is computed using ComputeColorTable method, the progress will run twice from 0 to 1. 2004 # - \a ProgressData (default is undef) 2006 # @return the destination band. 2008 # Usage example. This code converts an RGB JPEG image into a one band PNG image with a color table. 2010 # my $d = Geo::GDAL::Open('pic.jpg'); 2011 # Geo::GDAL::Driver('PNG')->Copy(Name => 'test.png', Src => $d->Dither->Dataset); 2016 my $p = named_parameters(\@_,
2023 ProgressData => undef);
2024 for my $b ($self->Bands) {
2025 for my $cion ($b->ColorInterpretation) {
2026 if ($cion eq
'RedBand') { $p->{red}
2027 if ($cion eq
'GreenBand') { $p->{green}
2028 if ($cion eq
'BlueBand') { $p->{blue}
2031 my ($w, $h) = $self->Size;
2035 Type =>
'Byte')->
Band;
2039 Green => $p->{green},
2041 Progress => $p->{progress},
2042 ProgressData => $p->{progressdata});
2043 Geo::GDAL::DitherRGB2PCT($p->{red},
2049 $p->{progressdata});
2054 #** @method Domains() 2060 #** @method Geo::GDAL::Driver Driver() 2062 # @note a.k.a. GetDriver 2063 # @return a Geo::GDAL::Driver object that was used to open or create this dataset. 2068 #** @method Geo::OGR::Layer ExecuteSQL($statement, $geom = undef, $dialect = "") 2070 # @param statement A SQL statement. 2071 # @param geom A Geo::OGR::Geometry object. 2073 # @return a new Geo::OGR::Layer object. The data source object will 2074 # exist as long as the layer object exists. 2078 my $layer = $self->_ExecuteSQL(@_);
2079 note($layer,
"is result set");
2080 keep($layer, $self);
2083 #** @method Geo::GDAL::Extent Extent(@params) 2085 # @param params nothing, or a list ($xoff, $yoff, $w, $h) 2086 # @return A new Geo::GDAL::Extent object that represents the area that 2087 # this raster or the specified tile covers. 2091 my $t = $self->GeoTransform;
2092 my $extent = $t->Extent($self->Size);
2094 my ($xoff, $yoff, $w, $h) = @_;
2095 my ($x, $y) = $t->Apply([$xoff, $xoff+$w, $xoff+$w, $xoff], [$yoff, $yoff, $yoff+$h, $yoff+$h]);
2096 my $xmin = shift @$x;
2099 $xmin = $x
if $x < $xmin;
2100 $xmax = $x
if $x > $xmax;
2102 my $ymin = shift @$y;
2105 $ymin = $y
if $y < $ymin;
2106 $ymax = $y
if $y > $ymax;
2113 #** @method list GCPs(@GCPs, Geo::OSR::SpatialReference sr) 2115 # Get or set the GCPs and their projection. 2116 # @param GCPs [optional] a list of Geo::GDAL::GCP objects 2117 # @param sr [optional] the projection of the GCPs. 2118 # @return a list of Geo::GDAL::GCP objects followed by a Geo::OSR::SpatialReference object. 2124 $proj = $proj->Export(
'WKT')
if $proj and ref($proj);
2125 SetGCPs($self, \@_, $proj);
2127 return unless defined wantarray;
2129 my $GCPs = GetGCPs($self);
2130 return (@$GCPs, $proj);
2133 #** @method Geo::GDAL::GeoTransform GeoTransform(Geo::GDAL::GeoTransform $geo_transform) 2135 # Transformation from cell coordinates (column,row) to projection 2138 # x = geo_transform[0] + column*geo_transform[1] + row*geo_transform[2] 2139 # y = geo_transform[3] + column*geo_transform[4] + row*geo_transform[5] 2141 # @param geo_transform [optional] 2142 # @return the geo transform in a non-void context. 2148 SetGeoTransform($self, $_[0]);
2150 SetGeoTransform($self, \@_);
2153 confess(last_error())
if $@;
2154 return unless defined wantarray;
2155 my $t = GetGeoTransform($self);
2163 #** @method GetDriver() 2168 #** @method list GetFileList() 2170 # @return list of files GDAL believes to be part of this dataset. 2175 #** @method scalar GetGCPProjection() 2177 # @return projection string. 2179 sub GetGCPProjection {
2182 #** @method GetGCPSpatialRef() 2184 sub GetGCPSpatialRef {
2187 #** @method Geo::OGR::Layer GetLayer($name) 2189 # @param name the name of the requested layer. If not given, then 2190 # returns the first layer in the data source. 2191 # @return a new Geo::OGR::Layer object that represents the layer 2192 # in the data source. 2195 my($self, $name) = @_;
2196 my $layer = defined $name ? GetLayerByName($self,
"$name") : GetLayerByIndex($self, 0);
2198 error(2, $name,
'Layer') unless $layer;
2199 keep($layer, $self);
2202 #** @method list GetLayerNames() 2204 # @note Delivers the functionality of undocumented method GetLayerCount. 2205 # @return a list of the names of the layers this data source provides. 2210 for my $i (0..$self->GetLayerCount-1) {
2211 my $layer = GetLayerByIndex($self, $i);
2212 push @names, $layer->GetName;
2217 #** @method GetNextFeature() 2219 sub GetNextFeature {
2222 #** @method GetSpatialRef() 2227 #** @method GetStyleTable() 2232 #** @method Geo::GDAL::Dataset Grid($Dest, hashref Options) 2234 # Creates a regular raster grid from this data source. 2235 # This is equivalent to the gdal_grid utility. 2236 # @param Dest Destination raster dataset definition string (typically 2237 # filename) or an object, which implements write and close. 2238 # @param Options See section \ref index_processing_options. 2241 my ($self, $dest, $options, $progress, $progress_data) = @_;
2242 $options = Geo::GDAL::GDALGridOptions->new(make_processing_options($options));
2243 return $self->stdout_redirection_wrapper(
2245 \&Geo::GDAL::wrapper_GDALGrid,
2246 $options, $progress, $progress_data
2250 #** @method scalar Info(hashref Options) 2252 # Information about this dataset. 2253 # @param Options See section \ref index_processing_options. 2256 my ($self, $o) = @_;
2257 $o = Geo::GDAL::GDALInfoOptions->new(make_processing_options($o));
2258 return GDALInfo($self, $o);
2261 #** @method Geo::GDAL::Dataset Nearblack($Dest, hashref Options, coderef progress, $progress_data) 2263 # Convert nearly black/white pixels to black/white. 2264 # @param Dest Destination raster dataset definition string (typically 2265 # filename), destination dataset to which to add an alpha or mask 2266 # band, or an object, which implements write and close. 2267 # @param Options See section \ref index_processing_options. 2268 # @return Dataset if destination dataset definition string was given, 2269 # otherwise a boolean for success/fail but the method croaks if there 2273 my ($self, $dest, $options, $progress, $progress_data) = @_;
2274 $options = Geo::GDAL::GDALNearblackOptions->new(make_processing_options($options));
2275 my $b = blessed($dest);
2276 if ($b && $b eq
'Geo::GDAL::Dataset') {
2277 Geo::GDAL::wrapper_GDALNearblackDestDS($dest, $self, $options, $progress, $progress_data);
2279 return $self->stdout_redirection_wrapper(
2281 \&Geo::GDAL::wrapper_GDALNearblackDestName,
2282 $options, $progress, $progress_data
2287 #** @method Geo::GDAL::Dataset Open() 2288 # Package subroutine. 2289 # The same as Geo::GDAL::Open 2294 #** @method Geo::GDAL::Dataset OpenShared() 2295 # Package subroutine. 2296 # The same as Geo::GDAL::OpenShared 2301 #** @method Geo::GDAL::Dataset Rasterize($Dest, hashref Options, coderef progress, $progress_data) 2303 # Render data from this data source into a raster. 2304 # @param Dest Destination raster dataset definition string (typically 2305 # filename), destination dataset, or an object, which implements write and close. 2306 # @param Options See section \ref index_processing_options. 2307 # @return Dataset if destination dataset definition string was given, 2308 # otherwise a boolean for success/fail but the method croaks if there 2313 my ($self, $dest, $options, $progress, $progress_data) = @_;
2314 $options = Geo::GDAL::GDALRasterizeOptions->new(make_processing_options($options));
2315 my $b = blessed($dest);
2316 if ($b && $b eq
'Geo::GDAL::Dataset') {
2317 Geo::GDAL::wrapper_GDALRasterizeDestDS($dest, $self, $options, $progress, $progress_data);
2319 # TODO: options need to force a new raster be made, otherwise segfault 2320 return $self->stdout_redirection_wrapper(
2322 \&Geo::GDAL::wrapper_GDALRasterizeDestName,
2323 $options, $progress, $progress_data
2328 #** @method scalar ReadRaster(%params) 2330 # Read data from the dataset. 2332 # @param params Named parameters: 2333 # - \a XOff x offset (cell coordinates) (default is 0) 2334 # - \a YOff y offset (cell coordinates) (default is 0) 2335 # - \a XSize width of the area to read (default is the width of the dataset) 2336 # - \a YSize height of the area to read (default is the height of the dataset) 2337 # - \a BufXSize (default is undef, i.e., the same as XSize) 2338 # - \a BufYSize (default is undef, i.e., the same as YSize) 2339 # - \a BufType data type of the buffer (default is the data type of the first band) 2340 # - \a BandList a reference to an array of band indices (default is [1]) 2341 # - \a BufPixelSpace (default is 0) 2342 # - \a BufLineSpace (default is 0) 2343 # - \a BufBandSpace (default is 0) 2344 # - \a ResampleAlg one of Geo::GDAL::RIOResamplingTypes (default is 'NearestNeighbour'), 2345 # - \a Progress reference to a progress function (default is undef) 2346 # - \a ProgressData (default is undef) 2348 # <a href="http://www.gdal.org/classGDALDataset.html">Entry in GDAL docs (method RasterIO)</a> 2349 # @return a buffer, open the buffer with \a unpack function of Perl. See Geo::GDAL::Band::PackCharacter. 2353 my ($width, $height) = $self->Size;
2354 my ($type) = $self->Band->DataType;
2355 my $p = named_parameters(\@_,
2367 ResampleAlg =>
'NearestNeighbour',
2369 ProgressData => undef
2371 $p->{resamplealg} = s2i(rio_resampling => $p->{resamplealg});
2372 $p->{buftype} = s2i(data_type => $p->{buftype}, 1);
2373 $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});
2376 #** @method ReadTile() 2379 my ($self, $xoff, $yoff, $xsize, $ysize, $w_tile, $h_tile, $alg) = @_;
2381 for my $i (0..$self->Bands-1) {
2382 $data[$i] = $self->Band($i+1)->ReadTile($xoff, $yoff, $xsize, $ysize, $w_tile, $h_tile, $alg);
2387 #** @method ReleaseResultSet($layer) 2389 # @param layer A layer the has been created with ExecuteSQL. 2390 # @note There is no need to call this method. The result set layer is 2391 # released in the destructor of the layer that was created with SQL. 2393 sub ReleaseResultSet {
2394 # a no-op, _ReleaseResultSet is called from Layer::DESTROY 2397 #** @method ResetReading() 2402 #** @method RollbackTransaction() 2404 sub RollbackTransaction {
2407 #** @method SetGCPs2() 2412 #** @method SetSpatialRef() 2417 #** @method SetStyleTable() 2422 #** @method list Size() 2424 # @return (width, height) 2428 return ($self->{RasterXSize}, $self->{RasterYSize});
2431 #** @method Geo::OSR::SpatialReference SpatialReference(Geo::OSR::SpatialReference sr) 2433 # Get or set the projection of this dataset. 2434 # @param sr [optional] a Geo::OSR::SpatialReference object, 2435 # which replaces the existing projection definition of this dataset. 2436 # @return a Geo::OSR::SpatialReference object, which represents the 2437 # projection of this dataset. 2438 # @note Methods GetProjection, SetProjection, and Projection return WKT strings. 2440 sub SpatialReference {
2441 my($self, $sr) = @_;
2442 SetProjection($self, $sr->As(
'WKT'))
if defined $sr;
2443 if (defined wantarray) {
2444 my $p = GetProjection($self);
2450 #** @method StartTransaction() 2452 sub StartTransaction {
2455 #** @method TestCapability() 2457 sub TestCapability {
2458 return _TestCapability(@_);
2461 #** @method Tile(Geo::GDAL::Extent e) 2463 # Compute the top left cell coordinates and width and height of the 2464 # tile that covers the given extent. 2465 # @param e The extent whose tile is needed. 2466 # @note Requires that the raster is a strictly north up one. 2467 # @return A list ($xoff, $yoff, $xsize, $ysize). 2470 my ($self, $e) = @_;
2471 my ($w, $h) = $self->Size;
2472 my $t = $self->GeoTransform;
2473 confess
"GeoTransform is not \"north up\"." unless $t->NorthUp;
2474 my $xoff = floor(($e->[0] - $t->[0])/$t->[1]);
2475 $xoff = 0
if $xoff < 0;
2476 my $yoff = floor(($e->[1] - $t->[3])/$t->[5]);
2477 $yoff = 0
if $yoff < 0;
2478 my $xsize = ceil(($e->[2] - $t->[0])/$t->[1]) - $xoff;
2479 $xsize = $w - $xoff
if $xsize > $w - $xoff;
2480 my $ysize = ceil(($e->[3] - $t->[3])/$t->[5]) - $yoff;
2481 $ysize = $h - $yoff
if $ysize > $h - $yoff;
2482 return ($xoff, $yoff, $xsize, $ysize);
2485 #** @method Geo::GDAL::Dataset Translate($Dest, hashref Options, coderef progress, $progress_data) 2487 # Convert this dataset into another format. 2488 # @param Dest Destination dataset definition string (typically 2489 # filename) or an object, which implements write and close. 2490 # @param Options See section \ref index_processing_options. 2491 # @return New dataset object if destination dataset definition 2492 # string was given, otherwise a boolean for success/fail but the 2493 # method croaks if there was an error. 2496 my ($self, $dest, $options, $progress, $progress_data) = @_;
2497 return $self->stdout_redirection_wrapper(
2501 #** @method
Geo::GDAL::Dataset Warp($Dest, hashref Options, coderef progress, $progress_data)
2503 # Reproject
this dataset.
2504 # @param Dest Destination raster dataset definition string (typically
2505 # filename) or an
object, which implements write and close.
2506 # @param Options See section \ref index_processing_options.
2507 # @note This method can be run as a package subroutine with a list of
2508 # datasets as the first argument to mosaic several datasets.
2511 my ($self, $dest, $options, $progress, $progress_data) = @_;
2512 # can be run as object method (one dataset) and as package sub (a list of datasets)
2513 $options = Geo::GDAL::GDALWarpAppOptions->new(make_processing_options($options));
2514 my $b = blessed($dest);
2515 $self = [$self] unless ref $self eq
'ARRAY';
2516 if ($b && $b eq
'Geo::GDAL::Dataset') {
2517 Geo::GDAL::wrapper_GDALWarpDestDS($dest, $self, $options, $progress, $progress_data);
2519 return stdout_redirection_wrapper(
2522 \&Geo::GDAL::wrapper_GDALWarpDestName,
2523 $options, $progress, $progress_data
2528 #** @method Geo::GDAL::Dataset Warped(%params) 2530 # Create a virtual warped dataset from this dataset. 2532 # @param params Named parameters: 2533 # - \a SrcSRS Override the spatial reference system of this dataset if there is one (default is undef). 2534 # - \a DstSRS The target spatial reference system of the result (default is undef). 2535 # - \a ResampleAlg The resampling algorithm (default is 'NearestNeighbour'). 2536 # - \a MaxError Maximum error measured in input cellsize that is allowed in approximating the transformation (default is 0 for exact calculations). 2538 # # <a href="http://www.gdal.org/gdalwarper_8h.html">Documentation for GDAL warper.</a> 2540 # @return a new Geo::GDAL::Dataset object 2544 my $p = named_parameters(\@_, SrcSRS => undef, DstSRS => undef, ResampleAlg =>
'NearestNeighbour', MaxError => 0);
2545 for my $srs (qw/srcsrs dstsrs/) {
2546 $p->{$srs} = $p->{$srs}->ExportToWkt
if $p->{$srs} && blessed $p->{$srs};
2548 $p->{resamplealg} = s2i(resampling => $p->{resamplealg});
2549 my $warped = Geo::GDAL::_AutoCreateWarpedVRT($self, $p->{srcsrs}, $p->{dstsrs}, $p->{resamplealg}, $p->{maxerror});
2550 keep($warped, $self)
if $warped; #
self must live as
long as warped
2553 #** @method WriteRaster(%params) 2555 # Write data into the dataset. 2557 # @param params Named parameters: 2558 # - \a XOff x offset (cell coordinates) (default is 0) 2559 # - \a YOff y offset (cell coordinates) (default is 0) 2560 # - \a XSize width of the area to write (default is the width of the dataset) 2561 # - \a YSize height of the area to write (default is the height of the dataset) 2562 # - \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. 2563 # - \a BufXSize (default is undef, i.e., the same as XSize) 2564 # - \a BufYSize (default is undef, i.e., the same as YSize) 2565 # - \a BufType data type of the buffer (default is the data type of the first band) 2566 # - \a BandList a reference to an array of band indices (default is [1]) 2567 # - \a BufPixelSpace (default is 0) 2568 # - \a BufLineSpace (default is 0) 2569 # - \a BufBandSpace (default is 0) 2571 # <a href="http://www.gdal.org/classGDALDataset.html">Entry in GDAL docs (method RasterIO)</a> 2575 my ($width, $height) = $self->Size;
2576 my ($type) = $self->Band->DataType;
2577 my $p = named_parameters(\@_,
2591 $p->{buftype} = s2i(data_type => $p->{buftype}, 1);
2592 $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});
2595 #** @method WriteTile() 2598 my ($self, $data, $xoff, $yoff) = @_;
2601 for my $i (0..$self->Bands-1) {
2602 $self->Band($i+1)->WriteTile($data->[$i], $xoff, $yoff);
2606 #** @class Geo::GDAL::Driver 2607 # @brief A driver for a specific dataset format. 2610 package Geo::GDAL::Driver;
2614 #** @attr $HelpTopic 2615 # $driver->{HelpTopic} 2619 # $driver->{LongName} 2622 #** @attr $ShortName 2623 # $driver->{ShortName} 2626 #** @method list Capabilities() 2628 # @return A list of capabilities. When executed as a package subroutine 2629 # returns a list of all potential capabilities a driver may have. When 2630 # executed as an object method returns a list of all capabilities the 2633 # Currently capabilities are: 2634 # CREATE, CREATECOPY, DEFAULT_FIELDS, NOTNULL_FIELDS, NOTNULL_GEOMFIELDS, OPEN, RASTER, VECTOR, and VIRTUALIO. 2638 # @all_capabilities = Geo::GDAL::Driver::Capabilities; 2639 # @capabilities_of_the_geotiff_driver = Geo::GDAL::Driver('GTiff')->Capabilities; 2644 return @CAPABILITIES unless $self;
2645 my $h = $self->GetMetadata;
2647 for my $cap (@CAPABILITIES) {
2648 my $test = $h->{
'DCAP_'.uc($cap)};
2649 push @cap, $cap
if defined($test) and $test eq
'YES';
2654 #** @method Geo::GDAL::Dataset Copy(%params) 2656 # Create a new raster Geo::GDAL::Dataset as a copy of an existing dataset. 2657 # @note a.k.a. CreateCopy 2659 # @param params Named parameters: 2660 # - \a Name name for the new raster dataset. 2661 # - \a Src the source Geo::GDAL::Dataset object. 2662 # - \a Strict 1 (default) if the copy must be strictly equivalent, or 0 if the copy may adapt. 2663 # - \a Options an anonymous hash of driver specific options. 2664 # - \a Progress [optional] a reference to a subroutine, which will 2665 # be called with parameters (number progress, string msg, progress_data). 2666 # - \a ProgressData [optional] 2667 # @return a new Geo::GDAL::Dataset object. 2671 my $p = named_parameters(\@_, Name =>
'unnamed', Src => undef, Strict => 1, Options => {}, Progress => undef, ProgressData => undef);
2672 return $self->stdout_redirection_wrapper(
2674 $self->can(
'_CreateCopy'),
2675 $p->{src}, $p->{strict}, $p->{options}, $p->{progress}, $p->{progressdata});
2678 #** @method CopyFiles($NewName, $OldName) 2680 # Copy the files of a dataset. 2681 # @param NewName String. 2682 # @param OldName String. 2687 #** @method Geo::GDAL::Dataset Create(%params) 2689 # Create a raster dataset using this driver. 2690 # @note a.k.a. CreateDataset 2692 # @param params Named parameters: 2693 # - \a Name The name for the dataset (default is 'unnamed') or an object, which implements write and close. 2694 # - \a Width The width for the raster dataset (default is 256). 2695 # - \a Height The height for the raster dataset (default is 256). 2696 # - \a Bands The number of bands to create into the raster dataset (default is 1). 2697 # - \a Type The data type for the raster cells (default is 'Byte'). One of Geo::GDAL::Driver::CreationDataTypes. 2698 # - \a Options Driver creation options as a reference to a hash (default is {}). 2700 # @return A new Geo::GDAL::Dataset object. 2704 my $p = named_parameters(\@_, Name =>
'unnamed', Width => 256, Height => 256, Bands => 1, Type =>
'Byte', Options => {});
2705 my $type = s2i(data_type => $p->{type});
2706 return $self->stdout_redirection_wrapper(
2708 $self->can(
'_Create'),
2709 $p->{width}, $p->{height}, $p->{bands}, $type, $p->{options}
2713 #** @method list CreationDataTypes() 2715 # @return a list of data types that can be used for new datasets of this format. A subset of Geo::GDAL::DataTypes 2717 sub CreationDataTypes {
2719 my $h = $self->GetMetadata;
2720 return split /\s+/, $h->{DMD_CREATIONDATATYPES}
if $h->{DMD_CREATIONDATATYPES};
2723 #** @method list CreationOptionList() 2725 # @return a list of options, each option is a hashref, the keys are 2726 # name, type and description or Value. Value is a listref. 2728 sub CreationOptionList {
2731 my $h = $self->GetMetadata->{DMD_CREATIONOPTIONLIST};
2733 $h = ParseXMLString($h);
2734 my($type, $value) = NodeData($h);
2735 if ($value eq
'CreationOptionList') {
2736 for my $o (Children($h)) {
2738 for my $a (Children($o)) {
2739 my(undef, $key) = NodeData($a);
2740 my(undef, $value) = NodeData(Child($a, 0));
2741 if ($key eq
'Value') {
2742 push @{$option{$key}}, $value;
2744 $option{$key} = $value;
2747 push @options, \%option;
2754 #** @method Delete($name) 2761 #** @method Domains() 2767 #** @method scalar Extension() 2769 # @note The returned extension does not contain a '.' prefix. 2770 # @return a suggested single extension or a list of extensions (in 2771 # list context) for datasets. 2775 my $h = $self->GetMetadata;
2777 my $e = $h->{DMD_EXTENSIONS};
2778 my @e = split / /, $e;
2780 for my $i (0..$#e) {
2785 my $e = $h->{DMD_EXTENSION};
2786 return '' if $e =~ /\
2792 #** @method scalar MIMEType() 2794 # @return a suggested MIME type for datasets. 2798 my $h = $self->GetMetadata;
2799 return $h->{DMD_MIMETYPE};
2802 #** @method scalar Name() 2804 # @return The short name of the driver. 2808 return $self->{ShortName};
2813 # The same as Geo::GDAL::Open except that only this driver is allowed. 2817 my @p = @_; # name, update
2818 my @flags = qw/RASTER/;
2819 push @flags, qw/READONLY/
if $p[1] eq
'ReadOnly';
2820 push @flags, qw/UPDATE/
if $p[1] eq
'Update';
2821 my $dataset = OpenEx($p[0], \@flags, [$self->Name()]);
2822 error(
"Failed to open $p[0]. Is it a raster dataset?") unless $dataset;
2826 #** @method Rename($NewName, $OldName) 2828 # Rename (move) a GDAL dataset. 2829 # @param NewName String. 2830 # @param OldName String. 2835 #** @method scalar TestCapability($cap) 2837 # Test whether the driver has the specified capability. 2838 # @param cap A capability string (one of those returned by Capabilities). 2839 # @return a boolean value. 2841 sub TestCapability {
2842 my($self, $cap) = @_;
2843 my $h = $self->GetMetadata->{
'DCAP_'.uc($cap)};
2844 return (defined($h) and $h eq
'YES') ? 1 : undef;
2847 #** @method stdout_redirection_wrapper() 2849 sub stdout_redirection_wrapper {
2850 my ($self, $name, $sub, @params) = @_;
2852 if ($name && blessed $name) {
2854 my $ref = $object->can(
'write');
2855 VSIStdoutSetRedirection($ref);
2856 $name =
'/vsistdout/';
2860 $ds = $sub->($self, $name, @params);
2864 $Geo::GDAL::stdout_redirection{tied(%$ds)} = $object;
2866 VSIStdoutUnsetRedirection();
2870 confess(last_error())
if $@;
2871 confess(
"Failed. Use Geo::OGR::Driver for vector drivers.") unless $ds;
2875 #** @class Geo::GDAL::Extent 2876 # @brief A rectangular area in projection coordinates: xmin, ymin, xmax, ymax. 2878 package Geo::GDAL::Extent;
2880 #** @method ExpandToInclude($extent) 2881 # Package subroutine. 2882 # Extends this extent to include the other extent. 2883 # @param extent Another Geo::GDAL::Extent object. 2885 sub ExpandToInclude {
2886 my ($self, $e) = @_;
2887 return if $e->IsEmpty;
2888 if ($self->IsEmpty) {
2891 $self->[0] = $e->[0]
if $e->[0] < $self->[0];
2892 $self->[1] = $e->[1]
if $e->[1] < $self->[1];
2893 $self->[2] = $e->[2]
if $e->[2] > $self->[2];
2894 $self->[3] = $e->[3]
if $e->[3] > $self->[3];
2898 #** @method IsEmpty() 2902 return $self->[2] < $self->[0];
2905 #** @method scalar Overlap($extent) 2906 # Package subroutine. 2907 # @param extent Another Geo::GDAL::Extent object. 2908 # @return A new, possibly empty, Geo::GDAL::Extent object, which 2909 # represents the joint area of the two extents. 2912 my ($self, $e) = @_;
2915 $ret->[0] = $e->[0]
if $self->[0] < $e->[0];
2916 $ret->[1] = $e->[1]
if $self->[1] < $e->[1];
2917 $ret->[2] = $e->[2]
if $self->[2] > $e->[2];
2918 $ret->[3] = $e->[3]
if $self->[3] > $e->[3];
2922 #** @method scalar Overlaps($extent) 2923 # Package subroutine. 2924 # @param extent Another Geo::GDAL::Extent object. 2925 # @return True if this extent overlaps the other extent, false otherwise. 2928 my ($self, $e) = @_;
2929 return $self->[0] < $e->[2] && $self->[2] > $e->[0] && $self->[1] < $e->[3] && $self->[3] > $e->[1];
2932 #** @method list Size() 2933 # Package subroutine. 2934 # @return A list ($width, $height). 2938 return (0,0)
if $self->
IsEmpty;
2939 return ($self->[2] - $self->[0], $self->[3] - $self->[1]);
2942 #** @method Geo::GDAL::Extent new(@params) 2943 # Package subroutine. 2944 # @param params nothing, a list ($xmin, $ymin, $xmax, $ymax), or an Extent object 2945 # @return A new Extent object (empty if no parameters, a copy of the parameter if it is an Extent object). 2952 } elsif (ref $_[0]) {
2957 bless $self, $class;
2961 #** @class Geo::GDAL::GCP 2962 # @brief A ground control point for georeferencing rasters. 2965 package Geo::GDAL::GCP;
2970 # cell x coordinate (access as $gcp->{Column}) 2974 # unique identifier (string) (access as $gcp->{Id}) 2978 # informational message (access as $gcp->{Info}) 2982 # cell y coordinate (access as $gcp->{Row}) 2986 # projection coordinate (access as $gcp->{X}) 2990 # projection coordinate (access as $gcp->{Y}) 2994 # projection coordinate (access as $gcp->{Z}) 2997 #** @method scalar new($x = 0.0, $y = 0.0, $z = 0.0, $column = 0.0, $row = 0.0, $info = "", $id = "") 2999 # @param x projection coordinate 3000 # @param y projection coordinate 3001 # @param z projection coordinate 3002 # @param column cell x coordinate 3003 # @param row cell y coordinate 3004 # @param info informational message 3005 # @param id unique identifier (string) 3006 # @return a new Geo::GDAL::GCP object 3010 my $self = Geo::GDALc::new_GCP(@_);
3011 bless $self, $pkg
if defined($self);
3014 #** @class Geo::GDAL::GeoTransform 3015 # @brief An array of affine transformation coefficients. 3016 # @details The geo transformation has the form 3018 # x = a + column * b + row * c 3019 # y = d + column * e + row * f 3022 # (column,row) is the location in cell coordinates, and 3023 # (x,y) is the location in projection coordinates, or vice versa. 3024 # A Geo::GDAL::GeoTransform object is a reference to an anonymous array [a,b,c,d,e,f]. 3026 package Geo::GDAL::GeoTransform;
3028 #** @method Apply($x, $y) 3030 # @param x Column or x, or a reference to an array of columns or x's 3031 # @param y Row or y, or a reference to an array of rows or y's 3032 # @return a list (x, y), where x and y are the transformed coordinates 3033 # or references to arrays of transformed coordinates. 3036 my ($self, $columns, $rows) = @_;
3037 return Geo::GDAL::ApplyGeoTransform($self, $columns, $rows) unless ref($columns) eq
'ARRAY';
3039 for my $i (0..$#$columns) {
3041 Geo::GDAL::ApplyGeoTransform($self, $columns->[$i], $rows->[$i]);
3048 # @return a new Geo::GDAL::GeoTransform object, which is the inverse 3049 # of this one (in void context changes this object). 3053 my @inv = Geo::GDAL::InvGeoTransform($self);
3058 #** @method NorthUp() 3062 return $self->[2] == 0 && $self->[4] == 0;
3065 #** @method new(@params) 3067 # @param params nothing, a reference to an array [a,b,c,d,e,f], a list 3068 # (a,b,c,d,e,f), or named parameters 3069 # - \a GCPs A reference to an array of Geo::GDAL::GCP objects. 3070 # - \a ApproxOK Minimize the error in the coefficients (integer, default is 1 (true), used with GCPs). 3071 # - \a Extent A Geo::GDAL::Extent object used to obtain the coordinates of the up left corner position. 3072 # - \a CellSize The cell size (width and height) (default is 1, used with Extent). 3074 # @note When Extent is specifid, the created geo transform will be 3075 # north up, have square cells, and coefficient f will be -1 times the 3076 # cell size (image y - row - will increase downwards and projection y 3077 # will increase upwards). 3078 # @return a new Geo::GDAL::GeoTransform object. 3084 $self = [0,1,0,0,0,1];
3085 } elsif (ref $_[0]) {
3087 } elsif ($_[0] =~ /^[a-zA-Z]/i) {
3088 my $p = named_parameters(\@_, GCPs => undef, ApproxOK => 1,
Extent => undef, CellSize => 1);
3090 $self = Geo::GDAL::GCPsToGeoTransform($p->{gcps}, $p->{approxok});
3091 } elsif ($p->{extent}) {
3094 error(
"Missing GCPs or Extent");
3100 bless $self, $class;
3103 #** @class Geo::GDAL::MajorObject 3104 # @brief An object, which holds meta data. 3107 package Geo::GDAL::MajorObject;
3111 #** @method scalar Description($description) 3113 # @param description [optional] 3114 # @return the description in a non-void context. 3117 my($self, $desc) = @_;
3118 SetDescription($self, $desc)
if defined $desc;
3119 GetDescription($self)
if defined wantarray;
3122 #** @method Domains() 3123 # Package subroutine. 3124 # @return the class specific DOMAINS list 3130 #** @method scalar GetDescription() 3134 sub GetDescription {
3137 #** @method hash reference GetMetadata($domain = "") 3139 # @note see Metadata 3146 #** @method GetMetadataDomainList() 3148 sub GetMetadataDomainList {
3151 #** @method hash reference Metadata(hashref metadata = undef, $domain = '') 3155 # @return the metadata in a non-void context. 3159 my $metadata = ref $_[0] ? shift : undef;
3161 SetMetadata($self, $metadata, $domain)
if defined $metadata;
3162 GetMetadata($self, $domain)
if defined wantarray;
3165 #** @method SetDescription($NewDesc) 3170 sub SetDescription {
3173 #** @method SetMetadata(hashref metadata, $domain = "") 3175 # @note see Metadata 3183 #** @class Geo::GDAL::RasterAttributeTable 3184 # @brief An attribute table in a raster band. 3187 package Geo::GDAL::RasterAttributeTable;
3198 #** @method ChangesAreWrittenToFile() 3200 sub ChangesAreWrittenToFile {
3203 #** @method Geo::GDAL::RasterAttributeTable Clone() 3205 # @return a new Geo::GDAL::RasterAttributeTable object 3210 #** @method hash Columns(%columns) 3212 # A get/set method for the columns of the RAT 3213 # @param columns optional, a the keys are column names and the values are anonymous 3214 # hashes with keys Type and Usage 3215 # @return a hash similar to the optional input parameter 3220 if (@_) { # create columns
3222 for my $name (keys %columns) {
3223 $self->CreateColumn($name, $columns{$name}{Type}, $columns{$name}{Usage});
3227 for my $c (0..$self->GetColumnCount-1) {
3228 my $name = $self->GetNameOfCol($c);
3229 $columns{$name}{Type} = $self->GetTypeOfCol($c);
3230 $columns{$name}{Usage} = $self->GetUsageOfCol($c);
3235 #** @method CreateColumn($name, $type, $usage) 3238 # @param type one of FieldTypes 3239 # @param usage one of FieldUsages 3242 my($self, $name, $type, $usage) = @_;
3243 for my $color (qw/Red Green Blue Alpha/) {
3244 carp
"RAT column type will be 'Integer' for usage '$color'." if $usage eq $color and $type ne
'Integer';
3246 $type = s2i(rat_field_type => $type);
3247 $usage = s2i(rat_field_usage => $usage);
3248 _CreateColumn($self, $name, $type, $usage);
3251 #** @method DumpReadable() 3256 #** @method list FieldTypes() 3257 # Package subroutine. 3261 return @FIELD_TYPES;
3264 #** @method list FieldUsages() 3265 # Package subroutine. 3269 return @FIELD_USAGES;
3272 #** @method scalar GetColOfUsage($usage) 3278 my($self, $usage) = @_;
3279 _GetColOfUsage($self, s2i(rat_field_usage => $usage));
3282 #** @method scalar GetColumnCount() 3286 sub GetColumnCount {
3289 #** @method scalar GetNameOfCol($column) 3297 #** @method scalar GetRowCount() 3303 #** @method scalar GetRowOfValue($value) 3305 # @param value a cell value 3306 # @return row index or -1 3311 #** @method GetTableType() 3316 #** @method scalar GetTypeOfCol($column) 3322 my($self, $col) = @_;
3323 i2s(rat_field_type => _GetTypeOfCol($self, $col));
3326 #** @method scalar GetUsageOfCol($column) 3332 my($self, $col) = @_;
3333 i2s(rat_field_usage => _GetUsageOfCol($self, $col));
3336 #** @method scalar GetValueAsDouble($row, $column) 3342 sub GetValueAsDouble {
3345 #** @method scalar GetValueAsInt($row, $column) 3354 #** @method scalar GetValueAsString($row, $column) 3360 sub GetValueAsString {
3363 #** @method LinearBinning($Row0MinIn, $BinSizeIn) 3365 # @param Row0MinIn [optional] the lower bound (cell value) of the first category. 3366 # @param BinSizeIn [optional] the width of each category (in cell value units). 3367 # @return ($Row0MinIn, $BinSizeIn) or an empty list if LinearBinning is not set. 3371 SetLinearBinning($self, @_)
if @_ > 0;
3372 return unless defined wantarray;
3373 my @a = GetLinearBinning($self);
3374 return $a[0] ? ($a[1], $a[2]) : ();
3377 #** @method SetRowCount($count) 3385 #** @method SetTableType() 3390 #** @method SetValueAsDouble($row, $column, $value) 3397 sub SetValueAsDouble {
3400 #** @method SetValueAsInt($row, $column, $value) 3410 #** @method SetValueAsString($row, $column, $value) 3417 sub SetValueAsString {
3420 #** @method scalar Value($row, $column, $value) 3424 # @param value [optional] 3428 my($self, $row, $column) = @_;
3429 SetValueAsString($self, $row, $column, $_[3])
if defined $_[3];
3430 return unless defined wantarray;
3431 GetValueAsString($self, $row, $column);
3434 #** @method Geo::GDAL::RasterAttributeTable new() 3436 # @return a new Geo::GDAL::RasterAttributeTable object 3440 my $self = Geo::GDALc::new_RasterAttributeTable(@_);
3441 bless $self, $pkg
if defined($self);
3444 #** @class Geo::GDAL::Transformer 3446 # @details This class is not yet documented for the GDAL Perl bindings. 3447 # @todo Test and document. 3449 package Geo::GDAL::Transformer;
3453 #** @method TransformGeolocations() 3455 sub TransformGeolocations {
3458 #** @method TransformPoint() 3460 sub TransformPoint {
3467 my $self = Geo::GDALc::new_Transformer(@_);
3468 bless $self, $pkg
if defined($self);
3471 #** @class Geo::GDAL::VSIF 3472 # @brief A GDAL virtual file system. 3475 package Geo::GDAL::VSIF;
3477 use base qw(Exporter)
3484 Geo::GDAL::VSIFCloseL($self);
3494 #** @method MkDir($path) 3495 # Package subroutine. 3497 # @param path The directory to make. 3498 # @note The name of this method is VSIMkdir in GDAL. 3502 # mode unused in CPL 3503 Geo::GDAL::Mkdir($path, 0);
3506 #** @method Geo::GDAL::VSIF Open($filename, $mode) 3507 # Package subroutine. 3508 # @param filename Name of the file to open. For example "/vsimem/x". 3509 # @param mode Access mode. 'r', 'r+', 'w', etc. 3510 # @return A file handle on success. 3513 my ($path, $mode) = @_;
3514 my $self = Geo::GDAL::VSIFOpenL($path, $mode);
3515 bless $self,
'Geo::GDAL::VSIF';
3518 #** @method scalar Read($count) 3520 # @param count The number of bytes to read from the file. 3521 # @return A byte string. 3524 my ($self, $count) = @_;
3525 Geo::GDAL::VSIFReadL($count, $self);
3528 #** @method list ReadDir($dir) 3529 # Package subroutine. 3530 # @return Contents of a directory in an anonymous array or as a list. 3534 Geo::GDAL::ReadDir($path);
3537 #** @method scalar ReadDirRecursive($dir) 3538 # Package subroutine. 3539 # @note Give the directory in the form '/vsimem', i.e., without trailing '/'. 3540 # @return Contents of a directory tree in an anonymous array. 3542 sub ReadDirRecursive {
3544 Geo::GDAL::ReadDirRecursive($path);
3547 #** @method Rename($old, $new) 3548 # Package subroutine. 3550 # @note The name of this method is VSIRename in GDAL. 3553 my ($old, $new) = @_;
3554 Geo::GDAL::Rename($old, $new);
3557 #** @method RmDir($path) 3558 # Package subroutine. 3559 # Remove a directory. 3560 # @note The name of this method is VSIRmdir in GDAL. 3563 my ($dirname, $recursive) = @_;
3566 Geo::GDAL::Rmdir($dirname);
3568 for my $f (ReadDir($dirname)) {
3569 next
if $f eq
'..' or $f eq
'.';
3570 my @s = Stat($dirname.
'/'.$f);
3572 Unlink($dirname.
'/'.$f);
3573 } elsif ($s[0] eq
'd') {
3574 Rmdir($dirname.
'/'.$f, 1);
3575 Rmdir($dirname.
'/'.$f);
3582 my $r = $recursive ?
' recursively' :
'';
3583 error(
"Cannot remove directory \"$dirname\"$r.");
3587 #** @method Seek($offset, $whence) 3591 my ($self, $offset, $whence) = @_;
3592 Geo::GDAL::VSIFSeekL($self, $offset, $whence);
3595 #** @method list Stat($filename) 3596 # Package subroutine. 3597 # @return ($filemode, $filesize). filemode is f for a plain file, d 3598 # for a directory, l for a symbolic link, p for a named pipe (FIFO), S 3599 # for a socket, b for a block special file, and c for a character 3604 Geo::GDAL::Stat($path);
3607 #** @method scalar Tell() 3612 Geo::GDAL::VSIFTellL($self);
3615 #** @method Truncate($new_size) 3619 my ($self, $new_size) = @_;
3620 Geo::GDAL::VSIFTruncateL($self, $new_size);
3623 #** @method Unlink($filename) 3624 # Package subroutine. 3625 # @param filename The file to delete. 3626 # @return 0 on success and -1 on an error. 3629 my ($filename) = @_;
3630 Geo::GDAL::Unlink($filename);
3633 #** @method Write($scalar) 3635 # @param scalar The byte string to write to the file. 3636 # @return Number of bytes written into the file. 3639 my ($self, $data) = @_;
3640 Geo::GDAL::VSIFWriteL($data, $self);
3643 #** @class Geo::GDAL::VSILFILE 3645 package Geo::GDAL::VSILFILE;
3649 #** @class Geo::GDAL::XML 3650 # @brief A simple XML parser 3653 package Geo::GDAL::XML;
3655 #** @method new($string) 3657 # @param string String containing XML. 3658 # @return A new Geo::GDAL::XML object, which is a reference to an anonymous array. 3663 my $self = ParseXMLString($xml);
3664 bless $self, $class;
3665 $self->traverse(sub {my $node = shift; bless $node, $class});
3669 #** @method serialize() 3671 # @return The XML serialized into a string. 3675 return SerializeXMLTree($self);
3678 # This file was automatically generated by SWIG (http://www.swig.org). 3681 # Do not make changes to this file unless you know what you are doing--modify 3682 # the SWIG interface file instead. 3685 #** @method traverse(coderef subroutine) 3687 # @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. 3690 my ($self, $sub) = @_;
3691 my $type = $self->[0];
3692 my $data = $self->[1];
3693 $type = NodeType($type);
3694 $sub->($self, $type, $data);
3695 for my $child (@{$self}[2..$#$self]) {
3696 traverse($child, $sub);
3701 # @brief Base class for geographical networks in GDAL. 3706 #** @method CastToGenericNetwork() 3708 sub CastToGenericNetwork {
3711 #** @method CastToNetwork() 3716 #** @method GATConnectedComponents() 3718 sub GATConnectedComponents {
3721 #** @method GATDijkstraShortestPath() 3723 sub GATDijkstraShortestPath {
3726 #** @method GATKShortestPath() 3728 sub GATKShortestPath {
3731 #** @method GNM_EDGE_DIR_BOTH() 3733 sub GNM_EDGE_DIR_BOTH {
3736 #** @method GNM_EDGE_DIR_SRCTOTGT() 3738 sub GNM_EDGE_DIR_SRCTOTGT {
3741 #** @method GNM_EDGE_DIR_TGTTOSRC() 3743 sub GNM_EDGE_DIR_TGTTOSRC {
3747 #** @class Geo::GNM::GenericNetwork 3750 package Geo::GNM::GenericNetwork;
3754 #** @method ChangeAllBlockState() 3756 sub ChangeAllBlockState {
3759 #** @method ChangeBlockState() 3761 sub ChangeBlockState {
3764 #** @method ConnectFeatures() 3766 sub ConnectFeatures {
3769 #** @method ConnectPointsByLines() 3771 sub ConnectPointsByLines {
3774 #** @method CreateRule() 3779 #** @method DeleteAllRules() 3781 sub DeleteAllRules {
3784 #** @method DeleteRule() 3789 #** @method DisconnectFeatures() 3791 sub DisconnectFeatures {
3794 #** @method DisconnectFeaturesWithId() 3796 sub DisconnectFeaturesWithId {
3799 #** @method GetRules() 3804 #** @method ReconnectFeatures() 3806 sub ReconnectFeatures {
3809 #** @class Geo::GNM::MajorObject 3812 package Geo::GNM::MajorObject;
3814 #** @class Geo::GNM::Network 3817 package Geo::GNM::Network;
3821 #** @method CommitTransaction() 3823 sub CommitTransaction {
3826 #** @method CopyLayer() 3831 #** @method DisconnectAll() 3836 #** @method GetFeatureByGlobalFID() 3838 sub GetFeatureByGlobalFID {
3841 #** @method GetFileList() 3846 #** @method GetLayerByIndex() 3848 sub GetLayerByIndex {
3851 #** @method GetLayerByName() 3853 sub GetLayerByName {
3856 #** @method GetLayerCount() 3861 #** @method GetName() 3866 #** @method GetPath() 3871 #** @method GetProjection() 3876 #** @method GetProjectionRef() 3878 sub GetProjectionRef {
3881 #** @method GetVersion() 3886 #** @method RollbackTransaction() 3888 sub RollbackTransaction {
3891 #** @method StartTransaction() 3893 sub StartTransaction {
3897 # @brief OGR utility functions. 3898 # @details A wrapper for many OGR utility functions and a root class for all 3903 #** @method list ByteOrders() 3904 # Package subroutine. 3905 # @return a list of byte order types, XDR and NDR. XDR denotes 3906 # big-endian and NDR denotes little-endian. 3911 #** @method Geo::GDAL::Driver Driver($name) 3912 # Package subroutine. 3914 # @param name the short name of the driver. 3915 # @note No check is made that the driver is actually a vector driver. 3916 # @return a Geo::GDAL::Driver object. 3919 return 'Geo::GDAL::Driver' unless @_;
3923 #** @method list DriverNames() 3924 # Package subroutine. 3925 # A.k.a GetDriverNames 3927 # perl -MGeo::GDAL -e '@d=Geo::OGR::DriverNames;print "@d\n"' 3929 # @note Use Geo::GDAL::DriverNames for raster drivers. 3930 # @return a list of the short names of all available GDAL vector drivers. 3935 #** @method list Drivers() 3936 # Package subroutine. 3937 # @note Use Geo::GDAL::Drivers for raster drivers. 3938 # @return a list of all available GDAL vector drivers. 3942 for my $i (0..GetDriverCount()-1) {
3943 my $driver = Geo::GDAL::GetDriver($i);
3944 push @drivers, $driver
if $driver->TestCapability(
'VECTOR');
3949 #** @method Flatten() 3954 #** @method scalar GeometryTypeModify($type, $modifier) 3956 # @param type a geometry type (one of Geo::OGR::GeometryTypes). 3957 # @param modifier one of 'flatten', 'set_Z', 'make_collection', 'make_curve', or 'make_linear'. 3958 # @return modified geometry type. 3960 sub GeometryTypeModify {
3961 my($type, $modifier) = @_;
3962 $type = s2i(geometry_type => $type);
3963 return i2s(geometry_type => GT_Flatten($type))
if $modifier =~ /flat/i;
3964 return i2s(geometry_type => GT_SetZ($type))
if $modifier =~ /z/i;
3965 return i2s(geometry_type => GT_GetCollection($type))
if $modifier =~ /collection/i;
3966 return i2s(geometry_type => GT_GetCurve($type))
if $modifier =~ /curve/i;
3967 return i2s(geometry_type => GT_GetLinear($type))
if $modifier =~ /linear/i;
3968 error(1, $modifier, {Flatten => 1, SetZ => 1, GetCollection => 1, GetCurve => 1, GetLinear => 1});
3971 #** @method scalar GeometryTypeTest($type, $test, $type2) 3973 # @param type a geometry type (one of Geo::OGR::GeometryTypes). 3974 # @param test one of 'has_z', 'is_subclass_of', 'is_curve', 'is_surface', or 'is_non_linear'. 3975 # @param type2 a geometry type (one of Geo::OGR::GeometryTypes). Required for 'is_subclass_of' test. 3976 # @return result of the test. 3978 sub GeometryTypeTest {
3979 my($type, $test, $type2) = @_;
3980 $type = s2i(geometry_type => $type);
3981 if (defined $type2) {
3982 $type = s2i(geometry_type => $type);
3984 error(
"Usage: GeometryTypeTest(type1, 'is_subclass_of', type2).")
if $test =~ /subclass/i;
3986 return GT_HasZ($type)
if $test =~ /z/i;
3987 return GT_IsSubClassOf($type, $type2)
if $test =~ /subclass/i;
3988 return GT_IsCurve($type)
if $test =~ /curve/i;
3989 return GT_IsSurface($type)
if $test =~ /surface/i;
3990 return GT_IsNonLinear($type)
if $test =~ /linear/i;
3991 error(1, $test, {HasZ => 1, IsSubClassOf => 1, IsCurve => 1, IsSurface => 1, IsNonLinear => 1});
3994 #** @method list GeometryTypes() 3995 # Package subroutine. 3996 # @return a list of all geometry types, currently: 3997 # CircularString, CircularStringM, CircularStringZ, CircularStringZM, CompoundCurve, CompoundCurveM, CompoundCurveZ, CompoundCurveZM, Curve, CurveM, CurvePolygon, CurvePolygonM, CurvePolygonZ, CurvePolygonZM, CurveZ, CurveZM, GeometryCollection, GeometryCollection25D, GeometryCollectionM, GeometryCollectionZM, LineString, LineString25D, LineStringM, LineStringZM, LinearRing, MultiCurve, MultiCurveM, MultiCurveZ, MultiCurveZM, MultiLineString, MultiLineString25D, MultiLineStringM, MultiLineStringZM, MultiPoint, MultiPoint25D, MultiPointM, MultiPointZM, MultiPolygon, MultiPolygon25D, MultiPolygonM, MultiPolygonZM, MultiSurface, MultiSurfaceM, MultiSurfaceZ, MultiSurfaceZM, None, Point, Point25D, PointM, PointZM, Polygon, Polygon25D, PolygonM, PolygonZM, PolyhedralSurface, PolyhedralSurfaceM, PolyhedralSurfaceZ, PolyhedralSurfaceZM, Surface, SurfaceM, SurfaceZ, SurfaceZM, TIN, TINM, TINZ, TINZM, Triangle, TriangleM, TriangleZ, TriangleZM, and Unknown. 4001 # This file was automatically generated by SWIG (http://www.swig.org). 4004 # Do not make changes to this file unless you know what you are doing--modify 4005 # the SWIG interface file instead. 4008 #** @method GetNonLinearGeometriesEnabledFlag() 4010 sub GetNonLinearGeometriesEnabledFlag {
4013 #** @method GetOpenDSCount() 4015 sub GetOpenDSCount {
4028 #** @method Geo::GDAL::Dataset Open($name, $update = 0) 4030 # Open a vector data source. 4031 # @param name The data source string (directory, filename, etc.). 4032 # @param update Whether to open the data source in update mode (default is not). 4033 # @return a new Geo::GDAL::Dataset object. 4036 my @p = @_; # name, update
4037 my @flags = qw/VECTOR/;
4038 push @flags, qw/UPDATE/
if $p[1];
4040 error(
"Failed to open $p[0]. Is it a vector dataset?") unless $dataset;
4044 #** @method Geo::GDAL::Dataset OpenShared($name, $update = 0) 4046 # Open a vector data source in shared mode. 4047 # @param name The data source string (directory, filename, etc.). 4048 # @param update Whether to open the data source in update mode. 4049 # @return a new Geo::GDAL::Dataset object. 4052 my @p = @_; # name, update
4053 my @flags = qw/VECTOR SHARED/;
4054 push @flags, qw/UPDATE/
if $p[1];
4056 error(
"Failed to open $p[0]. Is it a vector dataset?") unless $dataset;
4060 #** @method SetGenerate_DB2_V72_BYTE_ORDER($Generate_DB2_V72_BYTE_ORDER) 4062 # Needed only on IBM DB2. 4064 sub SetGenerate_DB2_V72_BYTE_ORDER {
4067 #** @method SetNonLinearGeometriesEnabledFlag() 4069 sub SetNonLinearGeometriesEnabledFlag {
4072 #** @class Geo::OGR::DataSource 4073 # @brief A vector dataset. 4074 # @details This is a legacy class which should not be 4075 # used in new code. Use Geo::GDAL::Dataset. 4077 package Geo::OGR::DataSource;
4079 #** @method Geo::GDAL::Dataset Open() 4080 # Package subroutine. 4081 # The same as Geo::OGR::Open 4086 #** @method Geo::GDAL::Dataset OpenShared() 4087 # Package subroutine. 4088 # The same as Geo::OGR::OpenShared 4093 #** @class Geo::OGR::Driver 4094 # @brief A vector format driver. 4095 # @details This is a legacy class which 4096 # should not be used in new code. Use Geo::GDAL::Driver. 4098 package Geo::OGR::Driver;
4102 #** @method Geo::GDAL::Dataset Copy(Geo::GDAL::Dataset source, $name, arrayref options = undef) 4104 # Copy a vector data source into a new data source with this driver. 4105 # @param source The Geo::GDAL::Dataset object to be copied. 4106 # @param name The name for the new data source. 4107 # @param options Driver specific options. In addition to options 4108 # specified in GDAL documentation the option STRICT can be set to 'NO' 4109 # for a more relaxed copy. Otherwise the STRICT is 'YES'. 4110 # @note The order of the first two parameters is different from that in Geo::GDAL::Driver::Copy. 4111 # @return a new Geo::GDAL::Dataset object. 4114 my ($self, @p) = @_; # src, name, options
4115 my $strict = 1; # the
default in bindings
4116 $strict = 0
if $p[2] && $p[2]->{STRICT} eq
'NO';
4117 $self->SUPER::Copy($p[1], $p[0], $strict, @{$p[2..4]}); # path, src, strict, options, cb, cb_data
4120 #** @method Geo::GDAL::Dataset Create($name, hashref options = undef ) 4122 # Create a new vector data source using this driver. 4123 # @param name The data source name. 4124 # @param options Driver specific dataset creation options. 4127 my ($self, $name, $options) = @_; # name, options
4129 $self->SUPER::Create(Name => $name, Width => 0, Height => 0, Bands => 0, Type =>
'Byte', Options => $options);
4134 # The same as Geo::OGR::Open except that only this driver is allowed. 4138 my @p = @_; # name, update
4139 my @flags = qw/VECTOR/;
4140 push @flags, qw/UPDATE/
if $p[1];
4142 error(
"Failed to open $p[0]. Is it a vector dataset?") unless $dataset;
4146 #** @class Geo::OGR::Feature 4147 # @brief A collection of non-spatial and spatial attributes. 4148 # @details A feature is a collection of non-spatial and spatial attributes and 4149 # an id, which is a special attribute, and data records according to 4150 # this data model. Attributes are called fields and some fields are 4151 # spatial, i.e., their value is a geometry. Fields have at least a 4152 # name and a type. Features may exist within a layer or 4153 # separetely. The data model of a feature is a definition object. 4155 package Geo::OGR::Feature;
4159 #** @method Geo::OGR::Feature Clone() 4161 # @return a new Geo::OGR::Feature object 4166 #** @method DumpReadable() 4168 # Write the contents of this feature to stdout. 4173 #** @method scalar Equal($feature) 4175 # @param feature a Geo::OGR::Feature object for comparison 4181 #** @method scalar FID($id) 4183 # @brief Get or set the id of this feature. 4184 # @param id [optional] the id to set for this feature. 4185 # @return integer the id of this feature. 4189 $self->SetFID($_[0])
if @_;
4190 return unless defined wantarray;
4194 #** @method Field($name, $value, ...) 4196 # @brief Get, set, or unset the field value. 4197 # @param name the name (or the index) of the field. 4198 # @param value a scalar, a list of scalars or a reference to a 4199 # list. If undef, the field is unset. If a scalar or a list of 4200 # scalars, the field is set from them. 4201 # @note Non-scalar fields (for example Date) can be set either from a 4202 # scalar, which is then assumed to be a string and parsed, or from a 4203 # list of values (for example year, month, day for Date). 4204 # @note Setting and getting Integer64 fields requires 'use bigint' if 4205 # \$Config{ivsize} is smaller than 8, i.e., in a 32 bit machine. 4206 # @return in non-void context the value of the field, which may be a 4207 # scalar or a list, depending on the field type. For unset fields the 4208 # undef value is returned. 4212 my $field = $self->GetFieldIndex(shift
4213 $self->SetField($field, @_)
if @_;
4214 $self->GetField($field)
if defined wantarray;
4217 #** @method FillUnsetWithDefault() 4219 sub FillUnsetWithDefault {
4222 #** @method Geometry($name, $geometry) 4224 # @brief Get or set the value of a geometry field. 4225 # @note This method delivers the functionality of undocumented methods 4226 # SetGeometry($geometry), SetGeometryDirectly, SetGeomField, 4227 # SetGeomFieldDirectly, GetGeometry, GetGeometryRef. 4229 # Set or get the geometry in the feature. When setting, does a check 4230 # against the schema (GeometryType) of the feature. If the parameter 4231 # is a geometry object, it is cloned. 4232 # @param name [optional] the name of the spatial field, 4233 # whose geometry is to be set. If not given, sets or gets the geometry 4234 # of the first (or the single) spatial field. 4235 # @param geometry [optional] a Geo::OGR::Geometry object or a 4236 # reference to a hash from which such can be created (using 4237 # Geo::OGR::Geometry::new). 4238 # @return in a non-void context the indicated geometry in the feature 4239 # as a Geo::OGR::Geometry object. The returned object contains a 4240 # reference to the actual geometry data in the feature (the geometry 4241 # is not cloned) and to the feature object, thus keeping the feature 4242 # object from being destroyed while the geometry object exists. 4246 my $field = ((@_ > 0 and ref($_[0]) eq
'') or (@_ > 2 and @_ % 2 == 1)) ? shift : 0;
4247 $field = $self->GetGeomFieldIndex($field);
4249 if (@_ and @_ % 2 == 0) {
4255 my $type = $self->GetDefn->GetGeomFieldDefn($field)->Type;
4256 if (blessed($geometry) and $geometry->isa(
'Geo::OGR::Geometry')) {
4257 my $gtype = $geometry->GeometryType;
4258 error(
"The type of the inserted geometry ('$gtype') is not the same as the type of the field ('$type').")
4259 if $type ne
'Unknown' and $type ne $gtype;
4261 $self->SetGeomFieldDirectly($field, $geometry->Clone);
4263 confess last_error()
if $@;
4264 } elsif (ref($geometry) eq
'HASH') {
4265 $geometry->{GeometryType}
4269 confess last_error()
if $@;
4271 error(
"The type of the inserted geometry ('$gtype') is not the same as the type of the field ('$type').")
4272 if $type ne
'Unknown' and $type ne $gtype;
4274 $self->SetGeomFieldDirectly($field, $geometry);
4276 confess last_error()
if $@;
4278 error(
"Usage: \$feature->Geometry([field],[geometry])");
4281 return unless defined wantarray;
4282 $geometry = $self->GetGeomFieldRef($field);
4283 return unless $geometry;
4284 keep($geometry, $self);
4287 #** @method Geo::OGR::FeatureDefn GetDefn() 4289 # @note A.k.a GetDefnRef. 4290 # @return a Geo::OGR::FeatureDefn object, which represents the definition of this feature. 4294 my $defn = $self->GetDefnRef;
4298 #** @method scalar GetFID() 4300 # @return the feature id (an integer). 4305 #** @method list GetField($name) 4310 my ($self, $field) = @_;
4311 $field = $self->GetFieldIndex($field);
4312 return unless IsFieldSet($self, $field);
4313 my $type = GetFieldType($self, $field);
4314 return GetFieldAsInteger($self, $field)
if $type == $Geo::OGR::OFTInteger;
4315 return GetFieldAsInteger64($self, $field)
if $type == $Geo::OGR::OFTInteger64;
4316 return GetFieldAsDouble($self, $field)
if $type == $Geo::OGR::OFTReal;
4317 return GetFieldAsString($self, $field)
if $type == $Geo::OGR::OFTString;
4318 if ($type == $Geo::OGR::OFTIntegerList) {
4319 my $ret = GetFieldAsIntegerList($self, $field);
4320 return wantarray ? @$ret : $ret;
4322 if ($type == $Geo::OGR::OFTInteger64List) {
4323 my $ret = GetFieldAsInteger64List($self, $field);
4324 return wantarray ? @$ret : $ret;
4326 if ($type == $Geo::OGR::OFTRealList) {
4327 my $ret = GetFieldAsDoubleList($self, $field);
4328 return wantarray ? @$ret : $ret;
4330 if ($type == $Geo::OGR::OFTStringList) {
4331 my $ret = GetFieldAsStringList($self, $field);
4332 return wantarray ? @$ret : $ret;
4334 if ($type == $Geo::OGR::OFTBinary) {
4335 return GetFieldAsBinary($self, $field);
4337 if ($type == $Geo::OGR::OFTDate) {
4338 my @ret = GetFieldAsDateTime($self, $field);
4339 # year, month, day, hour, minute, second, timezone 4340 return wantarray ? @ret[0..2] : [@ret[0..2]];
4342 if ($type == $Geo::OGR::OFTTime) {
4343 my @ret = GetFieldAsDateTime($self, $field);
4344 return wantarray ? @ret[3..6] : [@ret[3..6]];
4346 if ($type == $Geo::OGR::OFTDateTime) {
4347 my @ret = GetFieldAsDateTime($self, $field);
4348 return wantarray ? @ret : [@ret];
4350 error(
"Perl bindings do not support the field type '".i2s(field_type => $type).
"'.");
4353 #** @method scalar GetFieldDefn($name) 4355 # Get the definition of a field. 4356 # @param name the name of the field. 4357 # @return a Geo::OGR::FieldDefn object. 4361 my $field = $self->GetFieldIndex(shift);
4362 return $self->GetFieldDefnRef($field);
4365 #** @method list GetFieldNames() 4367 # Get the names of the fields in this feature. 4372 #** @method scalar GetGeomFieldDefn($name) 4374 # Get the definition of a spatial field. 4375 # @param name the name of the spatial field. 4376 # @return a Geo::OGR::GeomFieldDefn object. 4378 sub GetGeomFieldDefn {
4380 my $field = $self->GetGeomFieldIndex(shift);
4381 return $self->GetGeomFieldDefnRef($field);
4384 #** @method GetNativeData() 4389 #** @method GetNativeMediaType() 4391 sub GetNativeMediaType {
4394 #** @method hash reference GetSchema() 4396 # @brief Get the schema of this feature. 4398 # @return the schema as a hash whose keywords are Name, StyleIgnored 4399 # and Fields. Fields is an anonymous array of first non-spatial and 4400 # then spatial field schemas as in Geo::OGR::FieldDefn::Schema() and 4401 # Geo::OGR::GeomFieldDefn::Schema(). 4405 error(
"Schema of a feature cannot be set directly.")
if @_;
4406 return $self->GetDefnRef->Schema;
4409 #** @method scalar GetStyleString() 4413 sub GetStyleString {
4416 #** @method IsFieldNull() 4421 #** @method IsFieldSetAndNotNull() 4423 sub IsFieldSetAndNotNull {
4426 #** @method Geo::OGR::Layer Layer() 4428 # @return the layer to which this feature belongs to or undef. 4435 #** @method hash reference Row(%row) 4437 # @note This method discards the data the destination feature (or 4438 # layer) does not support. Changes in data due to differences between 4439 # field types may also occur. 4441 # Get and/or set the data of the feature. The key of the (key,value) 4442 # pairs of the row is the field name. Special field names FID and 4443 # Geometry are used for feature id and (single) geometry 4444 # respectively. The geometry/ies is/are set and get using the 4445 # Geo::OGR::Feature::Geometry method. Field values are set using the 4446 # Geo::OGR::Feature::Field method. 4447 # @param row [optional] feature data in a hash. 4448 # @return a reference to feature data in a hash. Spatial fields are 4449 # returned as Geo::OGR::Geometry objects. 4453 my $nf = $self->GetFieldCount;
4454 my $ngf = $self->GetGeomFieldCount;
4457 if (@_ == 1 and ref($_[0]) eq
'HASH') {
4459 } elsif (@_ and @_ % 2 == 0) {
4462 error(
'Usage: $feature->Row(%FeatureData).');
4464 $self->SetFID($row{FID})
if defined $row{FID};
4465 #$self->Geometry($schema, $row{Geometry}) if $row{Geometry}; 4466 for my $name (keys %row) {
4467 next
if $name eq
'FID';
4468 if ($name eq
'Geometry') {
4469 $self->Geometry(0, $row{$name});
4473 for my $i (0..$nf-1) {
4474 if ($self->GetFieldDefnRef($i)->Name eq $name) {
4475 $self->SetField($i, $row{$name});
4481 for my $i (0..$ngf-1) {
4482 if ($self->GetGeomFieldDefnRef($i)->Name eq $name) {
4483 $self->Geometry($i, $row{$name});
4489 carp
"Unknown field: '$name'.";
4492 return unless defined wantarray;
4494 for my $i (0..$nf-1) {
4495 my $name = $self->GetFieldDefnRef($i)->Name;
4496 $row{$name} = $self->GetField($i);
4498 for my $i (0..$ngf-1) {
4499 my $name = $self->GetGeomFieldDefnRef($i)->Name ||
'Geometry';
4500 $row{$name} = $self->GetGeometry($i);
4502 $row{FID} = $self->GetFID;
4506 #** @method SetFID($id) 4508 # @param id the feature id. 4513 #** @method SetField($name, @Value) 4519 my $field = $self->GetFieldIndex(shift);
4521 if (@_ == 0 or !defined($arg)) {
4522 _UnsetField($self, $field);
4525 $arg = [@_]
if @_ > 1;
4526 my $type = $self->GetFieldType($field);
4528 if ($type == $Geo::OGR::OFTIntegerList) {
4529 SetFieldIntegerList($self, $field, $arg);
4531 elsif ($type == $Geo::OGR::OFTInteger64List) {
4532 SetFieldInteger64List($self, $field, $arg);
4534 elsif ($type == $Geo::OGR::OFTRealList) {
4535 SetFieldDoubleList($self, $field, $arg);
4537 elsif ($type == $Geo::OGR::OFTStringList) {
4538 SetFieldStringList($self, $field, $arg);
4540 elsif ($type == $Geo::OGR::OFTDate) {
4541 _SetField($self, $field, @$arg[0..2], 0, 0, 0, 0);
4543 elsif ($type == $Geo::OGR::OFTTime) {
4545 _SetField($self, $field, 0, 0, 0, @$arg[0..3]);
4547 elsif ($type == $Geo::OGR::OFTDateTime) {
4549 _SetField($self, $field, @$arg[0..6]);
4551 elsif ($type == $Geo::OGR::OFTInteger64)
4553 SetFieldInteger64($self, $field, $arg);
4556 $type = i2s(field_type => $type);
4557 my $name = $self->GetFieldDefnRef($field)->Name;
4558 error(
"'$arg' is not a suitable value for field $name($type).");
4561 if ($type == $Geo::OGR::OFTBinary) {
4562 #$arg = unpack('H*', $arg); # remove when SetFieldBinary is available 4563 $self->SetFieldBinary($field, $arg);
4565 elsif ($type == $Geo::OGR::OFTInteger64)
4567 SetFieldInteger64($self, $field, $arg);
4569 elsif ($type == $Geo::OGR::OFTInteger or $type == $Geo::OGR::OFTReal or $type == $Geo::OGR::OFTString)
4571 _SetField($self, $field, $arg);
4574 $type = i2s(field_type => $type);
4575 my $name = $self->GetFieldDefnRef($field)->Name;
4576 error(
"'$arg' is not a suitable value for field $name($type).");
4581 #** @method SetFieldNull() 4586 #** @method SetFrom($other, $forgiving = 1, hashref map) 4588 # @param other a Geo::OGR::Feature object 4589 # @param forgiving [optional] set to false if the operation should not 4590 # continue if output fields do not match some of the source fields 4591 # @param map [optional] a mapping from output field indexes to source 4592 # fields, include into the hash all field indexes of this feature 4593 # which should be set 4596 my($self, $other) = @_;
4597 _SetFrom($self, $other),
return if @_ <= 2;
4598 my $forgiving = $_[2];
4599 _SetFrom($self, $other, $forgiving),
return if @_ <= 3;
4602 for my $i (1..GetFieldCount($self)) {
4603 push @list, ($map->{$i} || -1);
4605 SetFromWithMap($self, $other, 1, \@list);
4608 #** @method SetNativeData() 4613 #** @method SetNativeMediaType() 4615 sub SetNativeMediaType {
4618 #** @method SetStyleString($string) 4622 sub SetStyleString {
4625 #** @method list Tuple(@tuple) 4627 # @note This method discards the data the destination feature (or 4628 # layer) does not support. Changes in data due to differences between 4629 # field types may also occur. 4631 # @note The schema of the tuple needs to be the same as that of the 4634 # Get and/set the data of the feature. The expected data in the tuple 4635 # is ([feature_id,] non-spatial fields, spatial fields). The fields in 4636 # the tuple are in the order they are in the schema. Field values are 4637 # set using the Geo::OGR::Feature::Field method. Geometries are set 4638 # and get using the Geo::OGR::Feature::Geometry method. 4639 # @param tuple [optional] feature data in an array 4640 # @return feature data in an array 4644 my $nf = $self->GetFieldCount;
4645 my $ngf = $self->GetGeomFieldCount;
4647 my $values = ref $_[0] ? $_[0] : \@_;
4649 $FID = shift @$values
if @$values == $nf + $ngf + 1;
4650 $self->SetFID($FID)
if defined $FID;
4651 if (@$values != $nf + $ngf) {
4653 error(
"Too many or too few attribute values for a feature (need $n).");
4655 my $index = 0; # index to non-geometry and geometry fields
4656 for my $i (0..$nf-1) {
4657 $self->SetField($i, $values->[$i]);
4659 for my $i (0..$ngf-1) {
4660 $self->Geometry($i, $values->[$nf+$i]);
4663 return unless defined wantarray;
4664 my @ret = ($self->GetFID);
4665 for my $i (0..$nf-1) {
4666 my $v = $self->GetField($i);
4669 for my $i (0..$ngf-1) {
4670 my $v = $self->GetGeometry($i);
4676 #** @method scalar Validate(list flags) 4678 # @param flags one of more of null, geom_type, width, 4679 # allow_null_when_default, or all. 4680 # @exception croaks with an error message if the feature is not valid. 4681 # @return integer denoting the validity of the feature object. 4687 my $f = eval
'$Geo::OGR::'.uc($flag);
4690 _Validate($self, $flags);
4693 #** @method Geo::OGR::Feature new(%schema) 4695 # @brief Create a new feature. 4696 # @param Named parameters: 4697 # - \a Schema a reference to a schema hash, or a Geo::OGR::Layer, 4698 # Geo::OGR::Feature, or Geo::OGR::FeatureDefn object. 4699 # - \a Values values for the feature attributes. 4700 # - \a StyleIgnored whether the style can be omitted when fetching 4701 # features. (default is false) 4703 # Schema is a hash with the following keys: 4704 # - \a Name name of the schema (not used). 4705 # - \a Fields a list of Geo::OGR::FieldDefn or Geo::OGR::GeomFieldDefn 4706 # objects or references to hashes from which fields can be created. 4707 # - \a GeometryType the geometry type if the feature has only one spatial field. 4709 # @note Do not mix GeometryType and geometry fields in Fields list. 4710 # @note Old syntax where the argument is a Geo::OGR::FeatureDefn 4711 # object or Schema hash is supported. 4713 # @return a new Geo::OGR::Feature object. 4719 if (ref $_[0] eq
'HASH' && $_[0]->{Schema}) {
4722 $arg = {Schema => $_[0]};
4724 } elsif (@_ and @_ % 2 == 0) {
4726 unless ($arg->{Schema}) {
4728 $arg->{Schema} = \%tmp;
4731 error(
"The argument must be either a schema or a hash.");
4733 error(
"Missing schema.") unless $arg->{Schema};
4735 for (ref $arg->{Schema}) {
4737 $defn = $arg->{Schema}->GetDefn;
4741 $defn = $arg->{Schema};
4746 my $self = Geo::OGRc::new_Feature($defn);
4747 error(
"Feature creation failed.") unless $self;
4749 for (ref $arg->{Values}) {
4751 $self->Tuple($arg->{Values});
4755 $self->Row($arg->{Values});
4759 $self->
Tuple($arg->{Values}->Tuple);
4765 error(
"Value parameter must be an array, hash, or another feature. Not $_.");
4770 #** @class Geo::OGR::FeatureDefn 4771 # @brief The schema of a feature or a layer. 4772 # @details A FeatureDefn object is a collection of field definition objects. A 4773 # read-only FeatureDefn object can be obtained from a layer 4774 # (Geo::OGR::Layer::GetDefn()) or a feature 4775 # (Geo::OGR::Feature::GetDefn()). 4777 package Geo::OGR::FeatureDefn;
4781 #** @method AddField(%params) 4783 # @param params Named parameters to create a new Geo::OGR::FieldDefn 4784 # or Geo::OGR::GeomFieldDefn object. 4788 error(
"Read-only definition.")
if parent($self);
4791 } elsif (ref($_[0]) eq
'HASH') {
4793 } elsif (@_ % 2 == 0) {
4797 if (s_exists(field_type => $params{Type})) {
4799 $self->AddFieldDefn($fd);
4802 $self->AddGeomFieldDefn($fd);
4806 #** @method DeleteField($name) 4808 # @note Currently only geometry fields can be deleted. 4809 # @param index the index of the geometry field to be deleted. 4812 my ($self, $name) = @_;
4813 error(
"Read-only definition.")
if parent($self);
4814 for my $i (0..$self->GetFieldCount-1) {
4815 error(
"Non-spatial fields cannot be deleted.")
if $self->_GetFieldDefn($i)->Name eq $name;
4817 for my $i (0..$self->GetGeomFieldCount-1) {
4818 $self->DeleteGeomFieldDefn($i)
if $self->_GetGeomFieldDefn($i)->Name eq $name;
4820 error(2, $name,
'Field');
4823 #** @method Feature() 4827 return parent($self);
4830 #** @method scalar GetFieldDefn($name) 4832 # Get the definition of a field. 4833 # @param name the name of the field. 4834 # @return a Geo::OGR::FieldDefn object. 4838 my $field = $self->GetFieldIndex(shift);
4839 return $self->_GetFieldDefn($field);
4842 #** @method list GetFieldNames() 4844 # The names of the fields in this layer or feature definition. 4845 # @return the list of field names. 4850 for my $i (0..$self->GetFieldCount-1) {
4851 push @names, $self->_GetFieldDefn($i)->Name;
4853 for my $i (0..$self->GetGeomFieldCount-1) {
4854 push @names, $self->_GetGeomFieldDefn($i)->Name;
4859 #** @method scalar GetGeomFieldDefn($name) 4861 # Get the definition of a spatial field. 4862 # @param name the name of the spatial field. 4863 # @return a Geo::OGR::GeomFieldDefn object. 4865 sub GetGeomFieldDefn {
4867 my $field = $self->GetGeomFieldIndex(shift);
4868 return $self->_GetGeomFieldDefn($field);
4871 #** @method scalar GetName() 4873 # @return the name of this layer or feature definition. 4878 #** @method hash reference GetSchema() 4880 # @brief Get the schema of this feature or layer definition. 4882 # @return the schema as a hash whose keywords are Name, StyleIgnored 4883 # and Fields. Fields is an anonymous array of first non-spatial and 4884 # then spatial field schemas as in Geo::OGR::FieldDefn::Schema() and 4885 # Geo::OGR::GeomFieldDefn::Schema(). 4889 carp
"Schema of a feature definition should not be set directly." if @_;
4890 if (@_ and @_ % 2 == 0) {
4892 if ($schema{Fields}) {
4893 for my $field (@{$schema{Fields}}) {
4894 $self->AddField($field);
4899 $schema{Name} = $self->Name();
4900 $schema{StyleIgnored} = $self->StyleIgnored();
4901 $schema{Fields} = [];
4902 for my $i (0..$self->GetFieldCount-1) {
4903 my $s = $self->_GetFieldDefn($i)->Schema;
4904 push @{$schema{Fields}}, $s;
4906 for my $i (0..$self->GetGeomFieldCount-1) {
4907 my $s = $self->_GetGeomFieldDefn($i)->Schema;
4908 push @{$schema{Fields}}, $s;
4910 return wantarray ? %schema : \%schema;
4913 #** @method IsSame(Geo::OGR::FeatureDefn defn) 4915 # @return true if this definition is similar to the other definition, 4921 #** @method scalar IsStyleIgnored() 4923 # Get the ignore status of style information when fetching features. 4924 # @return the ignore status of style information 4927 sub IsStyleIgnored {
4930 #** @method SetStyleIgnored($IgnoreState) 4932 # Set the ignore status of style information when fetching features. 4935 sub SetStyleIgnored {
4938 #** @method Geo::OGR::FeatureDefn new(%schema) 4940 # Creates a new layer or feature definition. The new definition is 4941 # either initialized to the given schema or it will contain no 4942 # non-spatial fields and one spatial field, whose Name is '' and 4943 # GeometryType is 'Unknown' or the value of the named parameter 4945 # @param schema [optional] The schema for the new feature definition, 4946 # as in Geo::OGR::FeatureDefn::Schema(). 4947 # @return a Geo::OGR::FeatureDefn object 4951 # $fd = Geo::OGR::FeatureDefn->new( 4953 # Fields => [{ Name => 'field1', Type => 'String' }, 4954 # { Name => 'geom', GeometryType => 'Point' }] ); 4960 if (@_ == 1 and ref($_[0]) eq
'HASH') {
4962 } elsif (@_ and @_ % 2 == 0) {
4965 my $fields = $schema{Fields};
4966 error(
"The 'Fields' argument must be an array reference.")
if $fields and ref($fields) ne
'ARRAY';
4968 my $self = Geo::OGRc::new_FeatureDefn($schema{Name});
4970 my $gt = $schema{GeometryType};
4972 $self->GeometryType($gt);
4974 $self->DeleteGeomFieldDefn(0);
4976 $self->StyleIgnored($schema{StyleIgnored})
if exists $schema{StyleIgnored};
4977 for my $fd (@{$fields}) {
4979 if (ref($fd) eq
'HASH') {
4980 # if Name and Type are missing, assume Name => Type 4981 if (!(exists $fd->{Name} && exists $fd->{Type})) {
4982 for my $key (sort keys %$fd) {
4983 if (s_exists(field_type => $fd->{$key}) ||
4984 s_exists(geometry_type => $fd->{$key}))
4987 $fd->{Type} = $fd->{$key};
4993 if ($fd->{GeometryType} or ($fd->{Type} && s_exists(geometry_type => $fd->{Type}))) {
4999 if (blessed($d) and $d->isa(
'Geo::OGR::FieldDefn')) {
5000 AddFieldDefn($self, $d);
5001 } elsif (blessed($d) and $d->isa(
'Geo::OGR::GeomFieldDefn')) {
5002 error(
"Do not mix GeometryType and geometry fields in Fields.")
if $gt;
5003 AddGeomFieldDefn($self, $d);
5005 error(
"Item in field list does not define a field.");
5011 #** @class Geo::OGR::FieldDefn 5012 # @brief A definition of a non-spatial attribute. 5015 package Geo::OGR::FieldDefn;
5019 #** @method scalar Default($value) 5021 # Get or set the default value for this field. 5022 # @note a.k.a. GetDefault and SetDefault 5023 # @param value [optional] 5024 # @return the default value of this field in non-void context. 5028 SetDefault($self, $_[0])
if @_;
5029 GetDefault($self)
if defined wantarray;
5032 #** @method GetSchema() 5037 #** @method scalar Ignored($ignore) 5039 # Get and/or set the ignore status (whether this field should be 5040 # omitted when fetching features) of this field. 5041 # @note a.k.a. IsIgnored, SetIgnored 5042 # @param ignore [optional] 5043 # @return the ignore status of this field in non-void context. 5048 SetIgnored($self, $_[0])
if @_;
5049 IsIgnored($self)
if defined wantarray;
5052 #** @method IsDefaultDriverSpecific() 5054 sub IsDefaultDriverSpecific {
5057 #** @method scalar Justify($justify) 5059 # Get and/or set the justification of this field. 5060 # @note a.k.a. GetJustify, SetJustify 5061 # @param justify [optional] One of field justify types (Geo::OGR::FieldDefn::JustifyValues). 5062 # @return the justify value of this field in non-void context. 5065 my($self, $justify) = @_;
5066 if (defined $justify) {
5067 $justify = s2i(justify => $justify);
5068 SetJustify($self, $justify);
5070 return i2s(justify => GetJustify($self))
if defined wantarray;
5073 #** @method list JustifyValues() 5074 # Package subroutine. 5075 # Justify values supported by GDAL. Current list is 5076 # Left, Right, and Undefined. 5082 #** @method scalar Name($name) 5084 # Get and/or set the name of the field. 5085 # @note a.k.a. GetName, GetNameRef, SetName 5086 # @param name [optional] 5087 # @return the name in non-void context 5091 SetName($self, $_[0])
if @_;
5092 GetName($self)
if defined wantarray;
5095 #** @method scalar Nullable($nullable) 5097 # Get or set the nullable constraint for this field. 5098 # @note a.k.a. IsNullable and SetNullable 5099 # @param nullable [optional] 5100 # @return the nullable value of this field in non-void context. 5104 SetNullable($self, $_[0])
if @_;
5105 IsNullable($self)
if defined wantarray;
5108 #** @method scalar Precision($precision) 5110 # Get and/or set the precision of this field. 5111 # @note a.k.a. GetPrecision, SetPrecision 5112 # @param precision [optional] 5113 # @return the precision of this field in non-void context. 5117 SetPrecision($self, $_[0])
if @_;
5118 GetPrecision($self)
if defined wantarray;
5121 #** @method hash reference Schema(%params) 5123 # Get the schema or set parts of the schema 5124 # @param params [optional] as those in Geo::OGR::FieldDefn::new. 5125 # @return a reference to a hash whose keys are as those in Geo::OGR::FieldDefn::new. 5130 my $params = @_ % 2 == 0 ? {@_} : shift;
5131 for my $key (keys %SCHEMA_KEYS) {
5132 next unless exists $params->{$key};
5133 eval
"\$self->$key(\$params->{$key})";
5134 confess(last_error())
if $@;
5137 return unless defined wantarray;
5139 for my $key (keys %SCHEMA_KEYS) {
5140 $schema{$key} = eval
'$self->'.$key;
5142 return wantarray ? %schema : \%schema;
5145 #** @method SetSchema() 5150 #** @method scalar SubType($SubType) 5152 # @note a.k.a. GetSubType, SetSubType 5153 # @param SubType [optional] One of field sub types (Geo::OGR::FieldDefn::SubTypes). 5154 # @return the sub type of this field in non-void context. 5157 my($self, $subtype) = @_;
5158 if (defined $subtype) {
5159 $subtype = s2i(field_subtype => $subtype);
5160 SetSubType($self, $subtype);
5162 return i2s(field_subtype => GetSubType($self))
if defined wantarray;
5165 #** @method SubTypes() 5171 #** @method scalar Type($type) 5173 # Get and/or set the type of the field. 5174 # @note a.k.a. GetFieldTypeName, GetTypeName, GetType, SetType 5175 # @param type [optional] One of field types (Geo::OGR::FieldDefn::Types). 5176 # @return one of field types in non-void context. 5179 my($self, $type) = @_;
5180 if (defined $type) {
5181 $type = s2i(field_type => $type);
5182 SetType($self, $type);
5184 return i2s(field_type => GetType($self))
if defined wantarray;
5187 #** @method list Types() 5188 # Package subroutine. 5189 # Field types supported by GDAL. Current list is 5190 # Binary, Date, DateTime, Integer, Integer64, Integer64List, IntegerList, Real, RealList, String, StringList, Time, WideString, and WideStringList. 5191 # (However, WideString is not supported.) 5197 #** @method scalar Width($width) 5199 # Get and/or set the field width. 5200 # @note a.k.a. GetWidth, SetWidth 5201 # @param width [optional] 5202 # @return the width of this field in non-void context. 5206 SetWidth($self, $_[0])
if @_;
5207 GetWidth($self)
if defined wantarray;
5210 #** @method Geo::OGR::FieldDefn new(%params) 5212 # @brief Create a new field definition. 5214 # @param Named parameters: 5215 # - \a Name Field name (default is 'unnamed'). 5216 # - \a Type Field type, one of Geo::OGR::FieldDefn::Types (default is 'String'). 5217 # - \a SubType Field sub type, one of Geo::OGR::FieldDefn::SubTypes. 5218 # - \a Justify Justify value, one of Geo::OGR::FieldDefn::JustifyValues 5221 # - \a Nullable (default is true) 5223 # - \a Ignored (default is false) 5225 # @note Simplified parameters Name => 'Type' are also supported. 5227 # @return a new Geo::OGR::FieldDefn object 5231 my $params = {Name =>
'unnamed', Type =>
'String'};
5233 } elsif (@_ == 1 and not ref $_[0]) {
5234 $params->{Name} = shift;
5235 } elsif (@_ == 2 and not $Geo::OGR::FieldDefn::SCHEMA_KEYS{$_[0]}) {
5236 $params->{Name} = shift;
5237 $params->{Type} = shift;
5239 my $tmp = @_ % 2 == 0 ? {@_} : shift;
5240 for my $key (keys %$tmp) {
5241 if ($Geo::OGR::FieldDefn::SCHEMA_KEYS{$key}) {
5242 $params->{$key} = $tmp->{$key};
5244 carp
"Unknown parameter: '$key'." if $key ne
'Index';
5248 $params->{Type} = s2i(field_type => $params->{Type});
5249 my $self = Geo::OGRc::new_FieldDefn($params->{Name}, $params->{Type});
5251 delete $params->{Name};
5252 delete $params->{Type};
5253 $self->Schema($params);
5257 #** @class Geo::OGR::GeomFieldDefn 5258 # @brief A definition of a spatial attribute. 5261 package Geo::OGR::GeomFieldDefn;
5265 #** @method scalar GeometryType($type) 5267 # @note a.k.a. GetType, SetType 5268 # @return the geometry type of the field. 5273 #** @method GetSchema() 5278 #** @method scalar Ignored($ignore) 5280 # @note a.k.a. IsIgnored, SetIgnored 5281 # @return the ignore status of the field. 5285 SetIgnored($self, $_[0])
if @_;
5286 IsIgnored($self)
if defined wantarray;
5289 #** @method scalar Name($name) 5291 # @note a.k.a. GetName, GetNameRef, SetName 5292 # @return the name of the field. 5296 SetName($self, $_[0])
if @_;
5297 GetName($self)
if defined wantarray;
5300 #** @method scalar Nullable($nullable) 5302 # @note a.k.a. IsNullable, SetNullable 5303 # @return the nullable status of the field. 5307 SetNullable($self, $_[0])
if @_;
5308 IsNullable($self)
if defined wantarray;
5311 #** @method hash reference Schema(%params) 5313 # Get the schema or set parts of the schema. 5314 # @param params [optional] as those in Geo::OGR::GeomFieldDefn::new. 5315 # @return a reference to a hash whose keys are as those in Geo::OGR::GeomFieldDefn::new. 5320 my $params = @_ % 2 == 0 ? {@_} : shift;
5321 for my $key (keys %SCHEMA_KEYS) {
5322 next unless exists $params->{$key};
5323 eval
"\$self->$key(\$params->{$key})";
5324 confess last_error()
if $@;
5327 return unless defined wantarray;
5329 for my $key (keys %SCHEMA_KEYS) {
5330 $schema{$key} = eval
'$self->'.$key;
5332 return wantarray ? %schema : \%schema;
5335 #** @method SetSchema() 5340 #** @method scalar SpatialReference($sr) 5342 # @note a.k.a. GetSpatialRef, SetSpatialRef 5343 # @return the spatial reference of the field as a Geo::OSR::SpatialReference object. 5345 sub SpatialReference {
5347 SetSpatialRef($self, $_[0])
if @_;
5348 GetSpatialRef($self)
if defined wantarray;
5353 # @return the type of this geometry field. One of Geo::OGR::GeomFieldDefn::Types 5356 my($self, $type) = @_;
5357 if (defined $type) {
5358 $type = s2i(geometry_type => $type);
5359 SetType($self, $type);
5361 i2s(geometry_type => GetType($self))
if defined wantarray;
5365 # Package subroutine. 5366 # @return a list of all geometry types, currently: 5367 # CircularString, CircularStringM, CircularStringZ, CircularStringZM, CompoundCurve, CompoundCurveM, CompoundCurveZ, CompoundCurveZM, Curve, CurveM, CurvePolygon, CurvePolygonM, CurvePolygonZ, CurvePolygonZM, CurveZ, CurveZM, GeometryCollection, GeometryCollection25D, GeometryCollectionM, GeometryCollectionZM, LineString, LineString25D, LineStringM, LineStringZM, LinearRing, MultiCurve, MultiCurveM, MultiCurveZ, MultiCurveZM, MultiLineString, MultiLineString25D, MultiLineStringM, MultiLineStringZM, MultiPoint, MultiPoint25D, MultiPointM, MultiPointZM, MultiPolygon, MultiPolygon25D, MultiPolygonM, MultiPolygonZM, MultiSurface, MultiSurfaceM, MultiSurfaceZ, MultiSurfaceZM, None, Point, Point25D, PointM, PointZM, Polygon, Polygon25D, PolygonM, PolygonZM, PolyhedralSurface, PolyhedralSurfaceM, PolyhedralSurfaceZ, PolyhedralSurfaceZM, Surface, SurfaceM, SurfaceZ, SurfaceZM, TIN, TINM, TINZ, TINZM, Triangle, TriangleM, TriangleZ, TriangleZM, and Unknown. 5373 #** @method Geo::OGR::GeomFieldDefn new(%params) 5375 # @brief Create a new spatial field definition. 5377 # @param params one or more of: 5378 # - \a Name name for the field (default is 'geom'). 5379 # - \a GeometryType type for the field type, one of Geo::OGR::GeomFieldDefn::Types (default is 'Unknown'). 5380 # - \a SpatialReference a Geo::OSR::SpatialReference object. 5381 # - \a Nullable (default is true) 5382 # - \a Ignored (default is false) 5384 # @note Simplified parameters <name> => <type> is also supported. 5386 # @return a new Geo::OGR::GeomFieldDefn object 5390 my $params = {Name =>
'geom', Type =>
'Unknown'};
5393 $params->{Name} = shift;
5394 } elsif (@_ == 2 and not $Geo::OGR::GeomFieldDefn::SCHEMA_KEYS{$_[0]}) {
5395 $params->{Name} = shift;
5396 $params->{Type} = shift;
5398 my $tmp = @_ % 2 == 0 ? {@_} : shift;
5399 for my $key (keys %$tmp) {
5400 if ($Geo::OGR::GeomFieldDefn::SCHEMA_KEYS{$key}) {
5401 $params->{$key} = $tmp->{$key};
5403 carp
"Unknown parameter: '$key'." if $key ne
'Index' && $key ne
'GeometryType';
5408 $params->{Type} = s2i(geometry_type => $params->{Type});
5409 my $self = Geo::OGRc::new_GeomFieldDefn($params->{Name}, $params->{Type});
5411 delete $params->{Name};
5412 delete $params->{Type};
5413 $self->Schema($params);
5417 #** @class Geo::OGR::Geometry 5418 # @brief Spatial data. 5419 # @details A geometry is spatial data (coordinate values, and a reference to a 5420 # spatial reference system) organized into one of the geometry 5421 # types. Geometries can be created from several type of data including 5422 # a Perl data structure. There are several methods, which modify, 5423 # compare, test, or compute values from geometries. 5424 # @note Most spatial analysis methods require <a 5425 # href="http://geos.osgeo.org/doxygen/">GEOS</a> to work rigorously. 5427 package Geo::OGR::Geometry;
5431 #** @method AddGeometry($other) 5433 # Add a copy of another geometry to a geometry collection 5434 # @param other a Geo::OGR::Geometry object 5439 #** @method AddGeometryDirectly($other) 5441 # @param other a Geo::OGR::Geometry object 5443 sub AddGeometryDirectly {
5446 #** @method AddPoint($x, $y, $z) 5448 # Set the data of a point or add a point to a line string. Consider 5449 # using Geo::OGR::Geometry::Points. Note that the coordinate 5450 # dimension is automatically upgraded to 25D (3) if z is given. 5453 # @param z [optional] 5454 # Calls internally the 2D or 3D version depending on the number of parameters. 5458 my $t = $self->GetGeometryType;
5459 my $has_z = HasZ($t);
5460 my $has_m = HasM($t);
5461 if (!$has_z && !$has_m) {
5462 $self->AddPoint_2D(@_[0..1]);
5463 } elsif ($has_z && !$has_m) {
5464 $self->AddPoint_3D(@_[0..2]);
5465 } elsif (!$has_z && $has_m) {
5466 $self->AddPointM(@_[0..2]);
5468 $self->AddPointZM(@_[0..3]);
5472 #** @method AddPointM() 5477 #** @method AddPointZM() 5482 #** @method AddPoint_2D($x, $y) 5484 # Set the data of a point or add a point to a line string. Consider 5485 # using Geo::OGR::Geometry::Points. 5492 #** @method AddPoint_3D($x, $y, $z) 5494 # Set the data of a point or add a point to a line string. Note that 5495 # the coordinate dimension is automatically upgraded to 25D (3). Consider 5496 # using Geo::OGR::Geometry::Points. 5504 #** @method Geo::OGR::Geometry ApproximateArcAngles(%params) 5505 # Package subroutine. 5506 # Create a line string, which approximates an arc. 5507 # @note All angles are in degrees. 5509 # @param %params Named parameters: 5510 # - \a Center center point (default is [0, 0, 0]) 5511 # - \a PrimaryRadius default is 1. 5512 # - \a SecondaryAxis default is 1. 5513 # - \a Rotation default is 0. 5514 # - \a StartAngle default is 0. 5515 # - \a EndAngle default is 360. 5516 # - \a MaxAngleStepSizeDegrees default is 4. 5517 # @return a new Geo::OGR::Geometry object. 5519 sub ApproximateArcAngles {
5521 my %
default = ( Center => [0,0,0],
5527 MaxAngleStepSizeDegrees => 4
5529 for my $p (keys %p) {
5530 if (exists $default{$p}) {
5533 carp
"Unknown parameter: '$p'.";
5536 for my $p (keys %
default) {
5539 error(
"Usage: Center => [x,y,z].") unless ref($p{Center}) eq
'ARRAY';
5543 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});
5546 #** @method scalar Area() 5548 # @note a.k.a. GetArea 5549 # @return the area of the polygon or multipolygon 5554 #** @method scalar As(%params) 5556 # Export the geometry into a known format. 5558 # @param params Named parameters: 5559 # - \a Format One of 5560 # - \a WKT Well Known Text. 5561 # - <em>ISO WKT</em> 5562 # - \a Text Same as WKT. 5563 # - \a WKB Well Known Binary. 5564 # - <em>ISO WKB</em> 5565 # - \a Binary Same as WKB. 5570 # - \a ByteOrder Byte order for binary formats. Default is 'XDR'. 5571 # - \a SRID Spatial reference id for HEXEWKB. 5572 # - \a Options GML generation options. 5573 # - \a AltitudeMode For KML. 5575 # @return the geometry in a given format. 5579 my $p = named_parameters(\@_, Format => undef, ByteOrder =>
'XDR', SRID => undef, Options => undef, AltitudeMode => undef);
5580 my $f = $p->{format};
5581 if ($f =~ /text/i) {
5582 return $self->AsText;
5583 } elsif ($f =~ /wkt/i) {
5585 return $self->ExportToIsoWkt;
5587 return $self->AsText;
5589 } elsif ($f =~ /binary/i) {
5590 return $self->ExportToWkb($p->{byteorder});
5591 } elsif ($f =~ /wkb/i) {
5593 $p->{byteorder} = s2i(byte_order => $p->{byteorder});
5594 return $self->ExportToIsoWkb($p->{byteorder});
5595 } elsif ($f =~ /ewkb/i) {
5596 return $self->AsHEXEWKB($p->{srid});
5597 } elsif ($f =~ /hex/i) {
5598 return $self->AsHEXWKB;
5600 return $self->ExportToWkb($p->{byteorder});
5602 } elsif ($f =~ /gml/i) {
5603 return $self->ExportToGML($p->{options});
5604 } elsif ($f =~ /kml/i) {
5605 return $self->ExportToKML($p->{altitudemode});
5606 } elsif ($f =~ /json/i) {
5607 return $self->AsJSON;
5609 error(1, $f, map {$_=>1} qw/Text WKT ISO_WKT ISO_WKB HEX_WKB HEX_EWKB Binary GML KML JSON/);
5613 #** @method scalar AsBinary() 5615 # Export the geometry into WKB. 5616 # @sa Geo::OGR::Geometry::As 5617 # @return the geometry as WKB. 5622 #** @method scalar AsText() 5624 # Export the geometry into WKT. 5625 # @sa Geo::OGR::Geometry::As 5626 # @return the geometry as WKT. 5631 #** @method AssignSpatialReference($srs) 5633 # @param srs a Geo::OSR::SpatialReference object 5635 sub AssignSpatialReference {
5638 #** @method Geo::OGR::Geometry Boundary() 5640 # @note a.k.a. GetBoundary 5641 # @return the boundary of this geometry as a geometry 5647 #** @method Geo::OGR::Geometry Buffer($distance, $quadsecs = 30) 5651 # @return a new Geo::OGR::Geometry object 5656 #** @method Geo::OGR::Geometry BuildPolygonFromEdges($BestEffort = 0, $AutoClose = 0, $Tolerance = 0) 5658 # Attempt to create a polygon from a collection of lines or from a multilinestring. 5659 # @param BestEffort For future 5660 # @param AutoClose Assure the first and last points of rings are same. 5661 # @param Tolerance Snap distance. 5662 # @exception Several possibilities, some are reported, some are general errors. 5663 # @return a new Geo::OGR::Geometry object (Polygon) 5665 sub BuildPolygonFromEdges {
5668 #** @method list ByteOrders() 5669 # Package subroutine. 5670 # Same as Geo::OGR::ByteOrders 5673 return @BYTE_ORDER_TYPES;
5676 #** @method Geo::OGR::Geometry Centroid() 5678 # @return a new Geo::OGR::Geometry object 5684 #** @method Geo::OGR::Geometry Clone() 5686 # @return a new Geo::OGR::Geometry object 5691 #** @method CloseRings() 5697 #** @method Geo::OGR::Geometry Collect(@geometries) 5699 # Create a geometrycollection from this and possibly other geometries. 5700 # @param geometries [optional] More geometries to add to the collection. 5701 # @return a new Geo::OGR::Geometry object of type geometrycollection. 5706 #** @method scalar Contains($other) 5708 # @param other a Geo::OGR::Geometry object 5709 # @return true if this geometry contains the other geometry, false otherwise 5714 #** @method Geo::OGR::Geometry ConvexHull() 5716 # @return a new Geo::OGR::Geometry object 5721 #** @method scalar CoordinateDimension($dimension) 5723 # @param dimension [optional] 5726 sub CoordinateDimension {
5728 SetCoordinateDimension($self, $_[0])
if @_;
5729 GetCoordinateDimension($self)
if defined wantarray;
5732 #** @method scalar Crosses($other) 5734 # @param other a Geo::OGR::Geometry object 5735 # @return true if this geometry crosses the other geometry, false otherwise 5740 #** @method DelaunayTriangulation() 5742 sub DelaunayTriangulation {
5745 #** @method Geo::OGR::Geometry Difference($other) 5747 # @param other a Geo::OGR::Geometry object 5748 # @return a new Geo::OGR::Geometry object 5753 #** @method scalar Disjoint($other) 5755 # @param other a Geo::OGR::Geometry object 5756 # @return true if this geometry is disjoint from the other geometry, false otherwise 5761 #** @method list Dissolve() 5763 # Dissolve a geometrycollection into separate geometries. 5764 # @return a list of new Geo::OGR::Geometry objects cloned from the collection. 5769 my $n = $self->GetGeometryCount;
5771 for my $i (0..$n-1) {
5772 push @c, $self->GetGeometryRef($i)->Clone;
5780 #** @method scalar Distance($other) 5782 # @param other a Geo::OGR::Geometry object 5783 # @return the distance to the other geometry 5788 #** @method Distance3D() 5795 # Clear geometry data, i.e., remove all points, or, for a point, set 5796 # the coordinate dimension as zero. 5801 #** @method scalar Equals($other) 5803 # @note a.k.a. Equal (deprecated) 5804 # @param other a Geo::OGR::Geometry object 5805 # @return true if this geometry is equivalent to the other geometry, false otherwise 5810 #** @method Extent() 5817 #** @method Feature() 5824 #** @method FlattenTo2D() 5830 #** @method Geo::OGR::Geometry ForceTo($type, ref options) 5832 # Attempt to make a geometry of type 'type' out of this geometry. 5833 # @param type target geometry type. One of Geo::OGR::GeometryTypes. 5834 # @param options not used currently. 5835 # @return a new Geo::OGR::Geometry object. 5840 $type = s2i(geometry_type => $type);
5842 $self = Geo::OGR::ForceTo($self, $type, @_);
5844 confess last_error()
if $@;
5848 #** @method Geo::OGR::Geometry ForceToCollection(@geometries) 5850 # Create a geometrycollection from the geometry. 5851 # @param geometries [optional] More geometries to add to the collection. 5852 # @return a new Geo::OGR::Geometry object of type geometrycollection. 5854 sub ForceToCollection {
5862 #** @method Geo::OGR::Geometry ForceToLineString() 5864 # Attempt to create a line string from this geometry. 5865 # @return a new Geo::OGR::Geometry object. 5867 sub ForceToLineString {
5869 return Geo::OGR::ForceToLineString($self);
5872 #** @method Geo::OGR::Geometry ForceToMultiLineString(@linestrings) 5874 # Attempt to create a multilinestring from the geometry, which must be a linestring. 5875 # @param linestrings [optional] More linestrings to add to the collection. 5876 # @return a new Geo::OGR::Geometry object of type multilinestring. 5878 sub ForceToMultiLineString {
5880 $self = Geo::OGR::ForceToMultiLineString($self);
5882 $self->AddGeometry($g);
5887 #** @method Geo::OGR::Geometry ForceToMultiPoint(@points) 5889 # Attempt to create a multipoint from the geometry, which must be a point. 5890 # @param points [optional] More points to add to the collection. 5891 # @return a new Geo::OGR::Geometry object of type multipoint. 5893 sub ForceToMultiPoint {
5895 $self = Geo::OGR::ForceToMultiPoint($self);
5897 $self->AddGeometry($g);
5902 #** @method Geo::OGR::Geometry ForceToMultiPolygon(@polygons) 5904 # Attempt to create a multipolygon from the geometry, which must be a polygon. 5905 # @param polygons [optional] More polygons to add to the collection. 5906 # @return a new Geo::OGR::Geometry object of type multipolygon. 5908 sub ForceToMultiPolygon {
5910 $self = Geo::OGR::ForceToMultiPolygon($self);
5912 $self->AddGeometry($g);
5917 #** @method Geo::OGR::Geometry ForceToPolygon() 5919 # Attempt to create a polygon from this geometry. 5920 # @exception None reported. If this method fails, just a copy is returned. 5921 # @return a new Geo::OGR::Geometry object. 5923 sub ForceToPolygon {
5926 #** @method scalar Geometry($n) 5928 # Return the n:th (note zero-based index) element in this geometry or 5929 # geometry in this collection. 5930 # @note a.k.a. GetGeometryRef 5931 # @param n index to the geometry, which is a part of this geometry 5932 # @return a new Geo::OGR::Geometry object whose data is a part of the 5933 # parent geometry (this geometry is kept alive while the returned 5939 #** @method scalar GeometryCount() 5941 # Return the number of elements in this geometry or geometries in this collection. 5942 # @note a.k.a. GetGeometryCount 5943 # @return an integer 5948 #** @method scalar GeometryType() 5951 # @note The deprecated method GetGeometryType returns the 5952 # type as an integer 5954 # @return the geometry type of this geometry (one of Geo::OGR::GeometryTypes). 5958 return i2s(geometry_type => $self->GetGeometryType);
5961 #** @method list GeometryTypes() 5962 # Package subroutine. 5963 # Same as Geo::OGR::GeometryTypes 5966 return @GEOMETRY_TYPES;
5969 #** @method scalar GetCoordinateDimension() 5971 # @return an integer 5973 sub GetCoordinateDimension {
5976 #** @method GetCurveGeometry() 5978 sub GetCurveGeometry {
5981 #** @method scalar GetDimension() 5983 # @return 0, 1, or 2 5988 #** @method list GetEnvelope() 5990 # @note In scalar context returns a reference to an anonymous array 5991 # containing the envelope. 5992 # @return the envelope ($minx, $maxx, $miny, $maxy) 5997 #** @method list GetEnvelope3D() 5999 # @note In scalar context returns a reference to an anonymous array 6000 # containing the envelope. 6001 # @return the 3-D envelope ($minx, $maxx, $miny, $maxy, $minz, $maxz) 6007 #** @method scalar GetGeometryRef($index) 6009 # @deprecated Use Geo::OGR::Geometry 6011 sub GetGeometryRef {
6012 my ($self, $i) = @_;
6013 my $ref = $self->_GetGeometryRef($i);
6018 #** @method GetLinearGeometry() 6020 sub GetLinearGeometry {
6028 #** @method list GetPoint($index = 0) 6031 # @return (x,y) or a list with more coordinates 6036 my $t = $self->GetGeometryType;
6037 my $has_z = HasZ($t);
6038 my $has_m = HasM($t);
6040 if (!$has_z && !$has_m) {
6041 $point = $self->GetPoint_2D($i);
6042 } elsif ($has_z && !$has_m) {
6043 $point = $self->GetPoint_3D($i);
6044 } elsif (!$has_z && $has_m) {
6045 $point = $self->GetPointZM($i);
6046 @$point = ($point->[0], $point->[1], $point->[3]);
6048 $point = $self->GetPointZM($i);
6050 return wantarray ? @$point : $point;
6053 #** @method scalar GetPointCount() 6055 # @return an integer 6060 #** @method GetPointZM() 6065 #** @method scalar GetPoint_2D($index = 0) 6068 # @return (x,y) or a list with more coordinates 6073 #** @method scalar GetPoint_3D($index = 0) 6076 # @return (x,y) or a list with more coordinates 6081 #** @method Geo::OSR::SpatialReference GetSpatialReference() 6083 # @return a new Geo::OSR::SpatialReference object 6085 sub GetSpatialReference {
6088 #** @method scalar GetX($index = 0) 6096 #** @method scalar GetY($index = 0) 6104 #** @method scalar GetZ($index = 0) 6112 #** @method HasCurveGeometry() 6114 sub HasCurveGeometry {
6117 #** @method Geo::OGR::Geometry Intersection($other) 6119 # @param other a Geo::OGR::Geometry object 6120 # @return a new Geo::OGR::Geometry object 6125 #** @method scalar Intersects($other) 6127 # @note a.k.a. Intersect (deprecated) 6128 # @param other a Geo::OGR::Geometry object 6129 # @return true if this geometry intersects with the other geometry, false otherwise 6139 #** @method scalar IsEmpty() 6141 # Test whether the geometry is empty (has no points, or, for a point, 6142 # has coordinate dimension of zero). 6148 #** @method IsMeasured() 6153 #** @method scalar IsRing() 6155 # Test if the geometry is a ring. Requires GEOS in GDAL. 6161 #** @method scalar IsSimple() 6163 # Test the simplicity of the geometry (OGC sense). Requires GEOS in GDAL. 6169 #** @method scalar IsValid() 6171 # Test the validity of the geometry (OGC sense). Requires GEOS in GDAL. 6177 #** @method scalar Length() 6179 # @return the length of the linestring 6184 #** @method MakeValid() 6189 #** @method Move($dx, $dy, $dz) 6191 # Move every point of the object as defined by the parameters. 6194 # @param dz [optional] 6199 #** @method scalar Overlaps($other) 6201 # @param other a Geo::OGR::Geometry object 6202 # @return true if this geometry overlaps the other geometry, false otherwise 6207 #** @method list Point($index, $x, $y, $z) 6209 # Get or set the point 6210 # @param index The index of the point. Optional (ignored if given) for 6211 # Point and Point25D geometries. 6212 # @param x [optional] 6213 # @param y [optional] 6214 # @param z [optional] 6221 my $t = $self->GetGeometryType;
6223 if (Flatten($t) == $Geo::OGR::wkbPoint) {
6224 my $has_z = HasZ($t);
6225 my $has_m = HasM($t);
6226 if (!$has_z && !$has_m) {
6229 } elsif ($has_z || $has_m) {
6237 $i = shift unless defined $i;
6238 $self->SetPoint($i, @_);
6240 return unless defined wantarray;
6241 my $point = $self->GetPoint;
6242 return wantarray ? @$point : $point;
6245 #** @method PointOnSurface() 6247 sub PointOnSurface {
6250 #** @method array reference Points(arrayref points) 6252 # Get or set the points of the geometry. The points (vertices) are 6253 # stored in obvious lists of lists. When setting, the geometry is 6254 # first emptied. The method uses internally either AddPoint_2D or 6255 # AddPoint_3D depending on the coordinate dimension of the input data. 6257 # @note The same structure may represent different geometries 6258 # depending on the actual geometry type of the object. 6260 # @param points [optional] A reference to an array. A point is a reference to an 6261 # array of numbers, a linestring or a ring is a reference to an array of points, 6262 # a polygon is a reference to an array of rings, etc. 6264 # @return A reference to an array. 6268 my $t = $self->GetGeometryType;
6269 my $has_z = HasZ($t);
6270 my $has_m = HasM($t);
6272 $postfix .=
'Z' if HasZ($t);
6273 $postfix .=
'M' if HasM($t);
6274 $t = i2s(geometry_type => Flatten($t));
6278 if ($t eq
'Unknown' or $t eq
'None' or $t eq
'GeometryCollection') {
6279 error(
"Can't set points of a geometry of type '$t'.");
6280 } elsif ($t eq
'Point') {
6281 # support both "Point" as a list of one point and one point 6282 if (ref($points->[0])) {
6283 $self->AddPoint(@{$points->[0]});
6285 $self->AddPoint(@$points);
6287 } elsif ($t eq
'LineString' or $t eq
'LinearRing' or $t eq
'CircularString') {
6288 for my $p (@$points) {
6289 $self->AddPoint(@$p);
6291 } elsif ($t eq
'Polygon') {
6292 for my $r (@$points) {
6294 $ring->
Set3D(1)
if $has_z;
6295 $ring->SetMeasured(1)
if $has_m;
6297 $self->AddGeometryDirectly($ring);
6299 } elsif ($t eq
'MultiPoint') {
6300 for my $p (@$points) {
6303 $self->AddGeometryDirectly($point);
6305 } elsif ($t eq
'MultiLineString') {
6306 for my $l (@$points) {
6309 $self->AddGeometryDirectly($linestring);
6311 } elsif ($t eq
'MultiPolygon') {
6312 for my $p (@$points) {
6315 $self->AddGeometryDirectly($polygon);
6319 return unless defined wantarray;
6320 $self->_GetPoints();
6323 #** @method Polygonize() 6328 #** @method RemoveGeometry() 6330 sub RemoveGeometry {
6333 #** @method Segmentize($MaxLength) 6335 # Modify the geometry such it has no segment longer than the given length. 6336 # @param MaxLength the given length 6346 #** @method SetCoordinateDimension($dimension) 6350 sub SetCoordinateDimension {
6353 #** @method SetMeasured() 6358 #** @method SetPoint($index, $x, $y, $z) 6360 # Set the data of a point or a line string. Note that the coordinate 6361 # dimension is automatically upgraded to 25D (3) if z is given. 6365 # @param z [optional] 6369 my $t = $self->GetGeometryType;
6370 my $has_z = HasZ($t);
6371 my $has_m = HasM($t);
6372 if (!$has_z && !$has_m) {
6373 $self->SetPoint_2D(@_[0..2]);
6374 } elsif ($has_z && !$has_m) {
6375 $self->SetPoint_3D(@_[0..3]);
6376 } elsif (!$has_z && $has_m) {
6377 $self->SetPointM(@_[0..3]);
6379 $self->SetPointZM(@_[0..4]);
6383 #** @method SetPointM() 6388 #** @method SetPointZM() 6393 #** @method SetPoint_2D($index, $x, $y) 6402 #** @method SetPoint_3D($index, $x, $y, $z) 6404 # Set the data of a point or a line string. Note that the coordinate 6405 # dimension is automatically upgraded to 25D (3). 6414 #** @method Geo::OGR::Geometry Simplify($Tolerance) 6416 # Simplify the geometry. 6417 # @param Tolerance the length tolerance for the simplification 6419 # @return a new Geo::OSR::Geometry object 6424 #** @method SimplifyPreserveTopology() 6426 sub SimplifyPreserveTopology {
6429 #** @method SwapXY() 6434 #** @method Geo::OGR::Geometry SymDifference($other) 6436 # Compute symmetric difference. 6437 # @note a.k.a. SymmetricDifference 6438 # @param other a Geo::OGR::Geometry object 6439 # @return a new Geo::OGR::Geometry object 6445 #** @method scalar Touches($other) 6447 # @param other a Geo::OGR::Geometry object 6448 # @return true if this geometry touches the other geometry, false otherwise 6453 #** @method Transform($trans) 6455 # @param trans a Geo::OSR::CoordinateTransformation object 6460 #** @method TransformTo($srs) 6462 # @param srs a Geo::OSR::SpatialReference object 6467 #** @method Geo::OGR::Geometry Union($other) 6469 # @param other a Geo::OGR::Geometry object 6470 # @return a new Geo::OGR::Geometry object 6475 #** @method Geo::OGR::Geometry UnionCascaded() 6477 # @return a new Geo::OGR::Geometry object 6488 #** @method scalar Within($other) 6490 # @param other a Geo::OGR::Geometry object 6491 # @return true if this geometry is within the other geometry, false otherwise 6496 #** @method scalar WkbSize() 6498 # @return an integer 6503 #** @method Geo::OGR::Geometry new(%params) 6505 # @param %params A named parameter, one of: 6506 # - \a GeometryType one the supported geometry types, see Geo::OGR::GeometryTypes. 6507 # - \a WKT a well known text string, which defines a geometry. 6508 # - \a WKB a well known binary string, which defines a geometry. 6509 # - \a HEXWKB WKB in hexadecimal. 6510 # - \a HEXEWKB PostGIS extended WKB. 6511 # - \a GML geometry written in Geographic Markup Language. 6512 # - \a GeoJSON geometry written in GeoJSON (JavaScript Object Notation for Geographic data). 6513 # - \a arc a reference to a list of values defining an arc: [CenterX, 6514 # CenterY, CenterZ, PrimaryRadius, SecondaryRadius, Rotation, 6515 # StartAngle, EndAngle, MaxAngleStepSizeDegrees] (see also Geo::OGR::Geometry::ApproximateArcAngles) 6516 # - \a Points An anonymous array as in method 6517 # Geo::OGR::Geometry::Points; Note: requires also GeometryType 6520 # @return a new Geo::OGR::Geometry object. 6525 if (@_ == 1 and ref($_[0]) eq
'HASH') {
6527 } elsif (@_ % 2 == 0) {
6530 ($param{GeometryType}) = @_;
6532 my $type = $param{GeometryType}
6533 my $srs = $param{SRS}
6534 my $wkt = $param{WKT}
6535 my $wkb = $param{WKB}
6536 my $hex = $param{HEXEWKB}
6539 # EWKB contains SRID 6540 $srid = substr($hex, 10, 8);
6541 substr($hex, 10, 8) =
'';
6543 $hex = $param{HEXWKB}
6547 for (my $i = 0; $i < length($hex); $i+=2) {
6548 $wkb .= chr(hex(substr($hex,$i,2)));
6551 my $gml = $param{GML}
6552 my $json = $param{GeoJSON}
6553 my $points = $param{Points}
6554 my $arc = $param{Arc}
6557 $self = Geo::OGRc::CreateGeometryFromWkt($wkt, $srs);
6558 } elsif (defined $wkb) {
6559 $self = Geo::OGRc::CreateGeometryFromWkb($wkb, $srs);
6560 } elsif (defined $gml) {
6561 $self = Geo::OGRc::CreateGeometryFromGML($gml);
6562 } elsif (defined $json) {
6563 $self = Geo::OGRc::CreateGeometryFromJson($json);
6564 } elsif (defined $type) {
6565 $type = s2i(geometry_type => $type);
6566 $self = Geo::OGRc::new_Geometry($type); # flattens the type
6567 $self->Set3D(1)
if HasZ($type);
6568 $self->SetMeasured(1)
if HasM($type);
6569 } elsif (defined $arc) {
6570 $self = Geo::OGRc::ApproximateArcAngles(@$arc);
6572 error(1, undef, map {$_=>1} qw/GeometryType WKT WKB HEXEWKB HEXWKB GML GeoJSON Arc/);
6574 bless $self, $pkg
if defined $self;
6575 $self->Points($points)
if $points;
6579 #** @class Geo::OGR::Layer 6580 # @brief A collection of similar features. 6581 # @details A layer object is typically obtained with a data source object. A 6582 # layer has a data model (a schema), which is maintained in a 6583 # definition object, and a set of features, which contain data 6584 # according to the data model. The schema is typically set when the 6585 # layer is created or opened, but it may be altered somewhat with 6586 # methods Geo::OGR::Layer::CreateField, 6587 # Geo::OGR::Layer::AlterFieldDefn, and 6588 # Geo::OGR::Layer::DeleteField. Features and/or their data can be 6589 # read, inserted and deleted. Reading can be filtered. Layers can be 6590 # compared to each other with methods Clip, Erase, Identity, 6591 # Intersection, SymDifference, Union, and Update. 6592 # A layer may have metadata OLMD_FID64 => 'YES' if it holds features 6593 # with 64 bit FIDs. The metadata of a layer can be obtained with 6594 # GetMetadata method. 6596 package Geo::OGR::Layer;
6600 #** @method AlterFieldDefn($name, %params) 6602 # @param field the name of the field to be altered. 6603 # @param params as in Geo::OGR::FieldDefn::new. Width and 6604 # Precision should be both or neither. 6605 # @note Only non-spatial fields can be altered. 6606 # @note Also the deprecated form AlterFieldDefn($field, 6607 # Geo::OGR::FieldDefn $Defn, $Flags) works. 6609 sub AlterFieldDefn {
6611 my $index = $self->GetLayerDefn->GetFieldIndex(shift
6612 my $param = @_ % 2 == 0 ? {@_} : shift;
6613 if (blessed($param) and $param->isa(
'Geo::OGR::FieldDefn')) {
6614 _AlterFieldDefn($self, $index, @_);
6618 $flags |= 1
if exists $param->{Name};
6619 $flags |= 2
if exists $param->{Type};
6620 $flags |= 4
if exists $param->{Width} or exists $param->{Precision};
6621 $flags |= 8
if exists $param->{Nullable};
6622 $flags |= 16
if exists $param->{Default};
6623 _AlterFieldDefn($self, $index, $definition, $flags);
6627 #** @method list Capabilities() 6629 # Both a package subroutine and an object method. 6630 # @return a list of capabilities. The object method returns a list of 6631 # the capabilities the layer has. The package subroutine returns a list of 6632 # all potential capabilities a layer may have. These are currently: 6633 # AlterFieldDefn, CreateField, CreateGeomField, CurveGeometries, DeleteFeature, DeleteField, FastFeatureCount, FastGetExtent, FastSetNextByIndex, FastSpatialFilter, IgnoreFields, MeasuredGeometries, RandomRead, RandomWrite, ReorderFields, SequentialWrite, StringsAsUTF8, and Transactions. 6637 # @cap = Geo::OGR::Layer::Capabilities(); # the package subroutine 6638 # @cap = $layer->Capabilities(); # the object method 6642 return @CAPABILITIES
if @_ == 0;
6645 for my $cap (@CAPABILITIES) {
6646 push @cap, $cap
if _TestCapability($self, $CAPABILITIES{$cap});
6651 #** @method Clip(Geo::OGR::Layer method, Geo::OGR::Layer result, hashref options, coderef callback, $callback_data) 6653 # Clip off areas that are not covered by the method layer. The schema 6654 # of the result layer can be set before calling this method, or is 6655 # initialized to to contain all fields from 6656 # this and method layer. 6657 # @param method method layer. 6658 # @param result result layer. 6659 # @param options a reference to an options hash. 6660 # @param callback [optional] a reference to a subroutine, which will 6661 # be called with parameters (number progress, string msg, callback_data) 6662 # @param callback_data [optional] 6667 #** @method CommitTransaction() 6670 sub CommitTransaction {
6673 #** @method CreateFeature() 6678 #** @method CreateField(%params) 6681 # @param params as in Geo::OGR::FieldDefn::new or 6682 # Geo::OGR::GeomFieldDefn::new, plus ApproxOK (whose default is true). 6686 my %defaults = ( ApproxOK => 1,
6690 } elsif (ref($_[0]) eq
'HASH') {
6692 } elsif (@_ % 2 == 0) {
6695 ($params{Defn}) = @_;
6697 for my $k (keys %defaults) {
6700 if (blessed($params{Defn}) and $params{Defn}->isa(
'Geo::OGR::FieldDefn')) {
6701 $self->_CreateField($params{Defn}, $params{ApproxOK});
6702 } elsif (blessed($_[0]) and $params{Defn}->isa(
'Geo::OGR::GeomFieldDefn')) {
6703 $self->CreateGeomField($params{Defn}, $params{ApproxOK});
6705 # if Name and Type are missing, assume Name => Type 6706 if (!(exists $params{Name} && exists $params{Type})) {
6707 for my $key (sort keys %params) {
6708 if (s_exists(field_type => $params{$key}) ||
6709 s_exists(geometry_type => $params{$key}))
6711 $params{Name} = $key;
6712 $params{Type} = $params{$key};
6713 delete $params{$key};
6718 my $a = $params{ApproxOK};
6719 delete $params{ApproxOK};
6720 if (exists $params{GeometryType}) {
6721 $params{Type} = $params{GeometryType};
6722 delete $params{GeometryType};
6724 if (s_exists(field_type => $params{Type})) {
6726 _CreateField($self, $fd, $a);
6727 } elsif (s_exists(geometry_type => $params{Type})) {
6729 CreateGeomField($self, $fd, $a);
6730 } elsif ($params{Type} ) {
6731 error(
"Invalid field type: $params{Type}.")
6732 } elsif ($params{Name} ) {
6733 error(
"Missing type for field: $params{Name}.")
6735 error(
"Missing name and type for a field.")
6740 #** @method DataSource() 6745 #** @method Dataset() 6752 #** @method DeleteFeature($fid) 6754 # @param fid feature id 6759 #** @method DeleteField($field) 6761 # Delete an existing field from a layer. 6762 # @param field name (or index) of the field which is deleted 6763 # @note Only non-spatial fields can be deleted. 6766 my ($self, $field) = @_;
6767 my $index = $self->GetLayerDefn->GetFieldIndex($field
6768 _DeleteField($self, $index);
6771 #** @method Erase(Geo::OGR::Layer method, Geo::OGR::Layer result, hashref options, coderef callback, $callback_data) 6773 # The result layer contains features whose geometries represent areas 6774 # that are in the input layer but not in the method layer. The 6775 # features in the result layer have attributes from the input 6776 # layer. The schema of the result layer can be set by the user or, if 6777 # it is empty, is initialized to contain all fields in the input 6779 # @param method method layer. 6780 # @param result result layer. 6781 # @param options a reference to an options hash. 6782 # @param callback [optional] a reference to a subroutine, which will 6783 # be called with parameters (number progress, string msg, callback_data) 6784 # @param callback_data [optional] 6789 #** @method Geo::OGR::Feature Feature($f) 6792 # @param f [optional] feature id, a feature, a row, or a tuple 6794 # @note If the argument feature has a null FID (FID not set) the 6795 # feature is inserted into the layer as a new feature. If the FID is 6796 # non null, then the feature replaces the feature in the layer with 6799 # @return a new Geo::OGR::Feature object that represents the feature 6805 return $self->GetFeature($x) unless $x && ref $x;
6806 # Insert or Set depending on the FID 6808 if (ref $x eq
'ARRAY') {
6809 # FID is the first item in the array 6811 } elsif (ref $x eq
'HASH') {
6818 if (!defined $fid || $fid < 0) {
6819 $self->InsertFeature($x);
6821 $self->SetFeature($x);
6825 #** @method scalar FeatureCount($force = 1) 6827 # A.k.a GetFeatureCount 6834 #** @method Features() 6838 $self->ResetReading;
6840 return $self->GetNextFeature;
6844 #** @method ForFeatures($code, $in_place) 6846 # @note experimental, the syntax may change 6848 # Call code for all features. This is a simple wrapper for 6849 # ResetReading and while(GetNextFeature). 6853 # $layer->ForFeatures(sub {my $f = shift; $self->DeleteFeature($f->FID)}); # empties the layer 6856 # @param code a reference to a subroutine, which is called with each 6857 # feature as an argument 6858 # @param in_place if set to true, the feature is stored back to the 6864 my $in_place = shift;
6865 $self->ResetReading;
6866 while (my $f = $self->GetNextFeature) {
6869 $self->SetFeature($f)
if $in_place;
6873 #** @method ForGeometries($code, $in_place) 6875 # @note experimental, the syntax may change 6877 # Call code for all geometries. This is a simple wrapper for 6878 # ResetReading and while(GetNextFeature). 6883 # $layer->ForGeometries(sub {my $g = shift; $area += $g->Area}); # computes the total area 6886 # @param code a reference to a subroutine, which is called with each 6887 # geometry as an argument 6888 # @param in_place if set to true, the geometry is stored back to the 6894 my $in_place = shift;
6895 $self->ResetReading;
6896 while (my $f = $self->GetNextFeature) {
6897 my $g = $f->Geometry();
6901 $self->SetFeature($f);
6906 #** @method Geometries() 6910 $self->ResetReading;
6912 my $f = $self->GetNextFeature;
6914 return $f->Geometry;
6918 #** @method scalar GeometryType($field) 6920 # @param field the name or index of the spatial field. 6921 # @return the geometry type of the spatial field. 6925 my $d = $self->GetDefn;
6926 my $field = $d->GetGeomFieldIndex(shift
6927 my $fd = $d->_GetGeomFieldDefn($field);
6928 return $fd->Type
if $fd;
6931 #** @method Geo::OGR::DataSource GetDataSource() 6933 # @return the data source object to which this layer object belongs to. 6940 #** @method Geo::OGR::FeatureDefn GetDefn() 6942 # A.k.a GetLayerDefn. 6943 # @return a Geo::OGR::FeatureDefn object. 6947 my $defn = $self->GetLayerDefn;
6951 #** @method list GetExtent($force = 1) 6953 # @param force compute the extent even if it is expensive 6954 # @note In scalar context returns a reference to an anonymous array 6955 # containing the extent. 6956 # @return the extent ($minx, $maxx, $miny, $maxy) 6958 # @return the extent = ($minx, $maxx, $miny, $maxy) as a listref 6963 #** @method scalar GetFIDColumn() 6965 # @return the name of the underlying database column being used as the 6966 # FID column, or "" if not supported. 6971 #** @method Geo::OGR::Feature GetFeature($fid) 6973 # @param fid feature id 6974 # @return a new Geo::OGR::Feature object that represents the feature in the layer. 6977 my ($self, $fid) = @_;
6979 my $f = $self->_GetFeature($fid);
6980 error(2,
"FID=$fid",
'"Feature') unless ref $f eq
'Geo::OGR::Feature';
6984 #** @method GetFeatureCount() 6986 sub GetFeatureCount {
6989 #** @method scalar GetFeaturesRead() 6993 sub GetFeaturesRead {
6996 #** @method scalar GetFieldDefn($name) 6998 # Get the definition of a field. 6999 # @param name the name of the field. 7000 # @return a Geo::OGR::FieldDefn object. 7004 my $d = $self->GetDefn;
7005 my $field = $d->GetFieldIndex(shift
7006 return $d->_GetFieldDefn($field);
7009 #** @method list GetFieldNames() 7011 # @return a list of the names of the fields in this layer. The 7012 # non-geometry field names are first in the list and then the geometry 7017 my $d = $self->GetDefn;
7019 for (my $i = 0; $i < $d->GetFieldCount; $i++) {
7020 push @ret, $d->GetFieldDefn($i)->Name();
7022 for (my $i = 0; $i < $d->GetGeomFieldCount; $i++) {
7023 push @ret, $d->GetGeomFieldDefn($i)->Name();
7028 #** @method scalar GetGeomFieldDefn($name) 7030 # Get the definition of a spatial field. 7031 # @param name the name of the spatial field. 7032 # @return a Geo::OGR::GeomFieldDefn object. 7034 sub GetGeomFieldDefn {
7036 my $d = $self->GetDefn;
7037 my $field = $d->GetGeomFieldIndex(shift
7038 return $d->_GetGeomFieldDefn($field);
7041 #** @method scalar GetName() 7043 # @return the name of the layer. 7048 #** @method Geo::OGR::Feature GetNextFeature() 7050 # @return iteratively Geo::OGR::Feature objects from the layer. The 7051 # iteration obeys the spatial and the attribute filter. 7053 sub GetNextFeature {
7056 #** @method hash reference GetSchema() 7058 # @brief Get the schema of this layer. 7059 # @note The schema of a layer cannot be set with this method. If you 7060 # have a Geo::OGR::FeatureDefn object before creating the layer, use 7061 # its schema in the Geo::OGR::CreateLayer method. 7062 # @return the schema of this layer, as in Geo::OGR::FeatureDefn::Schema. 7066 carp
"Schema of a layer should not be set directly." if @_;
7067 if (@_ and @_ % 2 == 0) {
7069 if ($schema{Fields}) {
7070 for my $field (@{$schema{Fields}}) {
7071 $self->CreateField($field);
7075 return $self->GetDefn->Schema;
7078 #** @method Geo::OGR::Geometry GetSpatialFilter() 7080 # @return a new Geo::OGR::Geometry object 7082 sub GetSpatialFilter {
7085 #** @method GetStyleTable() 7090 #** @method Identity(Geo::OGR::Layer method, Geo::OGR::Layer result, hashref options, coderef callback, $callback_data) 7092 # The result layer contains features whose geometries represent areas 7093 # that are in the input layer. The features in the result layer have 7094 # attributes from both input and method layers. The schema of the 7095 # result layer can be set by the user or, if it is empty, is 7096 # initialized to contain all fields in input and method layers. 7097 # @param method method layer. 7098 # @param result result layer. 7099 # @param options a reference to an options hash. 7100 # @param callback [optional] a reference to a subroutine, which will 7101 # be called with parameters (number progress, string msg, callback_data) 7102 # @param callback_data [optional] 7107 #** @method InsertFeature($feature) 7109 # Creates a new feature which has the schema of the layer and 7110 # initializes it with data from the argument. Then inserts the feature 7111 # into the layer (using CreateFeature). Uses Geo::OGR::Feature::Row or 7112 # Geo::OGR::Feature::Tuple. 7113 # @param feature a Geo::OGR::Feature object or reference to feature 7114 # data in a hash (as in Geo::OGR::Feature::Row) or in an array (as in 7115 # Geo::OGR::Feature::Tuple) 7116 # @return the new feature. 7120 my $feature = shift;
7121 error(
"Usage: \$feature->InsertFeature(reference to a hash or array).") unless ref($feature);
7123 $self->CreateFeature($new);
7124 return unless defined wantarray;
7128 #** @method Intersection(Geo::OGR::Layer method, Geo::OGR::Layer result, hashref options, coderef callback, $callback_data) 7130 # The result layer contains features whose geometries represent areas 7131 # that are common between features in the input layer and in the 7132 # method layer. The schema of the result layer can be set before 7133 # calling this method, or is initialized to contain all fields from 7134 # this and method layer. 7135 # @param method method layer. 7136 # @param result result layer. 7137 # @param options a reference to an options hash. 7138 # @param callback [optional] a reference to a subroutine, which will 7139 # be called with parameters (number progress, string msg, callback_data) 7140 # @param callback_data [optional] 7145 #** @method ReorderField() 7150 #** @method ReorderFields() 7155 #** @method ResetReading() 7157 # Initialize the layer object for iterative reading. 7162 #** @method RollbackTransaction() 7165 sub RollbackTransaction {
7168 #** @method hash reference Row(%row) 7170 # Get and/or set the data of a feature that has the supplied feature 7171 # id (the next feature obtained with GetNextFeature is used if feature 7172 # id is not given). Calls Geo::OGR::Feature::Row. 7173 # @param row [optional] feature data 7174 # @return a reference to feature data in a hash 7178 my $update = @_ > 0;
7180 my $feature = defined $row{FID} ? $self->GetFeature($row{FID}) : $self->GetNextFeature;
7181 return unless $feature;
7183 if (defined wantarray) {
7184 $ret = $feature->Row(@_);
7188 $self->SetFeature($feature)
if $update;
7189 return unless defined wantarray;
7193 #** @method SetAttributeFilter($filter_string) 7195 # Set or clear the attribute filter. 7196 # @param filter_string a SQL WHERE clause or undef to clear the 7199 sub SetAttributeFilter {
7202 #** @method SetFeature($feature) 7204 # @note The feature should have the same schema as the layer. 7206 # Replaces a feature in the layer based on the given feature's 7207 # id. Requires RandomWrite capability. 7208 # @param feature a Geo::OGR::Feature object 7213 #** @method SetIgnoredFields(@fields) 7215 # @param fields a list of field names 7217 sub SetIgnoredFields {
7220 #** @method SetNextByIndex($new_index) 7222 # @param new_index the index to which set the read cursor in the 7225 sub SetNextByIndex {
7228 #** @method SetSpatialFilter($filter) 7230 # @param filter [optional] a Geo::OGR::Geometry object. If not given, 7231 # removes the filter if there is one. 7233 sub SetSpatialFilter {
7236 #** @method SetSpatialFilterRect($minx, $miny, $maxx, $maxy) 7243 sub SetSpatialFilterRect {
7246 #** @method SetStyleTable() 7251 #** @method Geo::OGR::Geometry SpatialFilter(@filter) 7253 # @param filter [optional] a Geo::OGR::Geometry object or a string. An 7254 # undefined value removes the filter if there is one. 7255 # @return a new Geo::OGR::Geometry object 7256 # @param filter [optional] a rectangle ($minx, $miny, $maxx, $maxy). 7257 # @return a new Geo::OGR::Geometry object 7261 $self->SetSpatialFilter($_[0])
if @_ == 1;
7262 $self->SetSpatialFilterRect(@_)
if @_ == 4;
7263 return unless defined wantarray;
7264 $self->GetSpatialFilter;
7267 #** @method Geo::OSR::SpatialReference SpatialReference($name, Geo::OSR::SpatialReference sr) 7269 # @note A.k.a GetSpatialRef. 7270 # Get or set the projection of a spatial field of this layer. Gets or 7271 # sets the projection of the first field if no field name is given. 7272 # @param name [optional] a name of a spatial field in this layer. 7273 # @param sr [optional] a Geo::OSR::SpatialReference object, 7274 # which replaces the existing projection. 7275 # @return a Geo::OSR::SpatialReference object, which represents the 7276 # projection in the given spatial field. 7278 sub SpatialReference {
7280 my $d = $self->GetDefn;
7281 my $field = @_ == 2 ? $d->GetGeomFieldIndex(shift
7283 my $d2 = $d->_GetGeomFieldDefn($field);
7284 $d2->SpatialReference($sr)
if defined $sr;
7285 return $d2->SpatialReference()
if defined wantarray;
7288 #** @method StartTransaction() 7291 sub StartTransaction {
7294 #** @method SymDifference(Geo::OGR::Layer method, Geo::OGR::Layer result, hashref options, coderef callback, $callback_data) 7296 # The result layer contains features whose geometries represent areas 7297 # that are in either in the input layer or in the method layer but not 7298 # in both. The features in the result layer have attributes from both 7299 # input and method layers. For features which represent areas that are 7300 # only in the input or in the method layer the respective attributes 7301 # have undefined values. The schema of the result layer can be set by 7302 # the user or, if it is empty, is initialized to contain all fields in 7303 # the input and method layers. 7304 # @param method method layer. 7305 # @param result result layer. 7306 # @param options a reference to an options hash. 7307 # @param callback [optional] a reference to a subroutine, which will 7308 # be called with parameters (number progress, string msg, callback_data) 7309 # @param callback_data [optional] 7314 #** @method SyncToDisk() 7320 #** @method scalar TestCapability($cap) 7322 # @param cap A capability string. 7323 # @return a boolean value indicating whether the layer has the 7324 # specified capability. 7326 sub TestCapability {
7327 my($self, $cap) = @_;
7328 return _TestCapability($self, $CAPABILITIES{$cap});
7331 #** @method list Tuple(@tuple) 7333 # Get and/set the data of a feature that has the supplied feature id 7334 # (the next feature obtained with GetNextFeature is used if feature id 7335 # is not given). The expected data in the tuple is: ([feature id,] 7336 # non-spatial fields, spatial fields). Calls Geo::OGR::Feature::Tuple. 7337 # @param tuple [optional] feature data 7338 # @note The schema of the tuple needs to be the same as that of the 7340 # @return a reference to feature data in an array 7345 my $feature = defined $FID ? $self->GetFeature($FID) : $self->GetNextFeature;
7346 return unless $feature;
7348 unshift @_, $feature->GetFID
if $set;
7350 if (defined wantarray) {
7351 @ret = $feature->Tuple(@_);
7353 $feature->Tuple(@_);
7355 $self->SetFeature($feature)
if $set;
7356 return unless defined wantarray;
7360 #** @method Union(Geo::OGR::Layer method, Geo::OGR::Layer result, hashref options, coderef callback, $callback_data) 7362 # The result layer contains features whose geometries represent areas 7363 # that are in either in the input layer or in the method layer. The 7364 # schema of the result layer can be set before calling this method, or 7365 # is initialized to contain all fields from this and method layer. 7366 # @param method method layer. 7367 # @param result result layer. 7368 # @param options a reference to an options hash. 7369 # @param callback [optional] a reference to a subroutine, which will 7370 # be called with parameters (number progress, string msg, callback_data) 7371 # @param callback_data [optional] 7376 #** @method Update(Geo::OGR::Layer method, Geo::OGR::Layer result, hashref options, coderef callback, $callback_data) 7378 # The result layer contains features whose geometries represent areas 7379 # that are either in the input layer or in the method layer. The 7380 # features in the result layer have areas of the features of the 7381 # method layer or those ares of the features of the input layer that 7382 # are not covered by the method layer. The features of the result 7383 # layer get their attributes from the input layer. The schema of the 7384 # result layer can be set by the user or, if it is empty, is 7385 # initialized to contain all fields in the input layer. 7386 # @param method method layer. 7387 # @param result result layer. 7388 # @param options a reference to an options hash. 7389 # @param callback [optional] a reference to a subroutine, which will 7390 # be called with parameters (number progress, string msg, callback_data) 7391 # @param callback_data [optional] 7396 #** @class Geo::OGR::StyleTable 7398 package Geo::OGR::StyleTable;
7402 #** @method AddStyle() 7412 #** @method GetLastStyleName() 7414 sub GetLastStyleName {
7417 #** @method GetNextStyle() 7422 #** @method LoadStyleTable() 7424 sub LoadStyleTable {
7427 #** @method ResetStyleStringReading() 7429 sub ResetStyleStringReading {
7432 #** @method SaveStyleTable() 7434 sub SaveStyleTable {
7441 my $self = Geo::OGRc::new_StyleTable(@_);
7442 bless $self, $pkg
if defined($self);
7446 # @brief Base class for projection related classes. 7451 #** @method list AngularUnits() 7452 # Package subroutine. 7453 # @return list of known angular units. 7456 return keys %ANGULAR_UNITS;
7459 #** @method CreateCoordinateTransformation() 7461 sub CreateCoordinateTransformation {
7464 #** @method list Datums() 7465 # Package subroutine. 7466 # @return list of known datums. 7469 return keys %DATUMS;
7472 #** @method GetPROJVersionMajor() 7474 sub GetPROJVersionMajor {
7477 #** @method GetPROJVersionMinor() 7479 sub GetPROJVersionMinor {
7482 #** @method scalar GetUserInputAsWKT($name) 7483 # Package subroutine. 7484 # @param name the user input 7485 # @return a WKT string. 7487 sub GetUserInputAsWKT {
7490 #** @method scalar GetWellKnownGeogCSAsWKT($name) 7491 # Package subroutine. 7492 # @brief Get well known geographic coordinate system as WKT 7493 # @param name a well known name 7494 # @return a WKT string. 7496 sub GetWellKnownGeogCSAsWKT {
7499 #** @method list LinearUnits() 7500 # Package subroutine. 7501 # @return list of known linear units. 7504 return keys %LINEAR_UNITS;
7507 #** @method OAMS_AUTHORITY_COMPLIANT() 7509 sub OAMS_AUTHORITY_COMPLIANT {
7512 #** @method OAMS_CUSTOM() 7517 #** @method OAMS_TRADITIONAL_GIS_ORDER() 7519 sub OAMS_TRADITIONAL_GIS_ORDER {
7522 #** @method OAO_Down() 7527 #** @method OAO_East() 7532 #** @method OAO_North() 7537 #** @method OAO_Other() 7542 #** @method OAO_South() 7547 #** @method OAO_Up() 7552 #** @method OAO_West() 7557 #** @method OSRAreaOfUse_east_lon_degree_get() 7559 sub OSRAreaOfUse_east_lon_degree_get {
7562 #** @method OSRAreaOfUse_name_get() 7564 sub OSRAreaOfUse_name_get {
7567 #** @method OSRAreaOfUse_north_lat_degree_get() 7569 sub OSRAreaOfUse_north_lat_degree_get {
7572 #** @method OSRAreaOfUse_south_lat_degree_get() 7574 sub OSRAreaOfUse_south_lat_degree_get {
7577 #** @method OSRAreaOfUse_west_lon_degree_get() 7579 sub OSRAreaOfUse_west_lon_degree_get {
7582 #** @method list Parameters() 7583 # Package subroutine. 7584 # @return list of known projection parameters. 7587 return keys %PARAMETERS;
7590 #** @method list Projections() 7591 # Package subroutine. 7592 # @return list of known projections. 7595 return keys %PROJECTIONS;
7598 #** @method SRS_PM_GREENWICH() 7600 sub SRS_PM_GREENWICH {
7603 #** @method SRS_WGS84_INVFLATTENING() 7605 sub SRS_WGS84_INVFLATTENING {
7608 #** @method SRS_WGS84_SEMIMAJOR() 7610 sub SRS_WGS84_SEMIMAJOR {
7613 #** @method SRS_WKT_WGS84_LAT_LONG() 7615 sub SRS_WKT_WGS84_LAT_LONG {
7618 #** @method SetPROJSearchPath() 7620 sub SetPROJSearchPath {
7623 #** @method SetPROJSearchPaths() 7625 sub SetPROJSearchPaths {
7628 #** @class Geo::OSR::AreaOfUse 7630 package Geo::OSR::AreaOfUse;
7638 my $self = Geo::OSRc::new_AreaOfUse(@_);
7639 bless $self, $pkg
if defined($self);
7642 #** @class Geo::OSR::CoordinateTransformation 7643 # @brief An object for transforming from one projection to another. 7646 package Geo::OSR::CoordinateTransformation;
7650 #** @method array reference TransformPoint($x, $y, $z) 7654 # @param z [optional] 7655 # @return arrayref = [$x, $y, $z] 7657 sub TransformPoint {
7660 #** @method TransformPoints(arrayref points) 7662 # @param points [in/out] a reference to a list of points (line string 7663 # or ring) that is modified in-place. A list of points is: ([x, y, z], 7664 # [x, y, z], ...), where z is optional. Supports also lists of line 7665 # strings and polygons. 7667 sub TransformPoints {
7668 my($self, $points) = @_;
7669 _TransformPoints($self, $points),
return unless ref($points->[0]->[0]);
7670 for my $p (@$points) {
7671 TransformPoints($self, $p);
7675 # This file was automatically generated by SWIG (http://www.swig.org). 7678 # Do not make changes to this file unless you know what you are doing--modify 7679 # the SWIG interface file instead. 7682 #** @method Geo::OSR::CoordinateTransformation new($src, $dst) 7684 # @param src a Geo::OSR::SpatialReference object 7685 # @param dst a Geo::OSR::SpatialReference object 7686 # @return a new Geo::OSR::CoordinateTransformation object 7690 my $self = Geo::OSRc::new_CoordinateTransformation(@_);
7691 bless $self, $pkg
if defined($self);
7694 #** @class Geo::OSR::CoordinateTransformationOptions 7696 package Geo::OSR::CoordinateTransformationOptions;
7700 #** @method SetAreaOfInterest() 7702 sub SetAreaOfInterest {
7705 #** @method SetOperation() 7714 my $self = Geo::OSRc::new_CoordinateTransformationOptions(@_);
7715 bless $self, $pkg
if defined($self);
7718 #** @class Geo::OSR::SpatialReference 7719 # @brief A spatial reference system. 7720 # @details <a href="http://www.gdal.org/classOGRSpatialReference.html">Documentation 7721 # of the underlying C++ class at www.gdal.org</a> 7723 package Geo::OSR::SpatialReference;
7732 #** @method AutoIdentifyEPSG() 7734 # Set EPSG authority info if possible. 7736 sub AutoIdentifyEPSG {
7739 #** @method Geo::OSR::SpatialReference Clone() 7741 # Make a duplicate of this SpatialReference object. 7742 # @return a new Geo::OSR::SpatialReference object 7747 #** @method Geo::OSR::SpatialReference CloneGeogCS() 7749 # Make a duplicate of the GEOGCS node of this SpatialReference object. 7750 # @return a new Geo::OSR::SpatialReference object 7755 #** @method ConvertToOtherProjection() 7757 sub ConvertToOtherProjection {
7760 #** @method CopyGeogCSFrom($rhs) 7762 # @param rhs Geo::OSR::SpatialReference 7764 sub CopyGeogCSFrom {
7767 #** @method EPSGTreatsAsLatLong() 7769 # Returns TRUE if EPSG feels this geographic coordinate system should be treated as having lat/long coordinate ordering. 7771 sub EPSGTreatsAsLatLong {
7774 #** @method EPSGTreatsAsNorthingEasting() 7776 sub EPSGTreatsAsNorthingEasting {
7779 #** @method Export($format) 7781 # Export the spatial reference to a selected format. 7784 # @param format One of the following. The return value is explained 7785 # after the format. Other arguments are explained in parenthesis. 7786 # - WKT (Text): Well Known Text string 7787 # - PrettyWKT: Well Known Text string nicely formatted (simplify) 7788 # - Proj4: PROJ.4 string 7789 # - PCI: a list: ($proj_string, $units, [$parms1, ...]) 7790 # - USGS: a list: ($code, $zone, [$parms1, ...], $datum) 7791 # - GML (XML): GML based string (dialect) 7792 # - MapInfoCS (MICoordSys): MapInfo style co-ordinate system definition 7794 # @note The named parameter syntax also works and is needed is those 7795 # cases when other arguments need or may be given. The format should 7796 # be given using key as, 'to' or 'format'. 7798 # @note ExportTo* and AsText methods also exist but are not documented here. 7800 # @return a scalar or a list depending on the export format 7805 $format = pop
if @_ == 1;
7808 my $simplify = $params{simplify}
7809 my $dialect = $params{dialect}
7811 WKT => sub {
return ExportToWkt($self) },
7812 Text => sub {
return ExportToWkt($self) },
7813 PrettyWKT => sub {
return ExportToPrettyWkt($self, $simplify) },
7814 Proj4 => sub {
return ExportToProj4($self) },
7815 PCI => sub {
return ExportToPCI($self) },
7816 USGS => sub {
return ExportToUSGS($self) },
7817 GML => sub {
return ExportToXML($self, $dialect) },
7818 XML => sub {
return ExportToXML($self, $dialect) },
7819 MICoordSys => sub {
return ExportToMICoordSys() },
7820 MapInfoCS => sub {
return ExportToMICoordSys() },
7822 error(1, $format, \%converters) unless $converters{$format};
7823 return $converters{$format}->();
7826 #** @method scalar GetAngularUnits() 7830 sub GetAngularUnits {
7833 #** @method GetAngularUnitsName() 7835 sub GetAngularUnitsName {
7838 #** @method GetAreaOfUse() 7843 #** @method scalar GetAttrValue($name, $child = 0) 7852 #** @method scalar GetAuthorityCode($target_key) 7857 sub GetAuthorityCode {
7860 #** @method scalar GetAuthorityName($target_key) 7865 sub GetAuthorityName {
7868 #** @method GetAxisMappingStrategy() 7870 sub GetAxisMappingStrategy {
7873 #** @method GetAxisName() 7878 #** @method GetAxisOrientation() 7880 sub GetAxisOrientation {
7883 #** @method GetDataAxisToSRSAxisMapping() 7885 sub GetDataAxisToSRSAxisMapping {
7888 #** @method GetInvFlattening() 7891 sub GetInvFlattening {
7894 #** @method scalar GetLinearUnits() 7898 sub GetLinearUnits {
7901 #** @method scalar GetLinearUnitsName() 7905 sub GetLinearUnitsName {
7908 #** @method GetName() 7913 #** @method scalar GetNormProjParm($name, $default_val = 0.0) 7916 # @param default_val 7919 sub GetNormProjParm {
7922 #** @method scalar GetProjParm($name, $default_val = 0.0) 7925 # @param default_val 7931 #** @method GetSemiMajor() 7937 #** @method GetSemiMinor() 7943 #** @method GetTOWGS84() 7945 # @return array = ($p1, $p2, $p3, $p4, $p5, $p6, $p7) 7950 #** @method GetTargetLinearUnits() 7952 sub GetTargetLinearUnits {
7955 #** @method GetUTMZone() 7957 # Get UTM zone information. 7958 # @return The UTM zone (integer). In scalar context the returned value 7959 # is negative for southern hemisphere zones. In list context returns 7960 # two values ($zone, $north), where $zone is always non-negative and 7961 # $north is true or false. 7965 my $zone = _GetUTMZone($self);
7972 return ($zone, $north);
7978 #** @method ImportFromOzi() 7983 #** @method scalar IsCompound() 7990 #** @method scalar IsGeocentric() 7997 #** @method scalar IsGeographic() 8004 #** @method scalar IsLocal() 8011 #** @method scalar IsProjected() 8018 #** @method scalar IsSame($rs) 8020 # @param rs a Geo::OSR::SpatialReference object 8026 #** @method scalar IsSameGeogCS($rs) 8028 # @param rs a Geo::OSR::SpatialReference object 8034 #** @method scalar IsSameVertCS($rs) 8036 # @param rs a Geo::OSR::SpatialReference object 8042 #** @method scalar IsVertical() 8049 #** @method MorphFromESRI() 8055 #** @method MorphToESRI() 8061 #** @method Set(%params) 8063 # Set a parameter or parameters in the spatial reference object. 8064 # @param params Named parameters. Recognized keys and respective 8065 # values are the following. 8066 # - Authority: authority name (give also TargetKey, Node and Code) 8068 # - Node: partial or complete path to the target node (Node and Value together sets an attribute value) 8069 # - Code: code for value with an authority 8070 # - Value: value to be assigned to a node, a projection parameter or an object 8071 # - AngularUnits: angular units for the geographic coordinate system (give also Value) (one of Geo::OSR::LinearUnits) 8072 # - LinearUnits: linear units for the target node or the object (give also Value and optionally Node) (one of Geo::OSR::LinearUnits) 8073 # - Parameter: projection parameter to set (give also Value and Normalized) (one of Geo::OSR::Parameters) 8074 # - Normalized: set to true to indicate that the Value argument is in "normalized" form 8075 # - Name: a well known name of a geographic coordinate system (e.g. WGS84) 8076 # - GuessFrom: arbitrary text that specifies a projection ("user input") 8077 # - LOCAL_CS: name of a local coordinate system 8078 # - GeocentricCS: name of a geocentric coordinate system 8079 # - VerticalCS: name of a vertical coordinate system (give also Datum and optionally VertDatumType [default is 2005]) 8080 # - Datum: a known (OGC or EPSG) name (or(?) one of Geo::OSR::Datums) 8081 # - 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 8082 # - Parameters: a reference to a list containing the coordinate system or projection parameters 8083 # - Zone: zone for setting up UTM or State Plane coordinate systems (State Plane zone in USGS numbering scheme) 8084 # - North: set false for southern hemisphere 8085 # - NAD83: set false if the NAD27 zone definition should be used instead of NAD83 8086 # - UnitName: to override the legal definition for a zone 8087 # - UnitConversionFactor: to override the legal definition for a zone 8088 # - Spheroid: user visible name 8089 # - HorizontalCS: Horizontal coordinate system name 8090 # - Projection: name of a projection, one of Geo::OSR::Projections (give also optionally Parameters and Variant) 8092 # @note Numerous Set* methods also exist but are not documented here. 8095 my($self, %params) = @_;
8096 if (exists $params{Authority} and exists $params{TargetKey} and exists $params{Node} and exists $params{Code}) {
8097 SetAuthority($self, $params{TargetKey}, $params{Authority}, $params{Code});
8098 } elsif (exists $params{Node} and exists $params{Value}) {
8099 SetAttrValue($self, $params{Node}, $params{Value});
8100 } elsif (exists $params{AngularUnits} and exists $params{Value}) {
8101 SetAngularUnits($self, $params{AngularUnits}, $params{Value});
8102 } elsif (exists $params{LinearUnits} and exists $params{Node} and exists $params{Value}) {
8103 SetTargetLinearUnits($self, $params{Node}, $params{LinearUnits}, $params{Value});
8104 } elsif (exists $params{LinearUnits} and exists $params{Value}) {
8105 SetLinearUnitsAndUpdateParameters($self, $params{LinearUnits}, $params{Value});
8106 } elsif ($params{Parameter} and exists $params{Value}) {
8107 error(1, $params{Parameter}, \%Geo::OSR::PARAMETERS) unless exists $Geo::OSR::PARAMETERS{$params{Parameter}};
8108 $params{Normalized} ?
8109 SetNormProjParm($self, $params{Parameter}, $params{Value}) :
8110 SetProjParm($self, $params{Parameter}, $params{Value});
8111 } elsif (exists $params{Name}) {
8112 SetWellKnownGeogCS($self, $params{Name});
8113 } elsif (exists $params{GuessFrom}) {
8114 SetFromUserInput($self, $params{GuessFrom});
8115 } elsif (exists $params{LOCAL_CS}) {
8116 SetLocalCS($self, $params{LOCAL_CS});
8117 } elsif (exists $params{GeocentricCS}) {
8118 SetGeocCS($self, $params{GeocentricCS});
8119 } elsif (exists $params{VerticalCS} and $params{Datum}) {
8120 my $type = $params{VertDatumType} || 2005;
8121 SetVertCS($self, $params{VerticalCS}, $params{Datum}, $type);
8122 } elsif (exists $params{CoordinateSystem}) {
8123 my @parameters = ();
8124 @parameters = @{$params{Parameters}}
if ref($params{Parameters});
8125 if ($params{CoordinateSystem} eq
'State Plane' and exists $params{Zone}) {
8126 my $NAD83 = exists $params{NAD83} ? $params{NAD83} : 1;
8127 my $name = exists $params{UnitName} ? $params{UnitName} : undef;
8128 my $c = exists $params{UnitConversionFactor} ? $params{UnitConversionFactor} : 0.0;
8129 SetStatePlane($self, $params{Zone}, $NAD83, $name, $c);
8130 } elsif ($params{CoordinateSystem} eq
'UTM' and exists $params{Zone} and exists $params{North}) {
8131 my $north = exists $params{North} ? $params{North} : 1;
8132 SetUTM($self, $params{Zone}, $north);
8133 } elsif ($params{CoordinateSystem} eq
'WGS') {
8134 SetTOWGS84($self, @parameters);
8135 } elsif ($params{CoordinateSystem} and $params{Datum} and $params{Spheroid}) {
8136 SetGeogCS($self, $params{CoordinateSystem}, $params{Datum}, $params{Spheroid}, @parameters);
8137 } elsif ($params{CoordinateSystem} and $params{HorizontalCS} and $params{VerticalCS}) {
8138 SetCompoundCS($self, $params{CoordinateSystem}, $params{HorizontalCS}, $params{VerticalCS});
8140 SetProjCS($self, $params{CoordinateSystem});
8142 } elsif (exists $params{Projection}) {
8143 error(1, $params{Projection}, \%Geo::OSR::PROJECTIONS) unless exists $Geo::OSR::PROJECTIONS{$params{Projection}};
8144 my @parameters = ();
8145 @parameters = @{$params{Parameters}}
if ref($params{Parameters});
8146 if ($params{Projection} eq
'Albers_Conic_Equal_Area') {
8147 SetACEA($self, @parameters);
8148 } elsif ($params{Projection} eq
'Azimuthal_Equidistant') {
8149 SetAE($self, @parameters);
8150 } elsif ($params{Projection} eq
'Bonne') {
8151 SetBonne($self, @parameters);
8152 } elsif ($params{Projection} eq
'Cylindrical_Equal_Area') {
8153 SetCEA($self, @parameters);
8154 } elsif ($params{Projection} eq
'Cassini_Soldner') {
8155 SetCS($self, @parameters);
8156 } elsif ($params{Projection} eq
'Equidistant_Conic') {
8157 SetEC($self, @parameters);
8158 # Eckert_I, Eckert_II, Eckert_III, Eckert_V ? 8159 } elsif ($params{Projection} eq
'Eckert_IV') {
8160 SetEckertIV($self, @parameters);
8161 } elsif ($params{Projection} eq
'Eckert_VI') {
8162 SetEckertVI($self, @parameters);
8163 } elsif ($params{Projection} eq
'Equirectangular') {
8165 SetEquirectangular($self, @parameters) :
8166 SetEquirectangular2($self, @parameters);
8167 } elsif ($params{Projection} eq
'Gauss_Schreiber_Transverse_Mercator') {
8168 SetGaussSchreiberTMercator($self, @parameters);
8169 } elsif ($params{Projection} eq
'Gall_Stereographic') {
8170 SetGS($self, @parameters);
8171 } elsif ($params{Projection} eq
'Goode_Homolosine') {
8172 SetGH($self, @parameters);
8173 } elsif ($params{Projection} eq
'Interrupted_Goode_Homolosine') {
8175 } elsif ($params{Projection} eq
'Geostationary_Satellite') {
8176 SetGEOS($self, @parameters);
8177 } elsif ($params{Projection} eq
'Gnomonic') {
8178 SetGnomonic($self, @parameters);
8179 } elsif ($params{Projection} eq
'Hotine_Oblique_Mercator') {
8180 # Hotine_Oblique_Mercator_Azimuth_Center ? 8181 SetHOM($self, @parameters);
8182 } elsif ($params{Projection} eq
'Hotine_Oblique_Mercator_Two_Point_Natural_Origin') {
8183 SetHOM2PNO($self, @parameters);
8184 } elsif ($params{Projection} eq
'Krovak') {
8185 SetKrovak($self, @parameters);
8186 } elsif ($params{Projection} eq
'Lambert_Azimuthal_Equal_Area') {
8187 SetLAEA($self, @parameters);
8188 } elsif ($params{Projection} eq
'Lambert_Conformal_Conic_2SP') {
8189 SetLCC($self, @parameters);
8190 } elsif ($params{Projection} eq
'Lambert_Conformal_Conic_1SP') {
8191 SetLCC1SP($self, @parameters);
8192 } elsif ($params{Projection} eq
'Lambert_Conformal_Conic_2SP_Belgium') {
8193 SetLCCB($self, @parameters);
8194 } elsif ($params{Projection} eq
'miller_cylindrical') {
8195 SetMC($self, @parameters);
8196 } elsif ($params{Projection} =~ /^Mercator/) {
8197 # Mercator_1SP, Mercator_2SP, Mercator_Auxiliary_Sphere ? 8198 # variant is in Variant (or Name) 8199 SetMercator($self, @parameters);
8200 } elsif ($params{Projection} eq
'Mollweide') {
8201 SetMollweide($self, @parameters);
8202 } elsif ($params{Projection} eq
'New_Zealand_Map_Grid') {
8203 SetNZMG($self, @parameters);
8204 } elsif ($params{Projection} eq
'Oblique_Stereographic') {
8205 SetOS($self, @parameters);
8206 } elsif ($params{Projection} eq
'Orthographic') {
8207 SetOrthographic($self, @parameters);
8208 } elsif ($params{Projection} eq
'Polyconic') {
8209 SetPolyconic($self, @parameters);
8210 } elsif ($params{Projection} eq
'Polar_Stereographic') {
8211 SetPS($self, @parameters);
8212 } elsif ($params{Projection} eq
'Robinson') {
8213 SetRobinson($self, @parameters);
8214 } elsif ($params{Projection} eq
'Sinusoidal') {
8215 SetSinusoidal($self, @parameters);
8216 } elsif ($params{Projection} eq
'Stereographic') {
8217 SetStereographic($self, @parameters);
8218 } elsif ($params{Projection} eq
'Swiss_Oblique_Cylindrical') {
8219 SetSOC($self, @parameters);
8220 } elsif ($params{Projection} eq
'Transverse_Mercator_South_Orientated') {
8221 SetTMSO($self, @parameters);
8222 } elsif ($params{Projection} =~ /^Transverse_Mercator/) {
8223 my($variant) = $params{Projection} =~ /^Transverse_Mercator_(\w+)/;
8226 SetTMVariant($self, $variant, @parameters) :
8227 SetTM($self, @parameters);
8228 } elsif ($params{Projection} eq
'Tunisia_Mining_Grid') {
8229 SetTMG($self, @parameters);
8230 } elsif ($params{Projection} eq
'VanDerGrinten') {
8231 SetVDG($self, @parameters);
8233 # Aitoff, Craster_Parabolic, International_Map_of_the_World_Polyconic, Laborde_Oblique_Mercator 8234 # Loximuthal, Miller_Cylindrical, Quadrilateralized_Spherical_Cube, Quartic_Authalic, Two_Point_Equidistant 8235 # Wagner_I, Wagner_II, Wagner_III, Wagner_IV, Wagner_V, Wagner_VI, Wagner_VII 8236 # Winkel_I, Winkel_II, Winkel_Tripel 8238 SetProjection($self, $params{Projection});
8241 error(
"Not enough information to create a spatial reference object.");
8245 #** @method SetAxisMappingStrategy() 8247 sub SetAxisMappingStrategy {
8250 #** @method SetMercator2SP() 8252 sub SetMercator2SP {
8255 #** @method Validate() 8261 #** @method Geo::OSR::SpatialReference new(%params) 8263 # Create a new spatial reference object using a named parameter. This 8264 # constructor recognizes the following key words (alternative in 8265 # parenthesis): WKT (Text), Proj4, ESRI, EPSG, EPSGA, PCI, USGS, GML 8266 # (XML), URL, ERMapper (ERM), MapInfoCS (MICoordSys). The value 8267 # depends on the key. 8268 # - WKT: Well Known Text string 8269 # - Proj4: PROJ.4 string 8270 # - ESRI: reference to a list of strings (contents of ESRI .prj file) 8271 # - EPSG: EPSG code number 8272 # - EPSGA: EPSG code number (the resulting CS will have EPSG preferred axis ordering) 8273 # - PCI: listref: [PCI_projection_string, Grid_units_code, [17 cs parameters]] 8274 # - USGS: listref: [Projection_system_code, Zone, [15 cs parameters], Datum_code, Format_flag] 8276 # - URL: URL for downloading the spatial reference from 8277 # - ERMapper: listref: [Projection, Datum, Units] 8278 # - MapInfoCS: MapInfo style co-ordinate system definition 8280 # For more information, consult the import methods in <a href="http://www.gdal.org/classOGRSpatialReference.html">OGR documentation</a>. 8282 # @note ImportFrom* methods also exist but are not documented here. 8286 # $sr = Geo::OSR::SpatialReference->new( key => value ); 8288 # @return a new Geo::OSR::SpatialReference object 8293 my $self = Geo::OSRc::new_SpatialReference();
8294 if (exists $param{WKT}) {
8295 ImportFromWkt($self, $param{WKT});
8296 } elsif (exists $param{Text}) {
8297 ImportFromWkt($self, $param{Text});
8298 } elsif (exists $param{Proj4}) {
8299 ImportFromProj4($self, $param{Proj4});
8300 } elsif (exists $param{ESRI}) {
8301 ImportFromESRI($self, @{$param{ESRI}});
8302 } elsif (exists $param{EPSG}) {
8303 ImportFromEPSG($self, $param{EPSG});
8304 } elsif (exists $param{EPSGA}) {
8305 ImportFromEPSGA($self, $param{EPSGA});
8306 } elsif (exists $param{PCI}) {
8307 ImportFromPCI($self, @{$param{PCI}});
8308 } elsif (exists $param{USGS}) {
8309 ImportFromUSGS($self, @{$param{USGS}});
8310 } elsif (exists $param{XML}) {
8311 ImportFromXML($self, $param{XML});
8312 } elsif (exists $param{GML}) {
8313 ImportFromGML($self, $param{GML});
8314 } elsif (exists $param{URL}) {
8315 ImportFromUrl($self, $param{URL});
8316 } elsif (exists $param{ERMapper}) {
8317 ImportFromERM($self, @{$param{ERMapper}});
8318 } elsif (exists $param{ERM}) {
8319 ImportFromERM($self, @{$param{ERM}});
8320 } elsif (exists $param{MICoordSys}) {
8321 ImportFromMICoordSys($self, $param{MICoordSys});
8322 } elsif (exists $param{MapInfoCS}) {
8323 ImportFromMICoordSys($self, $param{MapInfoCS});
8324 } elsif (exists $param{WGS}) {
8326 SetWellKnownGeogCS($self,
'WGS'.$param{WGS});
8328 confess last_error()
if $@;
8330 error(
"Unrecognized/missing parameters: @_.");
8332 bless $self, $pkg
if defined $self;
public Geo::GDAL::Extent new(array params)
public Geo::GDAL::ColorTable ColorTable(scalar ColorTable)
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)
public Geo::GDAL::ColorTable new(scalar GDALPaletteInterp='RGB')
A set of associated raster bands or vector layer source.
public Geo::GDAL::Band Band(scalar index)
public scalar Overlaps(scalar extent)
A driver for a specific dataset format.
An attribute table in a raster band.
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 method VSIFFlushL()
public Geo::GDAL::Driver Driver(scalar Name)
public scalar GeometryType()
public Geo::OGR::GeomFieldDefn new(hash params)
Create a new spatial field definition.
public list GeometryTypes()
A color table from a raster band or a color table, which can be used for a band. ...
public Geo::OGR::Feature new(hash schema)
Create a new feature.
public Geo::OGR::FeatureDefn new(hash schema)
public list Tuple(array tuple)
public array reference Points(arrayref points)
A rectangular area in projection coordinates: xmin, ymin, xmax, ymax.
An object, which holds meta data.
A collection of similar features.
public scalar GetDataTypeSize(scalar DataType)
A spatial reference system.
public scalar PackCharacter(scalar DataType)
A collection of non-spatial and spatial attributes.
A definition of a spatial attribute.