当前位置: 首页>>代码示例>>Python>>正文


Python QgsMapCanvas.mapSettings方法代码示例

本文整理汇总了Python中qgis.gui.QgsMapCanvas.mapSettings方法的典型用法代码示例。如果您正苦于以下问题:Python QgsMapCanvas.mapSettings方法的具体用法?Python QgsMapCanvas.mapSettings怎么用?Python QgsMapCanvas.mapSettings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在qgis.gui.QgsMapCanvas的用法示例。


在下文中一共展示了QgsMapCanvas.mapSettings方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testSaveMultipleCanvasesToProject

# 需要导入模块: from qgis.gui import QgsMapCanvas [as 别名]
# 或者: from qgis.gui.QgsMapCanvas import mapSettings [as 别名]
    def testSaveMultipleCanvasesToProject(self):
        # test saving/restoring canvas state to project with multiple canvases
        c1 = QgsMapCanvas()
        c1.setObjectName('c1')
        c1.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:3111'))
        c1.setRotation(45)
        c2 = QgsMapCanvas()
        c2.setObjectName('c2')
        c2.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:4326'))
        c2.setRotation(65)

        doc = QDomDocument("testdoc")
        elem = doc.createElement("qgis")
        doc.appendChild(elem)
        c1.writeProject(doc)
        c2.writeProject(doc)

        c3 = QgsMapCanvas()
        c3.setObjectName('c1')
        c4 = QgsMapCanvas()
        c4.setObjectName('c2')
        c3.readProject(doc)
        c4.readProject(doc)

        self.assertEqual(c3.mapSettings().destinationCrs().authid(), 'EPSG:3111')
        self.assertEqual(c3.rotation(), 45)
        self.assertEqual(c4.mapSettings().destinationCrs().authid(), 'EPSG:4326')
        self.assertEqual(c4.rotation(), 65)
开发者ID:timlinux,项目名称:QGIS,代码行数:30,代码来源:test_qgsmapcanvas.py

示例2: make_pdf

# 需要导入模块: from qgis.gui import QgsMapCanvas [as 别名]
# 或者: from qgis.gui.QgsMapCanvas import mapSettings [as 别名]
def make_pdf():
    canvas = QgsMapCanvas()
    # Load our project
    QgsProject.instance().read(QFileInfo(project_path))
    bridge = QgsLayerTreeMapCanvasBridge(
        QgsProject.instance().layerTreeRoot(), canvas)
    bridge.setCanvasLayers()
    if canvas.layerCount() < 1:
        print 'No layers loaded from this project, exiting.'
        return
    print canvas.mapSettings().extent().toString()
    template_file = file(template_path)
    template_content = template_file.read()
    template_file.close()
    document = QDomDocument()
    document.setContent(template_content)
    composition = QgsComposition(canvas.mapSettings())
    # You can use this to replace any string like this [key]
    # in the template with a new value. e.g. to replace
    # [date] pass a map like this {'date': '1 Jan 2012'}
    substitution_map = {
        'DATE_TIME_START': TIME_START,
        'DATE_TIME_END': TIME_STOP}
    composition.loadFromTemplate(document, substitution_map)
    # You must set the id in the template
    map_item = composition.getComposerItemById('map')
    map_item.setMapCanvas(canvas)
    map_item.zoomToExtent(canvas.extent())
    # You must set the id in the template
    legend_item = composition.getComposerItemById('legend')
    legend_item.updateLegend()
    composition.refreshItems()
    composition.exportAsPDF(
        '/home/web/reports/pdf/%s/%s.pdf' % (TIME_SLICE, LABEL))
    QgsProject.instance().clear()
开发者ID:Jannes123,项目名称:watchkeeper,代码行数:37,代码来源:pdf_report_generator.py

示例3: testSaveMultipleCanvasesToProject

