def addFeatureCache(self, newPt): featureCacheLen = len(self.featureCache) layer = self.entity.layer f = self.entity.getFeature() transformedPt = self.mapToLayerCoordinates(layer, newPt) # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) dummy = qad_utils.closestSegmentWithContext(transformedPt, self.subGeom) if self.offSet < 0: afterVertex = dummy[2] pt = qad_utils.getPerpendicularPointOnInfinityLine(self.subGeom.vertexAt(afterVertex - 1), \ self.subGeom.vertexAt(afterVertex), \ transformedPt) offSetDistance = qad_utils.getDistance(transformedPt, pt) else: offSetDistance = qad_utils.distMapToLayerCoordinates(self.offSet, \ self.plugIn.canvas,\ layer) if self.multi == True: if dummy[3] < 0: # alla sinistra offSetDistance = offSetDistance + self.lastOffSetOnLeftSide self.lastOffSetOnLeftSide = offSetDistance self.getPointMapTool().lastOffSetOnLeftSide = self.lastOffSetOnLeftSide else: # alla destra offSetDistance = offSetDistance + self.lastOffSetOnRightSide self.lastOffSetOnRightSide = offSetDistance self.getPointMapTool().lastOffSetOnRightSide = self.lastOffSetOnRightSide tolerance2ApproxCurve = qad_utils.distMapToLayerCoordinates(QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")), \ self.plugIn.canvas,\ layer) epsg = layer.crs().authid() lines = qad_utils.offSetPolyline(self.subGeom.asPolyline(), epsg, \ offSetDistance, \ "left" if dummy[3] < 0 else "right", \ self.gapType, \ tolerance2ApproxCurve) added = False for line in lines: if layer.geometryType() == QGis.Polygon: if line[0] == line[-1]: # se é una linea chiusa offsetGeom = QgsGeometry.fromPolygon([line]) else: offsetGeom = QgsGeometry.fromPolyline(line) else: offsetGeom = QgsGeometry.fromPolyline(line) if offsetGeom.type() == QGis.Line or offsetGeom.type() == QGis.Polygon: offsetFeature = QgsFeature(f) offsetFeature.setGeometry(offsetGeom) self.featureCache.append([layer, offsetFeature]) self.addFeatureToRubberBand(layer, offsetFeature) added = True if added: self.undoFeatureCacheIndexes.append(featureCacheLen)
def addFeatureCache(self, newPt): featureCacheLen = len(self.featureCache) layer = self.entity.layer f = self.entity.getFeature() # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) dummy = qad_utils.closestSegmentWithContext(newPt, self.subGeom) if self.offSet < 0: afterVertex = dummy[2] pt = qad_utils.getPerpendicularPointOnInfinityLine(self.subGeom.vertexAt(afterVertex - 1), \ self.subGeom.vertexAt(afterVertex), \ newPt) offSetDistance = qad_utils.getDistance(newPt, pt) else: offSetDistance = self.offSet if self.multi == True: if dummy[3] < 0: # alla sinistra offSetDistance = offSetDistance + self.lastOffSetOnLeftSide self.lastOffSetOnLeftSide = offSetDistance self.getPointMapTool().lastOffSetOnLeftSide = self.lastOffSetOnLeftSide else: # alla destra offSetDistance = offSetDistance + self.lastOffSetOnRightSide self.lastOffSetOnRightSide = offSetDistance self.getPointMapTool().lastOffSetOnRightSide = self.lastOffSetOnRightSide tolerance2ApproxCurve = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")) # uso il crs del canvas per lavorare con coordinate piane xy epsg = self.plugIn.canvas.mapSettings().destinationCrs().authid() lines = qad_utils.offSetPolyline(self.subGeom.asPolyline(), epsg, \ offSetDistance, \ "left" if dummy[3] < 0 else "right", \ self.gapType, \ tolerance2ApproxCurve) added = False for line in lines: if layer.geometryType() == QGis.Polygon: if line[0] == line[-1]: # se é una linea chiusa offsetGeom = QgsGeometry.fromPolygon([line]) else: offsetGeom = QgsGeometry.fromPolyline(line) else: offsetGeom = QgsGeometry.fromPolyline(line) if offsetGeom.type() == QGis.Line or offsetGeom.type() == QGis.Polygon: offsetFeature = QgsFeature(f) # trasformo la geometria nel crs del layer offsetFeature.setGeometry(self.mapToLayerCoordinates(layer, offsetGeom)) self.featureCache.append([layer, offsetFeature]) self.addFeatureToRubberBand(layer, offsetFeature) added = True if added: self.undoFeatureCacheIndexes.append(featureCacheLen)
def addOffSetGeometries(self, newPt): self.__rubberBand.reset() transformedPt = self.plugIn.canvas.mapRenderer().mapToLayerCoordinates(self.layer, newPt) # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) dummy = qad_utils.closestSegmentWithContext(transformedPt, self.subGeom) if self.offSet < 0: afterVertex = dummy[2] pt = qad_utils.getPerpendicularPointOnInfinityLine(self.subGeom.vertexAt(afterVertex - 1), \ self.subGeom.vertexAt(afterVertex), \ transformedPt) offSetDistance = qad_utils.getDistance(transformedPt, pt) else: offSetDistance = qad_utils.distMapToLayerCoordinates(self.offSet, \ self.plugIn.canvas,\ self.layer) if dummy[3] < 0: # alla sinistra offSetDistance = offSetDistance + self.lastOffSetOnLeftSide else: # alla destra offSetDistance = offSetDistance + self.lastOffSetOnRightSide tolerance2ApproxCurve = qad_utils.distMapToLayerCoordinates(QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")), \ self.plugIn.canvas,\ self.layer) epsg = self.layer.crs().authid() lines = qad_utils.offSetPolyline(self.subGeom.asPolyline(), epsg, \ offSetDistance, \ "left" if dummy[3] < 0 else "right", \ self.gapType, \ tolerance2ApproxCurve) for line in lines: if self.layer.geometryType() == QGis.Polygon: if line[0] == line[-1]: # se é una linea chiusa offsetGeom = QgsGeometry.fromPolygon([line]) else: offsetGeom = QgsGeometry.fromPolyline(line) else: offsetGeom = QgsGeometry.fromPolyline(line) self.__rubberBand.addGeometry(offsetGeom, self.layer)
def addOffSetGeometries(self, newPt): self.__highlight.reset() # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) dummy = qad_utils.closestSegmentWithContext(newPt, self.subGeom) if self.offSet < 0: afterVertex = dummy[2] pt = qad_utils.getPerpendicularPointOnInfinityLine(self.subGeom.vertexAt(afterVertex - 1), \ self.subGeom.vertexAt(afterVertex), \ newPt) offSetDistance = qad_utils.getDistance(newPt, pt) else: offSetDistance = self.offSet if dummy[3] < 0: # alla sinistra offSetDistance = offSetDistance + self.lastOffSetOnLeftSide else: # alla destra offSetDistance = offSetDistance + self.lastOffSetOnRightSide tolerance2ApproxCurve = QadVariables.get( QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")) # uso il crs del canvas per lavorare con coordinate piane xy epsg = self.canvas.mapRenderer().destinationCrs().authid() lines = qad_utils.offSetPolyline(self.subGeom.asPolyline(), epsg, \ offSetDistance, \ "left" if dummy[3] < 0 else "right", \ self.gapType, \ tolerance2ApproxCurve) for line in lines: if self.layer.geometryType() == QGis.Polygon: if line[0] == line[-1]: # se é una linea chiusa offsetGeom = QgsGeometry.fromPolygon([line]) else: offsetGeom = QgsGeometry.fromPolyline(line) else: offsetGeom = QgsGeometry.fromPolyline(line) self.__highlight.addGeometry( self.mapToLayerCoordinates(self.layer, offsetGeom), self.layer)
def addOffSetGeometries(self, newPt): self.__highlight.reset() # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) dummy = qad_utils.closestSegmentWithContext(newPt, self.subGeom) if self.offSet < 0: afterVertex = dummy[2] pt = qad_utils.getPerpendicularPointOnInfinityLine(self.subGeom.vertexAt(afterVertex - 1), \ self.subGeom.vertexAt(afterVertex), \ newPt) offSetDistance = qad_utils.getDistance(newPt, pt) else: offSetDistance = self.offSet if dummy[3] < 0: # alla sinistra offSetDistance = offSetDistance + self.lastOffSetOnLeftSide else: # alla destra offSetDistance = offSetDistance + self.lastOffSetOnRightSide tolerance2ApproxCurve = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")) # uso il crs del canvas per lavorare con coordinate piane xy epsg = self.canvas.mapSettings().destinationCrs().authid() lines = qad_utils.offSetPolyline(self.subGeom.asPolyline(), epsg, \ offSetDistance, \ "left" if dummy[3] < 0 else "right", \ self.gapType, \ tolerance2ApproxCurve) for line in lines: if self.layer.geometryType() == QGis.Polygon: if line[0] == line[-1]: # se é una linea chiusa offsetGeom = QgsGeometry.fromPolygon([line]) else: offsetGeom = QgsGeometry.fromPolyline(line) else: offsetGeom = QgsGeometry.fromPolyline(line) self.__highlight.addGeometry(self.mapToLayerCoordinates(self.layer, offsetGeom), self.layer)