1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786
|
/******************************************************************************
*
* Project: GDAL SWIG Interface declarations for Perl.
* Purpose: GDAL declarations.
* Author: Ari Jolma and Kevin Ruland
*
******************************************************************************
* Copyright (c) 2007, Ari Jolma and Kevin Ruland
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/
%init %{
/* gdal_perl.i %init code */
UseExceptions();
if ( GDALGetDriverCount() == 0 ) {
GDALAllRegister();
}
%}
%include callback.i
%include cpl_exceptions.i
%rename (GetMetadata) GetMetadata_Dict;
%ignore GetMetadata_List;
%import typemaps_perl.i
%import destroy.i
/*ALTERED_DESTROY(GDALRasterBandShadow, GDALc, delete_Band) !does not work! */
ALTERED_DESTROY(GDALColorTableShadow, GDALc, delete_ColorTable)
ALTERED_DESTROY(GDALConstShadow, GDALc, delete_Const)
ALTERED_DESTROY(GDALDatasetShadow, GDALc, delete_Dataset)
ALTERED_DESTROY(GDALDriverShadow, GDALc, delete_Driver)
ALTERED_DESTROY(GDAL_GCP, GDALc, delete_GCP)
ALTERED_DESTROY(GDALMajorObjectShadow, GDALc, delete_MajorObject)
ALTERED_DESTROY(GDALRasterAttributeTableShadow, GDALc, delete_RasterAttributeTable)
%rename (_GetDataTypeSize) GetDataTypeSize;
%rename (_DataTypeIsComplex) DataTypeIsComplex;
%rename (_GetDriver) GetDriver;
%rename (_Open) Open;
%newobject _Open;
%rename (_OpenShared) OpenShared;
%newobject _OpenShared;
/* those that need callback_data check: */
%rename (_ComputeMedianCutPCT) ComputeMedianCutPCT;
%rename (_DitherRGB2PCT) DitherRGB2PCT;
%rename (_ReprojectImage) ReprojectImage;
%rename (_ComputeProximity) ComputeProximity;
%rename (_RasterizeLayer) RasterizeLayer;
%rename (_Polygonize) Polygonize;
%rename (_SieveFilter) SieveFilter;
%rename (_RegenerateOverviews) RegenerateOverviews;
%rename (_RegenerateOverview) RegenerateOverview;
%rename (_AutoCreateWarpedVRT) AutoCreateWarpedVRT;
%newobject _AutoCreateWarpedVRT;
%rename (_Create) Create;
%newobject _Create;
%rename (_GetRasterBand) GetRasterBand;
%rename (_AddBand) AddBand;
%rename (_GetPaletteInterpretation) GetPaletteInterpretation;
%rename (_GetHistogram) GetHistogram;
%rename (_SetColorEntry) SetColorEntry;
%rename (_GetUsageOfCol) GetUsageOfCol;
%rename (_GetColOfUsage) GetColOfUsage;
%rename (_GetTypeOfCol) GetTypeOfCol;
%rename (_CreateColumn) CreateColumn;
%rename (Stat) VSIStatL;
%perlcode %{
use strict;
use Carp;
use Encode;
use Geo::GDAL::Const;
use Geo::OGR;
use Geo::OSR;
# $VERSION is the Perl module (CPAN) version number, which must be
# an increasing floating point number. $GDAL_VERSION is the
# version number of the GDAL that this module is a part of. It is
# used in build time to check the version of GDAL against which we
# build. For GDAL 1.9.2 and below $VERSION is made by dropping
# the second point. Hoping that there will not be GDAL 1.9.10, we
# set the $VERSION of GDAL 1.10 to 1.991. Thus GDAL 1.10.1 would
# have $VERSION 1.9911 and GDAL 1.11 would have $VERSION 1.992
# etc. GDAL 2.0 should then get VERSION 2.000 and 2.1 should get
# 2.001 etc.
our $VERSION = '1.9911';
our $GDAL_VERSION = '1.10.1';
use vars qw/
%TYPE_STRING2INT %TYPE_INT2STRING
%ACCESS_STRING2INT %ACCESS_INT2STRING
%RESAMPLING_STRING2INT %RESAMPLING_INT2STRING
%NODE_TYPE_STRING2INT %NODE_TYPE_INT2STRING
/;
for my $string (qw/Unknown Byte UInt16 Int16 UInt32 Int32 Float32 Float64 CInt16 CInt32 CFloat32 CFloat64/) {
my $int = eval "\$Geo::GDAL::Constc::GDT_$string";
$TYPE_STRING2INT{$string} = $int;
$TYPE_INT2STRING{$int} = $string;
}
for my $string (qw/ReadOnly Update/) {
my $int = eval "\$Geo::GDAL::Constc::GA_$string";
$ACCESS_STRING2INT{$string} = $int;
$ACCESS_INT2STRING{$int} = $string;
}
for my $string (qw/NearestNeighbour Bilinear Cubic CubicSpline/) {
my $int = eval "\$Geo::GDAL::Constc::GRA_$string";
$RESAMPLING_STRING2INT{$string} = $int;
$RESAMPLING_INT2STRING{$int} = $string;
}
{
my $int = 0;
for my $string (qw/Element Text Attribute Comment Literal/) {
$NODE_TYPE_STRING2INT{$string} = $int;
$NODE_TYPE_INT2STRING{$int} = $string;
$int++;
}
}
sub RELEASE_PARENTS {
}
sub NodeType {
my $type = shift;
return $NODE_TYPE_INT2STRING{$type} if $type =~ /^\d/;
return $NODE_TYPE_STRING2INT{$type};
}
sub NodeData {
my $node = shift;
return (Geo::GDAL::NodeType($node->[0]), $node->[1]);
}
sub Children {
my $node = shift;
return @$node[2..$#$node];
}
sub Child {
my($node, $child) = @_;
return $node->[2+$child];
}
sub GetDataTypeSize {
my $t = shift;
$t = $TYPE_INT2STRING{$t} if exists $TYPE_INT2STRING{$t};
return _GetDataTypeSize($t);
}
sub DataTypeValueRange {
my $t = shift;
# these values are from gdalrasterband.cpp
return (0,255) if $t =~ /^Byte$/;
return (0,65535) if $t =~ /^UInt16$/;
return (-32768,32767) if $t =~ /Int16$/; # also CInt
return (0,4294967295) if $t =~ /^UInt32$/;
return (-2147483648,2147483647) if $t =~ /Int32$/; # also CInt
return (-4294967295.0,4294967295.0) if $t =~ /Float32$/; # also CFloat
return (-4294967295.0,4294967295.0) if $t =~ /Float64$/; # also CFloat
croak "GDAL does not support data type '$t'";
}
sub DataTypeIsComplex {
my $t = shift;
$t = $TYPE_INT2STRING{$t} if exists $TYPE_INT2STRING{$t};
return _DataTypeIsComplex($t);
}
sub PackCharacter {
my $t = shift;
$t = $TYPE_INT2STRING{$t} if exists $TYPE_INT2STRING{$t};
my $is_big_endian = unpack("h*", pack("s", 1)) =~ /01/; # from Programming Perl
return 'C' if $t =~ /^Byte$/;
return ($is_big_endian ? 'n': 'v') if $t =~ /^UInt16$/;
return 's' if $t =~ /^Int16$/;
return ($is_big_endian ? 'N' : 'V') if $t =~ /^UInt32$/;
return 'l' if $t =~ /^Int32$/;
return 'f' if $t =~ /^Float32$/;
return 'd' if $t =~ /^Float64$/;
croak "data type '$t' is not known in Geo::GDAL::PackCharacter";
}
sub Drivers {
my @drivers;
for my $i (0..GetDriverCount()-1) {
push @drivers, _GetDriver($i);
}
return @drivers;
}
sub GetDriver {
my $driver = shift;
return _GetDriver($driver) if $driver =~ /^\d/;
return GetDriverByName($driver);
}
*Driver = *GetDriver;
sub Open {
my @p = @_;
$p[1] = $ACCESS_STRING2INT{$p[1]} if $p[1] and exists $ACCESS_STRING2INT{$p[1]};
return _Open(@p);
}
sub OpenShared {
my @p = @_;
$p[1] = $ACCESS_STRING2INT{$p[1]} if $p[1] and exists $ACCESS_STRING2INT{$p[1]};
return _OpenShared(@p);
}
sub ComputeMedianCutPCT {
$_[6] = 1 if $_[5] and not defined $_[6];
_ComputeMedianCutPCT(@_);
}
sub DitherRGB2PCT {
$_[6] = 1 if $_[5] and not defined $_[6];
_DitherRGB2PCT(@_);
}
sub ComputeProximity {
$_[4] = 1 if $_[3] and not defined $_[4];
_ComputeProximity(@_);
}
sub RasterizeLayer {
$_[8] = 1 if $_[7] and not defined $_[8];
_RasterizeLayer(@_);
}
sub Polygonize {
my @params = @_;
$params[6] = 1 if $params[5] and not defined $params[6];
$params[3] = $params[2]->GetLayerDefn->GetFieldIndex($params[3]) unless $params[3] =~ /^\d/;
_Polygonize(@params);
}
sub SieveFilter {
$_[7] = 1 if $_[6] and not defined $_[7];
_SieveFilter(@_);
}
sub RegenerateOverviews {
$_[4] = 1 if $_[3] and not defined $_[4];
_RegenerateOverviews(@_);
}
sub RegenerateOverview {
$_[4] = 1 if $_[3] and not defined $_[4];
_RegenerateOverview(@_);
}
sub ReprojectImage {
$_[8] = 1 if $_[7] and not defined $_[8];
$_[4] = $RESAMPLING_STRING2INT{$_[4]} if $_[4] and exists $RESAMPLING_STRING2INT{$_[4]};
return _ReprojectImage(@_);
}
sub AutoCreateWarpedVRT {
$_[3] = $RESAMPLING_STRING2INT{$_[3]} if $_[3] and exists $RESAMPLING_STRING2INT{$_[3]};
return _AutoCreateWarpedVRT(@_);
}
package Geo::GDAL::MajorObject;
use vars qw/@DOMAINS/;
use strict;
sub Domains {
return @DOMAINS;
}
sub Description {
my($self, $desc) = @_;
SetDescription($self, $desc) if defined $desc;
GetDescription($self) if defined wantarray;
}
sub Metadata {
my $self = shift;
my $metadata;
$metadata = shift if ref $_[0];
my $domain = shift;
$domain = '' unless defined $domain;
SetMetadata($self, $metadata, $domain) if defined $metadata;
GetMetadata($self, $domain) if defined wantarray;
}
package Geo::GDAL::Driver;
use vars qw/@CAPABILITIES @DOMAINS/;
use strict;
@CAPABILITIES = ('Create', 'CreateCopy');
sub Domains {
return @DOMAINS;
}
sub Name {
my $self = shift;
return $self->{ShortName};
}
sub Capabilities {
my $self = shift;
return @CAPABILITIES unless $self;
my $h = $self->GetMetadata;
my @cap;
for my $cap (@CAPABILITIES) {
my $test = $h->{'DCAP_'.uc($cap)};
push @cap, $cap if defined($test) and $test eq 'YES';
}
return @cap;
}
sub TestCapability {
my($self, $cap) = @_;
my $h = $self->GetMetadata->{'DCAP_'.uc($cap)};
return (defined($h) and $h eq 'YES') ? 1 : undef;
}
sub Extension {
my $self = shift;
my $h = $self->GetMetadata;
return $h->{DMD_EXTENSION};
}
sub MIMEType {
my $self = shift;
my $h = $self->GetMetadata;
return $h->{DMD_MIMETYPE};
}
sub CreationOptionList {
my $self = shift;
my @options;
my $h = $self->GetMetadata->{DMD_CREATIONOPTIONLIST};
if ($h) {
$h = Geo::GDAL::ParseXMLString($h);
my($type, $value) = Geo::GDAL::NodeData($h);
if ($value eq 'CreationOptionList') {
for my $o (Geo::GDAL::Children($h)) {
my %option;
for my $a (Geo::GDAL::Children($o)) {
my(undef, $key) = Geo::GDAL::NodeData($a);
my(undef, $value) = Geo::GDAL::NodeData(Geo::GDAL::Child($a, 0));
if ($key eq 'Value') {
push @{$option{$key}}, $value;
} else {
$option{$key} = $value;
}
}
push @options, \%option;
}
}
}
return @options;
}
sub CreationDataTypes {
my $self = shift;
my $h = $self->GetMetadata;
return split /\s+/, $h->{DMD_CREATIONDATATYPES};
}
sub CreateDataset {
my @p = @_;
$p[5] = $Geo::GDAL::TYPE_STRING2INT{$p[5]} if $p[5] and exists $Geo::GDAL::TYPE_STRING2INT{$p[5]};
return _Create(@p);
}
*Create = *CreateDataset;
*Copy = *CreateCopy;
package Geo::GDAL::Dataset;
use strict;
use vars qw/%BANDS @DOMAINS/;
@DOMAINS = ("IMAGE_STRUCTURE", "SUBDATASETS", "GEOLOCATION");
sub Domains {
return @DOMAINS;
}
*GetDriver = *_GetDriver;
sub Open {
return Geo::GDAL::Open(@_);
}
sub OpenShared {
return Geo::GDAL::OpenShared(@_);
}
sub Size {
my $self = shift;
return ($self->{RasterXSize}, $self->{RasterYSize});
}
sub Bands {
my $self = shift;
my @bands;
for my $i (1..$self->{RasterCount}) {
push @bands, GetRasterBand($self, $i);
}
return @bands;
}
sub GetRasterBand {
my($self, $index) = @_;
$index = 1 unless defined $index;
my $band = _GetRasterBand($self, $index);
$BANDS{tied(%{$band})} = $self;
return $band;
}
*Band = *GetRasterBand;
sub AddBand {
my @p = @_;
$p[1] = $Geo::GDAL::TYPE_STRING2INT{$p[1]} if $p[1] and exists $Geo::GDAL::TYPE_STRING2INT{$p[1]};
return _AddBand(@p);
}
sub Projection {
my($self, $proj) = @_;
SetProjection($self, $proj) if defined $proj;
GetProjection($self) if defined wantarray;
}
sub GeoTransform {
my $self = shift;
SetGeoTransform($self, \@_) if @_ > 0;
return unless defined wantarray;
my $t = GetGeoTransform($self);
return @$t;
}
sub GCPs {
my $self = shift;
if (@_ > 0) {
my $proj = pop @_;
SetGCPs($self, \@_, $proj);
}
return unless defined wantarray;
my $proj = GetGCPProjection($self);
my $GCPs = GetGCPs($self);
return (@$GCPs, $proj);
}
package Geo::GDAL::Band;
use strict;
use Carp;
use Scalar::Util 'blessed';
use vars qw/
@COLOR_INTERPRETATIONS
%COLOR_INTERPRETATION_STRING2INT %COLOR_INTERPRETATION_INT2STRING @DOMAINS
/;
@COLOR_INTERPRETATIONS = qw/Undefined GrayIndex PaletteIndex RedBand GreenBand BlueBand AlphaBand
HueBand SaturationBand LightnessBand CyanBand MagentaBand YellowBand BlackBand/;
for my $string (@COLOR_INTERPRETATIONS) {
my $int = eval "\$Geo::GDAL::Constc::GCI_$string";
$COLOR_INTERPRETATION_STRING2INT{$string} = $int;
$COLOR_INTERPRETATION_INT2STRING{$int} = $string;
}
@DOMAINS = ("IMAGE_STRUCTURE", "RESAMPLING");
sub Domains {
return @DOMAINS;
}
sub DESTROY {
my $self;
if ($_[0]->isa('SCALAR')) {
$self = $_[0];
} else {
return unless $_[0]->isa('HASH');
$self = tied(%{$_[0]});
return unless defined $self;
}
delete $ITERATORS{$self};
if (exists $OWNER{$self}) {
delete $OWNER{$self};
}
$self->RELEASE_PARENTS();
}
sub RELEASE_PARENTS {
my $self = shift;
delete $Geo::GDAL::Dataset::BANDS{$self};
}
sub Size {
my $self = shift;
return ($self->{XSize}, $self->{YSize});
}
sub DataType {
my $self = shift;
return $Geo::GDAL::TYPE_INT2STRING{$self->{DataType}};
}
sub NoDataValue {
my $self = shift;
SetNoDataValue($self, $_[0]) if @_ > 0;
GetNoDataValue($self);
}
sub Unit {
my $self = shift;
SetUnitType($self, $_[0]) if @_ > 0;
GetUnitType($self);
}
sub ScaleAndOffset {
my $self = shift;
SetScale($self, $_[0]) if @_ > 0;
SetOffset($self, $_[1]) if @_ > 1;
(GetScale($self), GetOffset($self));
}
sub ReadTile {
my($self, $xoff, $yoff, $xsize, $ysize) = @_;
$xoff = 0 unless defined $xoff;
$yoff = 0 unless defined $yoff;
$xsize = $self->{XSize} - $xoff unless defined $xsize;
$ysize = $self->{YSize} - $yoff unless defined $ysize;
my $buf = $self->ReadRaster($xoff, $yoff, $xsize, $ysize);
my $pc = Geo::GDAL::PackCharacter($self->{DataType});
my $w = $xsize * Geo::GDAL::GetDataTypeSize($self->{DataType})/8;
my $offset = 0;
my @data;
for (0..$ysize-1) {
my $sub = substr($buf, $offset, $w);
my @d = unpack($pc."[$xsize]", $sub);
push @data, \@d;
$offset += $w;
}
return \@data;
}
sub WriteTile {
my($self, $data, $xoff, $yoff) = @_;
$xoff = 0 unless defined $xoff;
$yoff = 0 unless defined $yoff;
my $xsize = @{$data->[0]};
$xsize = $self->{XSize} - $xoff if $xsize > $self->{XSize} - $xoff;
my $ysize = @{$data};
$ysize = $self->{YSize} - $yoff if $ysize > $self->{YSize} - $yoff;
my $pc = Geo::GDAL::PackCharacter($self->{DataType});
my $w = $xsize * Geo::GDAL::GetDataTypeSize($self->{DataType})/8;
for my $i (0..$ysize-1) {
my $scanline = pack($pc."[$xsize]", @{$data->[$i]});
$self->WriteRaster( $xoff, $yoff+$i, $xsize, 1, $scanline );
}
}
sub ColorInterpretation {
my($self, $ci) = @_;
if ($ci) {
$ci = $COLOR_INTERPRETATION_STRING2INT{$ci} if exists $COLOR_INTERPRETATION_STRING2INT{$ci};
SetRasterColorInterpretation($self, $ci);
return $ci;
} else {
return $COLOR_INTERPRETATION_INT2STRING{GetRasterColorInterpretation($self)};
}
}
sub ColorTable {
my $self = shift;
SetRasterColorTable($self, $_[0]) if @_;
return unless defined wantarray;
GetRasterColorTable($self);
}
sub CategoryNames {
my $self = shift;
SetRasterCategoryNames($self, \@_) if @_;
return unless defined wantarray;
my $n = GetRasterCategoryNames($self);
return @$n;
}
sub AttributeTable {
my $self = shift;
SetDefaultRAT($self, $_[0]) if @_;
return unless defined wantarray;
my $r = GetDefaultRAT($self);
$Geo::GDAL::RasterAttributeTable::BANDS{$r} = $self;
return $r;
}
sub GetHistogram {
my $self = shift;
my %defaults = (Min => -0.5,
Max => 255.5,
Buckets => 256,
IncludeOutOfRange => 0,
ApproxOK => 0,
Progress => undef,
ProgressData => undef);
my %params = @_;
for (keys %params) {
carp "unknown parameter $_ in Geo::GDAL::Band::GetHistogram" unless exists $defaults{$_};
}
for (keys %defaults) {
$params{$_} = $defaults{$_} unless defined $params{$_};
}
$params{ProgressData} = 1 if $params{Progress} and not defined $params{ProgressData};
_GetHistogram($self, $params{Min}, $params{Max}, $params{Buckets},
$params{IncludeOutOfRange}, $params{ApproxOK},
$params{Progress}, $params{ProgressData});
}
sub Contours {
my $self = shift;
my %defaults = (DataSource => undef,
LayerConstructor => {Name => 'contours'},
ContourInterval => 100,
ContourBase => 0,
FixedLevels => [],
NoDataValue => undef,
IDField => -1,
ElevField => -1,
callback => undef,
callback_data => undef);
my %params;
if (!defined($_[0]) or (blessed($_[0]) and $_[0]->isa('Geo::OGR::DataSource'))) {
($params{DataSource}, $params{LayerConstructor},
$params{ContourInterval}, $params{ContourBase},
$params{FixedLevels}, $params{NoDataValue},
$params{IDField}, $params{ElevField},
$params{callback}, $params{callback_data}) = @_;
} else {
%params = @_;
}
for (keys %params) {
carp "unknown parameter $_ in Geo::GDAL::Band::Contours" unless exists $defaults{$_};
}
for (keys %defaults) {
$params{$_} = $defaults{$_} unless defined $params{$_};
}
$params{DataSource} = Geo::OGR::GetDriver('Memory')->CreateDataSource('ds')
unless defined $params{DataSource};
$params{LayerConstructor}->{Schema} = {} unless $params{LayerConstructor}->{Schema};
$params{LayerConstructor}->{Schema}{Fields} = [] unless $params{LayerConstructor}->{Schema}{Fields};
my %fields;
unless ($params{IDField} =~ /^[+-]?\d+$/ or $fields{$params{IDField}}) {
push @{$params{LayerConstructor}->{Schema}{Fields}}, {Name => $params{IDField}, Type => 'Integer'};
}
unless ($params{ElevField} =~ /^[+-]?\d+$/ or $fields{$params{ElevField}}) {
my $type = $self->DataType() =~ /Float/ ? 'Real' : 'Integer';
push @{$params{LayerConstructor}->{Schema}{Fields}}, {Name => $params{ElevField}, Type => $type};
}
my $layer = $params{DataSource}->CreateLayer($params{LayerConstructor});
my $schema = $layer->GetLayerDefn;
for ('IDField', 'ElevField') {
$params{$_} = $schema->GetFieldIndex($params{$_}) unless $params{$_} =~ /^[+-]?\d+$/;
}
$params{callback_data} = 1 if $params{callback} and not defined $params{callback_data};
ContourGenerate($self, $params{ContourInterval}, $params{ContourBase}, $params{FixedLevels},
$params{NoDataValue}, $layer, $params{IDField}, $params{ElevField},
$params{callback}, $params{callback_data});
return $layer;
}
sub FillNodata {
croak 'usage: Geo::GDAL::Band->FillNodata($mask)' unless blessed($_[1]) and $_[1]->isa('Geo::GDAL::Band');
$_[2] = 10 unless defined $_[2];
$_[3] = 0 unless defined $_[3];
$_[4] = undef unless defined $_[4];
$_[5] = undef unless defined $_[5];
$_[6] = undef unless defined $_[6];
Geo::GDAL::FillNodata(@_);
}
*GetBandNumber = *GetBand;
package Geo::GDAL::ColorTable;
use strict;
use vars qw/
%PALETTE_INTERPRETATION_STRING2INT %PALETTE_INTERPRETATION_INT2STRING
/;
for my $string (qw/Gray RGB CMYK HLS/) {
my $int = eval "\$Geo::GDAL::Constc::GPI_$string";
$PALETTE_INTERPRETATION_STRING2INT{$string} = $int;
$PALETTE_INTERPRETATION_INT2STRING{$int} = $string;
}
sub create {
my($pkg, $pi) = @_;
$pi = $PALETTE_INTERPRETATION_STRING2INT{$pi} if defined $pi and exists $PALETTE_INTERPRETATION_STRING2INT{$pi};
my $self = Geo::GDALc::new_ColorTable($pi);
bless $self, $pkg if defined($self);
}
sub GetPaletteInterpretation {
my $self = shift;
return $PALETTE_INTERPRETATION_INT2STRING{GetPaletteInterpretation($self)};
}
sub SetColorEntry {
@_ == 3 ? _SetColorEntry(@_) : _SetColorEntry(@_[0..1], [@_[2..5]]);
}
sub ColorEntry {
my $self = shift;
my $index = shift;
SetColorEntry($self, $index, @_) if @_ > 0;
GetColorEntry($self, $index) if defined wantarray;
}
sub ColorTable {
my $self = shift;
my @table;
if (@_) {
my $index = 0;
for my $color (@_) {
push @table, [ColorEntry($self, $index, @$color)];
$index++;
}
} else {
for (my $index = 0; $index < GetCount($self); $index++) {
push @table, [ColorEntry($self, $index)];
}
}
return @table;
}
package Geo::GDAL::RasterAttributeTable;
use strict;
use vars qw/ %BANDS
%FIELD_TYPE_STRING2INT %FIELD_TYPE_INT2STRING
%FIELD_USAGE_STRING2INT %FIELD_USAGE_INT2STRING
/;
for my $string (qw/Integer Real String/) {
my $int = eval "\$Geo::GDAL::Constc::GFT_$string";
$FIELD_TYPE_STRING2INT{$string} = $int;
$FIELD_TYPE_INT2STRING{$int} = $string;
}
for my $string (qw/Generic PixelCount Name Min Max MinMax
Red Green Blue Alpha RedMin
GreenMin BlueMin AlphaMin RedMax GreenMax BlueMax AlphaMax
MaxCount/) {
my $int = eval "\$Geo::GDAL::Constc::GFU_$string";
$FIELD_USAGE_STRING2INT{$string} = $int;
$FIELD_USAGE_INT2STRING{$int} = $string;
}
sub FieldTypes {
return keys %FIELD_TYPE_STRING2INT;
}
sub FieldUsages {
return keys %FIELD_USAGE_STRING2INT;
}
sub RELEASE_PARENTS {
my $self = shift;
delete $BANDS{$self};
}
sub GetUsageOfCol {
my($self, $col) = @_;
$FIELD_USAGE_INT2STRING{_GetUsageOfCol($self, $col)};
}
sub GetColOfUsage {
my($self, $usage) = @_;
_GetColOfUsage($self, $FIELD_USAGE_STRING2INT{$usage});
}
sub GetTypeOfCol {
my($self, $col) = @_;
$FIELD_TYPE_INT2STRING{_GetTypeOfCol($self, $col)};
}
sub Columns {
my $self = shift;
my %columns;
if (@_) { # create columns
%columns = @_;
for my $name (keys %columns) {
$self->CreateColumn($name, $columns{$name}{Type}, $columns{$name}{Usage});
}
}
%columns = ();
for my $c (0..$self->GetColumnCount-1) {
my $name = $self->GetNameOfCol($c);
$columns{$name}{Type} = $self->GetTypeOfCol($c);
$columns{$name}{Usage} = $self->GetUsageOfCol($c);
}
return %columns;
}
sub CreateColumn {
my($self, $name, $type, $usage) = @_;
_CreateColumn($self, $name, $FIELD_TYPE_STRING2INT{$type}, $FIELD_USAGE_STRING2INT{$usage});
}
sub Value {
my($self, $row, $column) = @_;
SetValueAsString($self, $row, $column, $_[3]) if defined $_[3];
return unless defined wantarray;
GetValueAsString($self, $row, $column);
}
sub LinearBinning {
my $self = shift;
SetLinearBinning($self, @_) if @_ > 0;
return unless defined wantarray;
my @a = GetLinearBinning($self);
return $a[0] ? ($a[1], $a[2]) : ();
}
%}
#define GDAL_BINDINGS
%import ogr.i
%{
typedef void OGRLayerShadow;
%}
%extend GDALRasterBandShadow {
%apply (int nList, double* pList) {(int nFixedLevelCount, double *padfFixedLevels)};
%apply (int defined, double value) {(int bUseNoData, double dfNoDataValue)};
CPLErr ContourGenerate(double dfContourInterval, double dfContourBase,
int nFixedLevelCount, double *padfFixedLevels,
int bUseNoData, double dfNoDataValue,
OGRLayerShadow *hLayer, int iIDField, int iElevField,
GDALProgressFunc callback = NULL,
void* callback_data = NULL) {
return GDALContourGenerate( self, dfContourInterval, dfContourBase,
nFixedLevelCount, padfFixedLevels,
bUseNoData, dfNoDataValue,
hLayer, iIDField, iElevField,
callback,
callback_data );
}
%clear (int nFixedLevelCount, double *padfFixedLevels);
%clear (int bUseNoData, double dfNoDataValue);
}
|