Beispiel #1
0
 def draw_feature(self, points, _dummy):
     """create the floor feature and save to the floors layer"""
     minBouwlaag = int(self.bouwlaag_min.text())
     maxBouwlaag = int(self.bouwlaag_max.text())
     childFeature = QC.QgsFeature()
     layerName = PC.PAND["bouwlaaglayername"]
     layer = UC.getlayer_byname(layerName)
     foreignKey = CH.get_foreign_key_bl(layerName)
     # construct QgsFeature to save
     for i in range(minBouwlaag, maxBouwlaag + 1):
         if i != 0:
             childFeature.setGeometry(QC.QgsGeometry.fromPolygonXY([points
                                                                    ]))
             fields = layer.fields()
             childFeature.initAttributes(fields.count())
             childFeature.setFields(fields)
             childFeature[foreignKey] = self.objectId
             childFeature["bouwlaag"] = i
             UC.write_layer(layer, childFeature)
             # block the signals of changing the comboBox to add the new floor
             self.bouwlaag.blockSignals(True)
             self.bouwlaag.clear()
             if i not in self.bouwlaagList:
                 self.bouwlaagList.append(i)
     self.bouwlaagList.sort()
     self.bouwlagen_to_combobox()
     self.bouwlaag.blockSignals(False)
     self.iface.actionPan().trigger()
     # set all layers substring to the right floor
     sub_string = "bouwlaag = " + str(minBouwlaag)
     UG.set_layer_substring(sub_string)
     if maxBouwlaag != minBouwlaag:
         MSG.showMsgBox('bouwlaagcreated')
Beispiel #2
0
 def create_kaartblad(self, withGrid):
     gridUUID = uuid.uuid4()
     geom = self.rubberBand.asGeometry()
     geom.convertToMultiType()
     layerName = PC.OBJECT["gridlayername"]
     layer = UC.getlayer_byname(layerName)
     targetFeature = QC.QgsFeature()
     targetFields = layer.fields()
     targetFeature.initAttributes(targetFields.count())
     targetFeature.setFields(targetFields)
     targetFeature.setGeometry(geom)
     targetFeature["type"] = 'Kaartblad'
     if self.scale_25000.isChecked():
         targetFeature["scale"] = GH.DEFAULTSCALE
     else:
         targetFeature["scale"] = self.scale_custom.value()
     targetFeature["papersize"] = self.format_combo.currentText()
     if self.orient_landscape.isChecked():
         targetFeature["orientation"] = 'landscape'
     else:
         targetFeature["orientation"] = 'portrait'
     targetFeature["uuid"] = str(gridUUID)
     foreignKey = CH.get_foreign_key_ob(layerName)
     targetFeature[foreignKey] = self.objectId
     UC.write_layer(layer, targetFeature)
     bbox = geom.boundingBox()
     dist = self.distance_grid.value()
     if withGrid:
         self.create_grid(gridUUID, dist, bbox, 'Kaartblad')
     self.canvas.scene().removeItem(self.rubberBand)
Beispiel #3
0
 def copy_layers(self, parentID, newID, layer, bouwlaag):
     """select the features"""
     fields = layer.fields()
     newFeature = QC.QgsFeature()
     newFeature.initAttributes(fields.count())
     newFeature.setFields(fields)
     attrs = CH.get_allkeys_bl(layer.name())
     # get features by bouwlaag ID
     it = layer.getFeatures(
         QC.QgsFeatureRequest().setFilterExpression(attrs[0] + '=' +
                                                    str(parentID)))
     for feat in it:
         newFeature.setGeometry(feat.geometry())
         if attrs[1]:
             if str(feat[attrs[1]]).isdigit():
                 newFeature[attrs[1]] = int(feat[attrs[1]])
             else:
                 newFeature[attrs[1]] = feat[attrs[1]]
         if attrs[2]:
             newFeature[attrs[2]] = feat[attrs[2]]
         if attrs[3]:
             newFeature[attrs[3]] = feat[attrs[3]]
         newFeature[attrs[0]] = int(newID)
         newFeature["bouwlaag"] = bouwlaag
         UC.write_layer(layer, newFeature)
