I am new to Python.
I'm creating a Script Tool in 10.8.2 that generates polygons from Create Fishnet of 1 deg x 1 deg and a new field GEOCELL. I need to update field GEOCELL with the lower left corner extents latitude and longitude (XMin and YMin presumably) so that each polygon updates to "N50E015" format. Currently it is crashing on the extents line which originally came from an arcpy.SearchCursor script I found, however that script updated every polygon with the same string from the last polygon.
AttributeError: 'NoneType' object has no attribute 'extent'
with arcpy.da.UpdateCursor(layer1x1, "GEOCELL") as cursor:
for row in cursor:
extent = row[0].extent
lat = int(extent.YMin)
lon = int(extent.XMin)
# Set variables to buffer single and double lat/lon digits with leading zeros
# North/South
if lat > -1 and lat < 10:
ns = "N0"
elif lat > 9 and lat < 80:
ns = "N"
if lat > -10 and lat < 0:
ns = "S0"
elif lat > -81 and lat < -9:
ns = "S"
# East/West
if lon > -1 and lon < 10:
ew = "E00"
elif lon > 9 and lon < 100:
ew = "E0"
elif lon > 99 and lon < 180:
ew = "E"
if lon > -10 and lon < 0:
ew = "W00"
elif lon > -100 and lon < -9:
ew = "W0"
elif lon > -181 and lon < -99:
ew = "W"
# North/South Absolute values
if lat < 0:
nspos = str(lat * -1)
elif lat > -1:
nspos = str(lat)
# East/West Absolute values
if lon < 0:
ewpos = str(lon * -1)
elif lon > -1:
ewpos = str(lon)
# Geocell Name
geocell = ns + nspos + ew + ewpos
rows.updateRow(row)