row.shape for layer ?

529
6
10-25-2011 04:06 AM
OlivierOlivier
New Contributor III
Hi

Can someone be so kind to explain why when I use those  lines

rows = gp.SearchCursor(infc)
row = rows.Next()
feat=row.shape

it works when infc is a shapefile but not when it's a layer ? In this case, I get "Field shape does not exist" even if it exists when I open attributes in ArcView.

Thanks very much, sorry for a such basic question,

Olivier
Tags (2)
0 Kudos
6 Replies
ChrisSnyder
Regular Contributor III
The 'shape' field isn't always called shape...

dsc = gp.describe(infc) #or your featurelayer
rows = gp.SearchCursor(infc)  #or your featurelayer
row = rows.Next()
feat=row.getvalue(dsc.oidFieldName)
0 Kudos
OlivierOlivier
New Contributor III
Hi Chris,

Thanks for your answer. It seems to work but the problem is that after I used

partcount =feat.PartCount # Count the number of points in the current multipart feature

and I get this message :

AttributeError: 'int' object has no attribute 'PartCount'

That means that the feat objet I get is not the same 'shape' ?
0 Kudos
LoganPugh
Occasional Contributor III
Try shapeFieldName instead of oidFieldName.
0 Kudos
OlivierOlivier
New Contributor III
That's ok. Sorry for being stupid, OidFieldName sounded strange to me but I didn't thank further.

Thanks very much for your help Chris !

Olivier
0 Kudos
ChrisSnyder
Regular Contributor III
Woops - Thanks Logan...

Yes, I meant shapeFieldName, not oidFieldName (although oidFieldName is quite usefull sometimes as well).

I didn't have my coffe yet...
0 Kudos
OlivierOlivier
New Contributor III
I didn't get my coffee too, I thought previous answer was Chris's, sorry Logan.

Thanks to both of you, you helped much !

Olivier
0 Kudos