Пример #1
0
        public IEnumerable <UInt32> ExecuteOidQuery(SpatialBinaryExpression query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            SpatialExpression spatialExpression = query.SpatialExpression;

            if (SpatialExpression.IsNullOrEmpty(spatialExpression))
            {
                yield break;
            }

            if (query.Expression == null)
            {
                throw new ArgumentException("The SpatialQueryExpression must have " +
                                            "a non-null Expression.");
            }

            ExtentsExpression  extentsExpression  = spatialExpression as ExtentsExpression;
            GeometryExpression geometryExpression = spatialExpression as GeometryExpression;

            IExtents filterExtents = extentsExpression != null
                                         ? extentsExpression.Extents
                                         : null;
            IGeometry filterGeometry = geometryExpression != null
                                           ? geometryExpression.Geometry
                                           : null;

            Assert.IsTrue(filterExtents != null || filterGeometry != null);

            Boolean          isLeft = query.IsSpatialExpressionLeft;
            SpatialOperation op     = query.Op;

            LayerExpression layerExpression = query.Expression as LayerExpression;

            if (layerExpression != null)
            {
                for (UInt32 i = 0; i < _geometries.Count; i++)
                {
                    if (isGeometryAtIndexAMatch((Int32)i, op, isLeft, filterGeometry))
                    {
                        yield return(i);
                    }
                }

                yield break;
            }

            OidCollectionExpression oidsCollection = query.Expression as OidCollectionExpression;

            if (oidsCollection != null)
            {
                if (oidsCollection.Right == null)
                {
                    throw new ArgumentException("The OidCollectionExpression in the query " +
                                                "has a null collection");
                }

                IEnumerable oids = oidsCollection.Right.Collection;

                if (oids == null)
                {
                    yield break;
                }

                foreach (Object oid in oids)
                {
                    if (isGeometryAtIndexAMatch((Int32)oid, op, isLeft, filterGeometry))
                    {
                        yield return((UInt32)oid);
                    }
                }

                yield break;
            }
        }
Пример #2
0
        //private void handleLayersChanged(Object sender, ListChangedEventArgs e)
        //{
        //    IFeatureLayer newLayer = null;
        //    IFeatureLayer oldLayer = null;

        //    if (e.NewIndex >= 0 && e.NewIndex < Map.Layers.Count)
        //    {
        //        newLayer = Map.Layers[e.NewIndex] as IFeatureLayer;
        //    }

        //    if (e.OldIndex >= 0 && e.OldIndex < Map.Layers.Count && _highlightUpdating)
        //    {
        //        oldLayer = Map.Layers[e.OldIndex] as IFeatureLayer;
        //    }

        //    if (newLayer != null && e.ListChangedType == ListChangedType.ItemAdded)
        //    {
        //        wireupFeatureLayer(newLayer);
        //    }

        //    // BUG: this shouldn't work... e.OldIndex won't be the old layer
        //    // index if it was deleted...
        //    // TODO: make unit test which confirms or refutes the above bug
        //    if (oldLayer != null &&
        //        e.NewIndex < 0 &&
        //        e.ListChangedType == ListChangedType.ItemDeleted)
        //    {
        //        unwireFeatureLayer(oldLayer);
        //    }
        //}

        private void handleViewFeaturesHighlightedChanged(Object sender,
                                                          FeaturesHighlightedChangedEventArgs e)
        {
            Trace.Info(TraceCategories.Presentation, "AttributePresenter handling " +
                       "view features highlighted changed");
#if DEBUG
            Trace.Debug(TraceCategories.Presentation, "Layer on which highlight change: " +
                        e.LayerName);
            Trace.Debug(TraceCategories.Presentation, "Highlighted features: " +
                        EnumerablePrinter.Print(e.HighlightedFeatures));
#endif

            if (_highlightUpdating)
            {
                return;
            }

            ILayer layer = Map.Layers[e.LayerName];

            IFeatureLayer featureLayer = layer as IFeatureLayer;

            if (featureLayer == null)
            {
                LayerGroup group = layer as LayerGroup;

                if (group != null)
                {
                    featureLayer = group.MasterLayer as IFeatureLayer;
                }
            }

            Assert.IsNotNull(featureLayer);

            FeatureQueryExpression viewDefinition = featureLayer.HighlightedFilter;

            IEnumerable             oids          = getFeatureIdsFromIndexes(featureLayer, e.HighlightedFeatures);
            OidCollectionExpression oidExpression = new OidCollectionExpression(oids);

            if (viewDefinition == null)
            {
                viewDefinition = new FeatureQueryExpression(new AllAttributesExpression(),
                                                            oidExpression, null);
            }
            else
            {
                ProjectionExpression projection = viewDefinition.Projection;

                if (viewDefinition.SpatialPredicate == null)
                {
                    viewDefinition = new FeatureQueryExpression(projection, oidExpression, null);
                }
                else
                {
                    PredicateExpression predicate = new BinaryExpression(viewDefinition.SpatialPredicate,
                                                                         BinaryOperator.And,
                                                                         oidExpression);
                    viewDefinition = new FeatureQueryExpression(projection, predicate, null);
                }
            }

            _highlightUpdating             = true;
            featureLayer.HighlightedFilter = viewDefinition;
            _highlightUpdating             = false;
        }
