Пример #1
0
 def __linePreview(self, point):
     """
     To create a line geometry preview (rubberBand)
     :param point: new position as mapPoint
     """
     line_v2, curved = GeometryV2.asLineV2(
         self.__selectedFeature.geometry(), self.__iface)
     vertex = QgsPointV2()
     line_v2.pointAt(self.__selectedVertex, vertex)
     self.__rubberBand = QgsRubberBand(self.canvas(), QGis.Line)
     dx = vertex.x() - point.x()
     dy = vertex.y() - point.y()
     if isinstance(curved, (list, tuple)):
         self.__newFeature = QgsCompoundCurveV2()
         for pos in range(line_v2.nCurves()):
             curve_v2 = self.__newCurve(curved[pos], line_v2.curveAt(pos),
                                        dx, dy)
             self.__newFeature.addCurve(curve_v2)
             if pos == 0:
                 self.__rubberBand.setToGeometry(
                     QgsGeometry(curve_v2.curveToLine()), None)
             else:
                 self.__rubberBand.addGeometry(
                     QgsGeometry(curve_v2.curveToLine()), None)
     else:
         self.__newFeature = self.__newCurve(curved, line_v2, dx, dy)
         self.__rubberBand.setToGeometry(
             QgsGeometry(self.__newFeature.curveToLine()), None)
Пример #2
0
 def __linePreview(self, distance):
     """
     To create the preview (rubberBand) of the duplicate line at a certain distance
     :param distance: the given distance
     """
     self.__rubberBand = QgsRubberBand(self.canvas(), QGis.Line)
     line_v2, curved = GeometryV2.asLineV2(
         self.__selectedFeature.geometry(), self.__iface)
     if isinstance(curved, (list, tuple)):
         self.__newFeature = QgsCompoundCurveV2()
         for pos in range(line_v2.nCurves()):
             if curved[pos]:
                 curve_v2 = self.__newArc(line_v2.curveAt(pos), distance)
             else:
                 curve_v2 = self.__newLine(line_v2.curveAt(pos), distance)
             self.__newFeature.addCurve(curve_v2)
             if pos == 0:
                 self.__rubberBand.setToGeometry(
                     QgsGeometry(curve_v2.curveToLine()), None)
             else:
                 self.__rubberBand.addGeometry(
                     QgsGeometry(curve_v2.curveToLine()), None)
     else:
         if curved:
             self.__newFeature = self.__newArc(line_v2, distance)
         else:
             self.__newFeature = self.__newLine(line_v2, distance)
         self.__rubberBand.setToGeometry(
             QgsGeometry(self.__newFeature.curveToLine()), None)
Пример #3
0
    def asLineV2(geometry, iface):
        """
        To get the feature geometry from a line as a QgsLineStringV2/QgsCircularStringV2
        (as soon as the geometry().geometry() is crashing)
        :param geometry: the feature geometry
        :param iface: interface
        :return: the line as QgsLineStringV2/QgsCircularStringV2 , and true if it has curves or false if it hasn't,
        or none
        """
        wktLine = geometry.exportToWkt()
        curved = False
        if wktLine.startswith('LineStringZ'):
            line = wktLine.replace('LineStringZ', '')
        elif wktLine.startswith('LineString'):
            line = wktLine.replace('LineString', '')
        elif wktLine.startswith('CircularStringZ'):
            curved = True
            line = wktLine.replace('CircularStringZ', '')
        elif wktLine.startswith('CircularString'):
            curved = True
            line = wktLine.replace('CircularString', '')
        else:
            if wktLine.startswith('CompoundCurveZ'):
                compound = wktLine.replace('CompoundCurveZ', '')
            elif wktLine.startswith('CompoundCurve'):
                compound = wktLine.replace('CompoundCurve', '')
            else:
                iface.messageBar().pushMessage(
                    QCoreApplication.translate("VDLTools", "This geometry is not yet implemented"),
                    level=QgsMessageBar.WARNING)
                return None
            compound = compound.strip()[1:-1]
            lines = compound.split('),')
            compoundV2 = QgsCompoundCurveV2()
            curved = []
            for i in range(0, len(lines)):
                line = lines[i]
                if line.startswith('CircularStringZ'):
                    curved.append(True)
                    line = line.replace('CircularStringZ', '')
                elif line.startswith('CircularString'):
                    curved.append(True)
                    line = line.replace('CircularString', '')
                else:
                    curved.append(False)
                line = line.strip()[1:-1]

                compoundV2.addCurve(GeometryV2.__createLine(line.split(','), curved[i]))
            return compoundV2, curved

        line = line.strip()[1:-1]
        points = line.split(',')
        return GeometryV2.__createLine(points, curved), curved