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


Python QgsCoordinateReferenceSystem.toProj4方法代码示例

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


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

示例1: __signal_pbCopyKml_clicked

# 需要导入模块: from qgis.core import QgsCoordinateReferenceSystem [as 别名]
# 或者: from qgis.core.QgsCoordinateReferenceSystem import toProj4 [as 别名]
 def __signal_pbCopyKml_clicked(self, cheked):
     # Extent Openlayers
     action = "map.getExtent().toGeometry().toString();"
     wkt = self.webViewMap.page().mainFrame().evaluateJavaScript(action)
     rect = QgsGeometry.fromWkt(wkt).boundingBox()
     srsGE = QgsCoordinateReferenceSystem(
         4326, QgsCoordinateReferenceSystem.EpsgCrsId)
     coodTrans = QgsCoordinateTransform(self.__srsOL, srsGE,
                                        QgsProject.instance())
     rect = coodTrans.transform(
         rect, QgsCoordinateTransform.ForwardTransform)
     line = QgsGeometry.fromRect(rect).asPolygon()[0]
     wkt = str(QgsGeometry.fromPolylineXY(line).asWkt())
     # Kml
     proj4 = str(srsGE.toProj4())
     kmlLine = bindogr.exportKml(wkt, proj4)
     kml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"\
           "<kml xmlns=\"http://www.opengis.net/kml/2.2\" " \
           "xmlns:gx=\"http://www.google.com/kml/ext/2.2\" " \
           "xmlns:kml=\"http://www.opengis.net/kml/2.2\" " \
           "xmlns:atom=\"http://www.w3.org/2005/Atom\">" \
           "<Placemark>" \
           "<name>KML from Plugin Openlayers Overview for QGIS</name>" \
           "<description>Extent of openlayers map from Plugin Openlayers \
           Overview for QGIS</description>"\
           "%s" \
           "</Placemark></kml>" % kmlLine
     clipBoard = QApplication.clipboard()
     clipBoard.setText(kml)
开发者ID:dongikjang,项目名称:qgis-tmsforkorea-plugin,代码行数:31,代码来源:openlayers_ovwidget.py

示例2: test_ExpressionFieldEllipsoidLengthCalculation

# 需要导入模块: from qgis.core import QgsCoordinateReferenceSystem [as 别名]
# 或者: from qgis.core.QgsCoordinateReferenceSystem import toProj4 [as 别名]
    def test_ExpressionFieldEllipsoidLengthCalculation(self):
        #create a temporary layer
        temp_layer = QgsVectorLayer("LineString?crs=epsg:3111&field=pk:int", "vl", "memory")
        self.assertTrue(temp_layer.isValid())
        f1 = QgsFeature(temp_layer.dataProvider().fields(), 1)
        f1.setAttribute("pk", 1)
        f1.setGeometry(QgsGeometry.fromPolyline([QgsPoint(2484588, 2425722), QgsPoint(2482767, 2398853)]))
        temp_layer.dataProvider().addFeatures([f1])

        # set project CRS and ellipsoid
        srs = QgsCoordinateReferenceSystem(3111, QgsCoordinateReferenceSystem.EpsgCrsId)
        QgsProject.instance().writeEntry("SpatialRefSys", "/ProjectCRSProj4String", srs.toProj4())
        QgsProject.instance().writeEntry("SpatialRefSys", "/ProjectCRSID", srs.srsid())
        QgsProject.instance().writeEntry("SpatialRefSys", "/ProjectCrs", srs.authid())
        QgsProject.instance().writeEntry("Measure", "/Ellipsoid", "WGS84")
        QgsProject.instance().writeEntry("Measurement", "/DistanceUnits", QgsUnitTypes.encodeUnit(QGis.Meters))

        idx = temp_layer.addExpressionField('$length', QgsField('length', QVariant.Double))  # NOQA

        # check value
        f = temp_layer.getFeatures().next()
        expected = 26932.156
        self.assertAlmostEqual(f['length'], expected, 3)

        # change project length unit, check calculation respects unit
        QgsProject.instance().writeEntry("Measurement", "/DistanceUnits", QgsUnitTypes.encodeUnit(QGis.Feet))
        f = temp_layer.getFeatures().next()
        expected = 88360.0918635
        self.assertAlmostEqual(f['length'], expected, 3)
