Select to view content in your preferred language

Buffer the geometry type extent??

2327
2
09-22-2010 03:19 AM
MattiasEkström
Frequent Contributor
I have my own widget in the SFV 1.3 were the user draws either a point, polyline, polygon or extent, which is used for a spatial query. This works fine.
Now I've added a numeric stepper where the user may choose to make the query using a buffer around the point/polyline/polygon/extent. This works for all types except the extent.
I've added a Fault handler that gives me this message:
faultCode:400 faultString:'' faultDetail:'Invalid geometry type: 'esriGeometryEnvelope''

Is it impossible to use the extent geometry type as an input to a buffer geometry service?
If so, is there a way to "convert" the extent/envelope to a polygon?

The buffer is using this geometry service: "http://sampleserver2.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"

and the code looks like this:
   private function itemClickHandler(event:ItemClickEvent):void
   {    
    switch (event.index)
    {
     case 0:
     {
      setMapAction(Draw.MAPPOINT, "Sök med Punkt", drawEnd);
      break;
     }
     case 1:
     {
      setMapAction(Draw.POLYLINE, "Sök med Linje", drawEnd);
      break;
     }
     case 2:
     {
      setMapAction(Draw.POLYGON, "Sök med Yta", drawEnd);
      break;
     }
     case 3:
     {
      setMapAction(Draw.EXTENT, "Sök med rektangel", drawEnd);
      break;
     }
    }
   }
   private function drawEnd(event:DrawEvent):void
   {
    clear();
    
    if (buffert.value > 0) {
     var bufferParameters:BufferParameters = new BufferParameters();
     bufferParameters.features = [event.graphic];
     bufferParameters.distances = [buffert.value];
     bufferParameters.unit = BufferParameters.UNIT_METER;
     bufferParameters.bufferSpatialReference = new SpatialReference(3021);
     
     myGeometryService.addEventListener(GeometryServiceEvent.BUFFER_COMPLETE, bufferCompleteHandler);
     myGeometryService.addEventListener(FaultEvent.FAULT, bufferFaultHandler);
     myGeometryService.buffer(bufferParameters);
     
     function bufferCompleteHandler(event:GeometryServiceEvent):void
     {
      myGeometryService.removeEventListener(GeometryServiceEvent.BUFFER_COMPLETE, bufferCompleteHandler);
      for each (var graphic:Graphic in event.graphics)
      {
       graphic.symbol = symbBuff;
       graphicsLayer.add(graphic);

       query.geometry = graphic.geometry;
       queryFastighet.execute(query);       
      }
     }
     function bufferFaultHandler(event:FaultEvent):void
     {
      Alert.show(event.fault.message.toString());
     } 
    }
    else {
     query.geometry = event.graphic.geometry;
     queryFastighet.execute(query);
    }
        
   }
Tags (2)
0 Kudos
2 Replies
RobertScheitlin__GISP
MVP Emeritus
Mattias,

   You do have to convert the extent to a polygon. It is easy because the extent only has 4 point. I an not somewhere that I can through together so code right now but look at the extent object and it has a minx, miny, maxx, and maxy that you would use to combine and create points that you in turn add to an array and then add to a ring of a new polygon.
0 Kudos
MattiasEkström
Frequent Contributor
Thanks for pointing me in the right direction!
I successfully managed to convert the extent to a polygon (and also had to handle just a click, that caused a buffer error, so just a click uses a point instead of a polygon), and it works fine.
Here's my code for converting an extent to a polygon if anyone is interested:
if (event.graphic.geometry  is com.esri.ags.geometry.Extent){
      var p1:MapPoint = new MapPoint(event.graphic.geometry.extent.xmin, event.graphic.geometry.extent.ymin, spatRef);
      var p2:MapPoint = new MapPoint(event.graphic.geometry.extent.xmin, event.graphic.geometry.extent.ymax, spatRef);
      var p3:MapPoint = new MapPoint(event.graphic.geometry.extent.xmax, event.graphic.geometry.extent.ymax, spatRef);
      var p4:MapPoint = new MapPoint(event.graphic.geometry.extent.xmax, event.graphic.geometry.extent.ymin, spatRef);
      
      //If user doesn't draw an extent but just click using the draw extent tool, we have to use a MapPoint instead of a Polygon
      if ((event.graphic.geometry.extent.xmin == event.graphic.geometry.extent.xmax) && (event.graphic.geometry.extent.ymin == event.graphic.geometry.extent.ymax)){
       myGraphic = new Graphic(p1,symbBuff,spatRef); 
      } else {
       var myPoints:Array = new Array(p1, p2, p3, p4, p1);
       var myRing:Array = new Array(myPoints);
       var myPolygon:Polygon = new Polygon(myRing,spatRef);
       myGraphic = new Graphic(myPolygon,symbBuff,spatRef); 
      }
      
      bufferParameters.features = [myGraphic];
      
     } else {
      bufferParameters.features = [event.graphic];
     }
0 Kudos