-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathOSMM_HLU_Interpret V2.py
599 lines (544 loc) · 25.3 KB
/
OSMM_HLU_Interpret V2.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
# INTERPRETING HABITAT TYPE
# -----------------------------------
# Code by Martin Besnier and Alison Smith (Environmental Change Institute, University of Oxford)
# This code is a research tool and has not been rigorously tested for wider use.
# ------------------------------------------------------------------------------
# Processes a merged OSMM and habitat file (OR just OSMM) to assign the correct habitat type
#
# Expects input file to have the following fields:
# - DescriptiveGroup, DescriptiveTerm, Make
# - Phase 1 habitat and BAP habitat (field names specified as input parameters)
# -----------------------------------------------------------------------------------------------
import time, arcpy
import os
import MyFunctions
print(''.join(["## Started on : ", time.ctime()]))
arcpy.CheckOutExtension("Spatial")
arcpy.env.overwriteOutput = True # Overwrites files
# *** Enter parameters here
# -------------------------
# region = "Arc"
region = "Oxon"
# region = "Blenheim"
# region = "NP"
# method = "CROME_PHI"
method = "HLU"
# method = "OSMM_only"
if region == "Oxon" and method == "HLU":
# Operate in the Oxon_county folder
folder = r"D:\cenv0389\Oxon_GIS\Oxon_county\Data"
gdbs = [os.path.join(folder, "Merge_OSMM_HLU_CR_ALC.gdb")]
# LAD_table = os.path.join(folder, "Data.gdb", "Oxon_LADs")
in_file_name = "OSMM_HLU"
Hab_field = "Interpreted_habitat"
# *** Late habitat corrections ***
# in_file_name = "OSMM_HLU_CR_ALC"
# Hab_field = "Interpreted_habitat_temp"
in_hab_field = "PHASE1HAB" # Zach - change
BAP_field = "S41HABITAT" # change
# Which stages of the code do we want to run? Useful for debugging or updating.
delete_landform = True
add_OSMM_hab = True
simplify_OSMM = True
simplify_HLU = True
select_HLU_or_OSMM = True
interpret_BAP = True
elif method == "CROME_PHI":
folder = r"D:\cenv0389\OxCamArc\LADs"
arcpy.env.workspace = folder
gdbs = arcpy.ListWorkspaces("*", "FileGDB")
LAD_table = r"D:\cenv0389\OxCamArc\Arc_LADs_sort.shp"
in_file_name = "OSMM"
Hab_field = "Interpreted_habitat"
if region == "Arc":
LADs_included = ["Bedfordshire", "Buckinghamshire", "Cambridgeshire", "Northamptonshire", "Oxfordshire", "Peterborough"]
elif region == "Oxon":
LADs_included = ["Oxfordshire"]
else:
print("ERROR: Invalid region")
exit()
# We only want to run delete_landform and simplify_OSMM.
delete_landform = True
add_OSMM_hab = False
simplify_OSMM = True
simplify_HLU = False
select_HLU_or_OSMM = False
interpret_BAP = False
elif method == "OSMM_only":
if region == "Oxon":
folder = r"D:\cenv0389\Oxon_GIS\Oxon_county\Data"
gdbs = ["OSMM_Aug2020.gdb"]
in_file_name = "OSMM_Oxon_Aug2020_clip"
Hab_field = "Interpreted_habitat"
LADs_included = ["Oxfordshire"]
elif region == "NP":
folder = r"M:\urban_development_natural_capital\LADs"
arcpy.env.workspace = folder
LAD_names = ["Allerdale.gdb", "Barnsley.gdb", "Barrow-in-Furness.gdb", "Blackburn with Darwen.gdb", "Blackpool.gdb",
"Bolton.gdb", "Bradford.gdb", "Burnley.gdb", "Bury.gdb", "Calderdale.gdb", "Carlisle.gdb",
"Cheshire East.gdb", "Cheshire West and Chester.gdb", "Chorley.gdb", "Copeland.gdb", "County Durham.gdb",
"Craven.gdb", "Darlington.gdb", "Doncaster.gdb", "East Riding of Yorkshire.gdb", "Eden.gdb", "Fylde.gdb", "Gateshead.gdb",
"Halton.gdb", "Hambleton.gdb", "Harrogate.gdb", "Hartlepool.gdb", "Hyndburn.gdb", "Kirklees.gdb", "Knowsley.gdb",
"Lancaster.gdb", "Leeds.gdb", "Liverpool.gdb", "Manchester.gdb", "Middlesbrough.gdb", "Newcastle upon Tyne.gdb",
"North East Lincolnshire.gdb", "North Lincolnshire.gdb", "Northumberland.gdb", "North Tyneside.gdb", "Oldham.gdb",
"Pendle.gdb", "Preston.gdb", "Redcar and Cleveland.gdb", "Ribble Valley.gdb",
"Richmondshire.gdb", "Rochdale.gdb", "Rossendale.gdb", "Rotherham.gdb", "Ryedale.gdb", "Salford.gdb",
"Scarborough.gdb", "Sefton.gdb", "Selby.gdb", "Sheffield.gdb", "South Lakeland.gdb", "South Ribble.gdb",
"South Tyneside.gdb", "St Helens.gdb", "Stockport.gdb", "Stockton-on-Tees.gdb", "Sunderland.gdb",
"Tameside.gdb", "Trafford.gdb", "Wakefield.gdb", "Warrington.gdb", "West Lancashire.gdb", "Wigan.gdb", "Wirral.gdb",
"Wyre.gdb", "York.gdb"]
# LAD_names = []
gdbs = []
for LAD_name in LAD_names:
gdbs.append(os.path.join(folder, LAD_name.replace(" ", "")))
in_file_name = "OSMM"
# in_file_name = "OSMM_CR_PHI_ALC_Desig_GS" # Used for late corrections
Hab_field = "Interpreted_habitat"
# We only want to run delete_landform and simplify_OSMM.
# *** Change to only simplify_OSMM for late habitat corrections ***.
delete_landform = True
add_OSMM_hab = False
simplify_OSMM = True
simplify_HLU = False
select_HLU_or_OSMM = False
interpret_BAP = False
else:
print("ERROR: you cannot combine region " + region + " with method " + method)
exit()
# If OSMM is "undefined" this usually means the area is under development or scheduled for development. Choose whether to map as
# "undefined" or as the current / original habitat pre-development. Up till now including NP we have used original but in future best to
# use undefined - in fact should maybe change this for NP as well, though bit late now!!!
# undefined_or_original = "original"
undefined_or_original = "undefined"
# Check the county from the table of LADs, to identify the list of LADs to process
LADs = []
if region == "Oxon":
LADs = ["Oxfordshire"]
elif region == "Arc":
for LAD in arcpy.SearchCursor(LAD_table):
if LAD.getValue("county") in LADs_included:
LADs.append(LAD.getValue("desc_").replace(" ", ""))
# Or use this line to update only certain LADs
# LADs = ["AylesburyVale", "Chiltern", "Oxford", "SouthOxfordshire", "Wycombe"]
elif region == "Blenheim":
LADs = ["Blenheim"]
elif region == "NP":
LADs = LAD_names
if region == "NP":
OSMM_Term = "descriptiveterm"
OSMM_Group = "descriptivegroup"
OSMM_Make = "make"
else:
OSMM_Term = "DescriptiveTerm"
OSMM_Group = "DescriptiveGroup"
OSMM_Make = "Make"
print("LADs to process: " + "\n ".join(LADs))
i=0
for gdb in gdbs:
if (region == "Oxon" and (method == "HLU" or method == "OSMM_only")) or (os.path.split(gdb)[1])[:-4] in LADs or region == "NP":
i = i + 1
print "Processing LAD " + str(i) + " out of " + str(len(LADs))
arcpy.env.workspace = gdb
print(''.join(["## Started interpreting habitats for ", gdb, " ", in_file_name, " on : ", time.ctime()]))
in_file = os.path.join(folder, gdb, in_file_name)
if delete_landform:
print(" Deleting overlapping 'Landform' and 'Pylon' from OSMM for " + in_file_name)
arcpy.MakeFeatureLayer_management(in_file, "OSMM_layer")
expression = "DescriptiveGroup LIKE '%Landform%' OR DescriptiveTerm IN ('Cliff','Slope','Pylon')"
arcpy.SelectLayerByAttribute_management("OSMM_layer", where_clause=expression)
arcpy.DeleteFeatures_management("OSMM_layer")
arcpy.Delete_management("OSMM_layer")
# Simplify the OSMM habitats
# --------------------------
if simplify_OSMM:
print(" Simplifying OSMM habitats")
if add_OSMM_hab:
MyFunctions.check_and_add_field(in_file, "OSMM_hab", "TEXT", 100)
codeblock = """
def Simplify_OSMM(OSMM_Group, OSMM_Term, OSMM_Make):
if OSMM_Make == "Manmade":
if OSMM_Group[:8] == "Building" or OSMM_Group == "Glasshouse":
return "Building"
elif OSMM_Group[:4] == "Rail" and (OSMM_Term is None or OSMM_Term == ""):
return "Rail"
elif OSMM_Group == "Road Or Track":
return "Road"
elif "Path" in OSMM_Group:
return "Path: manmade"
elif OSMM_Term is None or OSMM_Term == "":
if OSMM_Group == "Roadside":
return "Roadside: manmade"
else:
return "Sealed surface"
elif OSMM_Term == "Electricity Sub Station":
return "Building"
elif "bridge" in OSMM_Term.lower(): #Bridge or footbridge
return "Bridge"
elif OSMM_Term in ["Swimming Pool","Fountain","Weir"]:
return OSMM_Term.capitalize()
elif OSMM_Term in ["Mill Leat","Mine Leat","Lock","Conduit"]:
return "Canal"
elif "Landfill" in OSMM_Term:
if "Inactive" in OSMM_Term:
return "Landfill: disused"
else:
return "Landfill"
elif "Mineral Workings" in OSMM_Term or "Spoil" in OSMM_Term or "Slag" in OSMM_Term:
if "Inactive" in OSMM_Term:
return "Quarry or spoil: disused"
else:
return "Quarry or spoil"
else:
return "Sealed surface"
elif OSMM_Make == "Multiple":
return "Garden"
elif OSMM_Make == "Natural":
if OSMM_Term is None or OSMM_Term == "": # Need this test before we start comparing OSMM_Term, otherwise it crashes
if "Roadside" in OSMM_Group:
return "Road island / verge"
elif "tidal water" in OSMM_Group.lower():
return "Saltwater"
elif "water" in OSMM_Group.lower():
return "Water"
else:
return "Natural surface"
elif "water" in OSMM_Group.lower() or "Leat" in OSMM_Term or OSMM_Term in ["Conduit","Spreads","Issues","Sink","Spring"]:
if OSMM_Term in ["Canal","Canal Feeder", "Conduit"]:
return "Canal"
elif OSMM_Term in ["Reservoir","Drain"]:
return OSMM_Term.capitalize()
elif OSMM_Term in ["Static Water","Collects","Mill Leat","Mine Leat","Spreads","Sink"]:
return "Standing water"
elif OSMM_Term in ["Watercourse","Waterfall","Ford","Spring","Issues"]:
return "Running water"
elif "Trees" in OSMM_Term:
return "Wet woodland"
elif "Reeds" in OSMM_Term:
return "Reedbed"
elif "Foreshore" in OSMM_Term:
if "Saltmarsh" in OSMM_Term:
return "Saltmarsh"
elif (OSMM_Term[:4] == "Rock" or OSMM_Term[:8] == "Boulders") and "Sand" not in OSMM_Term and "Mud" not in OSMM_Term:
return "Coastal rock"
elif OSMM_Term[:7] == "Shingle":
return "Shingle"
elif OSMM_Term[:3] == "Mud":
return "Mudflats"
else:
return "Intertidal sediment"
else:
return "Water"
elif OSMM_Term == "Agricultural Land":
return "Agricultural land" # Unknown farmland
elif OSMM_Term == "Track":
return "Track"
elif OSMM_Term in ["Bridge","Footbridge"]:
return "Bridge: natural"
elif OSMM_Term == "Tank":
return "Sealed surface"
elif "Trees" in OSMM_Term or "Coppice Or Osiers" in OSMM_Term:
if "Nonconiferous" in OSMM_Term or "Coppice Or Osiers" in OSMM_Term:
if "Coniferous" in OSMM_Term:
wood = "mixed"
else:
wood = "broadleaved"
else:
wood = "coniferous"
if (wood == "broadleaved" and "Nonconiferous Trees (Scattered)" in OSMM_Term):
scattered_trees = True
elif (wood == "coniferous" and "Coniferous Trees (Scattered)" in OSMM_Term):
scattered_trees = True
elif (wood == "mixed" and ("Nonconiferous Trees (Scattered)" in OSMM_Term and "Coniferous Trees (Scattered)" in OSMM_Term)):
scattered_trees = True
else:
scattered_trees = False
if scattered_trees == True or "Grass" in OSMM_Term or "Heath" in OSMM_Term or "Marsh" in OSMM_Term:
if "Heath" in OSMM_Term:
if "Grass" in OSMM_Term:
return ("Heath/grass mosaic with scattered trees: " + wood)
else:
return ("Heath with scattered trees: " + wood)
elif "Marsh" in OSMM_Term:
return ("Marsh with scattered trees: " + wood)
elif "Rough Grassland" in OSMM_Term:
return ("Semi-natural grassland with scattered trees: " + wood)
elif ("Scrub" in OSMM_Term and "Scrub (Scattered)" not in OSMM_Term):
return ("Scrub with scattered trees: " + wood)
elif "Scree" in OSMM_Term:
return ("Scree with scattered trees: " + wood)
elif ("Rock" in OSMM_Term and "Rock (Scattered)" not in OSMM_Term):
return ("Rock with scattered trees: " + wood)
else:
return ("Scattered trees: " + wood)
else:
return ("Woodland: " + wood)
elif "Scrub" in OSMM_Term:
if "Scrub (Scattered)" in OSMM_Term or "Grass" in OSMM_Term or "Heath" in OSMM_Term or "Marsh" in OSMM_Term:
if "Heath" in OSMM_Term:
if "Grass" in OSMM_Term:
return ("Heath/grass mosaic with scattered scrub")
else:
return ("Heath with scattered scrub")
elif "Marsh" in OSMM_Term:
if OSMM_Term[:6] == "Scrub,":
return ("Scrub with marsh")
else:
return ("Marsh with scattered scrub")
elif "Rough Grassland" in OSMM_Term:
return ("Semi-natural grassland with scattered scrub")
elif "Scree" in OSMM_Term:
return ("Scree with scattered scrub")
elif ("Rock" in OSMM_Term and "Rock (Scattered)" not in OSMM_Term):
return ("Rock with scattered scrub")
else:
return "Scattered scrub"
else:
return "Dense scrub"
elif "Orchard" in OSMM_Term:
return "Orchard"
elif "Heath" in OSMM_Term:
if "Grass" in OSMM_Term:
return "Heath/grass mosaic"
else:
return "Heathland"
elif "Marsh" in OSMM_Term:
return "Fen, marsh and swamp"
elif OSMM_Term[:9] == "Saltmarsh":
return "Saltmarsh"
elif OSMM_Term[:3] == "Mud":
return "Mudflats"
elif OSMM_Term[:7] == "Shingle":
return "Shingle"
elif OSMM_Term[:4] == "Sand":
return "Sand"
elif "Grass" in OSMM_Term:
return "Semi-natural grassland"
elif ("Mineral" in OSMM_Term or "Spoil" in OSMM_Term or "Slag" in OSMM_Term) and "Inactive" in OSMM_Term:
return "Quarry or spoil: disused"
elif OSMM_Term[:4] == "Rock":
return "Rock"
elif OSMM_Term[:5] == "Scree":
return "Scree"
elif OSMM_Term[:8] == "Boulders":
return "Boulders"
elif OSMM_Term == "Landfill (inactive)":
return "Landfill: disused"
else:
return OSMM_Term.capitalize()
else:
if OSMM_Group == "Roadside":
return "Roadside: unknown surface"
else:
return "Undefined"
"""
expression = "Simplify_OSMM(!" + OSMM_Group + "!, !" + OSMM_Term + "!, !" + OSMM_Make + "!)"
arcpy.CalculateField_management(in_file, "OSMM_hab", expression, "PYTHON_9.3", codeblock)
# Simplify the HLU habitats
#--------------------------
if simplify_HLU:
print("Simplifying HLU habitats")
MyFunctions.check_and_add_field(in_file, "HLU_hab", "TEXT", 100)
codeblock = """
def Simplify_HLU(HLU_Hab):
if HLU_Hab is None or HLU_Hab.strip() == "" or HLU_Hab == "Unknown" or HLU_Hab == "Unidentified":
return ""
else:
HLU_Hab = HLU_Hab.lower()
# 'Cultivated/disturbed land - ' categories: simplify to just 'Arable', 'Amenity grassland' etc
if "amenity" in HLU_Hab:
return "Amenity grassland"
elif "ephemeral" in HLU_Hab:
return "Ephemeral vegetation"
elif "arable" in HLU_Hab:
if "scattered" in HLU_Hab and "trees" in HLU_Hab:
return "Arable and scattered trees"
else:
return "Arable"
elif "felled" in HLU_Hab and "woodland" in HLU_Hab:
return "Felled woodland"
elif "scrub" in HLU_Hab:
if "scattered" in HLU_Hab:
if "neutral grassland" in HLU_Hab:
return "Neutral grassland and scattered scrub"
else:
return "Scattered scrub"
else:
return "Dense scrub"
elif "herb and fern" in HLU_Hab:
return "Tall herb and fern"
elif "heath" in HLU_Hab:
if "grass" in HLU_Hab:
return "Heath/grass mosaic"
else:
return "Heathland"
elif "hedge" in HLU_Hab and "trees" in HLU_Hab:
return "Hedge with trees"
elif "hedge" in HLU_Hab:
return "Hedge"
elif "refuse" in HLU_Hab or "landfill" in HLU_Hab:
return "Landfill"
elif "spoil" in HLU_Hab or "quarry" in HLU_Hab:
return "Quarry or spoil"
elif "fen" in HLU_Hab:
return "Lowland fens"
elif "flush" in HLU_Hab:
if "upland" in HLU_Hab:
return "Upland flushes, fens and swamps"
else:
return "Fen, marsh and swamp"
elif "marsh" in HLU_Hab:
return "Marshy grassland"
elif "marginal" in HLU_Hab:
return "Aquatic marginal vegetation"
elif "open mosaic" in HLU_Hab:
return "Open mosaic habitats"
else:
return HLU_Hab.capitalize()
"""
arcpy.CalculateField_management(in_file, "HLU_hab", "Simplify_HLU(!" + in_hab_field + "!)", "PYTHON_9.3", codeblock)
# Choose whether to use OSMM or HLU
# ----------------------------------
if select_HLU_or_OSMM:
print("Selecting or combining HLU and OSMM habitats")
MyFunctions.check_and_add_field(in_file, Hab_field, "TEXT", 100)
codeblock = """
def Interpret_hab(HLU_hab, OSMM_hab, OSMM_Make, OSMM_area, HLU_area, undefined_or_original):
if HLU_hab is None or HLU_hab.strip() == "" or HLU_hab == "Built-up areas":
return OSMM_hab.capitalize()
elif OSMM_hab == "Roadside: unknown surface":
return HLU_hab.capitalize()
elif OSMM_hab == "Undefined":
if undefined_or_original == "undefined":
return "Undefined"
else:
# Unclassified / undefined is usually sites under development, but this returns original habitat
return HLU_hab.capitalize()
else:
HLU_hab = HLU_hab.lower()
OSMM_hab = OSMM_hab.lower()
# OSMM manmade, gardens and water always take priority over HLU
if OSMM_Make == "Manmade" or OSMM_hab in ["garden","standing water","running water","canal","reservoir","drain","wet woodland","reedbed"]:
return OSMM_hab.capitalize()
# HLU takes priority over non-specific OSMM habitats
if OSMM_hab in ["agricultural land", "natural surface"]:
return HLU_hab.capitalize()
# Where HLU says grass but OSMM says trees or scrub, classify as trees / scrub encroaching onto grass
if "trees" in OSMM_hab:
if "mixed" in OSMM_hab:
wood = "mixed"
elif "broadleaved" in OSMM_hab:
wood = "broadleaved"
elif "coniferous" in OSMM_hab:
wood = "coniferous"
seminatural_grass = False
if "acid" in HLU_hab or "neutral" in HLU_hab or "calcareous" in HLU_hab or "marsh" in HLU_hab or "poor" in HLU_hab:
seminatural_grass = True
if "trees" in OSMM_hab and "grassland" in HLU_hab and "scattered" not in HLU_hab:
if "scattered" in OSMM_hab:
if seminatural_grass:
return ("Semi-natural grassland with scattered trees: " + wood)
else:
return ("Scattered trees: " + wood)
else:
if seminatural_grass == True:
return ("Woodland: " + wood + " on semi-natural grassland")
else:
return ("Woodland: " + wood)
if "scrub" in OSMM_hab and "grassland" in HLU_hab and "scattered" not in HLU_hab:
if "scattered" in OSMM_hab:
if "amenity" in HLU_hab:
return "Amenity grassland and scattered scrub"
elif "improved" in HLU_hab and "semi" not in HLU_hab:
return "Improved grassland and scattered scrub"
elif seminatural_grass == True:
return "Semi-natural grassland with scattered scrub"
else:
if seminatural_grass == True:
return "Scrub on semi-natural grassland"
else:
return "Dense scrub"
# Where HLU says woodland and OSMM says trees or scattered trees, use HLU definition unless HLU is unknown woodland
if ("woodland" in OSMM_hab or "orchard" in OSMM_hab) and ("woodland" in HLU_hab or "orchard" in HLU_hab):
if ("unknown" in HLU_hab) or (HLU_hab == "woodland"):
return OSMM_hab.capitalize() # if unknown woodland in HLU, use OSMM definition
else:
return HLU_hab.capitalize()
if "semi-natural grassland" in OSMM_hab and ("amenity" in HLU_hab or "arable" in HLU_hab): # OSMM rough grass trumps arable /amenity
return "Semi-natural grassland"
# All other habitats (woodland, semi-nat grass, orchard, marsh, heath, etc) - both OSMM and HLU are 'distinctive' so either
# could be correct. Use OSMM if it is considerably smaller than HLU (an 'island' or ride within larger HLU polygon), otherwise use HLU
if OSMM_area < HLU_area * 0.6:
return OSMM_hab.capitalize()
else:
return HLU_hab.capitalize()
"""
expression = "Interpret_hab(!HLU_hab!, !OSMM_hab!, !Make!, !OSMM_Area!, !HLU_Area!, '" + undefined_or_original + "')"
arcpy.CalculateField_management(in_file, Hab_field, expression, "PYTHON_9.3", codeblock)
# Update Interpreted_habitat column where appropriate using S41 Habitat information (previously known as BAP habitat)
if interpret_BAP:
print(''.join(["## BAP interpretation started on : ", time.ctime()]))
codeblock = """
def interpretBAP(Hab, BAP):
if BAP:
BAP = BAP.lower()
if BAP in ["none","not assessed yet",""," "]:
return Hab
elif Hab == "Garden": # Gardens usually mean the original BAP has been developed, except for Trad orchards in large gardens
if BAP == "traditional orchards":
return BAP.capitalize()
else:
return Hab
elif "possible priority grassland" in BAP:
if Hab in ["Natural surface", "Improved grassland", "Agricultural land", "Unknown", "Unidentified"]:
return "Semi-natural grassland"
elif Hab == "Scattered scrub":
return "Semi-natural grassland with scattered scrub"
elif Hab == "Dense scrub":
return "Scrub on semi-natural grassland"
elif Hab == "Scattered trees: broadleaved":
return "Semi-natural grassland with scattered trees: broadleaved"
elif Hab == "Scattered trees: mixed":
return "Semi-natural grassland with scattered trees: mixed"
elif Hab == "Scattered trees: coniferous":
return "Semi-natural grassland with scattered trees: coniferous"
else:
return Hab
elif "possible priority fen" in BAP:
if Hab in ["Natural surface", "Improved grassland", "Agricultural land", "Unknown", "Unidentified"]:
return "Lowland fens"
else:
return Hab
elif "reedbed" in BAP:
return "Reedbed"
elif "open mosaic habitat" in BAP:
return "Open mosaic habitats"
elif "purple moor grass" in BAP:
return "Marshy grassland"
elif "grazing marsh" in BAP:
if "grass" in Hab.lower():
return "Marshy grassland"
else:
return Hab
elif "deciduous" in BAP or "beech and yew" in BAP:
return "Woodland: broadleaved, semi-natural"
elif "acid grass" in BAP:
return "Acid grassland"
elif "meadow" in BAP:
return "Neutral grassland"
elif "calcareous" in BAP:
return "Calcareous grassland"
elif "heathland" in BAP:
return "Heathland"
elif "wood-pasture" in BAP or "wood pasture" in BAP:
return "Parkland and scattered trees: broadleaved"
elif "pond" in BAP or "river" in BAP or "water" in BAP or "lake" in BAP:
return Hab
else:
return BAP.capitalize()
else:
return Hab
"""
arcpy.CalculateField_management(in_file, Hab_field,
"interpretBAP( !" + Hab_field + "! , !" + BAP_field + "!)", "PYTHON_9.3", codeblock)
print(''.join(["## Completed on : ", time.ctime()]))
exit()