def set_crs(self, s): """Figure out the CRS for layer creation, from the selected options and/or string""" if self.dlg.CRSFromProject.isChecked(): self.crs_source = 'from project' self.crs = QgsProject.instance().crs() elif self.dlg.CRSFromFile.isChecked() and s: self.crs_source = 'from .3d file' self.crs = QgsCoordinateReferenceSystem() match = search('epsg:([0-9]*)', s) # check for epsg in proj string if match: # if found, use the EPSG number explicitly self.crs.createFromString('EPSG:{}'.format(int( match.group(1)))) else: # fall back to proj4 self.crs.createFromProj4(s) else: # fall back to raising a CRS selection dialog self.crs_source = 'from dialog' dialog = QgsProjectionSelectionDialog() dialog.setMessage('define the CRS for the imported layers') dialog.exec() # run the dialog .. self.crs = dialog.crs() # .. and recover the user input if self.crs.isValid(): msg = 'CRS {} : {}'.format(self.crs_source, self.crs.authid()) QgsMessageLog.logMessage(msg, tag='Import .3d', level=Qgis.Info) QgsMessageLog.logMessage(self.crs.description(), tag='Import .3d', level=Qgis.Info) else: # hopefully never happens msg = "CRS invalid!" QgsMessageLog.logMessage(msg, tag='Import .3d', level=Qgis.Info) self.crs = None
def reprojectCoords(self): self.refreshCoordsMatrix(self.prev_row) if self.valueChecker.checkCoordsMatrix(self.coords_matrix): srcProj = QgsCoordinateReferenceSystem() srcProj.createFromSrsId(self.featureCrsId) crsSelectorFrom = QgsProjectionSelectionDialog() crsSelectorFrom.setCrs(srcProj) crsSelectorFrom.setMessage( self.translate_str("Select source coordinates system")) if crsSelectorFrom.exec(): crsSelectorTo = QgsProjectionSelectionDialog() crsSelectorTo.setMessage( self.translate_str( "Select destination coordinates system")) if crsSelectorTo.exec(): rc = ReprojectCoordinates(crsSelectorFrom.crs().srsid(), crsSelectorTo.crs().srsid(), self.has_Z, self.has_M) self.coords_matrix = list( rc.reproject(self.coords_matrix, False)) self.__part_changing = True self.refreshTable(self.prev_row) self.__part_changing = False self.featureCrsId = crsSelectorTo.crs().srsid() if self.featureCrsId == self.mapCanvas.currentLayer().crs( ).srsid(): self.rb_LayerCrs.setChecked(True) elif self.featureCrsId == self.projectCrsId: self.rb_ProjectCrs.setChecked(True) else: self.rb_OtherCrs.blockSignals(True) self.rb_OtherCrs.setChecked(True) self.rb_OtherCrs.blockSignals(False) self.__displayAuthid()