How to do intersection in Flex?

4394
14
07-07-2015 07:32 AM
akshayloya
Occasional Contributor II

Hi All,

Can any help me with code in flex which can intersect two feature class?

Regards

Tags (2)
0 Kudos
14 Replies
RobertScheitlin__GISP
MVP Emeritus

Akshay,

   The intersect ability that the Flex API has is designed for a array of geometries and a SINGLE geometry. So intersecting two feature classes is a little difficult.

Here is the Flex API docs on the GeometryService: intersect() method:

com.esri.ags.tasks.GeometryService

0 Kudos
akshayloya
Occasional Contributor II

Robert,

I'm querying on one feature class and getting its geometries and passing that geometry to intersect with other layer.

Can you please share code snippet to pass array of geometries.

Regards

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Akshay,

  1. So your query results, do you have more than one geometry?
  2. What is the geometry type?
  3. The layer that you want to intersect with what geometry type is it?
  4. You understand that you will have to union all the geometries of the layer into one geometry using the Geometry service right?
  5. Which geometries will be the input and which will be the intersect feature?
0 Kudos
akshayloya
Occasional Contributor II

Yes more than one geometry. Yes I'm using GeometryService.

Geometry type is polygon which I'm trying to get it unioned but it is throwing an error.

Intersect feature can be point line or polygon.

Regards,

Akshay Loya

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Akshay,

   The union of the layers geometries is going to be the critical part then. If you can not get the layers geometries to union using the geometry service then this is issue. Have you tried to check the layer geometry in ArcMap using the "Check Geomtery" tool?

0 Kudos
akshayloya
Occasional Contributor II

Robert,

That is fine. Mine is SDE Geodatabases, it automatically check the validity of each geometry when they are uploaded.

Error:

Suspended: TypeError: Error #1034: Type Coercion failed: cannot convert com.esri.ags.geometry::Polygon@11bdc129 to com.esri.ags.events.GeometryServiceEvent.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Akshay,

   Can I see your code that you are using to do the union?

0 Kudos
akshayloya
Occasional Contributor II

Robert,

This the code I'm using:

         var queryT:QueryTask = new QueryTask();

                                         queryT.url = "url";

                                         queryT.useAMF= false;

                                         var queryB:Query = new Query();

                                         queryB.outSpatialReference = map.spatialReference;

                                         queryB.returnGeometry = true;

                                         queryB.outFields = ["*"];

                                         queryB.where= "DCPDistrictCode = 123";

                                         queryT.execute(queryB, new AsyncResponder(onResultT, onFaultT));

                                         function onResultT(featureSetB:FeatureSet, token:Object = null):void

                                         {

                                                var graphicProvider1:ArrayCollection = new  ArrayCollection();

                                                if (featureSetB.features.length == 0)

                                                {

                                                       Alert.show(resourceManager.getString('ViewerStrings', 'SearchAlert3'));

                                                }

                                                else

    for each(var myFirstGraphic:Graphic in  featureSetB.features)
     

                                                   {

                                                       var arrtest:Array= new Array;

       arrtest.push(myFirstGraphic.geometry);
   }

responder = new mx.rpc.Responder(myGeometryService_unionCompleteHandler,myGeometryService_faultHandler);
myGeometryService.union(arrtest,responder);

}

                     protected function myGeometryService_unionCompleteHandler(event:GeometryServiceEvent):void

                     {

                           doQuery(event.result[0] as Geometry);

                          

                     }

                    

                     protected function myGeometryService_faultHandler(event:FaultEvent):void

                     {

                           Alert.show("Service temporarily unavailable. Please try again","Information")

                     }

                    

                     protected function doQuery(geom:Geometry):void

                     {

                           query.geometry = geom;

                           query.outFields = ["*"];

                           query.outSpatialReference = map.spatialReference;

                           query.returnGeometry = true;

                           query.spatialRelationship = Query.SPATIAL_REL_INTERSECTS;                        

                           QueryTk.url = "url";

                           QueryTk.useAMF = false;

                           QueryTk.execute(query,new AsyncResponder(QueryIntersect,QueryIntersectFault));

                     }

                     protected function QueryIntersect(featureSetSpa:FeatureSet, token:Object = null):void

                     {

                           if (featureSetSpa.features.length = 0)

                           {

                                 

                                  Alert.show("No Records found");

                                  cursorManager.removeBusyCursor();

                           }

                           else

                           {

                                  var arrObjectId:Array=new Array();

                                  var strObjectId:String= new String();

                                  for(var i:int=0;i<featureSetSpa.features.length;i++)

                                  {

                                         arrObjectId.push("'" +FeatureSet+ "'");

                                  }

                                  strObjectId = arrObjectId.toString() ;

                                

                           }

                       }

                     protected function QueryIntersectFault(featureSet:FeatureSet, token:Object = null):void

                     {

                           Alert.show("Service temporarily unavailable. Please try again","Information");

                     }

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Akshay,

  This portion of your code concerns me:

function onResultT(featureSetB:FeatureSet, token:Object = null):void
{
  var graphicProvider1:ArrayCollection = new  ArrayCollection();
  if (featureSetB.features.length == 0){
    Alert.show(resourceManager.getString('ViewerStrings', 'SearchAlert3'));
  }else
    for each(var myFirstGraphic:Graphic in  featureSetB.features)
    {
      var arrtest:Array= new Array;
      arrtest.push(myFirstGraphic.geometry);
    }
    responder = new mx.rpc.Responder(myGeometryService_unionCompleteHandler,myGeometryService_faultHandler);
    myGeometryService.union(arrtest,responder);
}

Inside you for each loop you are recreating the arrtest array each time?...

0 Kudos