示例#1
0
        internal static List <Vector> GetIntersectionPoints(List <Polygon> polygons)
        {
            var f         = GeometryFactory.Floating;
            var iarray    = polygons.Where(poly => !poly.IsGrass).Select(p => p.ToIPolygon()).ToArray();
            var multipoly = f.CreateMultiPolygon(iarray);
            var isects    = iarray.Where(p => !p.IsValid).Select(p =>
            {
                var validOp = new IsValidOp(p).ValidationError.Coordinate;
                return(new Vector(validOp.X, validOp.Y));
            }).ToList();

            if (!multipoly.IsValid)
            {
                var validOp = new IsValidOp(multipoly).ValidationError;
                if (validOp.ErrorType == TopologyValidationErrors.SelfIntersection)
                {
                    isects.Add(new Vector(validOp.Coordinate.X, validOp.Coordinate.Y));
                }
            }

            var vectors = polygons.SelectMany(p => p.Vertices);
            var query   = vectors.GroupBy(x => x)
                          .Where(g => g.Count() > 1)
                          .Select(y => y.Key);

            isects.AddRange(query);
            return(isects);
        }
示例#2
0
        private void CheckIsValid(Geometry geom, bool expected)
        {
            var  validator = new IsValidOp(geom);
            bool isValid   = validator.IsValid;

            Assert.IsTrue(isValid == expected);
        }
        private void CheckIsValidDefault(string wkt, bool expected)
        {
            var  geom      = FromWKT(wkt);
            var  validator = new IsValidOp(geom);
            bool isValid   = validator.IsValid;

            Assert.IsTrue(isValid == expected);
        }
        private void CheckIsValidDefault(String wkt, bool expected)
        {
            IGeometry geom      = FromWKT(wkt);
            IsValidOp validator = new IsValidOp(geom);
            bool      isValid   = validator.IsValid;

            Assert.IsTrue(isValid == expected);
        }
        private void CheckIsValidSTR(string wkt, bool expected)
        {
            var geom      = FromWKT(wkt);
            var validator = new IsValidOp(geom);

            validator.IsSelfTouchingRingFormingHoleValid = true;
            bool isValid = validator.IsValid;

            Assert.IsTrue(isValid == expected);
        }
        public void CascadedUnionError2()
        {
            var sf    = new ShapefileReader(Path.Combine(CommonHelpers.TestShapefilesDirectory, "error_union.shp"));
            var geoms = sf.ReadAll();

            var isValidOp = new IsValidOp(geoms);

            Assert.That(!isValidOp.IsValid);
            Assert.That(isValidOp.ValidationError.ErrorType, Is.EqualTo(TopologyValidationErrors.RingSelfIntersection));

            Assert.That(geoms.Union, Throws.InstanceOf <TopologyException>());
        }
示例#7
0
 /// <summary>
 /// Validates the shape, throwing a descriptive error if it isn't valid. Note that this
 /// is usually called automatically by default, but that can be disabled.
 /// </summary>
 /// <exception cref="InvalidShapeException">with descriptive error if the shape isn't valid</exception>
 public virtual void Validate()
 {
     if (!validated)
     {
         IsValidOp isValidOp = new IsValidOp(geom);
         if (!isValidOp.IsValid)
         {
             throw new InvalidShapeException(isValidOp.ValidationError.ToString());
         }
         validated = true;
     }
 }
示例#8
0
        public void ToGeoJson_RelationWithTouchingPolygones_ShouldReturnValidMultiPolygon()
        {
            int id            = 1;
            var node1         = CreateNode(id++, 0, 0);
            var node2         = CreateNode(id++, 0, 1);
            var node3         = CreateNode(id++, 1, 1);
            var node4         = CreateNode(id++, 1, 0);
            var node5         = CreateNode(id++, 0, 2);
            var node6         = CreateNode(id++, 1, 2);
            var node7         = CreateNode(id++, -1, -1);
            var node8         = CreateNode(id++, 3, -1);
            var node9         = CreateNode(id++, 3, 3);
            var node10        = CreateNode(id++, -1, 3);
            var polygon1inner = new CompleteWay {
                Id = id++, Nodes = new[] { node1, node2, node3, node4, node1 }
            };
            var polygon2inner = new CompleteWay {
                Id = id++, Nodes = new[] { node2, node5, node6, node3, node2 }
            };
            var polygonOuter = new CompleteWay {
                Id = id++, Nodes = new[] { node7, node8, node9, node10, node7 }
            };

            var relation = new CompleteRelation {
                Id = id++, Tags = new TagsCollection()
            };

            relation.Tags.Add(NAME, NAME);
            relation.Tags.Add("type", "multipolygon");
            relation.Members = new[] {
                new CompleteRelationMember {
                    Member = polygonOuter, Role = "outer"
                },
                new CompleteRelationMember {
                    Member = polygon1inner
                },
                new CompleteRelationMember {
                    Member = polygon2inner
                }
            };

            var feature      = _converter.ToGeoJson(relation);
            var multiPolygon = feature.Geometry as MultiPolygon;

            Assert.IsNotNull(multiPolygon);
            var isValidOp = new IsValidOp(multiPolygon);

            Assert.IsTrue(isValidOp.IsValid);
        }
        //public static IList<ObjectId> CheckValid(IList<ObjectId> objectIds)
        //{
        //    var result = IsValid(objectIds);
        //    System.Diagnostics.Trace.WriteLine(result.Count);
        //    return result.Keys.ToList();
        //}

        public static Dictionary <ObjectId, SingleTopologyError> CheckValid(IList <ObjectId> objectIds)
        {
            var errorDictionary = new Dictionary <ObjectId, SingleTopologyError>();

            if (!objectIds.Any())
            {
                return(errorDictionary);
            }

            var database = objectIds[0].Database;

            var geometries = new List <IGeometry>();

            using (var tr = database.TransactionManager.StartTransaction())
            {
                var reader = new DwgReader();
                foreach (ObjectId objectId in objectIds)
                {
                    if (!objectId.IsValid)
                    {
                        continue;
                    }

                    IGeometry geom = reader.ReadEntityAsGeometry(tr, objectId);
                    if (geom == null)
                    {
                        continue;
                    }

                    geometries.Add(geom);
                    if (!geom.IsValid)
                    {
                        var ivop = new IsValidOp(geom);
                        if (!ivop.IsValid)
                        {
                            Console.WriteLine(geom.AsText());
                            Console.Write(ivop.ValidationError);
                            int errorType = (int)ivop.ValidationError.ErrorType;
                            var point     = new Point3d(ivop.ValidationError.Coordinate.X, ivop.ValidationError.Coordinate.Y, 0);
                            var error     = new SingleTopologyError((SingleTopologyErrors)errorType, point);
                            errorDictionary.Add(objectId, error);
                        }
                    }
                }
                tr.Commit();
            }

            return(errorDictionary);
        }
