Example #1
0
def gripStretchQgsLineStringGeometry(geom, basePt, ptListToStretch, offSetX, offSetY, tolerance2ApproxCurve):
   """
   Stira i punti di grip di una linestring che sono contenuti in ptListToStretch
   geom = geometria da stirare
   basePt = punto base
   ptListToStretch = lista dei punti da stirare
   offSetX = spostamento X
   offSetY = spostamento Y
   """
   obj = qad_utils.whatGeomIs(0, geom)
   if (type(obj) != list and type(obj) != tuple):
      objType = obj.whatIs()
      if objType == "CIRCLE": # se é cerchio
         newCircle = gripStretchCircle(obj, basePt, ptListToStretch, offSetX, offSetY, tolerance2ApproxCurve)
         if newCircle is not None:
            return QgsGeometry.fromPolyline(newCircle.asPolyline(tolerance2ApproxCurve))
      elif objType == "ARC": # se é arco
         newArc = gripStretchArc(obj, ptListToStretch, offSetX, offSetY, tolerance2ApproxCurve)
         if newArc is not None:
            return QgsGeometry.fromPolyline(newArc.asPolyline(tolerance2ApproxCurve))
      return None
   
   linearObjectListToStretch = qad_utils.QadLinearObjectList()
   linearObjectListToStretch.fromPolyline(geom.asPolyline())
   
   atPart = 0
   while atPart < linearObjectListToStretch.qty():
      linearObject = linearObjectListToStretch.getLinearObjectAt(atPart)      
      if linearObject.isSegment():
         pt = linearObject.getStartPt()
         if isPtContainedForStretch(pt, ptListToStretch): # se il punto è contenuto in ptListToStretch
            # cambio punto iniziale        
            pt.setX(pt.x() + offSetX)
            pt.setY(pt.y() + offSetY)
            linearObject.setStartPt(pt)
            
         pt = linearObject.getEndPt()
         if isPtContainedForStretch(pt, ptListToStretch): # se il punto è contenuto in ptListToStretch
            # cambio punto finale
            pt.setX(pt.x() + offSetX)
            pt.setY(pt.y() + offSetY)
            linearObject.setEndPt(pt)
      else: # se è arco
         newArc, newInverseFlag = gripStretchArc(linearObject.getArc(), ptListToStretch, offSetX, offSetY, tolerance2ApproxCurve, linearObject.isInverseArc())
         if newArc is None:
            return None
         linearObject.setArc(newArc, newInverseFlag)

      atPart = atPart + 1
   
      pt = linearObjectListToStretch.getCentroid(tolerance2ApproxCurve) # verifico se polilinea ha un centroide
      if pt is not None:
         if isPtContainedForStretch(pt, ptListToStretch): # se il punto è contenuto in ptListToStretch
            linearObjectListToStretch.move(offSetX, offSetY)
   
   pts = linearObjectListToStretch.asPolyline(tolerance2ApproxCurve)
   stretchedGeom = QgsGeometry.fromPolyline(pts)    
      
   return stretchedGeom   
Example #2
0
def getStartEndPointClosestPartWithContext(entity, point, destCrs):
   # legge il punto iniziale e finale della parte più vicina al punto di selezione
   # se non si tratta di cerchio altrimenti ritorna l'oggetto QadCircle
   geom = entity.getGeometry()

   # trasformo la geometria in screen coordinate
   coordTransform = QgsCoordinateTransform(entity.layer.crs(), destCrs) # trasformo la geometria
   geom.transform(coordTransform)         

   return qad_utils.whatGeomIs(point, geom)
