0

Visual Studio

As you can see the other attributes are doing well, but the shape of the feature throw an exception "Shape = "(pFeature).Shape" raises an exception of type "System.Runtime.InteropServices.COMException"". Why?

 a = axMapControl1.get_Layer(j) as ICompositeLayer;

 pfl = a.get_Layer(0) as IFeatureLayer;
 IFeatureClass pfeatureclass = pfl.FeatureClass;
 if (pfl != null)
 {
 IQueryFilter queryFilter = new QueryFilterClass
 {
  SubFields = "Id",
  WhereClause = "Id = " + pointid
 };

 pFeatureSelection = pfl as IFeatureSelection;
 pFeatureSelection.Clear();
 pFeatureSelection.SelectFeatures(queryFilter, esriSelectionResultEnum.esriSelectionResultNew, true);
 pSelectionSet = pFeatureSelection.SelectionSet;
 IFeatureCursor pFeatureCursor = pfl.Search(queryFilter, true);          
 IFeature pFeature;
 pFeature = pFeatureCursor.NextFeature();   
1
  • May be not your problem but why do you create a SelectionSet then completely ignore it and access the feature via the FeatureLayer?
    – Hornbydd
    Commented Nov 30, 2018 at 10:26

1 Answer 1

1

Your issue is that you are only retrieving the "Id" field with your query. The

feature.Shape 

attribute is simply a shortcut for

feature.Value[shape_field_index] 

and therefore still requires you to retrieve it with your query.

IQueryFilter queryFilter = new QueryFilterClass
 {
  SubFields = "Id", "Shape" //or whatever your shape field is called
  WhereClause = "Id = " + pointid
 };
0

Your Answer

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

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