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 have an issue on my OpenLayers openstreetmaps where I am loading LineString features from a kml file. Everything works fine except performance due to the sheer complexity of the LineString and the number of linestrings. I wanted to use the simplyfy() function to simplify the linestring geometry/feature. Here is some code I wrote to simplify on the fly. The problem is in the line of code below:

            feature.geometry.components[i].simplify(0.1);

This does not seem to modify the original geometry feature components at all. What am I doing wrong? I think we might need to use removeComponents and then add the simplified geometries using addComponents() but how to do this?

preFeatureInsert: function(feature)

{
    if (feature != "undefined" && feature.geometry != "undefined" && feature.geometry.CLASS_NAME == "OpenLayers.Geometry.Collection");
    {
        if (feature.geometry.components != "undefined" && typeof(feature.geometry.components) != "undefined")
        {
            for (var i = 0; i < feature.geometry.components.length; i++)
            {
                if (feature.geometry.components[i].CLASS_NAME ==  "OpenLayers.Geometry.LineString")
                {
                    feature.geometry.components[i].simplify(0.1);
                }
            }
        }                           
    }
} 
share|improve this question

1 Answer 1

According to the docs the simplify function returns the simplified linestring (it doesn't modify the original). Therefore I believe you should be using

feature.geometry.components[i] = feature.geometry.components[i].simplify(0.1);

If feasible it would be far prefereable to generalise the feature once at the data-level rather than every time it is loaded on the client.

share|improve this answer
    
Thank you very much. Worked a treat. Much appreciated.. –  Rahul Aug 14 '13 at 20:38

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.