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


Python iface.mapCanvas方法代码示例

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


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

示例1: __init__

# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mapCanvas [as 别名]
def __init__(self, dialog):
        super(ExtentSelectionPanel, self).__init__(None)
        self.dialog = dialog
        self.horizontalLayout = QHBoxLayout(self)
        self.horizontalLayout.setSpacing(2)
        self.horizontalLayout.setMargin(0)
        self.text = QLineEdit()
        if hasattr(self.text, 'setPlaceholderText'):
            self.text.setPlaceholderText("[xmin,xmax,ymin,ymax] Leave blank to use full extent")
        self.horizontalLayout.addWidget(self.text)
        self.pushButton = QPushButton()
        self.pushButton.setText("Define in canvas")
        self.pushButton.clicked.connect(self.selectOnCanvas)
        self.horizontalLayout.addWidget(self.pushButton)
        self.setLayout(self.horizontalLayout)
        canvas = iface.mapCanvas()
        self.prevMapTool = canvas.mapTool()
        self.tool = RectangleMapTool(canvas)
        self.tool.rectangleCreated.connect(self.fillCoords) 
开发者ID:planetfederal,项目名称:qgis-geoserver-plugin,代码行数:21,代码来源:extentpanel.py

示例2: getCenter

# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mapCanvas [as 别名]
def getCenter():
    """
        Returns the coordinates at the center of the map.

        https://developers.google.com/earth-engine/api_docs#map.getcenter

        Uses:
            >>> from ee_plugin import Map
            >>> center = Map.getCenter()
            >>> Map.addLayer(center, { 'color': 'red' }, 'center')
    """
    center = iface.mapCanvas().center()

    crs = iface.mapCanvas().mapSettings().destinationCrs().authid()

    return ee.Geometry.Point([center.x(), center.y()], crs) 
开发者ID:gee-community,项目名称:qgis-earthengine-plugin,代码行数:18,代码来源:Map.py

示例3: update_ee_image_layer

# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mapCanvas [as 别名]
def update_ee_image_layer(image, layer, shown=True, opacity=1.0):
    check_version()

    url = "type=xyz&url=" + get_ee_image_url(image)

    provider = layer.dataProvider()
    msg = 'Updating layer with provider %s' % (type(provider).__name__, )
    QgsMessageLog.logMessage(msg, 'Earth Engine')

    provider.setDataSourceUri(url)
    provider.reloadData()
    layer.triggerRepaint()
    layer.reload()
    iface.mapCanvas().refresh()

    item = QgsProject.instance().layerTreeRoot().findLayer(layer.id())
    if not (shown is None):
        item.setItemVisibilityChecked(shown) 
开发者ID:gee-community,项目名称:qgis-earthengine-plugin,代码行数:20,代码来源:utils.py

示例4: runAlgorithm

# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mapCanvas [as 别名]
def runAlgorithm(self):
        alg = RAlgorithm(description_file=None, script=self.editor.text())
        if alg.error is not None:
            error = QgsError(alg.error, "R")
            QgsErrorDialog.show(error,
                                self.tr("Execution error")
                                )
            return

        alg.setProvider(QgsApplication.processingRegistry().providerById("r"))
        alg.initAlgorithm()

        dlg = alg.createCustomParametersWidget(iface.mainWindow())
        if not dlg:
            dlg = AlgorithmDialog(alg, parent=iface.mainWindow())

        canvas = iface.mapCanvas()
        prevMapTool = canvas.mapTool()

        dlg.show()

        if canvas.mapTool() != prevMapTool:
            if canvas.mapTool():
                canvas.mapTool().reset()
            canvas.setMapTool(prevMapTool) 
开发者ID:north-road,项目名称:qgis-processing-r,代码行数:27,代码来源:script_editor_dialog.py

示例5: setCenter

# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mapCanvas [as 别名]
def setCenter(lon, lat, zoom=None):
    """
        Centers the map view at the given coordinates with the given zoom level. If no zoom level is provided, it uses the most recent zoom level on the map.

        https://developers.google.com/earth-engine/api_docs#map.setcenter

        Uses:
            >>> from ee_plugin import Map
            >>> Map.setCenter(lon, lat, zoom)
    """

    ### center
    center_point_in = QgsPointXY(lon, lat)
    # convert coordinates
    crsSrc = QgsCoordinateReferenceSystem(4326)  # WGS84
    crsDest = QgsCoordinateReferenceSystem(QgsProject.instance().crs())
    xform = QgsCoordinateTransform(crsSrc, crsDest, QgsProject.instance())
    # forward transformation: src -> dest
    center_point = xform.transform(center_point_in)
    iface.mapCanvas().setCenter(center_point)

    ### zoom
    if zoom is not None:
        # transform the zoom level to scale
        scale_value = 591657550.5 / 2 ** (zoom - 1)
        iface.mapCanvas().zoomScale(scale_value) 
开发者ID:gee-community,项目名称:qgis-earthengine-plugin,代码行数:28,代码来源:Map.py

示例6: selectOnCanvas

# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mapCanvas [as 别名]
def selectOnCanvas(self):
        canvas = iface.mapCanvas()
        canvas.setMapTool(self.tool)
        self.dialog.showMinimized() 
开发者ID:planetfederal,项目名称:qgis-geoserver-plugin,代码行数:6,代码来源:extentpanel.py

示例7: setValueFromRect

# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mapCanvas [as 别名]
def setValueFromRect(self,r):
        s = str(r.xMinimum()) + "," + str(r.xMaximum()) + "," + str(r.yMinimum()) + "," + str(r.yMaximum())
        self.text.setText(s)
        self.tool.reset()
        canvas = iface.mapCanvas()
        canvas.setMapTool(self.prevMapTool)
        self.dialog.showNormal()
        self.dialog.raise_()
        self.dialog.activateWindow() 
开发者ID:planetfederal,项目名称:qgis-geoserver-plugin,代码行数:11,代码来源:extentpanel.py

示例8: editStyle

# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mapCanvas [as 别名]
def editStyle(self, tree, explorer, gslayer = None):
        settings = QSettings()
        prjSetting = settings.value('/Projections/defaultBehaviour')
        settings.setValue('/Projections/defaultBehaviour', '')
        if gslayer is None:
            gslayer = getLayerFromStyle(self.element)
        if gslayer is not None:
            if not hasattr(gslayer.resource, "attributes"):
                QMessageBox.warning(explorer, "Edit style", "Editing raster layer styles is currently not supported")
                return
        sld = self.element.sld_body.decode()
        try:
            _sld = "\n".join([line for line in
                              xml.dom.minidom.parseString(sld).toprettyxml().splitlines() if line.strip()])
        except:
            self._showSldParsingError()
            return
        sld = adaptGsToQgs(sld)
        sldfile = tempFilename("sld")
        with open(sldfile, 'w') as f:
            f.write(sld)
        geomtype = getGeomTypeFromSld(sld)
        uri = geomtype + "?crs=epsg:4326&"
        if gslayer is not None:
            fields = gslayer.resource.attributes
            fieldsdesc = ['field=%s:double' % f for f in fields if "geom" not in f]
            fieldsstring = '&'.join(fieldsdesc)
            uri += fieldsstring
        layer = QgsVectorLayer(uri, "tmp", "memory")
        layer.loadSldStyle(sldfile)
        oldSld = getGsCompatibleSld(layer)[0]

        dlg = QgsRendererPropertiesDialog(layer, QgsStyle.defaultStyle())
        dlg.setMapCanvas(iface.mapCanvas())
        dlg.exec_()
        settings.setValue('/Projections/defaultBehaviour', prjSetting)
        newSld = getGsCompatibleSld(layer)[0]
        #TODO: we are not considering the possibility of the user selecting new svg markers,
        #      which would need to be uploaded
        if newSld != oldSld:
            explorer.run(self.element.update_body, "Update style", [], newSld) 