示例#10
0
        public void TestInvalidCoordinate()
        {
            var badCoord = new Coordinate(1.0, double.NaN);

            Coordinate[] pts       = { new Coordinate(0.0, 0.0), badCoord };
            Geometry     line      = geometryFactory.CreateLineString(pts);
            var          isValidOp = new IsValidOp(line);
            bool         valid     = isValidOp.IsValid;
            var          err       = isValidOp.ValidationError;
            var          errCoord  = err.Coordinate;

            Assert.AreEqual(TopologyValidationErrors.InvalidCoordinate, err.ErrorType);
            Assert.IsTrue(double.IsNaN(errCoord.Y));
            Assert.AreEqual(false, valid);
        }
示例#11
0
        public void ToGeoJson_Convert8Shape_ShouldConvertToMultipolygon()
        {
            int id    = 1;
            var node1 = CreateNode(id++, 0, 0);
            var node2 = CreateNode(id++, 0, 1);
            var node3 = CreateNode(id++, 1, 1);

            var node4 = CreateNode(id++, 1, 0);
            var node5 = CreateNode(id++, 0, -1);
            var node6 = CreateNode(id++, -1, -1);

            var node7 = CreateNode(id++, -1, 0);
            var way1  = new CompleteWay {
                Id = id++, Nodes = new[] { node1, node2, node3 }
            };
            var way2 = new CompleteWay {
                Id = id++, Nodes = new[] { node3, node4, node1, node5, node6 }
            };
            var way3 = new CompleteWay {
                Id = id++, Nodes = new[] { node6, node7, node1 }
            };

            var relation = new CompleteRelation {
                Id = id++, Tags = new TagsCollection()
            };

            relation.Tags.Add(NAME, NAME);
            relation.Tags.Add("type", "multipolygon");
            relation.Members = new[] {
                new CompleteRelationMember {
                    Member = way1, Role = "outer"
                },
                new CompleteRelationMember {
                    Member = way2, Role = "outer"
                },
                new CompleteRelationMember {
                    Member = way3, Role = "outer"
                }
            };

            var feature      = _converter.ToGeoJson(relation);
            var multiPolygon = feature.Geometry as MultiPolygon;

            Assert.IsNotNull(multiPolygon);
            var isValidOp = new IsValidOp(multiPolygon);

            Assert.IsTrue(isValidOp.IsValid);
        }
示例#12
0
        public static IGeometry InvalidGeoms(IGeometry g)
        {
            var invalidGeoms = new List <IGeometry>();

            for (int i = 0; i < g.NumGeometries; i++)
            {
                var geom = g.GetGeometryN(i);
                var ivop = new IsValidOp(geom);
                var err  = ivop.ValidationError;
                if (err != null)
                {
                    invalidGeoms.Add(geom);
                }
            }
            return(g.Factory.BuildGeometry(invalidGeoms));
        }
示例#13
0
        /// <summary>
        /// Validates all geometries in a collection independently.
        /// Errors are returned as points at the invalid location
        /// </summary>
        /// <param name="g"></param>
        /// <returns>the invalid locations, if any</returns>
        public static IGeometry InvalidLocations(IGeometry g)
        {
            var invalidLoc = new List <IPoint>();

            for (int i = 0; i < g.NumGeometries; i++)
            {
                var geom = g.GetGeometryN(i);
                var ivop = new IsValidOp(geom);
                var err  = ivop.ValidationError;
                if (err != null)
                {
                    invalidLoc.Add(g.Factory.CreatePoint(err.Coordinate));
                }
            }
            return(g.Factory.BuildGeometry(invalidLoc.ToArray()));
        }
        /// <inheritdoc />
        public List <Feature> Preprocess(Dictionary <string, List <ICompleteOsmGeo> > osmNamesDictionary)
        {
            _logger.LogInformation("Preprocessing OSM data to GeoJson, total distinct names: " + osmNamesDictionary.Keys.Count);
            var geoJsonNamesDictionary = new Dictionary <string, List <Feature> >();

            foreach (var pair in osmNamesDictionary)
            {
                var features = MergeOsmElements(pair.Value)
                               .Select(e =>
                {
                    var feature = _osmGeoJsonConverter.ToGeoJson(e);
                    if (feature == null)
                    {
                        _logger.LogError("Unable to convert " + e.ToString());
                    }
                    return(feature);
                })
                               .Where(f => f != null)
                               .ToList();
                if (!features.Any())
                {
                    continue;
                }
                AddAttributes(features);
                geoJsonNamesDictionary[pair.Key] = features;
            }

            geoJsonNamesDictionary.Values.SelectMany(v => v).ToList().ForEach(g =>
            {
                var isValidOp = new IsValidOp(g.Geometry);
                if (!isValidOp.IsValid)
                {
                    _logger.LogError($"{g.Geometry.GeometryType} with ID: {g.Attributes[FeatureAttributes.ID]} {isValidOp.ValidationError.Message} ({isValidOp.ValidationError.Coordinate.X},{isValidOp.ValidationError.Coordinate.Y})");
                }
                if (g.Geometry.IsEmpty)
                {
                    _logger.LogError($"{g.Geometry.GeometryType} with ID: {g.Attributes[FeatureAttributes.ID]} is an empty geometry - check for non-closed relations.");
                }
            });
            _logger.LogInformation("Finished GeoJson conversion");
            var featuresToReturn = geoJsonNamesDictionary.SelectMany(v => v.Value).ToList();

            ChangeLwnHikingRoutesToNoneCategory(featuresToReturn);
            return(featuresToReturn);
        }
