Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        /// <remarks>
        /// Note <paramref name="oidType"/> Is ignored for shapefile provider.
        /// </remarks>
        public IWritableFeatureProvider ConstructTargetProvider(Type oidType, IGeometryFactory geometryFactory, ICoordinateSystemFactory csFactory, FeatureDataTable schemaTable)
        {
            EnsureColumnNamesValid(schemaTable);

            string directoryPath = GetDirectoryPath();

            CreateAction overwrite;
            string       layerName = GetLayerName(directoryPath, out overwrite);

            ShapeType shapeType = GetShapeType();


            if (overwrite == CreateAction.Append)
            {
                _targetProvider = new ShapeFileProvider(Path.Combine(directoryPath, layerName + ".shp"),
                                                        geometryFactory,
                                                        csFactory);
            }
            else
            {
                _targetProvider = ShapeFileProvider.Create(directoryPath, layerName, shapeType, schemaTable,
                                                           geometryFactory,
                                                           csFactory);
            }

            _targetProvider.Open(WriteAccess.Exclusive);
            return(_targetProvider);
        }
Exemplo n.º 3
0
        public void HasDbfWithoutDbfFileIsFalseTest()
        {
            ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsWithOutDbfShapeFile, _geoFactory);

            Assert.IsFalse(shapeFile.HasDbf);
            shapeFile.Close();
        }
Exemplo n.º 4
0
        public void RebuildSpatialIndexWhenClosedThrowsExceptionTest()
        {
            ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsShapeFile, _geoFactory);

            shapeFile.RebuildSpatialIndex();
            shapeFile.Close();
        }
Exemplo n.º 5
0
 public void ExecuteIntersectionQueryByBoundingBoxWhenClosedThrowsExceptionTest()
 {
     ShapeFileProvider shapeFile = new ShapeFileProvider(
         BcRoadsShapeFile, _geoFactory, _coordSysFactory);
     FeatureQueryExpression query  = FeatureQueryExpression.Intersects(shapeFile.GetExtents());
     IFeatureDataReader     reader = shapeFile.ExecuteFeatureQuery(query);
 }
Exemplo n.º 6
0
        public void CreateMultiPointShapeFile()
        {
            var fdt = CreateMultiPointFeatureDataTable(_geometryFactory);
            using (var sfp = ShapeFileProvider.Create(".", "MultiPoint", ShapeType.MultiPoint, 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("MultiPoint.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);
        }
Exemplo n.º 7
0
        public void NewWithoutFileBasedSpatialIndexTest()
        {
            ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsShapeFile, _geoFactory);

            Assert.IsNotNull(shapeFile);
            shapeFile.Close();
        }
Exemplo n.º 8
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);
        }
        private static void setupShapefile(HttpContext context, Map m)
        {
            GeometryServices geometryServices = new GeometryServices();

            string[] layernames = new[]
                                      {
                                          "Countries",
                                          "Rivers"/*,
                                          "Cities"*/
                                      };

            foreach (string s in layernames)
            {
                ShapeFileProvider shapeFile =
               new ShapeFileProvider(context.Server.MapPath(string.Format("~/App_Data/Shapefiles/{0}.shp", s)),
                                     geometryServices.DefaultGeometryFactory,
                                     geometryServices.CoordinateSystemFactory, false);
                shapeFile.IsSpatiallyIndexed = false;

                AppStateMonitoringFeatureProvider provider = new AppStateMonitoringFeatureProvider(shapeFile);

                GeoJsonGeometryStyle style = RandomStyle.RandomGeometryStyle();
                /* include GeoJson styles */
                style.IncludeAttributes = false;
                style.IncludeBBox = true;
                style.PreProcessGeometries = false;
                style.CoordinateNumberFormatString = "{0:F}";

                GeometryLayer geometryLayer = new GeometryLayer(s, style, provider);
                geometryLayer.Features.IsSpatiallyIndexed = false;
                m.AddLayer(geometryLayer);
                provider.Open();
            }

        }
