def testPartNum(self):
        # test geometry_part_num variable
        s = QgsLineSymbol()
        s.deleteSymbolLayer(0)

        sym_layer = QgsGeometryGeneratorSymbolLayer.create({'geometryModifier': 'segments_to_lines($geometry)'})
        sym_layer.setSymbolType(QgsSymbol.Line)
        s.appendSymbolLayer(sym_layer)

        marker_line = QgsMarkerLineSymbolLayer(False)
        marker_line.setPlacement(QgsMarkerLineSymbolLayer.FirstVertex)
        f = QgsFontUtils.getStandardTestFont('Bold', 24)
        marker = QgsFontMarkerSymbolLayer(f.family(), 'x', 24, QColor(255, 255, 0))
        marker.setDataDefinedProperty(QgsSymbolLayer.PropertyCharacter, QgsProperty.fromExpression('@geometry_part_num'))
        marker_symbol = QgsMarkerSymbol()
        marker_symbol.changeSymbolLayer(0, marker)
        marker_line.setSubSymbol(marker_symbol)
        marker_line.setAverageAngleLength(0)
        line_symbol = QgsLineSymbol()
        line_symbol.changeSymbolLayer(0, marker_line)
        sym_layer.setSubSymbol(line_symbol)

        # rendering test
        g = QgsGeometry.fromWkt('LineString(0 0, 10 0, 10 10, 0 10)')
        rendered_image = self.renderGeometry(s, g, buffer=4)
        assert self.imageCheck('part_num_variable', 'part_num_variable', rendered_image)

        marker.setDataDefinedProperty(QgsSymbolLayer.PropertyCharacter,
                                      QgsProperty.fromExpression('@geometry_part_count'))

        # rendering test
        g = QgsGeometry.fromWkt('LineString(0 0, 10 0, 10 10, 0 10)')
        rendered_image = self.renderGeometry(s, g, buffer=4)
        assert self.imageCheck('part_count_variable', 'part_count_variable', rendered_image)
    def test_mixed(self):
        sym = self.polys_layer.renderer().symbol()

        buffer_layer = QgsGeometryGeneratorSymbolLayer.create({'geometryModifier': 'buffer($geometry, "value"/15)'})
        buffer_layer.setSymbolType(QgsSymbol.Fill)
        self.assertIsNotNone(buffer_layer.subSymbol())
        sym.appendSymbolLayer(buffer_layer)
        marker_layer = QgsGeometryGeneratorSymbolLayer.create({'geometryModifier': 'centroid($geometry)'})
        marker_layer.setSymbolType(QgsSymbol.Marker)
        sym.appendSymbolLayer(marker_layer)

        rendered_layers = [self.polys_layer]
        self.mapsettings.setLayers(rendered_layers)

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(self.mapsettings)
        renderchecker.setControlName('expected_geometrygenerator_mixed')
        self.assertTrue(renderchecker.runTest('geometrygenerator_mixed'))
    def test_marker(self):
        sym = self.polys_layer.renderer().symbol()
        sym_layer = QgsGeometryGeneratorSymbolLayer.create({'geometryModifier': 'centroid($geometry)'})
        sym_layer.setSymbolType(QgsSymbol.Marker)
        sym.changeSymbolLayer(0, sym_layer)

        rendered_layers = [self.polys_layer]
        self.mapsettings.setLayers(rendered_layers)

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(self.mapsettings)
        renderchecker.setControlName('expected_geometrygenerator_marker')
        self.assertTrue(renderchecker.runTest('geometrygenerator_marker'))
    def test_buffer_lines(self):
        sym = self.lines_layer.renderer().symbol()

        buffer_layer = QgsGeometryGeneratorSymbolLayer.create({"geometryModifier": 'buffer($geometry, "value"/15)'})
        buffer_layer.setSymbolType(QgsSymbol.Fill)
        self.assertIsNotNone(buffer_layer.subSymbol())
        sym.appendSymbolLayer(buffer_layer)

        rendered_layers = [self.lines_layer.id()]
        self.mapsettings.setLayers(rendered_layers)

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(self.mapsettings)
        renderchecker.setControlName("expected_geometrygenerator_buffer_lines")
        self.assertTrue(renderchecker.runTest("geometrygenerator_buffer_lines"))
    def test_buffer_points(self):
        sym = self.points_layer.renderer().symbol()

        buffer_layer = QgsGeometryGeneratorSymbolLayer.create({'geometryModifier': 'buffer($geometry, "staff"/15)', 'outline_color': 'black'})
        buffer_layer.setSymbolType(QgsSymbol.Fill)
        self.assertIsNotNone(buffer_layer.subSymbol())
        sym.appendSymbolLayer(buffer_layer)

        rendered_layers = [self.points_layer]
        self.mapsettings.setLayers(rendered_layers)

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(self.mapsettings)
        renderchecker.setControlName('expected_geometrygenerator_buffer_points')
        self.assertTrue(renderchecker.runTest('geometrygenerator_buffer_points'))
    def test_marker(self):
        sym = self.polys_layer.renderer().symbol()
        sym_layer = QgsGeometryGeneratorSymbolLayer.create(
            {'geometryModifier': 'centroid($geometry)'})
        sym_layer.setSymbolType(QgsSymbol.Marker)
        sym_layer.subSymbol().symbolLayer(0).setStrokeColor(QColor(0, 0, 0))
        sym.changeSymbolLayer(0, sym_layer)

        rendered_layers = [self.polys_layer]
        self.mapsettings.setLayers(rendered_layers)

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(self.mapsettings)
        renderchecker.setControlName('expected_geometrygenerator_marker')
        self.assertTrue(renderchecker.runTest('geometrygenerator_marker'))
    def test_buffer_points(self):
        sym = self.points_layer.renderer().symbol()

        buffer_layer = QgsGeometryGeneratorSymbolLayer.create({'geometryModifier': 'buffer($geometry, "staff"/15)'})
        buffer_layer.setSymbolType(QgsSymbol.Fill)
        self.assertIsNotNone(buffer_layer.subSymbol())
        sym.appendSymbolLayer(buffer_layer)

        rendered_layers = [self.points_layer]
        self.mapsettings.setLayers(rendered_layers)

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(self.mapsettings)
        renderchecker.setControlName('expected_geometrygenerator_buffer_points')
        self.assertTrue(renderchecker.runTest('geometrygenerator_buffer_points'))
    def test_basic(self):
        """
        Test getters/setters
        """
        sym_layer = QgsGeometryGeneratorSymbolLayer.create(
            {'geometryModifier': 'centroid($geometry)'})
        self.assertEqual(sym_layer.geometryExpression(), 'centroid($geometry)')
        sym_layer.setGeometryExpression('project($geometry, 4, 5)')
        self.assertEqual(sym_layer.geometryExpression(),
                         'project($geometry, 4, 5)')

        sym_layer.setSymbolType(Qgis.SymbolType.Marker)
        self.assertEqual(sym_layer.symbolType(), Qgis.SymbolType.Marker)

        sym_layer.setUnits(QgsUnitTypes.RenderMillimeters)
        self.assertEqual(sym_layer.units(), QgsUnitTypes.RenderMillimeters)
