Skip to content

Commit 6ffdaee

Browse files
Add files via upload
1 parent 5fd1e5a commit 6ffdaee

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

ArcGISProWrapperBegrensSkade_Excavation.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@
4242
feature_name = arcpy.GetParameterAsText(3)
4343
coord_syst = arcpy.GetParameterAsText(4)
4444

45-
sr = arcpy.SpatialReference()
46-
sr.loadFromString(coord_syst)
47-
output_proj = sr.PCSCode
45+
output_spatial_ref = arcpy.SpatialReference()
46+
output_spatial_ref.loadFromString(coord_syst)
47+
output_proj = output_spatial_ref.PCSCode
4848

4949
corner_name = feature_name + "_CORNER"
5050
wall_name = feature_name + "_WALL"
@@ -124,20 +124,20 @@
124124
status_field = None
125125

126126
############## GET INPUT PROJECTIONS ####################
127-
building_proj = Utils_arcpy.getProjCodeFromFC(building_polys_fl)
128-
excavation_proj = Utils_arcpy.getProjCodeFromFC(excavation_polys_fl)
127+
building_spatial_ref = arcpy.Describe(building_polys_fl).spatialReference
128+
excavation_spatial_ref = arcpy.Describe(excavation_polys_fl).spatialReference
129129

130130
### GET EXCAVATION ANS BUILDINGS ON SAME PROJECTION #####
131131
excavation_polys_matched = False
132-
if excavation_proj != building_proj:
132+
if excavation_spatial_ref != building_spatial_ref:
133133
arcpy.AddMessage("Matching input projections before clip..")
134134
excavation_polys_matched = output_folder + os.sep + "exc_match.shp"
135-
arcpy.Project_management(excavation_polys_fl, excavation_polys_matched, building_proj)
135+
arcpy.Project_management(excavation_polys_fl, excavation_polys_matched, building_spatial_ref)
136136
excavation_polys_fl = excavation_polys_matched
137137

138138
################ GET EXCAVATION INFO #####################
139139
excavation_outline_as_json = Utils_arcpy.getConstructionAsJson(excavation_polys_fl)
140-
buildingsClipExtent = Utils_arcpy.getBuildingsClipExtentFromConstruction(excavation_outline_as_json, CALCULATION_RANGE, building_proj, logger)
140+
buildingsClipExtent = Utils_arcpy.getBuildingsClipExtentFromConstruction(excavation_outline_as_json, CALCULATION_RANGE, building_spatial_ref, logger)
141141

142142
################ EXTRACTING BUILDINGS ##################
143143
buildings_clip = output_folder + os.sep + "buildings_clip.shp"
@@ -152,7 +152,7 @@
152152
excavation_polys_projected = False
153153
buildings_clip_projected = False
154154

155-
if building_proj != output_proj:
155+
if building_spatial_ref != output_spatial_ref:
156156

157157
arcpy.AddMessage("Projecting bulidings polygon..")
158158
buildings_clip_projected = output_folder + os.sep + "buil_proj.shp"

ArcGISProWrapperBegrensSkade_Tunnel.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@
4242
feature_name = arcpy.GetParameterAsText(3)
4343
coord_syst = arcpy.GetParameterAsText(4)
4444

45-
sr = arcpy.SpatialReference()
46-
sr.loadFromString(coord_syst)
47-
output_proj = sr.PCSCode
45+
output_spatial_ref = arcpy.SpatialReference()
46+
output_spatial_ref.loadFromString(coord_syst)
47+
output_proj = output_spatial_ref.PCSCode
4848

4949
corner_name = feature_name + "_CORNER"
5050
wall_name = feature_name + "_WALL"
@@ -130,20 +130,20 @@
130130
status_field = None
131131

132132
############## GET INPUT PROJECTIONS ###########################
133-
building_proj = Utils_arcpy.getProjCodeFromFC(building_polys_fl)
134-
tunnel_proj = Utils_arcpy.getProjCodeFromFC(tunnel_poly_fl)
133+
building_spatial_ref = arcpy.Describe(building_polys_fl).spatialReference
134+
tunnel_spatial_ref = arcpy.Describe(tunnel_poly_fl).spatialReference
135135

136136
######## GET EXCAVATION AND BUILDINGS ON SAME PROJECTION ###########
137137
tunnel_poly_matched = False
138-
if tunnel_proj != building_proj:
138+
if tunnel_spatial_ref != building_spatial_ref:
139139
arcpy.AddMessage("Matching input projections before clip..")
140140
tunnel_poly_matched = output_folder + os.sep + "tun_match.shp"
141-
arcpy.Project_management(tunnel_poly_fl, tunnel_poly_matched, building_proj)
141+
arcpy.Project_management(tunnel_poly_fl, tunnel_poly_matched, building_spatial_ref)
142142
tunnel_poly_fl = tunnel_poly_matched
143143

144144
################ GET TUNNEL INFO #####################
145145
tunnel_outline_as_json = Utils_arcpy.getConstructionAsJson(tunnel_poly_fl)
146-
buildingsClipExtent = Utils_arcpy.getBuildingsClipExtentFromConstruction(tunnel_outline_as_json, CALCULATION_RANGE, building_proj, logger)
146+
buildingsClipExtent = Utils_arcpy.getBuildingsClipExtentFromConstruction(tunnel_outline_as_json, CALCULATION_RANGE, building_spatial_ref, logger)
147147

148148
################ EXTRACTING BUILDINGS ##################
149149
buildings_clip = output_folder + os.sep + "buildings_clip.shp"
@@ -158,7 +158,7 @@
158158
tunnel_poly_projected = False
159159
buildings_clip_projected = False
160160

161-
if building_proj != output_proj:
161+
if building_spatial_ref != output_spatial_ref:
162162

163163
arcpy.AddMessage("Projecting bulidings polygon..")
164164
buildings_clip_projected = output_folder + os.sep + "buil_proj.shp"

Utils_arcpy.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,9 @@ def getConstructionAsJson(uploaded_construction_outline):
7272
bounding_as_json = geom.JSON
7373
return json.loads(bounding_as_json)
7474

75-
def getBuildingsClipExtentFromConstruction(constructionJson, margin, working_proj, logger):
75+
def getBuildingsClipExtentFromConstruction(constructionJson, margin, spatial_ref, logger):
7676
logger.debug("constructionJson: {}".format(constructionJson))
7777
construction_area_corners = BegrensSkadeLib.get_construction_corners_from_ArcGIS_json(constructionJson, 2, logger)
78-
sr = arcpy.SpatialReference(working_proj)
7978
minx = 99999999
8079
miny = 99999999
8180
maxx = -99999999
@@ -96,7 +95,7 @@ def getBuildingsClipExtentFromConstruction(constructionJson, margin, working_pro
9695
ur = arcpy.Point(maxx + margin, maxy + margin)
9796
lr = arcpy.Point(maxx + margin, miny - margin)
9897

99-
rectangle = arcpy.Polygon(arcpy.Array([ll, ul, ur, lr, ll]), sr)
98+
rectangle = arcpy.Polygon(arcpy.Array([ll, ul, ur, lr, ll]), spatial_ref)
10099

101100
logger.debug("Rectangle: {}".format(rectangle.extent.JSON))
102101
return rectangle

0 commit comments

Comments
 (0)