[GRASS-SVN] r37910 - in grass/branches/develbranch_6/gui/wxpython: gui_modules vdigit

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jun 16 14:47:00 EDT 2009


Author: martinl
Date: 2009-06-16 14:47:00 -0400 (Tue, 16 Jun 2009)
New Revision: 37910

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py
   grass/branches/develbranch_6/gui/wxpython/vdigit/digit.h
   grass/branches/develbranch_6/gui/wxpython/vdigit/line.cpp
Log:
wxGUI/vdigit: geometry attributes - area size/perimeter
	      (merge from trunk, r37909)


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py	2009-06-16 18:35:03 UTC (rev 37909)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py	2009-06-16 18:47:00 UTC (rev 37910)
@@ -1145,7 +1145,11 @@
                                                                    cats=cats,
                                                                    pos=posWindow,
                                                                    action="add")
-                
+
+                if not point:
+                    self.__geomAttrb(fid, addRecordDlg, 'area', digitClass)
+                    self.__geomAttrb(fid, addRecordDlg, 'perimeter', digitClass)
+
                 if addRecordDlg.mapDBInfo and \
                         addRecordDlg.ShowModal() == wx.ID_OK:
                     sqlfile = tempfile.NamedTemporaryFile(mode="w")
@@ -1166,17 +1170,25 @@
             self.polycoords.append(self.Pixel2Cell(event.GetPositionTuple()[:]))
             self.DrawLines(pdc=self.pdcTmp)
     
-    def __geomAttrb(self):
+    def __geomAttrb(self, fid, dialog, attrb, digit):
         """!Trac geometry attributes?"""
-        ret = list()
-        for key, val in UserSettings.Get(group = 'vdigit', key = 'geomAttrb',
-                                         internal = True).iteritems():
-            if not val['enabled'] or not val['column']:
-                continue
-            ret.append((key, val['column']))
-
-        return ret
-    
+        if UserSettings.Get(group = 'vdigit', key = 'geomAttrb',
+                            subkey = [attrb, 'enabled'], internal = True):
+            val = -1
+            if attrb == 'length':
+                val = digit.GetLineLength(fid)
+            elif attrb == 'area':
+                val = digit.GetAreaSize(fid)
+            elif attrb == 'perimeter':
+                val = digit.GetAreaPerimeter(fid)
+            
+            if val > 0:
+                layer = int(UserSettings.Get(group='vdigit', key="layer", subkey='value'))
+                column =  UserSettings.Get(group = 'vdigit', key = 'geomAttrb',
+                                           subkey = [attrb, 'column'], internal = True)
+                dialog.SetColumnValue(layer, column, val)
+                dialog.OnReset()
+        
     def __updateATM(self):
         """!Update open Attribute Table Manager
 
@@ -1948,6 +1960,7 @@
                     self.redrawAll = True
                     
                     # add new record into atribute table
+                    print UserSettings.Get(group='vdigit', key="addRecord", subkey='enabled'), line, fid
                     if UserSettings.Get(group='vdigit', key="addRecord", subkey='enabled') and \
                             (line is True or \
                                  (not line and fid > 0)):
@@ -1964,13 +1977,12 @@
                                                                            cats=cats,
                                                                            pos=posWindow,
                                                                            action="add")
-                        layer = int(UserSettings.Get(group='vdigit', key="layer", subkey='value'))
-                        for attrb, column in self.__geomAttrb():
-                            if attrb is 'length':
-                                val = digitClass.GetLineLength(fid)
-                            addRecordDlg.SetColumnValue(layer, column, val)
-                        addRecordDlg.OnReset()
-                        
+
+                        self.__geomAttrb(fid, addRecordDlg, 'length', digitClass)
+                        # auto-placing centroid
+                        self.__geomAttrb(fid, addRecordDlg, 'area', digitClass)
+                        self.__geomAttrb(fid, addRecordDlg, 'perimeter', digitClass)
+
                         if addRecordDlg.mapDBInfo and \
                                addRecordDlg.ShowModal() == wx.ID_OK:
                             sqlfile = tempfile.NamedTemporaryFile(mode="w")

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py	2009-06-16 18:35:03 UTC (rev 37909)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py	2009-06-16 18:47:00 UTC (rev 37910)
@@ -559,6 +559,8 @@
                                                                    'column' : '' }
         self.internalSettings['vdigit']['geomAttrb']['area']   = { 'enabled' : False,
                                                                    'column' : '' }
+        self.internalSettings['vdigit']['geomAttrb']['perimeter']   = { 'enabled' : False,
+                                                                        'column' : '' }
         
     def ReadSettingsFile(self, settings=None):
         """!Reads settings file (mapset, location, gisdbase)"""

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py	2009-06-16 18:35:03 UTC (rev 37909)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py	2009-06-16 18:47:00 UTC (rev 37910)
@@ -610,10 +610,30 @@
         @param line feature id
 
         @return line length
-        @return 0 for non-linear features
+        @return -1 on error
         """
         return self.digit.GetLineLength(line)
+
+    def GetAreaSize(self, centroid):
+        """!Get area size
+
+        @param centroid centroid id
+
+        @return area size
+        @return -1 on error
+        """
+        return self.digit.GetAreaSize(centroid)
         
