本文整理汇总了Python中safe.impact_functions.registry.Registry.filter_by_exposure方法的典型用法代码示例。如果您正苦于以下问题:Python Registry.filter_by_exposure方法的具体用法?Python Registry.filter_by_exposure怎么用?Python Registry.filter_by_exposure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类safe.impact_functions.registry.Registry
的用法示例。
在下文中一共展示了Registry.filter_by_exposure方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_filter_by_exposure_metadata
# 需要导入模块: from safe.impact_functions.registry import Registry [as 别名]
# 或者: from safe.impact_functions.registry.Registry import filter_by_exposure [as 别名]
def test_filter_by_exposure_metadata(self):
"""TestRegistry: Test filtering IF by exposure metadata."""
# Full metadata
exposure_metadata = {
'layer_mode': layer_mode_classified,
'layer_geometry': layer_geometry_point,
'exposure': exposure_structure,
'exposure_unit': []
}
registry = Registry()
impact_functions = registry.filter_by_exposure(
registry.impact_functions, exposure_metadata)
expected = [
FloodPolygonBuildingFunction,
FloodRasterBuildingFunction,
TsunamiRasterBuildingFunction,
ClassifiedRasterHazardBuildingFunction,
ClassifiedPolygonHazardBuildingFunction,
EarthquakeBuildingFunction,
VolcanoPointBuildingFunction,
VolcanoPolygonBuildingFunction
]
message = 'Expecting \n%s.\n\nGot \n%s \n instead' % (
'\n'.join([x.__name__ for x in expected]),
'\n'.join([x.__name__ for x in impact_functions]))
self.assertItemsEqual(expected, impact_functions, message)
# Full metadata
exposure_metadata = {
'layer_mode': layer_mode_classified,
'layer_geometry': layer_geometry_polygon,
'exposure': exposure_structure,
# 'exposure_unit': []
}
registry = Registry()
impact_functions = registry.filter_by_exposure(
registry.impact_functions, exposure_metadata)
expected = [
FloodPolygonBuildingFunction,
FloodRasterBuildingFunction,
TsunamiRasterBuildingFunction,
ClassifiedRasterHazardBuildingFunction,
ClassifiedPolygonHazardBuildingFunction,
EarthquakeBuildingFunction,
VolcanoPointBuildingFunction,
VolcanoPolygonBuildingFunction,
]
message = 'Expecting \n%s.\n\nGot \n%s instead' % (
'\n'.join([x.__name__ for x in expected]),
'\n'.join([x.__name__ for x in impact_functions]))
self.assertItemsEqual(expected, impact_functions, message)
示例2: RasterReclassifyDialog
# 需要导入模块: from safe.impact_functions.registry import Registry [as 别名]
# 或者: from safe.impact_functions.registry.Registry import filter_by_exposure [as 别名]
class RasterReclassifyDialog(QDialog, FORM_CLASS):
def __init__(self, parent=None, iface=None):
"""Constructor for Raster Reclassification to Vector Polygon.
.. versionadded: 3.4
:param parent: Optional widget to use as parent
:type parent: QWidget
:param iface: An instance of QGisInterface
:type iface: QGisInterface
"""
QDialog.__init__(self, parent)
self.parent = parent
self.setupUi(self)
self.setWindowTitle(self.tr('Raster Reclassification'))
self.iface = iface
self.if_registry = Registry()
self.keyword_io = KeywordIO()
# populate raster input
self.cbo_raster_input.clear()
registry = QgsMapLayerRegistry.instance()
# MapLayers returns a QMap<QString id, QgsMapLayer layer>
layers = registry.mapLayers().values()
for layer in layers:
try:
name = layer.name()
source = layer.id()
layer_purpose = self.keyword_io.read_keywords(
layer, 'layer_purpose')
if (isinstance(layer, QgsRasterLayer) and
layer_purpose == 'hazard'):
add_ordered_combo_item(
self.cbo_raster_input, self.tr(name), source)
except Exception as e:
raise e
# self.input_list_parameter = InputListParameter()
# self.input_list_parameter.name = 'Thresholds'
# self.input_list_parameter.description = (
# 'List of thresholds of values used in reclassification.')
# self.input_list_parameter.help_text = 'list of thresholds used'
# self.input_list_parameter.maximum_item_count = 100
# self.input_list_parameter.minimum_item_count = 1
# self.input_list_parameter.element_type = float
# self.input_list_parameter.value = [0.0, 1.0]
# self.input_list_parameter.ordering = \
# InputListParameter.AscendingOrder
# self.thresholds_widget = InputListParameterWidget(
# self.input_list_parameter)
# self.threshold_editor.layout().addWidget(self.thresholds_widget)
# Set up context help
self.help_button = self.button_box.button(QtGui.QDialogButtonBox.Help)
self.ok_button = self.button_box.button(QtGui.QDialogButtonBox.Ok)
# self.cancel_button = self.button_box.button(
# QtGui.QDialogButtonBox.Cancel)
self.button_box.accepted.connect(self.accept)
self.button_box.rejected.connect(self.reject)
# Allow toggling the help button
self.help_button.setCheckable(True)
self.help_button.toggled.connect(self.help_toggled)
self.main_stacked_widget.setCurrentIndex(1)
# adapt layer changed
self.cbo_raster_input.currentIndexChanged.connect(self.raster_changed)
self.raster_changed(self.cbo_raster_input.currentIndex())
# noinspection PyPep8Naming
@pyqtSlot(int)
def raster_changed(self, index):
"""Executed when raster is changed
:param index: index of the selected raster
:return:
"""
registry = QgsMapLayerRegistry.instance()
layer_id = self.cbo_raster_input.itemData(
index, QtCore.Qt.UserRole)
layer = registry.mapLayer(layer_id)
layer_purpose = self.keyword_io.read_keywords(layer, 'layer_purpose')
if layer_purpose == 'hazard':
impact_function = self.if_registry.filter_by_hazard(
self.if_registry.impact_functions,
self.keyword_io.read_keywords(layer)
)
elif layer_purpose == 'exposure':
impact_function = self.if_registry.filter_by_exposure(
self.if_registry.impact_functions,
self.keyword_io.read_keywords(layer)
)
else:
impact_function = []
#.........这里部分代码省略.........