本文整理汇总了Python中qgis.core.QgsOfflineEditing.convertToOfflineProject方法的典型用法代码示例。如果您正苦于以下问题:Python QgsOfflineEditing.convertToOfflineProject方法的具体用法?Python QgsOfflineEditing.convertToOfflineProject怎么用?Python QgsOfflineEditing.convertToOfflineProject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.core.QgsOfflineEditing
的用法示例。
在下文中一共展示了QgsOfflineEditing.convertToOfflineProject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _testInit
# 需要导入模块: from qgis.core import QgsOfflineEditing [as 别名]
# 或者: from qgis.core.QgsOfflineEditing import convertToOfflineProject [as 别名]
def _testInit(self):
"""
Preliminary checks for each test
"""
# goes offline
ol = QgsOfflineEditing()
online_layer = list(self.registry.mapLayers().values())[0]
self.assertTrue(online_layer.isSpatial())
# Check we have features
self.assertEqual(len([f for f in online_layer.getFeatures()]), len(TEST_FEATURES))
self.assertTrue(ol.convertToOfflineProject(self.temp_path, 'offlineDbFile.sqlite', [online_layer.id()]))
offline_layer = list(self.registry.mapLayers().values())[0]
self.assertTrue(offline_layer.isSpatial())
self.assertTrue(offline_layer.isValid())
self.assertTrue(offline_layer.name().find('(offline)') > -1)
self.assertEqual(len([f for f in offline_layer.getFeatures()]), len(TEST_FEATURES))
return ol, offline_layer
示例2: test_offlineConversion
# 需要导入模块: from qgis.core import QgsOfflineEditing [as 别名]
# 或者: from qgis.core.QgsOfflineEditing import convertToOfflineProject [as 别名]
def test_offlineConversion(self):
# goes offline
ol = QgsOfflineEditing()
online_layer = list(self.registry.mapLayers().values())[0]
self.assertTrue(online_layer.hasGeometryType())
# Check we have 3 features
self.assertEqual(len([f for f in online_layer.getFeatures()]), len(TEST_FEATURES))
self.assertTrue(ol.convertToOfflineProject(self.temp_path, 'offlineDbFile.sqlite', [online_layer.id()]))
offline_layer = list(self.registry.mapLayers().values())[0]
self.assertTrue(offline_layer.hasGeometryType())
self.assertTrue(offline_layer.isValid())
self.assertTrue(offline_layer.name().find('(offline)') > -1)
self.assertEqual(len([f for f in offline_layer.getFeatures()]), len(TEST_FEATURES))
# Edit feature 2
feat2 = self._getFeatureByAttribute(offline_layer, 'name', "'name 2'")
self.assertTrue(offline_layer.startEditing())
self.assertTrue(offline_layer.changeAttributeValue(feat2.id(), offline_layer.fieldNameIndex('name'), 'name 2 edited'))
self.assertTrue(offline_layer.changeGeometry(feat2.id(), QgsGeometry.fromPoint(QgsPoint(33.0, 60.0))))
self.assertTrue(offline_layer.commitChanges())
feat2 = self._getFeatureByAttribute(offline_layer, 'name', "'name 2 edited'")
self.assertTrue(ol.isOfflineProject())
# Sync
ol.synchronize()
# Does anybody know why the sleep is needed? Is that a threaded WFS consequence?
sleep(1)
online_layer = list(self.registry.mapLayers().values())[0]
self.assertTrue(online_layer.isValid())
self.assertFalse(online_layer.name().find('(offline)') > -1)
self.assertEqual(len([f for f in online_layer.getFeatures()]), len(TEST_FEATURES))
# Check that data have changed in the backend (raise exception if not found)
feat2 = self._getFeatureByAttribute(self._getLayer('test_point'), 'name', "'name 2 edited'")
feat2 = self._getFeatureByAttribute(online_layer, 'name', "'name 2 edited'")
self.assertEqual(feat2.geometry().asPoint().toString(), QgsPoint(33.0, 60.0).toString())
# Check that all other features have not changed
layer = self._getLayer('test_point')
self.assertTrue(self._compareFeature(layer, TEST_FEATURES[1 - 1]))
self.assertTrue(self._compareFeature(layer, TEST_FEATURES[3 - 1]))
self.assertTrue(self._compareFeature(layer, TEST_FEATURES[4 - 1]))
# Test for regression on double sync (it was a SEGFAULT)
# goes offline
ol = QgsOfflineEditing()
offline_layer = list(self.registry.mapLayers().values())[0]
# Edit feature 2
feat2 = self._getFeatureByAttribute(offline_layer, 'name', "'name 2 edited'")
self.assertTrue(offline_layer.startEditing())
self.assertTrue(offline_layer.changeAttributeValue(feat2.id(), offline_layer.fieldNameIndex('name'), 'name 2'))
self.assertTrue(offline_layer.changeGeometry(feat2.id(), QgsGeometry.fromPoint(TEST_FEATURES[1][2])))
# Edit feat 4
feat4 = self._getFeatureByAttribute(offline_layer, 'name', "'name 4'")
self.assertTrue(offline_layer.changeAttributeValue(feat4.id(), offline_layer.fieldNameIndex('name'), 'name 4 edited'))
self.assertTrue(offline_layer.commitChanges())
# Sync
ol.synchronize()
# Does anybody knows why the sleep is needed? Is that a threaded WFS consequence?
sleep(1)
online_layer = list(self.registry.mapLayers().values())[0]
layer = self._getLayer('test_point')
# Check that data have changed in the backend (raise exception if not found)
feat4 = self._getFeatureByAttribute(layer, 'name', "'name 4 edited'")
feat4 = self._getFeatureByAttribute(online_layer, 'name', "'name 4 edited'")
feat2 = self._getFeatureByAttribute(layer, 'name', "'name 2'")
feat2 = self._getFeatureByAttribute(online_layer, 'name', "'name 2'")
# Check that all other features have not changed
layer = self._getLayer('test_point')
self.assertTrue(self._compareFeature(layer, TEST_FEATURES[1 - 1]))
self.assertTrue(self._compareFeature(layer, TEST_FEATURES[2 - 1]))
self.assertTrue(self._compareFeature(layer, TEST_FEATURES[3 - 1]))