def __newPolygonCurve(self, curve_v2, distance, curved): """ To create a duplicate curve for a polygon curves :param curve_v2: curve to duplicate :param distance: distance where to :param curved: if the line is curved :return: new duplicate curve """ if curved: new_line_v2 = QgsCircularStringV2() else: new_line_v2 = QgsLineStringV2() points = [] for pos in range(curve_v2.numPoints()): if pos == 0: pos1 = curve_v2.numPoints() - 2 else: pos1 = pos - 1 pos2 = pos if pos == (curve_v2.numPoints() - 1): pos3 = 1 else: pos3 = pos + 1 angle1 = Circle.angle(curve_v2.pointN(pos1), curve_v2.pointN(pos2)) angle2 = Circle.angle(curve_v2.pointN(pos), curve_v2.pointN(pos3)) angle = old_div(float(pi + angle1 + angle2), 2) dist = old_div(float(distance), sin(old_div(float(pi + angle1 - angle2), 2))) points.append(self.__newPoint(angle, curve_v2.pointN(pos), dist)) new_line_v2.setPoints(points) return new_line_v2
def exportToQgsCircularStringV2(self): """Export CADCircle to a QgsCircularStringV2""" QgsCircString = QgsCircularStringV2() QgsCircString.setPoints([ QgsPointV2(p) for p in [self._ptStart, self._ptArc, self._ptEnd] ]) return QgsCircString
def __newArc(self, arc_v2, distance): curve_v2 = QgsCircularStringV2() points = [] circle = Circle(arc_v2.pointN(0), arc_v2.pointN(1), arc_v2.pointN(2)) points.append(self.newPoint(circle.angle1(), arc_v2.pointN(0), distance)) points.append(self.newPoint(circle.angle2(), arc_v2.pointN(1), distance)) points.append(self.newPoint(circle.angle3(), arc_v2.pointN(2), distance)) curve_v2.setPoints(points) return curve_v2
def exportToQgsCircularStringV2(self): """Export CADCircle to a QgsCircularStringV2""" quadrant = self.quadrant() quad = [QgsPointV2(p.x, p.y) for p in quadrant] + \ [QgsPointV2(quadrant[0].x, quadrant[0].y)] QgsCircString = QgsCircularStringV2() QgsCircString.setPoints(quad) return QgsCircString
def __newCurve(self, curved, line_v2, dx, dy): if curved: newCurve = QgsCircularStringV2() else: newCurve = QgsLineStringV2() points = [] for pos in xrange(line_v2.numPoints()): x = line_v2.pointN(pos).x() - dx y = line_v2.pointN(pos).y() - dy pt = QgsPointV2(x, y) pt.addZValue(line_v2.pointN(pos).z()) points.append(pt) newCurve.setPoints(points) return newCurve
def __newArc(self, arc_v2, distance): """ To duplicate a curve at a given distance :param arc_v2: the curve to duplicate :param distance: the given distance :return: the new curve """ curve_v2 = QgsCircularStringV2() points = [] circle = Circle(arc_v2.pointN(0), arc_v2.pointN(1), arc_v2.pointN(2)) points.append(self.__newPoint(circle.angle1(), arc_v2.pointN(0), distance)) points.append(self.__newPoint(circle.angle2(), arc_v2.pointN(1), distance)) points.append(self.__newPoint(circle.angle3(), arc_v2.pointN(2), distance)) curve_v2.setPoints(points) return curve_v2
def __createLine(tab, curved): """ To create a new line V2 from a list of points coordinates :param tab: list of points coordinates :param curved: true if it has curves, false if it hasn't :return: the new line as QgsLineStringV2/QgsCircularStringV2, or none """ if len(tab) < 2: return None points = [] for pt in tab: pt_tab = pt.strip().split() points.append(GeometryV2.__createPoint(pt_tab)) if curved: lineV2 = QgsCircularStringV2() else: lineV2 = QgsLineStringV2() lineV2.setPoints(points) return lineV2
def __onDstOk(self): """ When the Ok button in Intersect Distance Dialog is pushed """ self.__distance = float(self.__dstDlg.observation().text()) circle = QgsCircularStringV2() x = self.__dstDlg.mapPoint().x() y = self.__dstDlg.mapPoint().y() circle.setPoints([ QgsPointV2(x + self.__distance * cos(pi / 180 * a), y + self.__distance * sin(pi / 180 * a)) for a in range(0, 361, 90) ]) lineLayer = self.__lineLayer() lineLayer.startEditing() feature = QgsFeature() feature.setGeometry(QgsGeometry(circle)) fields = lineLayer.pendingFields() feature.setFields(fields) fieldsNames = [fields.at(pos).name() for pos in range(fields.count())] if "distance" in fieldsNames: feature.setAttribute("distance", self.__distance) if "x" in fieldsNames: feature.setAttribute("x", self.__dstDlg.mapPoint().x()) if "y" in fieldsNames: feature.setAttribute("y", self.__dstDlg.mapPoint().y()) lineLayer.addFeature(feature) # lineLayer.updateExtents() lineLayer.commitChanges() # center pointLayer = self.__pointLayer() pointLayer.startEditing() feature = QgsFeature() feature.setGeometry(QgsGeometry().fromPoint(self.__dstDlg.mapPoint())) fields = pointLayer.pendingFields() feature.setFields(fields) pointLayer.addFeature(feature) pointLayer.commitChanges() self.__dstDlg.accept() self.__cancel()
def __newCurve(curved, line_v2, dx, dy): """ To create a new moved line :param curved: if the line is curved :param line_v2: the original line :param dx: x translation :param dy: y translation :return: the new line """ if curved: newCurve = QgsCircularStringV2() else: newCurve = QgsLineStringV2() points = [] for pos in range(line_v2.numPoints()): x = line_v2.pointN(pos).x() - dx y = line_v2.pointN(pos).y() - dy pt = QgsPointV2(x, y) pt.addZValue(line_v2.pointN(pos).z()) points.append(pt) newCurve.setPoints(points) return newCurve
def __newLine(self, curve_v2, dx, dy, curved): """ To create a new moved line for a part of a polygon :param curve_v2: the original line :param dx: x translation :param dy: y translation :return: the line as lineV2 """ if curved: new_line_v2 = QgsCircularStringV2() else: new_line_v2 = QgsLineStringV2() points = [] for pos in xrange(curve_v2.numPoints()): x = curve_v2.pointN(pos).x() - dx y = curve_v2.pointN(pos).y() - dy pt = QgsPointV2(x, y) pt.addZValue(curve_v2.pointN(pos).z()) points.append(pt) new_line_v2.setPoints(points) return new_line_v2