0

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 
asked Apr 24, 2016 at 7:42

2 Answers 2

1

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.

answered Apr 24, 2016 at 14:53
1
  • 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? ". Commented Apr 25, 2016 at 5:52
0

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).

answered Apr 25, 2016 at 8:26

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.