What is the correct way to use measureOnLine attribute for polyline?

1388
4
Jump to solution
10-27-2018 11:53 PM
CharithKarandana
New Contributor

I created a polyline myself and testing the measureOnLine attribute to use it in another script which goes with real data. "polyline.measureOnLine((x, y))" doesn't work ("I'm pretty much sure the point (x,y) is on the polyline. The funny thing is

"polyline.measureOnLine(polyline.positionAlongLine(length))" works (Although there is no use of such). So I believe there is something is missing form me. Can anyone help me to overcome this?  

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

Polyline—ArcPy classes | ArcGIS Desktop 

measureOnLine (in_point, {use_percentage})

in_point has to be a point object and use_percentage is a boolean.

Your 'ValueError' is because you didn't provide the required object

So you need to make a point or use a point from some other object

ie arcpy.Point(x, y)

where x, y are coordinates.

Point—ArcPy classes | ArcGIS Desktop 

You need to explore the arcpy section of the help to piece the useage together

View solution in original post

4 Replies
CharithKarandana
New Contributor

One thing to add, I just found the 'queryPointAndDistance' brings the same error! It's called 'ValueError'

0 Kudos
DanPatterson_Retired
MVP Emeritus

Polyline—ArcPy classes | ArcGIS Desktop 

measureOnLine (in_point, {use_percentage})

in_point has to be a point object and use_percentage is a boolean.

Your 'ValueError' is because you didn't provide the required object

So you need to make a point or use a point from some other object

ie arcpy.Point(x, y)

where x, y are coordinates.

Point—ArcPy classes | ArcGIS Desktop 

You need to explore the arcpy section of the help to piece the useage together

CharithKarandana
New Contributor

Thanks for your response and I'm sorry to say I tried both these. It didn't work.

This was the line in my script which returned with the ffollowing error

polyline.queryPointAndDistance(startPoint)

File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\arcobjects\arcobjects.py", line 791, in queryPointAndDistance
return convertArcObjectToPythonObject(self._arc_object.QueryPointAndDistance(*gp_fixargs((in_point, use_percentage))))
ValueError: [422809.7100999998, 845539.4996000007]

Same happens to the measureOnLine.

0 Kudos
CharithKarandana
New Contributor

I was wrong. Your reply helped me to understand my error. Thank you very much.

0 Kudos