2

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

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jan 21, 2019 at 19:56
1
  • I don't even really know what language this is in. I thought I'd share it in case it helps: Calculate midpoint of Polyline Commented Dec 1, 2019 at 4:33

2 Answers 2

1

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!

answered Feb 19, 2019 at 20:31
0

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.

answered Jul 24, 2019 at 10:31

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.