Beispiel #1
0
    def update_syms(self, catalogue):
        self.syms = {}

        for flag in set(catalogue.data['Cluster_Flag'].tolist()):
            for index in set(catalogue.data['Cluster_Index'].tolist()):

                # main shock
                point = QgsMarkerSymbolV2.createSimple(
                    {'color': 'blue', 'name': 'square'})

                if index:  # belongs to a cluster
                    color = self.catalogue_model.cluster_color(index)

                    # non poissonian
                    if flag:
                        point = QgsMarkerSymbolV2.createSimple(
                            {'color': 'blue', 'name': 'triangle'})
                    color.setAlpha(125 + 125 * abs(flag))
                    point.setSize(3)
                    point.setColor(color)
                else:
                    point = QgsSymbolV2.defaultSymbol(QGis.Point)
                    point.setColor(QtGui.QColor("0,0,0,125"))
                    point.setSize(1.5)
                self.syms[self.Cluster(index, flag)] = point
    def legend_test(self):
        self.mAtlasMap.setAtlasDriven(True)
        self.mAtlasMap.setAtlasScalingMode(QgsComposerMap.Auto)
        self.mAtlasMap.setAtlasMargin(0.10)

        # add a point layer
        ptLayer = QgsVectorLayer("Point?crs=epsg:4326&field=attr:int(1)&field=label:string(20)", "points", "memory")

        pr = ptLayer.dataProvider()
        f1 = QgsFeature(1)
        f1.initAttributes(2)
        f1.setAttribute(0, 1)
        f1.setAttribute(1, "Test label 1")
        f1.setGeometry(QgsGeometry.fromPoint(QgsPoint(-0.638, 48.954)))
        f2 = QgsFeature(2)
        f2.initAttributes(2)
        f2.setAttribute(0, 2)
        f2.setAttribute(1, "Test label 2")
        f2.setGeometry(QgsGeometry.fromPoint(QgsPoint(-1.682, 48.550)))
        pr.addFeatures([f1, f2])

        # categorized symbology
        r = QgsCategorizedSymbolRendererV2("attr", [QgsRendererCategoryV2(1, QgsMarkerSymbolV2.createSimple({"color": "255,0,0"}), "red"),
                                                    QgsRendererCategoryV2(2, QgsMarkerSymbolV2.createSimple({"color": "0,0,255"}), "blue")])
        ptLayer.setRendererV2(r)

        QgsMapLayerRegistry.instance().addMapLayer(ptLayer)

        # add the point layer to the map settings
        layers = self.mapSettings.layers()
        layers = [ptLayer.id()] + layers
        self.mapSettings.setLayers(layers)

        # add a legend
        legend = QgsComposerLegend(self.mComposition)
        legend.moveBy(200, 100)
        # sets the legend filter parameter
        legend.setComposerMap(self.mAtlasMap)
        legend.setLegendFilterOutAtlas(True)
        self.mComposition.addComposerLegend(legend)

        self.mAtlas.beginRender()

        self.mAtlas.prepareForFeature(0)
        self.mLabel1.adjustSizeToText()

        checker = QgsCompositionChecker('atlas_legend', self.mComposition)
        myTestResult, myMessage = checker.testComposition()
        assert myTestResult

        self.mAtlas.endRender()

        # restore state
        self.mapSettings.setLayers([layers[1]])
        self.mComposition.removeComposerItem(legend)
        QgsMapLayerRegistry.instance().removeMapLayer(ptLayer.id())
