<?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: Compare Access Table to SDE Feature Class in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/compare-access-table-to-sde-feature-class/m-p/423075#M33250</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Brian,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would suggest you use a search cursor to extract each lot of data into a Python dictionary, then do the analysis on them... &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/50809-Update-Table-with-values-from-Second-Table"&gt;Here &lt;/A&gt;&lt;SPAN&gt;is a post where someone was trying to do something pretty similar to you; give it a browse, play around with it, and fire back any questions you might have!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Stacy&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 24 Apr 2012 00:47:54 GMT</pubDate>
    <dc:creator>StacyRendall1</dc:creator>
    <dc:date>2012-04-24T00:47:54Z</dc:date>
    <item>
      <title>Compare Access Table to SDE Feature Class</title>
      <link>https://community.esri.com/t5/python-questions/compare-access-table-to-sde-feature-class/m-p/423074#M33249</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am new to python so I am working through a comparison script that will let me know if there are any differences between an mdb and a feature class (FC). Both tables with contain roughly 500,000 records. When comparing it takes probably 30 seconds for each record to find a match. I find this method to be extremely slow and I still need to add another match field. Is there a better way to compare the tables? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Eventually my end result will:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Remove records from the FC that are no longer in the mdb table. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If the recor in the mdb is newer (based on comparing time stamp field) the FC record will be removed. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Any records not found or that have newer data than FC will be added to a table in my SDE database that is dynamically geocoded back to the FC.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
# Import system modules
import arcpy, os

desc = arcpy.Describe 

# Local variables:

table = "D:/HOPOLICIES/Test.mdb/tblHOPolicies"
fc = "Database Connections\\ArcSDE.sde\\ArcSDE.A10713.HOPolicies_NW"

cField = "Policy_Number"