Exemplo n.º 10
0
        public ILayer Create(String layerName, String connectionInfo)
        {
            ShapeFileProvider shapeFileData  = new ShapeFileProvider(connectionInfo, _geometryFactory);
            GeometryLayer     shapeFileLayer = new GeometryLayer(layerName, shapeFileData);

            return(shapeFileLayer);
        }
Exemplo n.º 11
0
        public void HasDbfWithDbfFileIsTrueTest()
        {
            ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsShapeFile, _geoFactory);

            Assert.IsTrue(shapeFile.HasDbf);
            shapeFile.Close();
        }
Exemplo n.º 12
0
        private static void setupShapefile(HttpContext context, Map m)
        {
            GeometryServices geometryServices = new GeometryServices();

            string[] layernames = new[]
            {
                "Countries",
                "Rivers"                          /*,
                                                   * "Cities"*/
            };

            foreach (string s in layernames)
            {
                ShapeFileProvider shapeFile =
                    new ShapeFileProvider(context.Server.MapPath(string.Format("~/App_Data/Shapefiles/{0}.shp", s)),
                                          geometryServices.DefaultGeometryFactory,
                                          geometryServices.CoordinateSystemFactory, false);
                shapeFile.IsSpatiallyIndexed = false;

                AppStateMonitoringFeatureProvider provider = new AppStateMonitoringFeatureProvider(shapeFile);

                GeoJsonGeometryStyle style = RandomStyle.RandomGeometryStyle();
                /* include GeoJson styles */
                style.IncludeAttributes            = false;
                style.IncludeBBox                  = true;
                style.PreProcessGeometries         = false;
                style.CoordinateNumberFormatString = "{0:F}";

                GeometryLayer geometryLayer = new GeometryLayer(s, style, provider);
                geometryLayer.Features.IsSpatiallyIndexed = false;
                m.AddLayer(geometryLayer);
                provider.Open();
            }
        }
Exemplo n.º 13
0
        public void GetShapeTypeWhenClosedThrowsExceptionTest()
        {
            ShapeFileProvider shapeFile = new ShapeFileProvider(
                BcRoadsWithOutDbfShapeFile,
                _geoFactory);

            Assert.AreEqual(ShapeType.PolyLine, shapeFile.ShapeType);
        }
Exemplo n.º 14
0
        public void NoPrjFileImpliesCoordinateSystemIsNullTest()
        {
            ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsWithOutDbfShapeFile, _geoFactory);

            shapeFile.Open();
            Assert.IsNull(shapeFile.SpatialReference);
            shapeFile.Close();
        }
Exemplo n.º 15
0
        public ShapeExporter(string shapefilepath)
        {
            _provider = new ShapeFileProvider(shapefilepath, _geometryServices.DefaultGeometryFactory,
                                              _geometryServices.CoordinateSystemFactory, false);

            _provider.IsSpatiallyIndexed = false;
            _provider.Open();
        }
Exemplo n.º 16
0
        public void GetFilenameTest()
        {
            ShapeFileProvider shapeFile = new ShapeFileProvider(
                BcRoadsWithOutDbfShapeFile,
                _geoFactory);

            Assert.AreEqual(BcRoadsWithOutDbfShapeFile, shapeFile.Filename);
        }
Exemplo n.º 17
0
        public void SetTableSchemaShouldFailIfShapeFileNotOpen()
        {
            ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsShapeFile, _geoFactory);

            FeatureDataTable nonKeyedTable = new FeatureDataTable(_geoFactory);

            shapeFile.SetTableSchema(nonKeyedTable);
        }
Exemplo n.º 18
0
        public void GetGeometriesInViewWhenClosedThrowsExceptionTest()
        {
            ShapeFileProvider shapeFile = new ShapeFileProvider(
                BcRoadsShapeFile, _geoFactory, _coordSysFactory);

            IGeometry empty = _geoFactory.CreatePoint();
            //new List<IGeometry>(shapeFile.ExecuteGeometryIntersectionQuery(empty));
        }
