public void RenderFeatureTest()
        {
            IFeatureProvider   provider       = DataSourceHelper.CreateGeometryDatasource(_factories.GeoFactory);
            TestVectorRenderer vectorRenderer = new TestVectorRenderer();
            BasicGeometryRenderer2D <RenderObject> geometryRenderer =
                new BasicGeometryRenderer2D <RenderObject>(vectorRenderer);

            FeatureDataTable       features = new FeatureDataTable(_factories.GeoFactory);
            IExtents               extents  = provider.GetExtents();
            FeatureQueryExpression query    = new FeatureQueryExpression(extents.ToGeometry(),
                                                                         SpatialOperation.Intersects,
                                                                         provider);

            features.Merge(provider.ExecuteFeatureQuery(query) as IEnumerable <IFeatureDataRecord>,
                           provider.GeometryFactory);

            foreach (FeatureDataRow feature in features)
            {
                IGeometry           g = feature.Geometry;
                List <RenderObject> renderedObjects = new List <RenderObject>(geometryRenderer.RenderFeature(feature));

                for (Int32 i = 0; i < renderedObjects.Count; i++)
                {
                    RenderObject ro = renderedObjects[i];
                }
            }
        }
예제 #2
0
        public void CreateLinealShapeFile()
        {
            var fdt = CreateLinealFeatureDataTable(_geometryFactory);

            using (var sfp = ShapeFileProvider.Create(".", "Lineal", ShapeType.PolyLine, fdt, _geometryFactory, new GeometryServices().CoordinateSystemFactory))
            {
                sfp.Open(WriteAccess.ReadWrite);
                foreach (FeatureDataRow row in fdt.Rows)
                {
                    sfp.Insert(row);
                }
            }


            int number = 0;
            var gs     = new GeometryServices();

            using (var sfp = new ShapeFileProvider("Lineal.shp", gs.DefaultGeometryFactory, gs.CoordinateSystemFactory))
            {
                sfp.IsSpatiallyIndexed = false;
                sfp.Open(WriteAccess.ReadOnly);
                using (var p = sfp.ExecuteFeatureQuery(FeatureQueryExpression.Intersects(sfp.GetExtents())))
                {
                    while (p.Read())
                    {
                        Assert.True(((FeatureDataRow)fdt.Rows[number]).Geometry.Equals(p.Geometry));
                        number++;
                        Console.WriteLine(string.Format("{0}; {1}; {2}", p.GetOid(), p.Geometry.GeometryTypeName, p.Geometry));
                    }
                }
            }
            Assert.True(number == 100);
        }
예제 #3
0
        public IFeatureDataReader ExecuteFeatureQuery(FeatureQueryExpression bounds,
                                                      FeatureQueryExecutionOptions options)
        {
            FeatureDataReader reader = new FeatureDataReader(_geoFactory, _features, bounds, options);

            return(reader);
        }
예제 #4
0
        public void AddingRowToTableTriggersViewListChangedItemAddedNotification()
        {
            FeatureProvider  data  = DataSourceHelper.CreateFeatureDatasource(_factories.GeoFactory);
            FeatureDataTable table = new FeatureDataTable(_factories.GeoFactory);

            IExtents halfBounds = data.GetExtents();

            halfBounds.Scale(0.5);

            FeatureQueryExpression query  = FeatureQueryExpression.Intersects(halfBounds);
            IFeatureDataReader     reader = data.ExecuteFeatureQuery(query);

            table.Load(reader, LoadOption.OverwriteChanges, null);
            FeatureDataView view = new FeatureDataView(table);

            Boolean addNotificationOccured = false;

            view.ListChanged += delegate(Object sender, ListChangedEventArgs e)
            {
                if (e.ListChangedType == ListChangedType.ItemAdded)
                {
                    addNotificationOccured = true;
                }
            };

            FeatureDataRow row = table.NewRow();

            row["Oid"]         = Guid.NewGuid();
            row["FeatureName"] = "New row";
            row.Geometry       = _factories.GeoFactory.CreatePoint2D(44, 44);
            table.AddRow(row);

            Assert.True(addNotificationOccured);
        }