rows = arcpy.SearchCursor(table)
row = rows.next()
while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp; tableValue = row.getValue(cField)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows2 = arcpy.SearchCursor(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp; row2 = rows2.next()
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; while row2:
&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; fcValue = row2.getValue(cField)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if tableValue == fcValue:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print tableValue + " Match Found to " + fcValue
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break&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; row2 = rows2.next()
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.next()&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Apr 2012 19:03:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/compare-access-table-to-sde-feature-class/m-p/423074#M33249</guid>
      <dc:creator>BrianLeroux</dc:creator>
      <dc:date>2012-04-23T19:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: Compare Access Table to SDE Feature Class</title>
      <link>https://community.esri.com/t5/python-questions/compare-access-table-to-sde-feature-class/m-p/423075#M33250</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Brian,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would suggest you use a search cursor to extract each lot of data into a Python dictionary, then do the analysis on them... &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/50809-Update-Table-with-values-from-Second-Table"&gt;Here &lt;/A&gt;&lt;SPAN&gt;is a post where someone was trying to do something pretty similar to you; give it a browse, play around with it, and fire back any questions you might have!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Stacy&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Apr 2012 00:47:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/compare-access-table-to-sde-feature-class/m-p/423075#M33250</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2012-04-24T00:47:54Z</dc:date>
    </item>
    <item>
      <title>Re: Compare Access Table to SDE Feature Class</title>
      <link>https://community.esri.com/t5/python-questions/compare-access-table-to-sde-feature-class/m-p/423076#M33251</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Imbedding any geoprocessing tool inside a cursor will always be too slow.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;They are not designed to be used that way, only on whole datasets at once, any looping is built into the tools and uses indexing and other optimisation.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You need to find a tool that does the comparison inside the tool.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. MakeQueryTable springs to mind, but first you would have to copy the table so they are both in the same database.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Nice and simple but not very flexible. You would make the comparison in an SQLquery expression.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Find the differences in a python set. This is the fastest by a long way (milliseconds for the whole thing).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The catch is that you still have to read the tables once each to make the sets and write out a selected set. But it will still be less than minute or two.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Apr 2012 05:00:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/compare-access-table-to-sde-feature-class/m-p/423076#M33251</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2012-04-24T05:00:07Z</dc:date>
    </item>
    <item>
      <title>Re: Compare Access Table to SDE Feature Class</title>
      <link>https://community.esri.com/t5/python-questions/compare-access-table-to-sde-feature-class/m-p/423077#M33252</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;2. Find the differences in a python set. This is the fastest by a long way (milliseconds for the whole thing).&lt;BR /&gt;The catch is that you still have to read the tables once each to make the sets and write out a selected set. But it will still be less than minute or two.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This sounds like an ideal chioce for me but as I said my python experience is limited. Do you happen to know of any samples that show how to populate a set from a table in sde? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Apr 2012 13:40:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/compare-access-table-to-sde-feature-class/m-p/423077#M33252</guid>
      <dc:creator>BrianLeroux</dc:creator>
      <dc:date>2012-04-24T13:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: Compare Access Table to SDE Feature Class</title>
      <link>https://community.esri.com/t5/python-questions/compare-access-table-to-sde-feature-class/m-p/423078#M33253</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here is a Keyfile selection tool. Rewritten from Bruce Harold's 9.3 version for 10.0 using sets instead of FIDSet which no longer works.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My samples were two polygon featureclasses with 2.4 million records in different file geodatabases.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I selected 630,000 in one featureclass and found the corresponding records in the other.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Total elapsed time to read each featureclass and create a new selection in ArcMap took 6.5 minutes &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I must catch up with the latest incarnation of ArcScripts....&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Anyway it is short enough to paste in, and I will attempt to add a toolbox with a dialog&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you want to detect changes in attributes, or deleted records then the same process can be done on a dictionary instead of just a single key. Create a dictionary indexed by the key of all the attributes that need to be compared and convert the keys to a set as before. When you have the intersection, then you can compare the dictionaries for a similarly fast operation. I use this to create&amp;nbsp; del/new/change sets of layers. Even geometry can be tested if you are creative about using a proxy for the shape such as a rounded area, length or xy pair of coordinates for poly,line,point featureclasses.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Author: ESRI (#5588)
# Date:&amp;nbsp;&amp;nbsp; April 27th 2009
# Purpose: This script applies an SQLquery to a layer or table view using the "IN"
#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; operator and a key value set taken from another layer or table view field.
#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The output is a new selection in the same layer or table view.
#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The process is like the KEYFILE reselection option in ArcInfo Workstation.
# edit by Kim to fix selection bugs
# 17 June 2009
# 12 August 2009 FIDSet broken at 9.3.1 ??
# 25 April 2012 10.0 completely redesigned using sets, 10.x compatible, faster
# Kim Ollivier kimo@ollivier.co.nz

import arcpy
import datetime
ts0 = datetime.datetime.now()
arcpy.env.overwriteOutput = True
try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # raise Exception # uncomment for debugging in PythonWin
&amp;nbsp;&amp;nbsp;&amp;nbsp; inLayer = arcpy.GetParameterAsText(0) # Get the input layer or table view to be subqueried
&amp;nbsp;&amp;nbsp;&amp;nbsp; inField = arcpy.GetParameterAsText(1) # Get the input object subquery field
&amp;nbsp;&amp;nbsp;&amp;nbsp; keyLayer = arcpy.GetParameterAsText(2) # Get the keyfile layer or table view
&amp;nbsp;&amp;nbsp;&amp;nbsp; keyField = arcpy.GetParameterAsText(3) # Get the keyfile field
&amp;nbsp;&amp;nbsp;&amp;nbsp; selOption = arcpy.GetParameterAsText(4) # Get the selection option defaults to NEW_SELECTION
except: # debugging
&amp;nbsp;&amp;nbsp;&amp;nbsp; inLayer = "e:/project/BTR/view/Geocoding_business2.lyr" # Get the input layer or table view to be subqueried
&amp;nbsp;&amp;nbsp;&amp;nbsp; inField = "ID" # Get the input object subquery field
&amp;nbsp;&amp;nbsp;&amp;nbsp; keyLayer = "e:/project/BTR/view/Geocoding_business.lyr" # Get the keyfile layer or table view
&amp;nbsp;&amp;nbsp;&amp;nbsp; keyField = "ID" # Get the keyfile field
&amp;nbsp;&amp;nbsp;&amp;nbsp; selOption = "NEW_SELECTION" # Get the selection option defaults to NEW_SELECTION&amp;nbsp;&amp;nbsp;&amp;nbsp; 
# Build two sets of keys
setInKey = set([row.getValue(inField) for row in arcpy.SearchCursor(inLayer)])
setKey = set([row.getValue(keyField) for row in arcpy.SearchCursor(keyLayer)]) # only uses selected records
# make the common set (so fast cannot be measured!
setCommon = setInKey.intersection(setKey)
print "Common",len(setCommon)
arcpy.AddMessage(str(len(setCommon))+ " common records")
if len(setCommon) &amp;gt; 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # build an SQLquery "[inField] IN (1,2,3....)"
&amp;nbsp;&amp;nbsp;&amp;nbsp; delimitedInField = arcpy.AddFieldDelimiters(inLayer,inField)
&amp;nbsp;&amp;nbsp;&amp;nbsp; subQuery = delimitedInField + " in "+ str(tuple(setCommon)) # creates a perfect SQL style list
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Update the layer with the new selection
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(selOption+" "+inLayer)
&amp;nbsp;&amp;nbsp;&amp;nbsp; result = arcpy.SelectLayerByAttribute_management(inLayer,selOption,subQuery)
&amp;nbsp;&amp;nbsp;&amp;nbsp; outLayer = result.getOutput(0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SetParameter(5,outLayer)
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddWarning("No common records, so no selection possible")
print "Total",datetime.datetime.now() - ts0
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;keyfile tool&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This tool is a replacement for the ARC/INFO workstation SELECT &amp;lt;cover&amp;gt; KEYFILE &amp;lt;cover&amp;gt; &amp;lt;keyitem&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It was originally 9.3 proposed by Bruce Harold using FIDSet on the Describe tool but this now fails and seems obsolete.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This is because the geoprocessing tools finally work on selected records in layers.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A better method is to use the new Python set data structure for comparisons. The set comparison is so fast &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;thst it can hardly be measured with datetime.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You still have to create the sets with a SearchCursor, but that may be a lot faster at 10.1 with the new da module.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you have a very large number of records you must have the key field indexed to ensure that the selection draws&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;in ArcMap in a reasonable time because the SQL expression is a list, not an equation. This tool does not check for indexes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There does not seem to be a limit on the number of records to be compared, but the largest size file for testing has been&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;to select 2,500 records from another file of 2.4 million records which took 5 minutes to complete. Selection 630,000 records from a set of 2.4 million and run against another earlier set of 2.4 million tool 6.5 minutes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;**Warning** Field Index names in ArcGIS are limited to 16 characters long, so you have to be careful just concatenating&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;_idx to the field name.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The nearest equivalent tool is MakeQueryTable. This tool has a number of limitations not in this keyfile tool.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The tables being compared can be in different databases and even different types of database.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Since only a selection is changed, all layers are in memory for speed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Make sure that you have suitable local memory and scratch space.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Both keys have to be the same basic type for the SQL query to be valid. Either both numeric or both text.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Limitations&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-----------&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;There is no validation or error trapping except if there are no common records.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It is recommended that the keys are indexed for large tables.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The toolbox is 9.3 format but the script is now written using 10.0 syntax with arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Kim Ollivier&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="mailto:kimo@ollivier.co.nz" rel="nofollow noopener noreferrer" target="_blank"&gt;kimo@ollivier.co.nz&lt;/A&gt;&lt;BR /&gt;&lt;A _jive_internal="true" href="https://community.esri.com/www.ollivier.co.nz" target="_blank"&gt;www.ollivier.co.nz&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;25 April 2012 (ANZAC Day)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:07:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/compare-access-table-to-sde-feature-class/m-p/423078#M33253</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2021-12-11T19:07:10Z</dc:date>
    </item>
  </channel>
</rss>

