3

I have declared a line geometry as:

var lineString = new OpenLayers.Geometry.LineString([source,target]);

then I am trying to get the centroid of this lineString as lineString.getCentroid().

But what's returning is a Start Point of the lineString.

So, is there any way to get the real centroid of a LineString?

P.S: I have also looked through this discussion. But couldn't figure out the solution.

4
  • If I understand your link correctly all you have to do is to call lineString.getCentroid(true) Commented Sep 4, 2014 at 10:49
  • Thanks for reply. I did the same exactly, but that didn't work. I mean it returns the same starting point. And apologies i didn't mention that here(while posting this question).
    – Suraj
    Commented Sep 4, 2014 at 14:32
  • Try lineString.getCentroid(weighted)?
    – Erica
    Commented Sep 4, 2014 at 15:25
  • Hi, the HimBromBeere was right (Thanks!). So the solution is lineString.getCentroid(true). I believe earlier it was not worked because of browser cache.
    – Suraj
    Commented Sep 5, 2014 at 8:51

1 Answer 1

0

As per the link shared in question itself, the solution is to call getCentroid() by passing the true as a parameter. i.e. lineString.getCentroid(true).

Thanks to HimBromBeere for his comment.

Your Answer

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

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