Ejemplo n.º 1
0
    def on_reliefClassTree_itemDoubleClicked(self, item, column):
        if not item:
            return

        if column == 0:
            d, ok = QInputDialog.getDouble(None,
                                           self.tr('Enter lower elevation class bound'),
                                           self.tr('Elevation'),
                                           float(item.text(0)),
                                           decimals=2)
            if ok:
                item.setText(0, str(d))
        elif column == 1:
            d, ok = QInputDialog.getDouble(None,
                                           self.tr('Enter upper elevation class bound'),
                                           self.tr('Elevation'),
                                           float(item.text(1)),
                                           decimals=2)
            if ok:
                item.setText(1, str(d))
        elif column == 2:
            c = QColorDialog.getColor(item.background(2).color(),
                                      None,
                                      self.tr('Select color for relief class'))
            if c.isValid():
                item.setBackground(2, QBrush(c))
Ejemplo n.º 2
0
    def on_reliefClassTree_itemDoubleClicked(self, item, column):
        if not item:
            return

        if column == 0:
            d, ok = QInputDialog.getDouble(None,
                                           self.tr('Enter lower elevation class bound'),
                                           self.tr('Elevation'),
                                           float(item.text(0)),
                                           decimals=2)
            if ok:
                item.setText(0, str(d))
        elif column == 1:
            d, ok = QInputDialog.getDouble(None,
                                           self.tr('Enter upper elevation class bound'),
                                           self.tr('Elevation'),
                                           float(item.text(1)),
                                           decimals=2)
            if ok:
                item.setText(1, str(d))
        elif column == 2:
            c = QColorDialog.getColor(item.background(2).color(),
                                      None,
                                      self.tr('Select color for relief class'))
            if c.isValid():
                item.setBackground(2, QBrush(c))
Ejemplo n.º 3
0
 def get_interval(self):
     interval, ok = QInputDialog.getDouble(self.parent, 'Podaj interwał', 'Interwał [m]:')
     if not ok:
         self.reset()
         return
     geom = self.tempGeom.asGeometry()
     
     activeCrs = QgsProject.instance().crs().authid()
     fromCrs = QgsCoordinateReferenceSystem(activeCrs)
     toCrs = QgsCoordinateReferenceSystem(2180)
     transformation = QgsCoordinateTransform(fromCrs, toCrs, QgsProject.instance())
     geom.transform(transformation)
     
     meters_len = geom.length()
     if meters_len <= interval:
         self.parent.on_message.emit('Długość linii krótsza lub równa podanemu interwałowi', Qgis.Critical, 5)
         self.reset()
         return
     try:
         num_points = meters_len/interval
     except ZeroDivisionError:
         self.parent.on_message.emit('Interwał musi być większy od 0', Qgis.Critical, 4)
         self.reset()
         return
     points_on_line = []
     max_interval = 0
     intervals = []
     for i in range(int(num_points)+1):
         pt = geom.interpolate(float(max_interval))
         points_on_line.append(pt)
         intervals.append(max_interval)
         max_interval += interval
     data = {'points':points_on_line, 'intervals':intervals}
     self.task = QgsTask.fromFunction('Pobieranie wysokości dla przekroju...', self.generateProfileFromPoints, data=data)
     QgsApplication.taskManager().addTask(self.task)
Ejemplo n.º 4
0
    def drawCircles(self):
        """Draws a circle around the selected points"""

        radius, okPress = QInputDialog.getDouble(
            None,
            'Circle Radius',
            'The circle radius in NM:',
            5,
            0.005,
            decimals=3
        )

        if not okPress:
            return

        try:
            drawing.drawCircles(radius)
        except Exception as e:
            QMessageBox.warning(None, 'QgsOpenScope', str(e))
Ejemplo n.º 5
0
 def canvasReleaseEvent(self, e):
     '''La sélection est faîte'''
     if not e.button() == Qt.LeftButton:
         return None
     self.status = 0
     if self.rb.numberOfVertices() > 3:
         self.selectionDone.emit()
     else:
         radius, ok = QInputDialog.getDouble(
             self.iface.mainWindow(), tr('Radius'),
             tr('Give a radius in m:'), min=0)
         if radius > 0 and ok:
             cp = self.toMapCoordinates(e.pos())
             cp.setX(cp.x() + radius)
             rbcircle(self.rb, self.toMapCoordinates(
                 e.pos()), cp, self.segments)
             self.rb.show()
             self.selectionDone.emit()
     return None
Ejemplo n.º 6
0
 def canvasReleaseEvent(self, e):
     '''La sélection est faîte'''
     if not e.button() == Qt.LeftButton:
         return None
     self.status = 0
     if self.rb.numberOfVertices() > 3:
         self.selectionDone.emit()
     else:
         radius, ok = QInputDialog.getDouble(self.iface.mainWindow(),
                                             self.tr('Radius'),
                                             self.tr('Give a radius in m:'),
                                             min=0)
         if ok:
             cp = self.toMapCoordinates(e.pos())
             cp.setX(cp.x() + radius)
             rbcircle(self.rb, self.toMapCoordinates(e.pos()), cp,
                      self.cercle)
             self.rb.show()
             self.selectionDone.emit()
     return None
