-
Notifications
You must be signed in to change notification settings - Fork 0
/
Script.py
570 lines (427 loc) · 25 KB
/
Script.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
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# Paleospeleology3D.py
# Created on: 2022-06-04 15:22:00.00000
# (generated by ArcGIS/ModelBuilder)
# Usage: Paleospeleology 1.0 (® I. Intxaurbe)
# Description: We need the following files (With the name that we indicate):
# CeilingsMax.wrl (the entire 3D of the cave, modified to show its paleo-state),
# CeilingsMin.wrl (3D of the "internal ceilings" in the cave, the obstacles between
# the ground and the highest Z), GroundOK.wrl (the ground level, presumably utilised
# by the societies in the past), GU.wrl (3D of the analysed depiction),
# Access.shp (the entrance used in the past).
# PUT THE FILES IN THE SAME FOLDER, "C/:Paleospeleology". (you need to create it)
# ---------------------------------------------------------------------------
# Import arcpy module
import arcpy
from arcpy import env
from arcpy.sa import *
arcpy.CheckOutExtension("3D")
env.workspace = "C:/Paleospeleology"
arcpy.env.overwriteOutput = True
# Local variables:
GroundOK_wrl = "GroundOK.wrl"
GroundOK_shp = "GroundOK.shp"
GroundOK_tif = "GroundOK.tif"
GroundOK25_tif = "GroundOK25.tif"
CeilingsMax_wrl = "CeilingsMax.wrl"
CeilingsMax_shp = "CeilingsMax.shp"
CeilingsMax_tif = "CeilingsMax.tif"
CeilingsMin_wrl = "CeilingsMin.wrl"
CeilingsMin_shp = "CeilingsMin.shp"
CeilingsMin_tif = "CeilingsMin.tif"
CeilingsOK_tif = "CeilingsOK.tif"
Slope_tif = "Slope.tif"
Height_tif = "Height.tif"
P1_tif = "P1.tif"
P2P3_tif = "P2P3.tif"
OPosture_tif = "OPosture.tif"
OPosition_tif = "OPosition.tif"
OP_shp = "OP.shp"
Target_shp = "Target.shp"
GU_wrl = "GU.wrl"
GU3D_shp = "GU3D.shp"
GU3D_tif = "GU3D.tif"
GU_shp = "GU.shp"
GUcentroid_shp = "GUcentroid.shp"
Buffer_shp = "Buffer.shp"
OPs_shp = "OPs.shp"
LS_shp = "LS.shp"
LSLight_shp = "LSLight.shp"
LSSelect_shp = "LSSelect.shp"
ObserverStatistics_dbf = "ObserverStatistics.dbf"
ObserverFrequency_tif = "ObserverFrequency.tif"
TargetStatistics_dbf = "TargetStatistics.dbf"
TargetFrequency_tif = "TargetFrequency.tif"
LyingDown_tif = "LyingDown.tif"
Standing_tif = "Standing.tif"
Stooping_tif = "Stooping.tif"
VisibilityRange_tif = "VisibilityRange.tif"
VisibilityLyingDown_tif = "VisibilityLyingDown.tif"
VisibilityStooping_tif = "VisibilityStooping.tif"
VisibilityStanding_tif = "VisibilityStanding.tif"
EstimatedPositionArtist_shp = "EstimatedPositionArtist.shp"
Access_shp = "Access.shp"
CostOK_tif = "CostOK.tif"
CostWalking_tif = "CostWalking.tif"
CostClimbing_tif = "CostClimbing.tif"
CostClimbingOK_tif = "CostClimbingOK.tif"
Cost_tif = "Cost.tif"
CostBack_shp = "CostBack.shp"
LCP_tif = "LCP.tif"
CostDistance_tif = "CostDistance.tif"
CostBack_tif = "CostBack.tif"
LCP_shp = "LCP.shp"
SpeedWalking_tif = "SpeedWalking.tif"
SpeedClimbing_tif = "SpeedClimbing.tif"
SecondsWalking_tif = "SecondsWalking.tif"
SecondsClimbing_tif = "SecondsClimbing.tif"
Seconds_tif = "Seconds.tif"
Time_tif = "Time.tif"
Time_shp = "Time.shp"
CostLCP_tif = "CostLCP.tif"
CostLCP_shp = "CostLCP.shp"
GreaterDifficulties_tif = "GreaterDifficulties.tif"
# Execute CreateFolder
arcpy.CreateFolder_management("C:/Paleospeleology", "Topography")
# for standard output
arcpy.env.workspace = "C:/Paleospeleology/Topography"
# Process: Import 3D Files
arcpy.Import3DFiles_3d(GroundOK_wrl, GroundOK_shp, "ONE_ROOT_ONE_FEATURE", "PROJCS['ETRS_1989_ETRS-TM30',GEOGCS['GCS_ETRS_1989',DATUM['D_ETRS_1989',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-3.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]];-5120900 -9998100 10000;-100000 10000;-100000 10000;0,001;0,001;0,001;IsHighPrecision", "Z_IS_UP", "*", "", "")
# Process: Multipatch to Raster
arcpy.MultipatchToRaster_conversion(GroundOK_shp, GroundOK_tif, "0,05")
# Process: Multipatch to Raster
arcpy.MultipatchToRaster_conversion(GroundOK_shp, GroundOK25_tif, "0,25")
# Process: Import 3D Files
arcpy.Import3DFiles_3d(CeilingsMax_wrl, CeilingsMax_shp, "ONE_ROOT_ONE_FEATURE", "PROJCS['ETRS_1989_ETRS-TM30',GEOGCS['GCS_ETRS_1989',DATUM['D_ETRS_1989',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-3.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]];-5120900 -9998100 10000;-100000 10000;-100000 10000;0,001;0,001;0,001;IsHighPrecision", "Z_IS_UP", "*", "", "")
# Process: Multipatch to Raster
arcpy.MultipatchToRaster_conversion(CeilingsMax_shp, CeilingsMax_tif, "0,05")
# Process: Import 3D Files
arcpy.Import3DFiles_3d(CeilingsMin_wrl, CeilingsMin_shp, "ONE_ROOT_ONE_FEATURE", "PROJCS['ETRS_1989_ETRS-TM30',GEOGCS['GCS_ETRS_1989',DATUM['D_ETRS_1989',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-3.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]];-5120900 -9998100 10000;-100000 10000;-100000 10000;0,001;0,001;0,001;IsHighPrecision", "Z_IS_UP", "*", "", "")
# Process: Multipatch to Raster
arcpy.MultipatchToRaster_conversion(CeilingsMin_shp, CeilingsMin_tif, "0,05")
# Process: Mosaic To New Raster
arcpy.MosaicToNewRaster_management("CeilingsMax.tif;CeilingsMin.tif", "C:\\Paleospeleology\Topography", \
"CeilingsOK.tif", "PROJCS['ETRS_1989_ETRS-TM30',GEOGCS['GCS_ETRS_1989',DATUM['D_ETRS_1989',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-3.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]",\
"32_BIT_FLOAT", "0,05", "1", "MINIMUM","REJECT")
# Process: Slope
arcpy.gp.Slope_sa(GroundOK_tif, Slope_tif, "DEGREE", "1")
# Process: Raster Calculator
Height = (Raster(CeilingsOK_tif) - Raster(GroundOK_tif))
Height.save(Height_tif)
# Execute CreateFolder
arcpy.CreateFolder_management("C:/Paleospeleology", "Rock-Art")
# for standard output
arcpy.env.workspace = "C:/Paleospeleology/Rock-Art"
# Process: Import 3D Files
arcpy.Import3DFiles_3d(GU_wrl, GU3D_shp, "ONE_ROOT_ONE_FEATURE", "PROJCS['ETRS_1989_ETRS-TM30',GEOGCS['GCS_ETRS_1989',DATUM['D_ETRS_1989',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-3.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]];-5120900 -9998100 10000;-100000 10000;-100000 10000;0,001;0,001;0,001;IsHighPrecision", "Z_IS_UP", "*", "", "")
# Process: Multipatch to Raster
arcpy.MultipatchToRaster_conversion(GU3D_shp, "C:/Paleospeleology/Rock-Art/GU3D.tif", "0,05")
# Execute FeatureVerticesToPoints
arcpy.FeatureVerticesToPoints_management(GU3D_shp, GU_shp, "ALL")
# Use FeatureToPoint function to find a point inside each park
arcpy.FeatureToPoint_management(GU3D_shp, GUcentroid_shp, "CENTROID")
# Execute CreateFolder
arcpy.CreateFolder_management("C:/Paleospeleology", "Metadata")
# for standard output
arcpy.env.workspace = "C:/Paleospeleology/Metadata"
# Process: Raster Calculator
Aa_tif = SetNull("C:/Paleospeleology/Topography/Height.tif", "C:/Paleospeleology/Topography/Height.tif", "VALUE < 0,24")
# Process: Raster Calculator
Ba_tif = SetNull("C:/Paleospeleology/Topography/Slope.tif", Aa_tif, "VALUE >= 30")
# Process: Raster Calculator
Aaa_tif = SetNull(Ba_tif, "0,24", "VALUE >= 0,71")
Aaa_tif.save(P1_tif)
# Process: Raster Calculator
A_tif = SetNull("C:/Paleospeleology/Topography/Height.tif", "C:/Paleospeleology/Topography/Height.tif", "VALUE < 0,71")
# Process: Raster Calculator
B_tif = SetNull("C:/Paleospeleology/Topography/Slope.tif", A_tif, "VALUE >= 30")
# Process: Raster Calculator
D_tif = Con(B_tif, "1,599", B_tif, "VALUE >= 1,599")
# Process: Raster Calculator (5)
E_tif = Con(D_tif, "0,71", D_tif, "VALUE < 1,599")
E_tif.save(P2P3_tif)
# Process: Mosaic To New Raster
arcpy.MosaicToNewRaster_management("P1.tif;P2P3.tif", "C:\\Paleospeleology\Metadata", \
"OPosture.tif", "PROJCS['ETRS_1989_ETRS-TM30',GEOGCS['GCS_ETRS_1989',DATUM['D_ETRS_1989',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-3.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]",\
"32_BIT_FLOAT", "0,05", "1", "SUM","REJECT")
# Process: Raster Calculator
F_tif = (Raster("C:/Paleospeleology/Topography/GroundOK25.tif")+Raster(OPosture_tif))
F_tif.save(OPosition_tif)
# Process: Raster to Point
arcpy.RasterToPoint_conversion(F_tif, OP_shp, "VALUE")
# Process: Buffer analysis
arcpy.Buffer_analysis("C:/Paleospeleology/Rock-Art/GU.shp", Buffer_shp, "2,99 Meters", "FULL", "ROUND", "NONE", "", "PLANAR")
# Process: Clip analysis
arcpy.Clip_analysis(OP_shp, Buffer_shp, OPs_shp)
# Process: Construct Sight Lines
arcpy.ConstructSightLines_3d(OPs_shp, "C:/Paleospeleology/Rock-Art/GU.shp", LS_shp, "grid_code", "Shape.Z", "<None>", "1", "NOT_OUTPUT_THE_DIRECTION")
# Process: Intervisibility
arcpy.Intervisibility_3d(LS_shp, "C:/Paleospeleology/Topography/CeilingsMax.shp", "VISIBLE")
# Process: Add Geometry
arcpy.AddGeometryAttributes_management(LS_shp, "LENGTH_3D", "METERS", "", "PROJCS['ETRS_1989_ETRS-TM30',GEOGCS['GCS_ETRS_1989',DATUM['D_ETRS_1989',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-3.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]")
# Process: Select
arcpy.Select_analysis(LS_shp, LSLight_shp, "\"LENGTH_3D\" <= 2.99")
# Process: Select
arcpy.Select_analysis(LSLight_shp, LSSelect_shp, "\"VISIBLE\" = 1")
# Process: Summary Statistics
arcpy.Statistics_analysis(LSSelect_shp, ObserverStatistics_dbf, "OID_OBSERV COUNT", "OID_OBSERV")
# Process: Join Field
arcpy.JoinField_management(OPs_shp, "FID", ObserverStatistics_dbf, "OID_OBSERV", "COUNT_OID_")
# Process: Add Field
arcpy.AddField_management(OPs_shp, "Frequency", "DOUBLE", 100, 10, 10, "", "NON_NULLABLE", "NON_REQUIRED")
## input file
file = OPs_shp
field_to_max = 'COUNT_OID_' ### field with values
field_to_update = 'Frequency' ### Field to be updated
values = []
# Process: Max
with arcpy.da.SearchCursor(file, field_to_max) as cursor, arcpy.da.UpdateCursor(file, [field_to_max, field_to_update]) as upd_cursor:
for row in cursor:
values.append(row[0])
max_num = max(values) ### get max value
for row in upd_cursor:
value = (float(row[0]) / float(max_num)) * 100
row[1] = float(value) ### calculate value
upd_cursor.updateRow(row) ### set value
# Process: Point to Raster
arcpy.PointToRaster_conversion(OPs_shp, "Frequency", ObserverFrequency_tif, "MAXIMUM", "NONE", "0,25")
# Process: Summary Statistics
arcpy.Statistics_analysis(LSSelect_shp, TargetStatistics_dbf, "OID_TARGET COUNT", "OID_TARGET")
# Process: Join Field
arcpy.JoinField_management("C:/Paleospeleology/Rock-Art/GU.shp", "FID", TargetStatistics_dbf, "OID_TARGET", "COUNT_OID_")
# Process: Add Field
arcpy.AddField_management("C:/Paleospeleology/Rock-Art/GU.shp", "Frequency", "DOUBLE", 100, 10, 10, "", "NON_NULLABLE", "NON_REQUIRED")
## input file
file2 = "C:/Paleospeleology/Rock-Art/GU.shp"
field_to_max2 = 'COUNT_OID_' ### field with values
field_to_update2 = 'Frequency' ### Field to be updated
values2 = []
with arcpy.da.SearchCursor(file2, [field_to_max2]) as cursor, arcpy.da.UpdateCursor(file2, [field_to_max2, field_to_update2]) as upd_cursor:
for row in cursor:
values2.append(row[0])
max_num2 = max(values2) ###
for row in upd_cursor:
value2 = (float(row[0]) / float(max_num2)) * 100
row[1] = float(value2) ### calculate value
upd_cursor.updateRow(row) ### set value
# Process: Point to Raster
arcpy.PointToRaster_conversion("C:/Paleospeleology/Rock-Art/GU.shp", "Frequency", TargetFrequency_tif, "MAXIMUM", "NONE", "0,25")
# for standard output
arcpy.env.workspace = "C:/Paleospeleology/Metadata"
# Process: Raster Calculator
XA_tif = SetNull("C:/Paleospeleology/Topography/Slope.tif", "C:/Paleospeleology/Topography/Height.tif", "VALUE >= 45")
# Process: Raster Calculator
XB_tif = SetNull(XA_tif, XA_tif, "VALUE < 0,24")
# Process: Raster Calculator
XC_tif = Con(XB_tif, "1,86", XB_tif, "VALUE >= 1,86")
# Process: Raster Calculator
XD_tif = Con(XC_tif, "11,607", XC_tif, "VALUE > 0")
# Process: Raster Calculator
XE_tif = Con(XD_tif, "6,217", XD_tif, "VALUE > 0")
# Process: Raster Calculator
XF_tif = (XE_tif*XC_tif)
# Process: Raster Calculator
CostWalking = (XD_tif - XF_tif)
CostWalking.save(CostWalking_tif)
# Process: Raster Calculator
XG_tif = SetNull("C:/Paleospeleology/Topography/Slope.tif", "C:/Paleospeleology/Topography/Slope.tif", "VALUE < 45")
# Process: Raster Calculator
XH_tif = Con(XG_tif, "-87,48216", XG_tif, "VALUE > 0")
# Process: Raster Calculator
XI_tif = Con(XG_tif, "1,95901", XG_tif, "VALUE > 0")
# Process: Raster Calculator
XJ_tif = (XI_tif*XG_tif)
# Process: Raster Calculator
CostClimbing = (XH_tif + XJ_tif)
CostClimbing.save(CostClimbing_tif)
# Process: Raster Calculator
DegreesToGradians = Con("C:/Paleospeleology/Topography/Slope.tif", "57,296", "C:/Paleospeleology/Topography/Slope.tif", "VALUE > 0")
# Process: Raster Calculator
SlopeInGradians = ("C:/Paleospeleology/Topography/Slope.tif" / DegreesToGradians)
# Process: Raster Calculator
ElevationGain = Tan(SlopeInGradians)
# Process: Raster Calculator
CostClimbingOK = (ElevationGain * CostClimbing)
CostClimbingOK.save(CostClimbingOK_tif)
# Process: Mosaic To New Raster
arcpy.MosaicToNewRaster_management("CostWalking.tif;CostClimbingOK.tif", "C:\\Paleospeleology\Metadata", \
"CostOK.tif", "PROJCS['ETRS_1989_ETRS-TM30',GEOGCS['GCS_ETRS_1989',DATUM['D_ETRS_1989',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-3.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]",\
"32_BIT_FLOAT", "0,05", "1", "MAXIMUM","REJECT")
# Process: Raster Calculator
Cost = SetNull(CostOK_tif, CostOK_tif, "VALUE < 0")
Cost.save(Cost_tif)
# Execute CreateFolder
arcpy.CreateFolder_management("C:/Paleospeleology", "Accessibility")
# for standard output
arcpy.env.workspace = "C:/Paleospeleology/Accessibility"
# Process: Cost Distance
CostDistance = CostDistance("C:/Paleospeleology/Access.shp", "C:/Paleospeleology/Metadata/Cost.tif", "", "CostBack.tif")
CostDistance.save(CostDistance_tif)
# Process: Near
arcpy.analysis.Near("C:/Paleospeleology/Rock-Art/GUcentroid.shp", "C:/Paleospeleology/Metadata/OPs.shp")
# Process: Join Field
arcpy.JoinField_management("C:/Paleospeleology/Metadata/OPs.shp", "FID", "C:/Paleospeleology/Rock-Art/GUcentroid.shp", "NEAR_FID", "NEAR_FID;NEAR_DIST")
# Process: Select
arcpy.Select_analysis("C:/Paleospeleology/Metadata/OPs.shp", "C:/Paleospeleology/Accessibility/EstimatedPositionArtist.shp", "\"NEAR_FID\" > 0")
# Process: Join Field
arcpy.JoinField_management("C:/Paleospeleology/Accessibility/EstimatedPositionArtist.shp", "NEAR_FID", "C:/Paleospeleology/Rock-Art/GUcentroid.shp", "NEAR_FID", "GU")
# Process: Cost Path
outCostPath = CostPath("C:/Paleospeleology/Accessibility/EstimatedPositionArtist.shp", "C:/Paleospeleology/Accessibility/CostDistance.tif", "CostBack.tif", "EACH_CELL")
outCostPath.save(LCP_tif)
# Process: Raster to Polyline
arcpy.RasterToPolyline_conversion(LCP_tif, LCP_shp, "ZERO", "0", "SIMPLIFY", "Value")
# Process: Join Field
arcpy.JoinField_management(LCP_shp, "GRID_CODE", LCP_tif, "Value", "PATHCOST")
# Process: Add Surface Information
arcpy.ddd.AddSurfaceInformation(LCP_shp, "C:/Paleospeleology/Topography/GroundOK.tif", "SURFACE_LENGTH")
# Process: Raster Calculator (18)
K_tif = Con("C:/Paleospeleology/Metadata/CostWalking.tif", "1", "C:/Paleospeleology/Metadata/CostWalking.tif", "VALUE > 0")
# Process: Raster Calculator (19)
SpeedWalking = (K_tif / "C:/Paleospeleology/Metadata/CostWalking.tif")
# Process: Raster Calculator (20)
SpeedWalkingOK = Con(SpeedWalking, "1,23", SpeedWalking, "VALUE > 1,23")
SpeedWalkingOK.save(SpeedWalking_tif)
# Process: Raster Calculator (21)
L_tif = Con("C:/Paleospeleology/Metadata/CostClimbing.tif", "1", "C:/Paleospeleology/Metadata/CostClimbing.tif", "VALUE > 0")
# Process: Raster Calculator (22)
SpeedClimbing = (L_tif / "C:/Paleospeleology/Metadata/CostClimbing.tif")
# Process: Raster Calculator (23)
SpeedClimbingOK = Con(SpeedClimbing, "0,02", SpeedClimbing, "VALUE < 0,02")
SpeedClimbingOK.save(SpeedClimbing_tif)
# Process: Raster Calculator (24)
M_tif = Con("C:/Paleospeleology/Metadata/CostWalking.tif", "0,05", "C:/Paleospeleology/Metadata/CostWalking.tif", "VALUE > 0")
# Process: Raster Calculator (25)
SecondsWalking = (M_tif / SpeedWalking_tif)
SecondsWalking.save(SecondsWalking_tif)
# Process: Raster Calculator (26)
N_tif = Con("C:/Paleospeleology/Metadata/CostClimbing.tif", "0,05", "C:/Paleospeleology/Metadata/CostClimbing.tif", "VALUE > 0")
# Process: Raster Calculator (27)
SecondsClimbing = (N_tif / SpeedClimbing_tif)
# Process: Raster Calculator (28)
SecondsClimbingOK = (SecondsClimbing * ElevationGain)
SecondsClimbingOK.save(SecondsClimbing_tif)
# Process: Mosaic To New Raster
arcpy.MosaicToNewRaster_management("SecondsWalking.tif;SecondsClimbing.tif", "C:\\Paleospeleology\Accessibility", \
"Seconds.tif", "PROJCS['ETRS_1989_ETRS-TM30',GEOGCS['GCS_ETRS_1989',DATUM['D_ETRS_1989',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-3.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]",\
"32_BIT_FLOAT", "0,05", "1", "MAXIMUM","REJECT")
# Process: Extract By Mask
outExtractByMask = ExtractByMask("Seconds.tif", "LCP.shp")
outExtractByMask.save(Time_tif)
# Process: Raster To Point
arcpy.RasterToPoint_conversion(Time_tif, Time_shp, "VALUE")
# Process: Add Field
arcpy.AddField_management(Time_shp, "Minutes", "DOUBLE", 100, 10, 10, "", "NON_NULLABLE", "NON_REQUIRED")
## input file
file = Time_shp
field_to_sum = 'grid_code' ### field with values
field_to_update = 'Minutes' ### Field to be updated
values = []
# Process: Max
with arcpy.da.SearchCursor(file, field_to_sum) as cursor, arcpy.da.UpdateCursor(file, [field_to_sum, field_to_update]) as upd_cursor:
for row in cursor:
values.append(row[0])
summed_total = sum(values) ### sum values
for row in upd_cursor:
value = (float(summed_total)) / 60
row[1] = float(value) ### calculate value
upd_cursor.updateRow(row) ### set value
# Process: Extract By Mask
outExtractByMask = ExtractByMask("C:/Paleospeleology/Metadata/CostOK.tif", "LCP.shp")
outExtractByMask.save(CostLCP_tif)
# Process: Raster To Point
arcpy.RasterToPoint_conversion(CostLCP_tif, CostLCP_shp, "VALUE")
# Process: Kernel Density
arcpy.gp.KernelDensity_sa(CostLCP_shp, "grid_code", GreaterDifficulties_tif, "0,25", "2", "SQUARE_MAP_UNITS", "DENSITIES", "PLANAR")
# Process: Add Surface Information
arcpy.ddd.AddSurfaceInformation("C:/Paleospeleology/Rock-Art/GUcentroid.shp", "C:/Paleospeleology/Rock-Art/GU3D.tif", "Z")
# Process: Add Field
arcpy.AddField_management("C:/Paleospeleology/Rock-Art/GUcentroid.shp", "GUs_Z", "DOUBLE", 100, 10, 10, "", "NON_NULLABLE", "NON_REQUIRED")
# Process: Calculate Field
arcpy.CalculateField_management("C:/Paleospeleology/Rock-Art/GUcentroid.shp", "GUs_Z", "[Z]", "VB", "")
# Process: Join Field
arcpy.JoinField_management("C:/Paleospeleology/Accessibility/EstimatedPositionArtist.shp", "NEAR_FID", "C:/Paleospeleology/Rock-Art/GUcentroid.shp", "NEAR_FID", "GUs_Z")
# Process: Add Surface Information
arcpy.ddd.AddSurfaceInformation("C:/Paleospeleology/Accessibility/EstimatedPositionArtist.shp", "C:/Paleospeleology/Topography/GroundOK.tif", "Z")
# Process: Add Field
arcpy.AddField_management("C:/Paleospeleology/Accessibility/EstimatedPositionArtist.shp", "Distance", "DOUBLE", 100, 10, 10, "", "NON_NULLABLE", "NON_REQUIRED")
# Process: Calculate Field
arcpy.CalculateField_management("C:/Paleospeleology/Accessibility/EstimatedPositionArtist.shp", "Distance", "[GUs_Z] - [Z]", "VB", "")
# Process: Add Field
arcpy.AddField_management("C:/Paleospeleology/Accessibility/EstimatedPositionArtist.shp", "Posture", "TEXT", "", "", 50, "")
# Process: Calculate Field
arcpy.CalculateField_management("C:/Paleospeleology/Accessibility/EstimatedPositionArtist.shp", "Posture", "a", "VB", "If [Distance]>=0 and [Distance]<=1 then\\na = \"Crouching/Kneeling/Sitting/Lying Down\"\\nend if\\n\\nIf [Distance]>1 and [Distance]<=1.3 then\\na = \"Leaning\"\\nend if\\n\\nIf [Distance]>1.3 and [Distance]<=1.7 then\\na = \"Leaning/Upright\"\\nend if\\n\\nIf [Distance]>1.7 and [Distance]<=1.8 then\\na = \"Upright\"\\nend if\\n\\nIf [Distance]>=1.8 then\\na = \"Elevated\"\\nend if")
# Execute CreateFolder
arcpy.CreateFolder_management("C:/Paleospeleology", "Visibility and Capacity")
# for standard output
arcpy.env.workspace = "C:/Paleospeleology/Visibility and Capacity"
# Process: Raster Calculator
Gaa_tif = Raster("C:/Paleospeleology/Metadata/OPosture.tif")
# Process: Raster Calculator
Ga_tif = SetNull(Gaa_tif, Gaa_tif, "VALUE >= 1,599")
# Process: Raster Calculator
Gaa_tif = SetNull(Ga_tif, 0, "VALUE = 0,71")
Gaa_tif.save(LyingDown_tif)
# Process: Raster Calculator
G_tif = SetNull("C:/Paleospeleology/Metadata/OPosture.tif", 0, "VALUE < 1,599")
G_tif.save(Standing_tif)
# Process: Raster Calculator
H_tif = SetNull(Ga_tif, 0, "VALUE = 0,24")
H_tif.save(Stooping_tif)
# Process: Reclassify
outReclass1 = Reclassify("C:/Paleospeleology/Metadata/ObserverFrequency.tif", "Value", RemapRange([[0.01,33.33,1],[33.33,66.66,2],[66.66,100,3]]),"DATA")
outReclass1.save(VisibilityRange_tif)
# Process: Raster Calculator
Ia_tif = (Gaa_tif+VisibilityRange_tif)
Ia_tif.save(VisibilityLyingDown_tif)
# Process: Raster Calculator
I_tif = (G_tif+VisibilityRange_tif)
I_tif.save(VisibilityStanding_tif)
# Process: Raster Calculator
J_tif = (H_tif+VisibilityRange_tif)
J_tif.save(VisibilityStooping_tif)
# Process: Add Field
arcpy.AddField_management(VisibilityStanding_tif, "Occupancy", "DOUBLE", 100, 10, 10, "", "NON_NULLABLE", "NON_REQUIRED")
## input file
file = VisibilityStanding_tif
field_to_take = 'Count' ### field with values
field_to_update = 'Occupancy' ### Field to be updated
values = []
# Process: CalculateMax
with arcpy.da.SearchCursor(file, field_to_take) as cursor, arcpy.da.UpdateCursor(file, [field_to_take, field_to_update]) as upd_cursor:
for row in cursor:
values.append(row[0])
for row in upd_cursor:
value = (float(row[0]) * 0.0625) / 0.77
row[1] = float(value) ### calculate value
upd_cursor.updateRow(row) ### set value
# Process: Add Field
arcpy.AddField_management(VisibilityStooping_tif, "Occupancy", "DOUBLE", 100, 10, 10, "", "NON_NULLABLE", "NON_REQUIRED")
## input file
file = VisibilityStooping_tif
field_to_take = 'Count' ### field with values
field_to_update = 'Occupancy' ### Field to be updated
values = []
# Process: CalculateMax
with arcpy.da.SearchCursor(file, field_to_take) as cursor, arcpy.da.UpdateCursor(file, [field_to_take, field_to_update]) as upd_cursor:
for row in cursor:
values.append(row[0])
for row in upd_cursor:
value = (float(row[0]) * 0.0625) / 0.9
row[1] = float(value) ### calculate value
upd_cursor.updateRow(row) ### set value
# Process: Add Field
arcpy.AddField_management(VisibilityLyingDown_tif, "Occupancy", "DOUBLE", 100, 10, 10, "", "NON_NULLABLE", "NON_REQUIRED")
## input file
file = VisibilityLyingDown_tif
field_to_take = 'Count' ### field with values
field_to_update = 'Occupancy' ### Field to be updated
values = []
# Process: CalculateMax
with arcpy.da.SearchCursor(file, field_to_take) as cursor, arcpy.da.UpdateCursor(file, [field_to_take, field_to_update]) as upd_cursor:
for row in cursor:
values.append(row[0])
for row in upd_cursor:
value = (float(row[0]) * 0.0625) / 1.75
row[1] = float(value) ### calculate value
upd_cursor.updateRow(row) ### set value