Skip to content

Commit 5fd1e5a

Browse files
Add files via upload
1 parent 0078ff6 commit 5fd1e5a

File tree

2 files changed

+34
-58
lines changed

2 files changed

+34
-58
lines changed

ArcGISProWrapperBegrensSkade_ImpactMap.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@
3535
logger.setLevel(logging.DEBUG)
3636
############################################################
3737

38-
3938
############## READ PARAMETERS ############################
4039
excavation_polys_fl = arcpy.GetParameter(0)
4140
output_folder = arcpy.GetParameterAsText(1)
4241
output_name = arcpy.GetParameterAsText(2)
4342
output_resolution = arcpy.GetParameterAsText(3)
4443
coord_syst = arcpy.GetParameterAsText(4)
4544

45+
logger.info("------------------------------NEW RUN: " + str(output_name)+"-------------------------------")
46+
4647
sr = arcpy.SpatialReference()
4748
sr.loadFromString(coord_syst)
4849
output_proj = sr.PCSCode
@@ -99,10 +100,9 @@
99100
os.remove(dtb_proj_raster)
100101
arcpy.ProjectRaster_management(dtb_raster, dtb_proj_raster, output_proj)
101102
dtb_raster = dtb_proj_raster
102-
logger.info("DONE raster projection")
103+
logger.info("DONE raster projection")
103104

104105
#Checks if raster area and requested resolution is too demanding and if clipping is necessary
105-
logger.debug("START raster clipping")
106106
for row in arcpy.da.SearchCursor(excavation_polys_fl, ['SHAPE@']):
107107
extent = row[0].extent
108108
xmin = extent.XMin - CALCULATION_RANGE
@@ -113,11 +113,12 @@
113113
area = abs(ymax-ymin)*abs(xmax-xmin)
114114
dtb_clip_raster = False
115115
if float(output_resolution)/area < 10/820000:
116+
logger.debug("START raster clipping")
116117
arcpy.AddWarning("High output resolution and/or large raster - clipping raster!")
117118
dtb_clip_raster = "clip_raster"
118119
arcpy.management.Clip(dtb_raster, extent_str, dtb_clip_raster)
119120
dtb_raster = dtb_clip_raster
120-
logger.debug("DONE raster clipping")
121+
logger.debug("DONE raster clipping")
121122

122123
#Resampels raster to the specified resolution
123124
dtb_raster_resample = "resampl_raster"
@@ -128,7 +129,7 @@
128129
logger.debug("DONE raster resampling")
129130
n_cols = arcpy.management.GetRasterProperties(dtb_raster, "COLUMNCOUNT")
130131
n_rows = arcpy.management.GetRasterProperties(dtb_raster, "ROWCOUNT")
131-
logger.info("Dtb raster cols and rows after resampling: " + str(n_cols) + ", " + str(n_rows) + "\n")
132+
logger.info("Dtb raster cols and rows after resampling: " + str(n_cols) + ", " + str(n_rows) )
132133

133134
#Create a tif file from the raster. Necessary for input to GDAL.
134135
raster_desc = arcpy.Describe(dtb_raster)
@@ -219,5 +220,5 @@
219220
lyr_impactmap = lyr_path + os.sep + "SETTLEMENT_IMPACT_FIELD.lyrx"
220221
result_lyr = Utils_arcpy.addLayer(pMap, result_raster, lyr_impactmap, output_name)
221222

222-
logger.info("------------------------------DONE-------------------------------")
223+
logger.info("------------------------------DONE-------------------------------\n ")
223224

BegrensSkade.py

