[FWTools] FWTools Shapes Refresh Problem

David Legault dlegault at vantpoint.com
Tue Apr 5 13:06:15 EDT 2005


Hi Frank

Here is a very simplifed version of the tool code that reproduces the
"display bug" I am having.

I used to demo image that comes with FWTools to demonstrate (make sur the
Earth like icon is white)

The pivot problem lies in these lines of code

def update_point_target( self ):

        print "------------------------"

        self.clear_shapes( )
        self.draw_target_region( self.point_data,
self.get_sub_region_size( ) )
        self.update_sub_view_display( self.view2, self.point_data )


where if I comment out the "self.update_sub_view_display( self.view2,
self.point_data )" part, the display gets refreshed properly with the box
being re-printed out, and enabling that line, causes the display box not to
be refreshed.

But everything is ok in OpenEV 1.80

I also tried adding "display_change()" function calls to force it to
refresh, but it doesn't change anything.

Hope it helps you figure it out.

If you need anything else, just let me know

Related to the "earth like" icon, is there a way to force a view to be in
the georeference mode by any command ?

David

----- Original Message ----- 
From: "Frank Warmerdam" <fwarmerdam at gmail.com>
To: "David Legault" <dlegault at vantpoint.com>
Cc: "Dev - FWTools - MList" <fwtools at lists.maptools.org>
Sent: Tuesday, April 05, 2005 12:02 PM
Subject: Re: [FWTools] FWTools Shapes Refresh Problem


> On Apr 5, 2005 10:18 AM, David Legault <dlegault at vantpoint.com> wrote:
> >
> >
> > Hello Frank,
> >
> > I've been developping stuff for OpenEV recently and the contractor asked
me
> > to move on to FWTools to test compatibility.
> >
> > I found an issue which I can't find the cause which works in OpenEV, but
> > fails in FWTools.
> >
> > Basically, I have an image and when the user clicks on the map, it
displays,
> > using a shapes layer, a rectangle of fixed width thats surrounds the
clicked
> > location. This rectangle is then plotted into another gui window which
works
> > fine. The problem encountered is that when the user clicks elswhere, the
> > original rectangle is deleted (the shapes of the layer are deleted) and
the
> > new one is added to the shapes.
> >
> > Now in OpenEV 1.80 the refreshing worked just fine, but in FWTools, it
draws
> > the rectangle once and on any subsequent clicks, the rectangle isn't
drawn
> > to the new location and what more, the original rectangle stays drawn
even
> > if it's confirmed that there aren't any shapes left in the object.
>
> David,
>
> Um, I'm afraid I have no idea why this would work differently.
>
> Could you provide something focused on this issue that I could
> do a bit of testing with?
>
> Best regards,
> -- 
> ---------------------------------------+----------------------------------
----
> I set the clouds in motion - turn up   | Frank Warmerdam,
warmerdam at pobox.com
> light and sound - activate the windows | http://pobox.com/~warmerdam
> and watch the world go round - Rush    | Geospatial Programmer for Rent
-------------- next part --------------
#!/usr/bin/python
# -*- coding: iso-8859-1 -*-

from gtk import *

import gview
import GtkExtra
import gviewapp
import gtk
import gdal
import gdalnumeric as gdaln
import Numeric

dialog = None

layer_name = "Test Layer"

###########################################
class TestTool( gviewapp.Tool_GViewApp ):

    ###########################################
    def __init__( self, app = None ):
        gviewapp.Tool_GViewApp.__init__( self, app )
        self.init_menu( )

    ###########################################
    def launch_dialog( self, *args ):

        global dialog

        if dialog == None:
            dialog = TestDialog( )

        dialog.show( )

    ###########################################
    def init_menu( self ):
        self.menu_entries.set_entry( "Tools/Test Tool" ,2 ,self.launch_dialog )