开发者ID:planetfederal,项目名称:qgis-geoserver-plugin,代码行数:43,代码来源:gsexploreritems.py

示例9: centerObject

# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mapCanvas [as 别名]
def centerObject(feature, zoom=None):
    """
        Centers the map view on a given object.

        https://developers.google.com/earth-engine/api_docs#map.centerobject

        Uses:
            >>> from ee_plugin import Map
            >>> Map.centerObject(feature)
    """


    feature = ee.Feature(feature)

    if not zoom:
        # make sure our geometry is in geo
        rect = feature.geometry().transform(ee.Projection('EPSG:4326'), 1)

        # get coordinates
        coords = rect.bounds().getInfo()['coordinates'][0]
        xmin = coords[0][0]
        ymin = coords[0][1]
        xmax = coords[2][0]
        ymax = coords[2][1]

        # construct QGIS geometry
        rect = QgsRectangle(xmin, ymin, xmax, ymax)

        # transform rect to a crs used by current project
        crs_src = QgsCoordinateReferenceSystem(4326)
        crs_dst = QgsCoordinateReferenceSystem(QgsProject.instance().crs())
        geo2proj = QgsCoordinateTransform(crs_src, crs_dst, QgsProject.instance())
        rect_proj = geo2proj.transform(rect)

        # center geometry
        iface.mapCanvas().zoomToFeatureExtent(rect_proj)
    else:
        # set map center to feature centroid at a specified zoom
        center = feature.geometry().centroid().coordinates().getInfo()
        setCenter(center[0], center[1], zoom) 
开发者ID:gee-community,项目名称:qgis-earthengine-plugin,代码行数:42,代码来源:Map.py

示例10: getBounds

# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mapCanvas [as 别名]
def getBounds(asGeoJSON=False):
    """
        Returns the bounds of the current map view, as a list in the format [west, south, east, north] in degrees.

        https://developers.google.com/earth-engine/api_docs#map.getbounds

        Uses:
            >>> from ee_plugin import Map
            >>> bounds = Map.getBounds(True)
            >>> Map.addLayer(bounds, {}, 'bounds')
    """
    ex = iface.mapCanvas().extent()
    # return ex
    xmax = ex.xMaximum()
    ymax = ex.yMaximum()
    xmin = ex.xMinimum()
    ymin = ex.yMinimum()

    # return as [west, south, east, north]
    if not asGeoJSON:
        return [xmin, ymin, xmax, ymax]

    # return as geometry
    crs = iface.mapCanvas().mapSettings().destinationCrs().authid()

    return ee.Geometry.Rectangle([xmin, ymin, xmax, ymax], crs, False) 
开发者ID:gee-community,项目名称:qgis-earthengine-plugin,代码行数:28,代码来源:Map.py

示例11: getScale

# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mapCanvas [as 别名]
def getScale():
    """
        Returns the approximate pixel scale of the current map view, in meters.

        https://developers.google.com/earth-engine/api_docs#map.getscale

        Uses:
            >>> from ee_plugin import Map
            >>> print(Map.getScale())
    """

    return iface.mapCanvas().scale() / 1000 
开发者ID:gee-community,项目名称:qgis-earthengine-plugin,代码行数:14,代码来源:Map.py

示例12: layerNamesFromCanvas

# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mapCanvas [as 别名]
def layerNamesFromCanvas(self):
        """
        Gets all available layers from map canvas.
        :return: (list-of-str) map cointaing layer name to vector layer object.
        """
        return sorted([l.name() for l in iface.mapCanvas().layers()]) 
开发者ID:dsgoficial,项目名称:DsgTools,代码行数:8,代码来源:filterDialog.py

示例13: on_scale_changed

# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mapCanvas [as 别名]
def on_scale_changed():
    print(scale_box.scale(),
          QgsScaleComboBox.toString(scale_box.scale()))
    print(scale_box.scaleString(),
          QgsScaleComboBox.toDouble(scale_box.scaleString()))
    print("Scale changed")
    iface.mapCanvas().zoomScale(1 / scale_box.scale())

