Geoinformatica  0.90
GDAL.pm
Go to the documentation of this file.
1 #** @file GDAL.pm
2 #*
3 
4 package Geo::Raster::Layer::Dialogs::Properties::GDAL;
5 
6 use strict;
7 use warnings;
8 use Carp;
9 use Glib qw/TRUE FALSE/;
10 use Gtk2::Ex::Geo::Dialogs qw/:all/;
11 
12 sub open {
13  my($self, $gui) = @_;
14 
15  # bootstrap:
16  my($dialog, $boot) = $self->bootstrap_dialog
17  ($gui, 'gdal_properties_dialog', "Properties of ".$self->name,
18  {
19  gdal_properties_dialog => [delete_event => \&cancel_gdal_properties, [$self, $gui]],
20  gdal_properties_apply_button => [clicked => \&apply_gdal_properties, [$self, $gui, 0]],
21  gdal_properties_cancel_button => [clicked => \&cancel_gdal_properties, [$self, $gui]],
22  gdal_properties_ok_button => [clicked => \&apply_gdal_properties, [$self, $gui, 1]],
23  });
24 
25  $self->{backup}->{name} = $self->name;
26  $self->{backup}->{alpha} = $self->alpha;
27  $self->{backup}->{nodata_value} = $self->nodata_value;
28 
29  $dialog->get_widget('gdal_name_entry')->set_text($self->name);
30  $dialog->get_widget('gdal_alpha_spinbutton')->set_value($self->alpha);
31 
32  my $type = $self->dataset->Band(1)->DataType;
33  $dialog->get_widget('gdal_datatype_label')->set_text($type);
34  my @size = $self->size();
35  $dialog->get_widget('gdal_size_label')->set_text("@size");
36 
37  @size = $self->world();
38  $dialog->get_widget('gdal_min_x_label')->set_text($size[0]);
39  $dialog->get_widget('gdal_min_y_label')->set_text($size[1]);
40  $dialog->get_widget('gdal_max_x_label')->set_text($size[2]);
41  $dialog->get_widget('gdal_max_y_label')->set_text($size[3]);
42 
43  @size = $self->cell_size();
44  $dialog->get_widget('gdal_cellsize_label')->set_text("@size");
45 
46  my $nodata = $self->nodata_value();
47  $nodata = '' unless defined $nodata;
48  $dialog->get_widget('gdal_nodata_entry')->set_text($nodata);
49 
50  @size = $self->value_range();
51  my $text = defined $size[0] ? "@size" : "not available";
52  $dialog->get_widget('gdal_minmax_label')->set_text($text);
53 
54  return $dialog->get_widget('gdal_properties_dialog');
55 }
56 
57 sub apply_gdal_properties {
58  my($self, $gui, $close) = @{$_[1]};
59  my $dialog = $self->{gdal_properties_dialog};
60 
61  eval {
62  my $name = $dialog->get_widget('gdal_name_entry')->get_text;
63  $self->name($name);
64  my $alpha = $dialog->get_widget('gdal_alpha_spinbutton')->get_value_as_int;
65  $self->alpha($alpha);
66 
67  my $nodata = get_number_from_entry($dialog->get_widget('gdal_nodata_entry'));
68  my $band = $self->band();
69  $band->SetNoDataValue($nodata) if $nodata ne '';
70  };
71  $gui->message("$@") if $@;
72 
73  $self->hide_dialog('gdal_properties_dialog') if $close;
74  $gui->set_layer($self);
75  $gui->{overlay}->render;
76 }
77 
78 sub cancel_gdal_properties {
79  my($self, $gui);
80  for (@_) {
81  next unless ref CORE::eq 'ARRAY';
82  ($self, $gui) = @{$_};
83  }
84 
85  eval {
86  $self->alpha($self->{backup}->{alpha});
87  $self->name($self->{backup}->{name});
88  my $band = $self->band();
89  $band->SetNoDataValue($self->{backup}->{nodata}) if $self->{backup}->{nodata} and $self->{backup}->{nodata} ne '';
90  };
91  $gui->message("$@") if $@;
92  $self->hide_dialog('gdal_properties_dialog');
93  $gui->set_layer($self);
94  $gui->{overlay}->render;
95  1;
96 }
97 
98 1;