示例#9
0
 def crossLinegenerator(self, xmin_source, ymin_source, px, py, u, t, dx,
                        dy, utmcheck, trLLUTM):
     p1 = QgsPoint(xmin_source + px * u, ymin_source + py * t)
     p2 = QgsPoint(xmin_source + px * u + dx, ymin_source + py * t + dy)
     self.utmLLtransform(utmcheck, p1, trLLUTM)
     self.utmLLtransform(utmcheck, p2, trLLUTM)
     properties = {'color': 'black'}
     line_temp = QgsLineSymbol.createSimple(properties)
     line_temp.setWidth(0.05)
     symb = QgsGeometryGeneratorSymbolLayer.create(properties)
     symb.setSymbolType(1)
     symb.setSubSymbol(line_temp)
     symb.setGeometryExpression('make_line(make_point(' + str(p1.x()) +
                                ',(' + str(p1.y()) + ')),make_point(' +
                                str(p2.x()) + ',(' + str(p2.y()) + ')))')
     return symb
示例#10
0
    def test_feature_transformation(self):
        poly_shp = os.path.join(TEST_DATA_DIR, 'polys.shp')
        layer = QgsVectorLayer(poly_shp, 'Layer', 'ogr')

        sub_symbol = QgsFillSymbol.createSimple({
            'color': '#8888ff',
            'outline_style': 'no'
        })

        sym = QgsFillSymbol()
        buffer_layer = QgsGeometryGeneratorSymbolLayer.create(
            {'geometryModifier': 'buffer($geometry, -0.4)'})
        buffer_layer.setSymbolType(QgsSymbol.Fill)
        buffer_layer.setSubSymbol(sub_symbol)
        sym.changeSymbolLayer(0, buffer_layer)
        layer.setRenderer(QgsSingleSymbolRenderer(sym))

        canvas = QgsMapCanvas()
        canvas.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:3857'))
        canvas.setFrameStyle(0)
        canvas.resize(600, 400)
        self.assertEqual(canvas.width(), 600)
        self.assertEqual(canvas.height(), 400)

        canvas.setLayers([layer])
        canvas.setExtent(QgsRectangle(-11960254, 4247568, -11072454, 4983088))
        canvas.show()

        # need to wait until first redraw can occur (note that we first need to wait till drawing starts!)
        while not canvas.isDrawing():
            app.processEvents()
        canvas.waitWhileRendering()

        feature = layer.getFeature(1)
        self.assertTrue(feature.isValid())

        highlight = QgsHighlight(canvas, feature, layer)
        color = QColor(Qt.red)
        highlight.setColor(color)
        color.setAlpha(50)
        highlight.setFillColor(color)
        highlight.show()
        highlight.show()

        self.assertTrue(
            self.canvasImageCheck('highlight_transform', 'highlight_transform',
                                  canvas))
    def test_buffer_lines(self):
        sym = self.lines_layer.renderer().symbol()

        buffer_layer = QgsGeometryGeneratorSymbolLayer.create({'geometryModifier': 'buffer($geometry, "value"/15)', 'outline_color': 'black'})
        buffer_layer.setSymbolType(QgsSymbol.Fill)
        self.assertIsNotNone(buffer_layer.subSymbol())
        sym.appendSymbolLayer(buffer_layer)

        rendered_layers = [self.lines_layer]
        self.mapsettings.setLayers(rendered_layers)

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(self.mapsettings)
        renderchecker.setControlName('expected_geometrygenerator_buffer_lines')
        res = renderchecker.runTest('geometrygenerator_buffer_lines')
        self.report += renderchecker.report()
        self.assertTrue(res)
