Python ERROR 000539

5449
11
01-09-2012 12:07 PM
ABDALLAMOHAMED
Occasional Contributor
Hello.I was running the following in ARCMap version 10: gp.CalculateField_management(nn_output_file, "patch_area", "[F_AREA]/1000000", "VB", ""), and keep getting the following error:
ERROR 000539:Error running expression: [F_AREA]/1000000. Name 'F_AREA' is not defined. Any hint. Appreciated. Thanks!
Tags (2)
0 Kudos
11 Replies
MathewCoyle
Frequent Contributor
Most likely, if that field does indeed exist, you are using improper syntax for the field. What is the data type of the feature class you are calculating on? Square brackets are for personal geodatabases. (See http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00s500000033000000.htm)

Also, double check the field data type to make sure it is numeric.

Also, if you are using ArcGIS 10, you should be using arcpy, not the old arcgisscripting. Unless you have it mapped to the new geoprocessor already.
0 Kudos
ABDALLAMOHAMED
Occasional Contributor
Mathew..Let me try that and will let you know about the result. Thanks for your input..
0 Kudos
ABDALLAMOHAMED
Occasional Contributor
I used the following code to add and calculate field:-
gp.AddField_management(nn_file, "p_area", "DOUBLE", "", "", "", "", "NON_NULLABLE", "NON_REQUIRED", "")
    gp.CalculateField_management(nn_file, "p_area", "[F_AREA]/1000", "PYTHON", "")


I keep getting error and couldn't figure it out..Any hint??? Thanks!
0 Kudos
curtvprice
MVP Esteemed Contributor
That's VBScript, you need to do one of the following. (This is documented in the Calculate Field tool documentation.)

VBScript (the default BTW):

gp.CalculateField_management(nn_file, "p_area", "[F_AREA] / 1000")


Python:

gp.CalculateField_management(nn_file, "p_area", "!F_AREA! / float(1000)","PYTHON")



  • It is best practice (in Python 2.x anyway) to recast one of the operands to float to ensure you get floating division. (Even though if !F_AREA! is a float field python will know that, it's a good idea.)

  • Mathew's comment about different field syntax for different dataset types does not apply here -- that applies only to SQL expressions used in tools like Select and MakeFeaturelayer. In  Calculate Field, fields are always surrounded by [] or !!, depending on the choice of script language.

0 Kudos
ABDALLAMOHAMED
Occasional Contributor
Let me try it and I will let you know about the output..
Thanks a lot...
0 Kudos
aaronboci1
New Contributor II
Hello, I am also getting this error. I am running raster calculator and I have 2 fields in which I am trying to multiply. One field is a float, the other was a long. This did not work. So I added a new field in the layer which had the long and designated it a float, then I filled the column with the values I had before as long. I then tried to multiply them again, but I received the same error. I need my data in float for further processing in Darcy's Tools. Currently I have the thickness and Hydrologic conductivity values. according to the formula K = T/b from those rules, that is the same as Kb=T. Transmissivity. This is the last layer I need to create to perform this tool. but I'm not sure why it will not multiply to floats.
0 Kudos
curtvprice
MVP Esteemed Contributor
Aaron, Raster Calculator is different - instead of accessing the fields directly in the expression, you access those data values for each cell using the Lookup() tool.
0 Kudos
aaronboci1
New Contributor II
Yes, I have the two layers necessary, both of which have the same cell size and alignment. What I did to get it to run just now was created a new field in the attribute table as a float. Then, i did a reclassify of that layer on that field. but, reclassify does not make negative values, I did a raster calculation of minus two on every cell. this brought me back to my original values but in long format again. but this time it performed. but did not give me the values I am expecting. one field goes from -2 to 6. the other goes from 0-1,000,000 and I only got values from -358 to 760. all I'm trying to do is simply multiply 2 raster layers values, I've used this tool a hundred times, that's why I am confused as to why it is not working. I understand the different number types but since they're the same, i don't know what to do. I don't know how to program so I am limited to tool use.
0 Kudos
curtvprice
MVP Esteemed Contributor
Instead of Reclassify, have you tried the Lookup tool? Say you have a field "XVALUE" in the raster table. In Raster Calculator you can use Lookup to create a new grid with XVALUE as the cell values:

Lookup("mygrid","XVALUE")

You can also just use the Lookup tool in the dialog, but the Raster Calculator would allow you to combine the operation with something else, for example:

Lookup("mygrid","XVALUE") * 100.0

I read your first post and it seems like you want to create a float field in the raster table, run Calculate Field in your raster table to get your "T/b" value, and .. then use Lookup to make a grid of that float field.
0 Kudos