in reply to Drawing Shapefiles in Goo::Canvas

I don't really follow your code, but since you say you are having problems with the PolyLine, you may want to look at Goo::Canvas Waypoint marker w zoom/save to svg and pdf.

First, to update a PolyLine, you must manually set the points option, it is not defined by default. Also, points takes an array_ref , NOT an array. It should go something like this:

my $num_points = \@shape; # an array_ref print "$num_points\n"; my $road = Goo::Canvas::Polyline->new( $road_group,FALSE,$num_points, .... other options);

Also note from my example node, that creating a PolyLine with an array_ref is a one shot deal. If you need to update it, your points need to be a Goo::Canvas::Points object, you update the Points object, then set it as the points in the PolyLine.


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

Replies are listed 'Best First'.
Re^2: Drawing Shapefiles in Goo::Canvas
by deadpickle (Pilgrim) on Jun 17, 2008 at 05:40 UTC
    I have changed to try and draw a line connecting the waypoints. I still have the same problem with crashing perl:
    my $num_points = (scalar @points)/2; #$num_points = $num_points / 2; print $num_points,"\n"; unless ($num_points == 1){ print " $count\n"; for(1..($num_points-$count)*2){ print "here is a point\n"; shift @points; } foreach (@points){ print $_,"\n"; } my $way_lines = Goo::Canvas::Polyline->new($way_group,TRUE +,$num_points,[\@points]); }
      As far as I can tell, you are still doing it wrong. Unless I'm missing some deep magic you are trying to use, the following is not right
      my $way_lines = Goo::Canvas::Polyline->new($way_group, TRUE, $num_points, [\@points]); #here you have both the $points (assuming its an array_ref of points) # AND you have a nested array_ref in an array_ref ??? # [ \@points] ???? where did you come up with that?
      You can only specify 1 array_ref, like $points = \@points and just use $points.

      Look closely at the example in Goo::Canvas Waypoint marker w zoom/save to svg and pdf and the man page for PolyLine. There are 2 ways to specify points when creating the PolyLine. One is to drop in an anonymous array_ref of x,y pairs. The other is to set the anonymous array_ref to undef, when creating the PolyLine, then after creation, set the points option to an array_ref. Additionally, if you later want to change(update) the points, the points must be a Goo::Canvas::Points object. The Goo::Canvas::Points object is just an object wrapper around the array_ref (look at my waypoint example closely), but the Goo::Canvas wants it that way.

      Remember, the Goo::Canvas is still in development, and the author hasn't tightened up those dangling inconsistencies yet. But you can get it to work, with the steps outlined above.


      I'm not really a human, but I play one on earth CandyGram for Mongo
        I have to say, thank you very much for the help!! I must be missing something cause it still is not displaying any lines at all I can't figure why. Its probably something I have overlooked and it may take another pair of eyes to remedy this.
        #!/usr/bin/perl -w use strict; use Glib qw/TRUE FALSE/; use Gtk2 -init; use Goo::Canvas; #variables my $ellipsoid = 23; #static WSG83 my $zone; my @mtp; my @ps; my @cs; my $count = 1; my $way_ref = [340, 170,340, 230]; #Create Window my $window = new Gtk2::Window ( "toplevel" ); $window->signal_connect ("delete_event", sub { Gtk2->main_quit; }); $window->set_border_width (10); $window->set_size_request(640,480); $window->set_position('center'); #Create Scrolled Window my $scwin = Gtk2::ScrolledWindow->new(); $scwin->set_policy('always','always'); $window->add($scwin); #add canvas my $canvas = Goo::Canvas->new(); $scwin->add($canvas); my $root = $canvas->get_root_item(); #waypoint lines group my $way_group = Goo::Canvas::Group->new($root); #add Background image my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file ($filename); my $image = Goo::Canvas::Image->new($root, $pixbuf, 0, 0, 'width' => $pixbuf->get_width, 'height' => $pixbuf->get_height); #handle the events $canvas->signal_connect (event => \&event_handler); #Start the waypoint connector my $way_lines = Goo::Canvas::Polyline->new($way_group,TRUE,undef, stroke_color => 'black', line_width => 3, ); $window->show_all; Gtk2->main; #------------------------------------------------ #handle the mosue events sub event_handler { my ( $widget, $event ) = @_; #on 2 mouse presses if ( $event->type eq "2button-press" ) { my ($x,$y) = ($event->x,$event->y); print 'x->',$x,' ','y->',$y; #Drop waypoint icon my $tgroup = Goo::Canvas::Group->new ($root); Goo::Canvas::Ellipse->new($tgroup,$x,$y,7.5,7.5, fill_color => 'purple', stroke_color => 'black'); Goo::Canvas::Text->new ($tgroup,$count,$x,$y,-1,'GTK_ANCHOR_CE +NTER', font => 'Sans Bold 15', fill_color => 'pink', ); print " $count\n"; push @$way_ref,$x,$y; my $points = Goo::Canvas::Points->new($way_ref); $way_lines->set(points => $points); $count++; print "$way_lines\n"; return; } } #------------------------------------------------