# 需要导入模块: from qgis.gui import QgsMapCanvas [as 别名]
# 或者: from qgis.gui.QgsMapCanvas import mapSettings [as 别名]
    def testSaveMultipleCanvasesToProject(self):
        # test saving/restoring canvas state to project with multiple canvases
        c1 = QgsMapCanvas()
        c1.setObjectName('c1')
        c1.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:3111'))
        c1.setRotation(45)
        c1.expressionContextScope().setVariable('vara', 1111)
        c1.expressionContextScope().setVariable('varb', 'bb')
        c2 = QgsMapCanvas()
        c2.setObjectName('c2')
        c2.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:4326'))
        c2.setRotation(65)
        c2.expressionContextScope().setVariable('vara', 2222)
        c2.expressionContextScope().setVariable('varc', 'cc')

        doc = QDomDocument("testdoc")
        elem = doc.createElement("qgis")
        doc.appendChild(elem)
        c1.writeProject(doc)
        c2.writeProject(doc)

        c3 = QgsMapCanvas()
        c3.setObjectName('c1')
        c4 = QgsMapCanvas()
        c4.setObjectName('c2')
        c3.readProject(doc)
        c4.readProject(doc)

        self.assertEqual(c3.mapSettings().destinationCrs().authid(), 'EPSG:3111')
        self.assertEqual(c3.rotation(), 45)
        self.assertEqual(set(c3.expressionContextScope().variableNames()), {'vara', 'varb'})
        self.assertEqual(c3.expressionContextScope().variable('vara'), 1111)
        self.assertEqual(c3.expressionContextScope().variable('varb'), 'bb')
        self.assertEqual(c4.mapSettings().destinationCrs().authid(), 'EPSG:4326')
        self.assertEqual(c4.rotation(), 65)
        self.assertEqual(set(c4.expressionContextScope().variableNames()), {'vara', 'varc'})
        self.assertEqual(c4.expressionContextScope().variable('vara'), 2222)
        self.assertEqual(c4.expressionContextScope().variable('varc'), 'cc')
开发者ID:dmarteau,项目名称:QGIS,代码行数:40,代码来源:test_qgsmapcanvas.py

示例4: GeometryDiffViewerDialog

# 需要导入模块: from qgis.gui import QgsMapCanvas [as 别名]
# 或者: from qgis.gui.QgsMapCanvas import mapSettings [as 别名]
class GeometryDiffViewerDialog(QDialog):

    def __init__(self, geoms, crs, parent = None):
        super(GeometryDiffViewerDialog, self).__init__(parent)
        self.geoms = geoms
        self.crs = crs
        self.initGui()

    def initGui(self):
        layout = QVBoxLayout()
        self.tab = QTabWidget()
        self.table = QTableView()

        self.setLayout(layout)
        self.canvas = QgsMapCanvas()
        self.canvas.setCanvasColor(Qt.white)
        settings = QSettings()
        self.canvas.enableAntiAliasing(settings.value("/qgis/enable_anti_aliasing", False, type = bool))
        self.canvas.useImageToRender(settings.value("/qgis/use_qimage_to_render", False, type = bool))
        self.canvas.mapSettings().setDestinationCrs(self.crs)
        action = settings.value("/qgis/wheel_action", 0, type = float)
        zoomFactor = settings.value("/qgis/zoom_factor", 2, type = float)
        self.canvas.setWheelAction(QgsMapCanvas.WheelAction(action), zoomFactor)
        self.panTool = QgsMapToolPan(self.canvas)
        self.canvas.setMapTool(self.panTool)

        execute(self.createLayers)

        model = GeomDiffTableModel(self.data)
        self.table.setModel(model)
        self.table.resizeColumnsToContents()
        self.table.resizeRowsToContents()
        self.tab.addTab(self.canvas, "Map view")
        self.tab.addTab(self.table, "Table view")
        layout.addWidget(self.tab)

        self.resize(600, 500)
        self.setWindowTitle("Geometry comparison")


    def createLayers(self):
        textGeometries = []
        for geom in self.geoms:
            text = geom.exportToWkt()
            valid = " -1234567890.,"
            text = "".join([c for c in text if c in valid])
            textGeometries.append(text.split(","))
        lines = difflib.Differ().compare(textGeometries[0], textGeometries[1])
        self.data = []
        for line in lines:
            if line.startswith("+"):
                self.data.append([None, line[2:]])
            if line.startswith("-"):
                self.data.append([line[2:], None])
            if line.startswith(" "):
                self.data.append([line[2:], line[2:]])
        types = [("LineString", lineBeforeStyle, lineAfterStyle),
                  ("Polygon", polygonBeforeStyle, polygonAfterStyle)]
        layers = []
        extent = self.geoms[0].boundingBox()
        for i, geom in enumerate(self.geoms):
            geomtype = types[int(geom.type() - 1)][0]
            style = types[int(geom.type() - 1)][i + 1]
            layer = loadLayerNoCrsDialog(geomtype + "?crs=" + self.crs.authid(), "layer", "memory")
            pr = layer.dataProvider()
            feat = QgsFeature()
            feat.setGeometry(geom)
            pr.addFeatures([feat])
            layer.loadNamedStyle(style)
            layer.updateExtents()
            layers.append(layer)
            QgsMapLayerRegistry.instance().addMapLayer(layer, False)
            extent.combineExtentWith(geom.boundingBox())

        layer = loadLayerNoCrsDialog("Point?crs=%s&field=changetype:string" % self.crs.authid(), "points", "memory")
        pr = layer.dataProvider()
        feats = []
        for coords in self.data:
            coord = coords[0] or coords[1]
            feat = QgsFeature()
            x, y = coord.strip().split(" ")
            x, y = (float(x), float(y))
            pt = QgsGeometry.fromPoint(QgsPoint(x, y))
            feat.setGeometry(pt)
            if coords[0] is None:
                changetype = "A"
            elif coords[1] is None:
                changetype = "R"
            else:
                changetype = "U"
            feat.setAttributes([changetype])
            feats.append(feat)

        pr.addFeatures(feats)
        layer.loadNamedStyle(pointsStyle)
        QgsMapLayerRegistry.instance().addMapLayer(layer, False)
        layers.append(layer)

        self.mapLayers = [QgsMapCanvasLayer(lay) for lay in layers]
        self.canvas.setLayerSet(self.mapLayers)