Beispiel #4
0
 def inlezen(self):
     targetLayerName = self.import_laag.currentText()
     targetLayer = UC.getlayer_byname(targetLayerName)
     sourceLayerName = 'tempImport'
     sourceLayer = UC.getlayer_byname(sourceLayerName)
     features = []
     for feature in sourceLayer.getFeatures():
         features.append(feature)
     UC.write_layer(targetLayer, features, False, False)
     MSG.showMsgBox('importsuccesfull')
     QC.QgsProject.instance().removeMapLayers([sourceLayer.id()])
 def place_object_terrein(self, points, _dummy):
     """save drawn terrain"""
     layer = UC.getlayer_byname(PC.OBJECT["terreinlayername"])
     if points:
         parentId, childFeature = UC.construct_feature('Polygon', PC.OBJECT["objectlayername"], points, self.object_id.text(), self.iface)
     if parentId is not None:
         buttonCheck = UC.get_attributes(parentId, childFeature, None, None, layer, PC.OBJECT["configtable"])
         if buttonCheck != 'Cancel':
             UC.write_layer(layer, childFeature)
     layer.commitChanges()
     layer.triggerRepaint()
     self.activatePan()
Beispiel #6
0
 def place_feature(self, points, snapAngle):
     parentId = None
     self.iface.setActiveLayer(self.drawLayer)
     if points:
         parentId, childFeature = UC.construct_feature(
             self.drawLayerType, self.parentLayerName, points,
             self.object_id.text(), self.iface)
     if parentId is not None:
         buttonCheck = UC.get_attributes(parentId, childFeature, snapAngle,
                                         self.identifier, self.drawLayer,
                                         PC.OBJECT["configtable"])
         if buttonCheck != 'Cancel':
             UC.write_layer(self.drawLayer, childFeature)
     self.run_tekenen('dummy', self.drawLayer.name(), self.identifier)
Beispiel #7
0
 def import_bouwlaag(self, bouwlaagFeature):
     """after the checks the import of the floor can start"""
     childFeature = QC.QgsFeature()
     layerName = 'Bouwlagen'
     layer = UC.getlayer_byname(layerName)
     # get necessary attributes from config file
     foreignKey = CH.get_foreign_key_bl(layerName)
     # construct QgsFeature to save
     childFeature.setGeometry(bouwlaagFeature.geometry())
     fields = layer.fields()
     childFeature.initAttributes(fields.count())
     childFeature.setFields(fields)
     childFeature[foreignKey] = str(self.object_id.text())
     childFeature["bouwlaag"] = int(self.bouwlaag.text())
     newFeatureId = UC.write_layer(layer, childFeature)
     self.bouwlaag_id.setText(str(newFeatureId))
     self.iface.actionPan().trigger()
     self.label2.setVisible(False)
     self.selectId.setVisible(False)
     self.label3.setVisible(True)
     self.label4.setVisible(True)
     self.label5a.setVisible(True)
     self.label5b.setVisible(True)
     self.import_laag.setVisible(True)
     self.check.setVisible(True)
     self.type.setVisible(True)
Beispiel #8
0
    def inlezen(self):
        """import the file after all settings wehere made"""
        importAttr = self.type.currentText()
        invalidCount = 0
        for importType in self.mappingDict:
            if self.mappingDict[importType]["targetType"] != 'niet importeren':
                checkConv = False
                expr = QC.QgsExpression('"{}"= \'{}\''.format(
                    importAttr, importType))
                featureIt = self.importLayer.getFeatures(
                    QC.QgsFeatureRequest(expr))
                targetFeature = QC.QgsFeature()
                targetLayerName = self.mappingDict[importType]["layerName"]
                if 'Labels' in targetLayerName:
                    LabelDialog.attributes = [
                        self.type.itemText(i) for i in range(self.type.count())
                    ]
                    LabelDialog.importType = importType
                    labelField, dummy = LabelDialog.getLabelAtrribute()
                targetLayer = UC.getlayer_byname(targetLayerName)
                targetFields = targetLayer.fields()
                targetFeature.initAttributes(targetFields.count())
                targetFeature.setFields(targetFields)
                if self.mappingDict[importType][
                        "convType"] != self.layerImportType:
                    checkConv = True
                query = "SELECT foreign_key, identifier, input_label FROM config_object WHERE child_layer = '{}'".format(
                    targetLayerName)
                attrs = UC.read_settings(query, False)[0]
                targetFeature[
                    attrs[1]] = self.mappingDict[importType]["targetType"]
                targetFeature[attrs[0]] = self.object_id.text()
                targetLayer.startEditing()

                for feat in featureIt:
                    geom = None
                    if not checkConv:
                        geom = EF.getfeature_geometry(feat.geometry(),
                                                      self.layerImportType)
                        if 'Labels' in targetLayerName:
                            if feat[labelField]:
                                targetFeature[attrs[2]] = feat[labelField]
                            else:
                                targetFeature[attrs[2]] = 'geen label'
                    if geom:
                        targetFeature.setGeometry(geom)
                        invalidCheck = UC.write_layer(targetLayer,
                                                      targetFeature, True)
                        if invalidCheck == 'invalid':
                            invalidCount += 1
                targetLayer.commitChanges()
        if invalidCount > 0:
            MSG.showMsgBox('importpartiallysuccesfull',
                           '{}'.format(invalidCount))
        else:
            MSG.showMsgBox('importsuccesfull')
        QC.QgsProject.instance().removeMapLayers([self.importLayer.id()])