예제 #5
0
        public void SettingOidFilterAllowsOnlyFeaturesContainingFilteredOidsInView()
        {
            FeatureProvider         data   = DataSourceHelper.CreateFeatureDatasource(_factories.GeoFactory);
            FeatureDataTable <Guid> table  = new FeatureDataTable <Guid>("Oid", _factories.GeoFactory);
            FeatureQueryExpression  query  = FeatureQueryExpression.Intersects(data.GetExtents());
            IFeatureDataReader      reader = data.ExecuteFeatureQuery(query);

            table.Load(reader, LoadOption.OverwriteChanges, null);
            Guid[] ids = new Guid[3];
            ids[0] = (table.Rows[1] as FeatureDataRow <Guid>).Id;
            ids[1] = (table.Rows[4] as FeatureDataRow <Guid>).Id;
            ids[2] = (table.Rows[6] as FeatureDataRow <Guid>).Id;
            FeatureDataView view = new FeatureDataView(table);

            view.OidFilter = new OidCollectionExpression(ids);

            Assert.Equal(3, view.Count);
            Assert.True(view.Find(ids[0]) > -1);
            Assert.True(view.Find(ids[1]) > -1);
            Assert.True(view.Find(ids[2]) > -1);
            Assert.Equal(-1, view.Find((table.Rows[0] as FeatureDataRow <Guid>).Id));
            Assert.Equal(-1, view.Find((table.Rows[2] as FeatureDataRow <Guid>).Id));
            Assert.Equal(-1, view.Find((table.Rows[3] as FeatureDataRow <Guid>).Id));
            Assert.Equal(-1, view.Find((table.Rows[5] as FeatureDataRow <Guid>).Id));
        }
예제 #6
0
        internal FeatureDataReader(IGeometryFactory factory,
                                   FeatureDataTable source,
                                   FeatureQueryExpression query,
                                   FeatureQueryExecutionOptions options)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            if (options != FeatureQueryExecutionOptions.FullFeature)
            {
                throw new ArgumentException("Only QueryExecutionOptions.All is supported.",
                                            "options");
            }

            _factory = factory;
            _options = options;
            _query   = query;
            _table   = source.Clone();

            foreach (FeatureDataRow row in source.Select(query.SpatialPredicate))
            {
                _table.ImportRow(row);
            }
        }
예제 #7
0
        public void ChangeViewSpatialFilterReturnsOnlyFilteredRows()
        {
            FeatureProvider        data   = DataSourceHelper.CreateFeatureDatasource(_factories.GeoFactory);
            FeatureDataTable       table  = new FeatureDataTable(_factories.GeoFactory);
            FeatureQueryExpression query  = FeatureQueryExpression.Intersects(data.GetExtents());
            IFeatureDataReader     reader = data.ExecuteFeatureQuery(query);

            table.Load(reader);
            IGeometry queryExtents = _factories.GeoFactory.CreateExtents2D(0, 0, 10, 10).ToGeometry();

            List <FeatureDataRow> expectedRows = new List <FeatureDataRow>();

            foreach (FeatureDataRow row in table)
            {
                IGeometry g = row.Geometry;

                if (queryExtents.Intersects(g))
                {
                    expectedRows.Add(row);
                }
            }

            FeatureDataView         view       = new FeatureDataView(table);
            SpatialBinaryExpression expression = SpatialBinaryExpression.Intersects(queryExtents);

            view.SpatialFilter = expression;

            Assert.Equal(expectedRows.Count, view.Count);
        }