Beispiel #3
0
    def getmap(self):
        if self.canvas:
            settings = self.canvas.mapSettings()
            layers = settings.layers()
            if GPS.isConnected:
                try:
                    gpslayer = QgsMapLayerRegistry.instance().mapLayersByName(
                        "__gps_layer")[0]
                except IndexError:
                    gpslayer = QgsVectorLayer("Point", "__gps_layer", "memory")
                    symbol = QgsMarkerSymbolV2.createSimple({
                        'name': 'circle',
                        'color': 'blue',
                        "size": '5'
                    })
                    gpslayer.rendererV2().setSymbol(symbol)
                    QgsMapLayerRegistry.instance().addMapLayer(gpslayer, False)

                layers.append(gpslayer.id())
                settings.setLayers(layers)

                map_pos = QgsPoint(GPS.gpsinfo("longitude"),
                                   GPS.gpsinfo("latitude"))
                # map_pos = QgsPoint(115.72589,-32.29597)
                geom = QgsGeometry.fromPoint(map_pos)
                feature = QgsFeature()
                feature.setGeometry(geom)
                gpslayer.startEditing()
                gpslayer.addFeature(feature)
                # gpslayer.commitChanges()

            self.renderjob = QgsMapRendererParallelJob(settings)
            self.renderjob.finished.connect(self.rendermap)
            self.renderjob.start()
    def setUp(self):
        self.iface = get_iface()

        polys_shp = os.path.join(TEST_DATA_DIR, 'polys.shp')
        points_shp = os.path.join(TEST_DATA_DIR, 'points.shp')
        lines_shp = os.path.join(TEST_DATA_DIR, 'lines.shp')
        self.polys_layer = QgsVectorLayer(polys_shp, 'Polygons', 'ogr')
        self.points_layer = QgsVectorLayer(points_shp, 'Points', 'ogr')
        self.lines_layer = QgsVectorLayer(lines_shp, 'Lines', 'ogr')
        QgsMapLayerRegistry.instance().addMapLayer(self.polys_layer)
        QgsMapLayerRegistry.instance().addMapLayer(self.lines_layer)
        QgsMapLayerRegistry.instance().addMapLayer(self.points_layer)

        # Create style
        sym1 = QgsFillSymbolV2.createSimple({'color': '#fdbf6f'})
        sym2 = QgsLineSymbolV2.createSimple({'color': '#fdbf6f'})
        sym3 = QgsMarkerSymbolV2.createSimple({'color': '#fdbf6f'})

        self.polys_layer.setRendererV2(QgsSingleSymbolRendererV2(sym1))
        self.lines_layer.setRendererV2(QgsSingleSymbolRendererV2(sym2))
        self.points_layer.setRendererV2(QgsSingleSymbolRendererV2(sym3))

        self.mapsettings = self.iface.mapCanvas().mapSettings()
        self.mapsettings.setOutputSize(QSize(400, 400))
        self.mapsettings.setOutputDpi(96)
        self.mapsettings.setExtent(QgsRectangle(-133, 22, -70, 52))
    def setUp(self):
        self.iface = get_iface()

        polys_shp = os.path.join(TEST_DATA_DIR, 'polys.shp')
        points_shp = os.path.join(TEST_DATA_DIR, 'points.shp')
        lines_shp = os.path.join(TEST_DATA_DIR, 'lines.shp')
        self.polys_layer = QgsVectorLayer(polys_shp, 'Polygons', 'ogr')
        self.points_layer = QgsVectorLayer(points_shp, 'Points', 'ogr')
        self.lines_layer = QgsVectorLayer(lines_shp, 'Lines', 'ogr')
        QgsMapLayerRegistry.instance().addMapLayer(self.polys_layer)
        QgsMapLayerRegistry.instance().addMapLayer(self.lines_layer)
        QgsMapLayerRegistry.instance().addMapLayer(self.points_layer)

        # Create style
        sym1 = QgsFillSymbolV2.createSimple({'color': '#fdbf6f'})
        sym2 = QgsLineSymbolV2.createSimple({'color': '#fdbf6f'})
        sym3 = QgsMarkerSymbolV2.createSimple({'color': '#fdbf6f'})

        self.polys_layer.setRendererV2(QgsSingleSymbolRendererV2(sym1))
        self.lines_layer.setRendererV2(QgsSingleSymbolRendererV2(sym2))
        self.points_layer.setRendererV2(QgsSingleSymbolRendererV2(sym3))

        self.mapsettings = self.iface.mapCanvas().mapSettings()
        self.mapsettings.setOutputSize(QSize(400, 400))
        self.mapsettings.setOutputDpi(96)
        self.mapsettings.setExtent(QgsRectangle(-133, 22, -70, 52))
