Austin Tarango
Austin Tarango

Reputation: 49

When cutting a polygon with a polyline the geometry engine will group certain peices together?? Arcgis javascript api

When preforming a cut action on a polygon with a polyline, some of the returned geometries are grouped while others are not?

I have a simple program where the user can create a polygon with a SketchViewModel. Then the user creates a polyline with a SketchViewModel. I then take the geometry from each sketch and preform a cut from the geometryEngine. I get an array of geometries from the cut and add them to the layer while removing the original polygon and polyline. I would expect to get each subdivided piece individually but for some reason some get grouped together as one geometry even if they're not connected.

   //polylineLayer and polygonLayer are graphiclayers
   //submit is a html button to call the execution
   submit.addEventListener("click", function() {

   //subDivisions is an Geometry[] for the produced geometries
   //ex. one line through a circle polygon would produce
   // two geometries of each half. (this works)
   // anything more complicated starts having grouping issues
   // (see pictures)
   var subDivisions = 
         geometryEngine.cut(polygonLayer.graphics.getItemAt(0).geometry, 
         polylineLayer.graphics.getItemAt(0).geometry);
    polygonLayer.removeAll();
    polylineLayer.removeAll();
    //show the number of subdivisions
    alert("size: " + subDivisions.length);
    // add created geometries to the graphiclayer
    for (var i = 0; i < subDivisions.length; i++){
           tempGraphic = new Graphic ({
           geometry: subDivisions[i]                    
           });
           polygonLayer.graphics.add(tempGraphic,i);

        }
    });

(sorry for the links to photos I don't have 10 reputation to post photos and this is a very visual project/issue)

Open screen: https://ibb.co/WDcgmSn

Draw first polygon: https://ibb.co/wd6CDbV

Draw polyline to cut polygon: https://ibb.co/BG32863

Expected subdivisions - 10 Actual - 7: https://ibb.co/0VMsHGg

Some are split into individual polygons: https://ibb.co/SKXCJR8

Others are not: https://ibb.co/7WqNB9q

All broken up pieces: https://ibb.co/Pr0smrw

Upvotes: 0

Views: 1062

Answers (1)

Reza
Reza

Reputation: 65

Wish I could comment instead of just answer but hard to say with out code.

Basically you are getting multipart polygons, you need to break those up.

Use a split in your array to break up the multi-part polygons split("]],[[")

Simplify Polygons using a geometry service would be worth a shot too. (before and after cutting)

https://developers.arcgis.com/rest/services-reference/geometry-service.htm

Upvotes: 1

Related Questions