예제 #8
0
        public void ChangeViewSpatialFilterTriggersNotification()
        {
            FeatureProvider        data   = DataSourceHelper.CreateFeatureDatasource(_factories.GeoFactory);
            FeatureDataTable       table  = new FeatureDataTable(_factories.GeoFactory);
            FeatureQueryExpression query  = FeatureQueryExpression.Intersects(data.GetExtents());
            IFeatureDataReader     reader = data.ExecuteFeatureQuery(query);

            table.Load(reader, LoadOption.OverwriteChanges, null);
            FeatureDataView view = new FeatureDataView(table);

            Boolean resetNotificationOccured = false;

            view.ListChanged += delegate(Object sender, ListChangedEventArgs e)
            {
                if (e.ListChangedType == ListChangedType.Reset)
                {
                    resetNotificationOccured = true;
                }
            };

            Assert.False(resetNotificationOccured);

            IExtents queryExtents = _factories.GeoFactory.CreateExtents2D(0, 0, 10, 10);
            SpatialBinaryExpression expression = SpatialBinaryExpression.Intersects(queryExtents);

            view.SpatialFilter = expression;

            Assert.True(resetNotificationOccured);
        }
        private void queueableBeginQuery(Object asyncResult)
        {
            AsyncResult<IFeatureDataReader> typedAsyncResult = asyncResult as AsyncResult<IFeatureDataReader>;
            Assert.IsNotNull(typedAsyncResult);
            FeatureQueryExpression query = typedAsyncResult.AsyncState as FeatureQueryExpression;

            if (query == null)
            {
                SpatialBinaryExpression spatialBinaryExpression 
                    = typedAsyncResult.AsyncState as SpatialBinaryExpression;

                if (spatialBinaryExpression != null)
                {
                    query = new FeatureQueryExpression(new AllAttributesExpression(), 
                                                       spatialBinaryExpression, query.Sort);
                }
            }

            try
            {
                typedAsyncResult.SetComplete(InnerFeatureProvider.ExecuteFeatureQuery(query), false);
            }
            catch (Exception terminatingException)
            {
                typedAsyncResult.SetComplete(false, terminatingException);
            }
        }
예제 #10
0
 public void ExecuteIntersectionQueryByBoundingBoxWhenClosedThrowsExceptionTest()
 {
     ShapeFileProvider shapeFile = new ShapeFileProvider(
         BcRoadsShapeFile, _geoFactory, _coordSysFactory);
     FeatureQueryExpression query  = FeatureQueryExpression.Intersects(shapeFile.GetExtents());
     IFeatureDataReader     reader = shapeFile.ExecuteFeatureQuery(query);
 }
        public void BeginExecuteQueryPollingNotification()
        {
            MockRepository   mocks        = new MockRepository();
            IFeatureProvider adapted      = mocks.CreateMock <IFeatureProvider>();
            IExtents         iExtentsStub =
                MockRepository.GenerateStub <IExtents>();
            FeatureQueryExpression featureQueryExpressionStub =
                MockRepository.GenerateStub <FeatureQueryExpression>(iExtentsStub, SpatialOperation.Intersects);

            _returnReaderStub = MockRepository.GenerateStub <IFeatureDataReader>();
            _sleepInterval    = 1000;

            using (mocks.Unordered())
            {
                Expect.Call(adapted.ExecuteFeatureQuery(featureQueryExpressionStub))
                .Do(new ExecuteQueryDelegate(executeQueryMock));
            }
            mocks.ReplayAll();

            AsyncFeatureProviderAdapter adapter = new AsyncFeatureProviderAdapter(adapted);
            IAsyncResult ar = adapter.BeginExecuteQuery(featureQueryExpressionStub, null);

            Assert.NotNull(ar);
            Assert.False(ar.IsCompleted);
            while (!ar.IsCompleted)
            {
                Thread.Sleep(350);
            }

            Assert.True(ar.IsCompleted);
            Assert.Same(_returnReaderStub, adapter.EndExecuteQuery(ar));

            mocks.VerifyAll();
        }