示例#15
0
        public void Fixing_invalid_polygon_with_Buffer_0_returns_empty_polygon()
        {
            //arrange
            var rdr = new WKTReader();

            rdr.RepairRings = true;
            var poly = rdr.Read(
                @"POLYGON ((1.4749999999994841 -5.15, 30 -5.15, 48.9 -2,
108.1997 -2, 130.25148787313435 0.75647348414179227, 
130.25148787313435 0.75647348414179161, 130 0.75, 
126.3 0.72, 122.9 0.7, 119.2 0.42, 115.2 0.45, 
111 0.29, 106.9 0.23, 102.8 0.2, 98.8 0.12, 94.8 0.04, 
90.7 -0.08, 86.5 -0.2, 82.4 -0.42, 78.3 -0.57, 74.1 -0.69,
69.9 -0.78, 65.8 -0.87, 61.7 -1.07, 57.7 -1.09, 53.7 -1.229,
49.5 -1.289, 45.3 -1.369, 41.2 -1.719, 37 -2.409, 32.8 -3.219,
28.6 -3.769, 24.5 -4.089, 20.4 -4.429, 16.3 -4.599, 12.1 -4.759,
8 -4.889, 4 -5.049, 1.4749999999994841 -5.15))");

            //act
            var gpr = new NetTopologySuite.Precision.GeometryPrecisionReducer(new PrecisionModel(1e10));
            //gpr.ChangePrecisionModel = true;
            //gpr.Pointwise = false;
            var poly1 = gpr.Reduce(poly);
            var poly2 = poly.Buffer(0);

            ToImage(0, poly, poly1, poly2);

            var isValidOp = new IsValidOp(poly);

            if (!isValidOp.IsValid)
            {
                Debug.WriteLine(isValidOp.ValidationError);
            }
            Debug.WriteLine(poly1.AsText());
            // assert
            //Assert.That(poly.IsValid, Is.True, "poly.IsValid");
            Assert.That(poly1.IsValid, Is.True, "poly1.IsValid");
            Assert.That(poly2, Is.Not.Null, "poly2 != null");

            //Known to fail
            //Assert.That(poly2.IsEmpty, Is.False, "poly2.IsEmpty");
        }
        public bool IsNonNested()
        {
            BuildQuadtree();

            int nCount = rings.Count;

            for (int i = 0; i < nCount; i++)
            {
                LinearRing      innerRing    = (LinearRing)rings[i];
                ICoordinateList innerRingPts = innerRing.Coordinates;

                IList results      = quadtree.Query(innerRing.Bounds);
                int   nResultCount = results.Count;
                for (int j = 0; j < nResultCount; j++)
                {
                    LinearRing      searchRing    = (LinearRing)results[j];
                    ICoordinateList searchRingPts = searchRing.Coordinates;

                    if (innerRing == searchRing)
                    {
                        continue;
                    }

                    if (!innerRing.Bounds.Intersects(searchRing.Bounds))
                    {
                        continue;
                    }

                    Coordinate innerRingPt = IsValidOp.FindPointNotNode(innerRingPts, searchRing, graph);
                    Debug.Assert(innerRingPt != null, "Unable to find a ring point not a node of the search ring");

                    bool IsInside = CGAlgorithms.IsPointInRing(innerRingPt, searchRingPts);
                    if (IsInside)
                    {
                        nestedPt = innerRingPt;
                        return(false);
                    }
                }
            }

            return(true);
        }
示例#17
0
        public void Test(int number, string wkt1, string wkt2)
        {
            const double scaleFactor = 1e10;

            var reader = new WKTReader();
            var geom1  = reader.Read(wkt1);
            var ve1    = new IsValidOp(geom1).ValidationError;

            if (ve1 != null)
            {
                Debug.WriteLine(string.Format("geom1 is not valid:\n{0} at {1}", ve1.Message, ve1.Coordinate));
                Debug.WriteLine("Attempt to make geom1 a valid geometry");
                Debug.WriteLine(geom1.AsText());
                geom1 = geom1.Buffer(0);
                Debug.WriteLine(geom1.AsText());
            }
            var geom2 = reader.Read(wkt2);
            var ve2   = new IsValidOp(geom1).ValidationError;

            if (ve2 != null)
            {
                Debug.WriteLine(string.Format("geom2 is not valid:\n{0} at {1}", ve2.Message, ve2.Coordinate));
                Debug.WriteLine("Attempt to make geom2 a valid geometry");
                Debug.WriteLine(geom2.AsText());
                geom2 = geom2.Buffer(0);
                Debug.WriteLine(geom2.AsText());
            }

            IGeometry result = null;

            try
            {
                result = geom1.Intersection(geom2);
            }
            catch (TopologyException)
            {
                Debug.WriteLine("Probing with SnapRoundOverlayFunctions");
                Assert.DoesNotThrow(() => result = SnapRoundOverlayFunctions.Intersection(geom1, geom2, scaleFactor));
            }

            ToImage(number, geom1, geom2, result);
        }
示例#18
0
//19.64311408996582 49.603153228759766
//        1914206496
//        180998242

//19.71388099829122, 49.648193645648
// 19.628429388931949, 49.617853376339596
        private ILinearRing ToLinearRing(List <Vector2> nodes)
        {
            var nodesAsCoordinates = nodes.Select(c => MyNetTopologySuiteUtils.ToCoordinate(c)).ToList();

            if (!nodesAsCoordinates.First().Equals(nodesAsCoordinates.Last()))
            {
                var repairedRing = nodesAsCoordinates.ToList();
                repairedRing.Add(nodesAsCoordinates.First());
                var ring = new LinearRing(repairedRing.ToArray());
                if (!ring.IsValid)
                {
                    //simple connection failed. Propably should do crectangle merging
                    var ringRect = ring.EnvelopeInternal;
                    Debug.Log("Pushing your luck. Lets hope that it is his only, 2415555 relation!");
                    //todo make better invalid circular way  repairing algorithm. Like find which two sides
                    // of enveloping rectangle would be shorted in repairing road
                    var newRingPoint = ringRect.ToMyRectangle().TopRightPoint;
                    repairedRing[repairedRing.Count - 1] = new Coordinate(newRingPoint.x, newRingPoint.y);
                    repairedRing.Add(nodesAsCoordinates.First());

                    ring = new LinearRing(repairedRing.ToArray());
                    if (!ring.IsValid)
                    {
                        var validOp = new IsValidOp(ring);
                        Debug.Log("Validation error is: " + validOp.ValidationError);
                        Debug.Log("R1 Ring is " + ring.ToString());
                        return(null);

                        //var text = ring.ToText();
                        //File.WriteAllText(@"C:\inz\wrongRing.wkt", text);
                    }
                    Preconditions.Assert(ring.IsValid, "Ring still invalid. What to do?");
                }
                return(ring);
            }
            else
            {
                return(new LinearRing(nodesAsCoordinates.ToArray()));
            }
        }
