#NAME: buildDeltaLYRs.py #AUTHOR: Kevin Bell #EMAIL: kevin.bell@slcgov.com #DATE: 20071207 # edited by KimO #PURPOSE: create adds/deletes layer files by comparing 2 point # feature classes shape and attributes. If the shape has # not changed, but any of the attributes have, the feature # will show as a delete, and an add. #RECOMMENDED SYMBOL: adds.lyr = green plus, deletes.lyr = red X # (this allows for nice stacking) #NOTE: __buildDict method has hard coded primary key and attribute names. #XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX def buildDeltaLayers(inFC1, inFC2): '''build an adds and deletes lyr for a given chrono FC ''' d1 = __buildDict(inFC1) d2 = __buildDict(inFC2) compareList = __valuesChanged(d1,d2) __makeLYR(inFC1, compareList, "deletes") print "...deletes.lyr is complete." d1 = __buildDict(inFC2) d2 = __buildDict(inFC1) compareList = __valuesChanged(d1,d2) __makeLYR(inFC2, compareList, "adds") print "...adds.lyr is complete." def __valuesChanged(dict1, dict2): '''get a list of keys from one dict if a cooresponding dict's values are different ''' outList = [key for key in set(dict1.keys() + dict2.keys()) if dict1.get(key) != dict2.get(key)] return outList def __buildDict(inputFC): #-----BEWARE OF HARDCODED PRIMARY KEY AND ATTRIBUTES BELOW!!!!! '''Build a dictionary of the primary key, and it's fields''' d = {} cur = gp.SearchCursor(inputFC) row = cur.Next() while row: d[row.FP] = [row.Shape.Centroid, row.LUMENS, row.WATTS, row.TYPE, row.OWNER, row.RATE] row = cur.Next() del cur return d def __makeLYR(fc, inList, outLyrName):# BEWARE OF HARDCODED PRIMARY KEY BELOW '''given a list, return a LYR file''' wc = str(tuple(inList)) whereclause = "FP IN " + wc # <----IF DATA ISN'T FILE GDB, YOU MAY NEED QUOTES/BRACKETS gp.MakeFeatureLayer_management (fc, outLyrName, whereclause) gp.SaveToLayerFile_management (outLyrName, outLyrName +".lyr") #XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX print "----------- building adds/deletes layer files ----------------" import arcgisscripting, time startTime = time.clock() gp = arcgisscripting.create() gp.workspace = r"F:\Temp\streetLightCompare.gdb"# <----BEWARE OF HARDCODED WORKSPACE !!!!! gp.OverwriteOutput = 1 #o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o buildDeltaLayers("SEP07","OCT07") #<-------------------BEWARE OF HARDCODED FEATURE CLASSES !!!!! #o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o print "Your adds/deletes lyr's are in:" print str(gp.workspace) del gp print "--------------------------------------------------------------------------------------------" stopTime = time.clock() elapsedTime = stopTime - startTime print "elapsed time = " + str(round(elapsedTime, 1)) + " seconds"
I'd like to have the table compare function output to a in-memory file or variable instead of an actual text file. Is that possible?I tried using a table variable, but that errored. I used a string variable and the process worked, but the string was empty. Any suggestions?This works:arcpy.TableCompare_management(table1, table2, 'OBJECTID', 'ALL', '#', '#', '#', 'NO_CONTINUE_COMPARE', r'C:\Temp\compare_table2.txt')This works, but the string is empty:output_compare_string = ''arcpy.TableCompare_management(table1, table2, 'OBJECTID', 'ALL', '#', '#', '#', 'NO_CONTINUE_COMPARE', output_compare_string)
サインインしたメンバーは投稿、更新のフォローなどができます。初めてですか?無料アカウントを登録してください。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.