コード例 #1
0
    def UpdateSettings(self):
        """Update digitizer settings

        .. todo::
            Needs refactoring
        """
        self._giface.workspaceChanged.emit()
        # symbology
        for key, (enabled, color) in six.iteritems(self.symbology):
            if enabled:
                UserSettings.Set(
                    group="vdigit",
                    key="symbol",
                    subkey=[key, "enabled"],
                    value=enabled.IsChecked(),
                )
                UserSettings.Set(
                    group="vdigit",
                    key="symbol",
                    subkey=[key, "color"],
                    value=tuple(color.GetColour()),
                )
            else:
                UserSettings.Set(
                    group="vdigit",
                    key="symbol",
                    subkey=[key, "color"],
                    value=tuple(color.GetColour()),
                )
        # display
        UserSettings.Set(
            group="vdigit",
            key="lineWidth",
            subkey="value",
            value=int(self.lineWidthValue.GetValue()),
        )

        # snapping
        UserSettings.Set(
            group="vdigit",
            key="snapping",
            subkey="value",
            value=self.snappingValue.GetValue(),
        )
        UserSettings.Set(
            group="vdigit",
            key="snapping",
            subkey="unit",
            value=self.snappingUnit.GetSelection(),
        )
        UserSettings.Set(
            group="vdigit",
            key="snapToVertex",
            subkey="enabled",
            value=self.snapVertex.IsChecked(),
        )

        # digitize new feature
        UserSettings.Set(
            group="vdigit",
            key="addRecord",
            subkey="enabled",
            value=self.addRecord.IsChecked(),
        )
        UserSettings.Set(
            group="vdigit",
            key="layer",
            subkey="value",
            value=int(self.layer.GetValue()),
        )
        UserSettings.Set(
            group="vdigit",
            key="category",
            subkey="value",
            value=int(self.category.GetValue()),
        )
        UserSettings.Set(
            group="vdigit",
            key="categoryMode",
            subkey="selection",
            value=self.categoryMode.GetSelection(),
        )

        # delete existing feature
        UserSettings.Set(
            group="vdigit",
            key="delRecord",
            subkey="enabled",
            value=self.deleteRecord.IsChecked(),
        )

        # geometry attributes (workspace)
        mapLayer = self.parent.toolbars["vdigit"].GetLayer()
        tree = self._giface.GetLayerTree()
        if tree:
            item = tree.FindItemByData("maplayer", mapLayer)
        else:
            item = None
        for key, val in six.iteritems(self.geomAttrb):
            checked = self.FindWindowById(val["check"]).IsChecked()
            column = self.FindWindowById(val["column"]).GetValue()
            unitsIdx = self.FindWindowById(val["units"]).GetSelection()
            if item and not tree.GetLayerInfo(item, key="vdigit"):
                tree.SetLayerInfo(item,
                                  key="vdigit",
                                  value={"geomAttr": dict()})

            if checked:  # enable
                if key == "area":
                    type = key
                else:
                    type = "length"
                unitsKey = Units.GetUnitsKey(type, unitsIdx)
                tree.GetLayerInfo(item, key="vdigit")["geomAttr"][key] = {
                    "column": column,
                    "units": unitsKey,
                }
            else:
                if (item and tree.GetLayerInfo(item, key="vdigit") and key
                        in tree.GetLayerInfo(item, key="vdigit")["geomAttr"]):
                    del tree.GetLayerInfo(item, key="vdigit")["geomAttr"][key]

        # query tool
        if self.queryLength.GetValue():
            UserSettings.Set(group="vdigit",
                             key="query",
                             subkey="selection",
                             value=0)
        else:
            UserSettings.Set(group="vdigit",
                             key="query",
                             subkey="type",
                             value=1)
        UserSettings.Set(group="vdigit",
                         key="query",
                         subkey="box",
                         value=self.queryBox.IsChecked())
        UserSettings.Set(
            group="vdigit",
            key="queryLength",
            subkey="than-selection",
            value=self.queryLengthSL.GetSelection(),
        )
        UserSettings.Set(
            group="vdigit",
            key="queryLength",
            subkey="thresh",
            value=self.queryLengthValue.GetValue(),
        )
        UserSettings.Set(
            group="vdigit",
            key="queryDangle",
            subkey="than-selection",
            value=self.queryDangleSL.GetSelection(),
        )
        UserSettings.Set(
            group="vdigit",
            key="queryDangle",
            subkey="thresh",
            value=int(self.queryDangleValue.GetValue()),
        )

        # select features
        for feature in ("point", "line", "centroid", "boundary"):
            UserSettings.Set(
                group="vdigit",
                key="selectType",
                subkey=[feature, "enabled"],
                value=self.FindWindowById(
                    self.selectFeature[feature]).IsChecked(),
            )
        UserSettings.Set(
            group="vdigit",
            key="selectThresh",
            subkey="value",
            value=int(self.selectThreshValue.GetValue()),
        )
        UserSettings.Set(
            group="vdigit",
            key="checkForDupl",
            subkey="enabled",
            value=self.checkForDupl.IsChecked(),
        )
        UserSettings.Set(
            group="vdigit",
            key="selectInside",
            subkey="enabled",
            value=self.selectIn.IsChecked(),
        )

        # on-exit
        UserSettings.Set(
            group="vdigit",
            key="saveOnExit",
            subkey="enabled",
            value=self.save.IsChecked(),
        )

        # break lines
        UserSettings.Set(
            group="vdigit",
            key="breakLines",
            subkey="enabled",
            value=self.intersect.IsChecked(),
        )

        # close boundary
        UserSettings.Set(
            group="vdigit",
            key="closeBoundary",
            subkey="enabled",
            value=self.closeBoundary.IsChecked(),
        )

        self.digit.UpdateSettings()

        # redraw map if auto-rendering is enabled
        if self.parent.IsAutoRendered():
            self.parent.OnRender(None)
