def run(self):
        vectorLayers = self.get_vector_layers()
        
        # get the currently active layer (if any)
        # layer = self.iface.mapCanvas().currentLayer()
        # if not hasattr(layer, 'isUsingRendererV2'):
        #     QMessageBox.information(None,"TileMill Exporter", "Please upgrade your version of qgis")
        #     return
        # # test for valid vector layer
        # if layer:
        #     if layer.type() == layer.VectorLayer:
        #         if layer.isUsingRendererV2() and layer.rendererV2().type() == 'graduatedSymbol':
        #             self.processGraduatedRenderer(renderer=layer.rendererV2())
        #             return
        #     QMessageBox.information(None,"TileMill Exporter","Unsupported renderer")
        #     #return
        # QMessageBox.information(None,"TileMill Exporter", "A vector layer must be selected")
        # #return


        # create and show the dialog
        dlg = QGISTileMillExportDialog(vectorLayers)
        # show the dialog
        dlg.show()
        result = dlg.exec_()
        # See if OK was pressed
        if result == 1:
            # do something useful (delete the line containing pass and
            # substitute with your code
            pass
Exemplo n.º 2
0
    def run(self):
        def processGraduatedRenderer(renderer):
            mss = ''
            attr = str(renderer.classAttribute())
            for i,ran in enumerate(renderer.ranges()):
                r = ran.symbol().symbolLayer(0).color().red()
                g = ran.symbol().symbolLayer(0).color().green()
                b = ran.symbol().symbolLayer(0).color().blue()
                a = ran.symbol().symbolLayer(0).color().alpha()
                if float(a) < 1:
                    color = "rgba({},{},{},{})".format(r,g,b,a)
                else:
                    color = "rgb({},{},{})".format(r,g,b)
                line_symbol = "line-color: {};".format(color)
                
                if i==0:
                    mss += "[{} <= {:.5}]{{ {} }}\n".format(attr, ran.upperValue(), line_symbol)
                elif i==len(renderer.ranges())-1:
                    mss+= "[{} > {:.5}]{{ {} }}\n".format(attr, ran.lowerValue(), line_symbol)
                else:
                    mss += "[{attr} > {lower:.5}][{attr} <= {upper:.5}]{{ {sym} }}\n".format(attr=attr, lower=ran.lowerValue(), upper=ran.upperValue(), sym=line_symbol)
            QMessageBox.information(None,"TileMill Exporter",mss)
            return

            '''for ran in rendererV2.ranges():
              print "%f - %f: %s %s" % (
                  range.lowerValue(),
                  range.upperValue(),
                  range.label(),
                  str(range.symbol())
                  )'''
        # get the currently active layer (if any)
        layer = self.iface.mapCanvas().currentLayer()
        if not hasattr(layer, 'isUsingRendererV2'):
            QMessageBox.information(None,"TileMill Exporter", "Please upgrade your version of qgis")
            return
        # test for valid vector layer
        if layer:
            if layer.type() == layer.VectorLayer:
                if layer.isUsingRendererV2() and layer.rendererV2().type() == 'graduatedSymbol':
                    processGraduatedRenderer(renderer=layer.rendererV2())
                    return
            QMessageBox.information(None,"TileMill Exporter","Unsupported renderer")
            return
        QMessageBox.information(None,"TileMill Exporter", "A vector layer must be selected")
        return


        # create and show the dialog
        dlg = QGISTileMillExportDialog()
        # show the dialog
        dlg.show()
        result = dlg.exec_()
        # See if OK was pressed
        if result == 1:
            # do something useful (delete the line containing pass and
            # substitute with your code
            pass