コード例 #1
0
    def OnLeftDownAddLine(self, event):
        """Left mouse button pressed - add new feature"""
        try:
            mapLayer = self.toolbar.GetLayer().GetName()
        except:
            return

        if self.toolbar.GetAction("type") in ["point", "centroid"]:
            # add new point / centroiud
            east, north = self.Pixel2Cell(self.mouse["begin"])
            nfeat, fids = self.digit.AddFeature(
                self.toolbar.GetAction("type"), [(east, north)]
            )
            if nfeat < 1:
                return

            self.UpdateMap(render=False)  # redraw map

            # add new record into attribute table
            if UserSettings.Get(group="vdigit", key="addRecord", subkey="enabled"):
                # select attributes based on layer and category
                cats = {
                    fids[0]: {
                        UserSettings.Get(group="vdigit", key="layer", subkey="value"): (
                            UserSettings.Get(
                                group="vdigit", key="category", subkey="value"
                            ),
                        )
                    }
                }

                posWindow = self.ClientToScreen(
                    (
                        self.mouse["end"][0] + self.dialogOffset,
                        self.mouse["end"][1] + self.dialogOffset,
                    )
                )

                addRecordDlg = DisplayAttributesDialog(
                    parent=self,
                    map=mapLayer,
                    cats=cats,
                    pos=posWindow,
                    action="add",
                    ignoreError=True,
                )

                if self.toolbar.GetAction("type") == "centroid":
                    for fid in fids:
                        self._geomAttrb(fid, addRecordDlg, "area")
                        self._geomAttrb(fid, addRecordDlg, "perimeter")

                if addRecordDlg.IsFound():
                    addRecordDlg.ShowModal()
                addRecordDlg.Destroy()

        elif self.toolbar.GetAction("type") in ["line", "boundary", "area"]:
            # add new point to the line
            self.polycoords.append(self.Pixel2Cell(event.GetPosition()))
            self.DrawLines(pdc=self.pdcTmp)