Exemplo n.º 19
0
        public void GetFeatureCountTest()
        {
            ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsShapeFile, _geoFactory);
            Int32             expected  = 7291;
            Int32             actual    = shapeFile.GetFeatureCount();

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 20
0
        public void OpenExclusiveTest()
        {
            ShapeFileProvider shapeFile = new ShapeFileProvider(
                BcRoadsShapeFile, _geoFactory, _coordSysFactory);

            shapeFile.Open(true);
            File.OpenRead(BcRoadsShapeFile);
        }
Exemplo n.º 21
0
        public void SetCoordinateSystemWithPrjFileThrowsExceptionTest()
        {
            ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsShapeFile, _geoFactory, _coordSysFactory);

            shapeFile.Open();
            IProjectedCoordinateSystem cs = createExpectedCoordinateSystem();

            shapeFile.SpatialReference = cs;
        }
Exemplo n.º 22
0
        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);
        }
Exemplo n.º 23
0
        public void GetExtentsTest()
        {
            ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsShapeFile, _geoFactory);
            IExtents          expected  = _geoFactory.CreateExtents2D(
                7332083.2127965018, 236823.71867240831,
                7538428.618, 405610.34692560317);
            IExtents actual = shapeFile.GetExtents();

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 24
0
        public void GetShapeTypeTest()
        {
            ShapeFileProvider shapeFile = new ShapeFileProvider(
                BcRoadsWithOutDbfShapeFile,
                _geoFactory);

            shapeFile.Open();
            Assert.AreEqual(ShapeType.PolyLine, shapeFile.ShapeType);
            shapeFile.Close();
        }
Exemplo n.º 25
0
        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();
        }
Exemplo n.º 26
0
        public void SetTableSchemaWithDifferentKeyCase()
        {
            ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsShapeFile, _geoFactory);

            shapeFile.Open();
            IGeometry empty = _geoFactory.CreatePoint();

            FeatureDataTable <UInt32> keyedTable = new FeatureDataTable <UInt32>("oid", _geoFactory);

            shapeFile.SetTableSchema(keyedTable);
        }
Exemplo n.º 27
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();
        }
Exemplo n.º 28
0
        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);
        }
Exemplo n.º 29
0
        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);
        }
Exemplo n.º 30
0
        private FileStream openDbfFileStream(WriteAccess writeAccess)
        {
            FilePermissions @params = ShapeFileProvider.GetPermissions(writeAccess);

            return(new FileStream(_filename,
                                  @params.FileMode,
                                  @params.FileAccess,
                                  @params.FileShare,
                                  4096,
                                  FileOptions.None));
        }
Exemplo n.º 31
0
        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();
        }
Exemplo n.º 32
0
        public void GetSchemaTableReturnsOid()
        {
            ShapeFileProvider shapeFile = new ShapeFileProvider(
                BcRoadsShapeFile, _geoFactory, _coordSysFactory);

            shapeFile.Open();

            DataTable schemaTable = shapeFile.GetSchemaTable();

            Assert.AreEqual(34, schemaTable.Rows.Count);
            Assert.AreEqual("OID", schemaTable.Rows[0][ProviderSchemaHelper.ColumnNameColumn]);
        }
Exemplo n.º 33
0
    public GuiTest1()
    {
        
        ShapeFileProvider shpData = new ShapeFileProvider(shapesDirPC, true);
        //Assert.IsNotNull(shpData);
        shpData.Open();
        //Assert.IsTrue(!File.Exists(@"..\..\..\TestData\BCROADS.shp.sidx"));
      

        //GeometryLayer gLayer = new GeometryLayer("My layer", shpData);


        //myMap.Layers.Add(gLayer);




    }
Exemplo n.º 34
0
 public void GetFilenameTest()
 {
     ShapeFileProvider shapeFile = new ShapeFileProvider(
                                         BcRoadsWithOutDbfShapeFile, 
                                         _geoFactory);
     Assert.AreEqual(BcRoadsWithOutDbfShapeFile, shapeFile.Filename);
 }
