I am trying to get name of raster for corresponding point if point belongs to raster and fill column "name" in points Attribute Table:
but no names in Attribute Table column "name" of point's shp. file What can be a problem?
I am getting error
File "", line 22, in if iR.contains(pnt[0]):
AttributeError: 'unicode' object has no attribute 'contains'
env.workspace = r"C:\Users1円_fire_dNBR" # folder with set of rasters
inputPoints = r"C:\Users\select3.shp"
# List of rasters in specific folder
RExtents = [arcpy.Describe(R).extent for R in arcpy.ListRasters()]
#Names:
#RNames = [arcpy.Describe(R).name[:-9]]
RNames = [arcpy.Describe(R).name[:-10] for R in arcpy.ListRasters()] # extract names of rasters
print RNames
with arcpy.da.UpdateCursor(inputPoints, ["SHAPE@","name"]) as iCur:
for pnt in iCur:
counter = 0
for iR in RNames:
if iR.contains(pnt[0]):
print iR
i.value.append(RNames[counter])
iCur.updateRow["name"]
counter =+ 1
2 Answers 2
This line:
for pnt in sCur:
should be:
for pnt in iCur:
Also you do not need this "del iCur" at the end of your script as you are creating iCur within a with
statement which deals with the release of the cursor.
-
Thank you. but Now i am getting "AttributeError: 'unicode' object has no attribute 'contains'" in line if iR.contains(pnt[0]): How to go away from this? ".Adams– Adams2016年04月25日 05:52:01 +00:00Commented Apr 25, 2016 at 5:52
Python string objects do not have a contains method. The correct syntax is
if pnt[0] in iR:
This will be a case-sensitive search. For case-insensitive search, use pnt[0].lower() and iR.lower() (or upper() if you prefer).