Пример #3
0
        public void VariousFilteringCombinationTestSequence()
        {
            // this horrendous sequence is what I had time alloted for
            // takes some better setup to factor into tests that test 1 thing
            FeatureDataTable <Guid> table;
            FeatureDataView         view;

            createDataViewOnNewTable(out view, out table, false);

            Assert.Equal(table.Rows.Count, view.Count);

            SpatialBinaryExpression spatialFilter =
                SpatialBinaryExpression.Intersects(_factories.GeoFactory.WktReader.Read("POLYGON ((19 19, 21 19, 20 21, 19 19))"));

            // test basic spatial filter
            view.SpatialFilter = spatialFilter;

            Assert.Equal(3, view.Count);

            // setup for combination tests
            List <Guid> oidsInSpatialFilter = new List <Guid>(3);

            foreach (FeatureDataRow row in (IEnumerable <FeatureDataRow>)view)
            {
                oidsInSpatialFilter.Add((Guid)row.GetOid());
            }

            List <Guid> oidsNotInSpatialFilter = new List <Guid>(table.Rows.Count - 3);

            foreach (FeatureDataRow <Guid> row in table)
            {
                if (!oidsNotInSpatialFilter.Contains(row.Id))
                {
                    oidsNotInSpatialFilter.Add(row.Id);
                }
            }

            List <Guid> twoOidsFromEachList = new List <Guid>(4);

            twoOidsFromEachList.AddRange(oidFilterSource(oidsInSpatialFilter, 2));
            twoOidsFromEachList.AddRange(oidFilterSource(oidsNotInSpatialFilter, 2));

            // test spatial filter and oid filter
            OidCollectionExpression spanningOids = new OidCollectionExpression(twoOidsFromEachList);

            view.OidFilter = spanningOids;

            Assert.Equal(2, view.Count);

            // test clearing spatial component
            view.SpatialFilter = null;

            Assert.Equal(4, view.Count);

            // test inverting oid filter
            view.IsViewDefinitionExclusive = true;

            Assert.Equal(table.Rows.Count - 4, view.Count);

            // test both components with inversion
            view.SpatialFilter = spatialFilter;

            Assert.Equal(table.Rows.Count - 2, view.Count);

            // test clearing OidFilter
            view.OidFilter = null;

            Assert.Equal(table.Rows.Count - 3, view.Count);

            // test clearing inversion
            view.IsViewDefinitionExclusive = false;

            Assert.Equal(3, view.Count);

            // test clearing everything
            view.SpatialFilter = null;

            Assert.Equal(table.Rows.Count, view.Count);
        }