コード例 #1
0
ファイル: duplicate_tool.py プロジェクト: dsavary/VDLTools
 def __polygonPreview(self, distance):
     """
     To create the preview (rubberBand) of the duplicate polygon at a certain distance
     :param distance: the given distance
     """
     self.__rubberBand = QgsRubberBand(self.canvas(), QGis.Line)
     polygon_v2, curved = GeometryV2.asPolygonV2(self.__selectedFeature.geometry(), self.__iface)
     self.__newFeature = QgsCurvePolygonV2()
     line_v2 = self.__newPolygonCurve(polygon_v2.exteriorRing(), distance, curved[0])
     self.__newFeature.setExteriorRing(line_v2)
     self.__rubberBand.setToGeometry(QgsGeometry(line_v2.curveToLine()), None)
     for num in range(polygon_v2.numInteriorRings()):
         if self.__dstDlg.isInverted():
             distance = -distance
         line_v2 = self.__newPolygonCurve(polygon_v2.interiorRing(num), distance, curved[num+1])
         self.__newFeature.addInteriorRing(line_v2)
         self.__rubberBand.addGeometry(QgsGeometry(line_v2.curveToLine()), None)
コード例 #2
0
    def asPolygonV2(geometry, iface):
        """
        To get the feature geometry from a polygon as a QgsCurvePolygonV2
        :param geometry: the feature geometry
        :param iface: interface
        :return: the polygon as QgsCurvePolygonV2 , and true if it has curves or false if it hasn't, or none
        """
        wktPolygon = geometry.exportToWkt()
        curved = []
        if wktPolygon.startswith('PolygonZ'):
            polygon = wktPolygon.replace('PolygonZ', '')
        elif wktPolygon.startswith('Polygon'):
            polygon = wktPolygon.replace('Polygon', '')
        elif wktPolygon.startswith('CurvePolygonZ'):
            polygon = wktPolygon.replace('CurvePolygonZ', '')
        elif wktPolygon.startswith('CurvePolygon'):
            polygon = wktPolygon.replace('CurvePolygon', '')
        else:
            iface.messageBar().pushMessage(
                QCoreApplication.translate("VDLTools", "This geometry is not yet implemented"),
                level=QgsMessageBar.WARNING)
            return None
        polygon = polygon.strip()[1:-1]
        lines = polygon.split('),')
        polygonV2 = QgsCurvePolygonV2()
        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]

            if i == 0:
                polygonV2.setExteriorRing(GeometryV2.__createLine(line.split(','), curved[i]))
            else:
                polygonV2.addInteriorRing(GeometryV2.__createLine(line.split(','), curved[i]))
        return polygonV2, curved
コード例 #3
0
    def asPolygonV2(geometry):
        """
        To get the feature geometry from a polygon as a QgsCurvePolygonV2
        (as soon as the geometry().geometry() is crashing)
        :param geometry: the feature geometry
        :return: the polygon as QgsCurvePolygonV2 , and true if it has curves or false if it hasn't, or none
        """
        wktPolygon = geometry.exportToWkt()
        curved = []
        if  wktPolygon.startswith('PolygonZ'):
            polygon = wktPolygon.replace('PolygonZ', '')
        elif wktPolygon.startswith('Polygon'):
            polygon = wktPolygon.replace('Polygon', '')
        elif wktPolygon.startswith('CurvePolygonZ'):
            polygon = wktPolygon.replace('CurvePolygonZ', '')
        elif wktPolygon.startswith('CurvePolygon'):
            polygon = wktPolygon.replace('CurvePolygon', '')
        else:
            print "This geometry is not yet implemented"
            return None
        polygon = polygon.strip()[1:-1]
        lines = polygon.split('),')
        polygonV2 = QgsCurvePolygonV2()
        for i in xrange(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]

            if i == 0:
                polygonV2.setExteriorRing(GeometryV2.__createLine(line.split(','), curved[i]))
            else:
                polygonV2.addInteriorRing(GeometryV2.__createLine(line.split(','), curved[i]))
        return polygonV2, curved
コード例 #4
0
ファイル: move_tool.py プロジェクト: ponceta/VDLTools
 def __polygonPreview(self, point):
     """
     To create a polygon geometry preview (rubberBand)
     :param point: new position as mapPoint
     """
     polygon_v2, curved = GeometryV2.asPolygonV2(
         self.__selectedFeature.geometry())
     vertex = polygon_v2.vertexAt(self.__polygonVertexId(polygon_v2))
     dx = vertex.x() - point.x()
     dy = vertex.y() - point.y()
     self.__newFeature = QgsCurvePolygonV2()
     self.__rubberBand = QgsRubberBand(self.__canvas, QGis.Line)
     line_v2 = self.__newLine(polygon_v2.exteriorRing(), dx, dy, curved[0])
     self.__newFeature.setExteriorRing(line_v2)
     self.__rubberBand.setToGeometry(QgsGeometry(line_v2.curveToLine()),
                                     None)
     for num in xrange(polygon_v2.numInteriorRings()):
         line_v2 = self.__newLine(polygon_v2.interiorRing(num), dx, dy,
                                  curved[num + 1])
         self.__newFeature.addInteriorRing(line_v2)
         self.__rubberBand.addGeometry(QgsGeometry(line_v2.curveToLine()),
                                       None)