Example #3
0
def stretchQgsLineStringGeometry(geom, containerGeom, offSetX, offSetY, tolerance2ApproxCurve):
   """
   Stira i punti di una linestring che sono contenuti in containerGeom
   point = punto da tirare
   containerGeom = può essere una QgsGeometry rappresentante un poligono contenente i punti di geom da stirare
                   oppure una lista dei punti da stirare
   offSetX = spostamento X
   offSetY = spostamento Y
   """
   obj = qad_utils.whatGeomIs(0, geom)
   if (type(obj) != list and type(obj) != tuple):
      objType = obj.whatIs()
      if objType == "CIRCLE": # se é cerchio
         if isPtContainedForStretch(obj.center, containerGeom): # se il punto è contenuto in containerGeom
            obj.center.setX(obj.center.x() + offSetX)
            obj.center.setY(obj.center.y() + offSetY)
         return QgsGeometry.fromPolyline(obj.asPolyline(tolerance2ApproxCurve))         

   stretchedGeom = QgsGeometry(geom)
   snapper = QadSnapper()
   points = snapper.getEndPoints(stretchedGeom)
   del snapper

   linearObjectListToStretch = qad_utils.QadLinearObjectList()
   linearObjectListToStretch.fromPolyline(geom.asPolyline())
   
   for point in points:
      if isPtContainedForStretch(point, containerGeom): # se il punto è contenuto in containerGeom
         atPart = linearObjectListToStretch.containsPt(point)
         while atPart >= 0:
            linearObject = linearObjectListToStretch.getLinearObjectAt(atPart)
            pt = linearObject.getStartPt()        
            if qad_utils.ptNear(pt, point): # cambio punto iniziale
               pt.setX(pt.x() + offSetX)
               pt.setY(pt.y() + offSetY)
               if linearObject.isSegment():
                  linearObject.setStartPt(pt)
               else:
                  oldArc = linearObject.getArc()
                  middlePt = oldArc.getMiddlePt()
                  distFromMiddleChord = qad_utils.getDistance(middlePt, qad_utils.getPerpendicularPointOnInfinityLine(oldArc.getStartPt(), oldArc.getEndPt(), middlePt))
                  
                  newArc = QadArc()
                  if linearObject.isInverseArc():                  
                     middlePt = qad_utils.getMiddlePoint(pt, oldArc.getStartPt())
                     middlePt = qad_utils.getPolarPointByPtAngle(middlePt, \
                                                                 qad_utils.getAngleBy2Pts(pt, oldArc.getStartPt()) + math.pi / 2, \
                                                                 distFromMiddleChord)                  
                     if newArc.fromStartSecondEndPts(oldArc.getStartPt(), middlePt, pt) == False:
                        return None
                  else:
                     middlePt = qad_utils.getMiddlePoint(pt, oldArc.getEndPt())
                     middlePt = qad_utils.getPolarPointByPtAngle(middlePt, \
                                                                 qad_utils.getAngleBy2Pts(pt, oldArc.getEndPt()) - math.pi / 2, \
                                                                 distFromMiddleChord)                  
                     if newArc.fromStartSecondEndPts(pt, middlePt, oldArc.getEndPt()) == False:
                        return None
                  linearObject.setArc(newArc, linearObject.isInverseArc())         
            else:
               pt = linearObject.getEndPt()
               if qad_utils.ptNear(pt, point): # cambio punto finale
                  pt.setX(pt.x() + offSetX)
                  pt.setY(pt.y() + offSetY)
                  if linearObject.isSegment():
                     linearObject.setEndPt(pt)
                  else:
                     oldArc = linearObject.getArc()
                     middlePt = oldArc.getMiddlePt()
                     distFromMiddleChord = qad_utils.getDistance(middlePt, qad_utils.getPerpendicularPointOnInfinityLine(oldArc.getStartPt(), oldArc.getEndPt(), middlePt))
                     
                     newArc = QadArc()
                     if linearObject.isInverseArc():
                        middlePt = qad_utils.getMiddlePoint(pt, oldArc.getEndPt())
                        middlePt = qad_utils.getPolarPointByPtAngle(middlePt, \
                                                                    qad_utils.getAngleBy2Pts(pt, oldArc.getEndPt()) - math.pi / 2, \
                                                                    distFromMiddleChord)                  
                        if newArc.fromStartSecondEndPts(pt, middlePt, oldArc.getEndPt()) == False:
                           return None
                     else:
                        middlePt = qad_utils.getMiddlePoint(pt, oldArc.getStartPt())
                        middlePt = qad_utils.getPolarPointByPtAngle(middlePt, \
                                                                    qad_utils.getAngleBy2Pts(pt, oldArc.getStartPt()) + math.pi / 2, \
                                                                    distFromMiddleChord)                  
                        if newArc.fromStartSecondEndPts(oldArc.getStartPt(), middlePt, pt) == False:
                           return None
                     linearObject.setArc(newArc, linearObject.isInverseArc())            
                  
            atPart = linearObjectListToStretch.containsPt(point, atPart + 1)
            
   pts = linearObjectListToStretch.asPolyline(tolerance2ApproxCurve)
   stretchedGeom = QgsGeometry.fromPolyline(pts)    
      
   return stretchedGeom   