示例#12
0
    def crossLinegenerator(self, utmSRID, x_geo, y_geo, px, py, u, t, dx, dy,
                           trLLUTM, linwidth_geo, color):
        p1 = QgsPoint(x_geo + px * u, y_geo + py * t)
        p2 = QgsPoint(x_geo + px * u + dx, y_geo + py * t + dy)
        p1.transform(trLLUTM)
        p2.transform(trLLUTM)
        properties = {'color': color.name()}
        line_temp = QgsLineSymbol.createSimple(properties)
        line_temp.setWidth(linwidth_geo)
        symb = QgsGeometryGeneratorSymbolLayer.create(properties)
        symb.setSymbolType(Qgis.SymbolType.Line)
        symb.setSubSymbol(line_temp)

        symb.setGeometryExpression(
            "transform(make_line(make_point({}, {}), make_point({}, {})), 'EPSG:{}', @map_crs)"
            .format(p1.x(), p1.y(), p2.x(), p2.y(), utmSRID))
        return symb
    def test_clone(self):
        """
        Test cloning layer
        """
        sym_layer = QgsGeometryGeneratorSymbolLayer.create(
            {'geometryModifier': 'centroid($geometry)'})
        sym_layer.setSymbolType(Qgis.SymbolType.Marker)
        sym_layer.setUnits(QgsUnitTypes.RenderMillimeters)
        sym_layer.subSymbol().symbolLayer(0).setStrokeColor(QColor(
            0, 255, 255))

        layer2 = sym_layer.clone()
        self.assertEqual(layer2.symbolType(), Qgis.SymbolType.Marker)
        self.assertEqual(layer2.units(), QgsUnitTypes.RenderMillimeters)
        self.assertEqual(layer2.geometryExpression(), 'centroid($geometry)')
        self.assertEqual(layer2.subSymbol()[0].strokeColor(),
                         QColor(0, 255, 255))