示例#19
0
        public void ToGeoJson_ConvertLoopAndLines_ShouldCreateValidMultiLine()
        {
            int id    = 1;
            var node1 = CreateNode(id++, 0, 0);
            var node2 = CreateNode(id++, 0, 1);
            var node3 = CreateNode(id++, 1, 1);
            var node4 = CreateNode(id++, 1, 0);

            var node5 = CreateNode(id++, 0, -1);

            var way1 = new CompleteWay {
                Id = id++, Nodes = new[] { node1, node5 }
            };
            var way2 = new CompleteWay {
                Id = id++, Nodes = new[] { node1, node2, node3, node4, node1 }
            };

            var relation = new CompleteRelation {
                Id = id++, Tags = new TagsCollection()
            };

            relation.Tags.Add(NAME, NAME);
            relation.Members = new[] {
                new CompleteRelationMember {
                    Member = way1, Role = "outer"
                },
                new CompleteRelationMember {
                    Member = way2, Role = "outer"
                }
            };

            var feature         = _converter.ToGeoJson(relation);
            var multiLineString = feature.Geometry as MultiLineString;

            Assert.IsNotNull(multiLineString);
            var isValidOp = new IsValidOp(multiLineString);

            Assert.IsTrue(isValidOp.IsValid);
        }
        private bool IsInside(LinearRing innerRing, LinearRing searchRing)
        {
            ICoordinateList innerRingPts  = innerRing.Coordinates;
            ICoordinateList searchRingPts = searchRing.Coordinates;

            if (!innerRing.Bounds.Intersects(searchRing.Bounds))
            {
                return(false);
            }

            Coordinate innerRingPt = IsValidOp.FindPointNotNode(innerRingPts, searchRing, graph);

            Debug.Assert(innerRingPt != null, "Unable to find a ring point not a node of the search ring");

            bool IsInside = CGAlgorithms.IsPointInRing(innerRingPt, searchRingPts);

            if (IsInside)
            {
                nestedPt = innerRingPt;
                return(true);
            }

            return(false);
        }
示例#21
0
		///<summary>
		///  Returns sTopologyValidationError object available if IsValid() returns false or null if no error exists.  
		///</summary>
		///<returns>Returns string corresponding to error message if IsValid fails.</returns>
		public virtual TopologyValidationError GetValidOpError()
		{
			IsValidOp isValidOp = new IsValidOp(this);
			return isValidOp.GetValidationError();
		}
示例#22
0
        public void Polygon_intersection_Error2()
        {
            //Arrange
            var reader = new WKTReader();
            var g1     = reader.Read(
                @"POLYGON ((0.0000000000000000 -6.1026585365860800,  3.8000000000000000 -5.7690000000000000,
7.9000000000000000 -5.4090000000000000,  12.0000000000000000 -5.3690000000000000,
16.1000000000000000 -5.0990000000000000,  20.3000000000000000 -5.1390000000000000,
24.5000000000000000 -4.9090000000000000,  28.5000000000000000 -4.6390000000000000,
32.6000000000000000 -4.1890000000000000,  36.6000000000000000 -3.2890000000000000,
40.8000000000000000 -3.1890000000000000,  44.8000000000000000 -2.9490000000000000,
49.0000000000000000 -2.8200000000000000,  53.3000000000000000 -2.3600000000000000,
57.3000000000000000 -2.1400000000000000,  61.3000000000000000 -1.5200000000000000,
65.5000000000000000 -1.3900000000000000,  69.6000000000000000 -1.1700000000000000,
73.6000000000000000 -1.0100000000000000,  77.9000000000000000 -0.9700000000000000,
82.0000000000000000 -0.8000000000000000,  86.2000000000000000 -0.7400000000000000,
90.2000000000000000 -0.6700000000000000,  94.5000000000000000 -0.6000000000000000,
98.6000000000000000 -0.5000000000000000,  102.6000000000000000 -0.3900000000000000,
106.9000000000000000 -0.2400000000000000,  111.1000000000000000 -0.1500000000000000,
115.1000000000000000 -0.1510000000000000,  119.2000000000000000 -0.1510000000000000,
123.1000000000000000 -0.0510000000000000,  127.2000000000000000 0.0590000000000000,
131.2000000000000000 0.2090000000000000,  132.2000000000000000 1.0250000000000000,
132.6000000000000000 2.6400000000000000,  132.6000000000000000 2.6400000000000000,
132.6000000000000000 0.5000000000000000,  128.6000000000000000 0.5000000000000000,
106.2000000000000000 -2.3000000000000000,  49.9000000000000000 -2.3000000000000000,
31.0000000000000000 -5.4500000000000000,  0.0000000000000000 -5.4500000000000000,
0.0000000000000000 -6.1026585365860800))");
            var isValidOp = new IsValidOp(g1);

            if (!isValidOp.IsValid)
            {
                Debug.WriteLine("g1 is not valid:" + isValidOp.ValidationError);
                g1 = g1.Buffer(0);
                Debug.WriteLine(g1.AsText());
            }
            var g2 = reader.Read(
                @"POLYGON ((0.0000000000000000 2.6400000000000000,  0.0000000000000000 -6.0030697674418800,
0.3200000000000000 -5.9800000000000000,  4.6200000000000000 -5.6700000000000000,
8.8100000000000000 -5.1600000000000000,  13.1000000000000000 -5.2100000000000000,
17.1200000000000000 -4.8400000000000000,  21.2800000000000000 -5.1700000000000000,
25.5000000000000000 -5.1600000000000000,  29.7100000000000000 -4.6700000000000000,
34.1300000000000000 -3.9000000000000000,  38.2800000000000000 -3.4800000000000000,
42.6400000000000000 -3.3000000000000000,  46.9800000000000000 -3.2600000000000000,
51.1600000000000000 -2.8900000000000000,  55.3200000000000000 -2.8300000000000000,
59.3000000000000000 -2.9200000000000000,  63.6800000000000000 -2.3600000000000000,
67.4800000000000000 -2.5700000000000000,  70.8900000000000000 -2.4800000000000000,
74.8900000000000000 -2.5500000000000000,  78.8800000000000000 -2.6900000000000000,
82.4400000000000000 -2.4600000000000000,  87.5300000000000000 -2.8100000000000000,
91.6200000000000000 -2.7500000000000000,  95.9000000000000000 -2.1000000000000000,
100.2200000000000000 -2.2100000000000000,  104.4400000000000000 -2.3000000000000000,
109.1500000000000000 -1.9500000000000000,  113.2400000000000000 -2.8200000000000000,
117.2400000000000000 -1.9600000000000000,  120.9400000000000000 -1.3000000000000000,
125.0300000000000000 -0.8200000000000000,  126.6800000000000000 0.1300000000000000,
132.5500000000000000 1.5400000000000000,  132.6000000000000000 2.6400000000000000,
132.6000000000000000 2.6400000000000000,  132.6000000000000000 2.6400000000000000,
0.0000000000000000 2.6400000000000000))");

            isValidOp = new IsValidOp(g1);
            if (!isValidOp.IsValid)
            {
                Debug.WriteLine("g2 is not valid:" + isValidOp.ValidationError);
                g2 = g2.Buffer(0);
                Debug.WriteLine(g2.AsText());
            }
            //Act
            var res = g1.Intersection(g2);

            //
            ToImage(1, g1, g2, res);

            // Assert
            Assert.That(res, Is.Not.Null);
            Debug.WriteLine(res.AsText());
        }
