[GRASS-SVN] r38077 - in grass/trunk/gui/wxpython: gui_modules vdigit

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jun 25 14:35:09 EDT 2009


Author: martinl
Date: 2009-06-25 14:35:09 -0400 (Thu, 25 Jun 2009)
New Revision: 38077

Modified:
   grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py
   grass/trunk/gui/wxpython/gui_modules/vdigit.py
   grass/trunk/gui/wxpython/vdigit/vertex.cpp
Log:
wxGUI/vdigit: update geometry attributes on move/remove vertex
	      (merge from devbr6, r38074)


Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py	2009-06-25 18:25:54 UTC (rev 38076)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py	2009-06-25 18:35:09 UTC (rev 38077)
@@ -21,6 +21,7 @@
 import time
 import math
 import sys
+import tempfile
 
 import wx
 
@@ -30,6 +31,7 @@
 import gcmd
 import utils
 import globalvar
+import gselect
 from debug import Debug
 from preferences import globalSettings as UserSettings
 from units import ConvertValue as UnitsConvertValue
@@ -1198,6 +1200,51 @@
                 dialog.SetColumnValue(layer, column, val)
                 dialog.OnReset()
         
+    def __geomAttrbUpdate(self, fids):
+        """!Update geometry atrributes of currently selected features
+
+        @param fid list feature id
+        """
+        mapLayer = self.parent.toolbars['vdigit'].GetLayer()
+        vectorName =  mapLayer.GetName()
+        digit = self.parent.digit
+        item = self.tree.FindItemByData('maplayer', mapLayer)
+        vdigit = self.tree.GetPyData(item)[0]['vdigit']
+        
+        if vdigit is None or not vdigit.has_key('geomAttr'):
+            return
+        
+        dbInfo = gselect.VectorDBInfo(vectorName)
+        sqlfile = tempfile.NamedTemporaryFile(mode="w")
+        for fid in fids:
+            for layer, cats in digit.GetLineCats(fid).iteritems():
+                table = dbInfo.GetTable(layer)
+                for attrb, item in vdigit['geomAttr'].iteritems():
+                    val = -1
+                    if attrb == 'length':
+                        val = digit.GetLineLength(fid)
+                        type = attrb
+                    elif attrb == 'area':
+                        val = digit.GetAreaSize(fid)
+                        type = attrb
+                    elif attrb == 'perimeter':
+                        val = digit.GetAreaPerimeter(fid)
+                        type = 'length'
+
+                    if val < 0:
+                        continue
+                    val = UnitsConvertValue(val, type, item['units'])
+                    
+                    for cat in cats:
+                        sqlfile.write('UPDATE %s SET %s = %f WHERE %s = %d;\n' % \
+                                          (table, item['column'], val,
+                                           dbInfo.GetKeyColumn(layer), cat))
+            sqlfile.file.flush()
+            gcmd.RunCommand('db.execute',
+                            parent = True,
+                            quiet = True,
+                            input = sqlfile.name)
+            
     def __updateATM(self):
         """!Update open Attribute Table Manager
 
@@ -1917,8 +1964,11 @@
                         return
                 elif digitToolbar.GetAction() == "moveVertex":
                     # move vertex
-                    if digitClass.MoveSelectedVertex(pFrom, move) < 0:
+                    fid = digitClass.MoveSelectedVertex(pFrom, move)
+                    if fid < 0:
                         return
+
+                    self.__geomAttrbUpdate([fid,])
                 
                 del self.vdigitMove
                 
@@ -2019,12 +2069,15 @@
                     return
             elif digitToolbar.GetAction() == "addVertex":
                 # add vertex
-                if digitClass.AddVertex(self.Pixel2Cell(self.mouse['begin'])) < 0:
+                fid = digitClass.AddVertex(self.Pixel2Cell(self.mouse['begin']))
+                if fid < 0:
                     return
             elif digitToolbar.GetAction() == "removeVertex":
                 # remove vertex
-                if digitClass.RemoveVertex(self.Pixel2Cell(self.mouse['begin'])) < 0:
+                fid = digitClass.RemoveVertex(self.Pixel2Cell(self.mouse['begin']))
+                if fid < 0:
                     return
+                self.__geomAttrbUpdate([fid,])
             elif digitToolbar.GetAction() in ("copyCats", "copyAttrs"):
                 try:
                     if digitToolbar.GetAction() == 'copyCats':

Modified: grass/trunk/gui/wxpython/gui_modules/vdigit.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/vdigit.py	2009-06-25 18:25:54 UTC (rev 38076)
+++ grass/trunk/gui/wxpython/gui_modules/vdigit.py	2009-06-25 18:35:09 UTC (rev 38077)
@@ -355,7 +355,7 @@
         @param coords click coordinates
         @param move   X,Y direction
 
-        @return 1 vertex moved
+        @return id of new feature
         @return 0 vertex not moved (not found, line is not selected)
         """
         snap, thresh = self.__getSnapThreshold()
@@ -378,7 +378,7 @@
 
         @param coords coordinates to add vertex
 
-        @return 1 vertex added
+        @return id of new feature
         @return 0 nothing changed
         @return -1 on failure
         """
@@ -395,7 +395,7 @@
 
         @param coords coordinates to remove vertex
 
-        @return 1 vertex removed
+        @return id of new feature
         @return 0 nothing changed
         @return -1 on failure
         """

Modified: grass/trunk/gui/wxpython/vdigit/vertex.cpp
===================================================================
--- grass/trunk/gui/wxpython/vdigit/vertex.cpp	2009-06-25 18:25:54 UTC (rev 38076)
+++ grass/trunk/gui/wxpython/vdigit/vertex.cpp	2009-06-25 18:35:09 UTC (rev 38077)
@@ -28,7 +28,7 @@
    \param thresh_coords threshold value to identify vertex position
    \param thresh_snap threshold value to snap moved vertex
 
-   \param 1 vertex moved
+   \param id id of the new feature
    \param 0 nothing changed
    \param -1 error
 */
@@ -95,7 +95,7 @@
 
     Vect_destroy_line_struct(point);
 
-    return ret;
+    return nlines + 1; // feature is write at the end of the file
 }
 
 /**
@@ -107,7 +107,7 @@
    \param x,y,z coordinates (z is used only if map is 3d
    \param thresh threshold value to identify vertex position
 
-   \param 1 vertex added/removed
+   \param id id of the new feature
    \param 0 nothing changed
    \param -1 error
 */
@@ -155,5 +155,5 @@
 
     Vect_destroy_line_struct(point);
 
-    return ret;
+    return nlines + 1; // feature is write at the end of the file
 }



More information about the grass-commit mailing list