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?

Adri
  • 61
  • 4
  • 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 06 '18 at 08: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 06 '18 at 08:48
  • I get an error message – Adri Feb 06 '18 at 09:10
  • And could you add the content of this error message?... – GISGe Feb 06 '18 at 09: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 06 '18 at 17:30
  • I don't understand what you mean. I created an attribute for the feature class in the database called "Shape_Length" and then did the "Calculate Field" – Adri Feb 06 '18 at 22:52
  • I updated the error image – Adri Feb 07 '18 at 08:06

0 Answers0