예제 #12
0
        public void ChangeViewAttributeFilterTriggersNotification()
        {
            FeatureProvider        data   = DataSourceHelper.CreateFeatureDatasource(_factories.GeoFactory);
            FeatureDataTable       table  = new FeatureDataTable(_factories.GeoFactory);
            FeatureQueryExpression query  = FeatureQueryExpression.Intersects(data.GetExtents());
            IFeatureDataReader     reader = data.ExecuteFeatureQuery(query);

            table.Load(reader, LoadOption.OverwriteChanges, null);
            FeatureDataView view = new FeatureDataView(table);

            Boolean resetNotificationOccured = false;

            view.ListChanged += delegate(Object sender, ListChangedEventArgs e)
            {
                if (e.ListChangedType == ListChangedType.Reset)
                {
                    resetNotificationOccured = true;
                }
            };

            Assert.False(resetNotificationOccured);

            Assert.Throws <NotSupportedException>(delegate { view.RowFilter = "FeatureName LIKE 'A m*'"; });
            Assert.True(resetNotificationOccured);
        }
        public void BeginExecuteQueryBlockUntilDone()
        {
            MockRepository   mocks        = new MockRepository();
            IFeatureProvider adapted      = mocks.CreateMock <IFeatureProvider>();
            IExtents         iExtentsStub =
                MockRepository.GenerateStub <IExtents>();
            FeatureQueryExpression featureQueryExpressionStub =
                MockRepository.GenerateStub <FeatureQueryExpression>(iExtentsStub, SpatialOperation.Intersects);

            _returnReaderStub = MockRepository.GenerateStub <IFeatureDataReader>();
            _sleepInterval    = 750;

            using (mocks.Unordered())
            {
                Expect.Call(adapted.ExecuteFeatureQuery(featureQueryExpressionStub))
                .Do(new ExecuteQueryDelegate(executeQueryMock));
            }
            mocks.ReplayAll();

            AsyncFeatureProviderAdapter adapter = new AsyncFeatureProviderAdapter(adapted);
            IAsyncResult ar = adapter.BeginExecuteQuery(featureQueryExpressionStub, null);

            Assert.NotNull(ar);

            Stopwatch timer = Stopwatch.StartNew();

            Assert.Same(_returnReaderStub, adapter.EndExecuteQuery(ar));
            timer.Stop();

            Assert.True(ar.IsCompleted);
            Assert.False(ar.CompletedSynchronously);
            Assert.True(timer.ElapsedMilliseconds > 500L);

            mocks.VerifyAll();
        }
        private void queueableBeginQuery(Object asyncResult)
        {
            AsyncResult <IFeatureDataReader> typedAsyncResult = asyncResult as AsyncResult <IFeatureDataReader>;

            Assert.IsNotNull(typedAsyncResult);
            FeatureQueryExpression query = typedAsyncResult.AsyncState as FeatureQueryExpression;

            if (query == null)
            {
                SpatialBinaryExpression spatialBinaryExpression
                    = typedAsyncResult.AsyncState as SpatialBinaryExpression;

                if (spatialBinaryExpression != null)
                {
                    query = new FeatureQueryExpression(new AllAttributesExpression(),
                                                       spatialBinaryExpression, query.Sort);
                }
            }

            try
            {
                typedAsyncResult.SetComplete(InnerFeatureProvider.ExecuteFeatureQuery(query), false);
            }
            catch (Exception terminatingException)
            {
                typedAsyncResult.SetComplete(false, terminatingException);
            }
        }
예제 #15
0
        public void MovingRowTriggersViewListChangedItemMovedNotification()
        {
            // TODO: implement MovingRowTriggersViewListChangedItemMovedNotification
            FeatureProvider  data  = DataSourceHelper.CreateFeatureDatasource(_factories.GeoFactory);
            FeatureDataTable table = new FeatureDataTable(_factories.GeoFactory);

            IExtents halfBounds = data.GetExtents();

            halfBounds.Scale(0.5);

            FeatureQueryExpression query  = FeatureQueryExpression.Intersects(data.GetExtents());
            IFeatureDataReader     reader = data.ExecuteFeatureQuery(query);

            table.Load(reader, LoadOption.OverwriteChanges, null);
            FeatureDataView view = new FeatureDataView(table);

            Boolean addNotificationOccured = false;

            view.ListChanged += delegate(Object sender, ListChangedEventArgs e)
            {
                if (e.ListChangedType == ListChangedType.ItemMoved)
                {
                    addNotificationOccured = true;
                }
            };

            Assert.True(addNotificationOccured);
        }
