protected override void IndexListChanged(Object sender, ListChangedEventArgs e) { switch (e.ListChangedType) { case ListChangedType.ItemAdded: FeatureDataRow feature = this[e.NewIndex].Row as FeatureDataRow; Debug.Assert(feature != null); if (_extents == null) { _extents = feature.Extents; } else { _extents.ExpandToInclude(feature.Extents); } break; case ListChangedType.Reset: case ListChangedType.ItemChanged: case ListChangedType.ItemDeleted: recomputeExtents(); break; default: break; } base.IndexListChanged(sender, e); }
/// <summary> /// The extents of the data source. /// </summary> /// <returns> /// An <see cref="IExtents"/> instance describing the extents of the /// data available in the data source. /// </returns> public override IExtents GetExtents() { if (_extents != null) { return(_extents); } if (_geometries.Count == 0) { _extents = _geoFactory.CreateExtents(); } else { foreach (IGeometry g in Geometries) { if (g.IsEmpty) { continue; } if (_extents == null) { _extents = g.Extents; } else { _extents.ExpandToInclude(g.Extents); } } } return(_extents); }
private void handleLayersChanged(Object sender, ListChangedEventArgs args) { switch (args.ListChangedType) { case ListChangedType.ItemAdded: { ILayer layer = _layers[args.NewIndex]; if (_extents == null) { _extents = _geoFactory.CreateExtents(layer.Extents); } else { _extents.ExpandToInclude(layer.Extents); } onExtentsChanged(); } break; case ListChangedType.ItemChanged: if (args.PropertyDescriptor.Name == Layer.ExtentsProperty.Name) { ILayer layer = _layers[args.NewIndex]; _extents.ExpandToInclude(layer.Extents); onExtentsChanged(); } break; case ListChangedType.ItemDeleted: recomputeExtents(); break; case ListChangedType.Reset: recomputeExtents(); break; case ListChangedType.ItemMoved: case ListChangedType.PropertyDescriptorAdded: case ListChangedType.PropertyDescriptorChanged: case ListChangedType.PropertyDescriptorDeleted: default: break; } }
private void recomputeExtents() { IExtents extents = null; foreach (ILayer layer in Layers) { if (layer.Enabled) { if (extents == null) { extents = layer.Extents; } else { extents.ExpandToInclude(layer.Extents); } } } _extents = extents; onExtentsChanged(); }
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); }