Select to view content in your preferred language

RPC error on Enhanced-Search-Widget

3788
15
Jump to solution
01-23-2014 08:51 AM
by Anonymous User
Not applicable
Original User: leonardo.brandao@gmail.com
Original Date: 2014-01-23T10:51:34-0600

Hi all,

I,m getting a unknown error "[RPC Fault faultString="Unable to complete operation." faultCode="400" faultDetail=""]" in my eSearch widget when I try to run a spatial query using the relationship "entirely contained in" to bring points within polygons.

This error happens when the polygons have a relationship of "contain" between them. That is, when a polygon contain other polygon.

When I have polygons that have intersection between them, identical polygon or polygons with no spatial relationship I do not get this error.

I am using flex api version 3.6 and the widget is also the latest version and I put two screenshots attached for better understanding.

Would anyone say how can I solve this problem?

Thanks,

Leonardo.
0 Kudos
15 Replies
by Anonymous User
Not applicable
Original User: rscheitlin

Leonardo,

   How are you determining if it is an inner ring or an outer ring?
0 Kudos
LeonardoAraújo
Deactivated User
I started testing all polygons to know if there were any that were contained by another. If so, put them in an array of discard and not used them in the union operation. I reached this goal by working with extensions of the polygons.

After that, with the polygons elected to union operation, I searched through all the existing rings of these polygons and turned them into polygons too and tested if the coordinates of their center (x, y using the extent attribute) coincided with the center of any polygon in the previously populated discard array.

If the coordinates of the center of the ring coincided, I did not include it in the array of rings that gave the simplified polygon returned by the function. That way I could simplify polygons with islands within them as if it were a dissolve function.

I hope you have understood,

Leonardo.
0 Kudos
by Anonymous User
Not applicable
Original User: rscheitlin

Leonardo,

   Okay, thanks for the explaination. I am sure I can re-create this functionality, but first I want to check if you are willing to contribute this code to the eSearchWidget?
0 Kudos
LeonardoAraújo
Deactivated User
Sure! Follows the code of the unionGeoms function that was to meet my needs.

 private function unionGeoms(featureSet:FeatureSet):Geometry
            {
                var graphic:Graphic;
                var retGeom:Geometry;
                var mPoint:Multipoint = new Multipoint;
  var poly:Polygon = new Polygon;
                var mPoly:Polygon = new Polygon;
                var mPolyL:Polyline = new Polyline;
                var rType:String;
    
  //Leonardo
  //For each polygon, tests if exists another that contains it.
  //If YES, the polygon will not included in union operation and it will added at polygonsToDiscard array.
  var aGraphic:Graphic;
  var polygonsToDiscard:Array = new Array;
  for each (graphic in featureSet.features){
   poly = graphic.geometry as Polygon;
   if(graphic.geometry.type == "esriGeometryPolygon"){
    for each (aGraphic in featureSet.features){
     var aPoly:Polygon = aGraphic.geometry as Polygon;
     if(aPoly.extent.contains(graphic.geometry) && (aPoly.extent.center.x != poly.extent.center.x || aPoly.extent.center.y != poly.extent.center.y)){
      // The polygon will not included in union operation.
      polygonsToDiscard.push(poly);
     }
    }
   }
  }
  //Leonardo: End of tests for discard polygons.
    
                for each (graphic in featureSet.features){
                    if(graphic.geometry.type == "esriGeometryPoint"){
                        mPoint.addPoint(graphic.geometry as MapPoint);
                        rType = "point";
                    }

                    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"){
   poly = graphic.geometry as Polygon;
      
   //Leonardo
   //Consider only the rings that not coincide with any polygon ring on polygonsToDiscard array.
   var targetRings:Array = new Array;
   for (var m:int = 0; m < poly.rings.length; m++){
    var polygonToDiscard:Polygon;
    var targetRing:Array = new Array;
    var targetPolygon:Polygon = new Polygon(new Array(poly.rings), poly.spatialReference);
    if (polygonsToDiscard.length > 0){
     for each (polygonToDiscard in polygonsToDiscard){
      var add:Boolean = true;
      if (targetPolygon.extent.center.x == polygonToDiscard.extent.center.x && targetPolygon.extent.center.y == polygonToDiscard.extent.center.y) {
       add = false;
       break;
      }
     }
     if(add){
      targetRing[0] = m;
      targetRing[1] = poly.rings;
      targetRings.push(targetRing);
     }
    } else {
     targetRing[0] = m;
     targetRing[1] = poly.rings;
     targetRings.push(targetRing);
    }
   }
   //Leonardo: End of target rings selection.
       
                        //Leonardo: Loop code below was changed to use targetRings array.
   for (var i2:int = targetRings.length - 1; i2 >=0; i2--){
                            var ringArray:Array = [];
       for (var j1:int = 0; j1 < targetRings[i2][1].length; j1++){
    var mp2:MapPoint = poly.getPoint(targetRings[i2][0],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";
                    }
                }
                var graphic2:Graphic = new Graphic();
                var sfs:SimpleFillSymbol = new SimpleFillSymbol();
                sfs.color = 0x0000FF;
                sfs.alpha = 0.2;
                var sms:SimpleMarkerSymbol = new SimpleMarkerSymbol();
                sms.color = 0x0000FF;
                sms.style = SimpleMarkerSymbol.STYLE_CIRCLE;
                sms.size = 8;
                sfs.alpha = 0.4;
                var sls:SimpleLineSymbol = new SimpleLineSymbol();
                sls.color = 0x0000FF;
                sls.style = SimpleLineSymbol.STYLE_SOLID;
                sls.width = 1;
                sls.alpha = 0.4;

                switch(rType){
                    case "point":{
                        graphic2.geometry = mPoint;
                        graphic2.symbol = sms;
                        graphicsLayerBuffer.clear();
                        graphicsLayerBuffer.add(graphic2);
                        retGeom = mPoint;
                        break;
                    }
                    case "poly":{
                        graphic2.geometry = mPoly;
                        graphic2.symbol = sfs;
                        graphicsLayerBuffer.clear();
                        graphicsLayerBuffer.add(graphic2);
                        retGeom = mPoly;
                        break;
                    }
                    case "line":{
                        graphic2.geometry = mPolyL;
                        graphic2.symbol = sls;
                        graphicsLayerBuffer.clear();
                        graphicsLayerBuffer.add(graphic2);
                        retGeom = mPolyL;
                        break;
                    }
                }
                return retGeom;
            }
0 Kudos
by Anonymous User
Not applicable
Original User: rscheitlin

Leonardo,

   Thanks for the code contribution. I will add and test the code before including it in the next release. I will place comments in the code giving you credit for this contribution.
0 Kudos
LeonardoAraújo
Deactivated User
We're here to help.

Regards and thanks again,

Leonardo.
0 Kudos