Beispiel #9
0
 def create_grid(self,
                 gridUUID=None,
                 dist=None,
                 extent=None,
                 gridType='Grid'):
     if not gridUUID:
         gridUUID = uuid.uuid4()
     if not dist and not extent:
         extent = self.canvas.extent()
         dist = self.distance.value()
     layerName = PC.OBJECT["gridlayername"]
     layer = UC.getlayer_byname(layerName)
     targetFeature = QC.QgsFeature()
     targetFields = layer.fields()
     targetFeature.initAttributes(targetFields.count())
     targetFeature.setFields(targetFields)
     foreignKey = CH.get_foreign_key_ob(layerName)
     xmin, dummy, ymin, dummy, xIt, yIt = self.calculate_extent(
         dist, extent, gridType)
     objectId = self.objectId
     targetFeature[foreignKey] = objectId
     targetFeature["type"] = 'Grid'
     for x in range(0, xIt):
         for y in range(0, yIt):
             yLabel = str(y + 1)
             if xIt < 26:
                 xLabel = chr(x + 97).upper()
             elif xIt >= 26:
                 xLabel = chr(int(math.floor(x / 26)) +
                              97).upper() + chr(x % 26 + 97).upper()
             geom = self.calculate_geometry(dist, xmin, ymin, x, y,
                                            gridType)
             targetFeature['vaknummer'] = xLabel + yLabel
             if x != 0:
                 yLabel = ''
             if y != 0:
                 xLabel = ''
             targetFeature.setGeometry(geom)
             targetFeature['y_as_label'] = yLabel
             targetFeature['x_as_label'] = xLabel
             targetFeature['afstand'] = dist
             targetFeature["uuid"] = str(gridUUID)
             UC.write_layer(layer, targetFeature)
     MSG.showMsgBox('gridcreated')
Beispiel #10
0
 def place_feature(self, point):
     childFeature = QC.QgsFeature()
     objectLayer = UC.getlayer_byname(PC.OBJECT["objectlayername"])
     # set geometry from the point clicked on the canvas
     childFeature.setGeometry(QC.QgsGeometry.fromPointXY(point))
     foreignKey = self.identificatienummer.text()
     buttonCheck, formeleNaam = self.get_attributes(foreignKey,
                                                    childFeature)
     # return of new created feature id
     if buttonCheck != 'Cancel':
         UC.write_layer(self.drawLayer, childFeature)
         objectLayer.reload()
         self.close_objectnieuw_show_base()
     else:
         self.iface.actionPan().trigger()
     try:
         self.parent.pinTool.canvasClicked.disconnect()
     except:
         pass
Beispiel #11
0
 def copy_bag_bouwlaag(self, ilayer, ifeature):
     """copy the floor drom the BAG features"""
     if ilayer.name() == PC.PAND["bouwlaaglayername"] or ilayer.name(
     ) == PC.bagpand_layername():
         childFeature = QC.QgsFeature()
         layerName = PC.PAND["bouwlaaglayername"]
         # get active floor from dockwidget
         minBouwlaag = int(self.bouwlaag_min.text())
         maxBouwlaag = int(self.bouwlaag_max.text())
         layer = UC.getlayer_byname(layerName)
         # get necessary attributes from config file
         foreignKey = CH.get_foreign_key_bl(layerName)
         # construct QgsFeature to save
         for i in range(minBouwlaag, maxBouwlaag + 1):
             if i != 0:
                 childFeature.setGeometry(ifeature.geometry())
                 fields = layer.fields()
                 childFeature.initAttributes(fields.count())
                 childFeature.setFields(fields)
                 childFeature[foreignKey] = self.objectId
                 childFeature["bouwlaag"] = i
                 newFeatureId = UC.write_layer(layer, childFeature)
                 # copy also the selected layers
                 if ilayer.name() == PC.PAND["bouwlaaglayername"]:
                     self.copy_selected_layers(ifeature, newFeatureId, i)
                 # block the signals of changing the comboBox to add the new floor
                 self.bouwlaag.blockSignals(True)
                 self.bouwlaag.clear()
                 if i not in self.bouwlaagList:
                     self.bouwlaagList.append(i)
         self.bouwlaagList.sort()
         self.bouwlagen_to_combobox()
         self.bouwlaag.blockSignals(False)
         self.iface.actionPan().trigger()
         # set all layers substring to the right floor
         sub_string = "bouwlaag = " + str(minBouwlaag)
         UG.set_layer_substring(sub_string)
         try:
             self.parent.selectTool.geomSelected.disconnect()
         except:  # pylint: disable=bare-except
             pass
         if maxBouwlaag >= minBouwlaag:
             MSG.showMsgBox('bouwlaagcreated')
     else:
         MSG.showMsgBox('nobouwlaagselected')
         try:
             self.parent.selectTool.geomSelected.disconnect()
         except:  # pylint: disable=bare-except
             pass
         self.parent.selectTool.geomSelected.connect(self.copy_bag_bouwlaag)
