Select to view content in your preferred language

combine graphics

849
1
01-07-2013 11:29 AM
karldailey
Deactivated User
I want to do a query on one or more drawn polygons.  Is there a way to combine the graphics and send them as one geometry to the query?
Tags (2)
0 Kudos
1 Reply
RobertScheitlin__GISP
MVP Emeritus
Karl,

   You will need to work with lower level geometries like rings and points. Here is a function I use in one of my widgets for this:

            /*
            * Function That takes all the graphics in a defined GraphicsLayer and adds unions them into one geometry
            *    @param GraphicsLayer gl is the graphics layer to union
            *    @return Geometry of the unioned graphics
            */
            private function unionGeoms2(gl:GraphicsLayer):Geometry
            {
                var retGeom:Geometry;
                var mPoint:Multipoint = new Multipoint(null);
                mPoint.spatialReference = map.spatialReference;
                var mPoly:Polygon = new Polygon(null);
                mPoly.spatialReference = map.spatialReference;
                var mPolyL:Polyline = new Polyline(null);
                mPolyL.spatialReference = map.spatialReference;
                var rType:String;
                for each (var graphic:Graphic in gl.graphicProvider){
                    if(graphic.geometry.type == "esriGeometryPoint" && !addTolerance.selected){
                        mPoint.addPoint(graphic.geometry as MapPoint);
                        rType = "point";
                    }else if (graphic.geometry.type == "esriGeometryPoint" && addTolerance.selected){
                        var ext2:Extent = createExtentAroundMapPoint(graphic.geometry as MapPoint, pointSearchTolerance) as Extent;
                        var pA2:Array = [];
                        pA2.push(new MapPoint(ext2.xmin,ext2.ymin,ext2.spatialReference));
                        pA2.push(new MapPoint(ext2.xmin,ext2.ymax,ext2.spatialReference));
                        pA2.push(new MapPoint(ext2.xmax,ext2.ymax,ext2.spatialReference));
                        pA2.push(new MapPoint(ext2.xmax,ext2.ymin,ext2.spatialReference));
                        pA2.push(new MapPoint(ext2.xmin,ext2.ymin,ext2.spatialReference));
                        mPoly.addRing(pA2);
                        rType = "poly";
                        mPoly.spatialReference = ext2.spatialReference;
                    }
                    
                    if(graphic.geometry.type == "esriGeometryMultipoint"){
                        var mp:Multipoint = graphic.geometry as Multipoint
                        var pnts:MapPoint;
                        for (var p:int=0;p < mp.points.length; p++){
                            mPoint.addPoint(mp.points
);
                        }
                        rType = "point";
                    }
                    
                    if(graphic.geometry.type == "esriGeometryPolygon"){
                        var poly:Polygon = graphic.geometry as Polygon;
                        for (var i2:int = poly.rings.length - 1; i2 >= 0; i2--){
                            var ringArray:Array = [];
                            for (var j1:int = 0; j1 < poly.rings[i2].length; j1++){
                                var mp2:MapPoint = poly.getPoint(i2,j1) as MapPoint;
                                mp2.spatialReference = poly.spatialReference;
                                ringArray.push(mp2);
                            }
                            mPoly.addRing(ringArray);
                        }
                        rType = "poly";
                        mPoly.spatialReference = poly.spatialReference;
                    }
                    
                    if(graphic.geometry.type == "esriGeometryPolyline"){
                        var polyl:Polyline = graphic.geometry as Polyline;
                        for(var l:int=polyl.paths.length-1; l >= 0; l--){
                            var pathArray:Array = [];
                            for (var j2:int = 0; j2 < polyl.paths.length; j2++){
                                var mp3:MapPoint = polyl.getPoint(l,j2) as MapPoint;
                                mp3.spatialReference = polyl.spatialReference;
                                pathArray.push(mp3);
                            }
                            mPolyL.addPath(pathArray);
                        }
                        rType = "line";
                    }
                    
                    if(graphic.geometry.type == "esriGeometryEnvelope"){
                        var ext:Extent = graphic.geometry as Extent;
                        var pA:Array = [];
                        pA.push(new MapPoint(ext.xmin,ext.ymin,ext.spatialReference));
                        pA.push(new MapPoint(ext.xmin,ext.ymax,ext.spatialReference));
                        pA.push(new MapPoint(ext.xmax,ext.ymax,ext.spatialReference));
                        pA.push(new MapPoint(ext.xmax,ext.ymin,ext.spatialReference));
                        pA.push(new MapPoint(ext.xmin,ext.ymin,ext.spatialReference));
                        mPoly.addRing(pA);
                        rType = "poly";
                    }
                }
                
                switch(rType){
                    case "point":{
                        retGeom = mPoint;
                        break;
                    }
                    case "poly":{
                        retGeom = mPoly;
                        break;
                    }
                    case "line":{
                        retGeom = mPolyL;
                        break;
                    }
                }
                return retGeom;
            }


Don't forget to click the Mark as answer check on this post and to click the top arrow (promote).
Follow these steps as shown in the below graphic:

0 Kudos