update question

Didrik Pinte dpinte at itae.be
Fri Sep 29 15:56:38 CEST 2006


Le jeudi 28 septembre 2006 à 21:50 +0200, Bernhard Reiter a écrit :
> Hi Didrik,
> 
> On Thursday 28 September 2006 18:27, Didrik Pinte wrote:
> > I've made little bugfix and one change to the code. Before commiting, i
> > need your opinion on it.
> >
> > Here is the future change log :
> > -----------------------------------------------------------------------
> > 2006-09-28 Didrik Pinte <dpinte at itae.be>
> >
> >     * Thuban/UI/classgen.py: bugfix due to wx2.6 update
> >
> >     * Thuban/UI/view.py: removed non needed declaration
> >
> >     * Thuban/UI/viewport.py : extracted method from LabelShapeAt to
> >     GetLabelPosForShape (see feature request #121 on wald)
> >
> >     * Thuban/UI/selection.py : typo correction
> > -----------------------------------------------------------------------
> 
> my suggestion is to submit in small blocks that belong together.
> So if you have a bunch of simple bugfixes this is fine.
> Execept for the viewport.py change, I would directly commit
> the smaller fixes.

Ok. I'll do that

> 
> > [1] Concerning the modification of the Thuban/UI/viewport.py file, i've
> > just extracted some code of the LabelShapeAt method in order to be used
> > by a more general method that will allow the user to label a complete
> > layer by selecting a field of the associated table. See
> > http://wald.intevation.org/tracker/index.php?func=detail&aid=121&group_id=6
> >&atid=108 The new method GetLabelPosForShape is at the moment in the
> > viewport.py file but IMHO, it could be moved to the Thuban/Model/map.py
> > file. What do you think about this ? Is there an other place that could be
> > more appropriate ?
> 
> Extracting methods, if you need the functionality from different places
> in the code is the right idea. 
> (I am currently commenting offline.)
> Without having seen the method your are extracting I cannot comment
> on the best place. From looking at LabelShapeAt I believe it works quite 
> closly to windows coordinates which I would consider UI dependent.
> So what is your idea in moving thi sot Model/map.py?

Here is the explanation (see code below or diff in attachement). The
piece of code in the old LabelShapeAt method concerning the label
positioning can be used pretty easily for any shape_index and layer. So,
i've extracted all this code to a new method called
GetLabelPosFromShape. This new method return a(x, y, halign, valign)
tuple when called with a layer and a shape_index.

Because the new GetLabelPosFromShape is not really UI related, I would
propose to extract it to Model/map.py.

Thuban/UI/viewport.py - line 951
--------------------------------------------------------------------------
    def LabelShapeAt(self, x, y, text = None):
        """Add or remove a label at window position x, y.

        If there's a label at the given position, remove it. Otherwise
        determine the shape at the position and add a label.

        Return True is an action was performed, False otherwise.
        """
        label_layer = self.map.LabelLayer()
        layer, shape_index = self.find_shape_at(x, y, select_labels = 1)
        if layer is None and shape_index is not None:
            # a label was selected
            label_layer.RemoveLabel(shape_index)
            return True
        elif layer is not None and text:
            (x, y, halign, valign)  = self.GetLabelPosFromShape(layer, \

shape_index)
            label_layer.AddLabel(x, y, text,
                                 halign = halign, valign = valign)
            return True
        return False

    def GetLabelPosFromShape(self, layer, shape_index):
        '''
        Return the label position parameters (x, y, halign, valign) from
the
        shape object
        '''
        proj = self.map.projection
        if proj is not None:
            map_proj = proj
        else:
            map_proj = None
        proj = layer.projection
        if proj is not None:
            layer_proj = proj
        else:
            layer_proj = None

        shapetype = layer.ShapeType()
        if shapetype == SHAPETYPE_POLYGON:
            shapefile = layer.ShapeStore().Shapefile().cobject()
            x, y = shape_centroid(shapefile, shape_index,
                                  map_proj, layer_proj, 1, 1, 0, 0)
            if map_proj is not None:
                x, y = map_proj.Inverse(x, y)
        else:
            shape = layer.Shape(shape_index)
            if shapetype == SHAPETYPE_POINT:
                x, y = shape.Points()[0][0]
            else:
                # assume SHAPETYPE_ARC
                points = shape.Points()[0]
                x, y = points[len(points) / 2]
            if layer_proj is not None:
                x, y = layer_proj.Inverse(x, y)
        if shapetype == SHAPETYPE_POINT:
            halign = ALIGN_LEFT
            valign = ALIGN_CENTER
        elif shapetype == SHAPETYPE_POLYGON:
            halign = ALIGN_CENTER
            valign = ALIGN_CENTER
        elif shapetype == SHAPETYPE_ARC:
            halign = ALIGN_LEFT
            valign = ALIGN_CENTER
        
        return (x, y, halign, valign)
--------------------------------------------------------------------------
> 
> > [2] What do you think about adding a new tool allowing the user to label
> > all the shapes of an existing layer (not only one shape like it is
> > now) ? If the answer is yes, i can easily integrate the work i've just
> > done into the trunk.
> 
> This is a feature I would like.
> Automatical labelling can become quite an art easily, if you take cartographic
> ideas into account, like try to position the labels nicely so that other 
> features can be intentified well and so on.
> Any progress is appreciated. ;)

At the moment, simply using the existing piece of code, it does work
nicely. I'm thinking about developping a simple algorithm of intelligent
label positionning to prevent superposition. I'll go on and let the list
know about the news !

Didrik
-------------- next part --------------
A non-text attachment was scrubbed...
Name: viewport_2708.diff
Type: text/x-patch
Size: 4049 bytes
Desc: not available
Url : http://www.intevation.de/pipermail/thuban-devel/attachments/20060929/6aada1a6/viewport_2708.diff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Ceci est une partie de message
	=?ISO-8859-1?Q?num=E9riquement?= =?ISO-8859-1?Q?_sign=E9e?=
Url : http://www.intevation.de/pipermail/thuban-devel/attachments/20060929/6aada1a6/attachment.bin


More information about the Thuban-devel mailing list

This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)