예제 #16
0
        public void LoadingTableFromReader()
        {
            FeatureDataTable       table    = new FeatureDataTable(_factories.GeoFactory);
            FeatureProvider        provider = DataSourceHelper.CreateFeatureDatasource(_factories.GeoFactory);
            FeatureQueryExpression query    = FeatureQueryExpression.Intersects(provider.GetExtents());

            table.Load(provider.ExecuteFeatureQuery(query));
        }
        public void IFeatureProviderMethodsPassThroughAdapter()
        {
            MockRepository   mocks   = new MockRepository();
            IFeatureProvider adapted = mocks.CreateMock <IFeatureProvider>();
            IGeometryFactory iGeometryFactoryStub =
                MockRepository.GenerateStub <IGeometryFactory>();
            FeatureDataTable featureDataTableStub =
                MockRepository.GenerateStub <FeatureDataTable>(iGeometryFactoryStub);
            IFeatureDataReader iFeatureDataReaderStub =
                MockRepository.GenerateStub <IFeatureDataReader>();
            IExtents iExtentsStub =
                MockRepository.GenerateStub <IExtents>();
            FeatureQueryExpression featureQueryExpressionStub =
                MockRepository.GenerateStub <FeatureQueryExpression>(iExtentsStub, SpatialOperation.Intersects);
            FeatureQueryExecutionOptions featureQueryExecutionOptionsStub =
                new FeatureQueryExecutionOptions();
            DataTable dataTableStub =
                MockRepository.GenerateStub <DataTable>();
            CultureInfo cultureInfoStub =
                MockRepository.GenerateStub <CultureInfo>(1);

            using (mocks.Unordered())
            {
                Expect.Call(adapted.CreateNewTable())
                .Return(featureDataTableStub);
                Expect.Call(adapted.ExecuteFeatureQuery(featureQueryExpressionStub, featureQueryExecutionOptionsStub))
                .Return(iFeatureDataReaderStub);
                Expect.Call(adapted.ExecuteFeatureQuery(featureQueryExpressionStub))
                .Return(iFeatureDataReaderStub);
                adapted.GeometryFactory = iGeometryFactoryStub;
                Expect.Call(adapted.GeometryFactory)
                .Return(iGeometryFactoryStub);
                Expect.Call(adapted.GetFeatureCount())
                .Return(3);
                Expect.Call(adapted.GetSchemaTable())
                .Return(dataTableStub);
                Expect.Call(adapted.Locale)
                .Return(cultureInfoStub);
                adapted.SetTableSchema(featureDataTableStub);
            }
            mocks.ReplayAll();

            AsyncFeatureProviderAdapter adapter = new AsyncFeatureProviderAdapter(adapted);

            Assert.Same(featureDataTableStub, adapter.CreateNewTable());
            Assert.Same(iFeatureDataReaderStub,
                        adapter.ExecuteFeatureQuery(featureQueryExpressionStub, featureQueryExecutionOptionsStub));
            Assert.Same(iFeatureDataReaderStub,
                        adapter.ExecuteFeatureQuery(featureQueryExpressionStub));
            adapter.GeometryFactory = iGeometryFactoryStub;
            Assert.Same(iGeometryFactoryStub, adapter.GeometryFactory);
            Assert.Equal(3, adapter.GetFeatureCount());
            Assert.Same(dataTableStub, adapter.GetSchemaTable());
            Assert.Same(cultureInfoStub, adapter.Locale);
            adapter.SetTableSchema(featureDataTableStub);

            mocks.VerifyAll();
        }
        public IFeatureDataReader ExecuteFeatureQuery(FeatureQueryExpression query)
        {
            if (CoordinateTransformation != null && query.IsSpatialPredicateNonEmpty)
            {
                query = transformQuery(query);
            }

            return InternalExecuteFeatureQuery(query);
        }
예제 #19
0
        public IEnumerable <FeatureDataRow> Select(FeatureQueryExpression query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            return(Features.Select(query.SpatialPredicate));
        }
예제 #20
0
        public IFeatureDataReader ExecuteFeatureQuery(FeatureQueryExpression query)
        {
            if (CoordinateTransformation != null && query.IsSpatialPredicateNonEmpty)
            {
                query = transformQuery(query);
            }

            return(InternalExecuteFeatureQuery(query));
        }
예제 #21
0
        public void NullSpatialFilterReturnsAllRows()
        {
            FeatureProvider        data  = DataSourceHelper.CreateFeatureDatasource(_factories.GeoFactory);
            FeatureDataTable       table = new FeatureDataTable(_factories.GeoFactory);
            FeatureQueryExpression query = FeatureQueryExpression.Intersects(data.GetExtents());

            table.Load(data.ExecuteFeatureQuery(query));
            FeatureDataView view = new FeatureDataView(table);

            Assert.Equal(table.Rows.Count, view.Count);
        }
예제 #22
0
        public void DefaultViewReturnsAllRows()
        {
            FeatureProvider        data   = DataSourceHelper.CreateFeatureDatasource(_factories.GeoFactory);
            FeatureDataTable       table  = new FeatureDataTable(_factories.GeoFactory);
            FeatureQueryExpression query  = FeatureQueryExpression.Intersects(data.GetExtents());
            IFeatureDataReader     reader = data.ExecuteFeatureQuery(query);

            table.Load(reader);

            Assert.Equal(table.Rows.Count, table.DefaultView.Count);
        }
