/// <summary>
 /// Computes the transformation of the source geometry.
 /// </summary>
 /// <param name="source">The source geometry.</param>
 /// <returns>The geometry in the specified reference system.</returns>
 private IGeometryCollection <IGeometry> Compute(IGeometryCollection <IGeometry> source)
 {
     return(_factory.CreateGeometryCollection(source.Select(item => Compute(item)),
                                              _metadataPreservation ? source.Metadata : null));
 }
Пример #2
0
        public void HalfedgeGeometryOverlayTest()
        {
            IMultiPolygon first = _factory.CreateMultiPolygon(new[]
            {
                _factory.CreatePolygon(
                    _factory.CreatePoint(0, 0),
                    _factory.CreatePoint(10, 0),
                    _factory.CreatePoint(10, 10),
                    _factory.CreatePoint(0, 10)),
                _factory.CreatePolygon(
                    _factory.CreatePoint(10, 0),
                    _factory.CreatePoint(20, 0),
                    _factory.CreatePoint(20, 10),
                    _factory.CreatePoint(10, 10)),
                _factory.CreatePolygon(
                    _factory.CreatePoint(0, 10),
                    _factory.CreatePoint(10, 10),
                    _factory.CreatePoint(10, 20),
                    _factory.CreatePoint(0, 20)),
            });

            IMultiPolygon second = _factory.CreateMultiPolygon(new[]
            {
                _factory.CreatePolygon(
                    _factory.CreatePoint(-5, -5),
                    _factory.CreatePoint(5, -5),
                    _factory.CreatePoint(5, 5),
                    _factory.CreatePoint(-5, 5)),
                _factory.CreatePolygon(
                    _factory.CreatePoint(5, -5),
                    _factory.CreatePoint(15, -5),
                    _factory.CreatePoint(15, 5),
                    _factory.CreatePoint(5, 5)),
                _factory.CreatePolygon(
                    _factory.CreatePoint(-5, -15),
                    _factory.CreatePoint(5, -15),
                    _factory.CreatePoint(5, -5),
                    _factory.CreatePoint(-5, -5)),
            });

            Coordinate[][] expected = new[]
            {
                // ExternalFirst
                new[]
                {
                    new Coordinate(0, 10),
                    new Coordinate(10, 10),
                    new Coordinate(10, 20),
                    new Coordinate(0, 20),
                    new Coordinate(0, 10)
                },
                new[]
                {
                    new Coordinate(0, 5),
                    new Coordinate(5, 5),
                    new Coordinate(10, 5),
                    new Coordinate(10, 10),
                    new Coordinate(0, 10),
                    new Coordinate(0, 5)
                },
                new[]
                {
                    new Coordinate(10, 5),
                    new Coordinate(15, 5),
                    new Coordinate(15, 0),
                    new Coordinate(20, 0),
                    new Coordinate(20, 10),
                    new Coordinate(10, 10),
                    new Coordinate(10, 5)
                },
                // Internal
                new[]
                {
                    new Coordinate(5, 0),
                    new Coordinate(10, 0),
                    new Coordinate(10, 5),
                    new Coordinate(5, 5),
                    new Coordinate(5, 0)
                },
                new[]
                {
                    new Coordinate(10, 0),
                    new Coordinate(15, 0),
                    new Coordinate(15, 5),
                    new Coordinate(10, 5),
                    new Coordinate(10, 0)
                },
                new[]
                {
                    new Coordinate(0, 0),
                    new Coordinate(5, 0),
                    new Coordinate(5, 5),
                    new Coordinate(0, 5),
                    new Coordinate(0, 0)
                },
                // ExternalSecond
                new[]
                {
                    new Coordinate(-5, -15),
                    new Coordinate(5, -15),
                    new Coordinate(5, -5),
                    new Coordinate(-5, -5),
                    new Coordinate(-5, -15)
                },
                new[]
                {
                    new Coordinate(-5, -5),
                    new Coordinate(5, -5),
                    new Coordinate(5, 0),
                    new Coordinate(0, 0),
                    new Coordinate(0, 5),
                    new Coordinate(-5, 5),
                    new Coordinate(-5, -5)
                },
                new[]
                {
                    new Coordinate(5, -5),
                    new Coordinate(15, -5),
                    new Coordinate(15, 0),
                    new Coordinate(10, 0),
                    new Coordinate(5, 0),
                    new Coordinate(5, -5)
                }
            };

            // Difference
            IGeometry result = _operator.Difference(first, second);

            Assert.IsInstanceOf <IGeometryCollection <IPolygon> >(result);

            IGeometryCollection <IPolygon> collection = (IGeometryCollection <IPolygon>)result;

            Assert.AreEqual(new[]
            {
                expected[0],
                expected[1],
                expected[2],
            }.ToRingSet(), collection.Select(polygon => polygon.Shell).ToRingSet());

            // Intersection
            result = _operator.Intersection(first, second);
            Assert.IsInstanceOf <IGeometryCollection <IPolygon> >(result);

            collection = (IGeometryCollection <IPolygon>)result;
            Assert.AreEqual(new[]
            {
                expected[3],
                expected[4],
                expected[5],
            }.ToRingSet(), collection.Select(polygon => polygon.Shell).ToRingSet());

            // Symmetric difference
            result = _operator.SymmetricDifference(first, second);
            Assert.IsInstanceOf <IGeometryCollection <IPolygon> >(result);

            collection = (IGeometryCollection <IPolygon>)result;
            Assert.AreEqual(new[]
            {
                expected[0],
                expected[1],
                expected[2],
                expected[6],
                expected[7],
                expected[8],
            }.ToRingSet(), collection.Select(polygon => polygon.Shell).ToRingSet());

            // Union
            result = _operator.Union(first, second);
            Assert.IsInstanceOf <IGeometryCollection <IPolygon> >(result);

            collection = (IGeometryCollection <IPolygon>)result;
            Assert.AreEqual(expected.ToRingSet(), collection.Select(polygon => polygon.Shell).ToRingSet());
        }
 /// <summary>
 /// Computes the transformation of the source geometry.
 /// </summary>
 /// <param name="source">The source geometry.</param>
 /// <returns>The geometry in the specified reference system.</returns>
 private IGeometryCollection <IGeometryGraph> Compute(IGeometryCollection <IGeometryGraph> source)
 {
     return(_factory.CreateGeometryCollection(source.Select(geometry => Compute(geometry)),
                                              _metadataPreservation ? source.Metadata : null));
 }