-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateApartmentDuplicates.py
100 lines (85 loc) · 3.86 KB
/
CreateApartmentDuplicates.py
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
import arcpy
import re
import agrc
from agrc import parse_address
def addBaseAddress(inAddressPoints):
def returnEmptyIfNull(word):
if word == None:
word = ''
return word
baseAddList = []
allAddsDict = {}
addressCoordDict = {}
addressAttributeDict = {}
flds = ['AddSystem', 'UTAddPtID', 'FullAdd', 'AddNum', 'AddNumSuffix', 'PrefixDir', 'StreetName', 'StreetType',
'SuffixDir', 'UnitType', 'UnitID', 'City', 'ZipCode', 'CountyID', 'State', 'PtType', 'AddSource',
'LoadDate', 'Status', 'ParcelID', 'USNG', 'SHAPE@XY', 'Building']
hwy_exceptions = ['OLD HWY 89']
with arcpy.da.SearchCursor(inAddressPoints, flds) as sCursor:
for row in sCursor:
stripStr = f' {row[9]} {row[10]}'
if '#' in row[1]:
stripStr = f' # {row[10]}'
if 'BLDG' in row[1] and row[22] != '':
stripStr = f' BLDG {row[22]} {row[9]} {row[10]}'
baseAdd = re.sub(stripStr, '', row[1])
print(baseAdd)
baseAddList.append(baseAdd)
allAddsDict.setdefault(row[1])
baseAddSet = set(baseAddList)
sCursor.reset()
for row in sCursor:
stripStr = f' {row[9]} {row[10]}'
if '#' in row[1]:
stripStr = f' # {row[10]}'
if 'BLDG' in row[1] and row[22] != '':
stripStr = f' BLDG {row[22]} {row[9]} {row[10]}'
baseAdd = re.sub(stripStr, '', row[1])
if baseAdd in baseAddSet and baseAdd not in allAddsDict:
addCoords = addressCoordDict.setdefault(baseAdd, [])
addCoords.append(row[21])
addAttributes = addressAttributeDict.setdefault(baseAdd, [])
addAttributes.extend([row[0], row[11], row[12], row[13], row[15], row[17], row[19], row[20]])
iCursror = arcpy.da.InsertCursor(inAddressPoints, flds)
for key, value in addressCoordDict.items():
if len(value) < 2:
continue
else:
if key in addressAttributeDict:
count = len(value)
addSys = addressAttributeDict[key][0]
utAddPtID = key
fullAdd = utAddPtID.split('|')[1].rstrip('#').strip()
address = parse_address.parse(fullAdd)
addNum = returnEmptyIfNull(address.houseNumber)
addNumSuf = returnEmptyIfNull(address.houseNumberSuffix)
preDir = returnEmptyIfNull(address.prefixDirection)
sName = returnEmptyIfNull(address.streetName)
sufDir = returnEmptyIfNull(address.suffixDirection)
sType = returnEmptyIfNull(address.suffixType)
if sName[:2].isdigit():
sType = ''
if sName.isdigit() == False:
sufDir = ''
city = addressAttributeDict[key][1]
zip = addressAttributeDict[key][2]
county = addressAttributeDict[key][3]
state = 'UT'
ptType = 'BASE ADDRESS'
addSrc = 'UGRC BASE'
loadDate = addressAttributeDict[key][5]
parcel_id = addressAttributeDict[key][6]
usng = addressAttributeDict[key][7]
coords = value
xSum = 0
ySum = 0
for coord in coords:
x = coord[0]
y = coord[1]
xSum = xSum + x
ySum = ySum + y
xCoord = xSum / count
yCoord = ySum / count
xyCoord = [xCoord, yCoord]
iCursror.insertRow((addSys, utAddPtID, fullAdd, addNum, addNumSuf, preDir, sName, sType, sufDir, '', '',
city, zip, county, state, ptType, addSrc, loadDate, 'COMPLETE', parcel_id, usng, xyCoord, ''))