コード例 #2
0
    def _createAttributesPage(self, notebook):
        """Create notebook page for attributes"""
        panel = wx.Panel(parent=notebook, id=wx.ID_ANY)
        notebook.AddPage(page=panel, text=_("Attributes"))

        border = wx.BoxSizer(wx.VERTICAL)

        #
        # add new record
        #
        box = StaticBox(parent=panel,
                        id=wx.ID_ANY,
                        label=" %s " % _("Digitize new feature"))
        sizer = wx.StaticBoxSizer(box, wx.VERTICAL)

        # checkbox
        self.addRecord = CheckBox(parent=panel,
                                  id=wx.ID_ANY,
                                  label=_("Add new record into table"))
        self.addRecord.SetValue(
            UserSettings.Get(group="vdigit", key="addRecord",
                             subkey="enabled"))
        sizer.Add(self.addRecord,
                  proportion=0,
                  flag=wx.ALL | wx.EXPAND,
                  border=1)
        # settings
        flexSizer = wx.FlexGridSizer(cols=2, hgap=3, vgap=3)
        flexSizer.AddGrowableCol(0)
        settings = ((_("Layer"), 1), (_("Category"), 1), (_("Mode"),
                                                          _("Next to use")))
        # layer
        text = StaticText(parent=panel, id=wx.ID_ANY, label=_("Layer"))
        self.layer = SpinCtrl(parent=panel,
                              id=wx.ID_ANY,
                              size=(125, -1),
                              min=1,
                              max=1e3)
        self.layer.SetValue(
            int(UserSettings.Get(group="vdigit", key="layer", subkey="value")))
        flexSizer.Add(text, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
        flexSizer.Add(self.layer,
                      proportion=0,
                      flag=wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL)
        # category number
        text = StaticText(parent=panel,
                          id=wx.ID_ANY,
                          label=_("Category number"))
        self.category = SpinCtrl(
            parent=panel,
            id=wx.ID_ANY,
            size=(125, -1),
            initial=UserSettings.Get(group="vdigit",
                                     key="category",
                                     subkey="value"),
            min=-1e9,
            max=1e9,
        )
        if (UserSettings.Get(
                group="vdigit", key="categoryMode", subkey="selection") != 1):
            self.category.Enable(False)
        flexSizer.Add(text, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
        flexSizer.Add(
            self.category,
            proportion=0,
            flag=wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL,
        )
        # category mode
        text = StaticText(parent=panel, id=wx.ID_ANY, label=_("Category mode"))
        self.categoryMode = wx.Choice(
            parent=panel,
            id=wx.ID_ANY,
            size=(125, -1),
            choices=[_("Next to use"),
                     _("Manual entry"),
                     _("No category")],
        )
        self.categoryMode.SetSelection(
            UserSettings.Get(group="vdigit",
                             key="categoryMode",
                             subkey="selection"))
        flexSizer.Add(text, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
        flexSizer.Add(
            self.categoryMode,
            proportion=0,
            flag=wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL,
        )

        sizer.Add(flexSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=1)
        border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)

        #
        # delete existing record
        #
        box = StaticBox(parent=panel,
                        id=wx.ID_ANY,
                        label=" %s " % _("Delete existing feature(s)"))
        sizer = wx.StaticBoxSizer(box, wx.VERTICAL)

        # checkbox
        self.deleteRecord = CheckBox(parent=panel,
                                     id=wx.ID_ANY,
                                     label=_("Delete record from table"))
        self.deleteRecord.SetValue(
            UserSettings.Get(group="vdigit", key="delRecord",
                             subkey="enabled"))
        sizer.Add(self.deleteRecord,
                  proportion=0,
                  flag=wx.ALL | wx.EXPAND,
                  border=1)
        border.Add(
            sizer,
            proportion=0,
            flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
            border=5,
        )

        #
        # geometry attributes (currently only length and area are supported)
        #
        box = StaticBox(parent=panel,
                        id=wx.ID_ANY,
                        label=" %s " % _("Geometry attributes"))
        sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
        gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
        self.geomAttrb = {
            "length": {
                "label": _("length")
            },
            "area": {
                "label": _("area")
            },
            "perimeter": {
                "label": _("perimeter")
            },
        }

        digitToolbar = self.parent.toolbars["vdigit"]
        try:
            vectorName = digitToolbar.GetLayer().GetName()
        except AttributeError:
            vectorName = None  # no vector selected for editing
        layer = UserSettings.Get(group="vdigit", key="layer", subkey="value")
        mapLayer = self.parent.toolbars["vdigit"].GetLayer()
        tree = self.parent.tree
        if tree:
            item = tree.FindItemByData("maplayer", mapLayer)
        else:
            item = None
        row = 0
        for attrb in ["length", "area", "perimeter"]:
            # checkbox
            check = 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 = ColumnSelect(parent=panel, size=(200, -1))
            column.InsertColumns(
                vector=vectorName,
                layer=layer,
                excludeKey=True,
                type=["integer", "double precision"],
            )
            # units
            if attrb == "area":
                choices = Units.GetUnitsList("area")
            else:
                choices = Units.GetUnitsList("length")
            win_units = wx.Choice(parent=panel,
                                  id=wx.ID_ANY,
                                  choices=choices,
                                  size=(120, -1))

            # default values
            check.SetValue(False)
            if (item and tree.GetLayerInfo(item, key="vdigit")
                    and "geomAttr" in tree.GetLayerInfo(item, key="vdigit")
                    and attrb in tree.GetLayerInfo(item,
                                                   key="vdigit")["geomAttr"]):
                check.SetValue(True)
                column.SetStringSelection(
                    tree.GetLayerInfo(
                        item, key="vdigit")["geomAttr"][attrb]["column"])
                if attrb == "area":
                    type = "area"
                else:
                    type = "length"
                unitsIdx = Units.GetUnitsIndex(
                    type,
                    tree.GetLayerInfo(
                        item, key="vdigit")["geomAttr"][attrb]["units"],
                )
                win_units.SetSelection(unitsIdx)

            if not vectorName:
                check.Enable(False)
                column.Enable(False)

            if not check.IsChecked():
                column.Enable(False)

            self.geomAttrb[attrb]["check"] = check.GetId()
            self.geomAttrb[attrb]["column"] = column.GetId()
            self.geomAttrb[attrb]["units"] = win_units.GetId()

            gridSizer.Add(check, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, 0))
            gridSizer.Add(column, pos=(row, 1))
            gridSizer.Add(win_units, pos=(row, 2))
            row += 1

        note = "\n".join(
            textwrap.wrap(
                _("Note: These settings are stored "
                  "in the workspace not in the vector digitizer "
                  "preferences."),
                55,
            ))
        gridSizer.Add(StaticText(parent=panel, id=wx.ID_ANY, label=note),
                      pos=(3, 0),
                      span=(1, 3))

        gridSizer.AddGrowableCol(0)
        sizer.Add(gridSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=1)
        border.Add(
            sizer,
            proportion=0,
            flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
            border=5,
        )

        # bindings
        self.Bind(wx.EVT_CHECKBOX, self.OnChangeAddRecord, self.addRecord)
        self.Bind(wx.EVT_CHOICE, self.OnChangeCategoryMode, self.categoryMode)
        self.Bind(wx.EVT_SPINCTRL, self.OnChangeLayer, self.layer)

        panel.SetSizer(border)

        return panel
コード例 #3
0
    def UpdateSettings(self):
        """Update digitizer settings

        .. todo::
            Needs refactoring 
        """
        # TODO: it seems that it needs to be replaced by signal
        # but if it makes sense generally for wxGUI it can be added to giface
        if self.parent.GetLayerManager():
            self.parent.GetLayerManager().WorkspaceChanged(
            )  # geometry attributes
        # symbology
        for key, (enabled, color) in self.symbology.iteritems():
            if enabled:
                UserSettings.Set(group='vdigit',
                                 key='symbol',
                                 subkey=[key, 'enabled'],
                                 value=enabled.IsChecked())
                UserSettings.Set(group='vdigit',
                                 key='symbol',
                                 subkey=[key, 'color'],
                                 value=tuple(color.GetColour()))
            else:
                UserSettings.Set(group='vdigit',
                                 key='symbol',
                                 subkey=[key, 'color'],
                                 value=tuple(color.GetColour()))
        # display
        UserSettings.Set(group='vdigit',
                         key="lineWidth",
                         subkey='value',
                         value=int(self.lineWidthValue.GetValue()))

        # snapping
        UserSettings.Set(group='vdigit',
                         key="snapping",
                         subkey='value',
                         value=int(self.snappingValue.GetValue()))
        UserSettings.Set(group='vdigit',
                         key="snapping",
                         subkey='units',
                         value=self.snappingUnit.GetStringSelection())
        UserSettings.Set(group='vdigit',
                         key="snapToVertex",
                         subkey='enabled',
                         value=self.snapVertex.IsChecked())

        # digitize new feature
        UserSettings.Set(group='vdigit',
                         key="addRecord",
                         subkey='enabled',
                         value=self.addRecord.IsChecked())
        UserSettings.Set(group='vdigit',
                         key="layer",
                         subkey='value',
                         value=int(self.layer.GetValue()))
        UserSettings.Set(group='vdigit',
                         key="category",
                         subkey='value',
                         value=int(self.category.GetValue()))
        UserSettings.Set(group='vdigit',
                         key="categoryMode",
                         subkey='selection',
                         value=self.categoryMode.GetSelection())

        # delete existing feature
        UserSettings.Set(group='vdigit',
                         key="delRecord",
                         subkey='enabled',
                         value=self.deleteRecord.IsChecked())

        # geometry attributes (workspace)
        mapLayer = self.parent.toolbars['vdigit'].GetLayer()
        tree = self._giface.GetLayerTree()
        if tree:
            item = tree.FindItemByData('maplayer', mapLayer)
        else:
            item = None
        for key, val in self.geomAttrb.iteritems():
            checked = self.FindWindowById(val['check']).IsChecked()
            column = self.FindWindowById(val['column']).GetValue()
            unitsIdx = self.FindWindowById(val['units']).GetSelection()
            if item and not tree.GetLayerInfo(item, key='vdigit'):
                tree.SetLayerInfo(item,
                                  key='vdigit',
                                  value={'geomAttr': dict()})

            if checked:  # enable
                if key == 'area':
                    type = key
                else:
                    type = 'length'
                unitsKey = Units.GetUnitsKey(type, unitsIdx)
                tree.GetLayerInfo(item, key='vdigit')['geomAttr'][key] = {
                    'column': column,
                    'units': unitsKey
                }
            else:
                if item and tree.GetLayerInfo(item, key = 'vdigit') and \
                        key in tree.GetLayerInfo(item, key = 'vdigit')['geomAttr']:
                    del tree.GetLayerInfo(item, key='vdigit')['geomAttr'][key]

        # query tool
        if self.queryLength.GetValue():
            UserSettings.Set(group='vdigit',
                             key="query",
                             subkey='selection',
                             value=0)
        else:
            UserSettings.Set(group='vdigit',
                             key="query",
                             subkey='type',
                             value=1)
        UserSettings.Set(group='vdigit',
                         key="query",
                         subkey='box',
                         value=self.queryBox.IsChecked())
        UserSettings.Set(group='vdigit',
                         key="queryLength",
                         subkey='than-selection',
                         value=self.queryLengthSL.GetSelection())
        UserSettings.Set(group='vdigit',
                         key="queryLength",
                         subkey='thresh',
                         value=int(self.queryLengthValue.GetValue()))
        UserSettings.Set(group='vdigit',
                         key="queryDangle",
                         subkey='than-selection',
                         value=self.queryDangleSL.GetSelection())
        UserSettings.Set(group='vdigit',
                         key="queryDangle",
                         subkey='thresh',
                         value=int(self.queryDangleValue.GetValue()))

        # select features
        for feature in ('point', 'line', 'centroid', 'boundary'):
            UserSettings.Set(group='vdigit',
                             key='selectType',
                             subkey=[feature, 'enabled'],
                             value=self.FindWindowById(
                                 self.selectFeature[feature]).IsChecked())
        UserSettings.Set(group='vdigit',
                         key="selectThresh",
                         subkey='value',
                         value=int(self.selectThreshValue.GetValue()))
        UserSettings.Set(group='vdigit',
                         key="checkForDupl",
                         subkey='enabled',
                         value=self.checkForDupl.IsChecked())
        UserSettings.Set(group='vdigit',
                         key="selectInside",
                         subkey='enabled',
                         value=self.selectIn.IsChecked())

        # on-exit
        UserSettings.Set(group='vdigit',
                         key="saveOnExit",
                         subkey='enabled',
                         value=self.save.IsChecked())

        # break lines
        UserSettings.Set(group='vdigit',
                         key="breakLines",
                         subkey='enabled',
                         value=self.intersect.IsChecked())

        # close boundary
        UserSettings.Set(group='vdigit',
                         key="closeBoundary",
                         subkey='enabled',
                         value=self.closeBoundary.IsChecked())

        self.digit.UpdateSettings()

        # redraw map if auto-rendering is enabled
        if self.parent.IsAutoRendered():
            self.parent.OnRender(None)