# The default values come from Options > Cartographic Tools, part Predefined scales 
开发者ID:webgeodatavore,项目名称:pyqgis-samples,代码行数:11,代码来源:qgis-sample-QgsScaleComboBox.py

示例14: on_scale_changed

# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mapCanvas [as 别名]
def on_scale_changed():
    print(scale_widget.scale(),
          QgsScaleWidget.toString(scale_widget.scale()))
    print(scale_widget.scaleString(),
          QgsScaleWidget.toDouble(scale_widget.scaleString()))
    print(scale_widget.showCurrentScaleButton())
    print("Scale changed")
    iface.mapCanvas().zoomScale(1 / scale_widget.scale()) 
开发者ID:webgeodatavore,项目名称:pyqgis-samples,代码行数:10,代码来源:qgis-sample-QgsScaleWidget.py

示例15: __init__

# 需要导入模块: from qgis.utils import iface [as 别名]
# 或者: from qgis.utils.iface import mapCanvas [as 别名]
def __init__(self, parent=None):
        ''' Constructor '''
        super().__init__(parent)
        self.surface = VideoWidgetSurface(self)
        self.setAttribute(Qt.WA_OpaquePaintEvent)

        self.Tracking_Video_RubberBand = QRubberBand(QRubberBand.Rectangle, self)
        self.Censure_RubberBand = QRubberBand(QRubberBand.Rectangle, self)

        color_blue = QColor(Qt.blue)
        color_black = QColor(Qt.black)
        color_amber = QColor(252, 215, 108)

        pal_blue = QPalette()
        pal_blue.setBrush(QPalette.Highlight, QBrush(color_blue))
        self.Tracking_Video_RubberBand.setPalette(pal_blue)

        pal_black = QPalette()
        pal_black.setBrush(QPalette.Highlight, QBrush(color_black))
        self.Censure_RubberBand.setPalette(pal_black)

        self._interaction = InteractionState()
        self._filterSatate = FilterState()

        self._isinit = False
        self._MGRS = False
        self.gt = None

        self.drawCesure = []
        self.poly_coordinates, self.drawPtPos, self.drawLines, self.drawMeasureDistance, self.drawMeasureArea, self.drawPolygon = [], [], [], [], [], []
        # Draw Polygon Canvas Rubberband
        self.poly_Canvas_RubberBand = QgsRubberBand(
            iface.mapCanvas(), True)  # Polygon type
        # set rubber band style
        self.poly_Canvas_RubberBand.setColor(color_amber)
        self.poly_Canvas_RubberBand.setWidth(3)

        # Tracking Canvas Rubberband
        self.Track_Canvas_RubberBand = QgsRubberBand(
            iface.mapCanvas(), QgsWkbTypes.LineGeometry)
        # set rubber band style
        self.Track_Canvas_RubberBand.setColor(color_blue)
        self.Track_Canvas_RubberBand.setWidth(5)

        # Cursor Canvas Rubberband
        self.Cursor_Canvas_RubberBand = QgsRubberBand(
            iface.mapCanvas(), QgsWkbTypes.PointGeometry)
        self.Cursor_Canvas_RubberBand.setWidth(4)
        self.Cursor_Canvas_RubberBand.setColor(QColor(255, 100, 100, 250))
        self.Cursor_Canvas_RubberBand.setIcon(QgsRubberBand.ICON_FULL_DIAMOND)

        self.parent = parent.parent()

        palette = self.palette()
        palette.setColor(QPalette.Background, Qt.transparent)
        self.setPalette(palette)

        self.origin, self.dragPos = QPoint(), QPoint()
        self.tapTimer = QBasicTimer()
        self.brush = QBrush(color_black)
        self.blue_Pen = QPen(color_blue, 3) 
开发者ID:All4Gis,项目名称:QGISFMV,代码行数:63,代码来源:QgsVideo.py


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