0

I have a shapefile and a layer file. In the shapefile, I am updating the last column using a .dbf file, which has numeric values. So, the last column of the shapefile will be updated five times and I have five data frames in one MXD file. So, whenever the shapefile gets updated, it has to go to a new data frame.

Here is my code:

import arcpy
arcpy.env.workspace = 'C:\\Users\\Jaggu\\Documents\\ArcGIS\\Default.gdb'
mxd = arcpy.mapping.MapDocument(r"D:\Project\CROPWAT\WRR\DistrictScaleNew1\Block_scale\ArcMap\IWR2.mxd")
lyrfile = r'D:\Project\CROPWAT\WRR\DistrictScaleNew1\Block_scale\ArcMap\AP_APWRIMS7.lyr'
lyrfile1 = arcpy.mapping.Layer(lyrfile) #Converting to a layer file in the current env

#update field
updateFld = "IWR"
#update fc key field
IdFld = "dtname"

#join feature class
joinFc = r"D:\Project\CROPWAT\WRR\DistrictScaleNew1\Block_scale\ArcMap\IWR.dbf"
#join value field to be transferred
#joinValFld = dbffields[i]
#join key field
joinIdFld = "district"

#create dictionary
#Key: join field
#Value: field with value to be transferred

for index, item in enumerate(arcpy.mapping.ListDataFrames(mxd)):
    
valueDists = []
for i in range(len(dfs)):
    arcpy.mapping.AddLayer(dfs[i],lyrfile1,"BOTTOM")
    joinValFld = dbffields[i]
    valueDist = {}
    valueDist = dict ([(key, val) for key, val in arcpy.da.SearchCursor(joinFc, [joinIdFld, joinValFld])])
    valueDists.append(valueDist)
currentlayers = []
#update feature class
for i in range(len(valueDists)):
    #currentlayer = arcpy.mapping.ListLayers(dfs[i])[0]
    with arcpy.da.UpdateCursor (shpfile, [updateFld, IdFld]) as cursor:
        valueDist = valueDists[i]
        for update, key in cursor:
            row = (valueDist [key], key)
            print row
            cursor.updateRow (row)
        arcpy.mapping.UpdateLayer(dfs[i], shpfile, currentlayer, True)
    currentlayer = arcpy.mapping.ListLayers(dfs[i])[0]
    currentlayers.append(currentlayer)
mxd.saveACopy('D:\\Project\\CROPWAT\\WRR\\DistrictScaleNew1\\Block_scale\\ArcMap\\AP_APWRIMS1.mxd')

The problem that I am facing is that the code is running without any errors but all five data frames were updated with the last updated shapefile data. Plot is looking like this: enter image description here

But I want five different choropleths. I have already checked the last column of shapefile and it gets updated but it is not showing in ArcMap.

What is wrong?

My Original MXD file looks like this: enter image description here

7
  • 1
    In the CAD model, the project file holds the data, but in the GIS model, a project file only contains the drawing rules. ArcGIS uses the GIS model, so each time you update the table you alter the contents of the previous project. You must either save different shapefiles or alter the shapefile to have five different columns and specify the column in the project.
    – Vince
    Commented Sep 8, 2021 at 10:20
  • Thank you for the idea. I will try and let you know.
    – G.S. J
    Commented Sep 8, 2021 at 10:25
  • The saving shapefiles method did not work. I saved shapefiles with the newly updated column. So, I will get 5 shapefiles. Then, I updated the old layer file with the newly created shapefile. Still, the last shapefile gets added to all data frames. I will try the other method of having five different columns in the shapefile.
    – G.S. J
    Commented Sep 8, 2021 at 10:52
  • Both methods should work. You are doing something wrong. You'd have to inspect the data frames layers to see what is wrong.
    – Vince
    Commented Sep 8, 2021 at 11:07
  • 1
    The picture doesn't help because all the the data frames have the same name. Name them A-E or 1-5.
    – Vince
    Commented Sep 8, 2021 at 11:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.