Exemplo n.º 35
0
 public void ConnectionIdTest()
 {
     ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsShapeFile, _geoFactory);
     Assert.AreEqual(BcRoadsShapeFile, shapeFile.ConnectionId);
 }
Exemplo n.º 36
0
        public void SetTableSchemaWithDifferentKeyNameAndSchemaMergeAction()
        {
            ShapeFileProvider shapeFile = new ShapeFileProvider(
                BcRoadsShapeFile, _geoFactory, _coordSysFactory);
            shapeFile.Open();
            IGeometry empty = _geoFactory.CreatePoint();
            FeatureDataTable<UInt32> queryTable = shapeFile.CreateNewTable() as FeatureDataTable<UInt32>;
            // expecting a new FeatureDataTable<UInt32>("OID", _geoFactory);

            FeatureDataTable<UInt32> keyedTable = new FeatureDataTable<UInt32>("FID", _geoFactory);
            shapeFile.SetTableSchema(keyedTable, SchemaMergeAction.KeyByType);
            DataTableHelper.AssertTableStructureIdentical(keyedTable, queryTable);
        }
Exemplo n.º 37
0
 public void GetShapeTypeTest()
 {
     ShapeFileProvider shapeFile = new ShapeFileProvider(
                                         BcRoadsWithOutDbfShapeFile, 
                                         _geoFactory);
     shapeFile.Open();
     Assert.AreEqual(ShapeType.PolyLine, shapeFile.ShapeType);
     shapeFile.Close();
 }
Exemplo n.º 38
0
        public void GetSchemaTableReturnsOid()
        {
            ShapeFileProvider shapeFile = new ShapeFileProvider(
                BcRoadsShapeFile, _geoFactory, _coordSysFactory);
            shapeFile.Open();

            DataTable schemaTable = shapeFile.GetSchemaTable();

            Assert.AreEqual(34, schemaTable.Rows.Count);
            Assert.AreEqual("OID", schemaTable.Rows[0][ProviderSchemaHelper.ColumnNameColumn]);
        }
Exemplo n.º 39
0
        public void SetTableSchemaShouldMatchShapeFileSchema()
        {
            ShapeFileProvider shapeFile = new ShapeFileProvider(
                BcRoadsShapeFile, _geoFactory, _coordSysFactory);
            shapeFile.Open();
            IGeometry empty = _geoFactory.CreatePoint();
            FeatureDataTable<UInt32> queryTable = shapeFile.CreateNewTable() as FeatureDataTable<UInt32>;

            FeatureDataTable nonKeyedTable = new FeatureDataTable(_geoFactory);
            shapeFile.SetTableSchema(nonKeyedTable);
            DataTableHelper.AssertTableStructureIdentical(nonKeyedTable, queryTable);

            FeatureDataTable<UInt32> keyedTable = new FeatureDataTable<UInt32>("OID", _geoFactory);
            shapeFile.SetTableSchema(keyedTable);
            DataTableHelper.AssertTableStructureIdentical(keyedTable, queryTable);
        }
Exemplo n.º 40
0
        public void GetGeometriesInViewTest()
        {
            ShapeFileProvider shapeFile = new ShapeFileProvider(
                BcRoadsShapeFile, _geoFactory, _coordSysFactory);
            shapeFile.Open();
            List<IGeometry> geometries = new List<IGeometry>();

            //geometries.AddRange(shapeFile.ExecuteGeometryIntersectionQuery(shapeFile.GetExtents()));
            Assert.AreEqual(shapeFile.GetFeatureCount(), geometries.Count);
            geometries.Clear();

            IGeometry empty = _geoFactory.CreatePoint();
            //geometries.AddRange(shapeFile.ExecuteGeometryIntersectionQuery(empty));
            Assert.AreEqual(0, geometries.Count);
        }
Exemplo n.º 41
0
        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);
        }
Exemplo n.º 42
0
 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);
 }
