I'm trying to assign an address to a building footprint.
Dataset:
Buildings Prints
Address Points
In some cases I have multiple addresses within a polygon and would like to use the lowest available address.
Attachment shows a couple polygon footprints and address points.
If you open the thread (not inside the inbox) when you edit a reply you see the "Use advanced editor" link in the upper right part :
When you click on it, it will open the advanced editor which has in the lower left corner a link to attach files:
After reviewing the results I have a few buildings that did not capture the lowest address number.
I may have put too much thought into creating the building footprints.. We geocoded all the addresses from legacy data. Then we dragged all the points over the building in hopes to populate the footprints with addresses. I'm not an expert writing code.. Self taught... Below is a link to show some of my work.. The Public Gallery is open to the everyone. The attachment I hope will show the problems I'm dealing with.. If floor plans or other source data were available I split the polygons into units to get a one to one match with the address points. I doubt very much that I will ever see a one to one match with every building in the city.
Link
http://cityofmiddletown.maps.arcgis.com/home/index.html
Thanks again for your interest.
OK, this is what I came up with...
First step is to spatially join the buildings to the point. Right click on the points, select "Joins and Relates" and then "Join"::
Then specify the following:
Then run the following code, but change:
def main():
import arcpy
# join the building to the points using spatial join
fc_pnts_join = r'C:\GeoNet\BuildAdd\data.gdb\PointsJoinBuildings'
fld_oid_pol = 'FID_2'
fld_lsn = 'LSN' # TEXT 75
fld_num = 'ADDR_NUM'
# polygon shapefile
fc_pol = r'C:\GeoNet\BuildAdd\BuildingFP.shp'
fld_oid = arcpy.Describe(fc_pol).OIDFieldName
fld_lsn_pol = 'Address'
# create dictionary of data from join
dct_join = {}
flds = (fld_oid_pol, fld_num, fld_lsn)
with arcpy.da.SearchCursor(fc_pnts_join, flds) as curs:
for row in curs:
oid_pol = row[0]
if oid_pol in dct_join:
data = dct_join[oid_pol]
data.append([row[1], row[2]])
else:
data = [[row[1], row[2]]]
dct_join[oid_pol] = data
# print dct_join
# add address field to building polygons
if len(arcpy.ListFields(fc_pol, fld_lsn_pol)) == 0:
arcpy.AddField_management(fc_pol, fld_lsn_pol, "TEXT", None, None, 75)
# now update the address field for the buildings
cnt = 0
flds = (fld_oid, fld_lsn_pol)
with arcpy.da.UpdateCursor(fc_pol, flds) as curs:
for row in curs:
cnt += 1
if cnt % 100 == 0:
print "Processing: {0}".format(cnt)
oid_pol = row[0]
if oid_pol in dct_join:
lst = dct_join[oid_pol]
address = getAdressForLowestNumber(lst)
row[1] = address
curs.updateRow(row)
def getAdressForLowestNumber(lst):
address = ""
if len(lst) == 1:
address = lst[0][1]
else:
min_mun = 999999
for data in lst:
num = int(data[0])
if num < min_mun:
min_mun = num
address = data[1]
return address
if __name__ == '__main__':
main()
I will attach the resulting building shapefile so you can validate the result.