示例#14
0
    def set_halo_styles(layer,
                        draw_method,
                        stroke_color,
                        use_effects,
                        fill_color=None):
        renderer = layer.renderer()
        sym = renderer.symbol()

        props = {'color': 'blue'}
        # noinspection PyArgumentList
        fill_symbol = QgsFillSymbol.createSimple(props)
        fill_symbol_layer = fill_symbol.symbolLayers()[0]
        fill_symbol_layer.setStrokeColor(stroke_color)
        if fill_color is not None:
            fill_symbol_layer.setColor(fill_color)
        elif not use_effects:
            fill_symbol_layer.setColor(TRANSPARENT_COLOR)

        if use_effects:
            # Assign effects
            effect_stack = QgsEffectStack()
            drop_shdw = QgsDropShadowEffect()
            drop_shdw.setColor(stroke_color)
            inner_shdw = QgsInnerShadowEffect()
            inner_shdw.setColor(stroke_color)
            effect_stack.appendEffect(drop_shdw)
            effect_stack.appendEffect(inner_shdw)

            fill_symbol_layer.setPaintEffect(effect_stack)
        # noinspection PyArgumentList
        if draw_method == HaloDrawMethod.buffered_point:
            renderer.setSymbol(fill_symbol)
        else:
            # noinspection PyCallByClass, PyArgumentList
            geom_generator_sl = QgsGeometryGeneratorSymbolLayer.create({
                'SymbolType':
                'Fill',
                'geometryModifier':
                'buffer($geometry, {:d})'.format(EARTH_RADIUS)
            })
            geom_generator_sl.setSubSymbol(fill_symbol)
            sym.changeSymbolLayer(0, geom_generator_sl)

        layer.triggerRepaint()
        return layer
    def test_subsymbol(self):
        """
        Test rendering a generator in a subsymbol of another symbol
        """
        sym = QgsLineSymbol()
        arrow = QgsArrowSymbolLayer()
        arrow.setIsRepeated(False)
        arrow.setArrowStartWidth(10)
        arrow.setArrowWidth(5)
        arrow.setHeadLength(20)
        arrow.setHeadThickness(10)

        sym.changeSymbolLayer(0, arrow)

        self.lines_layer.renderer().setSymbol(sym)

        # here "$geometry" must refer to the created ARROW shape, NOT the original feature line geometry!
        generator_layer = QgsGeometryGeneratorSymbolLayer.create(
            {'geometryModifier': 'buffer($geometry, 3)'})
        generator_layer.setSymbolType(QgsSymbol.Fill)
        generator_layer.setUnits(QgsUnitTypes.RenderMillimeters)
        self.assertIsNotNone(generator_layer.subSymbol())

        generator_layer.subSymbol().symbolLayer(0).setColor(
            QColor(255, 255, 255))
        generator_layer.subSymbol().symbolLayer(0).setStrokeColor(
            QColor(0, 0, 0))
        generator_layer.subSymbol().symbolLayer(0).setStrokeWidth(2)

        sub_symbol = QgsFillSymbol()
        sub_symbol.changeSymbolLayer(0, generator_layer)
        arrow.setSubSymbol(sub_symbol)

        rendered_layers = [self.lines_layer]
        self.mapsettings.setLayers(rendered_layers)

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(self.mapsettings)
        renderchecker.setControlName('expected_geometrygenerator_subsymbol')
        res = renderchecker.runTest('geometrygenerator_subsymbol')
        self.report += renderchecker.report()
        self.assertTrue(res)
    def testPartNum(self):
        # test geometry_part_num variable
        s = QgsLineSymbol()
        s.deleteSymbolLayer(0)

        sym_layer = QgsGeometryGeneratorSymbolLayer.create(
            {'geometryModifier': 'segments_to_lines($geometry)'})
        sym_layer.setSymbolType(QgsSymbol.Line)
        s.appendSymbolLayer(sym_layer)

        marker_line = QgsMarkerLineSymbolLayer(False)
        marker_line.setPlacement(QgsMarkerLineSymbolLayer.FirstVertex)
        f = QgsFontUtils.getStandardTestFont('Bold', 24)
        marker = QgsFontMarkerSymbolLayer(f.family(), 'x', 24,
                                          QColor(255, 255, 0))
        marker.setDataDefinedProperty(
            QgsSymbolLayer.PropertyCharacter,
            QgsProperty.fromExpression('@geometry_part_num'))
        marker_symbol = QgsMarkerSymbol()
        marker_symbol.changeSymbolLayer(0, marker)
        marker_line.setSubSymbol(marker_symbol)
        marker_line.setAverageAngleLength(0)
        line_symbol = QgsLineSymbol()
        line_symbol.changeSymbolLayer(0, marker_line)
        sym_layer.setSubSymbol(line_symbol)

        # rendering test
        g = QgsGeometry.fromWkt('LineString(0 0, 10 0, 10 10, 0 10)')
        rendered_image = self.renderGeometry(s, g, buffer=4)
        assert self.imageCheck('part_num_variable', 'part_num_variable',
                               rendered_image)

        marker.setDataDefinedProperty(
            QgsSymbolLayer.PropertyCharacter,
            QgsProperty.fromExpression('@geometry_part_count'))

        # rendering test
        g = QgsGeometry.fromWkt('LineString(0 0, 10 0, 10 10, 0 10)')
        rendered_image = self.renderGeometry(s, g, buffer=4)
        assert self.imageCheck('part_count_variable', 'part_count_variable',
                               rendered_image)
    def test_feature_geometry(self):
        """
        The geometry($currentfeature) expression used in a subsymbol should refer to the original FEATURE geometry
        """
        points = QgsVectorLayer('Point?crs=epsg:4326', 'Points', 'memory')
        self.assertTrue(points.isValid())
        f = QgsFeature()
        f.setGeometry(QgsGeometry.fromWkt('Point(1 2)'))
        points.dataProvider().addFeature(f)

        font = QgsFontUtils.getStandardTestFont('Bold')
        font_marker = QgsFontMarkerSymbolLayer(font.family(), 'x', 16)
        font_marker.setDataDefinedProperty(
            QgsSymbolLayer.PropertyCharacter,
            QgsProperty.fromExpression(
                'geom_to_wkt(geometry($currentfeature))'))
        subsymbol = QgsMarkerSymbol()
        subsymbol.changeSymbolLayer(0, font_marker)

        parent_generator = QgsGeometryGeneratorSymbolLayer.create(
            {'geometryModifier': 'translate($geometry, 1, 2)'})
        parent_generator.setSymbolType(QgsSymbol.Marker)

        parent_generator.setSubSymbol(subsymbol)

        geom_symbol = QgsMarkerSymbol()
        geom_symbol.changeSymbolLayer(0, parent_generator)
        points.renderer().setSymbol(geom_symbol)

        mapsettings = QgsMapSettings(self.mapsettings)
        mapsettings.setExtent(QgsRectangle(0, 0, 5, 5))
        mapsettings.setLayers([points])

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(mapsettings)
        renderchecker.setControlName(
            'expected_geometrygenerator_feature_geometry')
        res = renderchecker.runTest('geometrygenerator_feature_geometry')
        self.report += renderchecker.report()
        self.assertTrue(res)
    def test_no_feature_coordinate_transform(self):
        """
        Test rendering as a pure symbol, no feature associated, with coordinate transform
        """
        buffer_layer = QgsGeometryGeneratorSymbolLayer.create(
            {'geometryModifier': 'buffer($geometry, 5)'})
        buffer_layer.setSymbolType(QgsSymbol.Fill)
        buffer_layer.setUnits(QgsUnitTypes.RenderMillimeters)
        self.assertIsNotNone(buffer_layer.subSymbol())

        symbol = QgsLineSymbol()
        symbol.changeSymbolLayer(0, buffer_layer)

        image = QImage(400, 400, QImage.Format_RGB32)
        image.setDotsPerMeterX(int(96 / 25.4 * 1000))
        image.setDotsPerMeterY(int(96 / 25.4 * 1000))
        image.fill(QColor(255, 255, 255))
        painter = QPainter(image)

        context = QgsRenderContext.fromQPainter(painter)
        context.setCoordinateTransform(
            QgsCoordinateTransform(QgsCoordinateReferenceSystem('EPSG:4326'),
                                   QgsCoordinateReferenceSystem('EPSG:3857'),
                                   QgsProject.instance().transformContext()))

        symbol.startRender(context)

        symbol.renderPolyline(
            QPolygonF([QPointF(50, 200),
                       QPointF(100, 170),
                       QPointF(350, 270)]), None, context)

        symbol.stopRender(context)
        painter.end()

        self.assertTrue(
            self.imageCheck('geometrygenerator_nofeature',
                            'geometrygenerator_nofeature', image))
    def test_multi_poly_opacity(self):
        # test that multi-type features are only rendered once

        multipoly = QgsVectorLayer(os.path.join(TEST_DATA_DIR, 'multipatch.shp'), 'Polygons', 'ogr')

        sym = QgsFillSymbol.createSimple({'color': '#77fdbf6f', 'outline_color': 'black'})

        buffer_layer = QgsGeometryGeneratorSymbolLayer.create({'geometryModifier': 'buffer($geometry, -0.01)', 'outline_color': 'black'})
        buffer_layer.setSymbolType(QgsSymbol.Fill)
        buffer_layer.setSubSymbol(sym)
        geom_symbol = QgsFillSymbol()
        geom_symbol.changeSymbolLayer(0, buffer_layer)
        multipoly.renderer().setSymbol(geom_symbol)

        mapsettings = QgsMapSettings(self.mapsettings)
        mapsettings.setExtent(multipoly.extent())
        mapsettings.setLayers([multipoly])

        renderchecker = QgsMultiRenderChecker()
        renderchecker.setMapSettings(mapsettings)
        renderchecker.setControlName('expected_geometrygenerator_opacity')
        res = renderchecker.runTest('geometrygenerator_opacity')
        self.report += renderchecker.report()
        self.assertTrue(res)