Beispiel #6
0
    def getmap(self):
        if self.canvas:
            settings = self.canvas.mapSettings()
            layers = settings.layers()
            if GPS.isConnected:
                try:
                    gpslayer = QgsMapLayerRegistry.instance().mapLayersByName("__gps_layer")[0]
                except IndexError:
                    gpslayer = QgsVectorLayer("Point", "__gps_layer", "memory")
                    symbol = QgsMarkerSymbolV2.createSimple({'name': 'circle', 'color': 'blue', "size": '5'})
                    gpslayer.rendererV2().setSymbol(symbol)
                    QgsMapLayerRegistry.instance().addMapLayer(gpslayer, False)

                layers.append(gpslayer.id())
                settings.setLayers(layers)

                map_pos = QgsPoint(GPS.gpsinfo("longitude"), GPS.gpsinfo("latitude"))
                # map_pos = QgsPoint(115.72589,-32.29597)
                geom = QgsGeometry.fromPoint(map_pos)
                feature = QgsFeature()
                feature.setGeometry(geom)
                gpslayer.startEditing()
                gpslayer.addFeature(feature)
                # gpslayer.commitChanges()

            self.renderjob = QgsMapRendererParallelJob(settings)
            self.renderjob.finished.connect(self.rendermap)
            self.renderjob.start()
def createMarkerSymbol():
    symbol = QgsMarkerSymbolV2.createSimple({
        "color": "100,150,50",
        "name": "square",
        "size": "3.0"
    })
    return symbol
Beispiel #8
0
    def buildRenderer(self, xAttr, yAttr):
        color = QColor(randint(0, 255), randint(0, 255), randint(0, 255))
        symbol = QgsMarkerSymbolV2.createSimple({})
        symbol.deleteSymbolLayer(0)

        prop = QgsDataDefined()
        prop.setField("size")
        prop.setActive(True)

        symbol_layer = QgsSimpleMarkerSymbolLayerV2()
        symbol_layer.setColor(color)
        symbol_layer.setOutputUnit(QgsSymbolV2.MapUnit)
        symbol_layer.setDataDefinedProperty("size", prop)
        symbol.appendSymbolLayer(symbol_layer)

        symbol_layer = QgsVectorFieldSymbolLayer()
        symbol_layer.setColor(color)
        symbol_layer.VectorFieldType(QgsVectorFieldSymbolLayer.Cartesian)
        symbol_layer.AngleUnits(QgsVectorFieldSymbolLayer.Degrees)
        symbol_layer.setScale(2.0)
        symbol_layer.setXAttribute(xAttr)
        symbol_layer.setYAttribute(yAttr)
        subSymbol = self.subRenderer(color)
        symbol_layer.setSubSymbol(subSymbol)

        symbol.appendSymbolLayer(symbol_layer)

        renderer = QgsSingleSymbolRendererV2(symbol)

        return renderer
