Przeglądaj źródła

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 lat temu
rodzic
commit
0ea5378579

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

@@ -21,6 +21,7 @@ import os
 import time
 import math
 import sys
+import tempfile
 
 import wx
 
@@ -30,6 +31,7 @@ import gdialogs
 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 @@ class BufferedWindow(MapWindow, wx.Window):
                 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 @@ class BufferedWindow(MapWindow, wx.Window):
                         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 @@ class BufferedWindow(MapWindow, wx.Window):
                     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':

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

@@ -355,7 +355,7 @@ class VDigit(AbstractDigit):
         @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 @@ class VDigit(AbstractDigit):
 
         @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 @@ class VDigit(AbstractDigit):
 
         @param coords coordinates to remove vertex
 
-        @return 1 vertex removed
+        @return id of new feature
         @return 0 nothing changed
         @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_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 @@ int Digit::MoveVertex(double x, double y, double z,
 
     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 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 @@ int Digit::ModifyLineVertex(int add, double x, double y, double z,
 
     Vect_destroy_line_struct(point);
 
-    return ret;
+    return nlines + 1; // feature is write at the end of the file
 }