#.........这里部分代码省略.........
开发者ID:boundlessgeo,项目名称:qgis-geogiglight-plugin,代码行数:103,代码来源:geometrydiffviewerdialog.py

示例5: PdfMaker

# 需要导入模块: from qgis.gui import QgsMapCanvas [as 别名]
# 或者: from qgis.gui.QgsMapCanvas import mapSettings [as 别名]
class PdfMaker(object):
    """A generator that takes a QGIS project file and a layout template and makes a pdf."""

    def __init__(self, template_path, debug=False):
        """Constructor.

        :param template_path: Absolute path to a QGIS composer template file.
        :type template_path: str
        """
        gui_flag = True
        self.app = QgsApplication(sys.argv, gui_flag)

        # Make sure QGIS_PREFIX_PATH is set in your env if needed!
        self.app.initQgis()

        if debug:
            print QgsProviderRegistry.instance().pluginList()

        self.canvas = QgsMapCanvas()
        self.canvas.enableAntiAliasing(True)

        self.template_path = template_path

    def __del__(self):
        """Destructor."""
        del self.app

    def _load_template(self):
        """Load the template.

        :return: QgsComposition containing the loaded template.
        :rtype: QgsComposition
        """
        template_file = file(self.template_path)
        template_content = template_file.read()
        template_file.close()
        document = QDomDocument()
        document.setContent(template_content)
        composition = QgsComposition(self.canvas.mapSettings())
        # You can use this to replace any string like this [key]
        # in the template with a new value. e.g. to replace
        # [date] pass a map like this {'date': '1 Jan 2012'}
        substitution_map = {
            'DATE_TIME_START': 'foo',
            'DATE_TIME_END': 'bar'}
        composition.loadFromTemplate(document, substitution_map)
        return composition

    def _load_layers(self):
        """Manually load all the layers for our project.

        :return: A list of QgsMapLayer instances.
        :rtype: list
        """
        layers = []

        # First the RW layer

        host = 'db'
        port = '5432'
        user = 'docker'
        password = 'docker'
        dbname = 'gis'
        uri = QgsDataSourceURI()
        uri.setConnection(host, port, dbname, user, password)

        schema = 'public'
        table = 'flood_mapper_rw'
        geometry_column = 'geometry'
        where_clause = ''
        title = 'RW'
        uri.setDataSource(schema, table, geometry_column, where_clause)
        layer = QgsVectorLayer(uri.uri(), title, 'postgres')

        QgsMapLayerRegistry.instance().addMapLayer(layer, False)
        canvas_layer = QgsMapCanvasLayer(layer)
        layers.append(canvas_layer)

        # Now the JK layer
        path = './data/jk.shp'
        title = 'JK'
        layer = QgsVectorLayer(path, title, 'ogr')
        QgsMapLayerRegistry.instance().addMapLayer(layer, False)
        canvas_layer = QgsMapCanvasLayer(layer)
        layers.append(canvas_layer)

        return layers

    def make_pdf(self, pdf_path):
        """Generate a pdf for the given project and template files.

        :param pdf_path: Absolute path for the output PDF file.
        :type pdf_path: str

        """

        layers = self._load_layers()
        self.canvas.setLayerSet(layers)

        if self.canvas.layerCount() < 1:
#.........这里部分代码省略.........
开发者ID:Jannes123,项目名称:watchkeeper,代码行数:103,代码来源:pdf_report_generator_manual.py


注:本文中的qgis.gui.QgsMapCanvas.mapSettings方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。