Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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 = [
            this.components[0],
            this.components[this.components.length-1]
        ];
    } 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

1 Answer 1

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. –  Mingfeng Jan 28 '13 at 10:24

Your Answer

 
discard

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.