示例#23
0
        public void TestWeirdPolygonOverlaps()
        {
            var reader            = new WKTReader();
            var point             = new Point(14.436641302074806, 46.152664043249864);
            var weirdMultipolygon = reader.Read(@"MULTIPOLYGON (
((14.4339828 46.1531875, 14.4339638 46.153288800000006, 14.4340434 46.153408600000006, 
    14.4344242 46.1534977, 14.434769300000001 46.1534538, 14.434982900000001 46.153437600000004, 
    14.4351181 46.153387, 14.4351988 46.1533894, 14.435310800000002 46.153381100000004, 
    14.4354583 46.153404900000005, 14.4357 46.153395100000004, 14.4358213 46.1533117, 
    14.435957700000001 46.153234100000006, 14.436522600000002 46.1529219, 14.4367783 46.152714700000004, 
    14.437007900000001 46.1525638, 14.437267 46.1524513, 14.4373751 46.1523881, 
    14.4374035 46.152350500000004, 14.437399500000001 46.152310400000005, 14.4373728 46.152270300000005, 
    14.437467300000002 46.1522099, 14.437569300000002 46.152289, 14.4386974 46.1530106, 
    14.439418400000001 46.153347800000006, 14.440187600000002 46.153683400000006, 14.4401726 46.153703900000004, 
    14.440494900000001 46.153834200000006, 14.4405107 46.1538176, 14.441133700000002 46.154087700000005, 
    14.4415937 46.1542363, 14.441952800000001 46.154324800000005, 14.442209900000002 46.1543821, 
    14.442399000000002 46.154365500000004, 14.442551600000002 46.1543222, 14.442715000000002 46.154221500000006, 
    14.442780500000001 46.1541529, 14.4428213 46.154065700000004, 14.4428365 46.153967200000004, 
    14.442826 46.153854800000005, 14.442651900000001 46.1535689, 14.4425304 46.1533801, 
    14.442478500000002 46.153212200000006, 14.442479500000001 46.153058, 14.4425574 46.152778700000006, 
    14.4426371 46.152497000000004, 14.442915300000001 46.1518487, 14.443142600000002 46.151448300000006, 
    14.4436657 46.1506266, 14.4438697 46.1503127, 14.444000500000001 46.150151400000006, 
    14.444173300000001 46.150042600000006, 14.4443607 46.149981600000004, 14.444567500000002 46.1499444, 
    14.445336800000002 46.1499473, 14.445627000000002 46.149955600000006, 14.4457953 46.1499661, 
    14.445998900000001 46.1500013, 14.4460837 46.150012100000005, 14.446171300000001 46.1500077, 
    14.4462436 46.1499952, 14.4463074 46.149981600000004, 14.446402200000001 46.149934200000004, 
    14.4467049 46.1497067, 14.447263900000001 46.149275100000004, 14.448217900000001 46.148524, 
    14.448412900000001 46.148330200000004, 14.448585900000001 46.1480885, 14.448883100000002 46.1475354, 
    14.448523600000001 46.1472502, 14.4483288 46.1471152, 14.448225 46.1470144, 
    14.4481137 46.147063800000005, 14.4479263 46.1471281, 14.4475753 46.1472265, 
    14.447544200000001 46.1472458, 14.447290200000001 46.147287000000006, 14.447175000000001 46.147294300000006, 
    14.447003700000002 46.147295400000004, 14.4469139 46.147291, 14.446652700000001 46.147303400000006, 
    14.446551600000001 46.1473127, 14.446136000000001 46.1473166, 14.446079800000001 46.1473202, 
    14.446017900000001 46.1473394, 14.4459443 46.1473956, 14.4458593 46.147477200000004, 
    14.445736900000002 46.147623100000004, 14.445626200000001 46.147764800000004, 14.4454785 46.147933900000005, 
    14.445352600000001 46.148087800000006, 14.445152 46.148293300000006, 14.4450897 46.1483496, 
    14.445047400000002 46.148372800000004, 14.4447959 46.148531600000005, 14.444652000000001 46.148609, 
    14.4444683 46.148729100000004, 14.444135000000001 46.1489284, 14.443979400000002 46.149042800000004, 
    14.443939700000001 46.1490797, 14.4438373 46.1492158, 14.4435085 46.1495284, 
    14.4433281 46.149603600000006, 14.4432884 46.1496366, 14.443245600000001 46.149702700000006, 
    14.4431864 46.149733600000005, 14.443152600000001 46.1497432, 14.443107500000002 46.1497625, 
    14.4430653 46.149770100000005, 14.443028600000002 46.149789500000004, 14.443002700000001 46.1498518, 
    14.442980100000002 46.1498653, 14.442943600000001 46.149861200000004, 14.4429186 46.1498416, 
    14.4429051 46.149785, 14.442940900000002 46.149734, 14.4428782 46.1496815, 
    14.442812300000002 46.1496032, 14.442864900000002 46.149498, 14.442873200000001 46.1492767, 
    14.442783100000002 46.149187700000006, 14.442922000000001 46.148943900000006, 14.443127800000001 46.148683500000004, 
    14.442989 46.148579700000006, 14.4426725 46.1484108, 14.442645500000001 46.1483902, 
    14.4425296 46.1483196, 14.442456600000002 46.148332800000006, 14.442335700000001 46.148344, 
    14.4422288 46.148364900000004, 14.442062700000001 46.148409, 14.4419698 46.148439800000006, 
    14.4417887 46.1484844, 14.4416042 46.1485922, 14.441422800000002 46.148716500000006, 
    14.441218200000002 46.1489315, 14.4410713 46.149046000000006, 14.4409542 46.1491047, 
    14.4405616 46.149253800000004, 14.440293100000002 46.149322600000005, 14.440127100000002 46.149338900000004, 
    14.439948000000001 46.1493635, 14.439785800000001 46.149369, 14.4397122 46.149368100000004, 
    14.4396193 46.1493557, 14.439384800000001 46.149385800000005, 14.439052 46.1494895, 
    14.438935200000001 46.1495169, 14.438781100000002 46.1496221, 14.438736200000001 46.149692, 
    14.438693200000001 46.1497338, 14.438601400000001 46.149807700000004, 14.438438300000001 46.149903900000005, 
    14.4382484 46.149975000000005, 14.4381395 46.1500527, 14.4378568 46.150218800000005, 
    14.4376633 46.1504087, 14.437555900000001 46.150488800000005, 14.437429400000001 46.1506021, 
    14.437375600000001 46.1505981, 14.4373149 46.150613400000005, 14.4372564 46.150638, 
    14.437208900000002 46.150676700000005, 14.437179200000001 46.150729600000005, 14.4371094 46.1507658, 
    14.437100000000001 46.1507993, 14.4370527 46.1508224, 14.4370255 46.1508534, 
    14.4370229 46.1508939, 14.436627900000001 46.1511876, 14.436511600000001 46.1512553, 
    14.436389400000001 46.1512782, 14.436272500000001 46.151273700000004, 14.436114700000001 46.1512046, 
    14.4360374 46.151178800000004, 14.435941600000001 46.1511998, 14.435560200000001 46.1513952, 
    14.4354396 46.151509700000005, 14.4352768 46.1516243, 14.4352151 46.1517579, 
    14.435180500000001 46.1517963, 14.4350523 46.151873200000004, 14.435001000000002 46.1519355, 
    14.434919 46.151985800000006, 14.4348206 46.1520583, 14.434397700000002 46.1522841, 
    14.434253100000001 46.1524104, 14.434171200000002 46.1524471, 14.433937 46.1525377, 
    14.433781900000001 46.152585800000004, 14.4337139 46.152640100000006, 14.433716200000001 46.1526791, 
    14.4336686 46.152672300000006, 14.433621100000002 46.1526702, 14.433637200000001 46.1527119, 
    14.433701500000002 46.152717200000005, 14.433753600000001 46.1527572, 14.4338013 46.1528519, 
    14.433802900000002 46.1529455, 14.433817900000001 46.152973900000006, 14.433918400000001 46.1530928, 
    14.433961900000002 46.1531377, 14.4339828 46.1531875), 
    (14.4399359 46.1497936, 14.439883300000002 46.149801000000004, 14.4396012 46.1499071, 
        14.439490900000001 46.149971400000005, 14.439395200000002 46.1499862, 14.439327700000002 46.149970200000006, 
        14.439051500000001 46.150070400000004, 14.438846300000002 46.1501524, 14.4386995 46.150200600000005, 
        14.438623300000001 46.150236, 14.438541500000001 46.150297300000005, 14.4385469 46.150316800000006, 
        14.438633300000001 46.1502969, 14.4386668 46.1503127, 14.4386764 46.150372000000004, 
        14.438763300000002 46.1503323, 14.438963600000001 46.1502539, 14.439182700000002 46.150157, 
        14.439363400000001 46.150077800000005, 14.439442600000001 46.150027400000006, 14.439713300000001 46.1499164, 
        14.439900000000002 46.1498472, 14.439947400000001 46.149816300000005, 14.4399359 46.1497936), 
    (14.437723400000001 46.1511093, 14.437710800000001 46.151116900000005, 14.4377226 46.1511608, 
        14.4376417 46.151205700000006, 14.4375262 46.1512557, 14.437503000000001 46.151282200000004, 
        14.4375716 46.1513198, 14.437746 46.151382500000004, 14.437723400000001 46.1511093), 
    (14.441487 46.1496581, 14.441049600000001 46.1496457, 14.4408367 46.1496415, 
        14.440460000000002 46.1496599, 14.440289600000002 46.14967, 14.4400943 46.149694000000004, 
        14.4399265 46.149775000000005, 14.4399359 46.1497936, 14.439947400000001 46.149816300000005, 
        14.439900000000002 46.1498472, 14.439713300000001 46.1499164, 14.439442600000001 46.150027400000006, 
        14.439363400000001 46.150077800000005, 14.439182700000002 46.150157, 14.438963600000001 46.1502539, 
        14.438763300000002 46.1503323, 14.4386764 46.150372000000004, 14.4383447 46.150718600000005, 
        14.438307300000002 46.150771600000006, 14.438193400000001 46.150828000000004, 14.437723400000001 46.1511093, 
        14.437746 46.151382500000004, 14.437865500000001 46.151433100000006, 14.438002500000001 46.151529700000005, 
        14.4380749 46.1515727, 14.4382204 46.151584, 14.4383029 46.1516001, 
        14.438353900000001 46.151560700000005, 14.4384507 46.151501800000005, 14.438651700000001 46.151404500000005, 
        14.438736700000002 46.151332700000005, 14.438810900000002 46.151227600000006, 14.438872900000002 46.151202500000004, 
        14.438991300000001 46.1511718, 14.439197700000001 46.151045800000006, 14.4393846 46.150912000000005, 
        14.4395211 46.150777600000005, 14.439562500000001 46.1507517, 14.4396474 46.1506144, 
        14.439783400000001 46.150521100000006, 14.4398332 46.1504746, 14.439932200000001 46.150434600000004, 
        14.4402436 46.1503029, 14.440323200000002 46.1502114, 14.4403082 46.150187900000006, 
        14.440374400000001 46.1501455, 14.440437300000001 46.1501302, 14.440709600000002 46.1500727, 
        14.4408334 46.150059600000006, 14.440937900000002 46.150015200000006, 14.4411465 46.149885000000005, 
        14.441279000000002 46.1497821, 14.441487 46.1496581), 
    (14.4417065 46.1495107, 14.4416696 46.1495456, 14.441614000000001 46.1495784, 
        14.441519600000001 46.149619, 14.441487 46.1496581, 14.441279000000002 46.1497821, 
        14.4411465 46.149885000000005, 14.440937900000002 46.150015200000006, 14.4408334 46.150059600000006, 
        14.440709600000002 46.1500727, 14.440437300000001 46.1501302, 14.440374400000001 46.1501455, 
        14.4403082 46.150187900000006, 14.440323200000002 46.1502114, 14.4402436 46.1503029, 
        14.439932200000001 46.150434600000004, 14.4398332 46.1504746, 14.439783400000001 46.150521100000006, 
        14.4396474 46.1506144, 14.439562500000001 46.1507517, 14.4395211 46.150777600000005, 
        14.4393846 46.150912000000005, 14.439197700000001 46.151045800000006, 14.438991300000001 46.1511718, 
        14.438872900000002 46.151202500000004, 14.438810900000002 46.151227600000006, 14.438736700000002 46.151332700000005, 
        14.438651700000001 46.151404500000005, 14.4384507 46.151501800000005, 14.438353900000001 46.151560700000005, 
        14.4383029 46.1516001, 14.438316700000001 46.151619700000005, 14.438438000000001 46.1517397, 
        14.4385007 46.1518785, 14.438677700000001 46.1520473, 14.438816000000001 46.1521066, 
        14.438872400000001 46.152087300000005, 14.438948000000002 46.151999800000006, 14.439005100000001 46.151920000000004, 
        14.4390531 46.151862400000006, 14.439048900000001 46.1518164, 14.4390836 46.151778500000006, 
        14.439171100000001 46.1517059, 14.439232800000001 46.1516983, 14.439255800000002 46.1516777, 
        14.4392358 46.1516285, 14.439247400000001 46.1516031, 14.4394375 46.151548500000004, 
        14.439531500000001 46.1515046, 14.439669400000001 46.151419600000004, 14.439690500000001 46.1513657, 
        14.4397181 46.151338900000006, 14.439752400000001 46.151332700000005, 14.439811800000001 46.151329800000006, 
        14.439839300000001 46.151322, 14.439872000000001 46.151246, 14.439922600000001 46.1512113, 
        14.440085300000002 46.151155, 14.4400992 46.1511361, 14.440095000000001 46.1510964, 
        14.4401226 46.1510711, 14.440203 46.1510255, 14.440706500000001 46.1507834, 
        14.4410983 46.1506301, 14.4413526 46.1505239, 14.4414279 46.150506400000005, 
        14.441477500000001 46.1504902, 14.4415548 46.1504847, 14.441587100000001 46.1504744, 
        14.4416302 46.1504537, 14.4417691 46.150427, 14.4419278 46.1504016, 
        14.4421811 46.150332500000005, 14.4422215 46.1502927, 14.442168400000002 46.150257700000004, 
        14.4421014 46.150180600000006, 14.442105900000001 46.1500938, 14.442135200000001 46.150012200000006, 
        14.4421063 46.1499449, 14.4420728 46.1499437, 14.442005600000002 46.1499219, 
        14.441933 46.1498786, 14.4418327 46.149802, 14.4418135 46.1497649, 
        14.441803100000001 46.149675, 14.441818000000001 46.1495912, 14.441869500000001 46.149474700000006, 
        14.4418403 46.1494761, 14.4417065 46.1495107)), 
((14.4426816 46.1597324, 14.4426728 46.159786700000005, 14.4426778 46.159937600000006, 
    14.4426471 46.1600928, 14.4426488 46.160171600000005, 14.442702500000001 46.1602132, 
    14.442725900000001 46.1603055, 14.442762900000002 46.1603921, 14.442880700000002 46.160384400000005, 
    14.443374 46.160303400000004, 14.443548400000001 46.160095000000005, 14.4436318 46.1597981, 
    14.443667300000001 46.159687600000005, 14.443692500000001 46.159617000000004, 14.4437967 46.1595657, 
    14.4438458 46.1595121, 14.4438338 46.1594173, 14.4441106 46.1592113, 
    14.4441956 46.159160400000005, 14.444529800000002 46.1590154, 14.4447959 46.158920800000004, 
    14.444912200000001 46.1589176, 14.4450155 46.158867300000004, 14.445047500000001 46.1587814, 
    14.445527 46.158580300000004, 14.4458303 46.1585498, 14.446072200000001 46.158491500000004, 
    14.446358900000002 46.1584414, 14.4464973 46.1583951, 14.446144400000001 46.1579721, 
    14.446091200000001 46.1578816, 14.446111900000002 46.1577069, 14.4462314 46.1571209, 
    14.446263600000002 46.156874800000004, 14.446279400000002 46.156643700000004, 14.446277700000001 46.156545900000005, 
    14.446240300000001 46.1564987, 14.446280100000001 46.1563886, 14.4462638 46.1563518, 
    14.446335600000001 46.1559474, 14.4465198 46.155218500000004, 14.446719000000002 46.154667200000006, 
    14.446893300000001 46.154217700000004, 14.4470171 46.1539544, 14.447038500000001 46.153922400000006, 
    14.4475818 46.1529916, 14.4478807 46.1525106, 14.448260300000001 46.1519515, 
    14.448742600000001 46.151188600000005, 14.4489251 46.1509226, 14.449018200000001 46.1508236, 
    14.4490522 46.1507961, 14.4491425 46.150747800000005, 14.449398500000001 46.1506963, 
    14.4494716 46.150685, 14.449618000000001 46.1506447, 14.449705600000001 46.1506142, 
    14.450064200000002 46.1504052, 14.4501036 46.1503956, 14.4501854 46.150355000000005, 
    14.450405600000002 46.150274200000005, 14.450512300000002 46.1502418, 14.4505727 46.1502026, 
    14.450614600000002 46.150121600000006, 14.4508243 46.149982200000004, 14.4509161 46.149962900000006, 
    14.451005 46.149917200000004, 14.4510056 46.149855800000005, 14.450980900000001 46.149798600000004, 
    14.451025300000001 46.1497502, 14.4512254 46.1496731, 14.4512678 46.1496421, 
    14.4512906 46.149613, 14.4513365 46.149513600000006, 14.451416100000001 46.149412600000005, 
    14.451464300000001 46.149364000000006, 14.4515208 46.1493272, 14.451662 46.149245900000004, 
    14.4518231 46.1491355, 14.4519248 46.149071600000006, 14.451950400000001 46.1490366, 
    14.451976700000001 46.148937200000006, 14.4519996 46.148888500000005, 14.4520253 46.1488437, 
    14.452062300000001 46.148801000000006, 14.452107400000001 46.1487758, 14.4522089 46.1487392, 
    14.4522738 46.1487064, 14.4523191 46.148661700000005, 14.452438800000001 46.148484700000004, 
    14.4525561 46.1482667, 14.452602200000001 46.148140100000006, 14.452614700000002 46.1480133, 
    14.452601000000001 46.1479781, 14.452534600000002 46.147882200000005, 14.452521 46.1478334, 
    14.4525243 46.1477846, 14.452551000000001 46.1476423, 14.4525635 46.1475116, 
    14.452539400000001 46.1473905, 14.4525401 46.1473281, 14.452546000000002 46.1472969, 
    14.452376200000002 46.1469965, 14.452346200000001 46.146947600000004, 14.451617500000001 46.146817000000006, 
    14.451227600000001 46.146728700000004, 14.4510658 46.1471463, 14.450936800000001 46.1473534, 
    14.450821000000001 46.147471, 14.450705000000001 46.1476142, 14.4507332 46.147658400000005, 
    14.4506946 46.147701700000006, 14.450606800000001 46.147781300000005, 14.450569900000001 46.147824, 
    14.450521400000001 46.147899900000006, 14.4505011 46.147966200000006, 14.450494500000001 46.1480617, 
    14.4504712 46.148155300000006, 14.4504227 46.1482292, 14.450368800000001 46.1482855, 
    14.450348700000001 46.1483342, 14.450334000000002 46.1483927, 14.450330500000002 46.1484688, 
    14.4503383 46.1485332, 14.450340200000001 46.148621000000006, 14.4503284 46.1486815, 
    14.450302400000002 46.1487574, 14.450247500000001 46.1489094, 14.450099400000001 46.1491253, 
    14.4499863 46.149202800000005, 14.4499437 46.1492494, 14.4498136 46.1493483, 
    14.4496921 46.149419900000005, 14.449545700000002 46.149468000000006, 14.4494267 46.1494931, 
    14.4493573 46.149498300000005, 14.4492851 46.149486800000005, 14.4491668 46.149454500000004, 
    14.449107900000001 46.149450300000005, 14.4490628 46.1494657, 14.4489724 46.149525700000005, 
    14.4483955 46.1497751, 14.4483437 46.1497862, 14.4481978 46.149784100000005, 
    14.4481385 46.149804700000004, 14.447861900000001 46.1499536, 14.447833300000001 46.150004200000005, 
    14.447809500000002 46.1501426, 14.447789100000001 46.1502108, 14.4477437 46.150263300000006, 
    14.4476787 46.1503098, 14.447622200000001 46.150336900000006, 14.4475914 46.150336700000004, 
    14.447535400000001 46.150313000000004, 14.4471416 46.150452900000005, 14.446818200000001 46.1505245, 
    14.4469142 46.1505608, 14.4469904 46.1505967, 14.447003 46.150619600000006, 
    14.4470047 46.150654700000004, 14.4469992 46.150680200000004, 14.446976600000001 46.1507001, 
    14.4468554 46.150800100000005, 14.4466826 46.150941200000005, 14.446471500000001 46.1511695, 
    14.4463193 46.1512018, 14.446189400000002 46.151247700000006, 14.446079000000001 46.151367300000004, 
    14.446013500000001 46.1513481, 14.445574 46.1518542, 14.4455915 46.152287900000005, 
    14.445592000000001 46.152314700000005, 14.4456071 46.152839, 14.445615100000001 46.152891200000006, 
    14.445648100000001 46.1530459, 14.445658300000002 46.1530916, 14.4457097 46.1533214, 
    14.4456854 46.153486900000004, 14.445682900000001 46.1535042, 14.4456801 46.1535239, 
    14.445547600000001 46.1539811, 14.445393900000001 46.154462300000006, 14.445256100000002 46.154963200000005, 
    14.445229900000001 46.155615700000006, 14.4451847 46.155908800000006, 14.445136900000001 46.1560002, 
    14.445128500000001 46.1560162, 14.4451186 46.156035300000006, 14.4450949 46.1560828, 
    14.4449821 46.1562573, 14.4448077 46.156417100000006, 14.444770700000001 46.1564691, 
    14.444351800000002 46.1568708, 14.44424 46.1572442, 14.4441176 46.157488, 
    14.4440279 46.157632400000004, 14.443930100000001 46.157740700000005, 14.443804600000002 46.1577922, 
    14.4435704 46.157832400000004, 14.4433422 46.157836800000005, 14.442858600000001 46.1579502, 
    14.442698100000001 46.1579611, 14.442596700000001 46.158090300000005, 14.4425132 46.158328600000004, 
    14.4425041 46.1584188, 14.4426056 46.1585471, 14.4426321 46.1586112, 
    14.442593500000001 46.1586768, 14.4425737 46.158768800000004, 14.4426427 46.159167700000005, 
    14.4426035 46.159299100000005, 14.442604500000002 46.1594702, 14.4426904 46.1595803, 
    14.442697 46.159636000000006, 14.4426816 46.1597324))
)");

            Assert.That(weirdMultipolygon.IsValid, Is.False);
            double initialArea = weirdMultipolygon.Area;

            var isValidOp = new IsValidOp(weirdMultipolygon);

            if (!isValidOp.IsValid)
            {
                TestContext.WriteLine(isValidOp.ValidationError);
            }

            var fixedMultipolygon = weirdMultipolygon.Buffer(0);

            Assert.That(fixedMultipolygon.IsValid, Is.True);

            double similarity = new HausdorffSimilarityMeasure().Measure(weirdMultipolygon, fixedMultipolygon);

            Assert.That(similarity, Is.EqualTo(1).Within(0.001));

            bool res = true;

            Assert.That(() => res = fixedMultipolygon.Intersects(point), Throws.Nothing);
            Assert.That(res, Is.True);
        }