Ejemplo n.º 7
0
 def getInterval(self):
     """ Zebranie geometrii punktów na linii zgodnie z zadanym interwałem """
     interval, ok = QInputDialog.getDouble(self.parent, 'Podaj interwał',
                                           'Interwał [m]:')
     if not ok:
         self.reset()
         return
     geom = self.parent.transformGeometry(
         self.tempGeom.asGeometry(),
         current_crs=QgsProject.instance().crs().authid(),
     )
     meters_len = geom.length()
     if meters_len <= interval:
         self.parent.on_message.emit(
             'Długość linii krótsza lub równa podanemu interwałowi',
             Qgis.Critical, 5)
         self.reset()
         return
     try:
         num_points = meters_len / interval
     except ZeroDivisionError:
         self.parent.on_message.emit('Interwał musi być większy od 0',
                                     Qgis.Critical, 4)
         self.reset()
         return
     points_on_line = []
     max_interval = 0
     intervals = []
     for i in range(int(num_points) + 1):
         pt = geom.interpolate(float(max_interval)).asPoint()
         points_on_line.append(f'{pt.y()}%20{pt.x()}')
         intervals.append(max_interval)
         max_interval += interval
     data = {'points': points_on_line, 'intervals': intervals}
     self.task = QgsTask.fromFunction(
         'Pobieranie wysokości dla przekroju...',
         self.generateProfileFromPoints,
         data=data)
     QgsApplication.taskManager().addTask(self.task)
Ejemplo n.º 8
0
    def draw(self):
        rb = self.tool.rb
        g = rb.asGeometry()

        ok = True
        warning = False
        errBuffer_noAtt = False
        errBuffer_Vertices = False

        layer = self.iface.layerTreeView().currentLayer()
        if self.toolname == 'drawBuffer':
            if self.bGeom is None:
                warning = True
                errBuffer_noAtt = True
            else:
                perim, ok = QInputDialog.getDouble(
                    self.iface.mainWindow(),
                    self.tr('Perimeter'),
                    self.tr('Give a perimeter in m:') + '\n' +
                    self.tr('(works only with metric crs)'),
                    min=0)
                g = self.bGeom.buffer(perim, 40)
                rb.setToGeometry(
                    g,
                    QgsVectorLayer("Polygon?crs=" + layer.crs().authid(), "",
                                   "memory"))
                if g.length() == 0 and ok:
                    warning = True
                    errBuffer_Vertices = True

        if self.toolname == 'drawCopies':
            if g.length() < 0:
                warning = True
                errBuffer_noAtt = True

        if ok and not warning:
            name = ''
            ok = True
            add = False
            index = 0
            layers = []
            while not name.strip() and not add and ok:
                dlg = QDrawLayerDialog(self.iface, self.drawShape)
                name, add, index, layers, ok = dlg.getName(
                    self.iface, self.drawShape)
        if ok and not warning:
            layer = None
            if add:
                layer = layers[index]
                if self.drawShape in ['point', 'XYpoint']:
                    g = g.centroid()
            else:
                if self.drawShape == 'point':
                    layer = QgsVectorLayer(
                        "Point?crs=" + self.iface.mapCanvas().mapSettings(
                        ).destinationCrs().authid() + "&field=" +
                        self.tr('Drawings') + ":string(255)", name, "memory")
                    g = g.centroid()  # force geometry as point
                elif self.drawShape == 'XYpoint':
                    layer = QgsVectorLayer(
                        "Point?crs=" + self.XYcrs.authid() + "&field=" +
                        self.tr('Drawings') + ":string(255)", name, "memory")
                    g = g.centroid()
                elif self.drawShape == 'line':
                    layer = QgsVectorLayer(
                        "LineString?crs=" + self.iface.mapCanvas().mapSettings(
                        ).destinationCrs().authid() + "&field=" +
                        self.tr('Drawings') + ":string(255)", name, "memory")
                    # fix_print_with_import
                    print("LineString?crs=" + self.iface.mapCanvas(
                    ).mapSettings().destinationCrs().authid() + "&field=" +
                          self.tr('Drawings') + ":string(255)")
                else:
                    layer = QgsVectorLayer(
                        "Polygon?crs=" + self.iface.mapCanvas().mapSettings(
                        ).destinationCrs().authid() + "&field=" +
                        self.tr('Drawings') + ":string(255)", name, "memory")
            layer.startEditing()
            symbols = layer.renderer().symbols(
                QgsRenderContext())  # todo which context ?
            symbols[0].setColor(self.settings.getColor())
            feature = QgsFeature()
            feature.setGeometry(g)
            feature.setAttributes([name])
            layer.dataProvider().addFeatures([feature])
            layer.commitChanges()
            if not add:
                pjt = QgsProject.instance()
                pjt.addMapLayer(layer, False)
                if pjt.layerTreeRoot().findGroup(self.tr('Drawings')) is None:
                    pjt.layerTreeRoot().insertChildNode(
                        0, QgsLayerTreeGroup(self.tr('Drawings')))
                group = pjt.layerTreeRoot().findGroup(self.tr('Drawings'))
                group.insertLayer(0, layer)
            self.iface.layerTreeView().refreshLayerSymbology(layer.id())
            self.iface.mapCanvas().refresh()
        else:
            if warning:
                if errBuffer_noAtt:
                    self.iface.messageBar().pushWarning(
                        self.tr('Warning'),
                        self.tr('You didn\'t click on a layer\'s attribute !'))
                elif errBuffer_Vertices:
                    self.iface.messageBar().pushWarning(
                        self.tr('Warning'),
                        self.tr('You must give a non-null value for a \
                        point\'s or line\'s perimeter !'))
                else:
                    self.iface.messageBar().pushWarning(
                        self.tr('Warning'),
                        self.tr('There is no selected layer, or it is not \
                                vector nor visible !'))
        self.tool.reset()
        self.resetSB()
        self.bGeom = None