Beispiel #9
0
    def make_svg_link_sym_renderer(self, icon_name, svg_size=7, line_width=0.2):

        symbol = QgsLineSymbolV2().createSimple({})
        symbol.deleteSymbolLayer(0)

        # Line
        line_sym_lay = QgsSimpleLineSymbolLayerV2()
        line_sym_lay.setWidth(line_width)
        symbol.appendSymbolLayer(line_sym_lay)

        # Symbol
        self.marker_sym = QgsMarkerSymbolV2.createSimple({})
        self.marker_sym.deleteSymbolLayer(0)

        # marker_sym_lay = QgsSimpleMarkerSymbolLayerV2()
        current_dir = os.path.dirname(__file__)
        svg_props = dict()
        svg_props['name'] = os.path.join(current_dir, icon_name)
        svg_props['size'] = str(svg_size)
        marker_sym_lay = QgsSvgMarkerSymbolLayerV2().create(svg_props)
        self.marker_sym.appendSymbolLayer(marker_sym_lay)

        marker_line_sym_lay = QgsMarkerLineSymbolLayerV2()
        marker_line_sym_lay.setSubSymbol(self.marker_sym)  # Causes crash !!!
        marker_line_sym_lay.setPlacement(QgsMarkerLineSymbolLayerV2.CentralPoint)

        symbol.appendSymbolLayer(marker_line_sym_lay)

        renderer = QgsSingleSymbolRendererV2(symbol)
        return renderer
def createMarkerSymbol():
    symbol = QgsMarkerSymbolV2.createSimple({
        "color": "100,150,50",
        "name": "square",
        "size": "3.0"
    })
    return symbol
Beispiel #11
0
 def __init__(self):
     QgsFeatureRendererV2.__init__(self, "CatalogueCompletenessRenderer")
     complete = QgsSymbolV2.defaultSymbol(QGis.Point)
     uncomplete = QgsMarkerSymbolV2.createSimple(
         {'color': 'blue', 'name': 'triangle'})
     uncomplete.setSize(3)
     complete.setSize(1.5)
     complete.setColor(QtGui.QColor(255, 0, 0, 125))
     self.syms = [complete, uncomplete]
Beispiel #12
0
 def create_qlayer(self):
     layer= QgsVectorLayer("Point"+self.crs, self.prefix+"-nodes", "memory")
     # nice clean black dot
     symbol = QgsMarkerSymbolV2.createSimple({'outline_style':'no',
                                              'name': 'circle', 
                                              'size_unit':'MM',
                                              'size':'1',
                                              'color': 'black'})
     layer.rendererV2().setSymbol(symbol)
     return layer
Beispiel #13
0
 def setUp(self):
     #Create some simple symbols
     self.fill_symbol = QgsFillSymbolV2.createSimple({'color': '#ffffff'})
     self.line_symbol = QgsLineSymbolV2.createSimple({
         'color': '#ffffff',
         'line_width': '3'
     })
     self.marker_symbol = QgsMarkerSymbolV2.createSimple({
         'color': '#ffffff',
         'size': '3'
     })
     self.report = "<h1>Python QgsSymbolV2 Tests</h1>\n"
 def addLayer(self):
     uri = QgsDataSourceURI()
     # set host name, port, database name, username and password
     #uri.setConnection("localhost", "5432", "jguelat", "jguelat", "")
     uri.setConnection("local_jguelat", "", "", "")
     # set database schema, table name, geometry column and optionally subset (WHERE clause)
     uri.setDataSource("public", self.tableCombo.currentText(), "geom", "species_id = " + self.speciesCombo.currentText())
     #vlayer = self.iface.addVectorLayer(uri.uri(), "Species " + self.speciesCombo.currentText(), "postgres")
     vlayer = QgsVectorLayer(uri.uri(), "Species " + self.speciesCombo.currentText(), "postgres")
     props = vlayer.rendererV2().symbol().symbolLayer(0).properties()
     props['size'] = '3'
     props['color'] = 'blue'
     vlayer.rendererV2().setSymbol(QgsMarkerSymbolV2.createSimple(props))
     QgsMapLayerRegistry.instance().addMapLayer(vlayer)
     QgsMessageLog.logMessage("Tout est OK", 'BirdChooser', QgsMessageLog.INFO)
