Joe you had fish.
I am struggling for my address error issue during Geoprocessing and I am working on the book, Python Scripting for ArcGIS, by Paul Zandbergen. When I found this python script sample in the book, I assume that I saw the dawn from the horizon
This is a very useful tool.
Regards,
From the link that Kory provided, Bruce actually uploaded it two years ago...
Eat more fish!
Regards,
I believe the current link would be https://www.arcgis.com/home/item.html?id=d34959c8f11940c08143440e7fcf585e but like Bruce said, the script may not work at current releases...
There is not an idea for this right now as far as I can tell on ArcGIS Ideas
This helps!
Thanks!
Charles, Joe
Please see here:
http://resources.arcgis.com/gallery/file/geocoding/details?entryID=1A290038-1422-2418-88FC-098400376...
Regards
I think you have to check the "relative paths" option then "reload" the script so that the tool picks up on the new relative path.
Try the following script. Save the text as addressCheck.py; open in idle; change the local variables as neede and run the script. If you send me an email, I'll send you the script since it looks like all the indents have been stripped. Good luck
Chuck.Buzzard@PierceCountyWA.gov
# This Python script searches a GIS roads feature class and
# codes an error field depending on a series of address errors
# Addressing rules:
# Road segments must point in direction of increasing house numbers (FLIP)
# Even and Odd sides of street must remain consistant (EVENODD)
# From range value must be smaller that To Range value (FROMTO)
# Ranges can not overlap from one segment to another (OVRLAP)
# A check but not an error would be a missing street segment (GAP)
# Errors checked for are
# Even Odd Flips (EVENODD)
# Overlap in the range (OVRLAP)
# FromTo flip in address range (FROMTO)
# Flip of underlying segments (FLIP)
# Alerts are coded
# Gaps in the network (GAP)
#Dependencies:
# Requires ArcGIS Desktop Advanced License
# Requires standard python 2.7 libraries and ESRI's arcpy library
#Notes:
# Review Local variable section and modify as needed
#Author:
# Chuck Buzzard
#Updates:
# 6/2011;4/2014;9/2016
import sys, os, shutil, time, arcpy
def prepWksp(wksp,wkdb):
if os.path.exists(wksp+wkdb):
arcpy.Delete_management(wksp+wkdb)
arcpy.CreateFileGDB_management(wksp, wkdb)
def hideShowFlds(srclyr,fldLst):
srcFlds = arcpy.ListFields(srclyr)
fldinfo = arcpy.FieldInfo()
for fld in srcFlds:
if fld.name in fldLst:
#print fld.name
fldinfo.addField(fld.name, fld.name, "VISIBLE", "")
else:
fldinfo.addField(fld.name, fld.name, "HIDDEN", "")
def print2Log(logTxt,logLoc):
temp = sys.stdout
sys.stdout = open(logLoc,'a')
print(logTxt+os.linesep)
sys.stdout.close()
sys.stdout = temp
#Set Local Variables:
wsLog = "C:\\wkspace\\addr\\logs\\addrerr.log"
wsTrg = "C:\\wkspace\\addr\\"
wsSrc = ""
dbSrc = "\\\\data\\TransportationGDB.gdb\\"
dbTNm = "Staging.gdb"
dbTrg = wsTrg+dbTNm
fcRds = "Roads"
flRds = ["OBJECTID","Shape","LFROM","LTO","RFROM","RTO","PREDIR","NAME","TYPE","DIR","FULLNAME","LZIP","RZIP","LCITY","RCITY","MAPCLASS"]
print "Start Address Error Check: ("+time.ctime()+")"
print2Log("Start Address Error Check: ("+time.ctime()+")",wsLog)
#Prep Target Workspace:
prepWksp(wsTrg,dbTNm)
# Set Geoprocessing environments:
arcpy.env.scratchWorkspace = dbTrg
arcpy.env.workspace = dbTrg
arcpy.env.overwriteOutput = True
#Copy Production Data To Work Area:
arcpy.CopyFeatures_management(dbSrc+fcRds,fcRds)
print "#Prepare Data For Processing:"
print2Log("Prepare Data For Processing:",wsLog)
arcpy.MakeFeatureLayer_management(fcRds,fcRds+"_lyr")
hideShowFlds(fcRds+"_lyr",flRds)
#Code Address Errors
print "Make Nodes: ("+time.ctime()+")"
arcpy.AddField_management(fcRds+"_lyr","sX","LONG")
arcpy.AddField_management(fcRds+"_lyr","sY","LONG")
arcpy.AddField_management(fcRds+"_lyr","FNODE","TEXT",13)
arcpy.CalculateField_management(fcRds+"_lyr","sX","!SHAPE.FIRSTPOINT!.split()[0]","PYTHON")
arcpy.CalculateField_management(fcRds+"_lyr","sY","!SHAPE.FIRSTPOINT!.split()[1]","PYTHON")
arcpy.CalculateField_management(fcRds+"_lyr","FNODE","str(!sX!)+str(!sY!)","PYTHON")
arcpy.AddField_management(fcRds+"_lyr","eX","LONG")
arcpy.AddField_management(fcRds+"_lyr","eY","LONG")
arcpy.AddField_management(fcRds+"_lyr","TNODE","TEXT",13)
arcpy.CalculateField_management(fcRds+"_lyr","eX","!SHAPE.LASTPOINT!.split()[0]","PYTHON")
arcpy.CalculateField_management(fcRds+"_lyr","eY","!SHAPE.LASTPOINT!.split()[1]","PYTHON")
arcpy.CalculateField_management(fcRds+"_lyr","TNODE","str(!eX!)+str(!eY!)","PYTHON")
arcpy.AddField_management(fcRds+"_lyr","ADDERR","TEXT",50)
arcpy.Sort_management(fcRds+"_lyr","cadRoadsLSort",[["LCITY","ASCENDING"],["FULLNAME","ASCENDING"],["LFROM","ASCENDING"]])
print "Code Leftside: ("+time.ctime()+")"
fc="cadRoadsLSort"
flds = ('FNODE','TNODE','LCITY','FULLNAME','LFROM','LTO','ADDERR')
fn = ""
tn = ""
nm = ""
ct = ""
fh = -1
th = -1
er = ""
cnt = 0
with arcpy.da.UpdateCursor(fc,flds) as cursor:
for row in cursor:
if ((row[2] == ct) and (row[3] == nm)):
if (row[4]>row[5]):
er=str(er)+"FROMTO"
if (row[4]<=th):
er=str(er)+"OVERLAP"
if ((row[4]%2==0 and fh%2!=0) or (row[4]%2!=0 and fh%2==0)):
er=str(er)+"EVENODD"
if (row[1]==tn):
er=str(er)+"FLIP"
if (row[0]!=tn):
er=str(er)+"GAP"
row[6]=str(er)
fn=row[0]
tn=row[1]
ct=row[2]
nm=row[3]
fh=row[4]
th=row[5]
cursor.updateRow(row)
er=""
else :
fn=row[0]
tn=row[1]
ct=row[2]
nm=row[3]
fh=row[4]
th=row[5]
er=""
print "Code Rightside: ("+time.ctime()+")"
arcpy.Sort_management("cadRoadsLSort","cadRoadsRSort",[["RCITY","ASCENDING"],["FULLNAME","ASCENDING"],["RFROM","ASCENDING"]])
fc="cadRoadsRSort"
flds = ('FNODE','TNODE','RCITY','FULLNAME','RFROM','RTO','ADDERR')
fn = ""
tn = ""
nm = ""
ct = ""
fh = -1
th = -1
er = ""
with arcpy.da.UpdateCursor(fc,flds) as cursor:
for row in cursor:
if ((row[2] == ct) and (row[3] == nm)):
if (row[4]>row[5]):
er=str(er)+"FROMTO"
if (row[4]<=th):
er=str(er)+"OVERLAP"
if ((row[4]%2==0 and fh%2!=0) or (row[4]%2!=0 and fh%2==0)):
er=str(er)+"EVENODD"
if (row[1]==tn):
er=str(er)+"FLIP"
if (row[0]!=tn):
er=str(er)+"GAP"
row[6]=str(er)
fn=row[0]
tn=row[1]
ct=row[2]
nm=row[3]
fh=row[4]
th=row[5]
cursor.updateRow(row)
er=""
else :
fn=row[0]
tn=row[1]
ct=row[2]
nm=row[3]
fh=row[4]
th=row[5]
er=""
print "End Address Error Check: ("+time.ctime()+")"
print2Log("End Address Error Check: ("+time.ctime()+")",wsLog)