コード例 #2
0
    def _onRightUp(self, event):
        """Right mouse button released (confirm action)"""
        action = self.toolbar.GetAction()
        if action == "addLine" and self.toolbar.GetAction("type") in [
            "line",
            "boundary",
            "area",
        ]:
            # -> add new line / boundary
            try:
                mapName = self.toolbar.GetLayer().GetName()
            except:
                mapName = None
                GError(parent=self, message=_("No vector map selected for editing."))

            if mapName:
                if self.toolbar.GetAction("type") == "line":
                    line = True
                else:
                    line = False

                if len(self.polycoords) < 2:  # ignore 'one-point' lines
                    return

                nfeat, fids = self.digit.AddFeature(
                    self.toolbar.GetAction("type"), self.polycoords
                )
                if nfeat < 0:
                    return

                position = self.Cell2Pixel(self.polycoords[-1])
                self.polycoords = []
                self.UpdateMap(render=False)
                self.redrawAll = True
                self.Refresh()

                # add new record into attribute table
                if self._addRecord() and (line is True or (not line and nfeat > 0)):
                    posWindow = self.ClientToScreen(
                        (
                            position[0] + self.dialogOffset,
                            position[1] + self.dialogOffset,
                        )
                    )

                    # select attributes based on layer and category
                    cats = {
                        fids[0]: {
                            UserSettings.Get(
                                group="vdigit", key="layer", subkey="value"
                            ): (
                                UserSettings.Get(
                                    group="vdigit", key="category", subkey="value"
                                ),
                            )
                        }
                    }

                    addRecordDlg = DisplayAttributesDialog(
                        parent=self,
                        map=mapName,
                        cats=cats,
                        pos=posWindow,
                        action="add",
                        ignoreError=True,
                    )

                    for fid in fids:
                        self._geomAttrb(fid, addRecordDlg, "length")
                        # auto-placing centroid
                        self._geomAttrb(fid, addRecordDlg, "area")
                        self._geomAttrb(fid, addRecordDlg, "perimeter")

                    if addRecordDlg.IsFound():
                        addRecordDlg.ShowModal()
                    addRecordDlg.Destroy()

        elif action == "deleteLine":
            # -> delete selected vector features
            if self.digit.DeleteSelectedLines() < 0:
                return
            self._updateATM()
        elif action == "deleteArea":
            # -> delete selected vector areas
            if self.digit.DeleteSelectedAreas() < 0:
                return
            self._updateATM()
        elif action == "splitLine":
            # split line
            if self.digit.SplitLine(self.Pixel2Cell(self.mouse["begin"])) < 0:
                return
        elif action == "addVertex":
            # add vertex
            fid = self.digit.AddVertex(self.Pixel2Cell(self.mouse["begin"]))
            if fid < 0:
                return
        elif action == "removeVertex":
            # remove vertex
            fid = self.digit.RemoveVertex(self.Pixel2Cell(self.mouse["begin"]))
            if fid < 0:
                return
            self._geomAttrbUpdate(
                [
                    fid,
                ]
            )
        elif action in ("copyCats", "copyAttrs") and hasattr(self, "copyCatsIds"):
            if action == "copyCats":
                if (
                    self.digit.CopyCats(
                        self.copyCatsList, self.copyCatsIds, copyAttrb=False
                    )
                    < 0
                ):
                    return
            else:
                if (
                    self.digit.CopyCats(
                        self.copyCatsList, self.copyCatsIds, copyAttrb=True
                    )
                    < 0
                ):
                    return

            del self.copyCatsList
            del self.copyCatsIds

            self._updateATM()

        elif action == "editLine" and hasattr(self, "moveInfo"):
            line = self.digit.GetDisplay().GetSelected()[0]
            if self.digit.EditLine(line, self.polycoords) < 0:
                return

            del self.moveInfo

        elif action == "flipLine":
            if self.digit.FlipLine() < 0:
                return
        elif action == "mergeLine":
            if self.digit.MergeLine() < 0:
                return
        elif action == "breakLine":
            if self.digit.BreakLine() < 0:
                return
        elif action == "snapLine":
            if self.digit.SnapLine() < 0:
                return
        elif action == "connectLine":
            if len(self.digit.GetDisplay().GetSelected()) > 1:
                if self.digit.ConnectLine() < 0:
                    return
        elif action == "copyLine":
            if self.digit.CopyLine(self.copyIds) < 0:
                return
            del self.copyIds
            if self.layerTmp:
                self.Map.DeleteLayer(self.layerTmp)
                self.UpdateMap(render=True, renderVector=False)
            del self.layerTmp

        elif action == "zbulkLine" and len(self.polycoords) == 2:
            pos1 = self.polycoords[0]
            pos2 = self.polycoords[1]

            selected = self.digit.GetDisplay().GetSelected()
            dlg = VDigitZBulkDialog(
                parent=self, title=_("Z bulk-labeling dialog"), nselected=len(selected)
            )
            if dlg.ShowModal() == wx.ID_OK:
                if (
                    self.digit.ZBulkLines(
                        pos1, pos2, dlg.value.GetValue(), dlg.step.GetValue()
                    )
                    < 0
                ):
                    return
            self.UpdateMap(render=False)
        elif action == "typeConv":
            # -> feature type conversion
            # - point <-> centroid
            # - line <-> boundary
            if self.digit.TypeConvForSelectedLines() < 0:
                return

        if action != "addLine":
            # unselect and re-render
            self.digit.GetDisplay().SetSelected([])
            self.polycoords = []
            self.UpdateMap(render=False)
コード例 #3
0
    def OnLeftDownDisplayCA(self, event):
        """Left mouse button pressed - vector digitizer display categories
        or attributes action
        """
        try:
            mapLayer = self.toolbar.GetLayer().GetName()
        except:
            return

        coords = self.Pixel2Cell(self.mouse["begin"])

        # unselect
        self.digit.GetDisplay().SetSelected([])

        # select feature by point
        cats = {}
        self.digit.GetDisplay().SelectLineByPoint(coords)

        if not self.digit.GetDisplay().GetSelected():
            for key in ("attributes", "category"):
                if self.parent.dialogs[key] and self.parent.dialogs[key].IsShown():
                    self.parent.dialogs[key].Hide()
            self.UpdateMap(render=False, renderVector=True)
            return

        if UserSettings.Get(group="vdigit", key="checkForDupl", subkey="enabled"):
            lines = self.digit.GetDisplay().GetSelected()
        else:
            lines = (self.digit.GetDisplay().GetSelected()[0],)  # only first found

        for line in lines:
            cats[line] = self.digit.GetLineCats(line)

        posWindow = self.ClientToScreen(
            (
                self.mouse["end"][0] + self.dialogOffset,
                self.mouse["end"][1] + self.dialogOffset,
            )
        )

        if self.toolbar.GetAction() == "displayAttrs":
            # select attributes based on coordinates (all layers)
            if self.parent.dialogs["attributes"] is None:
                self.parent.dialogs["attributes"] = DisplayAttributesDialog(
                    parent=self, map=mapLayer, cats=cats, action="update"
                )
            else:
                # upgrade dialog
                self.parent.dialogs["attributes"].UpdateDialog(cats=cats)

            if (
                self.parent.dialogs["attributes"]
                and self.parent.dialogs["attributes"].mapDBInfo
            ):
                if len(cats.keys()) > 0:
                    # highlight feature & re-draw map
                    if not self.parent.dialogs["attributes"].IsShown():
                        self.parent.dialogs["attributes"].Show()
                else:
                    if (
                        self.parent.dialogs["attributes"]
                        and self.parent.dialogs["attributes"].IsShown()
                    ):
                        self.parent.dialogs["attributes"].Hide()

        else:  # displayCats
            if self.parent.dialogs["category"] is None:
                # open new dialog
                dlg = VDigitCategoryDialog(
                    parent=self,
                    vectorName=mapLayer,
                    cats=cats,
                    pos=posWindow,
                    title=_("Update categories"),
                )
                self.parent.dialogs["category"] = dlg
            else:
                # update currently open dialog
                self.parent.dialogs["category"].UpdateDialog(cats=cats)

            if self.parent.dialogs["category"]:
                if len(cats.keys()) > 0:
                    # highlight feature & re-draw map
                    if not self.parent.dialogs["category"].IsShown():
                        self.parent.dialogs["category"].Show()
                else:
                    if self.parent.dialogs["category"].IsShown():
                        self.parent.dialogs["category"].Hide()

        self.UpdateMap(render=False, renderVector=True)
