Exemplo n.º 1
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.º 2
0
        private static void generatePoints(IGeometryFactory geometryFactory,
                                           ICollection <IGeometry> geometry,
                                           Random rndGen)
        {
            Int32 numPoints = rndGen.Next(10, 100);

            for (Int32 pointIndex = 0; pointIndex < numPoints; pointIndex++)
            {
                IPoint point = geometryFactory.CreatePoint2D(rndGen.NextDouble() * 1000, rndGen.NextDouble() * 1000);
                geometry.Add(point);
            }
        }
        public void MultiLinestring()
        {
            IMultiLineString mls = _geoFactory.CreateMultiLineString();

            Assert.IsTrue(mls.IsEmpty);
            mls.Add(_geoFactory.CreateLineString());
            Assert.IsTrue(mls.IsEmpty);
            mls[0].Coordinates.Add(_geoFactory.CreatePoint2D(45, 68));
            mls[0].Coordinates.Add(_geoFactory.CreatePoint2D(82, 44));
            mls.Add(createLineString());

            foreach (ILineString ls in (IEnumerable <ILineString>)mls)
            {
                Assert.IsFalse(ls.IsEmpty);
            }

            Assert.IsFalse(mls.IsEmpty);

            foreach (ILineString ls in (IEnumerable <ILineString>)mls)
            {
                Assert.IsFalse(ls.IsClosed);
            }

            Assert.IsFalse(mls.IsClosed);

            //Close linestrings
            foreach (ILineString ls in (IEnumerable <ILineString>)mls)
            {
                ls.Coordinates.Add((ls.StartPoint.Clone() as IPoint).Coordinate);
            }

            foreach (ILineString ls in (IEnumerable <ILineString>)mls)
            {
                Assert.IsTrue(ls.IsClosed);
            }

            Assert.IsTrue(mls.IsClosed);
            Assert.AreEqual(_geoFactory.CreateExtents2D(1, 2, 930, 123), mls.Extents);
        }
Exemplo n.º 4
0
        public void IPoint()
        {
            //Do various IPoint method calls to cover the point class with sufficient testing
            IPoint2D p0 = _geoFactory.CreatePoint() as IPoint2D;
            IPoint2D p1 = _geoFactory.CreatePoint2D(0, 0);
            IPoint2D p2 = _geoFactory.CreatePoint2D(450, 120);

            Assert.IsTrue(p0.IsEmpty);
            Assert.IsFalse(p1.IsEmpty);
            Assert.AreNotEqual(p0, p1);
            Assert.AreEqual(450, p2.X);
            Assert.AreEqual(120, p2.Y);
            Assert.AreNotSame(p2.Clone(), p2);
            p0 = _geoFactory.CreatePoint2D(p2.X + 100, 150);
            p0 = _geoFactory.CreatePoint2D(p0.X + p0.Y, p0.Y);
            Assert.AreEqual(_geoFactory.CreatePoint2D(700, 150), p0);
            Assert.AreEqual(p2.Coordinate, p2.Extents.Min);
            Assert.AreEqual(p2.Coordinate, p2.Extents.Max);
            Assert.IsTrue(p2.IsSimple);
            Assert.IsFalse(p2.IsEmpty);
            Assert.AreEqual(2, p2.OrdinateCount);
            Assert.AreEqual(_geoFactory.CreatePoint2D(400, 100), p2.Add(_geoFactory.CreatePoint2D(-50, -20)));
            Assert.AreEqual(_geoFactory.CreatePoint2D(500, 100), p2.Subtract(_geoFactory.CreatePoint2D(-50, 20)));
            Assert.AreEqual(_geoFactory.CreatePoint2D(900, 240), p2.Multiply(2));
            Assert.AreEqual(0, p2.Dimension);
            Assert.AreEqual(450, p2[Ordinates.X]);
            Assert.AreEqual(120, p2[Ordinates.Y]);
            Assert.IsNull(p2.Boundary);
            Assert.AreEqual(p2.X.GetHashCode() ^ p2.Y.GetHashCode() ^ p2.IsEmpty.GetHashCode(), p2.GetHashCode());
            Assert.Greater(p2.CompareTo(p1), 0);
            Assert.Less(p1.CompareTo(p2), 0);
            Assert.AreEqual(p2.CompareTo(_geoFactory.CreatePoint2D(450, 120)), 0);
        }
        private static void generatePoints(IGeometryFactory geometryFactory,
                                           ICollection<IGeometry> geometry,
                                           Random rndGen)
        {
            Int32 numPoints = rndGen.Next(10, 100);

            for (Int32 pointIndex = 0; pointIndex < numPoints; pointIndex++)
            {
                IPoint point = geometryFactory.CreatePoint2D(rndGen.NextDouble() * 1000, rndGen.NextDouble() * 1000);
                geometry.Add(point);
            }
        }