0

I am trying to get features from a given geometry (getting only layers ). This is not selection. The validate part I will be doing using configuration. But I am not able to get the features from the geometry.Even I thought to open an attribute table and check how many rows are there and if I can find the values for each row. But no luck Here is what I did#

IFeatureClass pFeatureClass= null;
while ((pThisLayer = pEnumLayer.Next()) != null)
  {
 pThisFeatLayer = pThisLayer as IFeatureLayer;

 IFeatureCursor pFtCur = pThisFeatLayer.Search(spatialFilter, false);
 pTable = (ITable)pThisFeatLayer;
 pFeatureClass = pThisFeatLayer.FeatureClass;

 //pFields = (IFields)pFeatureClass;
  pFt = pFtCur.NextFeature();
  if (pThisFeatLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
  {
        continue;
  }
  if (pFt != null)
  {

      pCursor = pTable.Search(spatialFilter, false);
      pRow = pCursor.NextRow();
      while (pRow != null)
      {
        //string.IsNullOrEmpty(output);

        //output += pRow.get_Value(count).ToString() + "\n";
        MessageBox.Show(pFt.Class.AliasName.ToString()+ "  " +count.ToString());
        count++;
        pRow = pCursor.NextRow();

       }

  }

}

pFt = pFtCur.NextFeature(); statement instead of returning the next feature it returns the next layer. I also tried to get help from ESRI sites but those are down for maintenance.

  • I don't have my dev environment handy, so I can't really check right now. At first looks however, your code looks confusing: You start by searching the featurelayer (thats ok), but inside the loop, you search on a table, which in fact points to the same featureclass. Why do you do that? I think you should leave out that 2nd search (and don't forget to insert an additional pft = pftcur.NextFeature()). Also, if you're not modifying the features, set the recycle parameter to true. And don't forget to release the cursor, use the ComReleaser class for that. – Berend Jun 16 '17 at 10:37
  • Here's a sample: desktop.arcgis.com/en/arcobjects/latest/net/… – Berend Jun 16 '17 at 10:42
  • It's unlikely that the Esri sites will be "down for maintenance" for the 24 hours this question will be in the first 50 questions, much less for as long as this Question will exist. – Vince Jun 16 '17 at 11:00
  • Hi Berend, Thanks for correcting me. I actually understood that before iterating through the layer itself I was moving through the other layer. Now it is working. But even if I execute spatial query I doubt that it is fetching from total map but what I want is like it must search from the given geometry only. Here is what I did to construct this spatial query – royan Jun 18 '17 at 8:13
  • IGraphicsContainer graphicsContainer = (IGraphicsContainer)pMap; IElement element = null; IFillShapeElement fillShapeElement = new PolygonElementClass(); fillShapeElement.Symbol = simpleFillSymbol; element = (IElement)fillShapeElement; // Explicit cast. element.Geometry = geometry; graphicsContainer.AddElement(element, 0); activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGraphics, null, null);ISpatialFilter spatialFilter = new SpatialFilter(); spatialFilter.Geometry = element.Geometry;spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; – royan Jun 18 '17 at 8:16
0

I'm not sure what would cause the behavior you are seeing, but I would recommend changing this line:

IFeatureCursor pFtCur = pThisFeatLayer.Search(spatialFilter, false);

to:

IFeatureCursor pFtCur = pThisFeatLayer.FeatureClass.Search(spatialFilter, false);
  • Hi Denielm, the behavior is same after inserting your code. But what Berend here has indicated is correct that I need to insert additional pft = pftcur.NextFeature() to iterate through. I did that and it worked. But I doubt that it is taking from total map not from the given geometry. – royan Jun 18 '17 at 8:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.