开发者ID:Clayton-Davis,项目名称:QGIS,代码行数:31,代码来源:test_qgsvectorlayer.py

示例3: test_ExpressionFieldEllipsoidAreaCalculation

# 需要导入模块: from qgis.core import QgsCoordinateReferenceSystem [as 别名]
# 或者: from qgis.core.QgsCoordinateReferenceSystem import toProj4 [as 别名]
    def test_ExpressionFieldEllipsoidAreaCalculation(self):
        #create a temporary layer
        temp_layer = QgsVectorLayer("Polygon?crs=epsg:3111&field=pk:int", "vl", "memory")
        self.assertTrue(temp_layer.isValid())
        f1 = QgsFeature(temp_layer.dataProvider().fields(), 1)
        f1.setAttribute("pk", 1)
        f1.setGeometry(QgsGeometry.fromPolygon([[QgsPoint(2484588, 2425722), QgsPoint(2482767, 2398853), QgsPoint(2520109, 2397715), QgsPoint(2520792, 2425494), QgsPoint(2484588, 2425722)]]))
        temp_layer.dataProvider().addFeatures([f1])

        # set project CRS and ellipsoid
        srs = QgsCoordinateReferenceSystem(3111, QgsCoordinateReferenceSystem.EpsgCrsId)
        QgsProject.instance().writeEntry("SpatialRefSys", "/ProjectCRSProj4String", srs.toProj4())
        QgsProject.instance().writeEntry("SpatialRefSys", "/ProjectCRSID", srs.srsid())
        QgsProject.instance().writeEntry("SpatialRefSys", "/ProjectCrs", srs.authid())
        QgsProject.instance().writeEntry("Measure", "/Ellipsoid", "WGS84")
        QgsProject.instance().writeEntry("Measurement", "/AreaUnits", QgsUnitTypes.encodeUnit(QgsUnitTypes.SquareMeters))

        idx = temp_layer.addExpressionField('$area', QgsField('area', QVariant.Double))  # NOQA

        # check value
        f = temp_layer.getFeatures().next()
        expected = 1009089817.0
        self.assertAlmostEqual(f['area'], expected, delta=1.0)

        # change project area unit, check calculation respects unit
        QgsProject.instance().writeEntry("Measurement", "/AreaUnits", QgsUnitTypes.encodeUnit(QgsUnitTypes.SquareMiles))
        f = temp_layer.getFeatures().next()
        expected = 389.6117565069
        self.assertAlmostEqual(f['area'], expected, 3)
开发者ID:Clayton-Davis,项目名称:QGIS,代码行数:31,代码来源:test_qgsvectorlayer.py

示例4: browseCRS

# 需要导入模块: from qgis.core import QgsCoordinateReferenceSystem [as 别名]
# 或者: from qgis.core.QgsCoordinateReferenceSystem import toProj4 [as 别名]
 def browseCRS(self):
     selector = QgsGenericProjectionSelector()
     selector.setSelectedAuthId(self.crs)
     if selector.exec_():
         authId = selector.selectedAuthId()
         if authId.upper().startswith("EPSG:"):
             self.crs = authId
         else:
             proj = QgsCoordinateReferenceSystem()
             proj.createFromSrsId(selector.selectedCrsId())
             self.crs = proj.toProj4()
         self.updateText()
开发者ID:liminlu0314,项目名称:QGIS,代码行数:14,代码来源:CrsSelectionPanel.py

示例5: gdal_crs_string

# 需要导入模块: from qgis.core import QgsCoordinateReferenceSystem [as 别名]
# 或者: from qgis.core.QgsCoordinateReferenceSystem import toProj4 [as 别名]
    def gdal_crs_string(crs: QgsCoordinateReferenceSystem) -> str:
        """
        Converts a QgsCoordinateReferenceSystem to a string understandable
        by GDAL
        :param crs: crs to convert
        :return: gdal friendly string
        """
        if crs.authid().upper().startswith('EPSG:'):
            return crs.authid()

        # fallback to proj4 string
        return crs.toProj4()
开发者ID:pigreco,项目名称:QGIS,代码行数:14,代码来源:GdalUtils.py


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