def filletPolyline(self): layer = self.entity1.layer transformedRadius = qad_utils.distMapToLayerCoordinates(self.radius, self.plugIn.canvas, layer) tolerance2ApproxCurve = qad_utils.distMapToLayerCoordinates(QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")), \ self.plugin.canvas, \ layer) f = self.entity1.getFeature() geom = f.geometry() self.linearObjectList1.fillet(transformedRadius) updSubGeom = QgsGeometry.fromPolyline(self.linearObjectList1.asPolyline(tolerance2ApproxCurve)) updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom1) if updGeom is None: return False f.setGeometry(updGeom) self.plugIn.beginEditCommand("Feature edited", layer) # plugIn, layer, feature, refresh, check_validity if qad_layer.updateFeatureToLayer(self.plugIn, layer, f, False, False) == False: self.plugIn.destroyEditCommand() return False self.plugIn.endEditCommand() self.nOperationsToUndo = self.nOperationsToUndo + 1 return True
def filletPolyline(self): layer = self.entity1.layer tolerance2ApproxCurve = QadVariables.get( QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")) f = self.entity1.getFeature() # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy geom = self.layerToMapCoordinates(layer, f.getGeometry()) self.linearObjectList1.fillet(self.radius) updSubGeom = QgsGeometry.fromPolyline( self.linearObjectList1.asPolyline(tolerance2ApproxCurve)) updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom1) if updGeom is None: return False # trasformo la geometria nel crs del layer f.setGeometry(self.mapToLayerCoordinates(layer, updGeom)) self.plugIn.beginEditCommand("Feature edited", layer) # plugIn, layer, feature, refresh, check_validity if qad_layer.updateFeatureToLayer(self.plugIn, layer, f, False, False) == False: self.plugIn.destroyEditCommand() return False self.plugIn.endEditCommand() self.nOperationsToUndo = self.nOperationsToUndo + 1 return True
def filletPolyline(self): layer = self.entity1.layer tolerance2ApproxCurve = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")) f = self.entity1.getFeature() # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy geom = self.layerToMapCoordinates(layer, f.getGeometry()) self.linearObjectList1.fillet(self.radius) updSubGeom = QgsGeometry.fromPolyline(self.linearObjectList1.asPolyline(tolerance2ApproxCurve)) updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom1) if updGeom is None: return False # trasformo la geometria nel crs del layer f.setGeometry(self.mapToLayerCoordinates(layer, updGeom)) self.plugIn.beginEditCommand("Feature edited", layer) # plugIn, layer, feature, refresh, check_validity if qad_layer.updateFeatureToLayer(self.plugIn, layer, f, False, False) == False: self.plugIn.destroyEditCommand() return False self.plugIn.endEditCommand() self.nOperationsToUndo = self.nOperationsToUndo + 1 return True
def stretchQgsGeometry(geom, containerGeom, offSetX, offSetY, tolerance2ApproxCurve): """ Stira una geometria geom = geometria da tirare containerGeom = può essere una QgsGeometry rappresentante un poligono contenente i punti di geom da stirare oppure una lista dei punti di geom da stirare offSetX = spostamento X offSetY = spostamento Y tolerance2ApproxCurve = tolleranza per rigenerare le curve """ wkbType = geom.wkbType() if wkbType == QGis.WKBPoint or wkbType == QGis.WKBPoint25D: pt = stretchPoint(geom.asPoint(), containerGeom, offSetX, offSetY) if pt is not None: return QgsGeometry.fromPoint(pt) if wkbType == QGis.WKBMultiPoint: stretchedGeom = QgsGeometry(geom) points = stretchedGeom.asMultiPoint() # vettore di punti atSubGeom = 0 for pt in points: subGeom = QgsGeometry.fromPoint(pt) stretchedSubGeom = stretchQgsGeometry(subGeom, containerGeom, offSetX, offSetY, tolerance2ApproxCurve) stretchedGeom = qad_utils.setSubGeom(stretchedGeom, stretchedSubGeom, [atSubGeom]) atSubGeom = atSubGeom + 1 return stretchedGeom if wkbType == QGis.WKBLineString: return stretchQgsLineStringGeometry(geom, containerGeom, offSetX, offSetY, tolerance2ApproxCurve) if wkbType == QGis.WKBMultiLineString: stretchedGeom = QgsGeometry(geom) lines = stretchedGeom.asMultiPolyline() # lista di linee atSubGeom = 0 for line in lines: subGeom = QgsGeometry.fromPolyline(line) stretchedSubGeom = stretchQgsGeometry(subGeom, containerGeom, offSetX, offSetY, tolerance2ApproxCurve) stretchedGeom = qad_utils.setSubGeom(stretchedGeom, stretchedSubGeom, [atSubGeom]) atSubGeom = atSubGeom + 1 return stretchedGeom if wkbType == QGis.WKBPolygon: stretchedGeom = QgsGeometry(geom) lines = stretchedGeom.asPolygon() # lista di linee atSubGeom = 0 for line in lines: subGeom = QgsGeometry.fromPolyline(line) stretchedSubGeom = stretchQgsGeometry(subGeom, containerGeom, offSetX, offSetY, tolerance2ApproxCurve) stretchedGeom = qad_utils.setSubGeom(stretchedGeom, stretchedSubGeom, [atSubGeom]) atSubGeom = atSubGeom + 1 return stretchedGeom if wkbType == QGis.WKBMultiPolygon: stretchedGeom = QgsGeometry(geom) polygons = geom.asMultiPolygon() # vettore di poligoni atSubGeom = 0 for polygon in polygons: subGeom = QgsGeometry.fromPolygon(polygon) stretchedSubGeom = stretchQgsGeometry(subGeom, containerGeom, offSetX, offSetY, tolerance2ApproxCurve) stretchedGeom = qad_utils.setSubGeom(stretchedGeom, stretchedSubGeom, [atSubGeom]) atSubGeom = atSubGeom + 1 return stretchedGeom return None
def gripStretchQgsGeometry(geom, basePt, ptListToStretch, offSetX, offSetY, tolerance2ApproxCurve): """ Stira una geometria in coordinate piane mediante grip point geom = geometria da stirare ptListToStretch = lista dei punti di geom da stirare offSetX = spostamento X offSetY = spostamento Y tolerance2ApproxCurve = tolleranza per rigenerare le curve """ wkbType = geom.wkbType() if wkbType == QGis.WKBPoint or wkbType == QGis.WKBPoint25D: pt = stretchPoint(geom.asPoint(), ptListToStretch, offSetX, offSetY) if pt is not None: return QgsGeometry.fromPoint(pt) if wkbType == QGis.WKBMultiPoint: stretchedGeom = QgsGeometry(geom) points = stretchedGeom.asMultiPoint() # vettore di punti atSubGeom = 0 for pt in points: subGeom = QgsGeometry.fromPoint(pt) stretchedSubGeom = gripStretchQgsGeometry(subGeom, basePt, ptListToStretch, offSetX, offSetY, tolerance2ApproxCurve) stretchedGeom = qad_utils.setSubGeom(stretchedGeom, stretchedSubGeom, [atSubGeom]) atSubGeom = atSubGeom + 1 return stretchedGeom if wkbType == QGis.WKBLineString: return gripStretchQgsLineStringGeometry(geom, basePt, ptListToStretch, offSetX, offSetY, tolerance2ApproxCurve) if wkbType == QGis.WKBMultiLineString: stretchedGeom = QgsGeometry(geom) lines = stretchedGeom.asMultiPolyline() # lista di linee atSubGeom = 0 for line in lines: subGeom = QgsGeometry.fromPolyline(line) stretchedSubGeom = gripStretchQgsGeometry(subGeom, basePt, ptListToStretch, offSetX, offSetY, tolerance2ApproxCurve) stretchedGeom = qad_utils.setSubGeom(stretchedGeom, stretchedSubGeom, [atSubGeom]) atSubGeom = atSubGeom + 1 return stretchedGeom if wkbType == QGis.WKBPolygon: stretchedGeom = QgsGeometry(geom) lines = stretchedGeom.asPolygon() # lista di linee atSubGeom = 0 for line in lines: subGeom = QgsGeometry.fromPolyline(line) stretchedSubGeom = gripStretchQgsGeometry(subGeom, basePt, ptListToStretch, offSetX, offSetY, tolerance2ApproxCurve) stretchedGeom = qad_utils.setSubGeom(stretchedGeom, stretchedSubGeom, [atSubGeom]) atSubGeom = atSubGeom + 1 return stretchedGeom if wkbType == QGis.WKBMultiPolygon: stretchedGeom = QgsGeometry(geom) polygons = geom.asMultiPolygon() # vettore di poligoni atSubGeom = 0 for polygon in polygons: subGeom = QgsGeometry.fromPolygon(polygon) stretchedSubGeom = gripStretchQgsGeometry(subGeom, basePt, ptListToStretch, offSetX, offSetY, tolerance2ApproxCurve) stretchedGeom = qad_utils.setSubGeom(stretchedGeom, stretchedSubGeom, [atSubGeom]) atSubGeom = atSubGeom + 1 return stretchedGeom return None
def trimFeatures(self, geom, toExtend): # geom è in map coordinates tolerance2ApproxCurve = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")) LineTempLayer = None self.plugIn.beginEditCommand("Feature extended" if toExtend else "Feature trimmed", \ self.entitySet.getLayerList()) for layerEntitySet in self.entitySet.layerEntitySetList: layer = layerEntitySet.layer for featureId in layerEntitySet.featureIds: f = qad_utils.getFeatureById(layer, featureId) if f is None: continue # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy f_geom = self.layerToMapCoordinates(layer, f.geometry()) if geom.type() == QGis.Point: # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) dummy = qad_utils.closestSegmentWithContext(geom.asPoint(), f_geom) if dummy[1] is not None: intPts = [dummy[1]] else: intPts = qad_utils.getIntersectionPoints(geom, f_geom) for intPt in intPts: if toExtend: newGeom = qad_utils.extendQgsGeometry(self.plugIn.canvas.mapRenderer().destinationCrs(), f_geom, intPt, \ self.limitEntitySet, self.edgeMode, \ tolerance2ApproxCurve) if newGeom is not None: # aggiorno la feature con la geometria estesa extendedFeature = QgsFeature(f) # trasformo la geometria nel crs del layer extendedFeature.setGeometry(self.mapToLayerCoordinates(layer, newGeom)) # plugIn, layer, feature, refresh, check_validity if qad_layer.updateFeatureToLayer(self.plugIn, layer, extendedFeature, False, False) == False: self.plugIn.destroyEditCommand() return else: # trim result = qad_utils.trimQgsGeometry(self.plugIn.canvas.mapRenderer().destinationCrs(), f_geom, intPt, \ self.limitEntitySet, self.edgeMode, \ tolerance2ApproxCurve) if result is not None: line1 = result[0] line2 = result[1] atSubGeom = result[2] if layer.geometryType() == QGis.Line: updGeom = qad_utils.setSubGeom(f_geom, line1, atSubGeom) if updGeom is None: self.plugIn.destroyEditCommand() return trimmedFeature1 = QgsFeature(f) # trasformo la geometria nel crs del layer trimmedFeature1.setGeometry(self.mapToLayerCoordinates(layer, updGeom)) # plugIn, layer, feature, refresh, check_validity if qad_layer.updateFeatureToLayer(self.plugIn, layer, trimmedFeature1, False, False) == False: self.plugIn.destroyEditCommand() return if line2 is not None: trimmedFeature2 = QgsFeature(f) # trasformo la geometria nel crs del layer trimmedFeature2.setGeometry(self.mapToLayerCoordinates(layer, line2)) # plugIn, layer, feature, coordTransform, refresh, check_validity if qad_layer.addFeatureToLayer(self.plugIn, layer, trimmedFeature2, None, False, False) == False: self.plugIn.destroyEditCommand() return else: # aggiungo le linee nei layer temporanei di QAD if LineTempLayer is None: LineTempLayer = qad_layer.createQADTempLayer(self.plugIn, QGis.Line) self.plugIn.addLayerToLastEditCommand("Feature trimmed", LineTempLayer) lineGeoms = [line1] if line2 is not None: lineGeoms.append(line2) # trasformo la geometria in quella dei layer temporanei # plugIn, pointGeoms, lineGeoms, polygonGeoms, coord, refresh if qad_layer.addGeometriesToQADTempLayers(self.plugIn, None, lineGeoms, None, None, False) == False: self.plugIn.destroyEditCommand() return updGeom = qad_utils.delSubGeom(f_geom, atSubGeom) if updGeom is None or updGeom.isGeosEmpty(): # da cancellare # plugIn, layer, feature id, refresh if qad_layer.deleteFeatureToLayer(self.plugIn, layer, f.id(), False) == False: self.plugIn.destroyEditCommand() return else: trimmedFeature1 = QgsFeature(f) # trasformo la geometria nel crs del layer trimmedFeature1.setGeometry(self.mapToLayerCoordinates(layer, updGeom)) # plugIn, layer, feature, refresh, check_validity if qad_layer.updateFeatureToLayer(self.plugIn, layer, trimmedFeature1, False, False) == False: self.plugIn.destroyEditCommand() return self.plugIn.endEditCommand() self.nOperationsToUndo = self.nOperationsToUndo + 1
def lengthen(self, point): layer = self.entity.layer f = self.entity.getFeature() if f is None: # non c'è più la feature return False # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy geom = self.layerToMapCoordinates(layer, self.entity.getGeometry()) # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) res = False newLinearObjectList = qad_utils.QadLinearObjectList(self.linearObjectList) if self.move_startPt: linearObject = newLinearObjectList.getLinearObjectAt(0) else: linearObject = newLinearObjectList.getLinearObjectAt(-1) if linearObject.isSegment(): newPt = qad_utils.getPerpendicularPointOnInfinityLine(linearObject.getStartPt(), linearObject.getEndPt(), point) else: # arco newPt = qad_utils.getPolarPointByPtAngle(linearObject.getArc().center, \ qad_utils.getAngleBy2Pts(linearObject.getArc().center, point), \ linearObject.getArc().radius) if newLinearObjectList.qty() > 1 and linearObject.isSegment(): ang = linearObject.getTanDirectionOnStartPt() if self.move_startPt: linearObject.setStartPt(newPt) else: linearObject.setEndPt(newPt) if newLinearObjectList.qty() > 1 and linearObject.isSegment() and \ qad_utils.TanDirectionNear(ang, linearObject.getTanDirectionOnStartPt()) == False: res = False else: res = True if res == False: # allungamento impossibile return False pts = newLinearObjectList.asPolyline() updSubGeom = QgsGeometry.fromPolyline(pts) updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom) if updGeom is None: return False # trasformo la geometria nel crs del layer f.setGeometry(self.mapToLayerCoordinates(layer, updGeom)) self.plugIn.beginEditCommand("Feature edited", layer) if self.copyEntities == False: # plugIn, layer, feature, refresh, check_validity if qad_layer.updateFeatureToLayer(self.plugIn, layer, f, False, False) == False: self.plugIn.destroyEditCommand() return False else: # plugIn, layer, features, coordTransform, refresh, check_validity if qad_layer.addFeatureToLayer(self.plugIn, layer, f, None, False, False) == False: self.plugIn.destroyEditCommand() return False self.plugIn.endEditCommand() self.nOperationsToUndo = self.nOperationsToUndo + 1 return True
def lengthen(self, point): layer = self.entity.layer f = self.entity.getFeature() if f is None: # non c'è più la feature return False geom = self.entity.getGeometry() # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) res = False if self.OpMode == "DElta": newLinearObjectList = qad_utils.QadLinearObjectList(self.linearObjectList) if self.OpType == "length": res = newLinearObjectList.lengthen_delta(self.move_startPt, self.value) elif self.OpType == "Angle": res = newLinearObjectList.lengthen_deltaAngle(self.move_startPt, self.value) elif self.OpMode == "Percent": newLinearObjectList = qad_utils.QadLinearObjectList(self.linearObjectList) value = newLinearObjectList.length() * self.value / 100 value = value - newLinearObjectList.length() res = newLinearObjectList.lengthen_delta(self.move_startPt, value) elif self.OpMode == "Total": newLinearObjectList = qad_utils.QadLinearObjectList(self.linearObjectList) if self.OpType == "length": value = self.value - newLinearObjectList.length() res = newLinearObjectList.lengthen_delta(self.move_startPt, value) elif self.OpType == "Angle": if newLinearObjectList.qty() == 1: linearObject = newLinearObjectList.getLinearObjectAt(0) if linearObject.isArc() == True: # se è un arco value = self.value - linearObject.getArc().totalAngle() res = newLinearObjectList.lengthen_deltaAngle(self.move_startPt, value) elif self.OpMode == "DYnamic": newLinearObjectList = qad_utils.QadLinearObjectList(self.linearObjectList) transformedPt = self.mapToLayerCoordinates(layer, point) if self.move_startPt: linearObject = newLinearObjectList.getLinearObjectAt(0) else: linearObject = newLinearObjectList.getLinearObjectAt(-1) if linearObject.isSegment(): newPt = qad_utils.getPerpendicularPointOnInfinityLine(linearObject.getStartPt(), linearObject.getEndPt(), transformedPt) else: # arco newPt = qad_utils.getPolarPointByPtAngle(linearObject.getArc().center, \ qad_utils.getAngleBy2Pts(linearObject.getArc().center, transformedPt), \ linearObject.getArc().radius) if newLinearObjectList.qty() > 1 and linearObject.isSegment(): ang = linearObject.getTanDirectionOnStartPt() if self.move_startPt: linearObject.setStartPt(newPt) else: linearObject.setEndPt(newPt) if newLinearObjectList.qty() > 1 and linearObject.isSegment() and \ qad_utils.TanDirectionNear(ang, linearObject.getTanDirectionOnStartPt()) == False: res = False else: res = True if res == False: # allungamento impossibile return False pts = newLinearObjectList.asPolyline() updSubGeom = QgsGeometry.fromPolyline(pts) updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom) if updGeom is None: return False f.setGeometry(updGeom) self.plugIn.beginEditCommand("Feature edited", layer) # plugIn, layer, feature, refresh, check_validity if qad_layer.updateFeatureToLayer(self.plugIn, layer, f, False, False) == False: self.plugIn.destroyEditCommand() return False self.plugIn.endEditCommand() self.nOperationsToUndo = self.nOperationsToUndo + 1 return True
def fillet(self): tolerance2ApproxCurve = QadVariables.get( QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")) # stessa entità e stessa parte if self.entity1.layer.id() == self.entity2.layer.id() and \ self.entity1.featureId == self.entity2.featureId and \ self.partAt1 == self.partAt2: return False # uso il crs del canvas per lavorare con coordinate piane xy epsg = self.plugIn.canvas.mapSettings().destinationCrs().authid() res = qad_utils.getFilletLinearObjectList(self.linearObjectList1, self.partAt1, self.pointAt1, \ self.linearObjectList2, self.partAt2, self.pointAt2,\ self.filletMode, self.radius, epsg) if res is None: # raccordo non possibile msg = QadMsg.translate("Command_FILLET", "\nFillet with radius <{0}> impossible.") #showMsg self.showMsg(msg.format(str(self.radius))) return False filletLinearObjectList = res[0] whatToDoPoly1 = res[1] whatToDoPoly2 = res[2] self.plugIn.beginEditCommand("Feature edited", [self.entity1.layer, self.entity2.layer]) if whatToDoPoly1 == 1: # 1=modificare f = self.entity1.getFeature() # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy geom = self.layerToMapCoordinates(self.entity1.layer, f.geometry()) updSubGeom = QgsGeometry.fromPolyline( filletLinearObjectList.asPolyline(tolerance2ApproxCurve)) updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom1) if updGeom is None: self.plugIn.destroyEditCommand() return False # trasformo la geometria nel crs del layer f.setGeometry( self.mapToLayerCoordinates(self.entity1.layer, updGeom)) # plugIn, layer, feature, refresh, check_validity if qad_layer.updateFeatureToLayer(self.plugIn, self.entity1.layer, f, False, False) == False: self.plugIn.destroyEditCommand() return False elif whatToDoPoly1 == 2: # 2=cancellare # se non si tratta della stessa entità if self.entity1 != self.entity2: # plugIn, layer, featureId, refresh if qad_layer.deleteFeatureToLayer(self.plugIn, self.entity1.layer, \ self.entity1.featureId, False) == False: self.plugIn.destroyEditCommand() return False if whatToDoPoly2 == 1: # 1=modificare tolerance2ApproxCurve = QadVariables.get( QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")) f = self.entity2.getFeature() # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy geom = self.layerToMapCoordinates(self.entity2.layer, f.geometry()) updSubGeom = QgsGeometry.fromPolyline( filletLinearObjectList.asPolyline(tolerance2ApproxCurve)) updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom2) if updGeom is None: self.plugIn.destroyEditCommand() return False # trasformo la geometria nel crs del layer f.setGeometry( self.mapToLayerCoordinates(self.entity2.layer, updGeom)) # plugIn, layer, feature, refresh, check_validity if qad_layer.updateFeatureToLayer(self.plugIn, self.entity2.layer, f, False, False) == False: self.plugIn.destroyEditCommand() return False elif whatToDoPoly2 == 2: # 2=cancellare # se non si tratta della stessa entità if self.entity1 != self.entity2: # plugIn, layer, featureId, refresh if qad_layer.deleteFeatureToLayer(self.plugIn, self.entity2.layer, \ self.entity2.featureId, False) == False: self.plugIn.destroyEditCommand() return False if whatToDoPoly1 == 0 and whatToDoPoly2 == 0: # 0=niente geom = QgsGeometry.fromPolyline( filletLinearObjectList.asPolyline(tolerance2ApproxCurve)) # trasformo la geometria nel crs del layer geom = self.mapToLayerCoordinates(self.entity1.layer, geom) # plugIn, layer, geom, coordTransform, refresh, check_validity if qad_layer.addGeomToLayer(self.plugIn, self.entity1.layer, geom, None, False, False) == False: self.plugIn.destroyEditCommand() return False self.plugIn.endEditCommand() self.nOperationsToUndo = self.nOperationsToUndo + 1 return True
def fillet(self): tolerance2ApproxCurve = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")) # stessa entità e stessa parte if self.entity1.layer.id() == self.entity2.layer.id() and \ self.entity1.featureId == self.entity2.featureId and \ self.partAt1 == self.partAt2: return False # uso il crs del canvas per lavorare con coordinate piane xy epsg = self.plugIn.canvas.mapRenderer().destinationCrs().authid() res = qad_utils.getFilletLinearObjectList(self.linearObjectList1, self.partAt1, self.pointAt1, \ self.linearObjectList2, self.partAt2, self.pointAt2,\ self.filletMode, self.radius, epsg) if res is None: # raccordo non possibile msg = QadMsg.translate("Command_FILLET", "\nFillet with radius <{0}> impossible.") #showMsg self.showMsg(msg.format(str(self.radius))) return False filletLinearObjectList = res[0] whatToDoPoly1 = res[1] whatToDoPoly2 = res[2] self.plugIn.beginEditCommand("Feature edited", [self.entity1.layer, self.entity2.layer]) if whatToDoPoly1 == 1: # 1=modificare f = self.entity1.getFeature() # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy geom = self.layerToMapCoordinates(self.entity1.layer, f.geometry()) updSubGeom = QgsGeometry.fromPolyline(filletLinearObjectList.asPolyline(tolerance2ApproxCurve)) updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom1) if updGeom is None: self.plugIn.destroyEditCommand() return False # trasformo la geometria nel crs del layer f.setGeometry(self.mapToLayerCoordinates(self.entity1.layer, updGeom)) # plugIn, layer, feature, refresh, check_validity if qad_layer.updateFeatureToLayer(self.plugIn, self.entity1.layer, f, False, False) == False: self.plugIn.destroyEditCommand() return False elif whatToDoPoly1 == 2: # 2=cancellare # se non si tratta della stessa entità if self.entity1 != self.entity2: # plugIn, layer, featureId, refresh if qad_layer.deleteFeatureToLayer(self.plugIn, self.entity1.layer, \ self.entity1.featureId, False) == False: self.plugIn.destroyEditCommand() return False if whatToDoPoly2 == 1: # 1=modificare tolerance2ApproxCurve = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")) f = self.entity2.getFeature() # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy geom = self.layerToMapCoordinates(self.entity2.layer, f.geometry()) updSubGeom = QgsGeometry.fromPolyline(filletLinearObjectList.asPolyline(tolerance2ApproxCurve)) updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom2) if updGeom is None: self.plugIn.destroyEditCommand() return False # trasformo la geometria nel crs del layer f.setGeometry(self.mapToLayerCoordinates(self.entity2.layer, updGeom)) # plugIn, layer, feature, refresh, check_validity if qad_layer.updateFeatureToLayer(self.plugIn, self.entity2.layer, f, False, False) == False: self.plugIn.destroyEditCommand() return False elif whatToDoPoly2 == 2: # 2=cancellare # se non si tratta della stessa entità if self.entity1 != self.entity2: # plugIn, layer, featureId, refresh if qad_layer.deleteFeatureToLayer(self.plugIn, self.entity2.layer, \ self.entity2.featureId, False) == False: self.plugIn.destroyEditCommand() return False if whatToDoPoly1 == 0 and whatToDoPoly2 == 0: # 0=niente geom = QgsGeometry.fromPolyline(filletLinearObjectList.asPolyline(tolerance2ApproxCurve)) # trasformo la geometria nel crs del layer geom = self.mapToLayerCoordinates(self.entity1.layer, geom) # plugIn, layer, geom, coordTransform, refresh, check_validity if qad_layer.addGeomToLayer(self.plugIn, self.entity1.layer, geom, None, False, False) == False: self.plugIn.destroyEditCommand() return False self.plugIn.endEditCommand() self.nOperationsToUndo = self.nOperationsToUndo + 1 return True
def fillet(self): transformedRadius = qad_utils.distMapToLayerCoordinates(self.radius, self.plugIn.canvas, self.entity1.layer) tolerance2ApproxCurve = qad_utils.distMapToLayerCoordinates(QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")), \ self.plugIn.canvas,\ self.entity1.layer) if self.entity1.layer.crs() != self.entity2.layer.crs(): coordTransform = QgsCoordinateTransform(self.entity1.layer.crs(),\ self.entity2.layer.crs()) # trasformo la geometria transformedLinearObjectList2 = self.linearObjectList2.transform(coordTransform) transformedPointAt2 = coordTransform.transform(self.pointAt2) else: # stessa entità e stessa parte if self.entity1.layer.id() == self.entity2.layer.id() and \ self.entity1.featureId == self.entity2.featureId and \ self.partAt1 == self.partAt2: return False transformedLinearObjectList2 = qad_utils.QadLinearObjectList(self.linearObjectList2) transformedPointAt2 = self.pointAt2 epsg = self.entity1.layer.crs().authid() res = qad_utils.getFilletLinearObjectList(self.linearObjectList1, self.partAt1, self.pointAt1, \ transformedLinearObjectList2, self.partAt2, transformedPointAt2,\ self.filletMode, transformedRadius, epsg) if res is None: # raccordo non possibile msg = QadMsg.translate("Command_FILLET", "\nFillet with radius <{0}> impossible.") #showMsg self.showMsg(msg.format(str(self.radius))) return False filletLinearObjectList = res[0] whatToDoPoly1 = res[1] whatToDoPoly2 = res[2] self.plugIn.beginEditCommand("Feature edited", [self.entity1.layer, self.entity2.layer]) if whatToDoPoly1 == 1: # 1=modificare f = self.entity1.getFeature() geom = f.geometry() updSubGeom = QgsGeometry.fromPolyline(filletLinearObjectList.asPolyline(tolerance2ApproxCurve)) updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom1) if updGeom is None: self.plugIn.destroyEditCommand() return False f.setGeometry(updGeom) # plugIn, layer, feature, refresh, check_validity if qad_layer.updateFeatureToLayer(self.plugIn, self.entity1.layer, f, False, False) == False: self.plugIn.destroyEditCommand() return False elif whatToDoPoly1 == 2: # 2=cancellare # plugIn, layer, featureId, refresh if qad_layer.deleteFeatureToLayer(self.plugIn, self.entity1.layer, \ self.entity1.featureId, False) == False: self.plugIn.destroyEditCommand() return False if whatToDoPoly2 == 1: # 1=modificare if self.entity1.layer.crs() != self.entity2.layer.crs(): coordTransform = QgsCoordinateTransform(self.entity2.layer.crs(),\ self.entity1.layer.crs()) # trasformo la geometria transformedLinearObjectList2 = self.filletLinearObjectList.transform(coordTransform) else: transformedLinearObjectList2 = filletLinearObjectList tolerance2ApproxCurve = qad_utils.distMapToLayerCoordinates(QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")), \ self.plugIn.canvas,\ self.entity2.layer) f = self.entity2.getFeature() geom = f.geometry() updSubGeom = QgsGeometry.fromPolyline(transformedLinearObjectList2.asPolyline(tolerance2ApproxCurve)) updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom2) if updGeom is None: self.plugIn.destroyEditCommand() return False f.setGeometry(updGeom) # plugIn, layer, feature, refresh, check_validity if qad_layer.updateFeatureToLayer(self.plugIn, self.entity2.layer, f, False, False) == False: self.plugIn.destroyEditCommand() return False elif whatToDoPoly2 == 2: # 2=cancellare # plugIn, layer, featureId, refresh if qad_layer.deleteFeatureToLayer(self.plugIn, self.entity2.layer, \ self.entity2.featureId, False) == False: self.plugIn.destroyEditCommand() return False if whatToDoPoly1 == 0 and whatToDoPoly2 == 0: # 0=niente geom = QgsGeometry.fromPolyline(filletLinearObjectList.asPolyline(tolerance2ApproxCurve)) # plugIn, layer, geom, coordTransform, refresh, check_validity if qad_layer.addGeomToLayer(self.plugIn, self.entity1.layer, geom, None, False, False) == False: self.plugIn.destroyEditCommand() return False self.plugIn.endEditCommand() self.nOperationsToUndo = self.nOperationsToUndo + 1 return True
def stretchQgsGeometry(geom, containerGeom, offSetX, offSetY, tolerance2ApproxCurve = None): """ Stira una geometria geom = geometria da tirare containerGeom = può essere una QgsGeometry rappresentante un poligono contenente i punti di geom da stirare oppure una lista dei punti di geom da stirare offSetX = spostamento X offSetY = spostamento Y tolerance2ApproxCurve = tolleranza per rigenerare le curve """ if tolerance2ApproxCurve == None: tolerance = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")) else: tolerance = tolerance2ApproxCurve wkbType = geom.wkbType() if wkbType == QGis.WKBPoint or wkbType == QGis.WKBPoint25D: pt = stretchPoint(geom.asPoint(), containerGeom, offSetX, offSetY) if pt is not None: return QgsGeometry.fromPoint(pt) if wkbType == QGis.WKBMultiPoint: stretchedGeom = QgsGeometry(geom) points = stretchedGeom.asMultiPoint() # vettore di punti atSubGeom = 0 for pt in points: subGeom = QgsGeometry.fromPoint(pt) stretchedSubGeom = stretchQgsGeometry(subGeom, containerGeom, offSetX, offSetY, tolerance) stretchedGeom = qad_utils.setSubGeom(stretchedGeom, stretchedSubGeom, [atSubGeom]) atSubGeom = atSubGeom + 1 return stretchedGeom if wkbType == QGis.WKBLineString: return stretchQgsLineStringGeometry(geom, containerGeom, offSetX, offSetY, tolerance) if wkbType == QGis.WKBMultiLineString: stretchedGeom = QgsGeometry(geom) lines = stretchedGeom.asMultiPolyline() # lista di linee atSubGeom = 0 for line in lines: subGeom = QgsGeometry.fromPolyline(line) stretchedSubGeom = stretchQgsGeometry(subGeom, containerGeom, offSetX, offSetY, tolerance) stretchedGeom = qad_utils.setSubGeom(stretchedGeom, stretchedSubGeom, [atSubGeom]) atSubGeom = atSubGeom + 1 return stretchedGeom if wkbType == QGis.WKBPolygon: stretchedGeom = QgsGeometry(geom) lines = stretchedGeom.asPolygon() # lista di linee iRing = -1 for line in lines: subGeom = QgsGeometry.fromPolyline(line) stretchedSubGeom = gripStretchQgsGeometry(subGeom, basePt, ptListToStretch, offSetX, offSetY, tolerance) if iRing == -1: # si tratta della parte più esterna stretchedGeom = qad_utils.setSubGeom(stretchedGeom, stretchedSubGeom, [0]) else: stretchedGeom = qad_utils.setSubGeom(stretchedGeom, stretchedSubGeom, [0, iRing]) iRing = iRing + 1 return stretchedGeom if wkbType == QGis.WKBMultiPolygon: stretchedGeom = QgsGeometry(geom) polygons = geom.asMultiPolygon() # vettore di poligoni iPart = 0 for polygon in polygons: iRing = -1 for line in polygon: subGeom = QgsGeometry.fromPolyline(line) stretchedSubGeom = gripStretchQgsGeometry(subGeom, basePt, ptListToStretch, offSetX, offSetY, tolerance) if iRing == -1: # si tratta della parte più esterna stretchedGeom = qad_utils.setSubGeom(stretchedGeom, stretchedSubGeom, [iPart]) else: stretchedGeom = qad_utils.setSubGeom(stretchedGeom, stretchedSubGeom, [iPart, iRing]) iRing = iRing + 1 iPart = iPart + 1 return stretchedGeom return None
def gripStretchQgsGeometry(geom, basePt, ptListToStretch, offSetX, offSetY, tolerance2ApproxCurve): """ Stira una geometria in coordinate piane mediante grip point geom = geometria da stirare ptListToStretch = lista dei punti di geom da stirare offSetX = spostamento X offSetY = spostamento Y tolerance2ApproxCurve = tolleranza per rigenerare le curve """ wkbType = geom.wkbType() if wkbType == QGis.WKBPoint or wkbType == QGis.WKBPoint25D: pt = stretchPoint(geom.asPoint(), ptListToStretch, offSetX, offSetY) if pt is not None: return QgsGeometry.fromPoint(pt) if wkbType == QGis.WKBMultiPoint: stretchedGeom = QgsGeometry(geom) points = stretchedGeom.asMultiPoint() # vettore di punti atSubGeom = 0 for pt in points: subGeom = QgsGeometry.fromPoint(pt) stretchedSubGeom = gripStretchQgsGeometry(subGeom, basePt, ptListToStretch, offSetX, offSetY, tolerance2ApproxCurve) stretchedGeom = qad_utils.setSubGeom(stretchedGeom, stretchedSubGeom, [atSubGeom]) atSubGeom = atSubGeom + 1 return stretchedGeom if wkbType == QGis.WKBLineString: return gripStretchQgsLineStringGeometry(geom, basePt, ptListToStretch, offSetX, offSetY, tolerance2ApproxCurve) if wkbType == QGis.WKBMultiLineString: stretchedGeom = QgsGeometry(geom) lines = stretchedGeom.asMultiPolyline() # lista di linee atSubGeom = 0 for line in lines: subGeom = QgsGeometry.fromPolyline(line) stretchedSubGeom = gripStretchQgsGeometry(subGeom, basePt, ptListToStretch, offSetX, offSetY, tolerance2ApproxCurve) stretchedGeom = qad_utils.setSubGeom(stretchedGeom, stretchedSubGeom, [atSubGeom]) atSubGeom = atSubGeom + 1 return stretchedGeom if wkbType == QGis.WKBPolygon: stretchedGeom = QgsGeometry(geom) lines = stretchedGeom.asPolygon() # lista di linee iRing = -1 for line in lines: subGeom = QgsGeometry.fromPolyline(line) stretchedSubGeom = gripStretchQgsGeometry(subGeom, basePt, ptListToStretch, offSetX, offSetY, tolerance2ApproxCurve) if iRing == -1: # si tratta della parte più esterna stretchedGeom = qad_utils.setSubGeom(stretchedGeom, stretchedSubGeom, [0]) else: stretchedGeom = qad_utils.setSubGeom(stretchedGeom, stretchedSubGeom, [0, iRing]) iRing = iRing + 1 return stretchedGeom if wkbType == QGis.WKBMultiPolygon: stretchedGeom = QgsGeometry(geom) polygons = geom.asMultiPolygon() # vettore di poligoni iPart = 0 for polygon in polygons: iRing = -1 for line in polygon: subGeom = QgsGeometry.fromPolyline(line) stretchedSubGeom = gripStretchQgsGeometry( subGeom, basePt, ptListToStretch, offSetX, offSetY, tolerance2ApproxCurve) if iRing == -1: # si tratta della parte più esterna stretchedGeom = qad_utils.setSubGeom( stretchedGeom, stretchedSubGeom, [iPart]) else: stretchedGeom = qad_utils.setSubGeom( stretchedGeom, stretchedSubGeom, [iPart, iRing]) iRing = iRing + 1 iPart = iPart + 1 return stretchedGeom return None