コード例 #4
0
    def _onRightUp(self, event):
        """!Right mouse button released (confirm action)
        """
        action = self.toolbar.GetAction()
        if action == "addLine" and \
                self.toolbar.GetAction('type') in ["line", "boundary", "area"]:
            # -> add new line / boundary
            try:
                mapName = self.toolbar.GetLayer().GetName()
            except:
                mapName = None
                GError(parent=self,
                       message=_("No vector map selected for editing."))

            if mapName:
                if self.toolbar.GetAction('type') == 'line':
                    line = True
                else:
                    line = False

                if len(self.polycoords) < 2:  # ignore 'one-point' lines
                    return

                nfeat, fids = self.digit.AddFeature(
                    self.toolbar.GetAction('type'), self.polycoords)
                if nfeat < 0:
                    return

                position = self.Cell2Pixel(self.polycoords[-1])
                self.polycoords = []
                self.UpdateMap(render=False)
                self.redrawAll = True
                self.Refresh()

                # add new record into atribute table
                if UserSettings.Get(group = 'vdigit', key = "addRecord", subkey = 'enabled') and \
                        (line is True or \
                             (not line and nfeat > 0)):
                    posWindow = self.ClientToScreen(
                        (position[0] + self.dialogOffset,
                         position[1] + self.dialogOffset))

                    # select attributes based on layer and category
                    cats = {
                        fids[0]: {
                            UserSettings.Get(group='vdigit',
                                             key="layer",
                                             subkey='value'):
                            (UserSettings.Get(group='vdigit',
                                              key="category",
                                              subkey='value'), )
                        }
                    }

                    addRecordDlg = DisplayAttributesDialog(parent=self,
                                                           map=mapName,
                                                           cats=cats,
                                                           pos=posWindow,
                                                           action="add",
                                                           ignoreError=True)

                    for fid in fids:
                        self._geomAttrb(fid, addRecordDlg, 'length')
                        # auto-placing centroid
                        self._geomAttrb(fid, addRecordDlg, 'area')
                        self._geomAttrb(fid, addRecordDlg, 'perimeter')


                    if addRecordDlg.mapDBInfo and \
                            addRecordDlg.ShowModal() == wx.ID_OK:
                        sqlfile = tempfile.NamedTemporaryFile(mode="w")
                        for sql in addRecordDlg.GetSQLString():
                            sqlfile.file.write(sql + ";\n")
                        sqlfile.file.flush()
                        RunCommand('db.execute',
                                   parent=True,
                                   quiet=True,
                                   input=sqlfile.name)

                    if addRecordDlg.mapDBInfo:
                        self._updateATM()

        elif action == "deleteLine":
            # -> delete selected vector features
            if self.digit.DeleteSelectedLines() < 0:
                return
            self._updateATM()
        elif action == "splitLine":
            # split line
            if self.digit.SplitLine(self.Pixel2Cell(self.mouse['begin'])) < 0:
                return
        elif action == "addVertex":
            # add vertex
            fid = self.digit.AddVertex(self.Pixel2Cell(self.mouse['begin']))
            if fid < 0:
                return
        elif action == "removeVertex":
            # remove vertex
            fid = self.digit.RemoveVertex(self.Pixel2Cell(self.mouse['begin']))
            if fid < 0:
                return
            self._geomAttrbUpdate([
                fid,
            ])
        elif action in ("copyCats", "copyAttrs"):
            if action == 'copyCats':
                if self.digit.CopyCats(self.copyCatsList,
                                       self.copyCatsIds,
                                       copyAttrb=False) < 0:
                    return
            else:
                if self.digit.CopyCats(self.copyCatsList,
                                       self.copyCatsIds,
                                       copyAttrb=True) < 0:
                    return

            del self.copyCatsList
            del self.copyCatsIds

            self._updateATM()

        elif action == "editLine" and \
                hasattr(self, "moveInfo"):
            line = self.digit.GetDisplay().GetSelected()[0]
            if self.digit.EditLine(line, self.polycoords) < 0:
                return

            del self.moveInfo

        elif action == "flipLine":
            if self.digit.FlipLine() < 0:
                return
        elif action == "mergeLine":
            if self.digit.MergeLine() < 0:
                return
        elif action == "breakLine":
            if self.digit.BreakLine() < 0:
                return
        elif action == "snapLine":
            if self.digit.SnapLine() < 0:
                return
        elif action == "connectLine":
            if len(self.digit.GetDisplay().GetSelected()) > 1:
                if self.digit.ConnectLine() < 0:
                    return
        elif action == "copyLine":
            if self.digit.CopyLine(self.copyIds) < 0:
                return
            del self.copyIds
            if self.layerTmp:
                self.Map.DeleteLayer(self.layerTmp)
                self.UpdateMap(render=True, renderVector=False)
            del self.layerTmp

        elif action == "zbulkLine" and len(self.polycoords) == 2:
            pos1 = self.polycoords[0]
            pos2 = self.polycoords[1]

            selected = self.digit.GetDisplay().GetSelected()
            dlg = VDigitZBulkDialog(parent=self,
                                    title=_("Z bulk-labeling dialog"),
                                    nselected=len(selected))
            if dlg.ShowModal() == wx.ID_OK:
                if self.digit.ZBulkLines(pos1, pos2, dlg.value.GetValue(),
                                         dlg.step.GetValue()) < 0:
                    return
            self.UpdateMap(render=False)
        elif action == "typeConv":
            # -> feature type conversion
            # - point <-> centroid
            # - line <-> boundary
            if self.digit.TypeConvForSelectedLines() < 0:
                return

        if action != "addLine":
            # unselect and re-render
            self.digit.GetDisplay().SetSelected([])
            self.polycoords = []
            self.UpdateMap(render=False)
