Description�?
I would like to query Feature in a specified layer that intersects the specified Feature.For example, I would like to query all of the roads that intersect my specified lake.
As the figure below,The load "1,2,3" all intersect with lake "0",so they should be query out.
[ATTACH=CONFIG]28504[/ATTACH]
I can just get selection feature in the MapControl,but I do not know what to do then.
//Here "f" can be "lake",and I do not know how to select the roads.
ISelection selection = mapControl.Map.FeatureSelection;
IEnumFeature enumF = (IEnumFeature)selection;
IFeature f = null;
while((f = enumF.Next()) != null) {
//To do with the selected feature with 'f'.
}
I would appreciate it if you can help me.Thanks very much.
I seems that I make it:/// <summary>
/// Query feature class with specified geometry.
/// </summary>
/// <param name="baseGeometry">The base gemotry.</param>
/// <param name="featureClass">the featurey class to query.</param>
/// <param name="spatialRel">RelationShip between base geometry and query feature class.</param>
/// <returns>The query result cursor.</returns>
public static ESRI.ArcGIS.Geodatabase.IFeatureCursor QueryFeatureClass(ESRI.ArcGIS.Geometry.IGeometry baseGeometry, ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass, ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum spatialRel){
ESRI.ArcGIS.Geodatabase.ISpatialFilter spatialFilter = new ESRI.ArcGIS.Geodatabase.SpatialFilterClass();
spatialFilter.Geometry = baseGeometry;
spatialFilter.SpatialRel = spatialRel;
return featureClass.Search(spatialFilter,false);
}
//mapControl contains all of the layers.
ISelection selection = mapControl.Map.FeatureSelection;
IEnumFeature enumF = (IEnumFeature)selection;
IFeature f = null;
while((f = enumF.Next()) != null) {
//The fcQuery contains the query result.
IFeatureClass fcQuery = ((IFeatureLayer)this._MapCon.get_Layer(combox_layer.SelectedIndex)).FeatureClass;
IFeatureCursor fc = RelationShip.QueryFeatureClass(f.Shape, fcQuery, esriSpatialRelEnum.esriSpatialRelIntersects);
IFeature fResult = null;
while((fResult = fc.NextFeature()) != null) {
MessageBox.Show(fResult.OID.ToString()); //To do with 'fResult'.
}
}