<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Table compare output to variable or in-memory file in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/table-compare-output-to-variable-or-in-memory-file/m-p/165092#M12667</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Wow Kim!&amp;nbsp; Thanks!&amp;nbsp; I have hundreds of feature classes ranging from 10 records to 36000 records.&amp;nbsp; Then feature datasets, rasters and tables.&amp;nbsp; Unfortunately this fancy coding is quite over my head, but I'll save it for the future when I'm a more advanced scripter.&amp;nbsp; I appreciate the information!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 07 Aug 2012 22:41:15 GMT</pubDate>
    <dc:creator>StephanieSnider</dc:creator>
    <dc:date>2012-08-07T22:41:15Z</dc:date>
    <item>
      <title>Table compare output to variable or in-memory file</title>
      <link>https://community.esri.com/t5/python-questions/table-compare-output-to-variable-or-in-memory-file/m-p/165087#M12662</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'd like to have the table compare function output to a in-memory file or variable instead of an actual text file.&amp;nbsp; Is that possible?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried using a table variable, but that errored.&amp;nbsp; I used a string variable and the process worked, but the string was empty.&amp;nbsp; Any suggestions?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This works:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.TableCompare_management(table1, table2, 'OBJECTID', 'ALL', '#', '#', '#', 'NO_CONTINUE_COMPARE', r'C:\Temp\compare_table2.txt')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This works, but the string is empty:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;output_compare_string = ''&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.TableCompare_management(table1, table2, 'OBJECTID', 'ALL', '#', '#', '#', 'NO_CONTINUE_COMPARE', output_compare_string)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Aug 2012 23:35:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/table-compare-output-to-variable-or-in-memory-file/m-p/165087#M12662</guid>
      <dc:creator>StephanieSnider</dc:creator>
      <dc:date>2012-08-02T23:35:26Z</dc:date>
    </item>
    <item>
      <title>Re: Table compare output to variable or in-memory file</title>
      <link>https://community.esri.com/t5/python-questions/table-compare-output-to-variable-or-in-memory-file/m-p/165088#M12663</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I'd like to have the table compare function output to a in-memory file or variable instead of an actual text file.&amp;nbsp; Is that possible?&lt;BR /&gt;&lt;BR /&gt;I tried using a table variable, but that errored.&amp;nbsp; I used a string variable and the process worked, but the string was empty.&amp;nbsp; Any suggestions?&lt;BR /&gt;&lt;BR /&gt;This works:&lt;BR /&gt;arcpy.TableCompare_management(table1, table2, 'OBJECTID', 'ALL', '#', '#', '#', 'NO_CONTINUE_COMPARE', r'C:\Temp\compare_table2.txt')&lt;BR /&gt;&lt;BR /&gt;This works, but the string is empty:&lt;BR /&gt;output_compare_string = ''&lt;BR /&gt;arcpy.TableCompare_management(table1, table2, 'OBJECTID', 'ALL', '#', '#', '#', 'NO_CONTINUE_COMPARE', output_compare_string)&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It looks like that tool really wants to write a table to disk - you could always write it to a scratch workplace, then make a table view from that and work with the view as a work around.&amp;nbsp; Eventually you'll want to delete the contents of your scratch workspace to keep things clean - you could probably do it right away, as once the view is created I think you don't need the underlying table on disk (i could be wrong about this so double check).&amp;nbsp; Since the output of this could have many rows in it, treating the output as a string might be troublesome to work with anyway.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Aug 2012 12:34:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/table-compare-output-to-variable-or-in-memory-file/m-p/165088#M12663</guid>
      <dc:creator>ChristopherThompson</dc:creator>
      <dc:date>2012-08-03T12:34:16Z</dc:date>
    </item>
    <item>
      <title>Re: Table compare output to variable or in-memory file</title>
      <link>https://community.esri.com/t5/python-questions/table-compare-output-to-variable-or-in-memory-file/m-p/165089#M12664</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I was thinking that having the output in memory or in a variable might make the script run faster than having to read a file from the hard drive.&amp;nbsp; I'm using the table compare and featureclass compare functions to run a backup script for an ArcSDE fail over (mirror backup).&amp;nbsp; If differences are found, the old file is removed and the newer file is added.&amp;nbsp;&amp;nbsp; Well, its more complicated than that, but you get the idea.&amp;nbsp; When I went to the ESRI conference last week, an ESRI presenter spoke briefly about using in-memory data but it was in reference to Oracle trace files.&amp;nbsp; I guess I was hoping I could do the same thing in python.&amp;nbsp; I only need to scan the text for the word "false" to check for a difference in the table.&amp;nbsp; If there is a difference, then the update runs.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Aug 2012 15:24:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/table-compare-output-to-variable-or-in-memory-file/m-p/165089#M12664</guid>
      <dc:creator>StephanieSnider</dc:creator>
      <dc:date>2012-08-03T15:24:46Z</dc:date>
    </item>
    <item>
      <title>Re: Table compare output to variable or in-memory file</title>
      <link>https://community.esri.com/t5/python-questions/table-compare-output-to-variable-or-in-memory-file/m-p/165090#M12665</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Oops. I meant - if the file has the word "True" in it, then there is a difference between tables.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Aug 2012 15:46:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/table-compare-output-to-variable-or-in-memory-file/m-p/165090#M12665</guid>
      <dc:creator>StephanieSnider</dc:creator>
      <dc:date>2012-08-06T15:46:31Z</dc:date>
    </item>
    <item>
      <title>Re: Table compare output to variable or in-memory file</title>
      <link>https://community.esri.com/t5/python-questions/table-compare-output-to-variable-or-in-memory-file/m-p/165091#M12666</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If you were a keen scripter you could probably write a much faster change detector in Python using the SET datatype.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You have to load the sets of course, using a SearchCursor and creating a dictionary using the key. This takes a few seconds, but the result is definitely in memory.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The set comparison takes milliseconds.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Then you have to painfully write out the difference records using a layer. Depending on how many changes this can take a few minutes, or in your case, an update script can loop through the list.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;How large are your tables, and how many differences do you have?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For an idea, I do a comparison of two featureclasses of polygons containing 2.45 million records.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Last month there were 11616 changes, 1516 deletions and 2270 new records which are written out to new featureclasses.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It takes around 40 minutes to run.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is another example.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;When creating layer definition views you MUST index by the key for the SQL query to work in human time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#NAME:&amp;nbsp; buildDeltaLYRs.py
