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')
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)
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)
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)
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()
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)
def inlezen(self): """import the file after all settings wehere made""" targetLayerName = self.import_laag.currentText() if targetLayerName == "Ruimten": typeLayer = UC.getlayer_byname('ruimten_type') targetFeature = QC.QgsFeature() targetLayer = UC.getlayer_byname(targetLayerName) targetFields = targetLayer.fields() targetFeature.initAttributes(targetFields.count()) identifier = CH.get_identifier_bl(targetLayerName) targetFeature.setFields(targetFields) self.iface.setActiveLayer(self.importLayer) dummy, progressBar = self.progressdialog(0) progressBar.setValue(0) progressBar.setMaximum(100) count = 0 cntFeat = self.importLayer.featureCount() invalidCount = 0 for feature in self.importLayer.getFeatures(): count += 1 if self.mappingDict[feature[self.type.currentText( )]] != 'niet importeren' and feature.geometry(): if self.importTypeFile == 'DXF': if self.importLayer.geometryType( ) == QC.QgsWkbTypes.PolygonGeometry: geom = QC.QgsGeometry.fromPolygonXY( feature.geometry().asPolygon()) elif self.importLayer.wkbType( ) == QC.QgsWkbTypes.MultiLineString: geom = QC.QgsGeometry.fromMultiPolylineXY( feature.geometry().asMultiPolyline()) else: geom = QC.QgsGeometry.fromPolylineXY( feature.geometry().asPolyline()) elif self.importTypeFile in ('GPKG', 'SHP'): geom = feature.geometry() targetFeature.setGeometry(geom) targetFeature["bouwlaag_id"] = int(self.bouwlaag_id.text()) if targetLayerName == "Ruimten": request = QC.QgsFeatureRequest().setFilterExpression( '"naam" = ' + "'" + self.mappingDict[feature[self.type.currentText()]] + "'") tempFeature = next(typeLayer.getFeatures(request)) targetFeature[identifier] = tempFeature["id"] else: targetFeature[identifier] = self.mappingDict[feature[ self.type.currentText()]] invalidCheck = UC.write_layer(targetLayer, targetFeature, True) if invalidCheck == 'invalid': invalidCount += 1 progress = (float(count) / float(cntFeat)) * 100 progressBar.setValue(progress) if invalidCount > 0: MSG.showMsgBox('importpartiallysuccesfull', '{}'.format(invalidCount)) else: MSG.showMsgBox('importsuccesfull') QC.QgsProject.instance().removeMapLayers([self.importLayer.id()])
def place_feature(self, point): childFeature = QC.QgsFeature() newFeatureId = None self.iface.setActiveLayer(self.drawLayer) 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': newFeatureId = UC.write_layer(self.drawLayer, childFeature) objectLayer.reload() if not newFeatureId: idx = objectLayer.fields().indexFromName('id') maxObjectId = objectLayer.maximumValue(idx) request = QC.QgsFeatureRequest().setFilterExpression( '"id" > {}'.format(maxObjectId)) self.drawLayer.reload() tempFeatureIt = objectLayer.getFeatures(request) for feat in tempFeatureIt: if feat["formelenaam"] == formeleNaam: newFeatureId = feat["id"] #with new created feature run existing object widget if newFeatureId: self.run_objectgegevens(formeleNaam, newFeatureId) else: MSG.showMsgBox('newobjectslowanswer') else: self.iface.actionPan().trigger()
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()])
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')
def copy_bag_bouwlaag(self, ilayer, ifeature): """copy the floor drom the BAG features""" if ilayer.name() == PC.PAND["bouwlaaglayername"] or ilayer.name( ) == PC.PAND["bagpandlayername"]: 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)