result of arcpy.CalculateField_management with python is inconsistent but with VB, it is ok
Alice:
What database are you using for this feature class, SDE? File Geodatabase? Personal Geodatabase? (it does not appear it could be a shapefile based on the field names). If it is SDE, what underlying database is SDE using? What version of ArcMap do you have?
It is possible that rather than just transferring the value in the shape.area field the Python version is processing the actual shape geometry directly and perhaps altering it if the original geometry contains such things as true curves, rather than densified lines to form a curve. Python has issues with true curves.
If you are at version 10.0 or above, the VB Script calculation has no access to the actual geometry and can only process the value in the shape.area field as a numeric field, so the methodologies underlying the two languages could be different.
There is no way anyone can help you or replicate what you are reporting without the specific calculation code you are using. Please post your calculation. Otherwise, if you are just making a general statement about calculation behaviors using the two languages then your observation is not true for any of the calculations I do.
arcpy.CalculateField_management(temp, "ft", "!SHAPE.area!", "PYTHON_9.3", "")
result:
arcpy.CalculateField_management(temp, "ft", "[shape.area]", "VB", "")
VB: arcpy.CalculateField_management(temp, "ft", "[shape.area]", "VB", "")
Python: arcpy.CalculateField_management(temp, "ft", "!SHAPE.area!", "PYTHON_9.3", "")
Richard,
It's SDE. I'm calculating the same polygon but results are different from using VB vs Python
Thanks,
Alice
Flavor of SDE? ArcMap version? SDE database version? How was the polygon geometry created? COGO, buffer tool, parcel fabric processes?
All such details can potentially play an important role in what you are observing.
However, ultimately this question has to be posed directly to Esri, because the Field Calculator is a black box for everyone except for the developers of the tool. All of the details above will be required to make the report.
If the VB version of the calculation works, go ahead and include it in the nightly script. They work for my nightly scripts and I use VB in my Python script Field Calculations more than Python_9.3 or Python. Here are examples of VB script Field calculations I actually use in my nightly Python scripts:
Empty string assignment:
arcpy.CalculateField_management(CENTERLINE_ROUTES_MERGED__3_, "ROUTE_ALT1", "\" \"", "VB", "")
Numeric Value assignment:
arcpy.CalculateField_management(CENTERLINE_EXTENDED_Layer__13_, "CENTERLINE_EXTENDED.TRANSFERRED", "1", "VB", "")
Date/Time assignment:
arcpy.CalculateField_management(SCRIPT_LOG_View, "FINISH_TIME", "Now ( )", "VB", "")
Field data transfers in an unjoined table
arcpy.CalculateField_management(CENTERLINE_ROUTES_MERGED__5_, "ROUTE_NAME", "[ROUTE_ALT1]", "VB", "")
Field data transfers between joined tables
arcpy.CalculateField_management(RDNUMBER_Routes_Layer, "RDNUMBER_Routes.First_STNAME", "[RDNUMBERS_ALL.FIRST_STNAME]", "VB", "")
The calculation you are doing is in the Field data transfers in an unjoined table category and should work fine in your nightly python script. I have found that only VB Script multi-line advanced field calculations are not supported in a Python script.
But I got an error when I use VB option in my python scripts:
# Import arcpy module
import arcpy
# Local variables:
temp = "S:\\AVM\\ArcCatalogAvmConnections\\ro_gis(AVM).sde\\avm.AVM.Parcel_PolyOnly_Select_Ident1"
# Process: Calculate Field
> But I got an error when I use VB option in my python scripts
Make sure your Python script is running in 32-bit Python. Calculate Field's VB parser is only supported with 32-bit arcpy, in 64-bit you must use PYTHON or PYTHON_9.3 or the tool fails.
Curtis,
Thanks for your reply. How can I specify to use 32-bit Python when I run the Python scripts?
On Windows, you'd run the python script with something like this:
cmd /c C:\python27\ArcGIS10.1\python.exe myfile.py
You can also configure your IDE shortcut to run 32-bit (the default IDLE Python is the last one installed -- usually 64 bit). This of course varies by IDE. For example, I have an IDLE-32 windows shortcut that uses this execute line:
C:\Python27\ArcGIS10.1\pythonw.exe "C:\Python27\ArcGIS10.1\Lib\idlelib\idle.pyw"
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.