1

I'm trying to use this field calculator expression on field Shape to generate a perpendicular line, of 0.01m, at the midpoint of each existing line feature in ArcGIS:

CALCULATE FIELD (data management):
Input table: Clip_point_buffer
Field name: Shape
Expression: RotateExtend( !Shape!, 0.01)
Expression type: Python
Code Block: 

Pre logic script code:
def RotateExtend(plyP,sLength):
l=plyP.length
ptX=plyP.positionAlongLine (l/2).firstPoint
ptX0=plyP.firstPoint
ptX1=plyP.lastPoint
dX=float(ptX1.X)-float(ptX0.X)
dY=float(ptX1.Y)-float(ptX0.Y)
lenV=math.sqrt(dX*dX+dY*dY)
sX=-dY*sLength/lenV;sY=dX*sLength/lenV
leftP=arcpy.Point(ptX.X+sX,ptX.Y+sY)
rightP=arcpy.Point(ptX.X-sX, ptX.Y-sY)
array = arcpy.Array([leftP,rightP])
section=arcpy.Polyline(array)
return section

Shape:
RotateExtend( !Shape!, 0.01)

(the code block i'm using comes from: https://gis.stackexchange.com/a/201871/63418)

It works if I do it with a shapefile, but if I have the same file as feature class in a database (.gbd) it doesn't. The database has a tolerance 0.001 and the default resolution (0.0001). Why the process does not work when the feature is in a database and how can i do this process within a database. This is the error I get:

error

I've read that it might have something to do with the properties of "Shape" type of field, because it's locked when in a database. If that's the error, how could I obtain the same results working with a feature class in a database?

  • It is fine, and encouraged, to say where you got code from but the precise code that you have tested should be included within your question body so that your question can stand alone. – PolyGeo Feb 6 '18 at 8:40
  • 1
    What do you mean by 'it doesn't work'? Do you get an error message? Are the results not what you expected? – GISGe Feb 6 '18 at 8:48
  • I get an error message – Adri Feb 6 '18 at 9:10
  • And could you add the content of this error message?... – GISGe Feb 6 '18 at 9:18
  • You are missing Shape_Length in the shapefile. Just use .length instead. This is a geometry property for polylines and polygons. You code will more robust. – klewis Feb 6 '18 at 17:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.