Hi there everyone.
First of all thanks for helping, and I realize I need some tutorials in python and can hopefully address that soon.
Problem: Using the Calculate Field tool I would like copy values from two other fields based on specific criteria. For instance I have a new field called "UnathorizedOccupantID". I would like to copy values from the field called "ClusterID", however when there is a value of -1 I would like to copy the corresponding values from the "SourceID" field. As seen here:
I believe this will get me to the next part of the analysis which is aggregating the cluster ID's using the Dissolve tool.
Thanks for any help it is greatly appreciated!
Solved! Go to Solution.
Just modify the function as follows. Make sure your 'UOID' field is set to text and not numeric.
def uio(cluster, source):
if cluster > 0:
return 'C%s' %cluster
else:
return 'S%s' %source
For future reference, when you have a question please post as a question not as a discussion. You will get a better response from GeoNet.
This can be easily completed using python in field calculator. Create a function (uio), such as the following, which has a conditional statement that returns the ClusterID if it is not negative and otherwise returns the SourceID. You can customize this as needed.
def uio(cluster, source):
if cluster > 0:
return cluster
else:
return source
You will call this using the statement uio( !ClusterID!, !SourceID!).
Below is the same shown in Field Calculator from ArcGIS Desktop. It would be the same in Pro.
Lance
Thanks alot for taking the time to resolve the task and the geonet tip. Greatly appreciated!
-Noni
Hi Lance im running into an issue where two fields are populating the new field with the same value. Here is a description below:
Your code worked, however I need to tweak it so that the copied values are uniquely distinguishable.
Thanks again!
Just modify the function as follows. Make sure your 'UOID' field is set to text and not numeric.
def uio(cluster, source):
if cluster > 0:
return 'C%s' %cluster
else:
return 'S%s' %source