示例#24
0
        public NtsGeometry(IGeometry geom, NtsSpatialContext ctx, bool dateline180Check)
        {
            this.ctx = ctx;

            //GeometryCollection isn't supported in relate()
            if (geom.GetType() == typeof(GeometryCollection))
            {
                throw new ArgumentException("NtsGeometry does not support GeometryCollection but does support its subclasses.");
            }

            //NOTE: All this logic is fairly expensive. There are some short-circuit checks though.
            if (ctx.IsGeo())
            {
                //Unwraps the geometry across the dateline so it exceeds the standard geo bounds (-180 to +180).
                if (dateline180Check)
                {
                    UnwrapDateline(geom); //potentially modifies geom
                }
                //If given multiple overlapping polygons, fix it by union
                geom = UnionGeometryCollection(geom); //returns same or new geom
                Envelope unwrappedEnv = geom.EnvelopeInternal;

                //Cuts an unwrapped geometry back into overlaid pages in the standard geo bounds.
                geom = CutUnwrappedGeomInto360(geom);                       //returns same or new geom
                Debug.Assert(geom.EnvelopeInternal.Width <= 360);
                Debug.Assert(geom.GetType() != typeof(GeometryCollection)); //double check

                //note: this bbox may be sub-optimal. If geom is a collection of things near the dateline on both sides then
                // the bbox will needlessly span most or all of the globe longitudinally.
                // TODO so consider using MultiShape's planned minimal geo bounding box algorithm once implemented.
                double envWidth = unwrappedEnv.Width;

                //adjust minX and maxX considering the dateline and world wrap
                double minX, maxX;
                if (envWidth >= 360)
                {
                    minX = -180;
                    maxX = 180;
                }
                else
                {
                    minX = unwrappedEnv.MinX;
                    maxX = DistanceUtils.NormLonDEG(unwrappedEnv.MinX + envWidth);
                }
                bbox = new RectangleImpl(minX, maxX, unwrappedEnv.MinY, unwrappedEnv.MaxY, ctx);
            }
            else
            {//not geo
                Envelope env = geom.EnvelopeInternal;
                bbox = new RectangleImpl(env.MinX, env.MaxX, env.MinY, env.MaxY, ctx);
            }
            var _ = geom.EnvelopeInternal;            //ensure envelope is cached internally, which is lazy evaluated. Keeps this thread-safe.

            //Check geom validity; use helpful error
            // TODO add way to conditionally skip at your peril later
            var isValidOp = new IsValidOp(geom);

            if (!isValidOp.IsValid)
            {
                throw new InvalidShapeException(isValidOp.ValidationError.ToString());
            }
            this.geom = geom;

            this._hasArea = !((geom is ILineal) || (geom is IPuntal));
        }
示例#25
0
		///<summary>
		///  Returns false if the Geometry is invlaid.  
		///</summary>
		///<remarks>Subclasses provide their own definition of "valid". 
		///  If this Geometry is empty, returns true.</remarks>
		///<returns>Returns true if this Geometry is valid.</returns>
		public virtual bool IsValid()
		{
			IsValidOp isValidOp = new IsValidOp(this);
			return isValidOp.IsValid();
		}