Example #4
0
def gripStretchQgsLineStringGeometry(geom, basePt, ptListToStretch, offSetX, offSetY, tolerance2ApproxCurve):
   """
   Stira i punti di grip di una linestring che sono contenuti in ptListToStretch
   geom = geometria da stirare
   basePt = punto base
   ptListToStretch = lista dei punti da stirare
   offSetX = spostamento X
   offSetY = spostamento Y
   """
   if tolerance2ApproxCurve == None:
      tolerance = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE"))
   else:
      tolerance = tolerance2ApproxCurve
   
   obj = qad_utils.whatGeomIs(0, geom)
   if (type(obj) != list and type(obj) != tuple):
      objType = obj.whatIs()
      if objType == "CIRCLE": # se é cerchio
         newCircle = gripStretchCircle(obj, basePt, ptListToStretch, offSetX, offSetY, tolerance)
         if newCircle is not None:
            return QgsGeometry.fromPolyline(newCircle.asPolyline(tolerance))
      elif objType == "ARC": # se é arco
         newArc = gripStretchArc(obj, ptListToStretch, offSetX, offSetY, tolerance)
         if newArc is not None:
            return QgsGeometry.fromPolyline(newArc.asPolyline(tolerance))
      return None
   
   linearObjectListToStretch = qad_utils.QadLinearObjectList()
   linearObjectListToStretch.fromPolyline(geom.asPolyline())
   
   atPart = 0
   while atPart < linearObjectListToStretch.qty():
      linearObject = linearObjectListToStretch.getLinearObjectAt(atPart)
      if linearObject.isSegment():
         pt = linearObject.getStartPt()
         if isPtContainedForStretch(pt, ptListToStretch): # se il punto è contenuto in ptListToStretch
            # cambio punto iniziale        
            pt.setX(pt.x() + offSetX)
            pt.setY(pt.y() + offSetY)
            linearObject.setStartPt(pt)
            
         pt = linearObject.getEndPt()
         if isPtContainedForStretch(pt, ptListToStretch): # se il punto è contenuto in ptListToStretch
            # cambio punto finale
            pt.setX(pt.x() + offSetX)
            pt.setY(pt.y() + offSetY)
            linearObject.setEndPt(pt)
      else: # se è arco
         newArc, newInverseFlag = gripStretchArc(linearObject.getArc(), ptListToStretch, offSetX, offSetY, tolerance, linearObject.isInverseArc())
         if newArc is None:
            return None
         linearObject.setArc(newArc, newInverseFlag)

      atPart = atPart + 1
   
   pt = linearObjectListToStretch.getCentroid(tolerance) # verifico se polilinea ha un centroide
   if pt is not None:
      if isPtContainedForStretch(pt, ptListToStretch): # se il punto è contenuto in ptListToStretch
         linearObjectListToStretch.move(offSetX, offSetY)
   
   pts = linearObjectListToStretch.asPolyline(tolerance)
   stretchedGeom = QgsGeometry.fromPolyline(pts)    
      
   return stretchedGeom   