예제 #23
0
        public void InsertFeatureTest()
        {
            FeatureDataTable <UInt32> schema = new FeatureDataTable <UInt32>("oid", _geoFactory);

            schema.Columns.AddRange(new DataColumn[]
            {
                new DataColumn("Name", typeof(String)),
                new DataColumn("DateCreated", typeof(DateTime)),
                new DataColumn("Visits", typeof(Int32)),
                new DataColumn("Weight", typeof(Single))
            });

            ShapeFileProvider shapeFile = ShapeFileProvider.Create("UnitTestData", "Test2", ShapeType.Point, schema, _geoFactory);

            shapeFile.Open();

            DateTime dateCreated            = DateTime.Now;
            FeatureDataRow <UInt32> feature = schema.NewRow(1);

            feature["Name"]        = "Test feature";
            feature["DateCreated"] = dateCreated;
            feature["Visits"]      = 0;
            feature["Weight"]      = 100.0f;
            feature.Geometry       = _geoFactory.CreatePoint2D(1, 1);

            shapeFile.Insert(feature);
            shapeFile.Close();

            shapeFile = new ShapeFileProvider(@"UnitTestData\Test2.shp", _geoFactory);
            shapeFile.Open();

            Assert.AreEqual(1, shapeFile.GetFeatureCount());

            FeatureDataTable       dataTable = new FeatureDataTable("ShapeFile test", _geoFactory);
            FeatureQueryExpression query     = FeatureQueryExpression.Intersects(_geoFactory.CreateExtents2D(0.9, 0.9, 1, 1));
            IFeatureDataReader     reader    = shapeFile.ExecuteFeatureQuery(query);

            dataTable.Load(reader, LoadOption.OverwriteChanges, null);

            Assert.AreEqual(1, dataTable.Rows.Count);

            FeatureDataRow newFeature = dataTable.Rows[0] as FeatureDataRow;

            Assert.AreEqual(_geoFactory.CreatePoint2D(1, 1), newFeature.Geometry);
            Assert.AreEqual(newFeature["Name"], "Test feature");
            DateTime dateCreatedActual = (DateTime)newFeature["DateCreated"];

            Assert.AreEqual(dateCreatedActual.Year, dateCreated.Year);
            Assert.AreEqual(dateCreatedActual.Month, dateCreated.Month);
            Assert.AreEqual(dateCreatedActual.Day, dateCreated.Day);
            Assert.AreEqual(newFeature["Visits"], 0);
            Assert.AreEqual(newFeature["Weight"], 100.0f);
            shapeFile.Close();
        }
예제 #24
0
        public void AddNewRowThrowsNotSupported()
        {
            FeatureProvider        data   = DataSourceHelper.CreateFeatureDatasource(_factories.GeoFactory);
            FeatureDataTable       table  = new FeatureDataTable(_factories.GeoFactory);
            FeatureQueryExpression query  = FeatureQueryExpression.Intersects(data.GetExtents());
            IFeatureDataReader     reader = data.ExecuteFeatureQuery(query);

            table.Load(reader, LoadOption.OverwriteChanges, null);
            FeatureDataView view = new FeatureDataView(table);

            Assert.Throws <NotSupportedException>(delegate { view.AddNew(); });
        }
예제 #25
0
        public void CreatingDataViewReturnsValidDataView()
        {
            FeatureProvider        data   = DataSourceHelper.CreateFeatureDatasource(_factories.GeoFactory);
            FeatureDataTable       table  = new FeatureDataTable(_factories.GeoFactory);
            FeatureQueryExpression query  = FeatureQueryExpression.Intersects(data.GetExtents());
            IFeatureDataReader     reader = data.ExecuteFeatureQuery(query);

            table.Load(reader, LoadOption.OverwriteChanges, null);
            FeatureDataView view = new FeatureDataView(table);

            Assert.IsType(typeof(FeatureDataTable), view.Table);
            Assert.Same(table, view.Table);
        }