Beispiel #15
0
def createLayerControle(proj):

    layerStopLine = QgsVectorLayer("Point?crs=" + proj,
                                   CONST_NOM_LAYER_PT_CONTROLE, "memory")

    # Style
    # Symbologie des stations
    symbolPoint = QgsMarkerSymbolV2.createSimple({
        'name': 'square',
        'color_border': '255,216,0'
    })
    symbolPoint.setColor(QColor.fromRgb(255, 216, 0))  #F 216,7,96
    symbolPoint.setSize(2)
    layerStopLine.rendererV2().setSymbol(symbolPoint)

    return layerStopLine
 def test_point_ordered_symbol_bound_offset(self):
     # Test ordered placements for point using symbol bounds offset
     self.layer = TestQgsPalLabeling.loadFeatureLayer('point_ordered_placement')
     # Make a big symbol
     symbol = QgsMarkerSymbolV2.createSimple({u'color': u'31,120,180,255',
                                              u'outline_color': u'0,0,0,0',
                                              u'outline_style': u'solid',
                                              u'size': u'10',
                                              u'name': u'rectangle',
                                              u'size_unit': u'MM'})
     renderer = QgsSingleSymbolRendererV2(symbol)
     self.layer.setRendererV2(renderer)
     self._TestMapSettings = self.cloneMapSettings(self._MapSettings)
     self.lyr.placement = QgsPalLayerSettings.OrderedPositionsAroundPoint
     self.lyr.dist = 2
     self.lyr.offsetType = QgsPalLayerSettings.FromSymbolBounds
     self.checkTest()
     self.removeMapLayer(self.layer)
     self.layer = None
    def testInitialSizeSymbolMapUnits(self):
        """Test initial size of legend with a symbol size in map units"""

        point_path = os.path.join(TEST_DATA_DIR, 'points.shp')
        point_layer = QgsVectorLayer(point_path, 'points', 'ogr')
        QgsMapLayerRegistry.instance().addMapLayers([point_layer])

        marker_symbol = QgsMarkerSymbolV2.createSimple({
            'color': '#ff0000',
            'outline_style': 'no',
            'size': '5',
            'size_unit': 'MapUnit'
        })

        point_layer.setRendererV2(QgsSingleSymbolRendererV2(marker_symbol))

        s = QgsMapSettings()
        s.setLayers([point_layer.id()])
        s.setCrsTransformEnabled(False)
        composition = QgsComposition(s)
        composition.setPaperSize(297, 210)

        composer_map = QgsComposerMap(composition, 20, 20, 80, 80)
        composer_map.setFrameEnabled(True)
        composition.addComposerMap(composer_map)
        composer_map.setNewExtent(point_layer.extent())

        legend = QgsComposerLegend(composition)
        legend.setSceneRect(QRectF(120, 20, 80, 80))
        legend.setFrameEnabled(True)
        legend.setFrameOutlineWidth(2)
        legend.setBackgroundColor(QColor(200, 200, 200))
        legend.setTitle('')
        composition.addComposerLegend(legend)
        legend.setComposerMap(composer_map)

        checker = QgsCompositionChecker('composer_legend_mapunits',
                                        composition)
        checker.setControlPathPrefix("composer_legend")
        result, message = checker.testComposition()
        self.assertTrue(result, message)

        QgsMapLayerRegistry.instance().removeMapLayers([point_layer.id()])
 def test_point_ordered_symbol_bound_offset(self):
     # Test ordered placements for point using symbol bounds offset
     self.layer = TestQgsPalLabeling.loadFeatureLayer(
         'point_ordered_placement')
     # Make a big symbol
     symbol = QgsMarkerSymbolV2.createSimple({
         u'color': u'31,120,180,255',
         u'outline_color': u'0,0,0,0',
         u'outline_style': u'solid',
         u'size': u'10',
         u'name': u'rectangle',
         u'size_unit': u'MM'
     })
     renderer = QgsSingleSymbolRendererV2(symbol)
     self.layer.setRendererV2(renderer)
     self._TestMapSettings = self.cloneMapSettings(self._MapSettings)
     self.lyr.placement = QgsPalLayerSettings.OrderedPositionsAroundPoint
     self.lyr.dist = 2
     self.lyr.offsetType = QgsPalLayerSettings.FromSymbolBounds
     self.checkTest()
     self.removeMapLayer(self.layer)
     self.layer = None
    def testInitialSizeSymbolMapUnits(self):
        """Test initial size of legend with a symbol size in map units"""

        point_path = os.path.join(TEST_DATA_DIR, 'points.shp')
        point_layer = QgsVectorLayer(point_path, 'points', 'ogr')
        QgsMapLayerRegistry.instance().addMapLayers([point_layer])

        marker_symbol = QgsMarkerSymbolV2.createSimple({'color': '#ff0000', 'outline_style': 'no', 'size': '5', 'size_unit': 'MapUnit'})

        point_layer.setRendererV2(QgsSingleSymbolRendererV2(marker_symbol))

        s = QgsMapSettings()
        s.setLayers([point_layer.id()])
        s.setCrsTransformEnabled(False)
        composition = QgsComposition(s)
        composition.setPaperSize(297, 210)

        composer_map = QgsComposerMap(composition, 20, 20, 80, 80)
        composer_map.setFrameEnabled(True)
        composition.addComposerMap(composer_map)
        composer_map.setNewExtent(point_layer.extent())

        legend = QgsComposerLegend(composition)
        legend.setSceneRect(QRectF(120, 20, 80, 80))
        legend.setFrameEnabled(True)
        legend.setFrameOutlineWidth(2)
        legend.setBackgroundColor(QColor(200, 200, 200))
        legend.setTitle('')
        composition.addComposerLegend(legend)
        legend.setComposerMap(composer_map)

        checker = QgsCompositionChecker(
            'composer_legend_mapunits', composition)
        checker.setControlPathPrefix("composer_legend")
        result, message = checker.testComposition()
        self.assertTrue(result, message)

        QgsMapLayerRegistry.instance().removeMapLayers([point_layer.id()])