Exemplo n.º 43
0
 public void CloseExclusiveTest()
 {
     ShapeFileProvider shapeFile = new ShapeFileProvider(
         BcRoadsShapeFile, _geoFactory, _coordSysFactory);
     shapeFile.Open(true);
     shapeFile.Close();
     File.OpenRead(BcRoadsShapeFile).Close();
 }
Exemplo n.º 44
0
 public void HasDbfWithoutDbfFileIsFalseTest()
 {
     ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsWithOutDbfShapeFile, _geoFactory);
     Assert.IsFalse(shapeFile.HasDbf);
     shapeFile.Close();
 }
Exemplo n.º 45
0
 public void HasDbfWithDbfFileIsTrueTest()
 {
     ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsShapeFile, _geoFactory);
     Assert.IsTrue(shapeFile.HasDbf);
     shapeFile.Close();
 }
Exemplo n.º 46
0
 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();
 }
Exemplo n.º 47
0
        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();
        }
Exemplo n.º 48
0
        public void GetGeometriesInViewWhenClosedThrowsExceptionTest()
        {
            ShapeFileProvider shapeFile = new ShapeFileProvider(
                BcRoadsShapeFile, _geoFactory, _coordSysFactory);

            IGeometry empty = _geoFactory.CreatePoint();
            //new List<IGeometry>(shapeFile.ExecuteGeometryIntersectionQuery(empty));
        }
Exemplo n.º 49
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();
        }
Exemplo n.º 50
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();
 }
Exemplo n.º 51
0
        public void GetSchemaTableFailsifShapeFileNotOpen()
        {
            ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsShapeFile, _geoFactory);

            DataTable schemaTable = shapeFile.GetSchemaTable();
        }
Exemplo n.º 52
0
 public void ExecuteIntersectionQueryByBoundingBoxWhenClosedThrowsExceptionTest()
 {
     ShapeFileProvider shapeFile = new ShapeFileProvider(
         BcRoadsShapeFile, _geoFactory, _coordSysFactory);
     FeatureQueryExpression query = FeatureQueryExpression.Intersects(shapeFile.GetExtents());
     IFeatureDataReader reader = shapeFile.ExecuteFeatureQuery(query);
 }
Exemplo n.º 53
0
        public void SetTableSchemaShouldFailIfShapeFileNotOpen()
        {
            ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsShapeFile, _geoFactory);

            FeatureDataTable nonKeyedTable = new FeatureDataTable(_geoFactory);
            shapeFile.SetTableSchema(nonKeyedTable);
        }
Exemplo n.º 54
0
 public void GetFeatureCountTest()
 {
     ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsShapeFile, _geoFactory);
     Int32 expected = 7291;
     Int32 actual = shapeFile.GetFeatureCount();
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 55
0
        public void SetTableSchemaWithDifferentKeyCase()
        {
            ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsShapeFile, _geoFactory);
            shapeFile.Open();
            IGeometry empty = _geoFactory.CreatePoint();

            FeatureDataTable<UInt32> keyedTable = new FeatureDataTable<UInt32>("oid", _geoFactory);
            shapeFile.SetTableSchema(keyedTable);
        }
Exemplo n.º 56
0
        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();
        }
Exemplo n.º 57
0
        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);
        }
Exemplo n.º 58
0
 public void GetExtentsTest()
 {
     ShapeFileProvider shapeFile = new ShapeFileProvider(BcRoadsShapeFile, _geoFactory);
     IExtents expected =_geoFactory.CreateExtents2D(
         7332083.2127965018, 236823.71867240831, 
         7538428.618, 405610.34692560317);
     IExtents actual = shapeFile.GetExtents();
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 59
0
 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();
 }
Exemplo n.º 60
0
 public void GetShapeTypeWhenClosedThrowsExceptionTest()
 {
     ShapeFileProvider shapeFile = new ShapeFileProvider(
                                         BcRoadsWithOutDbfShapeFile,
                                         _geoFactory);
     Assert.AreEqual(ShapeType.PolyLine, shapeFile.ShapeType);
 }