1

I've a polygon with a hole which I created using turf.difference method. Now, I need to plot that GeoJSON on another screen and make both the inner polygon as well as outer polygon editable. Since I'm unable to make the polygon with hole editable, I'm thinking of plotting it as 2 separate polygons which can be edited and later saved as a single polygon with a hole. How can I achieve this?

Though I tried different options, none of them is working though. I believe turf union method will be of some help. But I don't know how to use it. Below is the feature collection of a polygon with hole.

{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[-93.918469,41.552623],[-93.918454,41.550828],[-93.918447,41.550031],[-93.918028,41.549961],[-93.917373,41.549944],[-93.916625,41.549858],[-93.916045,41.549748],[-93.916019,41.547895],[-93.915821,41.547897],[-93.915515,41.547808],[-93.91515,41.547845],[-93.914175,41.54783],[-93.912912,41.547852],[-93.911284,41.547979],[-93.910893,41.548314],[-93.910468,41.548386],[-93.910253,41.548273],[-93.910037,41.548069],[-93.909671,41.548026],[-93.908774,41.54817],[-93.90844,41.548173],[-93.908524,41.546559],[-93.908511,41.546468],[-93.906516,41.546444],[-93.906488,41.548359],[-93.906475,41.549275],[-93.906462,41.549905],[-93.90641,41.552261],[-93.906428,41.55352],[-93.906474,41.553565],[-93.910364,41.553588],[-93.913796,41.553608],[-93.913807,41.553587],[-93.918469,41.552623]],[[-93.914664,41.549957],[-93.913978,41.552205],[-93.909857,41.551756],[-93.911144,41.549379],[-93.914664,41.549957]]]}}]}

Since I'm a beginner here, I don't know much about the inner details.

1

I found the solution to my problem. Posting the code in case someone finds it useful in future.

var inputGeoJSON = JSON.parse(SectionsGeoJSON);
var myLayer = L.geoJSON();
inputGeoJSON.features.forEach(function(feature){
     var geom=feature.geometry;
     var props=feature.properties;
         for (var i=0; i < geom.coordinates.length; i++){
          var polygon = {
               'type':'Polygon', 
               'coordinates':[geom.coordinates[i]]
               };
        var newFeat = {'type':'Feature','properties':props,'geometry':polygon};
        
        myLayer.addData(newFeat);
     }
 });
myLayer.eachLayer(function (layer) {
drawnItems.addLayer(layer);
});
HomeMap.fitBounds(myLayer.getBounds());

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.