コード例 #5
0
    def OnLeftDownAddLine(self, event):
        """!Left mouse button pressed - add new feature
        """
        try:
            mapLayer = self.toolbar.GetLayer().GetName()
        except:
            return

        if self.toolbar.GetAction('type') in ['point', 'centroid']:
            # add new point / centroiud
            east, north = self.Pixel2Cell(self.mouse['begin'])
            nfeat, fids = self.digit.AddFeature(self.toolbar.GetAction('type'),
                                                [(east, north)])
            if nfeat < 1:
                return

            self.UpdateMap(render=False)  # redraw map

            # add new record into atribute table
            if UserSettings.Get(group='vdigit',
                                key="addRecord",
                                subkey='enabled'):
                # select attributes based on layer and category
                cats = {
                    fids[0]: {
                        UserSettings.Get(group='vdigit',
                                         key="layer",
                                         subkey='value'):
                        (UserSettings.Get(group='vdigit',
                                          key="category",
                                          subkey='value'), )
                    }
                }

                posWindow = self.ClientToScreen(
                    (self.mouse['end'][0] + self.dialogOffset,
                     self.mouse['end'][1] + self.dialogOffset))

                addRecordDlg = DisplayAttributesDialog(parent=self,
                                                       map=mapLayer,
                                                       cats=cats,
                                                       pos=posWindow,
                                                       action="add",
                                                       ignoreError=True)

                if self.toolbar.GetAction('type') == 'centroid':
                    for fid in fids:
                        self._geomAttrb(fid, addRecordDlg, 'area')
                        self._geomAttrb(fid, addRecordDlg, 'perimeter')

                if addRecordDlg.mapDBInfo and \
                        addRecordDlg.ShowModal() == wx.ID_OK:
                    sqlfile = tempfile.NamedTemporaryFile(mode="w")
                    for sql in addRecordDlg.GetSQLString():
                        sqlfile.file.write(sql + ";\n")
                    sqlfile.file.flush()

                    RunCommand('db.execute',
                               parent=self,
                               quiet=True,
                               input=sqlfile.name)

                if addRecordDlg.mapDBInfo:
                    self._updateATM()

        elif self.toolbar.GetAction('type') in ["line", "boundary", "area"]:
            # add new point to the line
            self.polycoords.append(self.Pixel2Cell(
                event.GetPositionTuple()[:]))
            self.DrawLines(pdc=self.pdcTmp)