I am making a python code for ArcGIS 9.3 :
-I have one folder with a lot of shapefile polygon inside - Ech polygon shapefile have a field "Average" and one ID - I have a table with each field corresponding to the ID of shapefile
I want to open each shapefile, take the "Average" and put it in the good field. So for shapefil 1, I take all the averages and i put them in line 1 of the table.
To do it I ha one SearchCursor in my shapefile and one UpdateCursor in my table. But it doesn't work and it seems to come from the update function.
The code is as following and the error come after "Marqueur 6.1" which is link to the SetValue method and to the update cursor.
The mesage error is : Marqueur 6.1 : ERROR 999999: Error executing function. Failed to execute (OpeTable2).
for infile in glob.glob(os.path.join(path, '*.shp')):
MyShape = os.path.join(path, infile)
Name = os.path.basename(MyShape)
fileName, fileExtension = os.path.splitext(Name)
gp.AddMessage(Name)
if TestFieldCreate == False :
TestFieldCreate = True
rowsP = gp.UpdateCursor(MyShape)
rowP = rowsP.Next()
#row est une ligne et non une colonne
while rowP:
ID_BVs = rowP.GetValue(Field_ID_BV)
ID_BV_STR = str(ID_BVs) #Converti en string
NameBV = "BV"+ ID_BV_STR
rowsP.updateRow(rowP)
rowP = rowsP.Next()
gp.addfield (MyTable, NameBV, "double")
#On place le curseur dans le shp
rowsInShape = gp.SearchCursor(MyShape)
rowInShape = rowsInShape.Next()
while rowInShape:
countStr =str(count)
gp.AddMessage( "Iteration N°" + countStr)
Moyenne = rowInShape.GetValue(Field_Moyenne)
if Moyenne != 0 :
gp.AddMessage("Marqueur 6")
# On récupère les valeur pour AfoisP et le num de BV que l'on converti de la même manière que le nom des champs
BV = rowInShape.GetValue(Field_ID_BV)
BV_STR = str(BV) #Converti en string
FieldName = "BV"+ BV_STR
gp.AddMessage("Marqueur 6.1")
rowInTable.SetValue(FieldName, Moyenne)
rowInTable.SetValue("NomFich", fileName)
rowsInTable.updateRow(rowInTable)
gp.AddMessage("Marqueur 7")
gp.AddMessage("Marqueur 7.1")
rowInSHape = rowsInShape.Next()
count=count+1
gp.AddMessage("Marqueur 7.2")
rowsInTable.updateRow(rowInTable)
rowInTable = rowsInTable.Next()
gp.AddMessage("Marqueur 8")
NumStr = str(Num)
gp.AddMessage(Name + " Fichier N° " + NumStr)
Num = Num +1
gp.AddMessage("Marqueur 9")
Thanks a lot