浏览代码

wxGUI/vdigit: update geometry attributes on move/remove vertex
(merge from devbr6, https://trac.osgeo.org/grass/changeset/38074)


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@38077 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa 16 年之前
父节点
当前提交
0ea5378579
共有 3 个文件被更改,包括 63 次插入10 次删除
  1. 56 3
      gui/wxpython/gui_modules/mapdisp_window.py
  2. 3 3
      gui/wxpython/gui_modules/vdigit.py
  3. 4 4
      gui/wxpython/vdigit/vertex.cpp

+ 56 - 3
gui/wxpython/gui_modules/mapdisp_window.py

@@ -21,6 +21,7 @@ import os
 import time
 import time
 import math
 import math
 import sys
 import sys
+import tempfile
 
 
 import wx
 import wx
 
 
@@ -30,6 +31,7 @@ import gdialogs
 import gcmd
 import gcmd
 import utils
 import utils
 import globalvar
 import globalvar
+import gselect
 from debug import Debug
 from debug import Debug
 from preferences import globalSettings as UserSettings
 from preferences import globalSettings as UserSettings
 from units import ConvertValue as UnitsConvertValue
 from units import ConvertValue as UnitsConvertValue
@@ -1198,6 +1200,51 @@ class BufferedWindow(MapWindow, wx.Window):
                 dialog.SetColumnValue(layer, column, val)
                 dialog.SetColumnValue(layer, column, val)
                 dialog.OnReset()
                 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):
     def __updateATM(self):
         """!Update open Attribute Table Manager
         """!Update open Attribute Table Manager
 
 
@@ -1917,8 +1964,11 @@ class BufferedWindow(MapWindow, wx.Window):
                         return
                         return
                 elif digitToolbar.GetAction() == "moveVertex":
                 elif digitToolbar.GetAction() == "moveVertex":
                     # move vertex
                     # move vertex
-                    if digitClass.MoveSelectedVertex(pFrom, move) < 0:
+                    fid = digitClass.MoveSelectedVertex(pFrom, move)
+                    if fid < 0:
                         return
                         return
+
+                    self.__geomAttrbUpdate([fid,])
                 
                 
                 del self.vdigitMove
                 del self.vdigitMove
                 
                 
@@ -2019,12 +2069,15 @@ class BufferedWindow(MapWindow, wx.Window):
                     return
                     return
             elif digitToolbar.GetAction() == "addVertex":
             elif digitToolbar.GetAction() == "addVertex":
                 # add vertex
                 # add vertex
-                if digitClass.AddVertex(self.Pixel2Cell(self.mouse['begin'])) < 0:
+                fid = digitClass.AddVertex(self.Pixel2Cell(self.mouse['begin']))
+                if fid < 0:
                     return
                     return
             elif digitToolbar.GetAction() == "removeVertex":
             elif digitToolbar.GetAction() == "removeVertex":
                 # remove vertex
                 # remove vertex
-                if digitClass.RemoveVertex(self.Pixel2Cell(self.mouse['begin'])) < 0:
+                fid = digitClass.RemoveVertex(self.Pixel2Cell(self.mouse['begin']))
+                if fid < 0:
                     return
                     return
+                self.__geomAttrbUpdate([fid,])
             elif digitToolbar.GetAction() in ("copyCats", "copyAttrs"):
             elif digitToolbar.GetAction() in ("copyCats", "copyAttrs"):
                 try:
                 try:
                     if digitToolbar.GetAction() == 'copyCats':
                     if digitToolbar.GetAction() == 'copyCats':

+ 3 - 3
gui/wxpython/gui_modules/vdigit.py

@@ -355,7 +355,7 @@ class VDigit(AbstractDigit):
         @param coords click coordinates
         @param coords click coordinates
         @param move   X,Y direction
         @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)
         @return 0 vertex not moved (not found, line is not selected)
         """
         """
         snap, thresh = self.__getSnapThreshold()
         snap, thresh = self.__getSnapThreshold()
@@ -378,7 +378,7 @@ class VDigit(AbstractDigit):
 
 
         @param coords coordinates to add vertex
         @param coords coordinates to add vertex
 
 
-        @return 1 vertex added
+        @return id of new feature
         @return 0 nothing changed
         @return 0 nothing changed
         @return -1 on failure
         @return -1 on failure
         """
         """
@@ -395,7 +395,7 @@ class VDigit(AbstractDigit):
 
 
         @param coords coordinates to remove vertex
         @param coords coordinates to remove vertex
 
 
-        @return 1 vertex removed
+        @return id of new feature
         @return 0 nothing changed
         @return 0 nothing changed
         @return -1 on failure
         @return -1 on failure
         """
         """

+ 4 - 4
gui/wxpython/vdigit/vertex.cpp

@@ -28,7 +28,7 @@ extern "C" {
    \param thresh_coords threshold value to identify vertex position
    \param thresh_coords threshold value to identify vertex position
    \param thresh_snap threshold value to snap moved vertex
    \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 0 nothing changed
    \param -1 error
    \param -1 error
 */
 */
@@ -95,7 +95,7 @@ int Digit::MoveVertex(double x, double y, double z,
 
 
     Vect_destroy_line_struct(point);
     Vect_destroy_line_struct(point);
 
 
-    return ret;
+    return nlines + 1; // feature is write at the end of the file
 }
 }
 
 
 /**
 /**
@@ -107,7 +107,7 @@ int Digit::MoveVertex(double x, double y, double z,
    \param x,y,z coordinates (z is used only if map is 3d
    \param x,y,z coordinates (z is used only if map is 3d
    \param thresh threshold value to identify vertex position
    \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 0 nothing changed
    \param -1 error
    \param -1 error
 */
 */
@@ -155,5 +155,5 @@ int Digit::ModifyLineVertex(int add, double x, double y, double z,
 
 
     Vect_destroy_line_struct(point);
     Vect_destroy_line_struct(point);
 
 
-    return ret;
+    return nlines + 1; // feature is write at the end of the file
 }
 }