Lines changed: 27 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,11 @@ def mainBegrensSkade_ImpactMap(
475475

476476
# "Loading construction zone to memory..."
477477

478-
logger.debug("Calling get_construction_corners_from_ArcGIS_json with json: {}".format(excavationJson))
478+
logger.debug("Get construction corners from json")
479+
#logger.debug("Calling get_construction_corners_from_ArcGIS_json with json: {}".format(excavationJson))
479480
construction_area_corners = BegrensSkadeLib.get_construction_corners_from_ArcGIS_json(excavationJson, CONSTR_RESAMPLE_LEN, logger)
480481

481-
logger.info("START calculate settlements")
482+
logger.info("START calculate settlements - iterating raster pixels")
482483

483484
dataset = gdal.Open(str(dtb_raster))
484485
band = dataset.GetRasterBand(1)
@@ -497,27 +498,23 @@ def mainBegrensSkade_ImpactMap(
497498
min_near_dist = 9999
498499
max_sv_long = 0
499500

500-
logger.info(
501-
"xOrigin, yOrigin, rows, cols, pixelWidht, pixelHeight: "
502-
+ str(xOrigin)
503-
+ ", "
504-
+ str(yOrigin)
505-
+ ", "
506-
+ str(rows)
507-
+ ", "
508-
+ str(cols)
509-
+ ", "
510-
+ str(pixelWidth)
511-
+ ", "
512-
+ str(pixelHeight)
513-
)
501+
tot_px = rows*cols
502+
px = 0
503+
progress = 0
504+
505+
#logger.info("xOrigin, yOrigin, rows, cols, pixelWidht, pixelHeight: "+ str(xOrigin)+ ", "+ str(yOrigin)+ ", "+ str(rows)+ ", "+ str(cols)+ ", "+ str(pixelWidth)+ ", "+ str(pixelHeight))
514506

515507
for row in range(0, rows):
516508
for col in range(0, cols):
517509
x = xOrigin + col * pixelWidth
518510
y = yOrigin - row * pixelHeight
519511
near_dist_sqr = BegrensSkadeLib.near_analysis_sqr(x, y, construction_area_corners)
520512
if near_dist_sqr > CALCULATION_RANGE**2:
513+
px += 1
514+
new_progress = int(100 * px / tot_px)
515+
if new_progress > progress:
516+
progress = new_progress
517+
logger.info("Progress: " + str(progress) + " %")
521518
continue
522519
dtb = inData[row][col]
523520
near_dist = np.sqrt(near_dist_sqr)
@@ -529,7 +526,6 @@ def mainBegrensSkade_ImpactMap(
529526

530527
else:
531528
# Evaluating Janbu long term settlements
532-
533529
# Lav poretrykksreduksjon
534530
# Middels poretrykksreduksjon
535531
# Høy poretrykksreduksjon
@@ -555,20 +551,9 @@ def mainBegrensSkade_ImpactMap(
555551
janbu_m,
556552
consolidation_time,
557553
)
558-
if count_clay < 50:
559-
logger.info(
560-
"row, col, SV_LONG, near_dist, dtb: "
561-
+ str(row)
562-
+ ","
563-
+ str(col)
564-
+ ","
565-
+ str(sv_long)
566-
+ ", "
567-
+ str(near_dist)
568-
+ ", "
569-
+ str(dtb)
570-
)
571-
count_clay += 1
554+
#if count_clay < 50:
555+
# logger.info( "row, col, SV_LONG, near_dist, dtb: "+ str(row)+ ","+ str(col)+ ","+ str(sv_long)+ ", "+ str(near_dist)+ ", "+ str(dtb))
556+
count_clay += 1
572557
max_sv_long = max(max_sv_long, sv_long)
573558

574559
if bShortterm:
@@ -600,27 +585,17 @@ def mainBegrensSkade_ImpactMap(
600585
sv_short = 0.0
601586

602587
outData[row, col] = sv_short + sv_long
603-
604-
logger.info("COUNT_CRUST: " + str(count_crust))
605-
logger.info("COUNT_CLAY: " + str(count_clay))
606-
logger.info("MIN NEAR DIST: " + str(min_near_dist))
607-
logger.info("MAX SV LONG: " + str(max_sv_long))
608-
609-
count = 0
610-
611-
for row in range(0, rows):
612-
for col in range(0, cols):
613-
if row in [8, 9, 10] and col in [30, 31, 32, 33, 34, 35]:
614-
logger.info(
615-
"row, col: "
616-
+ str(row)
617-
+ ", "
618-
+ str(col)
619-
+ ": "
620-
+ str(outData[row, col])
621-
)
622-
count += 1
623-
588+
px += 1
589+
new_progress = int(100*px/tot_px)
590+
if new_progress > progress:
591+
progress = new_progress
592+
logger.info("Progress: " + str(progress) + " %")
593+
594+
logger.info("Px, tot px: " + str(px) + ", " + str(tot_px))
595+
logger.info("Count crust: " + str(count_crust))
596+
logger.info("Count clay: " + str(count_clay))
597+
logger.info("Min near dist: " + str(min_near_dist))
598+
logger.info("Max near dist: " + str(max_sv_long))
624599
logger.info("STOP calculating settlements")
625600
logger.info("START writing results")
626601

0 commit comments

Comments
 (0)