###########################################
class TestDialog( GtkWindow ):

    ###########################################
    def __init__( self, app = None ):
        GtkWindow.__init__( self )
        self.set_title( 'Azimuth Ambiguity Tool' )
        self.set_default_size( 420, 700 )
        self.connect('delete-event', self.close)

        view = gview.app.sel_manager.get_active_view()
        view.connect( 'button-press-event', self.on_view_click, view )

        self.load_image( r"C:\FWTools0.9.6\demo-data\utm.tif" )

        self.create_gui( )
        self.show( )

    ###########################################
    def on_view_click( self, *args ):

        print "Clicking"

        global dialog

        if dialog != None:

            xy = args[0].get_pointer( )

            self.point_data = xy

            print self.point_data

            self.update_point_target( )

    ###########################################
    def update_point_target( self ):

        print "------------------------"

        self.clear_shapes( )
        self.draw_target_region( self.point_data, self.get_sub_region_size( ) )
        self.update_sub_view_display( self.view2, self.point_data )

    ###########################################
    def update_sub_view_display( self, view, xy ):

        self.clear_layers( view )

        arr = self.get_sub_region_array( xy, self.get_sub_region_size( ) )
        if arr != None:

            #print arr
            view_ds = gdaln.OpenArray( arr )
            imgraster = gview.GvRaster( dataset=view_ds )
            imgrlayer = gview.GvRasterLayer( raster = imgraster )
            view.add_layer( imgrlayer )

    ###########################################
    def clear_layers( self, view ):

         layer_list = view.list_layers( )
         for layer in layer_list:
             view.remove_layer( layer )

    ###########################################
    def get_sub_region_array( self, xy, size = 50 ):
    
        p1_x = int( round( xy[0] - size/2 ) )
        p1_y = int( round( xy[1] - size/2 ) )
        p2_x = int( round( xy[0] + size/2 ) )
        p2_y = int( round( xy[1] + size/2 ) )

        if p1_x > p2_x:
           temp = p2_x
           p2_x = p1_x
           p1_x = temp

        if p1_y > p2_y:
           temp = p2_y
           p2_y = p1_y
           p1_y = temp

        if p1_x < 0:
            p1_x = 0

        if p1_y < 0:
            p1_y = 0

        if p2_x > self.layer_ds.RasterXSize:
            p2_x = self.layer_ds.RasterXSize

        if p2_y > self.layer_ds.RasterYSize:
            p2_y = self.layer_ds.RasterYSize
            
        if p2_x < 0 or p1_x > self.layer_ds.RasterXSize or p2_y < 0 or p1_y > self.layer_ds.RasterYSize \
        or p1_y == p2_y or p1_x == p2_x:
            return None;

        return self.layer_ds.ReadAsArray( p1_x, p1_y, abs( p2_x - p1_x ), abs( p2_y - p1_y ) )

    ###########################################
    def clear_shapes( self ):
    
        print "Clearing Shapes ..."

        layer = self.get_pquery_layer( )

        if layer != None:

            # get Shapes layer to append points
            shapes = layer.get_parent( )

            # if shapes layer exists
            if shapes != None and shapes.__len__( ) > 0:

                print shapes.__len__( )
                #print dir(shapes)
                #ls = self.get_shape_list( shapes )
                shapes.delete_shapes( range( shapes.__len__( ) ) )

            print shapes.__len__( )


    ###########################################
    def draw_target_region( self, xy, size=50, color=None ):

        print "Drawing target regions ..."

        layer = self.get_pquery_layer( )

        p1_x = int( round( xy[0] - size/2 ) )
        p1_y = int( round( xy[1] - size/2 ) )
        p2_x = int( round( xy[0] + size/2 ) )
        p2_y = int( round( xy[1] + size/2 ) )

        #print p1_x, p1_y, p2_x, p2_y

        if layer != None:
        
           # get Shapes layer to append points
               shapes = layer.get_parent( )

               # if shapes layer exists
               if shapes != None:
               
                   #print "Making new shape..."

                   # Make a new Point Shape and add to Shapes Layer
                   shape = gview.GvShape( type=gview.GVSHAPE_POINT )
                   if color != None:
                       shape.set_property( '_gv_color', color )

                   #print dir(shape)
                   shape.set_node( xy[0], xy[1], 0.0, 0 )
                   shapes.append( shape )

                   shape2 = gview.GvShape( type=gview.GVSHAPE_LINE )
                   if color != None:
                       shape2.set_property( '_gv_color', color )

                   shape2.set_node( p1_x, p1_y, 0.0, 0 )
                   shape2.set_node( p2_x, p1_y, 0.0, 1 )
                   shape2.set_node( p2_x, p2_y, 0.0, 2 )
                   shape2.set_node( p1_x, p2_y, 0.0, 3 )
                   shape2.set_node( p1_x, p1_y, 0.0, 4 )
                   shapes.append( shape2 )

    ###########################################
    def get_sub_region_size( self ):

        return 50

    ###########################################
    def show( self ):
        GtkWindow.show_all( self )

    ###########################################
    def close( self, *args ):

        global dialog
        dialog = None
        self.destroy( )

    ###########################################
    def create_gui( self ):

        # vertical main box
        self.mbox = GtkVBox( spacing = 2 )
        self.mbox.set_border_width( 2 )
        # add box to dialog
        self.add( self.mbox )

        self.frame3_2 = GtkFrame( "Selection Target" )
        self.mbox.pack_start( self.frame3_2 )
        self.view2 = gview.GvViewArea( )
        self.frame3_2.add( self.view2 )

    ###########################################
    def get_pquery_layer( self ):

        global layer_name
        # get active view
        view = gview.app.sel_manager.get_active_view( )

        result_layer = None

        # if there is a view
        if view != None:

            # list of all layers
            layer_list = view.list_layers()

            # layer cycling
            for layer in layer_list:

                #found existing layer
                if layer.get_property('shape') != None and layer.get_name( ) == layer_name:
                    result_layer = layer

        return result_layer

    ###########################################
    def create_pquery_layer( self ):

        # did not find existing layer, create a new one
        if self.get_pquery_layer( ) == None:
        
            # get active view
            view = gview.app.sel_manager.get_active_view( )

            result_layer = gview.GvShapesLayer()
            #print dir( result_layer )
            result_layer.set_name( layer_name )
            #print result_layer.get_properties( )
            result_layer.set_selection_mode( 1 )
            #result_layer.signal_connect( 'changed', gcp_point_changed, result_layer )
            #print result_layer
            gview.undo_register( result_layer.get_parent( ) )
            result_layer.set_property( 'shape', 'true' )
            view.add_layer( result_layer )
            # set read only property on layer
            result_layer.set_read_only( TRUE )

            # set layer as the active one
            view.set_active_layer( result_layer )
            
    ###########################################
    def load_image( self, imgfile ):

        # image file not empty
        if imgfile is not None:

            self.layer_ds=gdal.Open( imgfile )

            self.raster_data = gview.GvRaster( dataset=self.layer_ds )
            self.raster_layer = gview.GvRasterLayer( raster=self.raster_data )

            view = gview.app.sel_manager.get_active_view()
            view.add_layer( self.raster_layer )
            view.set_active_layer( self.raster_layer )
            
            self.create_pquery_layer( )

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

TOOL_LIST = ['TestTool']


More information about the FWTools mailing list