-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPartitioning.pyt
More file actions
217 lines (169 loc) · 8.46 KB
/
Copy pathPartitioning.pyt
File metadata and controls
217 lines (169 loc) · 8.46 KB
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
#----------------------------------------------------------------------
# Name: IB-Tool2
# Purpose: Toolset for the delineation of settlements on the basis
# building footprints
#
# Author: Oliver Harig
#
# Created: 10.05.2021
# Cite: Oliver Harig (2021). Toolset for the delineation of settlements on the basis building footprints, road network and land use data (v1.0) https://doi.org/10.26084/IOERFDZ-SOFT-001
# Licence: MIT License
Copyright 2021 Oliver Harig
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
# associated documentation files (the "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
# following conditions:
#
# The above copyright notice, and this permission notice must be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#----------------------------------------------------------------------
import arcpy
import time
from arcpy import env
from numpy import*
import math
import random
from arcpy.sa import*
arcpy.env.referenceScale = "10000"
arcpy.env.overwriteOutput = True
arcpy.CheckOutExtension("Spatial")
# ############################### PARTITIONING-TOOL ##########################
class Toolbox(object):
def __init__(self):
self.label = "ib-tool2_partitioning "
self.alias = "partitioning "
self.description = "ArcGIS toolbox for partitioning of geodata based on building footprints"
# List of tool classes associated with this toolbox
self.tools = [Partitionen]
class ibtool:
arcpy.env.overwriteOutput = True
def siedgr(self, input_HU, cell_size, density_value):
arcpy.AddMessage("Start partitioning")
# Variables
radius = 2 * cell_size
d_var = str(cell_size // 2)
radius_del = '{} Meters'.format(d_var)
# File-Aliases
Input_feature = input_HU
Input_feature_point= 'Input_feature_point'
HU_Raster = 'HU_Raster'
HU_Raster_Layer = 'HU_Raster_Layer'
HU_Raster_Feature = 'HU_Raster_Feature'
Thiess_Poly = 'Thiess_Poly'
Thiess_Line = 'Thiess_Line'
Thiess_Split = 'Thiess_Split'
Thiess_Split_Lay = 'Thiess_Split_Lay'
Poly_Grenz = 'Poly_Grenz_{}_{}'.format(cell_size, radius)
# loading ArcGIS Spatial Analyst license
arcpy.CheckOutExtension("Spatial")
arcpy.env.overwriteOutput = True
arcpy.management.FeatureToPoint(Input_feature, Input_feature_point, "INSIDE")
# Creates rasters with density values
HU_dest = arcpy.sa.PointDensity(Input_feature_point, "NONE", cell_size, "Circle {} MAP".format(radius), "SQUARE_METERS")
# Raster to point
arcpy.RasterToPoint_conversion(HU_dest, HU_Raster, 'Value')
# Generates point grid clusters
arcpy.MakeFeatureLayer_management(HU_Raster, HU_Raster_Layer, '"grid_code" > {}'.format(density_value))
arcpy.CopyFeatures_management(HU_Raster_Layer, HU_Raster_Feature)
# generates Thiessen polygons
arcpy.CreateThiessenPolygons_analysis(HU_Raster_Feature, Thiess_Poly, 'ONLY_FID')
# Polygons to lines
arcpy.FeatureToLine_management(Thiess_Poly, Thiess_Line, '#', 'ATTRIBUTES')
# divides the Thisssen lines at the intersections
arcpy.SplitLine_management(Thiess_Line, Thiess_Split)
# Deletes all lines in the proximity of the point grid clusters
arcpy.MakeFeatureLayer_management(Thiess_Split, Thiess_Split_Lay)
arcpy.SelectLayerByLocation_management(Thiess_Split_Lay, 'WITHIN_A_DISTANCE', HU_Raster_Layer, radius_del, 'NEW_SELECTION')
arcpy.DeleteFeatures_management(Thiess_Split_Lay)
# creates settlement boundary polygon
arcpy.FeatureToPolygon_management(Thiess_Split_Lay, Poly_Grenz, '#', 'ATTRIBUTES', '#')
# Delete the temporary files
del_list = [HU_dest, HU_Raster, HU_Raster_Feature, HU_Raster_Layer, Thiess_Line, Thiess_Poly, Thiess_Split, Thiess_Split_Lay]
for list in del_list:
arcpy.Delete_management(list)
# Add Name-Field
if len(arcpy.ListFields(Poly_Grenz, "NAME")) > 0:
arcpy.DeleteField_management(Poly_Grenz, "NAME")
arcpy.AddField_management(Poly_Grenz, "NAME", "TEXT")
arcpy.management.CalculateField(Poly_Grenz, "NAME", "'PART_'+ str(!OBJECTID!)", "PYTHON_9.3", None)
return Poly_Grenz
ibtool = ibtool()
class Partitionen(object):
def __init__(self):
self.label = "Data set partitioning"
self.description = "With this tool, partitioning polygons are created from given building footprints for the step-by-step processing of the algorithm."
self.canRunInBackground = False
def getParameterInfo(self):
param0 = arcpy.Parameter(
displayName="Workspace",
name="arcpy.env.workspace",
datatype="DEWorkspace",
parameterType="Required",
direction="Input")
param1 = arcpy.Parameter(
displayName="Building footprints",
name="imput_HU",
datatype="DEFeatureClass",
parameterType="Required",
direction="Input")
param1.filter.list = ["POLYGON"]
param2 = arcpy.Parameter(
displayName="Cell size (metres)",
name="cell_size",
datatype="GPLong",
parameterType="Required",
direction="Input")
param2.value = 150
param3 = arcpy.Parameter(
displayName="Density threshold",
name="density_value",
datatype="GPDouble",
parameterType="Required",
direction="Input")
param3.value = 0.00001
param4 = arcpy.Parameter(
displayName="Output polygon",
name="out_put_poly",
datatype="DEFeatureClass",
parameterType="Required",
direction="Output")
param4.filter.list = ["POLYGON"]
param5 = arcpy.Parameter(
displayName="Expert delineation",
name="Muster_grenz",
datatype="DEFeatureClass",
parameterType="Optional",
direction="Input")
param5.category = "Conflict check (optional)"
params = [param0, param1, param2, param3, param4, param5]
return params
def execute(self, params, messages):
# Local variables
arcpy.env.workspace = params[0].valueAsText
input_HU = params[1].valueAsText
cell_size = params[2].valueAsText
density_value = params[3].valueAsText
out_put_poly = params[4].valueAsText
Muster_grenz = params[5].valueAsText
# Main programme
out_siedgr = ibtool.siedgr(input_HU, int(cell_size), float(density_value))
# Conflict check
if str(Muster_grenz) != 'None':
arcpy.FeatureToLine_management(out_siedgr, 'out_siedgr_line')
arcpy.MakeFeatureLayer_management('out_siedgr_line','out_siedgr_line_FL')
select_DELI = arcpy.SelectLayerByLocation_management('out_siedgr_line_FL', 'INTERSECT', Muster_grenz, '#', 'NEW_SELECTION')
arcpy.CopyFeatures_management(select_DELI, 'DELI_sel')
result = arcpy.GetCount_management('DELI_sel')
ANZ = int(result.getOutput(0))
arcpy.AddMessage("Es wurden " + str(ANZ) + " Konflikte mit der Referenzabgrenzung festgestelt.")
arcpy.DeleteFeatures_management('DELI_sel')
arcpy.DeleteFeatures_management('out_siedgr_line')
# Output
arcpy.CopyFeatures_management(out_siedgr, out_put_poly)