da.UpdateCurso: Where clause for geometry

358
3
Jump to solution
02-06-2014 12:46 AM
Marianne_BilstedWiese
New Contributor
Hi Forum

I have a versioned database, where I want to make short lines longer. So in Python I try to select the short lines like this
 >>> uCursor = arcpy.da.UpdateCursor(inFeatures, [ 'OID@', 'SHAPE@', 'GM_LABEL', 'GM_USER_DEF' ], 'SHAPE@LENGTH < 300' ) edit = arcpy.da.Editor(arcpy.env.workspace) edit.startEditing() edit.startOperation()

which goes without problems but on
line = uCursor.next()

I get this error
Runtime error  Traceback (most recent call last):   File "<string>", line 1, in <module> RuntimeError: Underlying DBMS error [ORA-04054: databaselink LENGTH does not exist ] [G100.geopoint_line]


I tried also this where clause, that works in ArcMap Select by attributes:
SHAPE.LEN < 300


Because there is also a field called SHAPE.LEN.
I tried with and without quotes with no success.

Is it possible at all to make a constraint based on geometry?

/Marianne
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor
Hi Marianne,

You will want to use the field name in the where clause.  Ex:

uCursor = arcpy.da.UpdateCursor(inFeatures, [ 'OID@', 'SHAPE@', 'GM_LABEL', 'GM_USER_DEF' ], 'SHAPE.LEN < 300' )

View solution in original post

0 Kudos
3 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Marianne,

You will want to use the field name in the where clause.  Ex:

uCursor = arcpy.da.UpdateCursor(inFeatures, [ 'OID@', 'SHAPE@', 'GM_LABEL', 'GM_USER_DEF' ], 'SHAPE.LEN < 300' )
0 Kudos
XanderBakker
Esri Esteemed Contributor
Hi Marianne,

What you could also try is to use the properties of the data you're accessing. So read the "lengthFieldName" properties after doing a describe on your data:

desc = arcpy.Describe(inFeatures)
fldLength = desc.lengthFieldName


Next, construct the expression. Make use of "AddFieldDelimiters" which will add the appropriate field delimiter if necessary:

minLength = 300
expression = "{0} < {1}".format(arcpy.AddFieldDelimiters(inFeatures, fldLength), minLength)


In my (non-versioned) SDE the expression will be:
"Shape.len" < 300

In a FGDB it will be:
Shape_Length < 300

Then continue with the UpdateCursor:

fields =  ['OID@', 'SHAPE@', 'GM_LABEL', 'GM_USER_DEF']
uCursor = arcpy.da.UpdateCursor(inFeatures, fields, expression)



Kind regards,

Xander
0 Kudos
Marianne_BilstedWiese
New Contributor
Hi Marianne,

You will want to use the field name in the where clause.  Ex:

uCursor = arcpy.da.UpdateCursor(inFeatures, [ 'OID@', 'SHAPE@', 'GM_LABEL', 'GM_USER_DEF' ], 'SHAPE.LEN < 300' )


Oh, simple as that!
Works like a charm, thanks.

-- But where is the 'accepted answer' button?

And also thanks, xander, this might be useful another time

/Marianne
0 Kudos