5

I wrote some code for removal of polygon holes whose area value is under the hardcoded threshold.

source_g.getFeatures()[0].getGeometry().getPolygons().forEach(function(poly){

    if(!(poly.getLinearRings().length<=1)) 
    {
        poly.getLinearRings().forEach(function(ring){ 
            if(Math.abs(ring.getArea()) < 0.1){ 

               ring.setCoordinates([])
            }
        })
    };
})

The idea is to set coordinates of inner LinearRings to [], I tried to do that on the whole feature and it disappeared. But for LinearRings it's not doing the same.

7

The geometry is defined as an array of coordinates, not collections of Polygons and LinearRings, so what is returned by getPolygons() and getLinearRings() should be treated as clones and you will need to rebuild the geometry from coordinates

var geom = source_g.getFeatures()[0].getGeometry();
var geomCoords = [];
geom.getPolygons().forEach(function(poly){
    var polyCoords = [];
    poly.getLinearRings().forEach(function(ring, index){ 
        if(index == 0 || Math.abs(ring.getArea()) >= 0.1){ 
           polyCoords.push(ring.getCoordinates());
        }
    };
    geomCoords.push(polyCoords);
});
geom.setCoordinates(geomCoords);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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