Beispiel #12
0
    def inlezen_validatie(self):
        """import the file after all settings wehere made"""
        targetLayerName = self.import_laag.currentText()
        targetLayer = UC.getlayer_byname(targetLayerName)
        targetFields = targetLayer.fields()

        if targetLayerName == "Ruimten":
            typeLayer = UC.getlayer_byname('ruimten_type')
            tempImportLayer = self.init_layer_fields(
                targetFields,
                ["MultiPolygon?crs=epsg:28992", "tempImport", "memory"])
            tempImportLayerInvalid = self.init_layer_fields(
                targetFields, [
                    "MultiPolygon?crs=epsg:28992", "tempImport_invalid",
                    "memory"
                ])
        else:
            tempImportLayer = self.init_layer_fields(
                targetFields,
                ["MultiLinestring?crs=epsg:28992", "tempImport", "memory"])
            tempImportLayerInvalid = self.init_layer_fields(
                targetFields, [
                    "MultiLinestring?crs=epsg:28992", "tempImport_invalid",
                    "memory"
                ])

        identifier = CH.get_identifier_bl(targetLayerName)

        bouwlaagGeomCentroid = self.get_centroid()
        dummy, progressBar = self.progressdialog(0)
        count = 0
        cntFeat = self.importLayer.featureCount()
        invalidCount = 0
        validFeatures = []
        invalidFeatures = []
        geomCheck = True

        for feature in self.importLayer.getFeatures():
            targetFeature = QC.QgsFeature()
            targetFeature.initAttributes(targetFields.count())
            targetFeature.setFields(targetFields)
            count += 1
            if self.mappingDict[feature[self.type.currentText(
            )]] != 'niet importeren' and feature.geometry():
                if self.importTypeFile == 'DXF':
                    geom, geomCheck = self.check_feature_validity(
                        feature, bouwlaagGeomCentroid)
                elif self.importTypeFile in ('GPKG', 'SHP'):
                    geom = feature.geometry()
                targetFeature.setGeometry(geom)
                targetFeature["bouwlaag_id"] = int(self.bouwlaag_id.text())
                if targetLayerName == "Ruimten":
                    req = '"naam" = ' + "'" + self.mappingDict[feature[
                        self.type.currentText()]] + "'"
                    request = QC.QgsFeatureRequest().setFilterExpression(req)
                    tempFeature = next(typeLayer.getFeatures(request))
                    targetFeature[identifier] = tempFeature["id"]
                else:
                    targetFeature[identifier] = self.mappingDict[feature[
                        self.type.currentText()]]
                    if geomCheck:
                        validFeatures.append(targetFeature)
                    else:
                        invalidFeatures.append(targetFeature)
                        invalidCount += 1
            progress = (float(count) / float(cntFeat)) * 100
            progressBar.setValue(progress)

        if validFeatures:
            UC.write_layer(tempImportLayer, validFeatures, False, False)
        if invalidFeatures:
            UC.write_layer(tempImportLayerInvalid, invalidFeatures, False,
                           False)
        QC.QgsProject.instance().addMapLayer(tempImportLayer, True)
        QC.QgsProject.instance().addMapLayer(tempImportLayerInvalid, True)
        if invalidCount > 0:
            MSG.showMsgBox('importpartiallysuccesfull',
                           '{}'.format(invalidCount))
        else:
            MSG.showMsgBox('importsuccesfull')
        QC.QgsProject.instance().removeMapLayers([self.importLayer.id()])
        self.label8.setVisible(True)
        self.import_file.setVisible(True)