forked from timlinux/impact_function_registry
/
main.py
77 lines (65 loc) · 2.09 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# coding=utf-8
"""Main file for showing off impact function registry."""
__author__ = 'Tim Sutton'
__project_name = 'impact_function_registry'
__filename = 'main'
__date__ = '8/26/14'
__copyright__ = 'tim@kartoza.com'
__doc__ = ''
import sys
print sys.path
from registry import Registry
from impact_functions.flood_on_buildings import FloodImpactFunction
from metadata import (
hazard_tsunami,
exposure_structure,
unit_metres_depth,
unit_building_type_type,
layer_vector_polygon,
unit_wetdry
)
def main():
"""Main function."""
registry = Registry()
registry.register(FloodImpactFunction)
registry.list()
function = registry.get('FloodImpactFunction')
function.extent = [10, 10, 20, 20]
function.extent_crs = [4326]
function_parameters = function.parameters()
for x in function_parameters:
print '--', x.name, x.value
print 'Change value of target field to FLOODED:'
function_parameters[0].value = 'FLOODED'
function_parameters = function.parameters()
for x in function_parameters:
print '--', x.name, x.value
function.run()
hazard_keywords = {
'subcategory': hazard_tsunami,
'units': unit_wetdry,
'layer_constraints': layer_vector_polygon
}
exposure_keywords = {
'subcategory': exposure_structure,
'units': unit_building_type_type,
'layer_constraints': layer_vector_polygon
}
impact_functions = registry.filter(hazard_keywords, exposure_keywords)
print len(impact_functions)
print [x.metadata()['name'] for x in impact_functions]
hazard_keywords = {
'subcategory': hazard_tsunami,
'units': unit_metres_depth,
'layer_constraints': layer_vector_polygon
}
exposure_keywords = {
'subcategory': exposure_structure,
'units': unit_building_type_type,
'layer_constraints': layer_vector_polygon
}
impact_functions = registry.filter(hazard_keywords, exposure_keywords)
print len(impact_functions)
print [x.metadata()['name'] for x in impact_functions]
if __name__ == '__main__':
main()