示例#20
0
    def utm_Symb_Generator(self, layer_bound, grid_spacing, trUTMLL, trLLUTM,
                           grid_symb, properties, UTM_num_x, UTM_num_y, t, u,
                           extentsGeo, extentsUTM, linwidth_utm, color):
        test_line = [None] * 2
        properties = {'color': color.name()}
        line_temp = QgsLineSymbol.createSimple(properties)
        line_temp.setWidth(linwidth_utm)
        symb = QgsGeometryGeneratorSymbolLayer.create(properties)
        symb.setSymbolType(Qgis.SymbolType.Line)
        symb.setSubSymbol(line_temp)

        #Test First And Last Grid Lines
        #Vertical
        if (t == 1 and u == 0) or (t == UTM_num_x and u == 0):

            #Symbol vertices
            auxPointlist = self.gridLinesymbolMaker(
                ((floor(extentsUTM[0] / grid_spacing) + t) * grid_spacing),
                extentsUTM[1],
                ((floor(extentsUTM[0] / grid_spacing) + t) * grid_spacing),
                extentsUTM[3], extentsGeo[2], extentsGeo[0], extentsGeo[3],
                extentsGeo[1], trUTMLL, trLLUTM, True)

            #0: left bound; 1: right bound
            test_line[0] = QgsGeometry.fromWkt('LINESTRING (' +
                                               str(extentsGeo[0]) + ' ' +
                                               str(extentsGeo[1]) + ',' +
                                               str(extentsGeo[0]) + ' ' +
                                               str(extentsGeo[3]) + ')')
            test_line[1] = QgsGeometry.fromWkt('LINESTRING (' +
                                               str(extentsGeo[2]) + ' ' +
                                               str(extentsGeo[1]) + ',' +
                                               str(extentsGeo[2]) + ' ' +
                                               str(extentsGeo[3]) + ')')
            test_grid = QgsGeometry.fromPolyline(
                [auxPointlist[0], auxPointlist[1]])
            if test_line[0].intersects(test_grid):
                mid_point = test_line[0].intersection(test_grid).vertexAt(0)
                mid_point.transform(trLLUTM)
                if auxPointlist[0].x() > auxPointlist[1].x():
                    symb.setGeometryExpression(
                        "transform(make_line(make_point({}, {}), make_point({}, {})), 'EPSG:{}', @map_crs)"
                        .format(auxPointlist[2].x(), auxPointlist[2].y(),
                                mid_point.x(), mid_point.y(), layer_bound))
                else:
                    symb.setGeometryExpression(
                        "transform(make_line(make_point({}, {}), make_point({}, {})), 'EPSG:{}', @map_crs)"
                        .format(mid_point.x(), mid_point.y(),
                                auxPointlist[3].x(), auxPointlist[3].y(),
                                layer_bound))
            elif test_line[1].intersects(test_grid):
                mid_point = test_line[1].intersection(test_grid).vertexAt(0)
                mid_point.transform(trLLUTM)
                if auxPointlist[0].x() < auxPointlist[1].x():
                    symb.setGeometryExpression(
                        "transform(make_line(make_point({}, {}), make_point({}, {})),'EPSG:{}', @map_crs)"
                        .format(auxPointlist[2].x(), auxPointlist[2].y(),
                                mid_point.x(), mid_point.y(), layer_bound))
                else:
                    symb.setGeometryExpression(
                        "transform(make_line(make_point({}, {}), make_point({}, {})),'EPSG:{}', @map_crs)"
                        .format(mid_point.x(), mid_point.y(),
                                auxPointlist[3].x(), auxPointlist[3].y(),
                                layer_bound))
            else:
                symb.setGeometryExpression(
                    "transform(make_line(make_point({}, {}), make_point({}, {})),'EPSG:{}', @map_crs)"
                    .format(auxPointlist[2].x(), auxPointlist[2].y(),
                            auxPointlist[3].x(), auxPointlist[3].y(),
                            layer_bound))

        #Horizontal
        elif (u == 1 and t == 0) or (u == UTM_num_y and t == 0):

            #Symbol vertices
            auxPointlist = self.gridLinesymbolMaker(
                extentsUTM[0],
                ((floor(extentsUTM[1] / grid_spacing) + u) * grid_spacing),
                extentsUTM[2],
                ((floor(extentsUTM[1] / grid_spacing) + u) * grid_spacing),
                extentsGeo[2], extentsGeo[0], extentsGeo[3], extentsGeo[1],
                trUTMLL, trLLUTM, False)

            #0: bottom bound; 1: upper bound
            test_line[0] = QgsGeometry.fromWkt('LINESTRING (' +
                                               str(extentsGeo[0]) + ' ' +
                                               str(extentsGeo[1]) + ',' +
                                               str(extentsGeo[2]) + ' ' +
                                               str(extentsGeo[1]) + ')')
            test_line[1] = QgsGeometry.fromWkt('LINESTRING (' +
                                               str(extentsGeo[0]) + ' ' +
                                               str(extentsGeo[3]) + ',' +
                                               str(extentsGeo[2]) + ' ' +
                                               str(extentsGeo[3]) + ')')
            test_grid = QgsGeometry.fromPolyline(
                [auxPointlist[0], auxPointlist[1]])
            if test_line[0].intersects(test_grid):
                mid_point = test_line[0].intersection(test_grid).vertexAt(0)
                mid_point.transform(trLLUTM)
                if auxPointlist[0].y() > auxPointlist[1].y():
                    symb.setGeometryExpression(
                        "transform(make_line(make_point({}, {}), make_point({}, {})),'EPSG:{}', @map_crs)"
                        .format(auxPointlist[2].x(), auxPointlist[2].y(),
                                mid_point.x(), mid_point.y(), layer_bound))
                else:
                    symb.setGeometryExpression(
                        "transform(make_line(make_point({}, {}), make_point({}, {})),'EPSG:{}', @map_crs)"
                        .format(mid_point.x(), mid_point.y(),
                                auxPointlist[3].x(), auxPointlist[3].y(),
                                layer_bound))
            elif test_line[1].intersects(test_grid):
                mid_point = test_line[1].intersection(test_grid).vertexAt(0)
                mid_point.transform(trLLUTM)
                if auxPointlist[0].y() < auxPointlist[1].y():
                    symb.setGeometryExpression(
                        "transform(make_line(make_point({}, {}), make_point({}, {})),'EPSG:{}', @map_crs)"
                        .format(auxPointlist[2].x(), auxPointlist[2].y(),
                                mid_point.x(), mid_point.y(), layer_bound))
                else:
                    symb.setGeometryExpression(
                        "transform(make_line(make_point({}, {}), make_point({}, {})),'EPSG:{}', @map_crs)"
                        .format(mid_point.x(), mid_point.y(),
                                auxPointlist[3].x(), auxPointlist[3].y(),
                                layer_bound))
            else:
                symb.setGeometryExpression(
                    "transform(make_line(make_point({}, {}), make_point({}, {})),'EPSG:{}', @map_crs)"
                    .format(auxPointlist[2].x(), auxPointlist[2].y(),
                            auxPointlist[3].x(), auxPointlist[3].y(),
                            layer_bound))

        #Inner Grid Lines
        #Vertical
        elif (not (t == 1)) and (not (t == UTM_num_x)) and u == 0:
            auxPointlist = self.gridLinesymbolMaker(
                ((floor(extentsUTM[0] / grid_spacing) + t) * grid_spacing),
                extentsUTM[1],
                ((floor(extentsUTM[0] / grid_spacing) + t) * grid_spacing),
                extentsUTM[3], extentsGeo[2], extentsGeo[0], extentsGeo[3],
                extentsGeo[1], trUTMLL, trLLUTM, True)
            symb.setGeometryExpression(
                "transform(make_line(make_point({}, {}), make_point({}, {})),'EPSG:{}', @map_crs)"
                .format(auxPointlist[2].x(), auxPointlist[2].y(),
                        auxPointlist[3].x(), auxPointlist[3].y(), layer_bound))

        #Horizontal
        elif (not (u == 1)) and (not (u == UTM_num_y)) and t == 0:
            auxPointlist = self.gridLinesymbolMaker(
                extentsUTM[0],
                ((floor(extentsUTM[1] / grid_spacing) + u) * grid_spacing),
                extentsUTM[2],
                ((floor(extentsUTM[1] / grid_spacing) + u) * grid_spacing),
                extentsGeo[2], extentsGeo[0], extentsGeo[3], extentsGeo[1],
                trUTMLL, trLLUTM, False)
            symb.setGeometryExpression(
                "transform(make_line(make_point({}, {}), make_point({}, {})),'EPSG:{}', @map_crs)"
                .format(auxPointlist[2].x(), auxPointlist[2].y(),
                        auxPointlist[3].x(), auxPointlist[3].y(), layer_bound))

        grid_symb.appendSymbolLayer(symb)
        return grid_symb
