def select_input_crs(self): projSelector = QgsGenericProjectionSelector() projSelector.exec_() self.input_epsg = projSelector.selectedAuthId() self.dockwidget.epsgLabel.setText("Input " + projSelector.selectedAuthId()) self.dockwidget.munLineEdit.clear()
def selectcrs(self): # Select a new CRS s = QSettings() previousselectedcrs=s.value("quickcrs/crs", 0) #if previousselectedcrs=="" or previousselectedcrs==0 or previousselectedcrs is None: #self.nocrsselected() global selectedcrs try: projSelector = QgsGenericProjectionSelector() projSelector.exec_() projSelector.selectedCrsId() selectedcrs=projSelector.selectedCrsId() except: projSelector = QgsProjectionSelectionDialog() projSelector.exec_() selectedcrsdef = projSelector.crs() selectedcrs=selectedcrsdef.srsid() if (selectedcrs=="" or selectedcrs==0 or self.CrsId2AuthID(selectedcrs)=="" or selectedcrs is None): #selectedcrs=previousselectedcrs pass if (selectedcrs=="" or selectedcrs==0 or self.CrsId2AuthID(selectedcrs)=="" or selectedcrs is None) and (previousselectedcrs=="" or previousselectedcrs==0 or previousselectedcrs is None): #self.nocrsselected() pass else: #self.dlg.labelselectedcrs.setText(self.CrsId2AuthID(selectedcrs)) src=self.CrsId2AuthID(selectedcrs).replace('\n','') if(not self.buscarEnArchivo(src, "src.txt")): this_folder = os.path.dirname(os.path.abspath(__file__)) file = open(this_folder+"/src.txt", mode='a') file.write('\n'+src) file.close() self.file2Combo("src.txt", self.dlg.combo_src,'') self.dlg.combo_src.setCurrentText(src) self.dlg.show()
def selectCrs(self): crsDiag = QgsGenericProjectionSelector() crsDiag.exec_() crsId = crsDiag.selectedCrsId() if crsId: crsType = QgsCoordinateReferenceSystem.InternalCrsId self.systemCRS = QgsCoordinateReferenceSystem(crsId, crsType) self.settings.setValue('crs', self.systemCRS.postgisSrid())
def crs_selector(self): # Request CRS for layers proj_selector = QgsGenericProjectionSelector() proj_selector.exec_() proj_id = proj_selector.selectedAuthId() crs = QgsCoordinateReferenceSystem(proj_id) self.params.crs = crs
def select_crs(self): """ Open Qgis CRS selector """ proj_selector = QgsGenericProjectionSelector() proj_selector.exec_() proj = proj_selector.selectedAuthId() self.gui.crsValue.setText(proj)
def setSrc(self): projSelector = QgsGenericProjectionSelector() projSelector.setMessage(theMessage='Por favor, selecione um sistema de coordenada !') projSelector.exec_() if projSelector.selectedAuthId(): epsg = int(projSelector.selectedAuthId().split(':')[-1]) # test = QgsCoordinateReferenceSystem(epsg, QgsCoordinateReferenceSystem.EpsgCrsId) self.SRCLineEdit.setText(str(epsg)) self.epsg = epsg else: self.msg(u"Selecione SRC para criar Banco !")
def on_crsButton_clicked(self): projSelector = QgsGenericProjectionSelector() message = 'Select the Spatial Reference System!' projSelector.setMessage(theMessage=message) projSelector.exec_() try: epsg = int(projSelector.selectedAuthId().split(':')[-1]) self.crs = QgsCoordinateReferenceSystem(epsg, QgsCoordinateReferenceSystem.EpsgCrsId) if self.crs: self.crsLineEdit.setText(self.crs.description()) except: QMessageBox.warning(self, self.tr("Warning!"), self.tr(message))
def _crs_authority_id(): """ Returns selected coordinate reference system (CRS) authority ID :return auth_id: CRS authority ID :return auth_id: String """ proj_selector = QgsGenericProjectionSelector() proj_selector.setOgcWmsCrsFilter(NAM_CRS) proj_selector.exec_() auth_id = proj_selector.selectedAuthId() return auth_id
def on_browse_input_crs_pressed(self): """ define input crs :return: """ crs_selector = QgsGenericProjectionSelector() crs_selector.show() crs_selector.exec_() self.input_authid = str(crs_selector.selectedAuthId()) selected_crs = QgsCoordinateReferenceSystem() selected_crs.createFromString(self.input_authid) self.input_crs.setText(selected_crs.description() + " (" + self.input_authid+")")
def openSystem(self): projSelector = QgsGenericProjectionSelector() projSelector.exec_() a = projSelector.selectedCrsId() b = projSelector.selectedAuthId() if b == '': QMessageBox.information(None, self.tr("Warning"), self.tr("Attention no Reference System selected")) else: self.numEPGS = int(str(b).split(':')[1]) self.setSistemaRiferimento() self.label_sr.setText(self.tr("Reference System Loaded: ") + b) self.label_sr.show()
def selectKBS(self): """KBS auswählen. Setzt das KBS für die weiteren Funktionen :returns: void """ projSelector = QgsGenericProjectionSelector() projSelector.exec_() erg = projSelector.selectedAuthId() if len(erg.split(':')) == 2: self.dlg.tf_epsg.setText(erg.split(':')[1]) else: self.dlg.tf_epsg.setText(erg)
def on_crsButton_clicked(self): projSelector = QgsGenericProjectionSelector() message = 'Select the Spatial Reference System!' projSelector.setMessage(theMessage=message) projSelector.exec_() try: epsg = int(projSelector.selectedAuthId().split(':')[-1]) self.crs = QgsCoordinateReferenceSystem( epsg, QgsCoordinateReferenceSystem.EpsgCrsId) if self.crs: self.crsLineEdit.setText(self.crs.description()) except: QMessageBox.warning(self, self.tr("Warning!"), self.tr(message))
def setaSistCoordCriaSpatialite(self): projSelector = QgsGenericProjectionSelector() projSelector.setMessage(theMessage=self.tr('Please, select the coordinate system')) projSelector.exec_() try: self.epsgCriaSpatialite = int(projSelector.selectedAuthId().split(':')[-1]) self.srsCriaSpatialite = QgsCoordinateReferenceSystem(self.epsgCriaSpatialite, QgsCoordinateReferenceSystem.EpsgCrsId) if self.srsCriaSpatialite <> "": self.coordSysDefinido = True self.coordSysCriaSpatialiteLineEdit.setText(self.srsCriaSpatialite.description()) except: self.bar.pushMessage("", self.tr('Please, select the coordinate system'), level=QgsMessageBar.WARNING) pass
def setGeoRef(self): generic_projection_selector = QgsGenericProjectionSelector() generic_projection_selector.exec_() crsId = generic_projection_selector.selectedCrsId() if crsId: crsType = QgsCoordinateReferenceSystem.InternalCrsId self.kmlCrs = QgsCoordinateReferenceSystem(crsId, crsType) self.settings.setValue('kmlCrs', crsId) for i in range(0, self.dlg.conLayerList.count()): item = self.dlg.conLayerList.item(i) item.crs = self.kmlCrs
def select_CRS(self): projSelector = QgsGenericProjectionSelector() projSelector.exec_() try: authid = projSelector.selectedAuthId() self.crs = QgsCoordinateReferenceSystem() success = self.crs.createFromString(authid) if not success: self.crs = None else: self.crsDesc.setText(self.crs.description()) self.form_crsID.setText(authid) except: self.crs = None
def openSystem(self): projSelector = QgsGenericProjectionSelector() projSelector.exec_() a = projSelector.selectedCrsId() b = projSelector.selectedAuthId() if b == '': QMessageBox.information( None, self.tr("Warning"), self.tr("Attention no Reference System selected")) else: self.numEPGS = int(str(b).split(':')[1]) self.setSistemaRiferimento() self.label_sr.setText(self.tr("Reference System Loaded: ") + b) self.label_sr.show()
def on_cmdOutCRS_clicked(self): dlg = QgsGenericProjectionSelector(self) dlg.setMessage(self.tr('Select coordinate system')) if dlg.exec_(): if dlg.selectedAuthId() != '': self.outQgsCRS = QgsCoordinateReferenceSystem( dlg.selectedAuthId()) if self.outQgsCRS.geographicFlag(): self.outQgsCRS = None self.send_to_messagebar(unicode( self. tr("Geographic coordinate systems are not allowed. Resetting to default.." )), level=QgsMessageBar.WARNING, duration=5) else: self.outQgsCRS = None if self.outQgsCRS is None: self.autoSetCoordinateSystem() self.lblOutCRSTitle.setStyleSheet('color:black') self.lblOutCRS.setStyleSheet('color:black') self.lblOutCRS.setText( self.tr('{} - {}'.format(self.outQgsCRS.description(), self.outQgsCRS.authid())))
def edit(): selector = QgsProjectionSelectionDialog() selector.setCrs(value); if selector.exec_(): crs = selector.crs() if crs.upper().startswith("EPSG:"): self.lineEdit.setText(crs)
def outProjFile(self): header = "Define layer CRS:" sentence1 = self.tr( "Please select the projection system that defines the current layer." ) sentence2 = self.tr( "Layer CRS information will be updated to the selected CRS.") projSelector = QgsGenericProjectionSelector(self) projSelector.setMessage("<h2>%s</h2>%s <br/> %s" % (header, sentence1, sentence2)) if projSelector.exec_(): self.crs = QgsCoordinateReferenceSystem( projSelector.selectedCrsId(), QgsCoordinateReferenceSystem.InternalCrsId) print "AUTHID", projSelector.selectedAuthId() if len(projSelector.selectedAuthId()) == 0: QMessageBox.information(self, self.tr("Export to new projection"), self.tr("No Valid CRS selected")) return else: self.txtProjection.clear() self.txtProjection.insert(self.crs.authid() + " - " + self.crs.description()) else: return
def selectProjection(self): dialog = QgsGenericProjectionSelector(self.widget) current_crs = QgsCoordinateReferenceSystem(self.combo.currentText()) if current_crs.isValid(): dialog.setSelectedCrsId(current_crs.srsid()) if dialog.exec_(): self.setValue(dialog.selectedAuthId())
def crsChange(self): projectionDlg = QgsGenericProjectionSelector(self) projectionDlg.exec_() # print projectionDlg.selectedCrsId() srs = QgsCoordinateReferenceSystem(projectionDlg.selectedCrsId(), QgsCoordinateReferenceSystem.InternalCrsId) self.mCRS = srs.srsid() self.crs = QgsCoordinateReferenceSystem() self.crs.createFromId(self.mCRS, QgsCoordinateReferenceSystem.InternalCrsId ) # authId = projectionDlg.selectedAuthId() # crsId = projectionDlg.selectedCrsId() # if authId != "": # if authId[:4] != "EPSG": # self.crs = QgsCoordinateReferenceSystem(crsId, QgsCoordinateReferenceSystem.InternalCrsId) # else: # self.crs = QgsCoordinateReferenceSystem(crsId, QgsCoordinateReferenceSystem.EpsgCrsId) self.ui.cmbCrs.setCurrentIndex(2) self.ui.txtCrs.setText(self.crs.description())
def onSpecifyCRS(self): selector = QgsGenericProjectionSelector(self) selector.setMessage("Specify CRS of the mesh file") selector.setSelectedCrsId(self.layer.crs().srsid()) if selector.exec_(): self.crs = QgsCoordinateReferenceSystem(selector.selectedCrsId(), QgsCoordinateReferenceSystem.InternalCrsId) self.updateEditCRS()
def on_srsButton_clicked(self): """ Opens the CRS selector dialog """ projSelector = QgsGenericProjectionSelector() message = 'Select the Spatial Reference System!' projSelector.setMessage(theMessage=message) projSelector.exec_() try: self.epsg = int(projSelector.selectedAuthId().split(':')[-1]) srs = QgsCoordinateReferenceSystem(self.epsg, QgsCoordinateReferenceSystem.EpsgCrsId) if srs: self.srsEdit.setText(srs.description()) else: self.epsg = 4326 except: QMessageBox.warning(self, self.tr("Warning!"), message)
def selectCrs(self): projSelector = QgsGenericProjectionSelector() ret = projSelector.exec_() if ret == 1: #QMessageBox.Ok: crsId = projSelector.selectedCrsId() crsAuthId = projSelector.selectedAuthId() self.crsLineEdit.setText(self.crsAuthId) self.crs.createFromUserInput(self.crsAuthId)
def on_srsButton_clicked(self): """ Opens the CRS selector dialog """ projSelector = QgsGenericProjectionSelector() message = 'Select the Spatial Reference System!' projSelector.setMessage(theMessage=message) projSelector.exec_() try: self.epsg = int(projSelector.selectedAuthId().split(':')[-1]) srs = QgsCoordinateReferenceSystem( self.epsg, QgsCoordinateReferenceSystem.EpsgCrsId) if srs: self.srsEdit.setText(srs.description()) else: self.epsg = 4326 except: QMessageBox.warning(self, self.tr("Warning!"), message)
def selectCrs(self): projectionDlg = QgsGenericProjectionSelector(self) projectionDlg.setSelectedAuthId(self.mCrs.authid()) if projectionDlg.exec_(): self.mCrs = QgsCoordinateReferenceSystem( projectionDlg.selectedCrsId(), QgsCoordinateReferenceSystem.InternalCrsId) self.ui.txtCrs.setText(self.mCrs.authid() + " - " + self.mCrs.description())
def projection_selector(self): """ Opens the QGIS projection selector """ projection_selector = QgsGenericProjectionSelector(self) if projection_selector.exec_() == QDialog.Accepted: #Remove 'EPSG:' part self._srid = projection_selector.selectedAuthId()[5:] self.btnCoord.setText(projection_selector.selectedAuthId())
def onSpecifyCRS(self): selector = QgsGenericProjectionSelector(self) selector.setMessage("Specify CRS of the mesh file") selector.setSelectedCrsId(self.layer.crs().srsid()) if selector.exec_(): self.crs = QgsCoordinateReferenceSystem( selector.selectedCrsId(), QgsCoordinateReferenceSystem.InternalCrsId) self.updateEditCRS()
def on_srsButton_clicked(self): projSelector = QgsGenericProjectionSelector() message = self.tr('Select the Spatial Reference System!') projSelector.setMessage(theMessage=message) if not projSelector.exec_(): QMessageBox.warning(self, self.tr("Warning!"), message) return else: self.epsg = int(projSelector.selectedAuthId().split(':')[-1]) srs = QgsCoordinateReferenceSystem( self.epsg, QgsCoordinateReferenceSystem.EpsgCrsId) self.srLineEdit.setText(srs.description())
def browseCRS(self): selector = QgsGenericProjectionSelector() selector.setSelectedAuthId(self.crs) if selector.exec_(): authId = selector.selectedAuthId() if authId.upper().startswith("EPSG:"): self.crs = authId else: proj = QgsCoordinateReferenceSystem() proj.createFromSrsId(selector.selectedCrsId()) self.crs = proj.toProj4() self.updateText()
def on_srsButton_clicked(self): ''' Opens the dialog to select CRS ''' projSelector = QgsGenericProjectionSelector() message = self.tr('Select the Spatial Reference System!') projSelector.setMessage(theMessage=message) if not projSelector.exec_(): QMessageBox.warning(self, self.tr("Warning!"), message) return else: self.epsg = int(projSelector.selectedAuthId().split(':')[-1]) srs = QgsCoordinateReferenceSystem(self.epsg, QgsCoordinateReferenceSystem.EpsgCrsId) self.srLineEdit.setText(srs.description())
def on_pbnCrs_pressed(self): selector = QgsGenericProjectionSelector(self) selector.setMessage(); if self.layerCrs.description(): selector.setSelectedCrsId( self.layerCrs.srsid() ); elif self.selectedCrs.description(): selector.setSelectedCrsId( self.selectedCrs.srsid() ); if selector.exec_(): self.selectedCrs.createFromId( selector.selectedCrsId(), QgsCoordinateReferenceSystem.InternalCrsId ); self.ui.cboCrs.setCurrentIndex(2) if self.selectedCrs.description(): self.ui.cboCrs.setItemText(2, self.tr( "Selected" ) + " (%s, %s)" % (self.selectedCrs.description(), self.selectedCrs.authid()) ) else: self.ui.cboCrs.setItemText(2, self.tr("Selected (None)"))
def outProjFile(self): header = "Define layer CRS:" sentence1 = self.tr("Please select the projection system that defines the current layer.") sentence2 = self.tr("Layer CRS information will be updated to the selected CRS.") projSelector = QgsGenericProjectionSelector(self) projSelector.setMessage("<h2>%s</h2>%s <br/> %s" % (header, sentence1, sentence2)) if projSelector.exec_(): self.crs = QgsCoordinateReferenceSystem(projSelector.selectedCrsId(), QgsCoordinateReferenceSystem.InternalCrsId) print "AUTHID", projSelector.selectedAuthId() if len(projSelector.selectedAuthId()) == 0: QMessageBox.information(self, self.tr("Export to new projection"), self.tr("No Valid CRS selected")) return else: self.txtProjection.clear() self.txtProjection.insert(self.crs.authid() + " - " + self.crs.description()) else: return
def on_cmdInCRS_clicked(self): self.messageBar.clearWidgets() dlg = QgsGenericProjectionSelector(self) dlg.setMessage('Select coordinate system for the Vesper raster files') if dlg.exec_(): if dlg.selectedAuthId() != '': self.in_qgscrs = QgsCoordinateReferenceSystem(dlg.selectedAuthId()) if self.in_qgscrs == 'Unspecified' or self.in_qgscrs == '': self.lblInCRS.setText('Unspecified') self.lblOutCRS.setText('Unspecified') else: self.lblInCRS.setText('{} - {}'.format(self.in_qgscrs.description(), self.in_qgscrs.authid())) self.lblInCRS.setStyleSheet('color:black;background:transparent;') self.lblInCRSTitle.setStyleSheet('color:black') self.cleanMessageBars(self)
def on_cmdInCRS_clicked(self): dlg = QgsGenericProjectionSelector(self) dlg.setMessage('Select coordinate system for the input file geometry') if self.vesper_qgscrs is not None: dlg.setSelectedAuthId(self.vesper_qgscrs.authid()) if dlg.exec_(): if dlg.selectedAuthId() != '': # ie clicked ok without selecting a projection crs = QgsCoordinateReferenceSystem(dlg.selectedAuthId()) if crs == 'Unspecified' or crs == '': self.vesper_qgscrs = None self.lneInCRS.setText('Unspecified') else: self.vesper_qgscrs = QgsCoordinateReferenceSystem(crs) self.vesper_qgscrs.validate() self.lneInCRS.setText( '{} - {}'.format(self.vesper_qgscrs.description(), self.vesper_qgscrs.authid())) self.lneInCRS.setStyleSheet('color:black;background:transparent;') self.lblInCRSTitle.setStyleSheet('color:black')
def on_pbnCrs_pressed(self): selector = QgsGenericProjectionSelector(self) selector.setMessage() if self.layerCrs.description(): selector.setSelectedCrsId(self.layerCrs.srsid()) elif self.selectedCrs.description(): selector.setSelectedCrsId(self.selectedCrs.srsid()) if selector.exec_(): self.selectedCrs.createFromId( selector.selectedCrsId(), QgsCoordinateReferenceSystem.InternalCrsId) self.ui.cboCrs.setCurrentIndex(2) if self.selectedCrs.description(): self.ui.cboCrs.setItemText( 2, self.tr("Selected") + " (%s, %s)" % (self.selectedCrs.description(), self.selectedCrs.authid())) else: self.ui.cboCrs.setItemText(2, self.tr("Selected (None)"))
def geomapfishCrsButtonClicked(self): dlg = QgsGenericProjectionSelector(self) dlg.setMessage('Select GeoMapFish CRS') dlg.setSelectedAuthId(self.geomapfishCrs.text()) if dlg.exec_(): self.geomapfishCrs.setText(dlg.selectedAuthId())
def loadAvailableSystems(self): coordSys="" crsDlg=QgsGenericProjectionSelector(self.parent) if crsDlg.exec_()==QDialog.Accepted: coordSys=str(crsDlg.selectedAuthId()) return coordSys
def run(self): """Run method that performs all the real work""" if ProcessingConfig.getSetting('ACTIVATE_R')==False: iface.messageBar().pushMessage("Error", "R not activated", level=QgsMessageBar.CRITICAL, duration=3) else : # show the dialog self.dlg.populateLayers() # self.dlg.outputFile.setText('') #if self.dlg.grid.isChecked(): # self.dlg.populateGrid() # self.dlg.useCanvasCRS() # self.dlg.mGroupBox.setCollapsed(True) self.dlg.show() # Run the dialog event loop result = self.dlg.exec_() # See if OK was pressed if result == 1: # Do something useful here - delete the line containing pass and # substitute with your code. inputLayer = QgsMapLayerRegistry.instance().mapLayersByName(self.dlg.inputLayer.currentText())[0] # attributeList = [field for field in inputLayer.pendingFields() if field.typeName in ('Integer', 'Real')] newAttributeList = [] newAttributeList.extend([QgsField('x', QVariant.Int, "Integer", 10)]) newAttributeList.extend([QgsField('y', QVariant.Int, "Integer", 10)]) valueFieldNames = self.dlg.selectedAttributesList if isinstance(valueFieldNames, str): valueFieldNames = (valueFieldNames,) listeIndex = [inputLayer.fieldNameIndex(element) \ for element in valueFieldNames] newAttributeList.extend([inputLayer.pendingFields()[elem] for elem in listeIndex]) features = inputLayer.getFeatures() listGeom = [] if inputLayer.geometryType() == qgis.QGis.NoGeometry: coordNames = [self.dlg.xCoord.currentText(), self.dlg.yCoord.currentText()] coordIndex = [inputLayer.fieldNameIndex(element) \ for element in coordNames] for element in features : outFeat = QgsFeature() if inputLayer.geometryType() == qgis.QGis.NoGeometry: x = element.attributes()[coordIndex[0]] y = element.attributes()[coordIndex[1]] else: # currentValues = [] # list(element.geometry().centroid().asPoint()) x = int(element.geometry().centroid().asPoint()[0]) y = int(element.geometry().centroid().asPoint()[1]) currentValues = [x,y] currentValues.extend([(element.attributes()[i]) for i in listeIndex]) # currentValues.extend([(element.attributes()[i]) for i in listeIndex]) outFeat.setAttributes(currentValues) listGeom.append(outFeat) tempLayer = QgsVectorLayer('Point?crs=epsg:4326', 'tempLayer','memory') tempLayer.dataProvider().addAttributes(newAttributeList) tempLayer.dataProvider().addFeatures(listGeom) tempLayer.updateFields() tempLayer.commitChanges() cellsize = int(self.dlg.cellsize.value()) bandwidth = int(self.dlg.bandwidth.value()) dirpath = tempfile.mkdtemp() sortie = str(re.sub('\\\\','/',dirpath) + "/output.csv") QgsVectorFileWriter.writeAsVectorFormat(tempLayer, sortie, "utf8", None, "CSV") outputFile = self.dlg.outputFile if self.dlg.mGroupBoxPercentile.isCollapsed(): quantileList = 'NULL' else: quantileList = self.dlg.RquantileList if self.dlg.mGroupBoxUserGrid.isCollapsed(): crsOption = False projSelector = QgsGenericProjectionSelector() while crsOption == False : projSelector.exec_() srs = projSelector.selectedAuthId() if 'EPSG' in srs : layerCRS = int(srs.split(':')[1]) crsOption = True else : iface.messageBar().pushMessage("Error", "Please choose a valid EPSG code", level=QgsMessageBar.CRITICAL, duration=3) # smoothedDatasPath = str(re.sub('\\\\','/',dirpath) + "/lissage.dbf") outputAlgo = processing.runalg("r:btbschematisationdecarreaux",sortie,cellsize,bandwidth,quantileList, layerCRS,None) tempShapefile = QgsVectorLayer(outputAlgo['grille_lissee '],'grille_lissee','ogr') QgsMapLayerRegistry.instance().addMapLayer(tempShapefile, addToLegend = False) QgsVectorFileWriter.writeAsVectorFormat(tempShapefile, outputFile,"utf-8", None, "ESRI Shapefile") smoothedDatas = QgsVectorLayer(self.dlg.outputFile,'grille_lissee','ogr') QgsMapLayerRegistry.instance().addMapLayer(smoothedDatas) QgsMapLayerRegistry.instance().removeMapLayers([tempShapefile.id()]) else: gridLayerPath = self.dlg.inputGrid.text() # smoothedDatasPath = self.dlg.outputFile.text() smoothedDatasPath = str(re.sub('\\\\','/',dirpath) + "/lissage.dbf") processing.runalg("r:btblissagegrille",sortie, cellsize,bandwidth, quantileList, re.sub('\.shp','.dbf',gridLayerPath), smoothedDatasPath) gridLayer = QgsVectorLayer(gridLayerPath,'grille','ogr') QgsMapLayerRegistry.instance().addMapLayer(gridLayer, addToLegend = False) # mergedLayer = processing.runalg("qgis:joinattributestable",gridLayer,"C:/Temp/output4.dbf","ID","ID",None) # newLayer = QgsVectorLayer(mergedLayer['OUTPUT_LAYER'],'grille_lissee','ogr') # QgsMapLayerRegistry.instance().addMapLayer(newLayer) smoothedDatas = QgsVectorLayer(smoothedDatasPath,'donnees_lissee','ogr') QgsMapLayerRegistry.instance().addMapLayer(smoothedDatas, addToLegend = False) fieldList = [field.name() for field in list(smoothedDatas.pendingFields().toList())] fieldList.remove('x') fieldList.remove('y') fieldList.remove('ID') joinObject = QgsVectorJoinInfo() joinObject.joinLayerId = smoothedDatas.id() joinObject.prefix = '' joinObject.joinFieldName = 'ID' joinObject.targetFieldName = 'ID' joinObject.setJoinFieldNamesSubset(fieldList) joinObject.memoryCache = True gridLayer.addJoin(joinObject) QgsVectorFileWriter.writeAsVectorFormat(gridLayer, self.dlg.outputFile,"utf-8", None, "ESRI Shapefile") # gridLayer.removeJoin(joinObject) QgsMapLayerRegistry.instance().removeMapLayers([gridLayer.id()]) # gridLayer.removeJoin(joinObject) QgsMapLayerRegistry.instance().removeMapLayers([smoothedDatas.id()]) resultLayer = QgsVectorLayer(self.dlg.outputFile,'lissage','ogr') QgsMapLayerRegistry.instance().addMapLayer(resultLayer) ''' smoothedDatasPath = str(re.sub('\\\\','/',dirpath) + "/lissage.dbf") gridLayerPath = self.dlg.inputGrid.text() print "gridLayerPath :", gridLayerPath processing.runalg("r:btblissagegrille",sortie, cellsize,bandwidth, re.sub('\.shp','.dbf',gridLayerPath), smoothedDatasPath) smoothedDatas = QgsVectorLayer(smoothedDatasPath,'donnees_lissee','ogr') gridLayer = QgsVectorLayer(gridLayerPath,'grille_de_lissage','ogr') QgsMapLayerRegistry.instance().addMapLayer(gridLayer) fieldList = [field.name() for field in list(smoothedDatas.pendingFields().toList())] print "fields 1 : ",fieldList fieldList.remove(u'x') fieldList.remove(u'y') fieldList.remove('ID') print "fields 2 : ", fieldList joinObject = QgsVectorJoinInfo() joinObject.joinLayerId = smoothedDatas.id() joinObject.prefix = '' joinObject.joinFieldName = 'ID' joinObject.targetFieldName = 'ID' # joinObject.setJoinFieldNamesSubset(fieldList) joinObject.memoryCache = True gridLayer.addJoin(joinObject) print 'fields 3 :', str([field.name() for field in list(gridLayer.pendingFields().toList())]) QgsVectorFileWriter.writeAsVectorFormat(gridLayer, outputFile,"utf-8", None, "ESRI Shapefile") resultLayer = QgsVectorLayer(outputFile,'sortie','ogr') QgsMapLayerRegistry.instance().addMapLayer(resultLayer) del smoothedDatas ''' shutil.rmtree(dirpath)
def selectCrs(self): crsDiag = QgsGenericProjectionSelector() crsDiag.exec_() crsId = crsDiag.selectedCrsId() crsType = QgsCoordinateReferenceSystem.InternalCrsId self.crs = QgsCoordinateReferenceSystem(crsId, crsType)
def loadAvailableSystems(self): coordSys = "" crsDlg = QgsGenericProjectionSelector(self.parent) if crsDlg.exec_() == QDialog.Accepted: coordSys = str(crsDlg.selectedAuthId()) return coordSys
def browseForSRS(self): srsSelector = QgsGenericProjectionSelector(self) srsSelector.setSelectedCrsName(self.leSRS.text()) if srsSelector.exec_(): self.dlg.ui.leSRS.clear() self.dlg.ui.leSRS.insert(srsSelector.selectedProj4String())