Beispiel #20
0
    def create_virtual_layer(self, virtual_layer_name):

        sql = (
            "SELECT value FROM " + self.controller.schema_name +
            ".config_param_user"
            " WHERE cur_user = current_user AND parameter = 'virtual_layer_point'"
        )
        row = self.controller.get_row(sql)
        if not row:
            sql = ("INSERT INTO " + self.schema_name +
                   ".config_param_user (parameter, value, cur_user) "
                   " VALUES ('virtual_layer_point', '" + virtual_layer_name +
                   "', current_user)")
            self.controller.execute_sql(sql)
        uri = "Point?crs=epsg:" + str(self.srid)
        virtual_layer = QgsVectorLayer(uri, virtual_layer_name, "memory")
        props = {'color': 'red', 'color_border': 'red', 'size': '1.5'}
        s = QgsMarkerSymbolV2.createSimple(props)
        virtual_layer.setRendererV2(QgsSingleSymbolRendererV2(s))
        virtual_layer.updateExtents()
        QgsProject.instance().setSnapSettingsForLayer(virtual_layer.id(), True,
                                                      0, 0, 1.0, False)
        QgsMapLayerRegistry.instance().addMapLayer(virtual_layer)
        self.iface.mapCanvas().refresh()
Beispiel #21
0
 def setUp(self):
     # Create some simple symbols
     self.fill_symbol = QgsFillSymbolV2.createSimple({"color": "#ffffff"})
     self.line_symbol = QgsLineSymbolV2.createSimple({"color": "#ffffff", "line_width": "3"})
     self.marker_symbol = QgsMarkerSymbolV2.createSimple({"color": "#ffffff", "size": "3"})
     self.report = "<h1>Python QgsSymbolV2 Tests</h1>\n"
    def legend_test(self):
        self.mAtlasMap.setAtlasDriven(True)
        self.mAtlasMap.setAtlasScalingMode(QgsComposerMap.Auto)
        self.mAtlasMap.setAtlasMargin(0.10)

        # add a point layer
        ptLayer = QgsVectorLayer(
            "Point?crs=epsg:4326&field=attr:int(1)&field=label:string(20)",
            "points", "memory")

        pr = ptLayer.dataProvider()
        f1 = QgsFeature(1)
        f1.initAttributes(2)
        f1.setAttribute(0, 1)
        f1.setAttribute(1, "Test label 1")
        f1.setGeometry(QgsGeometry.fromPoint(QgsPoint(-0.638, 48.954)))
        f2 = QgsFeature(2)
        f2.initAttributes(2)
        f2.setAttribute(0, 2)
        f2.setAttribute(1, "Test label 2")
        f2.setGeometry(QgsGeometry.fromPoint(QgsPoint(-1.682, 48.550)))
        pr.addFeatures([f1, f2])

        # categorized symbology
        r = QgsCategorizedSymbolRendererV2("attr", [
            QgsRendererCategoryV2(
                1, QgsMarkerSymbolV2.createSimple({"color": "255,0,0"}),
                "red"),
            QgsRendererCategoryV2(
                2, QgsMarkerSymbolV2.createSimple({"color": "0,0,255"}),
                "blue")
        ])
        ptLayer.setRendererV2(r)

        QgsMapLayerRegistry.instance().addMapLayer(ptLayer)

        # add the point layer to the map settings
        layers = self.mapSettings.layers()
        layers = [ptLayer.id()] + layers
        self.mapSettings.setLayers(layers)

        # add a legend
        legend = QgsComposerLegend(self.mComposition)
        legend.moveBy(200, 100)
        # sets the legend filter parameter
        legend.setComposerMap(self.mAtlasMap)
        legend.setLegendFilterOutAtlas(True)
        self.mComposition.addComposerLegend(legend)

        self.mAtlas.beginRender()

        self.mAtlas.prepareForFeature(0)
        self.mLabel1.adjustSizeToText()

        checker = QgsCompositionChecker('atlas_legend', self.mComposition)
        myTestResult, myMessage = checker.testComposition()
        assert myTestResult

        self.mAtlas.endRender()

        # restore state
        self.mapSettings.setLayers([layers[1]])
        self.mComposition.removeComposerItem(legend)
        QgsMapLayerRegistry.instance().removeMapLayer(ptLayer.id())
