-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenerate AAL and Claims Relationship.py
84 lines (73 loc) · 4.52 KB
/
Generate AAL and Claims Relationship.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
78
79
80
81
82
83
84
# -*- coding: utf-8 -*-
"""Generated by ArcGIS ModelBuilder on: 2019-07-18 12:26:57
All ModelBuilder functionality may not be exported. Edits may be required for equivalency with the original model.
"""
import arcpy
# To allow overwriting the outputs change the overwrite option to true.
arcpy.env.overwriteOutput = True
# C:\Users\jmatney\Documents\ArcGIS\Projects\StarrII\LA-AR\Model.gdb
arcpy.env.workspace = arcpy.GetParameterAsText(0)
# Script parameters
Census_Block = arcpy.GetParameterAsText(1) # or "Block"
Boundary_Polygon = arcpy.GetParameterAsText(2) # or "MSEast_Projected"
Claims_Points = arcpy.GetParameterAsText(3) # or "MSEast_Claims"
AAL_Points = arcpy.GetParameterAsText(4) # or "MSEast_Uniform"
# Local variables:
Census_Block_Clip = r"Census_Block_Clip"
Block_AAL = r"Block_SpJoin_AAL"
Block_AAL_Claims = r"Block_SpJoin_AALClaims"
Results = r"Results"
# Process: Clip Blocks to Boundary Polygon
arcpy.Clip_analysis(in_features=Census_Block,
clip_features=Boundary_Polygon,
out_feature_class=r"memory\Census_Block_Clip",
cluster_tolerance="")
# Process: Spatial Join AAL to Census Blocks
arcpy.SpatialJoin_analysis(target_features=r"memory\Census_Block_Clip",
join_features=AAL_Points,
out_feature_class=r"memory\Block_AAL",
join_operation="JOIN_ONE_TO_ONE",
join_type="KEEP_ALL",
field_mapping=r"NAME NAME true true false 11 Text 0 0,First,#,Census_Block_Clip,NAME,0,11;" \
"PAAL_Re PAAL_Re true true false 8 Double 0 0,Sum,#,MSEast_Uniform,PAAL_Re,-1,-1;" \
"FAAL FAAL true true false 8 Double 0 0,Sum,#,MSEast_Uniform,FAAL,-1,-1",
match_option="CONTAINS", search_radius="", distance_field_name="")
# Process: Spatial Join Claims to Census Blocks
arcpy.SpatialJoin_analysis(target_features=r"memory\Block_AAL",
join_features=Claims_Points,
out_feature_class=Results,
join_operation="JOIN_ONE_TO_ONE",
join_type="KEEP_ALL",
field_mapping=r"NAME NAME true true false 11 Text 0 0,First,#,Block_SpJoin_AAL,NAME,0,11;"
r"FAAL FAAL true true false 8 Double 0 0,First,#,Block_SpJoin_AAL,FAAL,-1,-1;"
r"PAAL_Re PAAL_Re true true false 8 Double 0 0,First,#,Block_SpJoin_AAL,PAAL_Re,-1,-1;"
r"SL_ClmCount SL_ClmCount true true false 2 Short 0 0,Sum,#,MSEast_Claims,SL_ClmCount,-1,-1;"
r"SL_TPay SL_TPay true true false 8 Double 0 0,Sum,#,MSEast_Claims,SL_TPay,-1,-1",
match_option="CONTAINS", search_radius="", distance_field_name="")
# Process: Add Total AAL Field
arcpy.AddField_management(in_table=Results,
field_name="Total_AAL",
field_type="FLOAT",
field_precision="",
field_scale="",
field_length="",
field_alias="Total AAL",
field_is_nullable="NULLABLE",
field_is_required="NON_REQUIRED",
field_domain="")
# Process: Delete TARGET_FID and Join Count Fields
arcpy.DeleteField_management(in_table=Results, drop_field="Join_Count;TARGET_FID")
# Process: Calculate Total AAL Field
arcpy.management.CalculateField(in_table=Results,
field="Total_AAL",
expression="total_aal(!FAAL!,!PAAL_Re!)",
expression_type="PYTHON3",
code_block="def total_aal(field1, field2):\n"
" if(field1 == None and field2 == None):\n "
" return None\n else:\n return field1 + field2")
arcpy.AlterField_management(in_table=Results,
field="SL_ClmCount",
new_field_alias="Structure Level Claim Count")
arcpy.AlterField_management(in_table=Results,
field="SL_TPay",
new_field_alias="Structure Level Total Pay")