Esempio n. 1
0
 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()
Esempio n. 2
0
 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 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)
Esempio n. 4
0
 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 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()
Esempio n. 6
0
 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())
Esempio n. 7
0
    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()
Esempio n. 8
0
 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()
Esempio n. 9
0
 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()
Esempio n. 10
0
 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()
Esempio n. 11
0
    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
Esempio n. 12
0
 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_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)"))
Esempio n. 14
0
    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())
Esempio n. 15
0
 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
Esempio n. 16
0
    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)"))
Esempio n. 17
0
    def run_open(self):
        """ Open an UPL and create temporary layers. """

        # Usefull variables
        reg = QgsMapLayerRegistry.instance()
        li = iface.legendInterface()

        # Ask for a filename
        fn = QFileDialog.getOpenFileName(None, "Open ADMS-Urban UPL file", "",
                                         "*.upl")
        if not fn:
            return

        # Open the UPL file
        upl = admsurban.ADMSUrbanUPL()
        upl.read(fn)
        pols = upl.pollutants

        # Projection selector
        projselector = QgsGenericProjectionSelector()
        rc = projselector.exec_()
        if not rc:
            return
        if not int(projselector.selectedCrsId()):
            msg_error("Projection not selected !")
            return
        crs = projselector.selectedAuthId()

        # Create group
        gpname = os.path.basename(fn)
        li.addGroup(gpname)
        idxgp = li.groups().index(gpname)  # index of this group

        # __ Point sources __
        if upl.src_points:

            # Create temporary layer
            vl_pts = QgsVectorLayer("Point?index=yes&crs=%s" % crs,
                                    "ADMS-Urban point sources", "memory")
            pr_pts = vl_pts.dataProvider()
            pr_pts.addAttributes([
                QgsField("src_name", QVariant.String),
            ] + [QgsField(e, QVariant.Double) for e in pols])
            vl_pts.updateFields()

            # Add features
            for src in upl.src_points:
                fet = QgsFeature()
                fet.setGeometry(
                    QgsGeometry.fromPoint(QgsPoint(src.geom.x, src.geom.y)))
                emis = []
                for p in pols:
                    if p in src.srcpol:
                        idx = src.srcpol.index(p)
                        emis.append(src.srcemi[idx])
                    else:
                        emis.append(None)
                fet.setAttributes([
                    src.srcname,
                ] + emis)
                pr_pts.addFeatures([fet])
                del fet, emis

            # Update extent
            vl_pts.setExtent(QgsRectangle(*upl.extent_points))

            # Style
            vl_pts.loadNamedStyle(
                os.path.join(self.plugin_dir, 'style', 'ponct.qml'))
            reg.addMapLayer(vl_pts)
            li.moveLayer(vl_pts, idxgp)

        # __ Road sources __
        if upl.src_roads:

            # Create temporary layer
            vl_road = QgsVectorLayer("LineString?index=yes&crs=%s" % crs,
                                     "ADMS-Urban road sources", "memory")
            pr_road = vl_road.dataProvider()
            pr_road.addAttributes([
                QgsField("src_name", QVariant.String),
            ] + [QgsField(e, QVariant.Double) for e in pols])
            vl_road.updateFields()

            # Add features
            for src in upl.src_roads:
                fet = QgsFeature()
                fet.setGeometry(QgsGeometry.fromWkt(src.geom.wkt))
                emis = []
                for p in pols:
                    if p in src.srcpol:
                        idx = src.srcpol.index(p)
                        emis.append(src.srcemi[idx])
                    else:
                        emis.append(None)
                fet.setAttributes([
                    src.srcname,
                ] + emis)
                pr_road.addFeatures([fet])
                del fet, emis

            # Update extent
            vl_road.setExtent(QgsRectangle(*upl.extent_roads))

            # Style
            vl_road.loadNamedStyle(
                os.path.join(self.plugin_dir, 'style', 'road.qml'))
            reg.addMapLayer(vl_road)
            li.moveLayer(vl_road, idxgp)

        # __ Area sources __
        if upl.src_surfs:

            # Create temporary layer
            vl_area = QgsVectorLayer("Polygon?index=yes&crs=%s" % crs,
                                     "ADMS-Urban area sources", "memory")
            pr_area = vl_area.dataProvider()
            pr_area.addAttributes([
                QgsField("src_name", QVariant.String),
            ] + [QgsField(e, QVariant.Double) for e in pols])
            vl_area.updateFields()

            # Add features
            for src in upl.src_surfs:
                fet = QgsFeature()
                fet.setGeometry(QgsGeometry.fromWkt(src.geom.wkt))
                emis = []
                for p in pols:
                    if p in src.srcpol:
                        idx = src.srcpol.index(p)
                        emis.append(src.srcemi[idx])
                    else:
                        emis.append(None)
                fet.setAttributes([
                    src.srcname,
                ] + emis)
                pr_area.addFeatures([fet])
                del fet, emis

            # Update extent
            vl_area.setExtent(QgsRectangle(*upl.extent_surfs))

            # Style
            vl_area.loadNamedStyle(
                os.path.join(self.plugin_dir, 'style', 'area.qml'))
            reg.addMapLayer(vl_area)
            li.moveLayer(vl_area, idxgp)

        # __ Volume sources __
        if upl.src_vols:

            # Create temporary layer
            vl_vol = QgsVectorLayer("Polygon?index=yes&crs=%s" % crs,
                                    "ADMS-Urban volume sources", "memory")
            pr_vol = vl_vol.dataProvider()
            pr_vol.addAttributes([
                QgsField("src_name", QVariant.String),
            ] + [QgsField(e, QVariant.Double) for e in pols])
            vl_vol.updateFields()

            # Add features
            for src in upl.src_vols:
                fet = QgsFeature()
                fet.setGeometry(QgsGeometry.fromWkt(src.geom.wkt))
                emis = []
                for p in pols:
                    if p in src.srcpol:
                        idx = src.srcpol.index(p)
                        emis.append(src.srcemi[idx])
                    else:
                        emis.append(None)
                fet.setAttributes([
                    src.srcname,
                ] + emis)
                pr_vol.addFeatures([fet])
                del fet, emis

            # Update extent
            vl_vol.setExtent(QgsRectangle(*upl.extent_vols))

            # Style
            vl_vol.loadNamedStyle(
                os.path.join(self.plugin_dir, 'style', 'vol.qml'))
            reg.addMapLayer(vl_vol)
            li.moveLayer(vl_vol, idxgp)

        # __ Cadastre sources __
        if upl.src_cads:

            # Create temporary layer
            vl_cad = QgsVectorLayer("Polygon?index=yes&crs=%s" % crs,
                                    "ADMS-Urban cadastre sources", "memory")
            pr_cad = vl_cad.dataProvider()
            pr_cad.addAttributes([
                QgsField("src_name", QVariant.String),
            ] + [QgsField(e, QVariant.Double) for e in pols])
            vl_cad.updateFields()

            # Add features
            for src in upl.src_cads:
                fet = QgsFeature()
                fet.setGeometry(QgsGeometry.fromWkt(src.geom.wkt))
                emis = []
                for p in pols:
                    if p in src.srcpol:
                        idx = src.srcpol.index(p)
                        emis.append(src.srcemi[idx])
                    else:
                        emis.append(None)
                fet.setAttributes([
                    src.srcname,
                ] + emis)
                pr_cad.addFeatures([fet])
                del fet, emis

            # Update extent
            vl_cad.setExtent(QgsRectangle(*upl.extent_cads))

            # Style
            vl_cad.loadNamedStyle(
                os.path.join(self.plugin_dir, 'style', 'cad.qml'))
            reg.addMapLayer(vl_cad)
            li.moveLayer(vl_cad, idxgp)

        # End
        msg_info("%s loaded" % os.path.basename(fn), duration=5)
Esempio n. 18
0
 def selectCrs(self):
     crsDiag = QgsGenericProjectionSelector()
     crsDiag.exec_()
     crsId = crsDiag.selectedCrsId()
     crsType = QgsCoordinateReferenceSystem.InternalCrsId
     self.crs = QgsCoordinateReferenceSystem(crsId, crsType)