Beispiel #23
0
    def make_flow_sym_renderer(self, layer, field_name, ranges_colors=None):

        feats = layer.getFeatures()

        min_val = sys.float_info.max
        max_val = -min_val

        # Find values range
        for feat in feats:
            attr = feat.attribute(field_name)
            val = float(attr)
            if val < min_val:
                min_val = val
            if val > max_val:
                max_val = val

        # Define colors
        if ranges_colors is None:
            ranges_colors = []
            colors = [
                QColor(0, 255, 0),
                QColor(128, 255, 0),
                QColor(255, 255, 0),
                QColor(255, 128, 0),
                QColor(255, 0, 0)]

            intv_nr = len(colors)
            intv = (max_val - min_val) / intv_nr
            for c in range(intv_nr):
                vrange = [min_val + intv * c, min_val + intv * (c + 1)]

                if c == len(colors) - 1:
                    vrange[1] = max_val

                ranges_colors.append([vrange, colors[c]])

        range_list = []
        for range_col in ranges_colors:
            r_min = range_col[0][0]
            r_max = range_col[0][1]
            title = str(r_min) + ' - ' + str(r_max)
            range_list.append(symbology_from_range(layer, r_min, r_max, range_col[1], title))

        renderer = QgsGraduatedSymbolRendererV2(field_name, range_list)

        # Line
        symbol = QgsLineSymbolV2().createSimple({})
        symbol.deleteSymbolLayer(0)
        line_sym_lay = QgsSimpleLineSymbolLayerV2()
        line_sym_lay.setWidth(0.2)
        symbol.appendSymbolLayer(line_sym_lay)

        # Define arrows for flow and velocities
        if u'Link flow' in layer.name() in layer.name():
            self.marker_sym = QgsMarkerSymbolV2.createSimple({'name': 'triangle', 'color': 'black'})
            data_def_angle = QgsDataDefined()
            data_def_angle_exp =\
                'case ' \
                    'when  "' + field_name + '"  >= 0 ' \
                        'then degrees(azimuth( start_point( $geometry), end_point($geometry))) ' \
                    'else ' \
                        'case ' \
                            'when degrees(azimuth( start_point( $geometry), end_point($geometry)))  < 180 ' \
                                'then degrees(azimuth( start_point( $geometry), end_point($geometry))) + 180 ' \
                            'else ' \
                                'degrees(azimuth( start_point( $geometry), end_point($geometry))) - 180 ' \
                        'end ' \
                'end'
            data_def_angle.setExpressionString(data_def_angle_exp)
            data_def_angle.setActive(True)
            self.marker_sym.setDataDefinedAngle(data_def_angle)

            # Size: 0 if attribute = 0
            data_def_size = QgsDataDefined()
            data_def_size_exp =\
                'case ' \
                    'when "' + field_name + '" = 0 ' \
                        'then 0 ' \
                    'else ' \
                        '2 ' \
                'end'
            data_def_size.setExpressionString(data_def_size_exp)
            data_def_size.setActive(True)
            self.marker_sym.setDataDefinedSize(data_def_size)


            marker_sym_lay = QgsMarkerLineSymbolLayerV2()
            marker_sym_lay.setColor(QColor(0, 0, 0))
            marker_sym_lay.setFillColor(QColor(0, 0, 0))
            marker_sym_lay.setPlacement(QgsMarkerLineSymbolLayerV2.CentralPoint)
            marker_sym_lay.setRotateMarker(False)
            marker_sym_lay.setSubSymbol(self.marker_sym)

            self.marker_sym.appendSymbolLayer(marker_sym_lay)

            symbol.appendSymbolLayer(marker_sym_lay)

        # renderer.setSourceSymbol(symbol)
        renderer.updateSymbols(symbol)

        return renderer
