public void HasDbfWithDbfFileIsTrueTest() { ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsShapeFile, _geoFactory); Assert.IsTrue(shapeFile.HasDbf); shapeFile.Close(); }
public void HasDbfWithoutDbfFileIsFalseTest() { ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsWithOutDbfShapeFile, _geoFactory); Assert.IsFalse(shapeFile.HasDbf); shapeFile.Close(); }
public void RebuildSpatialIndexWhenClosedThrowsExceptionTest() { ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsShapeFile, _geoFactory); shapeFile.RebuildSpatialIndex(); shapeFile.Close(); }
public void NoPrjFileThenSetCoordinateSystemGivesSpatialRefToGeometries() { //Layer name: BCROADSWithoutDbf //Geometry: Line String //Feature Count: 7291 //Extent: (7332083.212797, 236823.718672) - (7538428.618000, 405610.346926) ShapeFileProvider shapeFile = new ShapeFileProvider( BcRoadsWithOutDbfShapeFile, _geoFactory); shapeFile.Open(); ICoordinateSystemFactory <BufferedCoordinate2D> coordSysFactory = _coordSysFactory; String wkt = File.ReadAllText(BcRoadsPrjFile); IProjectedCoordinateSystem cs = WktReader <BufferedCoordinate2D> .ToCoordinateSystemInfo(wkt, coordSysFactory) as IProjectedCoordinateSystem; shapeFile.SpatialReference = cs; Assert.IsNotNull(shapeFile.SpatialReference); IGeometry g = shapeFile.GetGeometryByOid(0); Assert.IsTrue(g.SpatialReference.EqualParams(createExpectedCoordinateSystem())); shapeFile.Close(); }
public void NewWithoutFileBasedSpatialIndexTest() { ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsShapeFile, _geoFactory); Assert.IsNotNull(shapeFile); shapeFile.Close(); }
public void NoPrjFileImpliesCoordinateSystemIsNullTest() { ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsWithOutDbfShapeFile, _geoFactory); shapeFile.Open(); Assert.IsNull(shapeFile.SpatialReference); shapeFile.Close(); }
public void CloseExclusiveTest() { ShapeFileProvider shapeFile = new ShapeFileProvider( BcRoadsShapeFile, _geoFactory, _coordSysFactory); shapeFile.Open(true); shapeFile.Close(); File.OpenRead(BcRoadsShapeFile).Close(); }
public void GetDbfFilenameTest() { ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsShapeFile, _geoFactory); Assert.AreEqual(0, String.Compare( Path.Combine(new DirectoryInfo(TestDataFolder).FullName, "BCROADS.DBF"), shapeFile.DbfFilename, true)); shapeFile.Close(); }
public void GetShapeTypeTest() { ShapeFileProvider shapeFile = new ShapeFileProvider( BcRoadsWithOutDbfShapeFile, _geoFactory); shapeFile.Open(); Assert.AreEqual(ShapeType.PolyLine, shapeFile.ShapeType); shapeFile.Close(); }
public void NewWithFileBasedSpatialIndexTest() { ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsShapeFile, _geoFactory, _coordSysFactory, true); Assert.IsNotNull(shapeFile); shapeFile.Open(); Assert.IsTrue(File.Exists(BcRoadsSpatialIndex)); shapeFile.Close(); File.Delete(BcRoadsSpatialIndex); }
public void IsOpenTest() { ShapeFileProvider shapeFile = new ShapeFileProvider( BcRoadsShapeFile, _geoFactory, _coordSysFactory); Assert.IsFalse(shapeFile.IsOpen); shapeFile.Open(); Assert.IsTrue(shapeFile.IsOpen); shapeFile.Close(); Assert.IsFalse(shapeFile.IsOpen); }
public void RebuildSpatialIndexTest() { ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsShapeFile, _geoFactory, _coordSysFactory, false); shapeFile.Open(); File.Delete(BcRoadsSpatialIndex); shapeFile.RebuildSpatialIndex(); Assert.IsTrue(File.Exists(BcRoadsSpatialIndex)); shapeFile.Close(); File.Delete(BcRoadsSpatialIndex); }
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 GetFeatureTest() { ShapeFileProvider shapeFile = new ShapeFileProvider( BcRoadsShapeFile, _geoFactory, _coordSysFactory); shapeFile.Open(); FeatureDataRow <UInt32> feature = shapeFile.GetFeatureByOid(0) as FeatureDataRow <UInt32>; Assert.IsNotNull(feature); Assert.AreEqual(0, feature.Id); shapeFile.Close(); }
public void SridTest() { ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsShapeFile, _geoFactory); shapeFile.Open(); Assert.AreEqual(0, shapeFile.Srid); shapeFile.Close(); shapeFile = new ShapeFileProvider(BcRoadsWithOutDbfShapeFile, _geoFactory); shapeFile.Open(); Assert.AreEqual(-1, shapeFile.Srid); shapeFile.Close(); }
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 GetCoordinateSystemHavingPrjFileTest() { ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsShapeFile, _geoFactory, _coordSysFactory); shapeFile.Open(); Assert.IsNotNull(shapeFile.SpatialReference); Assert.IsInstanceOfType(typeof(IProjectedCoordinateSystem), shapeFile.SpatialReference); IProjectedCoordinateSystem cs = shapeFile.SpatialReference as IProjectedCoordinateSystem; Assert.IsNotNull(cs); Assert.AreEqual("NAD_1983_HARN_StatePlane_Oregon_North_FIPS_3601", cs.Name); IProjectedCoordinateSystem expected = createExpectedCoordinateSystem(); Assert.IsTrue(expected.EqualParams(cs)); shapeFile.Close(); }
private void Dispose(bool disposing) { if (!disposed) { if (_sourceProvider != null) { _sourceProvider.Close(); } if (_targetProvider != null) { _targetProvider.Close(); } disposed = true; } }
public void CreateNewWithAttributesSchemaTest() { FeatureDataTable schema = new FeatureDataTable(_geoFactory); schema.Columns.AddRange(new DataColumn[] { new DataColumn("Name", typeof(String)), new DataColumn("Date_Created", typeof(DateTime)), new DataColumn("Visits", typeof(Int32)), new DataColumn("Weight", typeof(Single)) }); ShapeFileProvider shapeFile = ShapeFileProvider.Create("UnitTestData", "Test1", ShapeType.Point, schema, _geoFactory); Assert.IsTrue(File.Exists(@"UnitTestData\Test1.shp")); Assert.IsTrue(File.Exists(@"UnitTestData\Test1.shx")); Assert.IsTrue(File.Exists(@"UnitTestData\Test1.dbf")); Assert.IsTrue(shapeFile.HasDbf); shapeFile.Close(); File.Delete(@"UnitTestData\Test1.shp"); File.Delete(@"UnitTestData\Test1.shx"); File.Delete(@"UnitTestData\Test1.dbf"); }
private void Export(string colName) { ExportDirectory = Path.Combine(Path.GetDirectoryName(Provider.Filename), Path.GetFileNameWithoutExtension(Provider.Filename) + "_Export"); if (!Directory.Exists(ExportDirectory)) { Directory.CreateDirectory(ExportDirectory); } FeatureDataTable fdt = Provider.CreateNewTable(); IFeatureDataReader reader = Provider.GetReader(); while (reader.Read()) { string layerName = GenerateUniqueName(reader[colName].ToString()); using ( ShapeFileProvider export = ShapeFileProvider.Create(ExportDirectory, layerName, Provider.ShapeType, Provider.CreateNewTable(), Provider.GeometryFactory, _geometryServices.CoordinateSystemFactory)) { export.IsSpatiallyIndexed = false; export.Open(); FeatureDataRow <uint> fdr = (FeatureDataRow <uint>)fdt.NewRow(); object[] vals = new object[fdt.Columns.Count]; reader.GetValues(vals); fdr.ItemArray = vals; fdr.Geometry = reader.Geometry; export.Insert(fdr); export.Close(); } } }
public void CreateNewNoAttributesTest() { if (File.Exists(@"UnitTestData\Test1.shp")) { File.Delete(@"UnitTestData\Test1.shp"); } if (File.Exists(@"UnitTestData\Test1.shx")) { File.Delete(@"UnitTestData\Test1.shx"); } if (File.Exists(@"UnitTestData\Test1.dbf")) { File.Delete(@"UnitTestData\Test1.dbf"); } ShapeFileProvider shapeFile = ShapeFileProvider.Create("UnitTestData", "Test1", ShapeType.Polygon, _geoFactory); Assert.IsTrue(File.Exists(@"UnitTestData\Test1.shp")); Assert.IsTrue(File.Exists(@"UnitTestData\Test1.shx")); Assert.IsFalse(File.Exists(@"UnitTestData\Test1.dbf")); shapeFile.Close(); File.Delete(@"UnitTestData\Test1.shp"); File.Delete(@"UnitTestData\Test1.shx"); }
public void NoPrjFileThenSetCoordinateSystemGivesSpatialRefToGeometries() { //Layer name: BCROADSWithoutDbf //Geometry: Line String //Feature Count: 7291 //Extent: (7332083.212797, 236823.718672) - (7538428.618000, 405610.346926) ShapeFileProvider shapeFile = new ShapeFileProvider( BcRoadsWithOutDbfShapeFile, _geoFactory); shapeFile.Open(); ICoordinateSystemFactory<BufferedCoordinate2D> coordSysFactory = _coordSysFactory; String wkt = File.ReadAllText(BcRoadsPrjFile); IProjectedCoordinateSystem cs = WktReader<BufferedCoordinate2D> .ToCoordinateSystemInfo(wkt, coordSysFactory) as IProjectedCoordinateSystem; shapeFile.SpatialReference = cs; Assert.IsNotNull(shapeFile.SpatialReference); IGeometry g = shapeFile.GetGeometryByOid(0); Assert.IsTrue(g.SpatialReference.EqualParams(createExpectedCoordinateSystem())); shapeFile.Close(); }
public void GetCoordinateSystemHavingPrjFileTest() { ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsShapeFile, _geoFactory, _coordSysFactory); shapeFile.Open(); Assert.IsNotNull(shapeFile.SpatialReference); Assert.IsInstanceOfType(typeof (IProjectedCoordinateSystem), shapeFile.SpatialReference); IProjectedCoordinateSystem cs = shapeFile.SpatialReference as IProjectedCoordinateSystem; Assert.IsNotNull(cs); Assert.AreEqual("NAD_1983_HARN_StatePlane_Oregon_North_FIPS_3601", cs.Name); IProjectedCoordinateSystem expected = createExpectedCoordinateSystem(); Assert.IsTrue(expected.EqualParams(cs)); shapeFile.Close(); }
public void GetFeatureTest() { ShapeFileProvider shapeFile = new ShapeFileProvider( BcRoadsShapeFile, _geoFactory, _coordSysFactory); shapeFile.Open(); FeatureDataRow<UInt32> feature = shapeFile.GetFeatureByOid(0) as FeatureDataRow<UInt32>; Assert.IsNotNull(feature); Assert.AreEqual(0, feature.Id); shapeFile.Close(); }
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 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 Dispose() { _provider.Close(); }