Select to view content in your preferred language

Convert a Polygon to Polyline for cut

5724
4
Jump to solution
04-01-2013 09:25 AM
by Anonymous User
Not applicable
I'm attempting to clip polygons with another polygon using the the cut operation.  The geomtry service requires a polyline for the "cutter" and the target can be polygons.  I have a polygon that I need to convert to a polyline(paths) before I can do the clip/cut.  Does someone have the code to do this conversion.  It might be simple - but, I can't find it.  thanks
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Dan,

   Just take the Polygons.rings array and set them to the paths array of a new polyline.

View solution in original post

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus
Dan,

   Just take the Polygons.rings array and set them to the paths array of a new polyline.
0 Kudos
by Anonymous User
Not applicable
cutPline.paths = poly.rings;
Well, I have have my polyline, thanks - let's see if I can use it to cut some polygons.


Dan,

   Just take the Polygons.rings array and set them to the paths array of a new polyline.
0 Kudos
by Anonymous User
Not applicable
    function polygonToPolyline(polygon:Polygon):Polyline
    {
     const polyline:Polyline = new Polyline;
     for each (var ring:Array in polygon.rings)
     {
      polyline.addPath(ring);
     }
     return polyline;
    }  
0 Kudos
PriyaRam
Deactivated User
    function polygonToPolyline(polygon:Polygon):Polyline
    {
     const polyline:Polyline = new Polyline;
     for each (var ring:Array in polygon.rings)
     {
      polyline.addPath(ring);
     }
     return polyline;
    }  


I tried with your example provided, but the cut didn't work. Did you get this working? Two polygons overlap on the top of each other in my case. Probably I'm missing a spatial reference, where should I set it.


              var arr:Array = fireAreas.selectedFeatures;
        
 var polyLineTemp:Polyline = polygonToPolyline( ((arr[1] as Graphic).geometry) as Polygon);
     
 var arr1:Array = [];
 arr1.push((arr[0] as Graphic ).geometry);
              
 geomService.cut( arr1,polyLineTemp, new AsyncResponder(onQueryResult, onQueryFault) );

Thanks,,
Priya
0 Kudos