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


Python QgsRectangle.isEmpty方法代码示例

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


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

示例1: calculate_layer_extent

# 需要导入模块: from qgis.core import QgsRectangle [as 别名]
# 或者: from qgis.core.QgsRectangle import isEmpty [as 别名]
 def calculate_layer_extent(self, layer):
     extent = QgsRectangle()
     
     features = layer.getFeatures()
     for feature in features:
         geometry = feature.geometry()
         if extent.isEmpty() :
             extent = geometry.boundingBox()
         else:
             extent.combineExtentWith(geometry.boundingBox())
             
     if extent.isEmpty() :
         extent = layer.extent()
         
     return extent
开发者ID:mapplus,项目名称:qgis-scripts,代码行数:17,代码来源:CreateRingMaps.py

示例2: _populate_bookmarks_list

# 需要导入模块: from qgis.core import QgsRectangle [as 别名]
# 或者: from qgis.core.QgsRectangle import isEmpty [as 别名]
    def _populate_bookmarks_list(self):
        """Read the sqlite database and populate the bookmarks list.

        If no bookmarks are found, the bookmarks radio button will be disabled
        and the label will be shown indicating that the user should add
        bookmarks in QGIS first.

        Every bookmark are reprojected to mapcanvas crs.
        """
        # Connect to the QGIS sqlite database and check if the table exists.
        # noinspection PyArgumentList
        db_file_path = QgsApplication.qgisUserDatabaseFilePath()
        db = sqlite3.connect(db_file_path)
        cursor = db.cursor()
        cursor.execute(
            'SELECT COUNT(*) '
            'FROM sqlite_master '
            'WHERE type=\'table\' '
            'AND name=\'tbl_bookmarks\';')

        number_of_rows = cursor.fetchone()[0]
        if number_of_rows > 0:
            cursor.execute(
                'SELECT * '
                'FROM tbl_bookmarks;')
            bookmarks = cursor.fetchall()

            canvas_crs = self.canvas.mapSettings().destinationCrs()

            for bookmark in bookmarks:
                name = bookmark[1]
                srid = bookmark[7]
                rectangle = QgsRectangle(
                    bookmark[3], bookmark[4], bookmark[5], bookmark[6])

                if srid != canvas_crs.srsid():
                    transform = QgsCoordinateTransform(
                        QgsCoordinateReferenceSystem(srid),
                        canvas_crs,
                        QgsProject.instance()
                    )
                    try:
                        rectangle = transform.transform(rectangle)
                    except QgsCsException:
                        rectangle = QgsRectangle()

                if rectangle.isEmpty():
                    pass

                self.bookmarks_list.addItem(name, rectangle)
        if self.bookmarks_list.currentIndex() >= 0:
            self.create_bookmarks_label.hide()
        else:
            self.create_bookmarks_label.show()
            self.hazard_exposure_bookmark.setDisabled(True)
            self.bookmarks_list.hide()
开发者ID:inasafe,项目名称:inasafe,代码行数:58,代码来源:extent_selector_dialog.py

示例3: testCtor

# 需要导入模块: from qgis.core import QgsRectangle [as 别名]
# 或者: from qgis.core.QgsRectangle import isEmpty [as 别名]
    def testCtor(self):
        rect = QgsRectangle(5.0, 5.0, 10.0, 10.0)

        myExpectedResult = True
        myResult = rect.isEmpty()
        myMessage = "Expected: %s Got: %s" % (myExpectedResult, myResult)
        assert rect.isEmpty(), myMessage

        myMessage = "Expected: %s\nGot: %s\n" % (5.0, rect.xMinimum())
        assert rect.xMinimum() == 5.0, myMessage

        myMessage = "Expected: %s\nGot: %s\n" % (5.0, rect.yMinimum())
        assert rect.yMinimum() == 5.0, myMessage

        myMessage = "Expected: %s\nGot: %s\n" % (10.0, rect.xMaximum())
        assert rect.xMaximum() == 10.0, myMessage

        myMessage = "Expected: %s\nGot: %s\n" % (10.0, rect.yMaximum())
        assert rect.yMaximum() == 10.0, myMessage
开发者ID:dwadler,项目名称:QGIS,代码行数:21,代码来源:test_qgsrectangle.py

示例4: _populate_bookmarks_list

# 需要导入模块: from qgis.core import QgsRectangle [as 别名]
# 或者: from qgis.core.QgsRectangle import isEmpty [as 别名]
    def _populate_bookmarks_list(self):
        """Read the sqlite database and populate the bookmarks list.

        Every bookmark are reprojected to mapcanvas crs.
        """

        # Connect to the QGIS sqlite database and check if the table exists.
        db_file_path = QgsApplication.qgisUserDbFilePath()
        if not isfile(db_file_path):
            # If the database does not exist.
            return

        try:
            db = sqlite3.connect(db_file_path)
            cursor = db.cursor()
            cursor.execute(
                'SELECT COUNT(*) '
                'FROM sqlite_master '
                'WHERE type=\'table\' '
                'AND name=\'tbl_bookmarks\';')

            number_of_rows = cursor.fetchone()[0]
            if number_of_rows > 0:
                cursor.execute(
                    'SELECT * '
                    'FROM tbl_bookmarks;')
                bookmarks = cursor.fetchall()

                map_renderer = self.canvas.mapRenderer()
                canvas_srid = map_renderer.destinationCrs().srsid()

                for bookmark in bookmarks:
                    name = bookmark[1]
                    srid = bookmark[7]
                    rectangle = QgsRectangle(
                        bookmark[3], bookmark[4], bookmark[5], bookmark[6])

                    if srid != canvas_srid:
                        transform = QgsCoordinateTransform(
                            srid, canvas_srid)
                        rectangle = transform.transform(rectangle)

                    if rectangle.isEmpty():
                        pass

                    self.comboBox_bookmarks_list.addItem(name, rectangle)
        except sqlite3.Error:
            # If we have any SQL error with SQLite.
            return
