本文整理汇总了Python中realtime.shake_event.ShakeEvent.local_cities_memory_layer方法的典型用法代码示例。如果您正苦于以下问题:Python ShakeEvent.local_cities_memory_layer方法的具体用法?Python ShakeEvent.local_cities_memory_layer怎么用?Python ShakeEvent.local_cities_memory_layer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类realtime.shake_event.ShakeEvent
的用法示例。
在下文中一共展示了ShakeEvent.local_cities_memory_layer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_local_cities
# 需要导入模块: from realtime.shake_event import ShakeEvent [as 别名]
# 或者: from realtime.shake_event.ShakeEvent import local_cities_memory_layer [as 别名]
def test_local_cities(self):
"""Test that we can retrieve the cities local to the event"""
working_dir = shakemap_extract_dir()
shake_event = ShakeEvent(
working_dir=working_dir,
event_id=SHAKE_ID,
data_is_local_flag=True)
# Get teh mem layer
cities_layer = shake_event.local_cities_memory_layer()
provider = cities_layer.dataProvider()
expected_feature_count = 2
self.assertEquals(provider.featureCount(), expected_feature_count)
strings = []
request = QgsFeatureRequest()
for feature in cities_layer.getFeatures(request):
# fetch map of attributes
attributes = cities_layer.dataProvider().attributeIndexes()
for attribute_key in attributes:
strings.append("%d: %s\n" % (
attribute_key, feature[attribute_key]))
strings.append('------------------\n')
LOGGER.debug('Mem table:\n %s' % strings)
file_path = unique_filename(prefix='test_local_cities',
suffix='.txt',
dir=temp_dir('test'))
cities_file = file(file_path, 'w')
cities_file.writelines(strings)
cities_file.close()
fixture_path = os.path.join(data_dir(),
'tests',
'test_local_cities.txt')
cities_file = file(fixture_path)
expected_string = cities_file.readlines()
cities_file.close()
diff = difflib.unified_diff(expected_string, strings)
diff_list = list(diff)
diff_string = ''
for _, myLine in enumerate(diff_list):
diff_string += myLine
message = ('Diff is not zero length:\n'
'Control file: %s\n'
'Test file: %s\n'
'Diff:\n%s' %
(fixture_path,
file_path,
diff_string))
self.assertEqual(diff_string, '', message)