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


Python core.QgsCoordinateTransform方法代码示例

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


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

示例1: canvasPressEvent

# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsCoordinateTransform [as 别名]
def canvasPressEvent(self, event):
        """Capture the coordinate when the mouse button has been released."""
        pt = self.snappoint(event.originalPixelPoint())
        self.removeVertexMarker()
        if self.azDigitizerDialog is None:
            from .azDigitizer import AzDigitizerWidget
            self.azDigitizerDialog = AzDigitizerWidget(self.iface, self.iface.mainWindow())

        layer = self.iface.activeLayer()
        if layer is None or layer.wkbType() != QgsWkbTypes.Point:
            self.azDigitizerDialog.includeStartLabel.setEnabled(False)
            self.azDigitizerDialog.checkBox.setEnabled(False)
        else:
            self.azDigitizerDialog.includeStartLabel.setEnabled(True)
            self.azDigitizerDialog.checkBox.setEnabled(True)
        try:
            canvasCRS = self.canvas.mapSettings().destinationCrs()
            transform = QgsCoordinateTransform(canvasCRS, epsg4326, QgsProject.instance())
            pt4326 = transform.transform(pt.x(), pt.y())
            self.azDigitizerDialog.setPoint(pt4326)
            self.azDigitizerDialog.show()
        except Exception:
            self.iface.messageBar().pushMessage("", tr("Clicked location is invalid"), level=Qgis.Warning, duration=4) 
开发者ID:NationalSecurityAgency,项目名称:qgis-shapetools-plugin,代码行数:25,代码来源:azDigitizer.py

示例2: canvasPressEvent

# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsCoordinateTransform [as 别名]
def canvasPressEvent(self, event):
        '''Capture the coordinate when the mouse button has been released.'''
        pt = self.snappoint(event.originalPixelPoint())
        self.removeVertexMarker()
        layer = self.iface.activeLayer()
        if layer is None:
            return
        if self.lineDigitizerDialog is None:
            from .lineDigitizer import LineDigitizerWidget
            self.lineDigitizerDialog = LineDigitizerWidget(self.iface, self.iface.mainWindow())

        if layer.geometryType() == QgsWkbTypes.LineGeometry:
            self.lineDigitizerDialog.closeLineCheckBox.setEnabled(True)
        else:
            self.lineDigitizerDialog.closeLineCheckBox.setEnabled(False)
        try:
            canvasCRS = self.canvas.mapSettings().destinationCrs()
            transform = QgsCoordinateTransform(canvasCRS, epsg4326, QgsProject.instance())
            pt4326 = transform.transform(pt.x(), pt.y())
            self.lineDigitizerDialog.setPoint(pt4326)
            self.lineDigitizerDialog.valuesTextEdit.clear()
            self.lineDigitizerDialog.show()
        except Exception:
            self.iface.messageBar().pushMessage("", tr("Clicked location is invalid"), level=Qgis.Warning, duration=4) 
开发者ID:NationalSecurityAgency,项目名称:qgis-shapetools-plugin,代码行数:26,代码来源:lineDigitizer.py

示例3: zoomToLayer

# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsCoordinateTransform [as 别名]
def zoomToLayer(self, layer, zoom = None):
        box = layer.boundingBoxOfSelected()
        if zoom is not None:
            box.grow(100-zoom)
        # Defining the crs from src and destiny
        epsg = self.iface.mapCanvas().mapSettings().destinationCrs().authid()
        crsDest = QgsCoordinateReferenceSystem(epsg)
        #getting srid from something like 'EPSG:31983'
        if not layer:
            layer = self.iface.mapCanvas().currentLayer()
        srid = layer.crs().authid()
        crsSrc = QgsCoordinateReferenceSystem(srid) #here we have to put authid, not srid
        # Creating a transformer
        coordinateTransformer = QgsCoordinateTransform(crsSrc, crsDest, QgsProject.instance())
        newBox = coordinateTransformer.transform(box)

        self.iface.mapCanvas().setExtent(newBox)
        self.iface.mapCanvas().refresh() 
开发者ID:dsgoficial,项目名称:DsgTools,代码行数:20,代码来源:inspectFeatures.py

示例4: addMarker

# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsCoordinateTransform [as 别名]
def addMarker(self, lat, lon):
        if self.marker:
            self.removeMarker()
        canvasCrs = self.canvas.mapSettings().destinationCrs()
        transform = QgsCoordinateTransform(self.epsg4326, canvasCrs, QgsProject.instance())
        center = transform.transform(lon, lat)
        self.marker = QgsVertexMarker(self.canvas)
        self.marker.setCenter(center)
        self.marker.setColor(QColor(255, 70, 0))
        self.marker.setIconSize(15)
        self.marker.setIconType(QgsVertexMarker.ICON_X)
        self.marker.setPenWidth(3)
        self.marker.show() 
开发者ID:NationalSecurityAgency,项目名称:qgis-bulk-nominatim,代码行数:15,代码来源:reverseGeocode.py

示例5: transform_geom

# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsCoordinateTransform [as 别名]
def transform_geom(self, geometry):
        canvasCrs = self.canvas.mapSettings().destinationCrs()
        geom = QgsGeometry(geometry)
        geom.transform(QgsCoordinateTransform(self.epsg4326, canvasCrs, QgsProject.instance()))
        return geom 
开发者ID:NationalSecurityAgency,项目名称:qgis-bulk-nominatim,代码行数:7,代码来源:reverseGeocode.py

示例6: copyCanvas

# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsCoordinateTransform [as 别名]
def copyCanvas(self):
        extent = self.iface.mapCanvas().extent()
        canvasCrs = self.canvas.mapSettings().destinationCrs()
        if settings.bBoxCrs == 0 and canvasCrs != epsg4326:
            transform = QgsCoordinateTransform(canvasCrs, epsg4326, QgsProject.instance())
            p1x, p1y = transform.transform(float(extent.xMinimum()), float(extent.yMinimum()))
            p2x, p2y = transform.transform(float(extent.xMaximum()), float(extent.yMaximum()))
            extent.set(p1x, p1y, p2x, p2y)
        delim = settings.bBoxDelimiter
        prefix = settings.bBoxPrefix
        suffix = settings.bBoxSuffix
        precision = settings.bBoxDigits
        outStr = ''
        minX = extent.xMinimum()
        minY = extent.yMinimum()
        maxX = extent.xMaximum()
        maxY = extent.yMaximum()
        if settings.bBoxFormat == 0:  # minX,minY,maxX,maxY - using the delimiter
            outStr = '{:.{prec}f}{}{:.{prec}f}{}{:.{prec}f}{}{:.{prec}f}'.format(
                minX, delim, minY, delim, maxX, delim, maxY, prec=precision)
        elif settings.bBoxFormat == 1:  # minX,maxX,minY,maxY - Using the selected delimiter'
            outStr = '{:.{prec}f}{}{:.{prec}f}{}{:.{prec}f}{}{:.{prec}f}'.format(
                minX, delim, maxX, delim, minY, delim, maxY, prec=precision)
        elif settings.bBoxFormat == 2:  # x1 y1,x2 y2,x3 y3,x4 y4,x1 y1 - Polygon format
            outStr = '{:.{prec}f} {:.{prec}f},{:.{prec}f} {:.{prec}f},{:.{prec}f} {:.{prec}f},{:.{prec}f} {:.{prec}f},{:.{prec}f} {:.{prec}f}'.format(
                minX, minY, minX, maxY, maxX, maxY, maxX, minY, minX, minY, prec=precision)
        elif settings.bBoxFormat == 3:  # x1,y1 x2,y2 x3,y3 x4,y4 x1,y1 - Polygon format
            outStr = '{:.{prec}f},{:.{prec}f} {:.{prec}f},{:.{prec}f} {:.{prec}f},{:.{prec}f} {:.{prec}f},{:.{prec}f} {:.{prec}f},{:.{prec}f}'.format(
                minX, minY, minX, maxY, maxX, maxY, maxX, minY, minX, minY, prec=precision)
        elif settings.bBoxFormat == 4:  # WKT Polygon
            outStr = extent.asWktPolygon()
        elif settings.bBoxFormat == 5:  # bbox: [minX, minY, maxX, maxY] - MapProxy
            outStr = 'bbox: [{}, {}, {}, {}]'.format(
                minX, minY, maxX, maxY)
        elif settings.bBoxFormat == 6:  # bbox: [minX, minY, maxX, maxY] - MapProxy
            outStr = 'bbox={},{},{},{}'.format(
                minX, minY, maxX, maxY)
        outStr = '{}{}{}'.format(prefix, outStr, suffix)
        clipboard = QApplication.clipboard()
        clipboard.setText(outStr)
        self.iface.messageBar().pushMessage("", "'{}' copied to the clipboard".format(outStr), level=Qgis.Info, duration=4) 
开发者ID:NationalSecurityAgency,项目名称:qgis-latlontools-plugin,代码行数:43,代码来源:latLonTools.py

示例7: zoomTo

# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsCoordinateTransform [as 别名]
def zoomTo(self, srcCrs, lat, lon):
        canvasCrs = self.canvas.mapSettings().destinationCrs()
        transform = QgsCoordinateTransform(srcCrs, canvasCrs, QgsProject.instance())
        x, y = transform.transform(float(lon), float(lat))

        rect = QgsRectangle(x, y, x, y)
        self.canvas.setExtent(rect)

        pt = QgsPointXY(x, y)
        self.highlight(pt)
        self.canvas.refresh()
        return pt 
开发者ID:NationalSecurityAgency,项目名称:qgis-latlontools-plugin,代码行数:14,代码来源:latLonTools.py

示例8: utmString2Crs

# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsCoordinateTransform [as 别名]
def utmString2Crs(utm, crs=epsg4326):
    parts = re.split(r'[\s]+', utm.upper())
    utmlen = len(parts)
    if utmlen == 3:
        m = re.findall(r'(\d+)([NS])', parts[0])
        if len(m) != 1 or len(m[0]) != 2:
            raise ValueError('Invalid UTM Coordinate')
        zone = int(m[0][0])
        hemisphere = m[0][1]
        easting = float(parts[1])
        northing = float(parts[2])
    elif utmlen == 4:
        if parts[1] != 'N' and parts[1] != 'S':
            raise ValueError('Invalid UTM Coordinate')
        zone = int(parts[0])
        easting = float(parts[2])
        northing = float(parts[3])
    else:
        raise ValueError('Invalid UTM Coordinate')
    if zone < 1 or zone > 60:
        raise ValueError('Invalid UTM Coordinate')

    utmcrs = QgsCoordinateReferenceSystem(utm_epsg_codes['{}{}'.format(zone, hemisphere)])
    pt = QgsPointXY(easting, northing)
    utmtrans = QgsCoordinateTransform(utmcrs, crs, QgsProject.instance())
    return(utmtrans.transform(pt)) 
开发者ID:NationalSecurityAgency,项目名称:qgis-latlontools-plugin,代码行数:28,代码来源:utm.py

示例9: latLon2UtmString

# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsCoordinateTransform [as 别名]
def latLon2UtmString(lat, lon, precision):
    zone = int((lon + 180) / 6) + 1
    if lon >= 0:
        zonestr = '{}N'.format(zone)
    else:
        zonestr = '{}S'.format(zone)
    try:
        utmcrs = QgsCoordinateReferenceSystem(utm_epsg_codes[zonestr])
        utmtrans = QgsCoordinateTransform(epsg4326, utmcrs, QgsProject.instance())
        pt = QgsPointXY(lon, lat)
        utmpt = utmtrans.transform(pt)
        msg = '{} {:.{prec}f} {:.{prec}f}'.format(zonestr, utmpt.x(), utmpt.y(), prec=precision)
    except Exception:
        msg = ''
    return(msg) 
开发者ID:NationalSecurityAgency,项目名称:qgis-latlontools-plugin,代码行数:17,代码来源:utm.py

示例10: canvasReleaseEvent

# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsCoordinateTransform [as 别名]
def canvasReleaseEvent(self, event):
        '''Capture the coordinate when the mouse button has been released,
        format it, and copy it to the clipboard. pt is QgsPointXY'''
        pt = self.snappoint(event.originalPixelPoint())
        self.removeVertexMarker()

        try:
            canvasCRS = self.canvas.mapSettings().destinationCrs()
            transform = QgsCoordinateTransform(canvasCRS, epsg4326, QgsProject.instance())
            pt4326 = transform.transform(pt.x(), pt.y())
            self.capturePoint.emit(pt4326)
        except Exception as e:
            pass 
开发者ID:NationalSecurityAgency,项目名称:qgis-latlontools-plugin,代码行数:15,代码来源:captureCoordinate.py

示例11: clickedOnCanvasAction

# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsCoordinateTransform [as 别名]
def clickedOnCanvasAction(self,clickedPoint):
        self.iface.mapCanvas().setMapTool(self.module.mapSelectionTool)
        crsCanvas = self.module.iface.mapCanvas().mapSettings().destinationCrs() # get current crs
        crsWGS84 = QgsCoordinateReferenceSystem(4326)  # WGS 84
        xform = QgsCoordinateTransform(crsCanvas, crsWGS84, QgsProject.instance())
        wgs84point = xform.transform(clickedPoint)
        self.lon_widget.setText(str(wgs84point.x()))
        self.lat_widget.setText(str(wgs84point.y()))
        super(mapillaryFilter, self).show()
        self.raise_() 
开发者ID:enricofer,项目名称:go2mapillary,代码行数:12,代码来源:mapillary_filter.py

示例12: panToAction

# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsCoordinateTransform [as 别名]
def panToAction(self):
        crsCanvas = self.module.iface.mapCanvas().mapSettings().destinationCrs() # get current crs
        crsWGS84 = QgsCoordinateReferenceSystem(4326)  # WGS 84
        xform = QgsCoordinateTransform(crsWGS84, crsCanvas, QgsProject.instance())
        sourcePoint = QgsPointXY(float(self.field_longitude.text()),float(self.field_latitude.text()))
        self.module.iface.mapCanvas().setCenter(xform.transform(sourcePoint))
        self.module.iface.mapCanvas().refresh() 
开发者ID:enricofer,项目名称:go2mapillary,代码行数:9,代码来源:mapillary_image_info.py

示例13: transformToWGS84

# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsCoordinateTransform [as 别名]
def transformToWGS84(self, pPoint):
        # transformation from the current SRS to WGS84
        crcMappaCorrente = self.iface.mapCanvas().mapSettings().destinationCrs() # get current crs
        crsSrc = crcMappaCorrente
        crsDest = QgsCoordinateReferenceSystem(4326)  # WGS 84
        xform = QgsCoordinateTransform(crsSrc, crsDest, QgsProject.instance())
        return xform.transform(pPoint) # forward transformation: src -> dest 
开发者ID:enricofer,项目名称:go2mapillary,代码行数:9,代码来源:mapillary_coverage.py

示例14: centerObject

# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsCoordinateTransform [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

示例15: setCenter

# 需要导入模块: from qgis import core [as 别名]
# 或者: from qgis.core import QgsCoordinateTransform [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


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