try: U_cursor=arcpy.UpdateCursor(downloaded_parcels, '"A1RENUM" LIKE \'%-%-%\'') for U_row in U_cursor: S_cursor=arcpy.SearchCursor(r"C:\GIS Projects\TaxChange\Parcels\2010 Parcels.shp", '"A1RENUM" = \'%s\'' % U_row.A1RENUM) for S_row in S_cursor: if S_row.VASJUST != 0: U_row.ChgJust = ((float(U_row.VASJUST)-float(S_row.VASJUST))/S_row.VASJUST)*100 if S_row.VASJUST == 0 and U_row.VASJUST != 0: U_row.ChgJust = 100 if S_row.VASTAXABLE != 0: U_row.ChgTaxable = ((float(U_row.VASTAXABLE)-float(S_row.VASTAXABLE))/S_row.VASTAXABLE)*100 if S_row.VASTAXABLE == 0 and U_row.VASTAXABLE != 0: U_row.ChgTAXABLE = 100 U_cursor.updateRow(U_row) del S_cursor VASTAXABLEtotal+=U_row.VASTAXABLE VASJUSTtotal+=U_row.VASJUST pbar.update(pbar.currval+1) finally: del U_cursor
#Defines the inputs sourceTable = gp.GetParameterAsText(0) destinationTable = gp.GetParameterAsText(1) sourceKey = gp.GetParameterAsText(2) destinationKey = gp.GetParameterAsText(3) sourceField1 = gp.GetParameterAsText(4) destinationField1 = gp.GetParameterAsText(5) sourceField2 = gp.GetParameterAsText(6) destinationField2 = gp.GetParameterAsText(7) sourceField3 = gp.GetParameterAsText(8) destinationField3 = gp.GetParameterAsText(9) #Process: Print out the input parameters message = "INPUT PARAMETERS"; showPyMessage() message = "----------------"; showPyMessage() message = "Source Table = " + sourceTable; showPyMessage() message = "Destination Table = " + destinationTable; showPyMessage() message = "Source Key = " + sourceKey; showPyMessage() message = "Destination Key = " + destinationKey; showPyMessage() message = "Source Field #1 = " + sourceField1; showPyMessage() message = "Destination Field #1 = " + destinationField1; showPyMessage() message = "Source Field #2 = " + sourceField2; showPyMessage() message = "Destination Field #2 = " + destinationField2; showPyMessage() message = "Source Field #3 = " + sourceField3; showPyMessage() message = "Destination Field #3 = " + destinationField3 + "\n"; showPyMessage() #Do some error checking message = "Running error checks..."; showPyMessage() #Process: Makes sure sourceTable exists if gp.exists(sourceTable) != True: message = "ERROR: " + sourceTable + " does not exist! Exiting script..."; showPyError(); sys.exit() #Process: Makes sure the sourceKey and sourceField1 fields exist in sourceTable fieldList = gp.listfields(sourceTable) fieldNameList = [] for field in fieldList: fieldNameList.append(field.name) if sourceKey not in fieldNameList: message = "ERROR: " + sourceKey + " field does not exist in " + sourceTable + "! Exiting script..."; showPyError(); sys.exit() if sourceField1 not in fieldNameList: message = "ERROR: " + sourceField1 + " field does not exist in " + sourceTable + "! Exiting script..."; showPyError(); sys.exit() #Process: Makes sure destinationTable exists if gp.exists(destinationTable) != True: message = "ERROR: " + destinationTable + " does not exist! Exiting script..."; showPyError(); sys.exit() #Process: Makes sure the destinationKey and destinationField1 fields exist in destinationTable fieldList = gp.listfields(destinationTable) fieldNameList = [] for field in fieldList: fieldNameList.append(field.name) if destinationKey not in fieldNameList: message = "ERROR: " + str(destinationKey) + " field does not exist in " + destinationTable + "! Exiting script..."; showPyError(); sys.exit() if destinationField1 not in fieldNameList: message = "ERROR: " + str(destinationField1) + " field does not exist in " + destinationTable + "! Exiting script..."; showPyError(); sys.exit() #Process: Figure out what fields we need for the search cursor searchCurFieldListString = sourceKey + ";" + sourceField1 #Process: Builds a dictionary of the sourceTable's sourceKey field values message = "Building source dictionary..."; showPyMessage() sourceDict = {} searchRows = gp.searchcursor(sourceTable,"","",searchCurFieldListString) searchRow = searchRows.next() while searchRow: sourceKeyValue = str(searchRow.getvalue(sourceKey)) #ensure the key is a string! sourceDict[sourceKeyValue] = searchRow.getvalue(sourceField1) searchRow = searchRows.next() del searchRow del searchRows #Process: Figure out what fields we need for the update cursor updateCurFieldListString = destinationKey + ";" + destinationField1 #Process: Updates the destinationTable message = "Updating destination table..."; showPyMessage() updateRows = gp.updatecursor(destinationTable,"","",updateCurFieldListString) updateRow = updateRows.next() while updateRow: destinationKeyValue = str(updateRow.getvalue(destinationKey)) #ensure the key is a string! if destinationKeyValue in sourceDict: updateRow.setvalue(destinationField1, sourceDict[destinationKeyValue]) updateRows.updaterow(updateRow) else: pass updateRow = updateRows.next() del sourceDict del updateRow del updateRows
I suppose I was a bit vague. I mean that the gp.JoinField() takes a long time because it is adding a field or fields and calculating the data over into them. I want to avoid python code blocks in field calculator which is why I want to use a update cursor. Can anyone speak to the function of the update cursor on joined tables in v10?
Public Sub GetLayerSelection2() Dim pMxDoc As IMxDocument Set pMxDoc = ThisDocument Dim pFLayer As IFeatureLayer Set pFLayer = pMxDoc.FocusMap.Layer(0) 'Get first layer Dim pQueryFilter As IQueryFilter Set pQueryFilter = New QueryFilter pQueryFilter.WhereClasue = "ParentTableName.OBJECTID > 0" ' do some sort of selection on the joined table If Not TypeOf pDisplayTable.DisplayTable Is IRelQueryTable Then MsgBox "Feature Layer is not joined! Exiting Sub." Exit Sub End If Dim pDisplayTable As IDisplayTable ' Variable for the joined features Set pDisplayTable = pFLayer Dim pFCursor As IFeatureCursor set pFCursor = pDisplayTable.SearchDisplayTable(pQueryFilter, False) Dim pFeature As IFeature Set pFeature = pFCursor.NextFeature Dim pFeatureClass as IFeatureClass ' Variable for the unjoiined features Set pFeatureClass = pFLayer pQueryFilter.WhereClasue = "OBJECTID > 0" ' do the same selection on the unjoined table Dim pUpdateCursor As IFeatureCursor Set pUpdateCursor = pFeatureClass.Update(pQueryFilter, False) Dim pFeature2 As IFeature Set pFeature2 = pUpdateCursor.NextFeature Dim pJoinIndex As Long pJoinIndex = pDisplayTable.DisplayTable.Fields.FindField("JoinTableName.JoinField") ' Substitute the actual Join Table and Field names If pJoinIndex = -1 Then MsgBox "JoinTableName.JoinField Field Not Found! Exiting Sub." ' Substitute the appropriate message. Exit Sub End If Dim pFieldIndex As Long pFieldIndex = pFeature.Fields.FindField("FieldName") ' Get an unjoined field of the parent FC to update If pFeatureIndex = -1 Then MsgBox "FieldName Field Not Found! Exiting Sub." ' Substitute the appropriate message Exit Sub End If Do Until pFeature Is Nothing ' Feature and Feature2 used the same query and run in synch. pFeature2.Value(pFieldIndex) & " = " & pFeature.Value(pJoinIndex) ' transfer value of join field to field pUpdateCursor.UpdateFeature = pFeature2 Set pFeature2 = pUpdateCursor.NextFeature ' Get the next unjoined feature Set pFeature = pFCursor.NextFeature ' Get the next matching joined feature Loop End Sub
Did you do the calculation with a python expresssion or a VB Script expression? A python expresssion will take 7 to 20 times as long to process as an equivalent VB Script expression on a joined table. I do join calculations all the time in python scripts with 100,000 records and using VB Script expressions. They usually take about 2 minutes or less per calculation, which I do not consider to be excessive (but if I had used a python expression the same calculation can take anywhere from 14 to 45 minutes, which is excessive).
Verified that (9.3.1 SP1) an updatecursor does NOT work with a featurelayer/table view created with the MakeQueryTable tool. I will submit a bug report to ESRI.
I've tried using JoinField and then using CalculateField. But with a large data set, as small as 100,000 records,this method takes way to long to be practical.
import arcgisscripting gp=arcgisscripting.create(9.3) gp.makefeaturelayer_management(r"C:\GIS Projects\CRW\TrakIt_Source_RS.gdb\Target_Data\parce_test", "parce_test") gp.addjoin("parce_test", "A1RENUM", r"C:\GIS Projects\CRW\parce_test_spatial_join.shp", "A1RENUM") cursor=gp.updatecursor("parce_test") row=cursor.Next() while row: row.Flood_zn = row.getvalue("parce_test_spatial_join.FLD_ZONE") cursor.updaterow(row) row=cursor.Next() del row del cursor
inputTable = r"C:\temp\test.gdb\blah" joinTable = r"C:\temp\test.gdb\lut" gp.makefeaturelayer(inputTable, "FL") gp.addjoin("FL","ID",joinTable,"ID") updateRows = gp.updatecursor("FL") updateRow = updateRows.next() while updateRow: if updateRow.getvalue("lut.ANIMAL_TYPE") == "CAT": updateRow.FOOD_TYPE = updateRow.getvalue("lut.ANIMAL_TYPE") + " FOOD" updateRows.updaterow(updateRow) updateRow = updateRows.next() del updateRow del updateRows
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.