Esempio n. 1
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. 2
0
    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 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())))
Esempio n. 4
0
    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())
Esempio n. 5
0
    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 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 !")
Esempio n. 7
0
    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())
Esempio n. 8
0
    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 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. 10
0
    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())
Esempio n. 11
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. 12
0
    def select_crs(self):
        """
            Open Qgis CRS selector
        """
        proj_selector = QgsGenericProjectionSelector()
        proj_selector.exec_()
        proj = proj_selector.selectedAuthId()

        self.gui.crsValue.setText(proj)
Esempio n. 13
0
    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)
Esempio n. 14
0
 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')
Esempio n. 15
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. 16
0
    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_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+")")
Esempio n. 18
0
 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
Esempio n. 19
0
 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 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))
Esempio n. 21
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. 22
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. 23
0
 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 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
Esempio n. 26
0
 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())
Esempio n. 27
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. 28
0
 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
Esempio n. 29
0
 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)
Esempio n. 30
0
 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)
Esempio n. 31
0
class CRSButton(QPushButton) :

    def __init__(self) :
        super(QPushButton, self).__init__()
        self.crsDialog = QgsGenericProjectionSelector()
        QObject.connect(self, SIGNAL("clicked()"), self.crsDialog.exec_)
        QObject.connect(self, SIGNAL("clicked()"), self.update)
        self._crs = None

    def crs(self) :
        return self._crs

    def setCrs(self, cr) :
        self._crs = cr
        self.setText(cr.description())
        self.crsDialog.setSelectedAuthId(cr.authid())

    def update(self) :
        self.setCrs(QgsCoordinateReferenceSystem(self.crsDialog.selectedAuthId()))
Esempio n. 32
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. 33
0
 def loadAvailableSystems(self):
     coordSys = ""
     crsDlg = QgsGenericProjectionSelector(self.parent)
     if crsDlg.exec_() == QDialog.Accepted:
         coordSys = str(crsDlg.selectedAuthId())
     return coordSys
Esempio n. 34
0
 def geomapfishCrsButtonClicked(self):
     dlg = QgsGenericProjectionSelector(self)
     dlg.setMessage('Select GeoMapFish CRS')
     dlg.setSelectedAuthId(self.geomapfishCrs.text())
     if dlg.exec_():
         self.geomapfishCrs.setText(dlg.selectedAuthId())
Esempio n. 35
0
 def loadAvailableSystems(self):
     coordSys=""
     crsDlg=QgsGenericProjectionSelector(self.parent)
     if crsDlg.exec_()==QDialog.Accepted:
         coordSys=str(crsDlg.selectedAuthId())
     return coordSys
Esempio n. 36
0
 def geomapfishCrsButtonClicked(self):
     dlg = QgsGenericProjectionSelector(self)
     dlg.setMessage('Select GeoMapFish CRS')
     dlg.setSelectedAuthId(self.geomapfishCrs.text())
     if dlg.exec_():
         self.geomapfishCrs.setText(dlg.selectedAuthId())
Esempio n. 37
0
    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)