public void ExecuteIntersectionQueryByBoundingBoxWhenClosedThrowsExceptionTest() { ShapeFileProvider shapeFile = new ShapeFileProvider( BcRoadsShapeFile, _geoFactory, _coordSysFactory); FeatureQueryExpression query = FeatureQueryExpression.Intersects(shapeFile.GetExtents()); IFeatureDataReader reader = shapeFile.ExecuteFeatureQuery(query); }
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); }
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 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); }
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); }
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)); }
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); }
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); }
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 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(); }
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); }
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); }
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(); }); }
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); }
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); }
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); }
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); }
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(); }
public void MergeSchemaToSchemalessTargetShouldCreateIdenticalTable() { 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 target = new FeatureDataTable(_factories.GeoFactory); table.MergeSchemaTo(target); DataTableHelper.AssertTableStructureIdentical(table, target); }
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); }
//[ExpectedException(typeof (NotImplementedException))] public void DataViewManagerIsAFeatureDataViewManager() { 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); FeatureDataSet dataSet = new FeatureDataSet(_factories.GeoFactory); dataSet.Tables.Add(table); FeatureDataView view = dataSet.DefaultViewManager.CreateDataView(table); Assert.NotNull(view.DataViewManager); Assert.IsType(typeof(FeatureDataViewManager), view.DataViewManager); }
public void CloneToCopiesTableStructureAndNoData() { 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 clone = new FeatureDataTable(_factories.GeoFactory); table.CloneTo(clone); DataTableHelper.AssertTableStructureIdentical(table, clone); Assert.Equal(0, clone.Rows.Count); }
public void SettingGeometryFilterToIdenticalGeometryDoesntChangeFilterObject() { 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); IGeometry filterCopy = filter.Clone(); Assert.NotSame(filter, filterCopy); Assert.Equal(filter, filterCopy); SpatialBinaryExpression expression = SpatialBinaryExpression.Intersects(filterCopy); view.SpatialFilter = expression; Assert.NotSame(expression, view.SpatialFilter); }
public void RenderingPointsGeometriesWithGdiVectorRendererProducesCorrectGdiBitmaps() { using (GdiVectorRenderer vectorRenderer = new GdiVectorRenderer()) { BasicGeometryRenderer2D <GdiRenderObject> geometryRenderer = new BasicGeometryRenderer2D <GdiRenderObject>(vectorRenderer); FeatureProvider provider = DataSourceHelper.CreateFeatureDatasource(_geoFactory); FeatureQueryExpression query = FeatureQueryExpression.Intersects(provider.GetExtents()); foreach (IFeatureDataRecord record in provider.ExecuteFeatureQuery(query)) { IEnumerable <GdiRenderObject> renderedObjects = geometryRenderer.RenderFeature(record); Int32 geoIndex = 0; foreach (GdiRenderObject ro in renderedObjects) { IGeometry g = record.Geometry; if (g is IMultiPoint) { IMultiPoint mp = g as IMultiPoint; Assert.AreEqual(mp[geoIndex][Ordinates.X], ro.Bounds.Location.X, _e); Assert.AreEqual(mp[geoIndex][Ordinates.Y], ro.Bounds.Location.Y, _e); geoIndex++; } else if (g is IPoint) { IPoint p = g as IPoint; Assert.AreEqual(p[Ordinates.X], ro.Bounds.Location.X, _e); Assert.AreEqual(p[Ordinates.Y], ro.Bounds.Location.Y, _e); } } } } }
public void ExecutingQueryOnTableTriggersViewListChangedResetNotification() { FeatureProvider data = DataSourceHelper.CreateFeatureDatasource(_factories.GeoFactory); FeatureDataTable table = new FeatureDataTable(_factories.GeoFactory); IExtents dataExtents = data.GetExtents(); IExtents halfBounds = _factories.GeoFactory.CreateExtents( dataExtents.Min, dataExtents.Max); 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.Reset) { addNotificationOccured = true; } }; IExtents otherHalfBounds = _factories.GeoFactory.CreateExtents( dataExtents.Min, dataExtents.Max); otherHalfBounds.TranslateRelativeToWidth(0.5, 0.5); otherHalfBounds.Scale(0.5); query = FeatureQueryExpression.Intersects(otherHalfBounds); reader = data.ExecuteFeatureQuery(query); table.Load(reader, LoadOption.OverwriteChanges, null); Assert.True(addNotificationOccured); }
public void CreateLinealShapeFileZ() { var fdt = CreateLinealFeatureDataTableZ(_geometryFactory); using (var sfp = ShapeFileProvider.Create(".", "LinealZ", ShapeType.PolyLineZ, 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("LinealZ.shp", gs.DefaultGeometryFactory, gs.CoordinateSystemFactory)) { sfp.IsSpatiallyIndexed = false; sfp.Open(WriteAccess.ReadOnly); using (var p = sfp.ExecuteFeatureQuery(FeatureQueryExpression.Intersects(sfp.GetExtents()))) { while (p.Read()) { var geom = ((FeatureDataRow)fdt.Rows[number]).Geometry; Assert.True(geom.AsText().Equals(p.Geometry.AsText()), string.Format("\n{0}\nis not equal to\n{1}", geom.AsText(), p.Geometry.AsText())); number++; Assert.True(p.Geometry.Coordinates[0].ContainsOrdinate(Ordinates.Z), "Geometry's coordinates should have Z values"); Assert.True(p.Geometry.Coordinates[0].ContainsOrdinate(Ordinates.M), "Geometry's coordinates should have M values"); Assert.False(p.Geometry.Coordinates[0].ContainsOrdinate(Ordinates.W), "Geometry's coordinates should not have W values"); Console.WriteLine(string.Format("{0}; {1}; {2}", p.GetOid(), p.Geometry.GeometryTypeName, p.Geometry)); } } } Assert.True(number == 100); }
public void ChangeViewAttributeFilterReturnsOnlyFilteredRows() { 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); Int32 expectedRowCount = 0; foreach (FeatureDataRow row in table.Rows) { if (row["FeatureName"].ToString().StartsWith("A m")) { expectedRowCount++; } } Assert.Throws <NotSupportedException>(delegate { view.RowFilter = "FeatureName LIKE 'A m*'"; }); Assert.Equal(expectedRowCount, view.Count); }
public void SelectFeatures(ICoordinate min, ICoordinate max) { IExtents extents = _geoFactory.CreateExtents(min, max); FeatureQueryExpression query = FeatureQueryExpression.Intersects(extents); List <IFeatureLayer> layersWithSelection = new List <IFeatureLayer>(); foreach (IFeatureLayer layer in _layers) { if (layer == null || !layer.Enabled || !layer.AreFeaturesSelectable) { continue; } layer.Features.SuspendIndexEvents(); layer.Select(query); layersWithSelection.Add(layer); } foreach (IFeatureLayer layer in layersWithSelection) { layer.Features.RestoreIndexEvents(false); } }
public void InsertFeaturesTest() { 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(Int64)), new DataColumn("Weight", typeof(Double)) }); ShapeFileProvider shapeFile = ShapeFileProvider.Create("UnitTestData", "Test3", ShapeType.PolyLine, schema, _geoFactory); shapeFile.Open(); IExtents computedBounds = _geoFactory.CreateExtents(); List <FeatureDataRow <UInt32> > rows = new List <FeatureDataRow <UInt32> >(); for (Int32 i = 0; i < 10000; i++) { DateTime dateCreated = new DateTime(_rnd.Next(1900, 2155), _rnd.Next(1, 12), _rnd.Next(1, 28)); FeatureDataRow <UInt32> feature = schema.NewRow((UInt32)i); Char[] chars = new Char[_rnd.Next(0, 254)]; for (Int32 charIndex = 0; charIndex < chars.Length; charIndex++) { chars[charIndex] = (Char)(Byte)_rnd.Next(32, 126); } feature["Name"] = new String(chars); feature["DateCreated"] = dateCreated; feature["Visits"] = _rnd.Next(0, Int32.MaxValue) << _rnd.Next(0, 32); feature["Weight"] = _rnd.NextDouble() * _rnd.Next(0, 100000); ICoordinateSequence coordinates = _geoFactory.CoordinateSequenceFactory.Create(generateCoordinates()); ILineString line = _geoFactory.CreateLineString(coordinates); computedBounds.ExpandToInclude(line.Extents); feature.Geometry = line; rows.Add(feature); } shapeFile.Insert(rows); shapeFile.Close(); shapeFile = new ShapeFileProvider(@"UnitTestData\Test3.shp", _geoFactory, _coordSysFactory, false); shapeFile.Open(); Assert.AreEqual(10000, shapeFile.GetFeatureCount()); Assert.AreEqual(computedBounds, shapeFile.GetExtents()); FeatureDataTable dataTable = new FeatureDataTable("ShapeFile test", _geoFactory); FeatureQueryExpression query = FeatureQueryExpression.Intersects(shapeFile.GetExtents()); IFeatureDataReader reader = shapeFile.ExecuteFeatureQuery(query); dataTable.Load(reader, LoadOption.OverwriteChanges, null); Assert.AreEqual(10000, dataTable.Rows.Count); }
public void RenderingPolygonsWithGdiVectorRendererProducesCorrectGdiPaths() { using (GdiVectorRenderer vectorRenderer = new GdiVectorRenderer()) { BasicGeometryRenderer2D <GdiRenderObject> geometryRenderer = new BasicGeometryRenderer2D <GdiRenderObject>(vectorRenderer); FeatureProvider provider = DataSourceHelper.CreateFeatureDatasource(_geoFactory); FeatureQueryExpression query = FeatureQueryExpression.Intersects(provider.GetExtents()); foreach (IFeatureDataRecord record in provider.ExecuteFeatureQuery(query)) { IEnumerable <GdiRenderObject> renderedObjects = geometryRenderer.RenderFeature(record); foreach (GdiRenderObject ro in renderedObjects) { IGeometry g = record.Geometry; if (g is IPolygon) { IPolygon p = g as IPolygon; using (GraphicsPathIterator iter = new GraphicsPathIterator(ro.GdiPath)) { Int32 start, end; Boolean isClosed; iter.NextSubpath(out start, out end, out isClosed); Assert.IsTrue(isClosed); Assert.AreEqual(p.ExteriorRing.Coordinates.Count, end - start + 1); for (Int32 vertexIndex = 0; vertexIndex < p.ExteriorRing.Coordinates.Count; vertexIndex++) { ICoordinate v = (ICoordinate)p.ExteriorRing.Coordinates[vertexIndex]; PointF gdiPoint = ro.GdiPath.PathPoints[vertexIndex + start]; Assert.AreEqual(v[Ordinates.X], gdiPoint.X); Assert.AreEqual(v[Ordinates.Y], gdiPoint.Y); } foreach (ILineString interiorRing in p.InteriorRings) { iter.NextSubpath(out start, out end, out isClosed); Assert.IsTrue(isClosed); Assert.AreEqual(interiorRing.PointCount, end - start + 1); for (Int32 vertexIndex = 0; vertexIndex < interiorRing.PointCount; vertexIndex++) { ICoordinate v = interiorRing.Coordinates[vertexIndex]; PointF gdiPoint = ro.GdiPath.PathPoints[vertexIndex + start]; Assert.AreEqual(v[Ordinates.X], gdiPoint.X); Assert.AreEqual(v[Ordinates.Y], gdiPoint.Y); } } } } else if (g is IMultiPolygon) { IMultiPolygon mp = g as IMultiPolygon; using (GraphicsPathIterator iter = new GraphicsPathIterator(ro.GdiPath)) { foreach (IPolygon p in (IEnumerable <IPolygon>)mp) { Int32 start, end; Boolean isClosed; iter.NextSubpath(out start, out end, out isClosed); Assert.IsTrue(isClosed); Int32 exteriorPointCount = p.ExteriorRing.PointCount; Assert.AreEqual(exteriorPointCount, end - start + 1); for (Int32 vertexIndex = 0; vertexIndex < exteriorPointCount; vertexIndex++) { ICoordinate v = p.ExteriorRing.Coordinates[vertexIndex]; PointF gdiPoint = ro.GdiPath.PathPoints[vertexIndex + start]; Assert.AreEqual(v[Ordinates.X], gdiPoint.X); Assert.AreEqual(v[Ordinates.Y], gdiPoint.Y); } foreach (ILineString interiorRing in p.InteriorRings) { iter.NextSubpath(out start, out end, out isClosed); Assert.IsTrue(isClosed); Assert.AreEqual(interiorRing.PointCount, end - start + 1); for (Int32 vertexIndex = 0; vertexIndex < interiorRing.PointCount; vertexIndex++) { ICoordinate v = interiorRing.Coordinates[vertexIndex]; PointF gdiPoint = ro.GdiPath.PathPoints[vertexIndex + start]; Assert.AreEqual(v[Ordinates.X], gdiPoint.X); Assert.AreEqual(v[Ordinates.Y], gdiPoint.Y); } } } } } } } } }