deadpickle has asked for the wisdom of the Perl Monks concerning the following question:

Ok monks, here we go!!!
I have this Gtk2 app that displays geotiffs and allows the user to add waypoints to the screen by using Goo::Canvas. I want to go further, I want to add a radar image to the display. I would like to read on how you monks think this could be done, but I do have a few ideas of my own:
*Create a dual Goo::Canvas that overlays over the geotiff image. This will allow the radar to be displayed using gridded coordinates maybe with a pixel size relevant to the radar image (which is probably different from the geotiff.
*Create an image, jpg png etc, that can be overlayed over the Goo::Canvas. This may mean that the image will have a transparent color.

Replies are listed 'Best First'.
Re: Radar and Goo::Canvas
by zentara (Cardinal) on Jun 30, 2008 at 15:00 UTC
    I have no idea what radar means as you describe it. At first thought I pictured a rotating line sweeping over the canvas, but you talk like you want some sort of locator grid, superimposed on the geotiff. This all sounds pretty complex, and at the very least you will need to show a basic code sample of what you want to do.

    From your ideas, it sounds like you are making it too complicated with overlays. What you need to do is setup a coordinate-transformation system, between your geotiff and the canvas. Then just put a blinking red-dot at that point, and move it as needed.

    The difficult part is figuring out the formulas to match the geotiff to the canvas, and I have no idea what geotiff does. Does it define the latitude and longitude of it's corners with smooth gradations from corner to corner? That is the sort of thing you will need to figure out.

    As far as pixel size goes, I bellieve you would just do your calculations as a 1-1 pixel size, then when done multiply the x y values by the current zoom level. I havn't tested that.... the zoom may work automagically.


    I'm not really a human, but I play one on earth CandyGram for Mongo
      probably wanted weather radar (green is rain ...)
        Yes!! I'm looking to add a WSR-88D (doppler radar) overlay to the application. Most radar data is in spherical coordinates which can be hard to transfer to gridded (lat lon) coordinates, but it is possible. The best thing I can think of to do is to overlay an image, such as a png, over the top of the application field. Is there a way to set a color in goo::canvas that will be invisible?
Re: Radar and Goo::Canvas
by zentara (Cardinal) on Jul 01, 2008 at 11:58 UTC
    UPDATE: Further discussion on the maillist revealed the method to do this completely in Gtk2, using add_alpha The following code shows how.
    #!/usr/bin/perl -w use strict; use warnings; use Goo::Canvas; use Gtk2 '-init'; use Glib qw(TRUE FALSE); my $window = Gtk2::Window->new('toplevel'); $window->signal_connect('delete_event' => sub { Gtk2->main_quit; }); $window->set_default_size(640, 600); my $swin = Gtk2::ScrolledWindow->new; $swin->set_shadow_type('in'); $window->add($swin); my $canvas = Goo::Canvas->new(); $canvas->set_size_request(600, 450); $canvas->set_bounds(0, 0, 1000, 1000); $swin->add($canvas); my $root = $canvas->get_root_item(); # base file my $im = Gtk2::Gdk::Pixbuf->new_from_file("MI.png"); my $w = $im->get_width; my $h = $im->get_height; my $image = Goo::Canvas::Image->new( $root, $im, 0, 0, 'width' => $w, 'height' => $h); # overlay file which needs transparency added my $im1 = Gtk2::Gdk::Pixbuf->new_from_file("zzrgbwb.png"); my $im2 = $im1->add_alpha(1,0 ,255 , 0); # returns a new pixbuf # makes green transparent # use 0..255 for color levels, NOT hex my $w1 = $im2->get_width; my $h1 = $im2->get_height; my $image1 = Goo::Canvas::Image->new( $root, $im2, 50, 50, 'width' => $w, 'height' => $h); $window->show_all(); Gtk2->main;
    END UPDATE

    #############################################

    I asked on the Perl/Gtk2 maillist if a transparency can be set in an image loaded with a pixbuf. The answer is yes, but setting up the mask is complicated. However, GD makes it simple, the following script will make green transparent in a image, and you can then overlay that on top of your geotiff. Notice you can make any color transparent. Also GD will let you write to an inline scalar, so you could read the radar image in, process it it with GD, write the output to a scalar, and load the pixbuf from the scalar( so there will be no temp file). I tested the output of the following on a Goo Canvas, and it works fine.

    #!/usr/bin/perl use warnings; use strict; use GD; GD::Image->trueColor(1); my $img_file = 'zzrgbwb.png'; my $gd = GD::Image->new($img_file) or die; my ($w, $h) = $gd->getBounds(); print "$w $h\n"; # allocate some colors my $white = $gd->colorAllocate(255,255,255); my $black = $gd->colorAllocate(0,0,0); my $red = $gd->colorAllocate(255,0,0); my $green = $gd->colorAllocate(0,255,0); my $blue = $gd->colorAllocate(0,0,255); # make the background transparent and interlaced $gd->transparent($green); #$gd->interlaced('true'); open(GD, ">zzrgbwb-gt.png") or die; binmode GD; print GD $gd->png; close GD;

    I'm not really a human, but I play one on earth CandyGram for Mongo