-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculate_CEQA_Requirements_and_Exemptions_Statewide.py
1300 lines (1048 loc) · 66.5 KB
/
Calculate_CEQA_Requirements_and_Exemptions_Statewide.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
########################################################################################################################
# Script: Calculate CEQA Requirements and Exemptions (Statewide Implementation)
# Author: Mike Gough
# Date created: 05/04/2023
# Python Version: 3.x (ArcGIS Pro)/(Should work in 2.7 (ArcGIS Desktop))
# Description: This script calculates CEQA requirements & exemptions for parcels in the state of California.
# Requirement calculations are based on the spatial relationships each parcel has with other spatial datasets
# pertaining to the requirement. For example, requirement 2.3 is "within city limits" -- This script will assess
# whether or not a parcel meets this requirement based on whether or not the center of the parcel falls within
# the extent of a city boundary.
# Exemptions are based on requirements. In order to meet an exemption, a parcel must meet one or more requirements.
# The list of requirements and the list of exemptions (along with their dependent requirements) are defined by the user
# in the requirements dictionary and the exemptions dictionary, respectively.
# This script adds a field for every requirement and exemption and calculates a value to indicate whether or not each
# parcel meets the requirement or exemption.
# A calculated value of 1 indicates that the parcel meets the requirement or exemption.
# A calculated value of 0 indicates that the parcel does not meet the requirement or exemption.
# A NULL value indicates that there is not enough information to calculate a 1 or a 0.
# In most cases, this is due to a lack of data representing the phenomenon being assessed.
# The list of counties and the requirements for which they are missing data is defined by the user
# (refer to the requirements_with_no_data dictionary).
# Each requirement is calculated either by a python function, or a call to an external ArcGIS Model.
# The logic for each is defined by a set of methods in the RequirementFunctions class.
# Use the function calls at the bottom of this script to choose which operations this script should perform.
# RUNTIME DURATION:
# ArcGIS Desktop: ~ 1 week (all counties and requirements)
# ArcGIS Pro: 3 Days 20 hours (all counties and requirements without deleting requirements & exemptions tables).
# ~5 days if parcels change and those need to be recreated.
# ArcGIS Pro: 1 requirement (9.5) ~17 hours.
# NOTE If running from ArcGIS Desktop, the script begins to slow down over time. To increase the speed, run 50% of
# counties at a time, or kill the script after it has completed a county and restart it on the remaining counties.
# If processing requirements for all counties (any number of requirements), manually delete the requirements table
# first since all records in this table will be deleted. This will increase performance.
# Similarly, if processing exemptions for all counties (any number of requirements), manually delete the exemptions
# table first since all records in this table will be deleted. This will increase performance.
# Indicating the parcel feature classes to process:
# Use "*" to process all counties, or create a list of counties to process. Examples:
# input_parcels_fc_list = "*"
# input_parcels_fc_list = ["SANBENITO_Parcels", "SANBERNARDINO_Parcels"].
# For one county, also use a list. For example, ["SANBENITO_Parcels"]
# Indicate the requirements to process.
# Use "*" to process all requirements, or create a list of requirements to process. Examples:
# requirements_to_process = "*"
# requirements_to_process = ["3.10", "2.6"].
# For one requirement, also use a list. For example, ["3.10"]
########################################################################################################################
import os
import arcpy
import datetime
arcpy.env.overwriteOutput = True
arcpy.CheckOutExtension("Spatial")
appdata_dir = os.environ.get("APPDATA")
favorites_dir = appdata_dir + "\Esri\ArcGISPro\Favorites"
########################################### CEQA Phase 2.0 Runs ########################################################
# 04/03/23 Run #1
# Notes: Uses parcels data from CEQA version 1.0 (DigiMap/Lightbox). Updated data for 3.6 and 3.8.
requirements_to_process = ["3.6", "3.8"]
input_parcels_fc_list = "*"
# 05/04/23 Run #2
# Notes: Uses new parcels data (Statewide ec9dc5c9-e485-11ed-8586-c45ab1d6625e, separated into counties).
requirements_to_process = "*"
input_parcels_fc_list = "*"
# 05/18/23 Run #3
# Notes: Updates to Specific Plan, VMT, and HQTC data (from Justin Heyerdahl).
requirements_to_process = ["2.6", "3.2", "3.4", "3.5", "3.6", "3.8"]
input_parcels_fc_list = "*"
# 05/23/23 Run #4
# Notes: Updates to VMT data and new path to specific plan data (from Justin Heyerdahl).
requirements_to_process = ["2.6", "3.6", "3.8"]
input_parcels_fc_list = "*"
# 10/06/23 Run #5
# Notes: Several updates to the transportation and location requirements.
requirements_to_process = "*"
input_parcels_fc_list = "*"
# 11/30/2023 Run #6
# Notes: Re-run using updated version of the Statewide Toolbox (Statewide.tbx). The old Statewide_2023_v2_1.tbx was used for the previous run.
#requirements_to_process = ["3.1", "3.2", "3.4", "3.5", "8.1", "8.2"]
#input_parcels_fc_list = "*"
# 01/22/2024 Run #7 (v5.3)
# Notes: Data updates. Updates to NULL data list.
#requirements_to_process = ["2.6", "3.1", "3.2", "3.3", "3.4", "3.5", "9.2"]
#input_parcels_fc_list = "*"
# 01/23/2024 Run #8 (v5.4)
#requirements_to_process = ["9.5"]
#input_parcels_fc_list = "*"
# 02/02/2024 Run #9 (v5.5)
# Duration: 1 day, 0:23:23.437617
# Rerun with 1m landslide raster.
#requirements_to_process = ["9.5"]
#input_parcels_fc_list = "*"
# 02/26/2024 Run #10 (v5.6)
# Duration: 4:38:20.836241 (new workstation)
# Updates to NULL list and
requirements_to_process = ["2.6"]
input_parcels_fc_list = "*"
# NOTE: If parcels change, the geodatabases should be deleted as the county parcel feature classes can be recreated.
# If this is not performed, the old county parcels data copies will be used and the tables will be incorrect.
########################################################################################################################
# Workspaces
input_parcels_gdb = r"P:\Projects3\CEQA_Site_Check_Version_2_0_2023_mike_gough\Tasks\CEQA_Parcel_Exemptions\Data\Inputs\Parcels\Parcels_Prepared_By_County.gdb"
output_gdb_data_basin = r"P:\Projects3\CEQA_Site_Check_Version_2_0_2023_mike_gough\Tasks\CEQA_Parcel_Exemptions\Data\Outputs\Outputs_for_DataBasin.gdb"
output_gdb_dev_team = r'P:\Projects3\CEQA_Site_Check_Version_2_0_2023_mike_gough\Tasks\CEQA_Parcel_Exemptions\Data\Outputs\Outputs_for_DevTeam.gdb'
intermediate_ws = "P:\Projects3\CEQA_Site_Check_Version_2_0_2023_mike_gough\Tasks\CEQA_Parcel_Exemptions\Data\Intermediate\Intermediate.gdb"
scratch_ws = "P:\Projects3\CEQA_Site_Check_Version_2_0_2023_mike_gough\Tasks\CEQA_Parcel_Exemptions\Data\Intermediate\Scratch\Scratch.gdb"
# Toolbox containing models for processing additional requirements (from Charlotte Smith).
# Updated Toolbox for version 2.0. Provided by Charlotte on 3/08/2023
#statewide_toolbox = r"\\loxodonta\GIS\Projects\CEQA_Site_Check_Version_2_0_2023\Workspaces\CEQA_Site_Check_Version_2_0_2023_charlotte_smith\Tasks\CEQA_revisions_2023_03\Tools\Models\Statewide_2023_v2_0.tbx"
#statewide_toolbox = r"\\loxodonta\GIS\Projects\CEQA_Site_Check_Version_2_0_2023\Workspaces\CEQA_Site_Check_Version_2_0_2023_justin_heyerdahl\Tools\Models\Statewide_2023_v2_1.tbx"
statewide_toolbox = r"\\loxodonta\GIS\Projects\CEQA_Site_Check_Version_2_0_2023\Workspaces\CEQA_Site_Check_Version_2_0_2023_justin_heyerdahl\Tools\Models\Statewide.tbx"
statewide_toolbox_alias = "Statewide"
arcpy.ImportToolbox(statewide_toolbox, statewide_toolbox_alias)
output_requirements_table_name = "requirements"
output_exemptions_table_name = "exemptions"
# External Join Table (Not used in version 1.0)
join_requirements_table = r"\\loxodonta\GIS\Projects\CDT-CEQA_California_2019\Workspaces\CDT-CEQA_California_2019_kai_foster\Tasks\General_Tasks\Data\Inputs\Inputs.gdb\Sacramento_Pilot\Sacramento_Parcels_MG"
# Fields from the original parcels feature class to keep in the output parcels for Data Basin & Dev.
#original_fields_to_keep = [ "PARCEL_APN", "FIPS_CODE", county_name_field, "TAXAPN", "SITE_ADDR", "SITE_CITY", "SITE_STATE", "SITE_ZIP", "LATITUDE", "LONGITUDE", "CENSUS_TRACT", "CENSUS_BLOCK_GROUP", "Zoning", "LOT_SIZE_AREA", "LOT_SIZE_AREA_UNIT", parcel_id_field ]
original_fields_to_keep = [
"fips",
"county_name",
"fips_apn",
"apn",
"apn_d",
"s_city",
"s_addr_d",
"cbi_parcel_id_fips_apn_oid",
"state_name",
"latitude",
"longitude",
"zip_code",
]
# The field in the parcels data that uniquely identifies each parcel.
parcel_id_field = "cbi_parcel_id_fips_apn_oid"
# The field in the parcels data containing the county name.
county_name_field = "county_name"
# Datasets used in calculating requirements:
######################################## CEQA version 1.0 2021 Cities ##################################################
# 0.1, 2.1
#urbanized_area_prc_21071_fc = r"P:\Projects3\CEQA_Site_Check_Version_1_0_2021_mike_gough\Tasks\CEQA_Parcel_Exemptions\Data\Intermediate\Intermediate.gdb\urbanized_area_prc_21071_v1_0"
# 2.2
#urban_area_prc_21094_5_fc = r"P:\Projects3\CEQA_Site_Check_Version_1_0_2021_mike_gough\Tasks\CEQA_Parcel_Exemptions\Data\Intermediate\Intermediate.gdb\urban_area_prc_21094_5_v1_0"
# 0.1, 2.3
#city_boundaries_fc = r"\\loxodonta\GIS\Source_Data\boundaries\state\CA\California_Incorporated_Cities\incorp21_2.shp"
#unincorporated_islands = r"P:\Projects3\CEQA_Site_Check_Version_1_0_2021_mike_gough\Tasks\CEQA_Parcel_Exemptions\Data\Intermediate\Intermediate.gdb\Unincorporated_Islands_CALFIRE_2021_with_Population_Dissolve" #2.2
# 2.4 # Select within incorporated cities, then switch the selection
#incorporated_place_fc = r"\\loxodonta\GIS\Source_Data\boundaries\state\CA\California_Incorporated_Cities\incorp21_2.shp"
######################################## CEQA version 2.0 2023 Cities ##################################################
# 0.1, 2.1
urbanized_area_prc_21071_fc = r"P:\Projects3\CEQA_Site_Check_Version_2_0_2023_mike_gough\Tasks\CEQA_Parcel_Exemptions\Data\Intermediate\Intermediate.gdb\urbanized_area_prc_21071_v2_0"
# 2.2
urban_area_prc_21094_5_fc = r"P:\Projects3\CEQA_Site_Check_Version_2_0_2023_mike_gough\Tasks\CEQA_Parcel_Exemptions\Data\Intermediate\Intermediate.gdb\urban_area_prc_21094_5_v2_0"
# 0.1, 2.3
city_boundaries_fc = r"P:\Projects3\CEQA_Site_Check_Version_2_0_2023_mike_gough\Tasks\CEQA_Parcel_Exemptions\Data\Source\California_Incorporated_Cities_2023\_ags_dataB9A2584E098B4442A45D05AF49BC3B0C.gdb\incorp23_1"
unincorporated_islands = r"P:\Projects3\CEQA_Site_Check_Version_2_0_2023_mike_gough\Tasks\CEQA_Parcel_Exemptions\Data\Intermediate\Intermediate.gdb\Unincorporated_Islands_CALFIRE_2023_with_Population_Dissolve" #2.2
# 2.4 # Select within incorporated cities, then switch the selection
incorporated_place_fc = r"P:\Projects3\CEQA_Site_Check_Version_2_0_2023_mike_gough\Tasks\CEQA_Parcel_Exemptions\Data\Source\California_Incorporated_Cities_2023\_ags_dataB9A2584E098B4442A45D05AF49BC3B0C.gdb\incorp23_1"
########################################################################################################################
# 2.5
mpo_boundary_dissolve_fc = r"P:\Projects3\CDT-CEQA_California_2019_mike_gough\Tasks\CEQA_Parcel_Exemptions\Data\Intermediate\Intermediate.gdb\MPO_boundaries_dissolve"
# 2.7
#urbanized_area_urban_cluster_fc = r"P:\Projects3\CDT-CEQA_California_2019_mike_gough\Tasks\CEQA_Parcel_Exemptions\Data\Inputs\Inputs.gdb\CA_urbanized_area_urban_cluster"
urbanized_area_urban_cluster_fc = favorites_dir + r"\CBI Inputs.sde\cbiinputs.justin_heyerdahl.tl_2020_ca_uac20"
# 8.5
rare_threatened_or_endangered_fc = favorites_dir + r"\CBI Intermediate.sde\cbiintermediate.mike_gough.CA_Rare_Threatened_or_Endangered_Erase_Impervious_del_fields_23"
# 8.6
prime_farmlands_fc = r"\\loxodonta\gis\Source_Data\farming\state\CA\FMMP\2018_2016_from_Data_Basin\California - Farmland Mapping and Monitoring Program (FMMP), 2018_2016\data\commondata\2018_in_progress_fmmp_shape_files\CA_FMMP_2018_state.shp"
# 9.3
wildfire_hazard_fc = r"\\loxodonta\gis\Source_Data\environment\state\CA\Fire_Hazard_Severity_Zones_2017\fhszs06_3.shp"
# 9.4
flood_plain_fc = r"P:\Projects3\CDT-CEQA_California_2019_mike_gough\Tasks\CEQA_Parcel_Exemptions\Data\Inputs\Inputs.gdb\CA_100_Year_FEMA_Floodplain"
# 9.5
landslide_area_percent_threshold = 20 # The percent of the parcel that must have a very high landslide susceptibility value.
#landslide_hazard_raster = r"P:\Projects3\CDT-CEQA_California_2019_mike_gough\Tasks\CEQA_Parcel_Exemptions\Data\Inputs\Inputs.gdb\CA_ms58_very_high_landslide_susceptibility_1s"
#landslide_hazard_raster = r"\\loxodonta\gis\Projects\CEQA_Site_Check_Version_2_0_2023\Workspaces\CEQA_Site_Check_Version_2_0_2023_justin_heyerdahl\Data\Rasters\req9_5_LandslideHazard_20240118.tif"
# New 1m version (02/02/2024)
landslide_hazard_raster = r"\\loxodonta\gis\Projects\CEQA_Site_Check_Version_2_0_2023\Workspaces\CEQA_Site_Check_Version_2_0_2023_justin_heyerdahl\Data\Rasters\req9_5_LandslideHazard_1m_20240118.tif"
# 9.6
state_conservancy_fc = r"P:\Projects3\CDT-CEQA_California_2019_mike_gough\Tasks\CEQA_Parcel_Exemptions\Data\Inputs\Inputs.gdb\CA_State_Conservancy_ds1754"
# 9.7
local_coastal_zone_fc = r"P:\Projects3\CDT-CEQA_California_2019_mike_gough\Tasks\CEQA_Parcel_Exemptions\Data\Inputs\Inputs.gdb\CA_Coastal_Zone_Boundary_ds990"
# 9.8
protected_area_mask_fc = r"P:\Projects3\CDT-CEQA_California_2019_mike_gough\Tasks\CEQA_Parcel_Exemptions\Data\Inputs\Inputs.gdb\CA_protected_area_mask"
# Requirements that begin with 0 aren't applicable to any exemptions
requirements = {
"0.1": "urbanized_area_prc_21071_unincorporated_0_1",
# Location Requirements
"2.1": "urbanized_area_prc_21071_2_1",
"2.2": "urban_area_prc_21094_2_2",
"2.3": "within_city_limits_2_3",
"2.4": "unincorporated_2_4",
"2.5": "within_mpo_2_5",
"2.6": "covered_by_a_specific_plan_2_6",
"2.7": "urbanized_area_or_urban_cluster_2_7",
# Transit Proximity Requirements
"3.1": "within_half_mile_major_transit_stop_3_1",
"3.2": "within_quarter_mile_transit_corridor_3_2",
"3.3": "transit_priority_area_3_3",
"3.4": "within_half_mile_transit_corridor_3_4",
"3.5": "within_half_mile_stop_transit_corridor_3_5",
"3.6": "low_vmt_15_percent_below_regional_3_6",
#"3.7": "low_vmt_15_percent_below_city_3_7", # 3.7 removed from the tool according to spreadsheet
"3.8": "low_vehicle_travel_area_3_8",
"3.9": "planned_rtp_half_mile_major_transit_stop_3_9",
"3.10": "planned_rtip_half_mile_major_transit_stop_3_10",
"3.11": "planned_rtip_half_mile_stop_hqtc_3_11",
"3.12": "planned_rtp_half_mile_hqtc_3_12",
"3.13": "planned_rtp_quarter_mile_hqtc_3_13",
"3.14": "within_half_mile_rail_transit_station_or_ferry_terminal_3_14",
# Environmental Limitations
"8.1": "wetlands_8_1",
"8.2": "riparian_areas_8_2",
"8.3": "special_habitats_8_3",
#"8.4": "species_of_concern_8_4",
"8.5": "rare_threatened_endangered_sp_8_5",
"8.6": "prime_farmlands_or_farmlands_of_statewide_importance_8_6",
# Hazards
#"9.1": "sea_level_rise_9_1",
"9.2": "earthquake_hazard_zone_9_2",
"9.3": "wildfire_hazard_9_3",
"9.4": "flood_plain_9_4",
"9.5": "landslide_hazard_9_5",
"9.6": "state_conservancy_9_6",
"9.7": "local_coastal_zone_9_7",
"9.8": "protected_area_mask_9_8",
}
# If county is missing data for a requirement (as indicated below), a field will be added to the county for that requirement with null values in it.
# 07/24/2020 Added in sanbenito and santacruz as those were missing from the NoData list.
# 01/22/2024 Updated for applicable reqs 2.6, 3.3, and 9.5 (Justin H).
# 02/26/2024 Updated for applicable reqs 2.6 (Justin H).
requirements_with_no_data = {
# ALL COUNTIES
"ALL_COUNTIES": [],
#AMBAG
"monterey":["2.6","3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
"sanbenito":["2.6","3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
"santacruz":["3.10","3.9","3.11","3.12","3.13","3.14","9.5"],
# BCAG
"butte":["3.10","3.14","9.5"],
#FCOG
"fresno":["3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
#KCAG
"kings":["2.6","3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
# KCOG
"kern": ["3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
#MCAG
"merced":["3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
#MCTC
"madera":["2.6","3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
# MTC
"alameda": ["3.10","3.11","3.12","3.13", "3.14"],
"contracosta": ["3.10","3.11","3.12","3.13","3.14"],
"marin": ["3.10","3.11","3.12","3.13","3.14","9.5"],
"napa": ["3.10","3.11","3.12","3.13","3.14","9.5"],
"sanfrancisco": ["2.6","3.10","3.11","3.12","3.13","3.14"],
"sanmateo": ["3.10","3.11","3.12","3.13","3.14"],
"santaclara": ["3.10","3.11","3.12","3.13","3.14"],
"solano": ["3.10","3.11","3.12","3.13","3.14","9.5"],
"sonoma": ["3.10","3.11","3.12","3.13","3.14","9.5"],
# SACOG
"eldorado": ["9.5"],
"placer": ["9.5"],
"sacramento": ["9.5"],
"sutter": ["9.5"],
"yolo": ["9.5"],
"yuba": ["9.5"],
# SANDAG
"sandiego": ["3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
#SBCAG
"santabarbara":["3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
# SCAG
"imperial": ["3.10","3.14","9.5"],
"losangeles": ["3.10","3.14"],
"orange": ["3.10","3.14"],
"riverside": ["3.10","3.14"],
"sanbernardino": ["3.10","3.14"],
"ventura": ["3.10","3.14"],
#SJCOG
"sanjoaquin":["2.6","3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
#SLOCOG
"sanluisobispo":["3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
#SRTA
"shasta":["3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
#StanCOG
"stanislaus":["3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
#TCAG
"tulare": ["2.6","3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
# OTHER COUNTIES
"alpine": ["2.6","3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
"amador": ["2.6","3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
"calaveras": ["2.6","3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
"colusa": ["2.6","3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
"delnorte": ["2.6","3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
"glenn": ["2.6","3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
"humboldt": ["2.6","3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
"inyo": ["2.6","3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
"lake": ["2.6","3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
"lassen": ["2.6","3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
"mariposa": ["2.6","3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
"mendocino": ["3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
"modoc": ["2.6","3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
"mono": ["3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
"nevada": ["2.6","3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
"plumas": ["2.6","3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
"sierra": ["2.6","3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
"siskiyou": ["2.6","3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
"tehama": ["2.6","3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
"trinity": ["2.6","3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
"tuolumne": ["2.6","3.9","3.10","3.11","3.12","3.13","3.14","9.5"],
}
# 04/06/2023 March 6 2023 version of Criteria Spreadsheet. Requirement 3.6 was added back in.
exemptions = {
"21159.24": ["2.1", "3.1", "8.1", "8.2", "8.3", "8.5", "9.2", "9.3", "9.4", "9.5", "9.6"],
"21155.1": ["2.5", ["3.2", "3.13", "3.14"], "8.1", "8.2", "8.3", "8.5", "9.2", "9.3", "9.4", "9.5"],
"21155.2": ["2.5", ["3.1", "3.4", "3.9", "3.12"]],
"21155.4": ["2.5", "2.6", "3.3"],
"21094.5": ["2.2", ["3.1", "3.5", "3.8", "3.10", "3.11"]],
"65457": ["2.6"],
# "15183": [""], # No Requirements
"15332": ["2.3", "8.5"],
"21159.25": ["2.4", "2.7", "8.5"],
# "15303": ["2.1"], # No Requirements
"21099": ["3.3"],
"21159.28": ["2.5"],
#"15064.3": [["3.1", "3.5"]] # Remove 3.6 and 3.7
"15064.3": [["3.1", "3.5", "3.6"]] # Add 3.6 back in. We have 3.6 for CEQA Site Check version 2.0
}
# DATA PROCESSING FUNCTIONS ############################################################################################
if input_parcels_fc_list == "*":
input("All parcels will be processed. Deleting the requirements and exemptions tables will increase performance." +
" It is recommended that you do that now (after backing up metadata if needed). " +
" When you're ready, push any key to continue...")
def copy_parcels_fc(input_parcels_fc, output_parcels_fc):
""" Copies the original parcels feature class with only a subset of the original fields.
Used to create both the Data Basin output which will be populated with requirements and exemptions,
as well as the Parcels Feature Class for the Dev Team without the requirements and exemptions fields.
"""
print("Copying the original parcels Feature Class with only the user specified fields to keep...")
print("From: " + input_parcels_fc)
print("To: " + output_parcels_fc)
# create an empty field mapping object
mapS = arcpy.FieldMappings()
# for each field, create an individual field map, and add it to the field mapping object
for field in original_fields_to_keep:
map = arcpy.FieldMap()
map.addInputField(input_parcels_fc, field)
mapS.addFieldMap(map)
output_gdb = os.path.dirname(output_parcels_fc)
output_fc_name = os.path.basename(output_parcels_fc)
# Create the empty parcels feature class with the subset of original fields to keep
arcpy.FeatureClassToFeatureClass_conversion(
in_features=input_parcels_fc,
out_path=output_gdb, out_name=output_fc_name, where_clause="",
field_mapping=mapS,
config_keyword="")
def delete_county_rows_from_dev_table(output_parcels_fc, table):
# Get the name of the county that appears in the the attribute table.
output_parcels_fc_layer = arcpy.MakeFeatureLayer_management(output_parcels_fc)
arcpy.SelectLayerByAttribute_management(output_parcels_fc_layer, "NEW_SELECTION", "OBJECTID = 1")
with arcpy.da.SearchCursor(output_parcels_fc_layer, county_name_field) as sc:
for row in sc:
county_name_in_att_table = row[0]
print("\nChecking to see if this county (%s) has rows in the dev table (%s)." % (county_name_in_att_table, table))
temp_table_view = "temp_table_view"
arcpy.MakeTableView_management(table, temp_table_view)
expression = county_name_field + " = '%s'" % county_name_in_att_table
# Execute SelectLayerByAttribute to see if there are any rows in the requirements table with this county name.
arcpy.SelectLayerByAttribute_management(temp_table_view, "NEW_SELECTION", expression)
if int(arcpy.GetCount_management(temp_table_view)[0]) > 0:
print("There were rows in the dev team table for this county (%s) from a previous run. Deleting..." % county_name_in_att_table)
with arcpy.da.UpdateCursor(table, county_name_field) as uc:
for row in uc:
if row[0] == county_name_in_att_table:
uc.deleteRow()
def calculate_requirements(requirements_to_process=requirements.keys()):
county_name = os.path.basename(output_parcels_fc).split("_")[0].lower()
# Get a list of all the requirements that this county doesn't have data for.
requirements_with_no_data_this_county = requirements_with_no_data[county_name] + requirements_with_no_data["ALL_COUNTIES"]
# If the field for the no data requirement exists, calculate values as <null>.
# If the field does not exist, add it. The field will get set to <null> but default.
for requirement_with_no_data_this_county in requirements_with_no_data_this_county:
field_to_calc = requirements[requirement_with_no_data_this_county]
# If the field exists, recalculate as None, which is <null>
if field_to_calc in existing_output_fields:
arcpy.CalculateField_management(output_parcels_fc, field_to_calc, "None", "PYTHON")
# If the field does not exist, add it, and the values will get set to <null> by default.
else:
arcpy.AddField_management(output_parcels_fc, field_to_calc, "SHORT")
existing_output_fields.append(field_to_calc)
# Create an object that contains all the requirement processing functions.
requirement_functions = RequirementFunctions()
count = 1
requirement_count = str(len(requirements_to_process))
# For each requirement passed in...
for requirement in requirements_to_process:
print("\nProcessing requirement (" + str(count) + "/" + requirement_count + "): " + requirement + "\n")
field_to_calc = requirements[requirement]
if field_to_calc not in existing_output_fields:
print("Adding field: " + field_to_calc)
arcpy.AddField_management(output_parcels_fc, field_to_calc, "SHORT")
if requirement not in requirements_with_no_data_this_county:
print("Calling function to calculate values for this requirement...")
requirement_functions.do_command(requirement, output_parcels_fc, field_to_calc)
else:
print("No data for this requirement. A field has been added with <null> values.")
count += 1
# Call function to delete rows in the requirements table for this county if this county is in that table.
output_requirements_table_dev_team = output_gdb_dev_team + os.sep + output_requirements_table_name
if arcpy.Exists(output_requirements_table_dev_team):
delete_county_rows_from_dev_table(output_parcels_fc, output_requirements_table_dev_team)
class RequirementFunctions(object):
# ARCPY FUNCTIONS
def calc_requirement_0_1(self, output_parcels_fc, field_to_calc):
"""
0.1
Requirements that begin with 0 aren't applicable to any exemptions
Requirement Long Name: Urbanized Area Prc 21071 Unincorporated
Description: Select parcels that have their centers in the unincorporated islands of requirement 2.1. Yes = 1, No = 0
"""
output_parcels_layer = arcpy.MakeFeatureLayer_management(output_parcels_fc)
# Select Light Green areas, unincorporated areas meeting prc_21071
expression = "community_type = 'Unincorporated Island' AND urbanized_area_prc_21071 = 1"
urbanized_area_prc_21071_layer = arcpy.MakeFeatureLayer_management(urbanized_area_prc_21071_fc)
urbanized_area_prc_21071_unincorporated_layer = arcpy.SelectLayerByAttribute_management(urbanized_area_prc_21071_layer, "NEW_SELECTION", expression)
# Select parcels within the green areas
arcpy.SelectLayerByLocation_management(output_parcels_layer, "HAVE_THEIR_CENTER_IN", urbanized_area_prc_21071_unincorporated_layer)
arcpy.CalculateField_management(output_parcels_layer, field_to_calc, 1, "PYTHON")
arcpy.SelectLayerByAttribute_management(output_parcels_layer, "SWITCH_SELECTION")
arcpy.CalculateField_management(output_parcels_layer, field_to_calc, 0, "PYTHON")
def calc_requirement_2_1(self, output_parcels_fc, field_to_calc):
"""
2.1
Requirement Long Name: Urbanized Area PRC 21071
Description: Complicated, see description here:
https://leginfo.legislature.ca.gov/faces/codes_displaySection.xhtml?lawCode=PRC§ionNum=21071.
The basic idea is that we iterate over each parcel, pass the OID to a subfunction which determines whether or
not it meets the requirements in the the link above.
"""
output_parcels_layer = arcpy.MakeFeatureLayer_management(output_parcels_fc)
urbanized_area_prc_21071_layer = arcpy.MakeFeatureLayer_management(urbanized_area_prc_21071_fc)
query = "urbanized_area_prc_21071 = 1"
urbanized_area_prc_21071_layer_1s = arcpy.SelectLayerByAttribute_management(urbanized_area_prc_21071_layer, "NEW_SELECTION", query)
arcpy.SelectLayerByLocation_management(output_parcels_layer, "HAVE_THEIR_CENTER_IN", urbanized_area_prc_21071_layer_1s)
arcpy.CalculateField_management(output_parcels_layer, field_to_calc, 1, "PYTHON")
arcpy.SelectLayerByAttribute_management(output_parcels_layer, "SWITCH_SELECTION")
arcpy.CalculateField_management(output_parcels_layer, field_to_calc, 0, "PYTHON")
def calc_requirement_2_2(self, output_parcels_fc, field_to_calc):
"""
2.2
Requirement Long Name: Urban Area PRC 21094.5
Description: Select parcels WITHIN a city. Yes = 1, No = 0
If not in a city, check to see if WITHIN an unincorporated island
If within an unincorporated island, check to see if the unincorporated island it's in meets both of the following requirements:
(A) The population of the unincorporated area and the population of the surrounding incorporated cities equal a population of 100,000 or more.
(B) The population density of the unincorporated area is equal to, or greater than, the population density of the surrounding cities.
"""
output_parcels_layer = arcpy.MakeFeatureLayer_management(output_parcels_fc)
urban_area_prc_21094_5_layer = arcpy.MakeFeatureLayer_management(urban_area_prc_21094_5_fc)
query = "urban_area_prc_21094_5 = 1"
urban_area_prc_21094_5_layer_1s = arcpy.SelectLayerByAttribute_management(urban_area_prc_21094_5_layer, "NEW_SELECTION", query)
arcpy.SelectLayerByLocation_management(output_parcels_layer, "HAVE_THEIR_CENTER_IN", urban_area_prc_21094_5_layer_1s)
arcpy.CalculateField_management(output_parcels_layer, field_to_calc, 1, "PYTHON")
arcpy.SelectLayerByAttribute_management(output_parcels_layer, "SWITCH_SELECTION")
arcpy.CalculateField_management(output_parcels_layer, field_to_calc, 0, "PYTHON")
def calc_requirement_2_3(self, output_parcels_fc, field_to_calc):
"""
2.3
Requirement Long Name: Within City Limit
Description: Select parcels that have their centers in a city boundary. Yes = 1, No = 0
"""
output_parcels_layer = arcpy.MakeFeatureLayer_management(output_parcels_fc)
arcpy.SelectLayerByLocation_management(output_parcels_layer, "HAVE_THEIR_CENTER_IN", city_boundaries_fc)
arcpy.CalculateField_management(output_parcels_layer, field_to_calc, 1, "PYTHON")
arcpy.SelectLayerByAttribute_management(output_parcels_layer, "SWITCH_SELECTION")
arcpy.CalculateField_management(output_parcels_layer, field_to_calc, 0, "PYTHON")
def calc_requirement_2_4(self, output_parcels_fc, field_to_calc):
"""
2.4
Requirement Long Name: Unincorporated
If within an incorporated, calc 0, switch selection, calc 1.
Select parcels that HAVE THEIR CENTERS IN TIGER CENSUS incorporated areas. Yes = 0, No = 1
"""
output_parcels_layer = arcpy.MakeFeatureLayer_management(output_parcels_fc)
# Select parcels that HAVE THEIR CENTERS IN the incorporated area
arcpy.SelectLayerByLocation_management(output_parcels_layer, "HAVE_THEIR_CENTER_IN", incorporated_place_fc)
# Calculate 1's and 0's
arcpy.CalculateField_management(output_parcels_layer, field_to_calc, 0, "PYTHON")
arcpy.SelectLayerByAttribute_management(output_parcels_layer, "SWITCH_SELECTION")
arcpy.CalculateField_management(output_parcels_layer, field_to_calc, 1, "PYTHON")
def calc_requirement_2_5(self, output_parcels_fc, field_to_calc):
"""
2.5
Requirement Long Name: Within a Metropolitan Planning Organization boundary
Description: Select parcels that HAVE THEIR CENTERS IN an MPO boundary. Yes = 1, No = 0
"""
arcpy.MakeFeatureLayer_management(output_parcels_fc, "output_parcels_layer")
arcpy.SelectLayerByLocation_management("output_parcels_layer", "HAVE_THEIR_CENTER_IN", mpo_boundary_dissolve_fc)
arcpy.CalculateField_management("output_parcels_layer", field_to_calc, 1, "PYTHON")
arcpy.SelectLayerByAttribute_management("output_parcels_layer", "SWITCH_SELECTION")
arcpy.CalculateField_management("output_parcels_layer", field_to_calc, 0, "PYTHON")
def calc_requirement_2_7(self, output_parcels_fc, field_to_calc):
"""
2.7
Requirement Long Name: Urbanized area or urban cluster
Select parcels that HAVE THEIR CENTERS IN this layer.
"""
# Select parcels that HAVE THEIR CENTERS IN the unincorporated urbanized area or urban cluster
output_parcels_layer = arcpy.MakeFeatureLayer_management(output_parcels_fc)
arcpy.SelectLayerByLocation_management(output_parcels_layer, "HAVE_THEIR_CENTER_IN", urbanized_area_urban_cluster_fc)
# Calculate 1's and 0's
arcpy.CalculateField_management(output_parcels_layer, field_to_calc, 1, "PYTHON")
arcpy.SelectLayerByAttribute_management(output_parcels_layer, "SWITCH_SELECTION")
arcpy.CalculateField_management(output_parcels_layer, field_to_calc, 0, "PYTHON")
def calc_requirement_8_5(self, output_parcels_fc, field_to_calc):
"""
8.5
Requirement Long Name: Rare, Threatened, or Endangered Species
Description: Select parcels that intersect the Rare, Threatened, or Endangered Species Dataset. Yes = 0, No = 1
"""
output_parcels_layer = arcpy.MakeFeatureLayer_management(output_parcels_fc)
arcpy.SelectLayerByLocation_management(output_parcels_layer, "INTERSECT", rare_threatened_or_endangered_fc)
arcpy.CalculateField_management(output_parcels_layer, field_to_calc, 0, "PYTHON")
arcpy.SelectLayerByAttribute_management(output_parcels_layer, "SWITCH_SELECTION")
arcpy.CalculateField_management(output_parcels_layer, field_to_calc, 1, "PYTHON")
def calc_requirement_8_6(self, output_parcels_fc, field_to_calc):
"""
8.6
Requirement Long Name: Prime Farmlands or Farmlands of Statewide Importance
Description: Select parcels that intersect Prime farmlands or farmlands of statewide importance. Yes = 0, No = 1
"""
output_parcels_layer = arcpy.MakeFeatureLayer_management(output_parcels_fc)
prime_farmlands_layer = arcpy.MakeFeatureLayer_management(prime_farmlands_fc)
expression = "\"polygon_ty\" = 'P' or \"polygon_ty\" = 'S'"
farmland_types_selected = arcpy.SelectLayerByAttribute_management(prime_farmlands_layer, "NEW_SELECTION", expression)
arcpy.SelectLayerByLocation_management(output_parcels_layer, "INTERSECT", farmland_types_selected)
arcpy.CalculateField_management(output_parcels_layer, field_to_calc, 0, "PYTHON")
arcpy.SelectLayerByAttribute_management(output_parcels_layer, "SWITCH_SELECTION")
arcpy.CalculateField_management(output_parcels_layer, field_to_calc, 1, "PYTHON")
def calc_requirement_9_3(self, output_parcels_fc, field_to_calc):
"""
9.3
Requirement Long Name: Wildfire Hazard
Description: Select parcels that intersect the Wildfire Hazard Zones (Yes = 0, No = 1)
For version 1.0, the wildfire hazard layer is vector, so the calculation was changed from zonal stats to SBL.
"""
output_parcels_layer = arcpy.MakeFeatureLayer_management(output_parcels_fc)
wildfire_hazard_layer = arcpy.MakeFeatureLayer_management(wildfire_hazard_fc)
expression = "\"HAZ_CLASS\" = 'High' or \"HAZ_CLASS\" = 'Very High'"
wildfire_hazard_types_selected = arcpy.SelectLayerByAttribute_management(wildfire_hazard_layer, "NEW_SELECTION", expression)
arcpy.SelectLayerByLocation_management(output_parcels_layer, "INTERSECT", wildfire_hazard_types_selected)
arcpy.CalculateField_management(output_parcels_layer, field_to_calc, 0, "PYTHON")
arcpy.SelectLayerByAttribute_management(output_parcels_layer, "SWITCH_SELECTION")
arcpy.CalculateField_management(output_parcels_layer, field_to_calc, 1, "PYTHON")
def calc_requirement_9_4(self, output_parcels_fc, field_to_calc):
"""
9.4
Requirement Long Name: Flood Plain
Description: Select parcels that intersect the 100 Year Floodplain. Yes = 0, No = 1
Field Values defining the floodplain come from here: https://waterresources.saccounty.net/stormready/PublishingImages/100-year-floodplain-map-small.jpg
"""
output_parcels_layer = arcpy.MakeFeatureLayer_management(output_parcels_fc)
arcpy.SelectLayerByLocation_management(output_parcels_layer, "INTERSECT", flood_plain_fc)
arcpy.CalculateField_management(output_parcels_layer, field_to_calc, 0, "PYTHON")
arcpy.SelectLayerByAttribute_management(output_parcels_layer, "SWITCH_SELECTION")
arcpy.CalculateField_management(output_parcels_layer, field_to_calc, 1, "PYTHON")
def calc_requirement_9_5(self, output_parcels_fc, field_to_calc):
"""
9.5
Requirement Long Name: Landslide Hazard
Description: Select parcels that intersect the Landslide Hazard dataset. Yes = 0, No = 1
"""
# Get the resolution of the landslide hazard raster
landslide_hazard_raster_resolution = float(arcpy.GetRasterProperties_management(landslide_hazard_raster, "CELLSIZEX")[0])
print("Calculating Zonal Statistics...")
# Calculate zonal stats to get a count of the number of landslide hazard pixels within each parcel.
tmp_zonal_stats_table = scratch_ws + os.sep + "landslide_hazard_zonal_stats_subset"
arcpy.sa.ZonalStatisticsAsTable(output_parcels_fc, parcel_id_field, landslide_hazard_raster, tmp_zonal_stats_table, "", "SUM")
print("Joining Zonal Stats table to the parcels dataset...")
# Join the zonal stats table (output_parcels_fc, just the "COUNT" field) to the parcels feature class.
arcpy.JoinField_management(output_parcels_fc, parcel_id_field, tmp_zonal_stats_table, parcel_id_field, "COUNT")
# Loop over each row and determine whether or not > 20% of the parcel has a landslide hazard pixel.
uc = arcpy.da.UpdateCursor(output_parcels_fc, ["SHAPE_Area", "COUNT", field_to_calc, "OBJECTID"])
for row in uc:
# If no join record, no pixel, no landslide hazard
if not row[1]:
row[2] = 1
# Otherwise see if the parcel is > the 20% threshold.
else:
#Calculate the area of the landslide hazard pixels.
landslide_hazard_sq_meters = row[1] * pow(landslide_hazard_raster_resolution, 2)
parcel_area = row[0]
#Calculate the percent of the landslide hazard pixels with the parcel
percent_high_landslide = (float(landslide_hazard_sq_meters) / parcel_area) * 100
# If it's > the threshold, it's not eligible.
if percent_high_landslide >= landslide_area_percent_threshold:
row[2] = 0
else:
row[2] = 1
uc.updateRow(row)
arcpy.DeleteField_management(output_parcels_fc, "COUNT")
def calc_requirement_9_6(self, output_parcels_fc, field_to_calc):
"""
9.6
Requirement Long Name: State Conservancy
Description: Select parcels that intersect the State Conservancy Dataset. Yes = 0, No = 1
"""
output_parcels_layer = arcpy.MakeFeatureLayer_management(output_parcels_fc)
arcpy.SelectLayerByLocation_management(output_parcels_layer, "INTERSECT", state_conservancy_fc)
arcpy.CalculateField_management(output_parcels_layer, field_to_calc, 0, "PYTHON")
arcpy.SelectLayerByAttribute_management(output_parcels_layer, "SWITCH_SELECTION")
arcpy.CalculateField_management(output_parcels_layer, field_to_calc, 1, "PYTHON")
def calc_requirement_9_7(self, output_parcels_fc, field_to_calc):
"""
9.7
Requirement Long Name: Local Coastal Zone
Description: Select parcels that intersect the Local Coastal Zone Dataset. Yes = 0, No = 1
"""
output_parcels_layer = arcpy.MakeFeatureLayer_management(output_parcels_fc)
arcpy.SelectLayerByLocation_management(output_parcels_layer, "INTERSECT", local_coastal_zone_fc)
arcpy.CalculateField_management(output_parcels_layer, field_to_calc, 0, "PYTHON")
arcpy.SelectLayerByAttribute_management(output_parcels_layer, "SWITCH_SELECTION")
arcpy.CalculateField_management(output_parcels_layer, field_to_calc, 1, "PYTHON")
def calc_requirement_9_8(self, output_parcels_fc, field_to_calc):
"""
9.8
Requirement Long Name: Protected Area Mask
Description: Select parcels that intersect the Protected Area Mask Dataset. Yes = 0, No = 1
"""
output_parcels_layer = arcpy.MakeFeatureLayer_management(output_parcels_fc)
arcpy.SelectLayerByLocation_management(output_parcels_layer, "INTERSECT", protected_area_mask_fc)
arcpy.CalculateField_management(output_parcels_layer, field_to_calc, 0, "PYTHON")
arcpy.SelectLayerByAttribute_management(output_parcels_layer, "SWITCH_SELECTION")
arcpy.CalculateField_management(output_parcels_layer, field_to_calc, 1, "PYTHON")
# MODELS
# Calling a model from arcpy after the toolbox has been imported:
# arcpy.ModelName_ToolboxAlias() #Note that it's ModelName not Label.
# arcpy.SpecificPlan26_Statewide(output_parcels_fc, field_to_calc)
def calc_requirement_2_6(self, output_parcels_fc, field_to_calc):
# This is the name of the model (not the label)
model_name = "r26"
full_model_name = model_name + "_" + statewide_toolbox_alias
run_model_command = "arcpy." + full_model_name + "(r'%s', '%s')" % (output_parcels_fc, field_to_calc)
exec(run_model_command)
def calc_requirement_3_1(self, output_parcels_fc, field_to_calc):
# This is the name of the model (not the label)
model_name = "r31"
full_model_name = model_name + "_" + statewide_toolbox_alias
run_model_command = "arcpy." + full_model_name + "(r'%s', '%s')" % (output_parcels_fc, field_to_calc)
exec(run_model_command)
def calc_requirement_3_2(self, output_parcels_fc, field_to_calc):
# This is the name of the model (not the label)
model_name = "r32"
full_model_name = model_name + "_" + statewide_toolbox_alias
run_model_command = "arcpy." + full_model_name + "(r'%s', '%s')" % (output_parcels_fc, field_to_calc)
exec(run_model_command)
def calc_requirement_3_3(self, output_parcels_fc, field_to_calc):
# This is the name of the model (not the label)
model_name = "r33"
full_model_name = model_name + "_" + statewide_toolbox_alias
run_model_command = "arcpy." + full_model_name + "(r'%s', '%s')" % (output_parcels_fc, field_to_calc)
exec(run_model_command)
def calc_requirement_3_4(self, output_parcels_fc, field_to_calc):
# This is the name of the model (not the label)
model_name = "r34"
full_model_name = model_name + "_" + statewide_toolbox_alias
run_model_command = "arcpy." + full_model_name + "(r'%s', '%s')" % (output_parcels_fc, field_to_calc)
exec(run_model_command)
def calc_requirement_3_5(self, output_parcels_fc, field_to_calc):
# This is the name of the model (not the label)
model_name = "r35"
full_model_name = model_name + "_" + statewide_toolbox_alias
run_model_command = "arcpy." + full_model_name + "(r'%s', '%s')" % (output_parcels_fc, field_to_calc)
exec(run_model_command)
def calc_requirement_3_6(self, output_parcels_fc, field_to_calc):
# This is the name of the model (not the label)
model_name = "r36"
full_model_name = model_name + "_" + statewide_toolbox_alias
run_model_command = "arcpy." + full_model_name + "(r'%s', '%s')" % (output_parcels_fc, field_to_calc)
exec(run_model_command)
def calc_requirement_3_7(self, output_parcels_fc, field_to_calc):
# This is the name of the model (not the label)
model_name = "r37"
full_model_name = model_name + "_" + statewide_toolbox_alias
run_model_command = "arcpy." + full_model_name + "(r'%s', '%s')" % (output_parcels_fc, field_to_calc)
exec(run_model_command)
def calc_requirement_3_8(self, output_parcels_fc, field_to_calc):
# This is the name of the model (not the label)
model_name = "r38"
full_model_name = model_name + "_" + statewide_toolbox_alias
run_model_command = "arcpy." + full_model_name + "(r'%s', '%s')" % (output_parcels_fc, field_to_calc)
exec(run_model_command)
def calc_requirement_3_9(self, output_parcels_fc, field_to_calc):
# This is the name of the model (not the label)
model_name = "r39"
full_model_name = model_name + "_" + statewide_toolbox_alias
run_model_command = "arcpy." + full_model_name + "(r'%s', '%s')" % (output_parcels_fc, field_to_calc)
exec(run_model_command)
def calc_requirement_3_10(self, output_parcels_fc, field_to_calc):
# This is the name of the model (not the label)
model_name = "r310"
full_model_name = model_name + "_" + statewide_toolbox_alias
run_model_command = "arcpy." + full_model_name + "(r'%s', '%s')" % (output_parcels_fc, field_to_calc)
exec(run_model_command)
def calc_requirement_3_11(self, output_parcels_fc, field_to_calc):
# This is the name of the model (not the label)
model_name = "r311"
full_model_name = model_name + "_" + statewide_toolbox_alias
run_model_command = "arcpy." + full_model_name + "(r'%s', '%s')" % (output_parcels_fc, field_to_calc)
exec(run_model_command)
def calc_requirement_3_12(self, output_parcels_fc, field_to_calc):
# This is the name of the model (not the label)
model_name = "r312"
full_model_name = model_name + "_" + statewide_toolbox_alias
run_model_command = "arcpy." + full_model_name + "(r'%s', '%s')" % (output_parcels_fc, field_to_calc)
exec(run_model_command)
def calc_requirement_3_13(self, output_parcels_fc, field_to_calc):
# This is the name of the model (not the label)
model_name = "r313"
full_model_name = model_name + "_" + statewide_toolbox_alias
run_model_command = "arcpy." + full_model_name + "(r'%s', '%s')" % (output_parcels_fc, field_to_calc)
exec(run_model_command)
def calc_requirement_3_14(self, output_parcels_fc, field_to_calc):
# This is the name of the model (not the label)
model_name = "r314"
full_model_name = model_name + "_" + statewide_toolbox_alias
run_model_command = "arcpy." + full_model_name + "(r'%s', '%s')" % (output_parcels_fc, field_to_calc)
exec(run_model_command)
def calc_requirement_8_1(self, output_parcels_fc, field_to_calc):
# This is the name of the model (not the label)
model_name = "r81"
full_model_name = model_name + "_" + statewide_toolbox_alias
run_model_command = "arcpy." + full_model_name + "(r'%s', '%s')" % (output_parcels_fc, field_to_calc)
exec(run_model_command)
def calc_requirement_8_2(self, output_parcels_fc, field_to_calc):
# This is the name of the model (not the label)
model_name = "r82"
full_model_name = model_name + "_" + statewide_toolbox_alias
run_model_command = "arcpy." + full_model_name + "(r'%s', '%s')" % (output_parcels_fc, field_to_calc)
exec(run_model_command)
def calc_requirement_8_3(self, output_parcels_fc, field_to_calc):
# This is the name of the model (not the label)
model_name = "r83"
full_model_name = model_name + "_" + statewide_toolbox_alias
run_model_command = "arcpy." + full_model_name + "(r'%s', '%s')" % (output_parcels_fc, field_to_calc)
exec(run_model_command)
def calc_requirement_9_2(self, output_parcels_fc, field_to_calc):
# This is the name of the model (not the label)
model_name = "r92"
full_model_name = model_name + "_" + statewide_toolbox_alias
run_model_command = "arcpy." + full_model_name + "(r'%s', '%s')" % (output_parcels_fc, field_to_calc)
exec(run_model_command)
def default_function(self, *args):
print("No function for this requirement. Values will not be calculated.")
def do_command(self, requirement_id, *args):
return getattr(self, "calc_requirement_" + requirement_id.replace(".", "_"), self.default_function)(*args)
def join_additional_requirements(join_table, requirements_to_join):
#Create index on join table once.
#arcpy.AddIndex_management(join_table, "parcel_id", "parcel_id_index")
fields_to_join = []
for requirement_id in requirements_to_join:
# Find the field name in join_table
field_code = requirement_id.replace(".", "_")
matching_field = arcpy.ListFields(join_table, "*" + field_code)[0].name
print("Field to join: " + matching_field)
fields_to_join.append(matching_field)
# Delete standardized field name if it exists.
standardized_field_name = requirements[requirement_id]
print("Standardized field name: " + standardized_field_name)
if standardized_field_name in existing_output_fields:
print("The standardized field above already exists. Deleting it to avoid conflicts when the rename function is called...")
arcpy.DeleteField_management(output_parcels_fc, standardized_field_name)
print("Performing join of additional fields...")
arcpy.JoinField_management(output_parcels_fc, "parcel_id", join_table, "parcel_id", fields_to_join)
def rename_fields():
""" This function will rename fields to match the standardized field names in the requirements dictionary
It only works if the field to be renamed has the requirement code at the end of the field name (e.g., "8_3")
It will operate on requirement codes that exist in the requirements dictionary.
It will skip over any fields that have a name that's already in the requirements dictionary.
"""
if arcpy.Exists(output_parcels_fc):
existing_output_fields = [field.name for field in arcpy.ListFields(output_parcels_fc)]
for input_field in existing_output_fields:
print("Input field: " + input_field)
try:
#requirement_code = float(input_field.split("_")[-2] + "." + input_field.split("_")[-1])
requirement_code = input_field.split("_")[-2] + "." + input_field.split("_")[-1]
print("Requirement code in field name: " + str(requirement_code))
except:
requirement_code = False
print("No requirement code")
if requirement_code in requirements:
standardized_field_name = requirements[requirement_code]
if requirement_code in requirements and not (input_field == standardized_field_name):
print(input_field + " will be renamed to " + standardized_field_name)
# If the standardized field name already exists in the fc, just recalculate it using the input field name.
if standardized_field_name in existing_output_fields:
print("1. Calculating field...")
arcpy.CalculateField_management(output_parcels_fc, standardized_field_name, "!" + input_field + "!", "PYTHON")
arcpy.DeleteField_management(output_parcels_fc, input_field)
# Handles the case where an input field name is not all lower case, but otherwise matches the standardized field name.
elif input_field.lower() == standardized_field_name:
arcpy.AddField_management(output_parcels_fc, standardized_field_name + "_lower", "SHORT")
arcpy.CalculateField_management(output_parcels_fc, standardized_field_name + "_lower", "!" + input_field + "!", "PYTHON")
arcpy.DeleteField_management(output_parcels_fc, input_field)
arcpy.AlterField_management(output_parcels_fc, standardized_field_name + "_lower", standardized_field_name)
# If the length of the standardized field name is > 31, we have to add a new field (standardized_field_name), calculate it, and then delete the input_field.
elif len(standardized_field_name) > 31:
print("2. Adding Field and Calculating Field...")
arcpy.AddField_management(output_parcels_fc, standardized_field_name, "SHORT")
arcpy.CalculateField_management(output_parcels_fc, standardized_field_name, "!" + input_field + "!", "PYTHON")
arcpy.DeleteField_management(output_parcels_fc, input_field)
# Otherwise we just do what we came here to do: rename the field.
else:
print("3. Altering Field...")
try:
arcpy.AlterField_management(output_parcels_fc, input_field, standardized_field_name)
except:
print("ERROR...could not alter field. There was likely more than one field with " + \