예제 #26
0
        public void SpatialQueryTypeIsWhatIsSpecifiedAtCreateTime()
        {
            FeatureProvider        data   = DataSourceHelper.CreateFeatureDatasource(_factories.GeoFactory);
            FeatureDataTable       table  = new FeatureDataTable(_factories.GeoFactory);
            FeatureQueryExpression query  = FeatureQueryExpression.Intersects(data.GetExtents());
            IFeatureDataReader     reader = data.ExecuteFeatureQuery(query);

            table.Load(reader, LoadOption.OverwriteChanges, null);
            IGeometry       filter = _factories.GeoFactory.CreateExtents2D(0, 0, 10, 10).ToGeometry();
            FeatureDataView view   = new FeatureDataView(table, filter, "", DataViewRowState.CurrentRows);

            Assert.Equal(SpatialOperation.Intersects, view.SpatialFilter.Op);
        }
예제 #27
0
        public void ExecuteIntersectionQueryByBoundingBoxTest()
        {
            ShapeFileProvider shapeFile = new ShapeFileProvider(
                BcRoadsShapeFile, _geoFactory, _coordSysFactory);

            shapeFile.Open();
            FeatureDataTable       data   = new FeatureDataTable("ShapeFile test", _geoFactory);
            FeatureQueryExpression query  = FeatureQueryExpression.Intersects(shapeFile.GetExtents());
            IFeatureDataReader     reader = shapeFile.ExecuteFeatureQuery(query);

            data.Load(reader, LoadOption.OverwriteChanges, null);
            Assert.AreEqual(shapeFile.GetFeatureCount(), data.Rows.Count);
            shapeFile.Close();
        }
예제 #28
0
        /// <summary>
        /// Retrieves a <see cref="IFeatureDataReader"/> for the features that
        /// match the given <paramref name="query"/>.
        /// </summary>
        /// <param name="query">Spatial query to execute.</param>
        /// <returns>An IFeatureDataReader to iterate over the results.</returns>
        public IFeatureDataReader ExecuteFeatureQuery(FeatureQueryExpression query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            FeatureDataReader reader = new FeatureDataReader(_geoFactory,
                                                             _features,
                                                             query,
                                                             FeatureQueryExecutionOptions.FullFeature);

            return(reader);
        }
예제 #29
0
        private void createDataViewOnNewTable(out FeatureDataView view,
                                              out FeatureDataTable <Guid> table,
                                              Boolean includeGeometryCollections)
        {
            FeatureProvider data = DataSourceHelper.CreateFeatureDatasource(_factories.GeoFactory,
                                                                            includeGeometryCollections);

            table = new FeatureDataTable <Guid>("Oid", _factories.GeoFactory);
            FeatureQueryExpression query  = FeatureQueryExpression.Intersects(data.GetExtents());
            IFeatureDataReader     reader = data.ExecuteFeatureQuery(query);

            table.Load(reader, LoadOption.OverwriteChanges, null);
            view = new FeatureDataView(table);
        }
예제 #30
0
        public void CreatingDataViewWithEqualsSpatialExpressionSucceeds()
        {
            // This test is here so that when it is supported, the test breaks and is rewritten

            FeatureProvider        data   = DataSourceHelper.CreateFeatureDatasource(_factories.GeoFactory);
            FeatureDataTable       table  = new FeatureDataTable(_factories.GeoFactory);
            FeatureQueryExpression query  = FeatureQueryExpression.Intersects(data.GetExtents());
            IFeatureDataReader     reader = data.ExecuteFeatureQuery(query);

            table.Load(reader, LoadOption.OverwriteChanges, null);
            Point <BufferedCoordinate> empty = _factories.GeoFactory.CreatePoint() as Point <BufferedCoordinate>;

            new FeatureDataView(table, empty, SpatialOperation.Equals, "", DataViewRowState.CurrentRows);
        }
예제 #31
0
        public void MergeSchemaToKeyedTableWithDifferentKeyNameButSameTypeShouldKeepKeyButAddOtherColumns()
        {
            FeatureDataTable       table    = new FeatureDataTable(_factories.GeoFactory);
            FeatureProvider        provider = DataSourceHelper.CreateFeatureDatasource(_factories.GeoFactory);
            FeatureQueryExpression query    = FeatureQueryExpression.Intersects(provider.GetExtents());
            IFeatureDataReader     reader   = provider.ExecuteFeatureQuery(query);

            table.Load(reader, LoadOption.OverwriteChanges, null);

            FeatureDataTable <Guid> target = new FeatureDataTable <Guid>("GID", _factories.GeoFactory);

            table.MergeSchemaTo(target);

            DataTableHelper.AssertTableStructureIdentical(table, target);
        }
