result of arcpy.CalculateField_management with python is inconsistent but with VB, it is ok
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", "")
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", "")
It's SDE. I'm calculating the same polygon but results are different from using VB vs Python
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.
I think you are right - it happened all polygons with curves (see the map - the blue are shapes without curves and they are correct numbers as shape.area, the red polygons are shapes with curves and they are different from shape.area...). So, how can I still use python but get the true result like using VB since I need to write python scripts for my nightly process? Many thanks !
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", "")
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
# Local variables:
temp = "S:\\AVM\\ArcCatalogAvmConnections\\ro_gis(AVM).sde\\avm.AVM.Parcel_PolyOnly_Select_Ident1"
# Process: Calculate Field
I ran the following script using SDE under SQL server and it worked without error:
# Import arcpy module
# Local variables:
temp = r"C:\Users\RFAIRHUR\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\Trans Connection to SQL Server.sde\GDB_TRANS.TRANS.Test_Area"
# Process: Calculate Field
arcpy.CalculateField_management(temp, "ft", "[Shape.STArea()]", "VB", "")
But I noticed that I have never had a field name called [Shape.area]. In my file geodatabase it is [Shape_area} and in my SDE database it is [Shape.STArea()]. But this could be a difference in the way my SDE administrator set my SDE geometry defaults up.
The script is being run on a computer with an Advanced Desktop license install. I have never used ArcGIS Engine license if that is what you are using. You would have to pose your question to users of Engine if that is what you are using.
This may be an installation option issue. I also do not do ArcGIS installations, so if my IT staff enabled some option that lets my script run that was not enabled when your install was done, I would not know what option that might have been, I only know that with Desktop installs there is a way to get VB Field Calculations to work within Python scripts.
Thanks Richard. I'm going to set up a job in sql to see if this works for me...
Richard, I tried in sql and got an error:
Here's my python codes for this job in sql:
temp = r'C:\AVM\AVM @ RO_GIS - AVM.sde\avm.AVM.Parcel_PolyOnly_Select_Ident1'
I have never processed a script on a service, only on normal SDE connections through Desktop, so this may be a restriction when you are using services.
In that case, I have no solution for your problem if you are using services other than to run your nightly scripts against the Desktop SDE connection and replicate the result to the service. All versions of python will always simplify all of your true curves when they operate on your geometry and you will see a change the in the area output from what you see in the area field. Your only other option would be to permanently convert all of the polygons with true curves to high density N-gons to get both the VB Script and the Python calculations to return the same reported area shown in the shape.area field.
So if this was all done against a standard Desktop SDE connection you could use a VB Script calculation in a nightly Python script, but the same is not necessarily true for an SDE service. So the details of every aspect of your set up can be significant in determining the cause of the behavior and the different configurations of your data storage, software, database connections, etc. can all play a key role in the behavior of a given process.
I’ll try the sql route to get this. Thank you very much for your helps!
> 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.
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:
Thanks Curtis. I tried and got this error...
That's interesting. I think you may have to use Python with Engine - may want to contact support about that to see if there is a way.
I thought your areas calculated with and without the curves were pretty close. Are you sure the approximation of the area using PYTHON_9.3 isn't good enough?
(25637 - 25641) / 25641 = .00015 (less than 0.02% difference)
Retrieving data ...