當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。