Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am having a LineString, where I need to find the vertices logically and save those vertices. Can anyone help me out. Or else how below can help me.

OpenLayers.Geometry.LineString = OpenLayers.Class(OpenLayers.Geometry.Curve, { getVertices: function(nodes) {
    var vertices;
    if(nodes === true) {
        vertices = [
    } else if (nodes === false) {
        vertices = this.components.slice(1, this.components.length-1);
    } else {
        vertices = this.components.slice();
    return vertices;
                }       );  

Please help me.

Thank you

share|improve this question
up vote 3 down vote accepted

You can get the vertices by calling getVertices() function of LineString object. Assume you have a LineString obeject named as line, you can get vertices of the Line by using following code:

var vertices = line.getVertices();

The function has an optional parameter nodes. If it's true, only endpoints will be returned, and false, only non-endpoints will be returned. If it's not provided all vertices in the line will be returned. You can find full documentation here.

share|improve this answer
thanks a lot, its working, but how do I get vertex by vertex. – SriRamaChandra.G Jan 28 '13 at 9:31
The function returns an array, so you just iterate over vertices to get vertex one by one. – mfdev Jan 28 '13 at 10:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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