def intersection(self): if self.p11 == None or self.p12 == None or self.p21 == None or self.p22 == None: QMessageBox.information( None, QCoreApplication.translate("ctools", "Cancel"), QCoreApplication.translate( "ctools", "Not enough line segments selected.")) else: p = QgsPoint() p = LineIntersection.intersectionPoint(self.p11, self.p12, self.p21, self.p22) g = None g = LineIntersection.intersectionLine(self.p11, self.p12, self.p21, self.p22) if p <> None and g <> None: cadutils.addGeometryToCadLayer(QgsGeometry.fromPoint(p)) cadutils.addGeometryToCadLayer(g) self.canvas.refresh() self.unsetTool() self.deactivate() self.p11 = None self.p12 = None self.p21 = None self.p22 = None
def createParallelLine(self, method, distance): # We need this because adding a layer to the mapcanvas deletes everything.... # Is this true? Why? What happens? p1 = QgsPoint() p2 = QgsPoint() p1.setX(self.p1.x()) p1.setY(self.p1.y()) p2.setX(self.p2.x()) p2.setY( self.p2.y()) print str(method) print str(distance) if method == "fixed": g = ParallelLine.calculateLine(self.p1, self.p2, distance) cadutils.addGeometryToCadLayer(g) self.canvas.refresh() elif method == "vertex": print "************************888" points = [self.p1, self.p2] g = QgsGeometry.fromPolyline(points) g.translate( self.pv.x() - self.p1.x(), self.pv.y() - self.p1.y() ) # print str(g) cadutils.addGeometryToCadLayer(g) self.canvas.refresh() # del self.m1 self.p1 = p1 self.p2 = p2
def ortholineandpoint(self): if self.p1 == None or self.p2 == None or self.p3 == None: QMessageBox.information(None, "Cancel", "Not enough objects selected.") else: # Intersection of the selected segment and the orthogonal line through the selected point # Selektierter Punkt ist Aufpunkt (= p1) # Richtungsvektor ist der Vektor, der rechwinklig zum Differenzvektor # (gebildet aus den beiden Segmentpunkten) liegt (-> x/y vertauschen). xp = self.p1.x() + (self.p3.y()-self.p2.y()) yp = self.p1.y() - (self.p3.x()-self.p2.x()) p0 = QgsPoint(xp, yp) p = LineIntersection.intersectionPoint(self.p1, p0, self.p2, self.p3) line = [self.p1, p] if p <> None: # Draw the point cadutils.addGeometryToCadLayer(QgsGeometry.fromPoint(p)) # Draw the line cadutils.addGeometryToCadLayer(QgsGeometry.fromPolyline(line)) self.canvas.refresh() self.unsetTool() self.deactivate() else: self.unsetTool() return self.p1 = None self.p2 = None self.p3 = None
def ortholineandpoint(self): if self.p1 == None or self.p2 == None or self.p3 == None: QMessageBox.information(None, QCoreApplication.translate("ctools", "Cancel"), QCoreApplication.translate("ctools", "Not enough objects selected.")) else: # Intersection of the selected segment and the orthogonal line through the selected point # Selektierter Punkt ist Aufpunkt (= p1) # Richtungsvektor ist der Vektor, der rechwinklig zum Differenzvektor # (gebildet aus den beiden Segmentpunkten) liegt (-> x/y vertauschen). xp = self.p1.x() + (self.p3.y()-self.p2.y()) yp = self.p1.y() - (self.p3.x()-self.p2.x()) p0 = QgsPoint(xp, yp) p = LineIntersection.intersectionPoint(self.p1, p0, self.p2, self.p3) line = [self.p1, p] if p <> None: # Draw the point cadutils.addGeometryToCadLayer(QgsGeometry.fromPoint(p)) # Draw the line cadutils.addGeometryToCadLayer(QgsGeometry.fromPolyline(line)) self.canvas.refresh() self.unsetTool() self.deactivate() else: self.unsetTool() return self.p1 = None self.p2 = None self.p3 = None
def calculateTraverse(self, traverse, x1, y1, x2, y2, adjust, addLine): # Azimuth Startingpoint to Endpoint referenceAzimuth = cadutils.azimuth(QgsPoint(x1, y1), QgsPoint(x2, y2)) # Create the line in a local coordinatesystem: # - origin is the starting point # - azimuth is 0 line = OrthogonalTraverse.traverse(traverse, 0, 1) if line == None: print "Line is None!" else: points = line.asPolyline() # Azimuth of the new line (first to last point of the line) actualAzimuth = cadutils.azimuth(points[0], points[-1]) # Difference of reference distance and actual distance diff = 100 * (cadutils.distance(QgsPoint(x1, y1), QgsPoint(x2, y2)) - cadutils.distance(points[0], points[-1])) # number of characters to show as "Fs" if diff > 10: digit = math.ceil(math.log10(abs(diff))) else: digit = 1 digit += 3 if diff < 0: digit += 1 # update the difference ("Fs") text in the GUI self.ctrl.lineEditFs.setText( str(diff)[:int(digit)] + str(" [cm]")) # If the OK button was clicked we will rotate and if desired scale/adjust # the line and add it to the map canvas. if addLine == True: rotationAngle = actualAzimuth - referenceAzimuth scale = cadutils.distance(QgsPoint(x1, y1), QgsPoint( x2, y2)) / cadutils.distance(points[0], points[-1]) print str("scale ") + str(scale) if adjust == True: lineTransformed = cadutils.helmert2d( line, x1, y1, rotationAngle, scale) else: lineTransformed = cadutils.helmert2d( line, x1, y1, rotationAngle, 1.0) if lineTransformed <> None: cadutils.addGeometryToCadLayer(lineTransformed) self.canvas.refresh() else: QMessageBox.information( None, QCoreApplication.translate("ctools", "Warning"), QCoreApplication.translate( "ctools", "Error while transforming geometry."))
def calculateTraverse(self, traverse, x1, y1, x2, y2, adjust, addLine): # Azimuth Startingpoint to Endpoint referenceAzimuth = cadutils.azimuth(QgsPoint(x1,y1), QgsPoint(x2,y2)) # Create the line in a local coordinatesystem: # - origin is the starting point # - azimuth is 0 line = OrthogonalTraverse.traverse(traverse, 0, 1) if line == None: print "Line is None!" else: points = line.asPolyline() # Azimuth of the new line (first to last point of the line) actualAzimuth = cadutils.azimuth( points[0], points[-1] ) # Difference of reference distance and actual distance diff = 100* (cadutils.distance(QgsPoint(x1,y1), QgsPoint(x2,y2)) - cadutils.distance(points[0], points[-1])) # number of characters to show as "Fs" if diff > 10: digit = math.ceil(math.log10(abs(diff))) else: digit = 1 digit += 3 if diff < 0: digit += 1 # update the difference ("Fs") text in the GUI self.ctrl.lineEditFs.setText(str(diff)[:int(digit)] + str( " [cm]")); # If the OK button was clicked we will rotate and if desired scale/adjust # the line and add it to the map canvas. if addLine == True: rotationAngle = actualAzimuth - referenceAzimuth scale = cadutils.distance(QgsPoint(x1,y1), QgsPoint(x2,y2)) / cadutils.distance(points[0], points[-1]) print str("scale ") + str(scale) if adjust == True: lineTransformed = cadutils.helmert2d(line, x1, y1, rotationAngle, scale) else: lineTransformed = cadutils.helmert2d(line, x1, y1, rotationAngle, 1.0) if lineTransformed <> None: cadutils.addGeometryToCadLayer(lineTransformed) self.canvas.refresh() else: QMessageBox.information(None, "Warning", "Error while transforming geometry.")
def calculateArcIntersection(self, dist1, dist2): result = ArcIntersection.intersectionPoint(self.p1, self.p2, dist1, dist2) if result == 0: mc = self.canvas mc.unsetMapTool(self.tool) return else: cadutils.addGeometryToCadLayer(QgsGeometry.fromPoint(result[0])) cadutils.addGeometryToCadLayer(QgsGeometry.fromPoint(result[1])) self.canvas.refresh() mc = self.canvas mc.unsetMapTool(self.tool) self.deactivate()
def createCircularArc(self): settings = QSettings("CatAIS","cadtools") method = settings.value("arcs/featuremethod", "pitch") if method == "pitch": value = settings.value("arcs/featurepitch", 2) else: value = settings.value("arcs/featureangle", 1) if self.p1 == None or self.p2 == None or self.p3 == None: QMessageBox.information(None, "Cancel", "Not enough points selected.") else: g = CircularArc.getInterpolatedArc(self.p1, self.p2, self.p3, method.toString(), value.toDouble()[0]) cadutils.addGeometryToCadLayer(g) self.canvas.refresh() self.unsetTool()
def createCircularArc(self): settings = QSettings("CatAIS","cadtools") method = settings.value("arcs/featuremethod", "pitch") if method == "pitch": value = settings.value("arcs/featurepitch", 2, type=float) else: value = settings.value("arcs/featureangle", 1, type=float) if self.p1 == None or self.p2 == None or self.p3 == None: QMessageBox.information(None, QCoreApplication.translate("ctools", "Cancel"), QCoreApplication.translate("ctools", "Not enough points selected.")) else: g = CircularArc.getInterpolatedArc(self.p1, self.p2, self.p3, method, value) cadutils.addGeometryToCadLayer(g) self.canvas.refresh() self.unsetTool()
def intersect_line(self): if self.p11 == None or self.p12 == None or self.p21 == None or self.p22 == None: QMessageBox.information(None, "Cancel", "Not enough line segments selected.") else: g = None g = LineIntersection.intersectionLine(self.p11, self.p12, self.p21, self.p22) if g <> None: cadutils.addGeometryToCadLayer(g) self.canvas.refresh() self.unsetTool() self.deactivate() self.p11 = None self.p12 = None self.p21 = None self.p22 = None
def createCircularArc(self): settings = QSettings("CatAIS", "cadtools") method = settings.value("arcs/featuremethod", "pitch") if method == "pitch": value = settings.value("arcs/featurepitch", 2) else: value = settings.value("arcs/featureangle", 1) if self.p1 == None or self.p2 == None or self.p3 == None: QMessageBox.information(None, "Cancel", "Not enough points selected.") else: g = CircularArc.getInterpolatedArc(self.p1, self.p2, self.p3, method.toString(), value.toDouble()[0]) cadutils.addGeometryToCadLayer(g) self.canvas.refresh() self.unsetTool()
def calculateRectangularPoint(self, dX, dY, inverse): # I still don't get it..... pt1 = QgsPoint() pt1.setX(self.p1.x()) pt1.setY(self.p1.y()) pt2 = QgsPoint() pt2.setX(self.p2.x()) pt2.setY(self.p2.y()) # Calculate the new (rectangular) Point result = RectangularPoint.point(pt1, pt2, dX, dY, inverse) if result == 0: mc = self.canvas mc.unsetMapTool(self.tool) return else: cadutils.addGeometryToCadLayer(QgsGeometry.fromPoint(result)) self.canvas.refresh() self.p1 = pt1 self.p2 = pt2
def intersection(self): if self.p11 == None or self.p12 == None or self.p21 == None or self.p22 == None: QMessageBox.information(None, QCoreApplication.translate("ctools", "Cancel"), QCoreApplication.translate("ctools", "Not enough line segments selected.")) else: p = QgsPoint() p = LineIntersection.intersectionPoint(self.p11, self.p12, self.p21, self.p22) g = None g = LineIntersection.intersectionLine(self.p11, self.p12, self.p21, self.p22) if p <> None and g <> None: cadutils.addGeometryToCadLayer(QgsGeometry.fromPoint(p)) cadutils.addGeometryToCadLayer(g) self.canvas.refresh() self.unsetTool() self.deactivate() self.p11 = None self.p12 = None self.p21 = None self.p22 = None
def rotateObject(self, angle): geom = cadutils.rotate(self.feat.geometry(), self.p1, angle * math.pi / 180) if geom <> None: cadutils.addGeometryToCadLayer(geom) self.canvas.refresh()