Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm trying to intersect two layers and get resulting features with the following code I've written:

   ESRI.ArcGIS.Geodatabase.ISpatialFilter spatialFilter = new ESRI.ArcGIS.Geodatabase.SpatialFilterClass();
   spatialFilter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelIntersects;

   int indOfLayer1 = Int32.Parse(ConvertFromLayerNameToLayerId(m_Map, m_ResourceMapItem, m_firstLayerName));
   int indOfLayer2 = Int32.Parse(ConvertFromLayerNameToLayerId(m_Map, m_ResourceMapItem, m_masterLayerName));


   // Get the map underlying the map service and the IGeoFeatureLayers contained in the map
   ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal mfunct = 
                    (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal)
   m_Map.MapResourceManagerInstance.GetResource(m_ResourceMapItem);
   ESRI.ArcGIS.Carto.IMapServer iMapServer = (ESRI.ArcGIS.Carto.IMapServer)mfunct.MapServer;

    ESRI.ArcGIS.Carto.IMapServerObjects mapServerObjects = (ESRI.ArcGIS.Carto.IMapServerObjects)iMapServer;
    ESRI.ArcGIS.Carto.IMap map = mapServerObjects.get_Map(iMapServer.DefaultMapName);
    ESRI.ArcGIS.esriSystem.UID layerTypeID = new ESRI.ArcGIS.esriSystem.UIDClass();
    layerTypeID.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}"; //feature layer
    ESRI.ArcGIS.Carto.IEnumLayer enumLayer = map.get_Layers(layerTypeID, true);
    enumLayer.Reset();

    // first layer
    ESRI.ArcGIS.Carto.IFeatureLayer featureLayer1 = map.get_Layer(indOfLayer1) as ESRI.ArcGIS.Carto.IFeatureLayer;

    // master layer (second)
    ESRI.ArcGIS.Carto.IFeatureLayer featureLayer2 = map.get_Layer(indOfLayer2) as ESRI.ArcGIS.Carto.IFeatureLayer;

    spatialFilter.Geometry = (IGeometry)multipointPoints2;

    // perform the query
    ESRI.ArcGIS.Geodatabase.IFeatureCursor cursor = featureLayer1.Search(spatialFilter, true);

    ESRI.ArcGIS.Geodatabase.IFeature feature = null;
    // Create a ComReleaser for cursor management.
    IGeometryCollection formetotali = new MultipointClass();
    ESRI.ArcGIS.ADF.ComReleaser comReleaser = new ESRI.ArcGIS.ADF.ComReleaser();
    // Create and manage a cursor.
    comReleaser.ManageLifetime(cursor);
    object missing = Type.Missing;
    // Delete the retrieved features.

    while ((feature = cursor.NextFeature()) != null)
    {
        ESRI.ArcGIS.Geometry.IGeometry mageometry = feature.Shape;
        formetotali.AddGeometry(mageometry, ref missing, ref missing);
    }


    DrawIGeometryOnMap(m_Map, (IGeometry)formetotali);

but I'm getting no results at all even if the layers intersect

What's wrong with that?

share|improve this question
    
Where do you declare multipointPoints2? –  MathiasWestin Sep 2 '11 at 13:47
    
You are building a feature cursor using a spatial filter. What results do you get when you do this with the default tools (Select by Location). That would be my first step in debugging this. then put breakpoints in your code and examine variables. –  Jakub Sep 2 '11 at 15:11
    
Thank you for your interest: multipointPoints2 is a IGeometry object which contains one of the two layers. It is correct and I know it because I've drawn it correctly. If you need the code anyway, I'll post it. The feature cursor usually returns nothing. Sometimes it returns 3 elements which are not drawn at all on the screen so I can't say what are they representing –  Marco A. Sep 2 '11 at 15:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.