1

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.

Kadir Şahbaz
78.6k57 gold badges260 silver badges407 bronze badges
asked Jun 16, 2017 at 8:56
7
  • 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. Commented Jun 16, 2017 at 10:37
  • Here's a sample: desktop.arcgis.com/en/arcobjects/latest/net/… Commented Jun 16, 2017 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. Commented Jun 16, 2017 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 Commented Jun 18, 2017 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; Commented Jun 18, 2017 at 8:16

1 Answer 1

1

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);
answered Jun 16, 2017 at 14:37
1
  • 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. Commented Jun 18, 2017 at 8:20

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.