New to the field of GIS and learning ArcGIS Pro and Python at the same time.
How does one change Type field based on Name field
Collected data using Field Maps. Add more options for Type after the data was collected.
Special was also added after the data collection process.
For the record "Al Anderson Park", I want Type to change to Park regardless of whats already inputted.
Also for "Al Anderson Park EX", change Special from <Null> to EX Raid
I have more than 100 points collected in my map and would rather have this processes automated some how.
Furthest I got was this code that works [ !LandmarkName!.replace("EX", "") ]
Tried other things that dont work cause im also new to python.
if "Park" in !LandmarkName!:
!LandmarkType!.replace(, "Park")
Version 2.9 if that matters
Cool, is this for Pokemon Go?
If you're using calculate field, I think what you want is:
# Expression
setLandmarkType(!LandmarkName!, !LandmarkType!)
# Code block
def setLandmarkType(landmark_name, landmark_type):
if "park" in landmark_name.lower():
landmark_type = "Park"
return landmark_type
Be careful though, you will almost certainly get false positives by broadly grabbing anything with "park" in the name.
EDIT:
I just noticed the part about the Special field for EX Raids...
With Calculate Field:
# Expression
setSpecial(!LandmarkName!, !Special!)
# Code block
def setSpecial(landmark_name, special):
if landmark_name.lower().endswith(" ex"):
special = "EX Raid"
return special
With an update cursor:
with arcpy.da.UpdateCursor(path_to_fc, ["LandmarkName", "LandmarkType", "Special"]) as cursor:
for landmark_name, landmark_type, special in cursor:
if "park" in landmark_name.lower():
landmark_type = "Park"
if landmark_name.lower().endswith(" ex"):
special = "EX Raid"
cursor.updateRow([landmark_name, landmark_type, special])