示例#21
0
    def utm_symb_generator(self, grid_spacing, trUTMLL, trLLUTM, grid_symb,
                           properties, geo_number_x, geo_number_y, UTM_num_x,
                           UTM_num_y, t, u, geo_bound_bb, bound_UTM_bb,
                           utmcheck):
        xmin_source = float(geo_bound_bb.split()[1])
        ymin_source = float(geo_bound_bb.split()[2])
        xmax_source = float(geo_bound_bb.split()[3])
        ymax_source = float(geo_bound_bb.split()[4])
        xmin_UTM = float(bound_UTM_bb.split()[1])
        ymin_UTM = float(bound_UTM_bb.split()[2])
        xmax_UTM = float(bound_UTM_bb.split()[3])
        ymax_UTM = float(bound_UTM_bb.split()[4])
        test_line = [None] * 2
        properties = {'color': 'black'}
        line_temp = QgsLineSymbol.createSimple(properties)
        line_temp.setWidth(0.05)
        symb = QgsGeometryGeneratorSymbolLayer.create(properties)
        symb.setSymbolType(1)
        symb.setSubSymbol(line_temp)

        #Test First And Last Grid Lines
        #Vertical
        if (t == 1 and u == 0) or (t == UTM_num_x and u == 0):
            #Symbol vertices
            auxPointlist = self.gridLinesymbolMaker(
                ((floor(xmin_UTM / grid_spacing) + t) * grid_spacing),
                ymin_UTM,
                ((floor(xmin_UTM / grid_spacing) + t) * grid_spacing),
                ymax_UTM, xmax_source, xmin_source, ymax_source, ymin_source,
                trUTMLL, trLLUTM, utmcheck, True)
            #0: left bound; 1: right bound
            test_line[0] = QgsGeometry.fromWkt('LINESTRING (' +
                                               str(xmin_source) + ' ' +
                                               str(ymin_source) + ',' +
                                               str(xmin_source) + ' ' +
                                               str(ymax_source) + ')')
            test_line[1] = QgsGeometry.fromWkt('LINESTRING (' +
                                               str(xmax_source) + ' ' +
                                               str(ymin_source) + ',' +
                                               str(xmax_source) + ' ' +
                                               str(ymax_source) + ')')
            test_grid = QgsGeometry.fromPolyline(
                [auxPointlist[0], auxPointlist[1]])
            if test_line[0].intersects(test_grid):
                mid_point = test_line[0].intersection(test_grid).vertexAt(0)
                self.utmLLtransform(utmcheck, mid_point, trLLUTM)
                if auxPointlist[0].x() > auxPointlist[1].x():
                    symb.setGeometryExpression('make_line(make_point(' +
                                               str(auxPointlist[2].x()) + ',' +
                                               str(auxPointlist[2].y()) +
                                               '), make_point(' +
                                               str(mid_point.x()) + ',' +
                                               str(mid_point.y()) + '))')
                else:
                    symb.setGeometryExpression('make_line(make_point(' +
                                               str(mid_point.x()) + ',' +
                                               str(mid_point.y()) +
                                               '), make_point(' +
                                               str(auxPointlist[3].x()) + ',' +
                                               str(auxPointlist[3].y()) + '))')
            elif test_line[1].intersects(test_grid):
                mid_point = test_line[1].intersection(test_grid).vertexAt(0)
                self.utmLLtransform(utmcheck, mid_point, trLLUTM)
                if auxPointlist[0].x() < auxPointlist[1].x():
                    symb.setGeometryExpression('make_line(make_point(' +
                                               str(auxPointlist[2].x()) + ',' +
                                               str(auxPointlist[2].y()) +
                                               '), make_point(' +
                                               str(mid_point.x()) + ',' +
                                               str(mid_point.y()) + '))')
                else:
                    symb.setGeometryExpression('make_line(make_point(' +
                                               str(mid_point.x()) + ',' +
                                               str(mid_point.y()) +
                                               '), make_point(' +
                                               str(auxPointlist[3].x()) + ',' +
                                               str(auxPointlist[3].y()) + '))')
            else:
                symb.setGeometryExpression('make_line(make_point(' +
                                           str(auxPointlist[2].x()) + ',' +
                                           str(auxPointlist[2].y()) +
                                           '), make_point(' +
                                           str(auxPointlist[3].x()) + ',' +
                                           str(auxPointlist[3].y()) + '))')

        #Horizontal
        elif (u == 1 and t == 0) or (u == UTM_num_y and t == 0):
            #Symbol vertices
            auxPointlist = self.gridLinesymbolMaker(
                xmin_UTM,
                ((floor(ymin_UTM / grid_spacing) + u) * grid_spacing),
                xmax_UTM,
                ((floor(ymin_UTM / grid_spacing) + u) * grid_spacing),
                xmax_source, xmin_source, ymax_source, ymin_source, trUTMLL,
                trLLUTM, utmcheck, False)
            #0: bottom bound; 1: upper bound
            test_line[0] = QgsGeometry.fromWkt('LINESTRING (' +
                                               str(xmin_source) + ' ' +
                                               str(ymin_source) + ',' +
                                               str(xmax_source) + ' ' +
                                               str(ymin_source) + ')')
            test_line[1] = QgsGeometry.fromWkt('LINESTRING (' +
                                               str(xmin_source) + ' ' +
                                               str(ymax_source) + ',' +
                                               str(xmax_source) + ' ' +
                                               str(ymax_source) + ')')
            test_grid = QgsGeometry.fromPolyline(
                [auxPointlist[0], auxPointlist[1]])
            if test_line[0].intersects(test_grid):
                mid_point = test_line[0].intersection(test_grid).vertexAt(0)
                self.utmLLtransform(utmcheck, mid_point, trLLUTM)
                if auxPointlist[0].y() > auxPointlist[1].y():
                    symb.setGeometryExpression('make_line(make_point(' +
                                               str(auxPointlist[2].x()) + ',' +
                                               str(auxPointlist[2].y()) +
                                               '), make_point(' +
                                               str(mid_point.x()) + ',' +
                                               str(mid_point.y()) + '))')
                else:
                    symb.setGeometryExpression('make_line(make_point(' +
                                               str(mid_point.x()) + ',' +
                                               str(mid_point.y()) +
                                               '), make_point(' +
                                               str(auxPointlist[3].x()) + ',' +
                                               str(auxPointlist[3].y()) + '))')
            elif test_line[1].intersects(test_grid):
                mid_point = test_line[1].intersection(test_grid).vertexAt(0)
                self.utmLLtransform(utmcheck, mid_point, trLLUTM)
                if auxPointlist[0].y() < auxPointlist[1].y():
                    symb.setGeometryExpression('make_line(make_point(' +
                                               str(auxPointlist[2].x()) + ',' +
                                               str(auxPointlist[2].y()) +
                                               '), make_point(' +
                                               str(mid_point.x()) + ',' +
                                               str(mid_point.y()) + '))')
                else:
                    symb.setGeometryExpression('make_line(make_point(' +
                                               str(mid_point.x()) + ',' +
                                               str(mid_point.y()) +
                                               '), make_point(' +
                                               str(auxPointlist[3].x()) + ',' +
                                               str(auxPointlist[3].y()) + '))')
            else:
                symb.setGeometryExpression("make_line(make_point(" +
                                           str(auxPointlist[2].x()) + "," +
                                           str(auxPointlist[2].y()) +
                                           "), make_point(" +
                                           str(auxPointlist[3].x()) + "," +
                                           str(auxPointlist[3].y()) + "))")

        #Inner Grid Lines
        #Vertical
        elif (not (t == 1)) and (not (t == UTM_num_x)) and u == 0:
            auxPointlist = self.gridLinesymbolMaker(
                ((floor(xmin_UTM / grid_spacing) + t) * grid_spacing),
                ymin_UTM,
                ((floor(xmin_UTM / grid_spacing) + t) * grid_spacing),
                ymax_UTM, xmax_source, xmin_source, ymax_source, ymin_source,
                trUTMLL, trLLUTM, utmcheck, True)
            symb.setGeometryExpression('make_line(make_point(' +
                                       str(auxPointlist[2].x()) + ',' +
                                       str(auxPointlist[2].y()) +
                                       '), make_point(' +
                                       str(auxPointlist[3].x()) + ',' +
                                       str(auxPointlist[3].y()) + '))')
        #Horizontal
        elif (not (u == 1)) and (not (u == UTM_num_y)) and t == 0:
            auxPointlist = self.gridLinesymbolMaker(
                xmin_UTM,
                ((floor(ymin_UTM / grid_spacing) + u) * grid_spacing),
                xmax_UTM,
                ((floor(ymin_UTM / grid_spacing) + u) * grid_spacing),
                xmax_source, xmin_source, ymax_source, ymin_source, trUTMLL,
                trLLUTM, utmcheck, False)
            symb.setGeometryExpression("make_line(make_point(" +
                                       str(auxPointlist[2].x()) + "," +
                                       str(auxPointlist[2].y()) +
                                       "), make_point(" +
                                       str(auxPointlist[3].x()) + "," +
                                       str(auxPointlist[3].y()) + "))")

        grid_symb.appendSymbolLayer(symb)
        return grid_symb