public void SetTableSchemaShouldMatchShapeFileSchema() { ShapeFileProvider shapeFile = new ShapeFileProvider(@"..\..\..\TestData\BCROADS.SHP"); shapeFile.Open(); FeatureDataTable<uint> queryTable = new FeatureDataTable<uint>("OID"); shapeFile.ExecuteIntersectionQuery(BoundingBox.Empty, queryTable); FeatureDataTable nonKeyedTable = new FeatureDataTable(); shapeFile.SetTableSchema(nonKeyedTable); DataTableHelper.AssertTableStructureIdentical(nonKeyedTable, queryTable); FeatureDataTable<uint> keyedTable = new FeatureDataTable<uint>("OID"); shapeFile.SetTableSchema(keyedTable); DataTableHelper.AssertTableStructureIdentical(keyedTable, queryTable); }
public void InsertFeatureTest() { FeatureDataTable<uint> schema = new FeatureDataTable<uint>("oid"); schema.Columns.AddRange(new DataColumn[] { new DataColumn("Name", typeof (String)), new DataColumn("DateCreated", typeof (DateTime)), new DataColumn("Visits", typeof (int)), new DataColumn("Weight", typeof (float)) }); ShapeFileProvider shapeFile = ShapeFileProvider.Create("UnitTestData", "Test2", ShapeType.Point, schema); shapeFile.Open(); DateTime dateCreated = DateTime.Now; FeatureDataRow<uint> feature = schema.NewRow(1); feature["Name"] = "Test feature"; feature["DateCreated"] = dateCreated; feature["Visits"] = 0; feature["Weight"] = 100.0f; feature.Geometry = new Point(1, 1); shapeFile.Insert(feature); shapeFile.Close(); shapeFile = new ShapeFileProvider(@"UnitTestData\Test2.shp"); shapeFile.Open(); Assert.AreEqual(1, shapeFile.GetFeatureCount()); FeatureDataSet dataSet = new FeatureDataSet("ShapeFile test"); shapeFile.ExecuteIntersectionQuery(new BoundingBox(1, 1, 1, 1), dataSet); Assert.AreEqual(1, dataSet.Tables.Count); Assert.AreEqual(1, dataSet.Tables[0].Rows.Count); FeatureDataRow<uint> newFeature = dataSet.Tables[0].Rows[0] as FeatureDataRow<uint>; Assert.AreEqual(new Point(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 InsertFeaturesTest() { FeatureDataTable<uint> schema = new FeatureDataTable<uint>("OID"); 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); shapeFile.Open(); Random rnd = new Random(); BoundingBox computedBounds = BoundingBox.Empty; List<FeatureDataRow<uint>> rows = new List<FeatureDataRow<uint>>(); for (int i = 0; i < 10000; i++) { DateTime dateCreated = new DateTime(rnd.Next(1900, 2155), rnd.Next(1, 12), rnd.Next(1, 28)); FeatureDataRow<uint> feature = schema.NewRow((uint) i); char[] chars = new char[rnd.Next(0, 254)]; for (int 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); LineString line = new LineString(); int pointCount = rnd.Next(1, 100); for (int pointIndex = 0; pointIndex < pointCount; pointIndex++) { Point p = new Point(rnd.NextDouble()*rnd.Next(200000, 700000), (rnd.NextDouble()*rnd.Next(1000000)) + 50000000); line.Vertices.Add(p); } computedBounds.ExpandToInclude(line.GetBoundingBox()); feature.Geometry = line; rows.Add(feature); } shapeFile.Insert(rows); shapeFile.Close(); shapeFile = new ShapeFileProvider(@"UnitTestData\Test3.shp", true); shapeFile.Open(); Assert.AreEqual(10000, shapeFile.GetFeatureCount()); Assert.AreEqual(computedBounds, shapeFile.GetExtents()); FeatureDataSet dataSet = new FeatureDataSet("ShapeFile test"); shapeFile.ExecuteIntersectionQuery(shapeFile.GetExtents(), dataSet); Assert.AreEqual(1, dataSet.Tables.Count); Assert.AreEqual(10000, dataSet.Tables[0].Rows.Count); }
public void GetFeatureTest() { ShapeFileProvider shapeFile = new ShapeFileProvider(@"..\..\..\TestData\BCROADS.SHP"); shapeFile.Open(); FeatureDataRow<uint> feature = shapeFile.GetFeature(0); Assert.AreEqual(0, feature.Id); shapeFile.Close(); }
public void SridTest() { ShapeFileProvider shapeFile = new ShapeFileProvider(@"..\..\..\TestData\BCROADS.SHP"); shapeFile.Open(); Assert.AreEqual(0, shapeFile.Srid); shapeFile.Close(); shapeFile = new ShapeFileProvider(@"..\..\..\TestData\BCROADSWithoutDbf.SHP"); shapeFile.Open(); Assert.AreEqual(-1, shapeFile.Srid); shapeFile.Close(); }
public void GetCoordinateSystemHavingPrjFileTest() { ShapeFileProvider shapeFile = new ShapeFileProvider(@"..\..\..\TestData\BCROADS.SHP"); 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 ExecuteIntersectionQueryByBoundingBoxTest() { Console.WriteLine("EN ExecuteIntersectionQueryByBoundingBoxTest"); //ShapeFileProvider shapeFile = new ShapeFileProvider(@"..\..\..\TestData\BCROADS.SHP"); ShapeFileProvider shapeFile = new ShapeFileProvider(@"..\..\..\TestData\rivers.shp"); shapeFile.Open(); FeatureDataSet data = new FeatureDataSet("ShapeFile test"); shapeFile.ExecuteIntersectionQuery(shapeFile.GetExtents(), data); foreach (FeatureDataTable fdt in data.Tables) { Console.WriteLine("una fdt"); foreach (FeatureDataRow fdr in fdt.Rows) { Geometry geom = fdr.Geometry; Console.WriteLine("fdr.Geometry:" + geom.AsText()); } Console.WriteLine("fdt.Rows.Count:" + fdt.Rows.Count); } Assert.AreEqual(1, data.Tables.Count); Assert.AreEqual(shapeFile.GetFeatureCount(), data.Tables[0].Rows.Count); shapeFile.Close(); }
public void OpenExclusiveTest() { ShapeFileProvider shapeFile = new ShapeFileProvider(@"..\..\..\TestData\BCROADS.SHP"); shapeFile.Open(true); File.OpenRead(@"..\..\..\TestData\BCROADS.SHP"); }
public void CloseExclusiveTest() { ShapeFileProvider shapeFile = new ShapeFileProvider(@"..\..\..\TestData\BCROADS.SHP"); shapeFile.Open(true); //shapeFile.Close(); //File.OpenRead(@"..\..\..\TestData\BCROADS.SHP").Close(); }
public void GetShapeTypeTest() { ShapeFileProvider shapeFile = new ShapeFileProvider(@"..\..\..\TestData\BCROADSWithoutDbf.SHP"); shapeFile.Open(); Assert.AreEqual(ShapeType.PolyLine, shapeFile.ShapeType); shapeFile.Close(); }
public void IsOpenTest() { ShapeFileProvider shapeFile = new ShapeFileProvider(@"..\..\..\TestData\BCROADS.SHP"); Assert.IsFalse(shapeFile.IsOpen); shapeFile.Open(); Assert.IsTrue(shapeFile.IsOpen); shapeFile.Close(); Assert.IsFalse(shapeFile.IsOpen); }
public void NoPrjFileSetCoordinateSystemTest() { ShapeFileProvider shapeFile = new ShapeFileProvider(@"..\..\..\TestData\BCROADSWithoutDbf.SHP"); shapeFile.Open(); string wkt = File.ReadAllText(@"..\..\..\TestData\BCROADS.prj"); IProjectedCoordinateSystem cs = CoordinateSystemWktReader.Parse(wkt) as IProjectedCoordinateSystem; shapeFile.SpatialReference = cs; Assert.IsNotNull(shapeFile.SpatialReference); Geometry g = shapeFile.GetGeometryById(0); Assert.IsTrue(g.SpatialReference.EqualParams(createExpectedCoordinateSystem())); shapeFile.Close(); }
public void SetCoordinateSystemWithPrjFileThrowsExceptionTest() { ShapeFileProvider shapeFile = new ShapeFileProvider(@"..\..\..\TestData\BCROADS.SHP"); shapeFile.Open(); IProjectedCoordinateSystem cs = createExpectedCoordinateSystem(); shapeFile.SpatialReference = cs; }
public void NoPrjFileImpliesCoordinateSystemIsNullTest() { ShapeFileProvider shapeFile = new ShapeFileProvider(@"..\..\..\TestData\BCROADSWithoutDbf.SHP"); shapeFile.Open(); Assert.IsNull(shapeFile.SpatialReference); shapeFile.Close(); }
public void SetTableSchemaWithDifferentKeyNameAndSchemaMergeAction() { ShapeFileProvider shapeFile = new ShapeFileProvider(@"..\..\..\TestData\BCROADS.SHP"); shapeFile.Open(); FeatureDataTable<uint> queryTable = new FeatureDataTable<uint>("OID"); shapeFile.ExecuteIntersectionQuery(BoundingBox.Empty, queryTable); FeatureDataTable<uint> keyedTable = new FeatureDataTable<uint>("FID"); shapeFile.SetTableSchema(keyedTable, SchemaMergeAction.KeyByType); DataTableHelper.AssertTableStructureIdentical(keyedTable, queryTable); }
public void GetGeometriesInViewTest() { ShapeFileProvider shapeFile = new ShapeFileProvider(@"..\..\..\TestData\BCROADS.SHP"); shapeFile.Open(); List<Geometry> geometries = new List<Geometry>(); geometries.AddRange(shapeFile.ExecuteGeometryIntersectionQuery(shapeFile.GetExtents())); Assert.AreEqual(shapeFile.GetFeatureCount(), geometries.Count); geometries.Clear(); geometries.AddRange(shapeFile.ExecuteGeometryIntersectionQuery(BoundingBox.Empty)); Assert.AreEqual(0, geometries.Count); }
public void NewWithFileBasedSpatialIndexTest() { ShapeFileProvider shapeFile = new ShapeFileProvider(@"..\..\..\TestData\BCROADS.SHP", true); Assert.IsNotNull(shapeFile); shapeFile.Open(); Assert.IsTrue(File.Exists(@"..\..\..\TestData\BCROADS.shp.sidx")); shapeFile.Close(); File.Delete(@"..\..\..\TestData\BCROADS.shp.sidx"); }
public void RebuildSpatialIndexTest() { ShapeFileProvider shapeFile = new ShapeFileProvider(@"..\..\..\TestData\BCROADS.SHP", true); shapeFile.Open(); File.Delete(@"..\..\..\TestData\BCROADS.shp.sidx"); shapeFile.RebuildSpatialIndex(); Assert.IsTrue(File.Exists(@"..\..\..\TestData\BCROADS.shp.sidx")); shapeFile.Close(); File.Delete(@"..\..\..\TestData\BCROADS.shp.sidx"); }