Интерфейс ISpatialQuery
Добавлено: 06 июн 2013, 19:24
Здравствуйте.
Решил организовать пространственный запрос. Вот код:
Круг рисуется правильно, но если в ISpatialFilter не использовать параметр SpatialRel, он выводит все объекты, а если использовать, то ни одного.
Помогите пожалуйста разобраться
Решил организовать пространственный запрос. Вот код:
Код: Выделить всё
#region для запроса
Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(@"C:\PI\California.gdb", 0);
IFeatureClass featureClass = featureWorkspace.OpenFeatureClass("Cities");
IFeature featureT = featureClass.CreateFeature();
#endregion
IGeometry pGeometry = null;
IUnitConverter uc = new UnitConverterClass();
double radius = uc.ConvertUnits(double.Parse(_tbRad.Text), esriUnits.esriMiles, esriUnits.esriDecimalDegrees);
try
{
IMxDocument imxdocument = ArcMap.Document;
ICircularArc arc = new CircularArcClass();
arc.PutCoordsByAngle(point, 0, 2 * Math.PI, radius);
IScreenDisplay screenDisplay = imxdocument.ActiveView.ScreenDisplay;
screenDisplay.StartDrawing(screenDisplay.hDC,
(System.Int16)ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache);
IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
rgbColor.Red = 255;
rgbColor.Transparency = 50;
IColor color = rgbColor;
ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass();
simpleLineSymbol.Color = color;
simpleLineSymbol.Width = 3;
ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass();
simpleMarkerSymbol.Color = color;
ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();
simpleFillSymbol.Color = color;
object missing = Type.Missing;
ISymbol symbol = (ESRI.ArcGIS.Display.ISymbol)simpleMarkerSymbol;
// polygon
ISegment pSegment = arc as ISegment;
ISegmentCollection pSegColl = new PolygonClass();
pSegColl.AddSegment(pSegment, ref missing, ref missing);
pGeometry = pSegColl as IGeometry;
symbol = (ESRI.ArcGIS.Display.ISymbol)simpleFillSymbol;
var transparencyDisplayFilter = new TransparencyDisplayFilterClass
{
Transparency = 127
};
screenDisplay.SetSymbol(symbol);
screenDisplay.Filter = transparencyDisplayFilter;
screenDisplay.DrawPolygon(pGeometry);
screenDisplay.FinishDrawing();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
ISpatialFilter spatialFilter = new SpatialFilterClass()
{
Geometry = pGeometry,
GeometryField = featureClass.ShapeFieldName
//SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects
};
IFeatureCursor featureCursor;
featureCursor = featureClass.Search(spatialFilter, true);
//comReleaser.ManageLifetime(featureCursor);
IFeature feature = null;
while ((feature = featureCursor.NextFeature()) != null)
{
MessageBox.Show(feature.Value[0].ToString());
//выводит ID элементов
}
Помогите пожалуйста разобраться