Converting a Feature Into a Layer

651
2
Jump to solution
06-21-2012 08:11 AM
BruceNielsen
Occasional Contributor III
If I am looping through a series of features using a featurecursor, how can I create a temporary layer of each feature? I'm planning on using the resulting layer as input to a geoprocessing tool (clip).
Dim pFCursor as IFeatureCursor
Dim pFeature as IFeature = pFCursor.NextFeature
Do Until pFeature is Nothing
    Need to create ILayer object from pFeature here
    pFeature = pFCursor.NextFeature
Loop
0 Kudos
1 Solution

Accepted Solutions
JohnNelson3
New Contributor III
What about setting the definition query of the initial layer using the feature???s  ID and feeding that layer into the clip tool?

View solution in original post

0 Kudos
2 Replies
FengZhang2
Occasional Contributor
One possible solution is to use the CreateSelectionLayer method with IFeatureLayerDefinition interface. First, construct a temporalLayer using the first function; then construct a query Filter for each feature in the loop; and call the second function to create one individual layer per feature.

public ITemporalLayer CreateTemporalLayer(IFeatureClass featureClass, string layerName, string trackIdField, string timeField)
{
 ITemporalLayer temporalLayer = new TemporalFeatureLayerClass();
 IFeatureLayer featureLayer = (IFeatureLayer)temporalLayer;
 featureLayer.FeatureClass = featureClass;
 featureLayer.Name = layerName;
 ITemporalRenderer temporalRenderer = (ITemporalRenderer)temporalLayer.Renderer;
 temporalRenderer.TemporalObjectColumnName = trackIdField;
 temporalRenderer.TemporalFieldName = timeField;
 temporalRenderer.ShowObservationLegendGroup = true;
 temporalRenderer.ShowTimeLegendGroup = true;
 temporalRenderer.Renderer = (IFeatureRenderer)temporalRenderer;
 return temporalLayer;
}

private ITemporalLayer CreateLayerSubset(IQueryFilter queryFilter, ITemporalLayer temporalLayer)
{
 IFeatureSelection featureSelection = (IFeatureSelection)temporalLayer;
 featureSelection.SelectFeatures(queryFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
 if(featureSelection.SelectionSet.Count == 0)
  throw new NoDataException();
 IFeatureLayerDefinition featureLayerDefinition = (IFeatureLayerDefinition)temporalLayer;
 ITemporalLayer queryResult = (ITemporalLayer)featureLayerDefinition.CreateSelectionLayer(temporalLayer.Name, true, null, null);
 return queryResult;
}  
0 Kudos
JohnNelson3
New Contributor III
What about setting the definition query of the initial layer using the feature???s  ID and feeding that layer into the clip tool?
0 Kudos