Ejemplo n.º 9
0
    def draw(self):
        rb = self.tool.rb
        g = rb.asGeometry()

        ok = True
        warning = False
        errBuffer_noAtt = False
        errBuffer_Vertices = False

        layer = self.iface.layerTreeView().currentLayer()
        if self.toolname == 'drawBuffer':
            if self.bGeom is None:
                warning = True
                errBuffer_noAtt = True
            else:
                perim, ok = QInputDialog.getDouble(
                    self.iface.mainWindow(), self.tr('Perimeter'),
                    self.tr('Give a perimeter in m:')
                    + '\n'+self.tr('(works only with metric crs)'),
                    min=0)
                g = self.bGeom.buffer(perim, 40)
                rb.setToGeometry(g, QgsVectorLayer(
                    "Polygon?crs="+layer.crs().authid(), "", "memory"))
                if g.length() == 0 and ok:
                    warning = True
                    errBuffer_Vertices = True

        if self.toolname == 'drawCopies':
            if g.length() < 0:
                warning = True
                errBuffer_noAtt = True

        if ok and not warning:
            name = ''
            ok = True
            add = False
            index = 0
            layers = []
            while not name.strip() and not add and ok:
                dlg = QDrawLayerDialog(self.iface, self.drawShape)
                name, add, index, layers, ok = dlg.getName(
                    self.iface, self.drawShape)
        if ok and not warning:
            layer = None
            if add:
                layer = layers[index]
                if self.drawShape in ['point', 'XYpoint']:
                    g = g.centroid()
            else:
                if self.drawShape == 'point':
                    layer = QgsVectorLayer("Point?crs="+self.iface.mapCanvas().mapSettings().destinationCrs().authid()+"&field="+self.tr('Drawings')+":string(255)", name, "memory")
                    g = g.centroid()  # force geometry as point
                elif self.drawShape == 'XYpoint':
                    layer = QgsVectorLayer("Point?crs="+self.XYcrs.authid()+"&field="+self.tr('Drawings')+":string(255)", name, "memory")
                    g = g.centroid()
                elif self.drawShape == 'line':
                    layer = QgsVectorLayer("LineString?crs="+self.iface.mapCanvas().mapSettings().destinationCrs().authid()+"&field="+self.tr('Drawings')+":string(255)", name, "memory")
                    # fix_print_with_import
                    print("LineString?crs="+self.iface.mapCanvas().mapSettings().destinationCrs().authid()+"&field="+self.tr('Drawings')+":string(255)")
                else:
                    layer = QgsVectorLayer("Polygon?crs="+self.iface.mapCanvas().mapSettings().destinationCrs().authid()+"&field="+self.tr('Drawings')+":string(255)", name, "memory")
            layer.startEditing()
            symbols = layer.renderer().symbols(QgsRenderContext())  # todo which context ?
            symbols[0].setColor(self.settings.getColor())
            feature = QgsFeature()
            feature.setGeometry(g)
            feature.setAttributes([name])
            layer.dataProvider().addFeatures([feature])
            layer.commitChanges()
            if not add:
                pjt = QgsProject.instance()
                pjt.addMapLayer(layer, False)
                if pjt.layerTreeRoot().findGroup(self.tr('Drawings')) is None:
                    pjt.layerTreeRoot().insertChildNode(
                        0, QgsLayerTreeGroup(self.tr('Drawings')))
                group = pjt.layerTreeRoot().findGroup(
                    self.tr('Drawings'))
                group.insertLayer(0, layer)
            self.iface.layerTreeView().refreshLayerSymbology(layer.id())
            self.iface.mapCanvas().refresh()
        else:
            if warning:
                if errBuffer_noAtt:
                    self.iface.messageBar().pushWarning(
                        self.tr('Warning'),
                        self.tr('You didn\'t click on a layer\'s attribute !'))
                elif errBuffer_Vertices:
                    self.iface.messageBar().pushWarning(
                        self.tr('Warning'),
                        self.tr('You must give a non-null value for a \
point\'s or line\'s perimeter !'))
                else:
                    self.iface.messageBar().pushWarning(
                        self.tr('Warning'),
                        self.tr('There is no selected layer, or it is not \
vector nor visible !'))
        self.tool.reset()
        self.resetSB()
        self.bGeom = None