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.
1 Answer 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);
-
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– royan2017年06月18日 08:20:37 +00:00Commented Jun 18, 2017 at 8:20
pft = pftcur.NextFeature()
). Also, if you're not modifying the features, set therecycle
parameter totrue
. And don't forget to release the cursor, use the ComReleaser class for that.