开发者ID:NyakudyaA,项目名称:inasafe,代码行数:51,代码来源:extent_selector_dialog.py

示例5: testCtor

# 需要导入模块: from qgis.core import QgsRectangle [as 别名]
# 或者: from qgis.core.QgsRectangle import isEmpty [as 别名]
    def testCtor(self):
        rect = QgsRectangle( 5.0, 5.0, 10.0, 10.0)

        assert rect.isEmpty(), "Empty rectangle constructed"

        myMessage = ('Expected: %s\nGot: %s\n' %
                      (5.0, rect.xMinimum()))
        assert rect.xMinimum() == 5.0, myMessage

        myMessage = ('Expected: %s\nGot: %s\n' %
                      (5.0, rect.yMinimum()))
        assert rect.yMinimum() == 5.0, myMessage

        myMessage = ('Expected: %s\nGot: %s\n' %
                      (10.0, rect.xMaximum()))
        assert rect.xMaximum() == 10.0, myMessage

        myMessage = ('Expected: %s\nGot: %s\n' %
                      (10.0, rect.yMaximum()))
        assert rect.yMaximum() == 10.0, myMessage
开发者ID:,项目名称:,代码行数:22,代码来源:

示例6: PyProvider

# 需要导入模块: from qgis.core import QgsRectangle [as 别名]
# 或者: from qgis.core.QgsRectangle import isEmpty [as 别名]

#.........这里部分代码省略.........
                continue
            new_fields[fieldIndex].setName(new_name)
        if result:
            self._fields = QgsFields()
            for i in range(len(new_fields)):
                self._fields.append(new_fields[i])
        return result

    def deleteAttributes(self, attributes):
        attrIdx = sorted(attributes, reverse=True)

        # delete attributes one-by-one with decreasing index
        for idx in attrIdx:
            self._fields.remove(idx)
            for f in self._features.values():
                attr = f.attributes()
                del(attr[idx])
                f.setAttributes(attr)
        self.clearMinMaxCache()
        return True

    def changeAttributeValues(self, attr_map):
        for feature_id, attrs in attr_map.items():
            try:
                f = self._features[feature_id]
            except KeyError:
                continue
            for k, v in attrs.items():
                f.setAttribute(k, v)
        self.clearMinMaxCache()
        return True

    def changeGeometryValues(self, geometry_map):
        for feature_id, geometry in geometry_map.items():
            try:
                f = self._features[feature_id]
                f.setGeometry(geometry)
            except KeyError:
                continue
        self.updateExtents()
        return True

    def allFeatureIds(self):
        return list(self._features.keys())

    def subsetString(self):
        return self._subset_string

    def setSubsetString(self, subsetString):
        if subsetString == self._subset_string:
            return True
        self._subset_string = subsetString
        self.updateExtents()
        self.clearMinMaxCache()
        self.dataChanged.emit()
        return True

    def supportsSubsetString(self):
        return True

    def createSpatialIndex(self):
        if self._spatialindex is None:
            self._spatialindex = QgsSpatialIndex()
            for f in self._features.values():
                self._spatialindex.insertFeature(f)
        return True

    def capabilities(self):
        return QgsVectorDataProvider.AddFeatures | QgsVectorDataProvider.DeleteFeatures | QgsVectorDataProvider.CreateSpatialIndex | QgsVectorDataProvider.ChangeGeometries | QgsVectorDataProvider.ChangeAttributeValues | QgsVectorDataProvider.AddAttributes | QgsVectorDataProvider.DeleteAttributes | QgsVectorDataProvider.RenameAttributes | QgsVectorDataProvider.SelectAtId | QgsVectorDataProvider. CircularGeometries

    #/* Implementation of functions from QgsDataProvider */

    def name(self):
        return self.providerKey()

    def extent(self):
        if self._extent.isEmpty() and self._features:
            self._extent.setMinimal()
            if not self._subset_string:
                # fast way - iterate through all features
                for feat in self._features.values():
                    if feat.hasGeometry():
                        self._extent.combineExtentWith(feat.geometry().boundingBox())
            else:
                for f in self.getFeatures(QgsFeatureRequest().setSubsetOfAttributes([])):
                    if f.hasGeometry():
                        self._extent.combineExtentWith(f.geometry().boundingBox())

        elif not self._features:
            self._extent.setMinimal()
        return QgsRectangle(self._extent)

    def updateExtents(self):
        self._extent.setMinimal()

    def isValid(self):
        return True

    def crs(self):
        return self._crs
开发者ID:dmarteau,项目名称:QGIS,代码行数:104,代码来源:provider_python.py


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