Example #5
0
def stretchQgsLineStringGeometry(geom, containerGeom, offSetX, offSetY, tolerance2ApproxCurve = None):
   """
   Stira i punti di una linestring che sono contenuti in containerGeom
   point = punto da tirare
   containerGeom = può essere una QgsGeometry rappresentante un poligono contenente i punti di geom da stirare
                   oppure una lista dei punti da stirare
   offSetX = spostamento X
   offSetY = spostamento Y
   """
   if tolerance2ApproxCurve == None:
      tolerance = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE"))
   else:
      tolerance = tolerance2ApproxCurve

   obj = qad_utils.whatGeomIs(0, geom)
   if (type(obj) != list and type(obj) != tuple):
      objType = obj.whatIs()
      if objType == "CIRCLE": # se é cerchio
         if isPtContainedForStretch(obj.center, containerGeom): # se il punto è contenuto in containerGeom
            obj.center.setX(obj.center.x() + offSetX)
            obj.center.setY(obj.center.y() + offSetY)
         return QgsGeometry.fromPolyline(obj.asPolyline(tolerance))

   stretchedGeom = QgsGeometry(geom)
   snapper = QadSnapper()
   points = snapper.getEndPoints(stretchedGeom)
   del snapper

   linearObjectListToStretch = qad_utils.QadLinearObjectList()
   linearObjectListToStretch.fromPolyline(geom.asPolyline())
   
   for point in points:
      if isPtContainedForStretch(point, containerGeom): # se il punto è contenuto in containerGeom
         atPart = linearObjectListToStretch.containsPt(point)
         while atPart >= 0:
            linearObject = linearObjectListToStretch.getLinearObjectAt(atPart)
            pt = linearObject.getStartPt()        
            if qad_utils.ptNear(pt, point): # cambio punto iniziale
               pt.setX(pt.x() + offSetX)
               pt.setY(pt.y() + offSetY)
               if linearObject.isSegment():
                  linearObject.setStartPt(pt)
               else:
                  oldArc = linearObject.getArc()
                  middlePt = oldArc.getMiddlePt()
                  distFromMiddleChord = qad_utils.getDistance(middlePt, qad_utils.getPerpendicularPointOnInfinityLine(oldArc.getStartPt(), oldArc.getEndPt(), middlePt))
                  
                  newArc = QadArc()
                  if linearObject.isInverseArc():                  
                     middlePt = qad_utils.getMiddlePoint(pt, oldArc.getStartPt())
                     middlePt = qad_utils.getPolarPointByPtAngle(middlePt, \
                                                                 qad_utils.getAngleBy2Pts(pt, oldArc.getStartPt()) + math.pi / 2, \
                                                                 distFromMiddleChord)                  
                     if newArc.fromStartSecondEndPts(oldArc.getStartPt(), middlePt, pt) == False:
                        return None
                  else:
                     middlePt = qad_utils.getMiddlePoint(pt, oldArc.getEndPt())
                     middlePt = qad_utils.getPolarPointByPtAngle(middlePt, \
                                                                 qad_utils.getAngleBy2Pts(pt, oldArc.getEndPt()) - math.pi / 2, \
                                                                 distFromMiddleChord)                  
                     if newArc.fromStartSecondEndPts(pt, middlePt, oldArc.getEndPt()) == False:
                        return None
                  linearObject.setArc(newArc, linearObject.isInverseArc())         
            else:
               pt = linearObject.getEndPt()
               if qad_utils.ptNear(pt, point): # cambio punto finale
                  pt.setX(pt.x() + offSetX)
                  pt.setY(pt.y() + offSetY)
                  if linearObject.isSegment():
                     linearObject.setEndPt(pt)
                  else:
                     oldArc = linearObject.getArc()
                     middlePt = oldArc.getMiddlePt()
                     distFromMiddleChord = qad_utils.getDistance(middlePt, qad_utils.getPerpendicularPointOnInfinityLine(oldArc.getStartPt(), oldArc.getEndPt(), middlePt))
                     
                     newArc = QadArc()
                     if linearObject.isInverseArc():
                        middlePt = qad_utils.getMiddlePoint(pt, oldArc.getEndPt())
                        middlePt = qad_utils.getPolarPointByPtAngle(middlePt, \
                                                                    qad_utils.getAngleBy2Pts(pt, oldArc.getEndPt()) - math.pi / 2, \
                                                                    distFromMiddleChord)                  
                        if newArc.fromStartSecondEndPts(pt, middlePt, oldArc.getEndPt()) == False:
                           return None
                     else:
                        middlePt = qad_utils.getMiddlePoint(pt, oldArc.getStartPt())
                        middlePt = qad_utils.getPolarPointByPtAngle(middlePt, \
                                                                    qad_utils.getAngleBy2Pts(pt, oldArc.getStartPt()) + math.pi / 2, \
                                                                    distFromMiddleChord)                  
                        if newArc.fromStartSecondEndPts(oldArc.getStartPt(), middlePt, pt) == False:
                           return None
                     linearObject.setArc(newArc, linearObject.isInverseArc())            
                  
            atPart = linearObjectListToStretch.containsPt(point, atPart + 1)
            
   pts = linearObjectListToStretch.asPolyline(tolerance)
   stretchedGeom = QgsGeometry.fromPolyline(pts)    
      
   return stretchedGeom