# coding: utf-8
from qgis.core import QgsMarkerSymbolV2
from qgis.gui import QgsSizeScaleWidget
from qgis.utils import iface


layer = iface.activeLayer()
canvas = iface.mapCanvas()
marker_symbol_v2 = QgsMarkerSymbolV2.createSimple({"color": "blue", "name": "triangle"})

size_scale_widget = QgsSizeScaleWidget(layer, marker_symbol_v2)
size_scale_widget.setMapCanvas(canvas)

size_scale_widget.show()
Beispiel #25
0
 def setUp(self):
     #Create some simple symbols
     self.fill_symbol = QgsFillSymbolV2.createSimple({'color': '#ffffff'})
     self.line_symbol = QgsLineSymbolV2.createSimple({'color': '#ffffff', 'line_width': '3'})
     self.marker_symbol = QgsMarkerSymbolV2.createSimple({'color': '#ffffff', 'size': '3'})
     self.report = "<h1>Python QgsSymbolV2 Tests</h1>\n"
Beispiel #26
0
 def apply(self, layer):
     symbol = QgsMarkerSymbolV2.createSimple({'name': self.shape,
                                              'color': self.color})
     self.renderer = QgsSingleSymbolRendererV2(symbol)
     super(SimpleSymbology, self).apply(layer)
# coding: utf-8
from qgis.core import QgsMarkerSymbolV2
from qgis.gui import QgsSizeScaleWidget
from qgis.utils import iface

layer = iface.activeLayer()
canvas = iface.mapCanvas()
marker_symbol_v2 = QgsMarkerSymbolV2.createSimple({
    'color': 'blue',
    'name': 'triangle'
})

size_scale_widget = QgsSizeScaleWidget(layer, marker_symbol_v2)
size_scale_widget.setMapCanvas(canvas)

size_scale_widget.show()