|
123 | 123 | structure_field = None |
124 | 124 | status_field = None |
125 | 125 |
|
126 | | -############## SET PROJECTION ########################### |
127 | | -working_proj = Utils_arcpy.getProjCodeFromFC(building_polys_fl) |
| 126 | +############## GET INPUT PROJECTIONS #################### |
| 127 | +building_proj = Utils_arcpy.getProjCodeFromFC(building_polys_fl) |
128 | 128 | excavation_proj = Utils_arcpy.getProjCodeFromFC(excavation_polys_fl) |
129 | 129 |
|
130 | | -######## PROJECT EXCAVATION POLY IF NECESSARY ########### |
131 | | -excavation_polys_projected = False |
132 | | -if excavation_proj != working_proj: |
133 | | - arcpy.AddMessage("Projecting excavation polygon..") |
134 | | - excavation_polys_projected = output_folder + os.sep + "exc_proj.shp" |
135 | | - arcpy.Project_management(excavation_polys_fl, excavation_polys_projected, working_proj) |
136 | | - excavation_polys_fl = excavation_polys_projected |
| 130 | +### GET EXCAVATION ANS BUILDINGS ON SAME PROJECTION ##### |
| 131 | +excavation_polys_matched = False |
| 132 | +if excavation_proj != building_proj: |
| 133 | + arcpy.AddMessage("Matching input projections before clip..") |
| 134 | + excavation_polys_matched = output_folder + os.sep + "exc_match.shp" |
| 135 | + arcpy.Project_management(excavation_polys_fl, excavation_polys_matched, building_proj) |
| 136 | + excavation_polys_fl = excavation_polys_matched |
137 | 137 |
|
138 | 138 | ################ GET EXCAVATION INFO ##################### |
139 | 139 | excavation_outline_as_json = Utils_arcpy.getConstructionAsJson(excavation_polys_fl) |
140 | | -buildingsClipExtent = Utils_arcpy.getBuildingsClipExtentFromConstruction(excavation_outline_as_json, CALCULATION_RANGE, working_proj, logger) |
| 140 | +buildingsClipExtent = Utils_arcpy.getBuildingsClipExtentFromConstruction(excavation_outline_as_json, CALCULATION_RANGE, building_proj, logger) |
141 | 141 |
|
142 | 142 | ################ EXTRACTING BUILDINGS ################## |
143 | 143 | buildings_clip = output_folder + os.sep + "buildings_clip.shp" |
144 | 144 | logger.debug("TIME - Starting extraction of buildings") |
145 | 145 | Utils_arcpy.extractBuildingsFromFL(building_polys_fl, buildingsClipExtent, buildings_clip, logger) |
146 | 146 | logger.info("TIME - Done extraction of buildings.") |
147 | 147 |
|
| 148 | +#arcpy.SelectLayerByAttribute_management(building_polys_fl, "CLEAR_SELECTION") |
| 149 | + |
| 150 | +###### PROJECT BUILDING AND EXCAVATION TO OUTPUT ######## |
| 151 | +building_polys_projected = False |
| 152 | +excavation_polys_projected = False |
| 153 | +buildings_clip_projected = False |
| 154 | + |
| 155 | +if building_proj != output_proj: |
| 156 | + |
| 157 | + arcpy.AddMessage("Projecting bulidings polygon..") |
| 158 | + buildings_clip_projected = output_folder + os.sep + "buil_proj.shp" |
| 159 | + arcpy.Project_management(buildings_clip, buildings_clip_projected, output_proj) |
| 160 | + building_polys_fl = buildings_clip_projected |
| 161 | + |
| 162 | + arcpy.AddMessage("Projecting excavation polygon..") |
| 163 | + excavation_polys_projected = output_folder + os.sep + "exc_proj.shp" |
| 164 | + arcpy.Project_management(excavation_polys_fl, excavation_polys_projected, output_proj) |
| 165 | + excavation_polys_fl = excavation_polys_projected |
| 166 | + |
| 167 | + excavation_outline_as_json = Utils_arcpy.getConstructionAsJson(excavation_polys_fl) |
| 168 | + |
| 169 | +else: |
| 170 | + building_polys_fl = buildings_clip |
| 171 | + |
| 172 | + |
| 173 | + |
148 | 174 | ############### HANDELING OF INPUT RASTER ################ |
149 | 175 |
|
| 176 | +dtb_proj_raster = False |
150 | 177 | if bLongterm: |
151 | 178 | # If necessary, projects raster to the working projection |
152 | 179 | raster_desc = arcpy.Describe(dtb_raster) |
153 | 180 | dtb_raster_proj = raster_desc.SpatialReference.PCSCode |
154 | | - if (str(dtb_raster_proj) != str(working_proj)): |
| 181 | + if (str(dtb_raster_proj) != str(output_proj)): |
155 | 182 | logger.info("START raster projection") |
156 | | - arcpy.AddMessage("Projecting raster...") |
| 183 | + arcpy.AddMessage("Projecting bedrock raster...") |
157 | 184 | dtb_proj_raster = "temp_raster" |
158 | 185 | if os.path.exists(dtb_proj_raster): |
159 | 186 | os.remove(dtb_proj_raster) |
160 | | - arcpy.ProjectRaster_management(dtb_raster, dtb_proj_raster, working_proj) |
| 187 | + arcpy.ProjectRaster_management(dtb_raster, dtb_proj_raster, output_proj) |
161 | 188 | dtb_raster = dtb_proj_raster |
162 | 189 | logger.info("DONE raster projection") |
163 | 190 |
|
164 | 191 | # Create a tif file from the raster. Necessary for input to GDAL. |
165 | 192 | raster_desc = arcpy.Describe(dtb_raster) |
166 | 193 | if raster_desc.extension != ".tif": |
167 | 194 | logger.info("START raster to TIFF conversion") |
168 | | - arcpy.AddMessage("Converting raster...") |
| 195 | + arcpy.AddMessage("Converting bedrock raster...") |
169 | 196 | dtb_raster_tiff = output_folder + os.sep + raster_desc.name + ".tif" |
170 | 197 | #Delete existing rasters with the same name |
171 | 198 | if os.path.exists(dtb_raster_tiff): |
|
181 | 208 | try: |
182 | 209 | outputFiles = BegrensSkade.mainBegrensSkade_Excavation( |
183 | 210 | logger, |
184 | | - buildings_clip, |
| 211 | + building_polys_fl, |
185 | 212 | excavation_outline_as_json, |
186 | 213 | output_folder, |
187 | 214 | feature_name, |
188 | | - working_proj, |
189 | 215 | output_proj, |
190 | 216 | bShortterm, |
191 | 217 | excavation_depth=excavation_depth, |
|
213 | 239 | arcpy.AddError(sys.exc_info()[1]) |
214 | 240 | sys.exit() |
215 | 241 |
|
| 242 | +if dtb_proj_raster: |
| 243 | + try: |
| 244 | + arcpy.Delete_management(output_folder + os.sep + dtb_proj_raster + ".tif") |
| 245 | + except: |
| 246 | + arcpy.AddWarning("Failed to delete temporary bedrock raster!") |
| 247 | + |
| 248 | +arcpy.Delete_management(buildings_clip) |
| 249 | +if excavation_polys_matched: |
| 250 | + arcpy.Delete_management(excavation_polys_matched) |
| 251 | +if building_polys_projected: |
| 252 | + arcpy.Delete_management(building_polys_projected) |
| 253 | +if buildings_clip_projected: |
| 254 | + arcpy.Delete_management(buildings_clip_projected) |
216 | 255 | if excavation_polys_projected: |
217 | 256 | arcpy.Delete_management(excavation_polys_projected) |
218 | 257 |
|
|
221 | 260 | walls_Shapefile_result = outputFiles[1] |
222 | 261 | corners_Shapefile_result = outputFiles[2] |
223 | 262 |
|
224 | | -arcpy.SelectLayerByAttribute_management(building_polys_fl, "CLEAR_SELECTION") |
225 | | - |
226 | 263 | arcpy.AddMessage("Adding symbology layer to map...") |
227 | 264 | p = arcpy.mp.ArcGISProject("CURRENT") |
228 | 265 | pMap = p.activeMap |
|
235 | 272 | addWalls = Utils.setBooleanParameter(arcpy.GetParameter(28)) |
236 | 273 | addCorners = Utils.setBooleanParameter(arcpy.GetParameter(29)) |
237 | 274 |
|
238 | | -lyr_corners = lyr_path + os.sep + "CORNER_SV_mm.lyrx" |
| 275 | +lyr_corners = lyr_path + os.sep + "CORNER_SV.lyrx" |
239 | 276 | lyr_walls = lyr_path + os.sep + "WALL_ANGLE.lyrx" |
240 | 277 | lyr_building_sv_max = lyr_path + os.sep + "BUILDING_TOTAL_SV_MAX_mm.lyrx" |
241 | 278 | lyr_building_a_max = lyr_path + os.sep + "BUILDING_TOTAL_ANGLE_MAX.lyrx" |
|
250 | 287 | Utils_arcpy.addLayerToGroup(pMap, corners_Shapefile_result, lyr_corners, lyr_group) |
251 | 288 | if addWalls: |
252 | 289 | Utils_arcpy.addLayerToGroup(pMap, walls_Shapefile_result, lyr_walls, lyr_group) |
253 | | -if addImpactSettl: |
254 | | - Utils_arcpy.addLayerToGroup(pMap, buildings_Shapefile_result, lyr_building_sv_max, lyr_group) |
255 | | -if addImpactAngle: |
256 | | - Utils_arcpy.addLayerToGroup(pMap, buildings_Shapefile_result, lyr_building_a_max, lyr_group) |
257 | 290 | if bVulnerability: |
258 | | - if addRiskSettl: |
259 | | - Utils_arcpy.addLayerToGroup(pMap, buildings_Shapefile_result, lyr_building_risk_sv, lyr_group) |
260 | 291 | if addRiskAngle: |
261 | 292 | Utils_arcpy.addLayerToGroup(pMap, buildings_Shapefile_result, lyr_building_risk_a,lyr_group) |
| 293 | + if addRiskSettl: |
| 294 | + Utils_arcpy.addLayerToGroup(pMap, buildings_Shapefile_result, lyr_building_risk_sv, lyr_group) |
| 295 | +if addImpactAngle: |
| 296 | + Utils_arcpy.addLayerToGroup(pMap, buildings_Shapefile_result, lyr_building_a_max, lyr_group) |
| 297 | +if addImpactSettl: |
| 298 | + Utils_arcpy.addLayerToGroup(pMap, buildings_Shapefile_result, lyr_building_sv_max, lyr_group) |
| 299 | + |
| 300 | +#arcpy.SelectLayerByAttribute_management(buildings_Shapefile_result, "CLEAR_SELECTION") |
| 301 | + |
262 | 302 |
|
263 | 303 | logger.info("------------------------------DONE-------------------------------") |
264 | 304 |
|
|
0 commit comments