Select from NALayer

565
4
Jump to solution
12-28-2013 03:49 AM
AysberqTundra
Occasional Contributor
Hello.

I want to select a feature from Network Analysis layer. I have the result (naLayer), which is solution of some Network Analysis problem. But when I cast   naLayer as IfeatureLayer   I get NULL.

Can anyone help me to solve this problem?

 SelectByAttributeQuery(naLayer as IfeatureLayer, "myQuery", true);   public void SelectByAttributeQuery(IFeatureLayer featureLayer,String whereClause,bool justOne) {     IMap m_map = axMapControl.Map;     if (m_map.SelectionCount > 0) m_map.ClearSelection();     IFeatureSelection featureSelection = featureLayer as IFeatureSelection;     IQueryFilter queryFilter = new QueryFilterClass();     queryFilter.WhereClause = whereClause;     featureSelection.SelectFeatures(queryFilter,esriSelectionResultEnum.esriSelectionResultNew,justOne);      axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); }
0 Kudos
1 Solution

Accepted Solutions
AysberqTundra
Occasional Contributor
Sanjay, many thanks for your reply.
I can get ILayer from INALayer, but when I try get IFeatureLayer from that ILayer I get NULL.

But I solved this problem using following way:

     IFeatureClass routesFeatureClass = m_NAContext.NAClasses.get_ItemByName("Routes") as IFeatureClass;      IFeatureLayer routesFeatureLayer = new FeatureLayerClass();      routesFeatureLayer.FeatureClass = routesFeatureClass;      axMapControl.AddLayer(routesFeatureLayer as ILayer, 0);      SelectByAttributeQuery(routesFeatureLayer, "myWhereClause", true);  

View solution in original post

0 Kudos
4 Replies
SanajyJadhav
Occasional Contributor II
So, do you get false when you execute following line?

if ( naLayer is IFeatureLayer) 
{

}
0 Kudos
SanajyJadhav
Occasional Contributor II
INALayer is implemented by NALayerClass class. This class also implements ILayer and other interfaces but not IFeatureLayer. This could be the reason.

Can you try to get ILayer from INALayer and then IFeatureLayer from ILayer?

HTH.
0 Kudos
AysberqTundra
Occasional Contributor
Sanjay, many thanks for your reply.
I can get ILayer from INALayer, but when I try get IFeatureLayer from that ILayer I get NULL.

But I solved this problem using following way:

     IFeatureClass routesFeatureClass = m_NAContext.NAClasses.get_ItemByName("Routes") as IFeatureClass;      IFeatureLayer routesFeatureLayer = new FeatureLayerClass();      routesFeatureLayer.FeatureClass = routesFeatureClass;      axMapControl.AddLayer(routesFeatureLayer as ILayer, 0);      SelectByAttributeQuery(routesFeatureLayer, "myWhereClause", true);  
0 Kudos
SanajyJadhav
Occasional Contributor II
Glad your issue is fixed and thanks for posting the solution.
0 Kudos