Пример #1
0
    def disjoinCurrentSubGeomToPolygon(self):
        """
      Sconnette la sotto-geometria corrente del poligono da modificare creando una nuova entità
      """
        layer = self.entity.layer
        # la posizione é espressa con una lista (<index ogg. princ> [<index ogg. sec.>])
        part = self.currAtSubGeom[0]
        ring = self.currAtSubGeom[1] if len(self.currAtSubGeom) == 2 else None

        geom = self.entity.getGeometry()
        wkbType = geom.wkbType()
        if wkbType == QGis.WKBMultiPoint or wkbType == QGis.WKBMultiLineString:
            if geom.deletePart(part) == False:  # disgrego una parte
                self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                return False
            newGeom = self.mapToLayerCoordinates(layer, self.currSubGeom)
        elif wkbType == QGis.WKBPolygon or wkbType == QGis.WKBMultiPolygon:
            if ring is not None:  # disgrego un'isola
                if geom.deleteRing(
                        ring + 1, part
                ) == False:  # cancello una isola (Ring 0 is outer ring and can't be deleted)
                    self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                    return False
                newGeom = QgsGeometry.fromPolygon([
                    self.mapToLayerCoordinates(layer,
                                               self.currSubGeom).asPolyline()
                ])
            else:  # disgrego una parte
                if wkbType == QGis.WKBPolygon:
                    self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                    return False

                newGeom = QgsGeometry.fromPolygon([
                    self.mapToLayerCoordinates(layer,
                                               self.currSubGeom).asPolyline()
                ])
                ring = 0
                ringGeom = qad_utils.getSubGeomAt(geom, [part, ring])
                # se la parte ha delle isole
                while ringGeom is not None:
                    # aggiungo un'isola
                    points = ringGeom.asPolyline()  # vettore di punti
                    if newGeom.addRing(points) != 0:  # 0 in case of success
                        self.showMsg(QadMsg.translate("QAD",
                                                      "Invalid object."))
                        return False
                    ring = ring + 1
                    ringGeom = qad_utils.getSubGeomAt(geom, [part, ring])

                if geom.deletePart(part) == False:  # cancello una parte
                    self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                    return False
        else:
            self.showMsg(QadMsg.translate("QAD", "Invalid object."))
            return False

        f = self.entity.getFeature()
        f.setGeometry(geom)

        self.plugIn.beginEditCommand("Feature edited", self.entity.layer)

        # plugIn, layer, feature, refresh, check_validity
        if qad_layer.updateFeatureToLayer(self.plugIn, self.entity.layer, f,
                                          False, False) == False:
            self.plugIn.destroyEditCommand()
            return False

        # Aggiungo nuova feature
        newF = QgsFeature(f)
        newF.setGeometry(newGeom)
        if qad_layer.addFeatureToLayer(self.plugIn, self.entity.layer, newF,
                                       None, False, False) == False:
            self.plugIn.destroyEditCommand()
            return False

        self.plugIn.endEditCommand()

        return True
Пример #2
0
   def disjoinCurrentSubGeomToPolygon(self):
      """
      Sconnette la sotto-geometria corrente del poligono da modificare creando una nuova entità
      """
      layer = self.entity.layer
      # la posizione é espressa con una lista (<index ogg. princ> [<index ogg. sec.>])
      part = self.currAtSubGeom[0]
      ring = self.currAtSubGeom[1] if len(self.currAtSubGeom) == 2 else None
      
      geom = self.entity.getGeometry()
      wkbType = geom.wkbType()
      if wkbType == QGis.WKBMultiPoint or wkbType == QGis.WKBMultiLineString:
         if geom.deletePart(part) == False: # disgrego una parte
            self.showMsg(QadMsg.translate("QAD", "Invalid object."))
            return False
         newGeom = self.mapToLayerCoordinates(layer, self.currSubGeom)
      elif wkbType == QGis.WKBPolygon or wkbType == QGis.WKBMultiPolygon:
         if ring is not None: # disgrego un'isola 
            if geom.deleteRing(ring + 1, part) == False: # cancello una isola (Ring 0 is outer ring and can't be deleted)
               self.showMsg(QadMsg.translate("QAD", "Invalid object."))
               return False
            newGeom = QgsGeometry.fromPolygon([self.mapToLayerCoordinates(layer, self.currSubGeom).asPolyline()])
         else: # disgrego una parte
            if wkbType == QGis.WKBPolygon:
               self.showMsg(QadMsg.translate("QAD", "Invalid object."))
               return False
            
            newGeom = QgsGeometry.fromPolygon([self.mapToLayerCoordinates(layer, self.currSubGeom).asPolyline()])
            ring = 0
            ringGeom = qad_utils.getSubGeomAt(geom, [part, ring])
            # se la parte ha delle isole
            while ringGeom is not None:
               # aggiungo un'isola
               points = ringGeom.asPolyline() # vettore di punti
               if newGeom.addRing(points) != 0: # 0 in case of success
                  self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                  return False
               ring = ring + 1
               ringGeom = qad_utils.getSubGeomAt(geom, [part, ring])

            if geom.deletePart(part) == False: # cancello una parte
               self.showMsg(QadMsg.translate("QAD", "Invalid object."))
               return False
      else:
         self.showMsg(QadMsg.translate("QAD", "Invalid object."))
         return False

      f = self.entity.getFeature()
      f.setGeometry(geom)

      self.plugIn.beginEditCommand("Feature edited", self.entity.layer)
         
      # plugIn, layer, feature, refresh, check_validity
      if qad_layer.updateFeatureToLayer(self.plugIn, self.entity.layer, f, False, False) == False:
         self.plugIn.destroyEditCommand()
         return False

      # Aggiungo nuova feature
      newF = QgsFeature(f)
      newF.setGeometry(newGeom)
      if qad_layer.addFeatureToLayer(self.plugIn, self.entity.layer, newF, None, False, False) == False:
         self.plugIn.destroyEditCommand()
         return False
         
      self.plugIn.endEditCommand()

      return True