#AUTHOR:&amp;nbsp; Kevin Bell
#EMAIL:&amp;nbsp; kevin.bell@slcgov.com
#DATE:&amp;nbsp; 20071207
# edited by KimO
#PURPOSE:&amp;nbsp; create adds/deletes layer files by comparing 2 point
#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; feature classes shape and attributes. If the shape has
#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; not changed, but any of the attributes have, the feature
#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; will show as a delete, and an add.

#RECOMMENDED SYMBOL: adds.lyr = green plus, deletes.lyr = red X
#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (this allows for nice stacking)

#NOTE:&amp;nbsp; __buildDict method has hard coded primary key and attribute names.

 

#XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

def buildDeltaLayers(inFC1, inFC2):
&amp;nbsp;&amp;nbsp;&amp;nbsp; '''build an adds and deletes lyr for a given chrono FC '''
&amp;nbsp;&amp;nbsp;&amp;nbsp; d1 = __buildDict(inFC1)
&amp;nbsp;&amp;nbsp;&amp;nbsp; d2 = __buildDict(inFC2)
&amp;nbsp;&amp;nbsp;&amp;nbsp; compareList = __valuesChanged(d1,d2)
&amp;nbsp;&amp;nbsp;&amp;nbsp; __makeLYR(inFC1, compareList, "deletes")
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "...deletes.lyr is complete."
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; d1 = __buildDict(inFC2)
&amp;nbsp;&amp;nbsp;&amp;nbsp; d2 = __buildDict(inFC1)
&amp;nbsp;&amp;nbsp;&amp;nbsp; compareList = __valuesChanged(d1,d2)
&amp;nbsp;&amp;nbsp;&amp;nbsp; __makeLYR(inFC2, compareList, "adds")
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "...adds.lyr is complete."

