Геопространственный запрос

ArcGIS 8.x,9.x,10.x (Arcview, ArcEditor, Arcinfo).
Ответить
BodyZ
Участник
Сообщения: 70
Зарегистрирован: 04 сен 2009, 16:47
Репутация: 1

Геопространственный запрос

Сообщение BodyZ »

Доброго времени суток.
Помогите разобраться с программированием пространственного запроса. :?:
Пробовал следующим образом.
По клику миши получаю координаты карты в point1 с помощью следующего кода

Код: Выделить всё

         
                  IMxDocument m_doc = m_application.Document as IMxDocument;
                  IActiveView pActiveView = m_doc.FocusMap as IActiveView;
                  IPoint point1 = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
Потом мне необходимо определить для конкретного слоя какой объект имеет такие координаты.
Сделать это пытаюсь с помощью ISpatialFilter.
Вот пример кода, взял сдесь

Код: Выделить всё

               
              IFeatureClass featureClass = (pLayer as IFeatureLayer).FeatureClass;  
 // Create the envelope and define its position.
             IEnvelope envelope = new EnvelopeClass();
             envelope.PutCoords( point1.X - 0.9, point1.Y - 0.9,point1.X + 0.9, point1.Y + 0.9 );
// Create the spatial filter and set its spatial constraints.
            ISpatialFilter spatialFilter = new SpatialFilterClass();
            spatialFilter.Geometry = envelope;
            spatialFilter.GeometryField = featureClass.ShapeFieldName;
            spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects;
 // Set the attribute constraints and subfields.
 // We want to exclude ramps, highways and interstates.
            spatialFilter.WhereClause = "Id = 0";
            spatialFilter.SubFields = "Id";
// Execute the query.
            IFeatureCursor featureCursor = featureClass.Search(spatialFilter, true);
Но ни одного объекта не находится :|
Помогите плиз. Не знаю что делать. :mrgreen:
Заранее спасибо за помощь
BodyZ
Участник
Сообщения: 70
Зарегистрирован: 04 сен 2009, 16:47
Репутация: 1

Re: Геопространственный запрос

Сообщение BodyZ »

Получилось сделать так

Код: Выделить всё

        public IFeature GetInfoAboutObject(IFeatureClass featureClass, IPoint pointOfCenter,int Radius)
        {
            ITopologicalOperator topOperator = pointOfCenter as ITopologicalOperator;
            IGeometry geometry = topOperator.Buffer(Radius); //Радиус задается в метрах
            // Create the spatial filter and set its spatial constraints.
            ISpatialFilter spatialFilter = new SpatialFilterClass();
            spatialFilter.Geometry = geometry;
            spatialFilter.GeometryField = featureClass.ShapeFieldName;
            spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
            // Execute the query.
            IFeatureCursor featureCursor = featureClass.Search(spatialFilter, true);
            return featureCursor.NextFeature();
        }
Ответить

Вернуться в «ArcGIS»

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и 9 гостей