I would like to reach the mid point of a polyline.

I just tried the centroid and realcentroid properties but I only got a soluction in ArcPy with the code below:

Midpoint = geometry.positionAlongLine(0.50,True).firstPoint
... print Midpoint.X
... print Midpoint.Y

How do I find the correct mid point (not centerline or gravity point of an irregular polyline)?

enter image description here


Do you have to use esri js? Turf.js has a function called "along" that could be used for this, but you'd need to calculate the length of the line beforehand before halving it and sending that length into the .along() parameters. You could calculate the length in turf as well, or use esri if you prefer.

If it has to be esri js... have fun. I suppose that I would first get the length of the entire line using a geometry service (if this doesn't all need to be client side). From there, I would probably break the line into segments by iterating over its paths and then running along a those segments, getting the distance of each and keeping track until I found the right segment to finally drop a point with whatever distance I had left at an angle calculated from the segment endpoints.

Lucky for you, someone else already wrote this and seems to have cut out the step of exploding the geometry for us. How convenient!


This is my way to get the centerpoint of a Line. In this Case for the Lines of esris Measuretool.

var lineCenter = new Point((PointA.x+PointB.x)/2,(PointA.y+PointB.y)/2,map.spatialReference);

Maybe this is not the cleanest way to solve it, but it works.

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.