def __valuesChanged(dict1, dict2):
&amp;nbsp;&amp;nbsp;&amp;nbsp; '''get a list of keys from one dict if a cooresponding dict's values are different '''
&amp;nbsp;&amp;nbsp;&amp;nbsp; outList = [key for key in set(dict1.keys() + dict2.keys()) if dict1.get(key) != dict2.get(key)]
&amp;nbsp;&amp;nbsp;&amp;nbsp; return outList

def __buildDict(inputFC): #-----BEWARE OF HARDCODED PRIMARY KEY AND ATTRIBUTES BELOW!!!!!
&amp;nbsp;&amp;nbsp;&amp;nbsp; '''Build a dictionary of the primary key, and it's fields'''
&amp;nbsp;&amp;nbsp;&amp;nbsp; d = {}
&amp;nbsp;&amp;nbsp;&amp;nbsp; cur = gp.SearchCursor(inputFC)
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = cur.Next()
&amp;nbsp;&amp;nbsp;&amp;nbsp; while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; d[row.FP] = [row.Shape.Centroid, row.LUMENS, row.WATTS, row.TYPE, row.OWNER, row.RATE]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = cur.Next()
&amp;nbsp;&amp;nbsp;&amp;nbsp; del cur
&amp;nbsp;&amp;nbsp;&amp;nbsp; return d

def __makeLYR(fc, inList, outLyrName):# BEWARE OF HARDCODED PRIMARY KEY BELOW
&amp;nbsp;&amp;nbsp;&amp;nbsp; '''given a list, return a LYR file'''
&amp;nbsp;&amp;nbsp;&amp;nbsp; wc = str(tuple(inList))
&amp;nbsp;&amp;nbsp;&amp;nbsp; whereclause = "FP IN " + wc # &amp;lt;----IF DATA ISN'T FILE GDB, YOU MAY NEED QUOTES/BRACKETS
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.MakeFeatureLayer_management (fc, outLyrName, whereclause)
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.SaveToLayerFile_management&amp;nbsp; (outLyrName, outLyrName +".lyr")

#XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

print "-----------&amp;nbsp; building adds/deletes layer files&amp;nbsp; ----------------"

import arcgisscripting, time
startTime = time.clock()

gp = arcgisscripting.create()
gp.workspace = r"F:\Temp\streetLightCompare.gdb"# &amp;lt;----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") #&amp;lt;-------------------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"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:37:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/table-compare-output-to-variable-or-in-memory-file/m-p/165091#M12666</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2021-12-11T08:37:20Z</dc:date>
    </item>
    <item>
      <title>Re: Table compare output to variable or in-memory file</title>
      <link>https://community.esri.com/t5/python-questions/table-compare-output-to-variable-or-in-memory-file/m-p/165092#M12667</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Wow Kim!&amp;nbsp; Thanks!&amp;nbsp; I have hundreds of feature classes ranging from 10 records to 36000 records.&amp;nbsp; Then feature datasets, rasters and tables.&amp;nbsp; Unfortunately this fancy coding is quite over my head, but I'll save it for the future when I'm a more advanced scripter.&amp;nbsp; I appreciate the information!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Aug 2012 22:41:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/table-compare-output-to-variable-or-in-memory-file/m-p/165092#M12667</guid>
      <dc:creator>StephanieSnider</dc:creator>
      <dc:date>2012-08-07T22:41:15Z</dc:date>
    </item>
  </channel>
</rss>