예제 #32
0
        public IExtents GetExtentsByOid(TOid oid)
        {
            FeatureQueryExpression query =
                new FeatureQueryExpression(new AttributesProjectionExpression(new[] { GeometryColumn }),
                                           null, null, new OidCollectionExpression(new[] { oid }), null);

            using (IFeatureDataReader fdr = ExecuteFeatureQuery(query))
            {
                while (fdr.Read())
                {
                    return((IExtents)fdr.Geometry.Extents.Clone());
                }
            }
            return(GeometryFactory.CreateExtents());
        }
예제 #33
0
        internal FeatureDataReader(IGeometryFactory factory,
                                   FeatureDataTable source,
                                   FeatureQueryExpression query,
                                   FeatureQueryExecutionOptions options)
        {
            if (source == null) throw new ArgumentNullException("source");

            if (options != FeatureQueryExecutionOptions.FullFeature)
            {
                throw new ArgumentException("Only QueryExecutionOptions.All is supported.",
                                            "options");
            }

            _factory = factory;
            _options = options;
            _query = query;
            _table = source.Clone();

            foreach (FeatureDataRow row in source.Select(query.SpatialPredicate))
            {
                _table.ImportRow(row);
            }
        }
 protected abstract IFeatureDataReader InternalExecuteFeatureQuery(FeatureQueryExpression query);
        private FeatureQueryExpression transformQuery(FeatureQueryExpression query)
        {
            SpatialBinaryExpression spatial = query.SpatialPredicate;
            ICoordinateSystem querySpatialReference = spatial.SpatialExpression.SpatialReference;

            if (querySpatialReference.EqualParams(OriginalSpatialReference))
            {
                return query;
            }

            //if (querySpatialReference != OriginalSpatialReference)
            //{
            //    throw new InvalidOperationException("The query's spatial reference doesn't match the provider's.");
            //}

            GeometryExpression geoExpression = spatial.SpatialExpression as GeometryExpression;

            if (geoExpression != null)
            {
                IGeometry transformed = CoordinateTransformation.InverseTransform(geoExpression.Geometry,
                                                                                  GeometryFactory);
                geoExpression = new GeometryExpression(transformed);
                spatial = spatial.IsSpatialExpressionLeft
                              ? new SpatialBinaryExpression(geoExpression, spatial.Op, spatial.Expression)
                              : new SpatialBinaryExpression(spatial.Expression, spatial.Op, geoExpression);
            }
            else
            {
                IExtents transformed = CoordinateTransformation.InverseTransform(spatial.SpatialExpression.Extents,
                                                                                 GeometryFactory);
                ExtentsExpression extentsExpression = new ExtentsExpression(transformed);
                spatial = spatial.IsSpatialExpressionLeft
                              ? new SpatialBinaryExpression(extentsExpression, spatial.Op, spatial.Expression)
                              : new SpatialBinaryExpression(spatial.Expression, spatial.Op, extentsExpression);
            }

            query = new FeatureQueryExpression(query, spatial);
            return query;
        }
예제 #36
0
        public IEnumerable<FeatureDataRow> Select(FeatureQueryExpression query)
        {
            if (query == null) throw new ArgumentNullException("query");

            return Features.Select(query.SpatialPredicate);
        }
예제 #37
0
 private static Expression MergeFeatureQueryAndPredicateExpression(FeatureQueryExpression expression,
                                                                   PredicateExpression predicateExpression)
 {
     return new FeatureQueryExpression(expression.Projection,
                                       MergePredicateExpressions(expression.Predicate, predicateExpression), expression.Sort);
 }
 public IFeatureDataReader ExecuteFeatureQuery(FeatureQueryExpression query)
 {
     return InnerFeatureProvider.ExecuteFeatureQuery(query);
 }
 public IFeatureDataReader ExecuteFeatureQuery(FeatureQueryExpression query, FeatureQueryExecutionOptions options)
 {
     return InnerFeatureProvider.ExecuteFeatureQuery(query, options);
 }
 private IFeatureDataReader executeQueryMock(FeatureQueryExpression query)
 {
     Thread.Sleep(_sleepInterval);
     return _returnReaderStub;
 }
 private IFeatureDataReader executeQueryExceptionMock(FeatureQueryExpression query)
 {
     Thread.Sleep(100);
     throw new InvalidOperationException("Failure succeeded");
 }