-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_border_effect.py
More file actions
38 lines (36 loc) · 1.71 KB
/
create_border_effect.py
File metadata and controls
38 lines (36 loc) · 1.71 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
import arcpy, os, common, collections, loaders
OVERLAP_FLD = 'OVERLAP'
TMP_BORDS = 'tmp_borders'
PTOL_LEFT_FLD = 'LEFT_FID'
PTOL_RIGHT_FLD = 'RIGHT_FID'
with common.runtool(7) as parameters:
regions, idFld, overlapTable, idFrom, idTo, overlapFld, outBorders = parameters
common.progress('creating borders')
tmpBords = common.featurePath(os.path.dirname(outBorders), TMP_BORDS)
arcpy.PolygonToLine_management(regions, tmpBords, 'IDENTIFY_NEIGHBORS')
# dissolve to remove line duplication on shared borders
common.progress('removing border duplicates')
arcpy.Dissolve_management(tmpBords, outBorders, [PTOL_LEFT_FLD, PTOL_RIGHT_FLD])
common.progress('loading region identifiers')
oidFld = arcpy.Describe(regions).OIDFieldName
idReader = loaders.DictReader(regions, {'id' : idFld, 'fid' : oidFld})
regions = idReader.read()
regIDType = type(next(regions.itervalues()))
common.progress('loading region overlap values')
overlapReader = loaders.OverlapReader(overlapTable, {'from' : idFrom, 'to' : idTo, 'value' : overlapFld})
overlaps = overlapReader.read()
# remap to FIDs
tofid = {}
for id, valdict in overlaps.iteritems():
fid = regions[id]['fid']
tofid[fid] = {}
for toid, toval in valdict.iteritems():
tofid[fid][regions[toid]['fid']] = {'from' : id, 'to' : toid, 'value' : toval}
common.progress('writing border effects')
marker = loaders.OverlapMarker(outBorders,
inSlots={'from' : PTOL_LEFT_FLD, 'to' : PTOL_RIGHT_FLD},
outSlots={'from' : common.NEIGH_FROM_FLD, 'to' : common.NEIGH_TO_FLD, 'value' : OVERLAP_FLD},
where=('{} <> -1 AND {} <> -1'.format(PTOL_LEFT_FLD, PTOL_RIGHT_FLD)))
marker.mark(tofid)
common.progress('removing temporary files')
common.delete(tmpBords)