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 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
Exemple #3
0
        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 intersection(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:
                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 intersect_line(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:
         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   
Exemple #6
0
    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 createFeature(self):

        layer = self.canvas.currentLayer()
        provider = layer.dataProvider()
        fields = layer.pendingFields()
        f = QgsFeature(fields)

        if self.isPolygon and self.mCtrl and self.rb.numberOfVertices() > 3:
            # we will move the first point to close the polygon square... (square??)
            # NO: move the last point!

            # the last segment
            #            pn = self.rb.getPoint(0,  self.rb.numberOfVertices()-2)
            #            pm = self.rb.getPoint(0,  self.rb.numberOfVertices()-1)
            pn = self.rb.getPoint(0, self.rb.numberOfVertices() - 2)
            pm = self.rb.getPoint(0, self.rb.numberOfVertices() - 1)

            p1 = self.rb.getPoint(0, 0)
            p2 = self.rb.getPoint(0, 1)

            # but we need a line segment that is orthogonal to the last segment
            # der letzte Punkt ist der Aufpunkt
            # der Richtungsvektor ist der Vektor, der rechwinklig zum Differenzvektor pn-pm liegt (-> x/y vertauschen)
            d = ((pn.x() - pm.x())**2 + (pn.y() - pm.y())**2)**0.5
            xp = p1.x() + (p1.y() - p2.y())
            yp = p1.y() - (p1.x() - p2.x())
            pp = QgsPoint(xp, yp)

            p0 = LineIntersection.intersectionPoint(pn, pm, p1, pp)
            self.rb.movePoint(self.rb.numberOfVertices() - 1, p0, 0)

        coords = []
        [
            coords.append(self.rb.getPoint(0, i))
            for i in range(self.rb.numberOfVertices())
        ]

        ## On the Fly reprojection.
        layerEPSG = cadutils.authidToCrs(layer.crs().authid())
        projectEPSG = cadutils.authidToCrs(
            self.canvas.mapRenderer().destinationCrs().authid())

        if layerEPSG != projectEPSG:
            coords_tmp = coords[:]
            coords = []
            for point in coords_tmp:
                transformedPoint = self.canvas.mapRenderer(
                ).mapToLayerCoordinates(layer, point)
                coords.append(transformedPoint)

        ## Add geometry to feature.
        if self.isPolygon == True:
            g = QgsGeometry().fromPolygon([coords])
        else:
            g = QgsGeometry().fromPolyline(coords)
        f.setGeometry(g)

        ## Add attributefields to feature.
        for field in fields.toList():
            ix = fields.indexFromName(field.name())
            f[field.name()] = provider.defaultValue(ix)

        layer.beginEditCommand("Feature added")
        layer.addFeature(f)
        layer.endEditCommand()

        # reset rubberband and refresh the canvas
        if self.type == 1:
            self.isPolygon = False
            self.rb.reset()
        else:
            self.isPolygon = True
            self.rb.reset(QGis.Polygon)

        self.canvas.refresh()
  def createFeature(self):
     
    layer = self.canvas.currentLayer() 
    provider = layer.dataProvider()
    f = QgsFeature()

    if self.isPolygon == True:
        if self.mCtrl == True:
            # we will move the first point to close the polygon square... (square??)
        
            # the last segment 
            pn = self.rb.getPoint(0,  self.rb.numberOfVertices()-2)
            pm = self.rb.getPoint(0,  self.rb.numberOfVertices()-1)
        
            # but we need a line segment that ist orthogonal to the last segment
            # der letzte Punkt ist der Aufpunkt
            # der Richtungsvektor ist der Vektor, der rechwinklig zum Differenzvektor pn-pm liegt (-> x/y vertauschen)
            d = ( (pn.x()-pm.x())**2 + (pn.y()-pm.y())**2 )**0.5
            xp = pm.x() + (pm.y()-pn.y()) 
            yp = pm.y() - (pm.x()-pn.x())  
            pp = QgsPoint(xp,  yp)
        
            p0 = LineIntersection.intersectionPoint(self.rb.getPoint(0,  0),  self.rb.getPoint(0,  1),  pm,  pp)
            self.rb.movePoint(0,  p0,  0)
        
    coords = []
    [coords.append(self.rb.getPoint(0, i)) for i in range(self.rb.numberOfVertices())]
    
    ## On the Fly reprojection.
    layerEPSG = layer.srs().epsg()
    projectEPSG = self.canvas.mapRenderer().destinationSrs().epsg()
    
    if layerEPSG != projectEPSG:
        coords_tmp = coords[:]
        coords = []
        for point in coords_tmp:
            transformedPoint = self.canvas.mapRenderer().mapToLayerCoordinates( layer, point );
            coords.append(transformedPoint)
          
    ## Add geometry to feature.
    if self.isPolygon == True:
        g = QgsGeometry().fromPolygon([coords])
    else:
        g = QgsGeometry().fromPolyline(coords)
    f.setGeometry(g)
        
    ## Add attributefields to feature.
    fields = layer.pendingFields()
    for i in fields:
        f.addAttribute(i,  provider.defaultValue(i))
            
    layer.beginEditCommand("Feature added")
    layer.addFeature(f)
    layer.endEditCommand()
        
    # reset rubberband and refresh the canvas
    if self.type == 1:
        self.isPolygon = False
    else:
        self.isPolygon = True
        
    self.rb.reset(self.isPolygon)
    self.canvas.refresh()
Exemple #9
0
    def createFeature(self):

        layer = self.canvas.currentLayer()
        provider = layer.dataProvider()
        fields = layer.pendingFields()
        f = QgsFeature(fields)

        if self.isPolygon and self.mCtrl and self.rb.numberOfVertices() > 3:

            pn = self.rb.getPoint(0, self.rb.numberOfVertices() - 2)
            pm = self.rb.getPoint(0, self.rb.numberOfVertices() - 1)

            p1 = self.rb.getPoint(0, 0)
            p2 = self.rb.getPoint(0, 1)

            d = ((pn.x() - pm.x())**2 + (pn.y() - pm.y())**2)**0.5
            xp = p1.x() + (p1.y() - p2.y())
            yp = p1.y() - (p1.x() - p2.x())
            pp = QgsPoint(xp, yp)

            p0 = LineIntersection.intersectionPoint(pn, pm, p1, pp)
            self.rb.movePoint(self.rb.numberOfVertices() - 1, p0, 0)

        coords = []
        [
            coords.append(self.rb.getPoint(0, i))
            for i in range(self.rb.numberOfVertices())
        ]

        ## On the Fly reprojection.
        layerEPSG = utils.authidToCrs(layer.crs().authid())
        projectEPSG = utils.authidToCrs(
            self.canvas.mapRenderer().destinationCrs().authid())

        if layerEPSG != projectEPSG:
            coords_tmp = coords[:]
            coords = []
            for point in coords_tmp:
                transformedPoint = self.canvas.mapRenderer(
                ).mapToLayerCoordinates(layer, point)
                coords.append(transformedPoint)

        ## Add geometry to feature.
        if self.isPolygon == True:
            g = QgsGeometry().fromPolygon([coords])
        else:
            g = QgsGeometry().fromPolyline(coords)
        f.setGeometry(g)

        ## Add attributefields to feature.
        for field in fields.toList():
            ix = fields.indexFromName(field.name())
            f[field.name()] = provider.defaultValue(ix)

        layer.beginEditCommand("Feature added")
        layer.addFeature(f)
        layer.endEditCommand()

        # reset rubberband and refresh the canvas
        if self.type == 1:
            self.isPolygon = False
            self.rb.reset()
        else:
            self.isPolygon = True
            self.rb.reset(QGis.Polygon)

        self.canvas.refresh()