+    def GetAreaPerimeter(self, centroid):
+        """!Get area perimeter
+
+        @param centroid centroid id
+
+        @return area size
+        @return -1 on error
+        """
+        return self.digit.GetAreaPerimeter(centroid)
+
     def SetLineCats(self, line, layer, cats, add=True):
         """!Set categories for given line and layer
 
@@ -1493,10 +1513,11 @@
         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY,
                               label = " %s " % _("Geometry attributes"))
         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
-        flexSizer = wx.FlexGridSizer(cols=2, hgap=3, vgap=3)
+        flexSizer = wx.FlexGridSizer(cols=3, hgap=3, vgap=3)
         flexSizer.AddGrowableCol(0)
         self.geomAttrb = { 'length' : { 'label' : _('length') },
-                           'area' : { 'label' : _('area') } }
+                           'area' : { 'label' : _('area') },
+                           'perimeter' : { 'label' : _('perimeter') } }
 
         digitToolbar = self.parent.toolbars['vdigit']
         try:
@@ -1504,22 +1525,29 @@
         except AttributeError:
             vectorName = None # no vector selected for editing
         layer = UserSettings.Get(group='vdigit', key="layer", subkey='value')
-        for attrb in self.geomAttrb.keys():
+        for attrb in ['length', 'area', 'perimeter']:
             # checkbox
             check = wx.CheckBox(parent = panel, id = wx.ID_ANY,
                                 label = self.geomAttrb[attrb]['label'])
             ### self.deleteRecord.SetValue(UserSettings.Get(group='vdigit', key="delRecord", subkey='enabled'))
             check.Bind(wx.EVT_CHECKBOX, self.OnGeomAttrb)
             # column (only numeric)
-            column = gselect.ColumnSelect(parent = panel)
+            column = gselect.ColumnSelect(parent = panel, size=(200, -1))
             column.InsertColumns(vector = vectorName,
                                  layer = layer, excludeKey = True,
                                  type = ['integer', 'double precision'])
+            # units 
+            ### TODO: more units
+            units = wx.Choice(parent = panel, id = wx.ID_ANY,
+                              choices = [_("map units")])
             
             # default values
             check.SetValue(UserSettings.Get(group='vdigit', key='geomAttrb',
                                             subkey=[attrb, 'enabled'],
                                             internal=True))
+            column.SetStringSelection(UserSettings.Get(group='vdigit', key='geomAttrb',
+                                                       subkey=[attrb, 'column'],
+                                                       internal=True))
             
             if not vectorName:
                 check.Enable(False)
@@ -1528,12 +1556,14 @@
             if not check.IsChecked():
                 column.Enable(False)
             
-            self.geomAttrb[attrb]['check'] = check.GetId()
+            self.geomAttrb[attrb]['check']  = check.GetId()
             self.geomAttrb[attrb]['column'] = column.GetId()
-            
+            self.geomAttrb[attrb]['units']  = units.GetId()
+
             flexSizer.Add(item = check, proportion = 0,
                           flag = wx.ALIGN_CENTER_VERTICAL)
             flexSizer.Add(item = column, proportion = 0)
+            flexSizer.Add(item = units, proportion = 0)
 
         sizer.Add(item=flexSizer, proportion=1,
                   flag=wx.ALL | wx.EXPAND, border=1)

Modified: grass/branches/develbranch_6/gui/wxpython/vdigit/digit.h
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/digit.h	2009-06-16 18:35:03 UTC (rev 37909)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/digit.h	2009-06-16 18:47:00 UTC (rev 37910)
@@ -83,7 +83,9 @@
 					int, int, double);
 
     double GetLineLength(int);
-    
+    double GetAreaSize(int);
+    double GetAreaPerimeter(int);
+
     int CopyCats(std::vector<int>, std::vector<int>, bool);
     int GetCategory(int);
     std::map<int, std::vector<int> > GetLineCats(int);

Modified: grass/branches/develbranch_6/gui/wxpython/vdigit/line.cpp
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/line.cpp	2009-06-16 18:35:03 UTC (rev 37909)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/line.cpp	2009-06-16 18:47:00 UTC (rev 37910)
@@ -1046,7 +1046,7 @@
   \param line feature id
 
   \return line length
-  \return 0 for non-linear features
+  \return -1 for non-linear features
 */
 double Digit::GetLineLength(int line)
 {
@@ -1056,18 +1056,75 @@
     struct line_pnts *points;
     
     if (!Vect_line_alive(display->mapInfo, line))
-	return 0;
+	return -1;
     
     points = Vect_new_line_struct();
     
     type = Vect_read_line(display->mapInfo, points, NULL, line);
     
-    if (!(type & GV_LINES))
-	length = 0.0;
-    else
+    length = -1;
+    if (type & GV_LINES)
 	length = Vect_line_length(points);
 
     Vect_destroy_line_struct(points);
 
     return length;
 }
+
+/*!
+  \brief Get area size
+
+  \param centroid centroid id
+
+  \return area in map units
+  \return -1 on error
+*/
+double Digit::GetAreaSize(int centroid)
+{
+    int area;
+    double size;
+    
+    area = Vect_get_centroid_area(display->mapInfo, centroid);
+    size = -1;
+    if (area > 0) {
+	if (!Vect_area_alive(display->mapInfo, area))
+	    return -1;
+	
+	size = Vect_get_area_area(display->mapInfo, area);
+    }
+    
+    return size;
+}
+
+/*!
+  \brief Get area perimeter
+
+  \param centroid centroid id
+
+  \return perimeter in map units
+  \return -1 on error
+*/
+double Digit::GetAreaPerimeter(int centroid)
+{
+    int area;
+    double perimeter;
+    struct line_pnts *points = NULL;
+    
+    area = Vect_get_centroid_area(display->mapInfo, centroid);
+    perimeter = -1;
+    if (area > 0) {
+
+	if (!Vect_area_alive(display->mapInfo, area))
+	return -1;
+    
+	points = Vect_new_line_struct();
+    
+	Vect_get_area_points(display->mapInfo, area, points);
+	perimeter = Vect_area_perimeter(points);
+    }
+    
+    if (points)
+	Vect_destroy_line_struct(points);
+    
+    return perimeter;
+}



More information about the grass-commit mailing list