2

I'm trying to get the First Point coordinates (x,y) and Final Point coordinates (x2,y2) from a polyline in ArcGIS 10 with the Field calculator.

I've added 4 (double) fields like StartX,StartY,EndX and EndY,I tried with:

"!Shape!.positionAlongLine(0.0,True).firstPoint.X"
"!Shape!.positionAlongLine(0.0,True).firstPoint.Y"
"!Shape!.positionAlongLine(1.0,True).firstPoint.X"
"!Shape!.positionAlongLine(1.0,True).firstPoint.Y"

But no luck. The error: "The row contains a bad value".

What am I doing wrong?

Thanks to @radouxju for your answer because it was what I was looking for!!, but NOW I don't know What's happening with my ArcGIS10. Let's see:

I could compute all these statements (4), to every field:

  • "!Shape!.lastPoint.X"
  • "!Shape!.lastPoint.Y"...

But, after that I checked for errors and I found this! That there are times that the ArcGIS field calculator doesn't compute well. In the example, the yellow one, it's 16 meter long, but its coordinates are the same, but the the next polyline is well computed... What's happening?

Error with ArcGIS10

6

you do not need "positionalongline" in your case. A simple snippets would be:

"!Shape!.firstPoint.X"

similarly, you can use

"!Shape!.lastPoint.Y"

However, this should have worked. So the first thing to do is to use Repair Geometry to remove problematic rows, or use a code block to handle issues in your features

def robustFX(shp):
    if (shp and (shp.length > 0)):
        return str(shp.FirstPoint.X)
    else:
        return "no data"
  • Thanks @radouxju !!it works with: "!Shape!.firstPoint.X" in a String field. ;) – juasmilla Jun 4 '14 at 10:36
  • QUESTION edited, found some troubles :( @radouxju – juasmilla Jun 5 '14 at 12:01
  • maybe it is a naive question, but how long is your line when you measure it on the screen ? – radouxju Jun 5 '14 at 12:13
  • I measured myself again and the same as shown in "Shape_Lenght" – juasmilla Jun 5 '14 at 13:32
  • this is really strange, could you please try with "!Shape!.positionAlongLine(0.5,True).firstPoint.Y". Could you also start an edit session and check the from and to coordiantes of this strange line. – radouxju Jun 5 '14 at 18:08

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.