Exemple #1
0
 public void ExecuteIntersectionQueryByBoundingBoxWhenClosedThrowsExceptionTest()
 {
     ShapeFileProvider shapeFile = new ShapeFileProvider(
         BcRoadsShapeFile, _geoFactory, _coordSysFactory);
     FeatureQueryExpression query  = FeatureQueryExpression.Intersects(shapeFile.GetExtents());
     IFeatureDataReader     reader = shapeFile.ExecuteFeatureQuery(query);
 }
        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);
        }
Exemple #3
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);
        }
Exemple #4
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();
        }
        public void Save()
        {
            using (FileStream indexStream = _indexFile.Open(FileMode.Create, FileAccess.Write, FileShare.None))
                using (BinaryWriter indexWriter = new BinaryWriter(indexStream))
                {
                    _header.Extents           = ShapeFile.GetExtents();
                    _header.FileLengthInWords = computeIndexLengthInWords();
                    _header.WriteHeader(indexWriter);

                    foreach (IndexEntry entry in _shapeIndex.Values)
                    {
                        indexWriter.Write(ByteEncoder.GetBigEndian(entry.Offset));
                        indexWriter.Write(ByteEncoder.GetBigEndian(entry.Length));
                    }

                    indexWriter.Flush();
                }
        }
        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 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 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);
 }
 public void ExecuteIntersectionQueryByBoundingBoxWhenClosedThrowsExceptionTest()
 {
     ShapeFileProvider shapeFile = new ShapeFileProvider(
         BcRoadsShapeFile, _geoFactory, _coordSysFactory);
     FeatureQueryExpression query = FeatureQueryExpression.Intersects(shapeFile.GetExtents());
     IFeatureDataReader reader = shapeFile.ExecuteFeatureQuery(query);
 }
 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();
 }
Exemple #11
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);
        }
Exemple #12
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);
        }
Exemple #13
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);
        }