/// <summary> /// /// </summary> /// <returns></returns> public bool IsNonNested() { for (int i = 0; i < rings.Count; i++) { ILinearRing innerRing = (ILinearRing)rings[i]; Coordinate[] innerRingPts = innerRing.Coordinates; for (int j = 0; j < rings.Count; j++) { ILinearRing searchRing = (ILinearRing)rings[j]; Coordinate[] searchRingPts = searchRing.Coordinates; if (innerRing == searchRing) { continue; } if (!innerRing.EnvelopeInternal.Intersects(searchRing.EnvelopeInternal)) { continue; } Coordinate innerRingPt = IsValidOp.FindPointNotNode(innerRingPts, searchRing, graph); Assert.IsTrue(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); }
/// <summary> /// /// </summary> /// <returns></returns> public bool IsNonNested() { foreach (var innerRing in rings) { var innerRingPts = innerRing.Coordinates; foreach (var searchRing in rings) { var searchRingPts = searchRing.Coordinates; if (innerRing == searchRing) { continue; } if (!innerRing.EnvelopeInternal.Intersects(searchRing.EnvelopeInternal)) { continue; } var innerRingPt = IsValidOp.FindPointNotNode(innerRingPts, searchRing, graph); Assert.IsTrue(innerRingPt != null, "Unable to find a ring point not a node of the search ring"); bool isInside = PointLocation.IsInRing(innerRingPt, searchRingPts); if (isInside) { nestedPt = innerRingPt; return(false); } } } return(true); }
public bool IsNonNested() { BuildIndex(); for (int i = 0; i < _rings.Count; i++) { var innerRing = (ILinearRing)_rings[i]; var innerRingPts = innerRing.Coordinates; var results = _index.Query(innerRing.EnvelopeInternal); for (int j = 0; j < results.Count; j++) { var searchRing = (ILinearRing)results[j]; var searchRingPts = searchRing.Coordinates; if (innerRing == searchRing) { continue; } if (!innerRing.EnvelopeInternal.Intersects(searchRing.EnvelopeInternal)) { continue; } var innerRingPt = IsValidOp.FindPointNotNode(innerRingPts, searchRing, _graph); // Diego Guidi: removed => see Issue 121 //Assert.IsTrue(innerRingPt != null, "Unable to find a ring point not a node of the search ring"); /** * If no non-node pts can be found, this means * that the searchRing touches ALL of the innerRing vertices. * This indicates an invalid polygon, since either * the two holes create a disconnected interior, * or they touch in an infinite number of points * (i.e. along a line segment). * Both of these cases are caught by other tests, * so it is safe to simply skip this situation here. */ if (innerRingPt == null) { continue; } bool isInside = PointLocation.IsInRing(innerRingPt, searchRingPts); if (isInside) { _nestedPt = innerRingPt; return(false); } } } return(true); }
public void TestInvalidCoordinate() { Coordinate badCoord = new Coordinate(1.0, Double.NaN); Coordinate[] pts = { new Coordinate(0.0, 0.0), badCoord }; IGeometry line = geometryFactory.CreateLineString(pts); IsValidOp isValidOp = new IsValidOp(line); bool valid = isValidOp.IsValid; TopologyValidationError err = isValidOp.ValidationError; Coordinate errCoord = err.Coordinate; Assert.AreEqual(TopologyValidationErrors.InvalidCoordinate, err.ErrorType); Assert.IsTrue(Double.IsNaN(errCoord.Y)); Assert.AreEqual(false, valid); }
public static IGeometry InvalidGeoms(IGeometry g) { var invalidGeoms = new List<IGeometry>(); for (var 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); }
/// <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 (var 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()); }
/// <summary> /// /// </summary> /// <param name="innerRing"></param> /// <param name="searchRing"></param> /// <returns></returns> private bool IsInside(ILinearRing innerRing, ILinearRing searchRing) { Coordinate[] innerRingPts = innerRing.Coordinates; Coordinate[] searchRingPts = searchRing.Coordinates; if (!innerRing.EnvelopeInternal.Intersects(searchRing.EnvelopeInternal)) { return(false); } Coordinate innerRingPt = IsValidOp.FindPointNotNode(innerRingPts, searchRing, graph); Assert.IsTrue(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); }
/// <summary> /// /// </summary> /// <returns></returns> public bool IsNonNested() { BuildQuadtree(); for (int i = 0; i < _rings.Count; i++) { var innerRing = _rings[i]; var innerRingPts = innerRing.Coordinates; var results = _quadtree.Query(innerRing.EnvelopeInternal); for (int j = 0; j < results.Count; j++) { var searchRing = results[j]; var searchRingPts = searchRing.Coordinates; if (innerRing == searchRing) { continue; } if (!innerRing.EnvelopeInternal.Intersects(searchRing.EnvelopeInternal)) { continue; } var innerRingPt = IsValidOp.FindPointNotNode(innerRingPts, searchRing, _graph); Assert.IsTrue(innerRingPt != null, "Unable to find a ring point not a node of the search ring"); bool isInside = PointLocation.IsInRing(innerRingPt, searchRingPts); if (isInside) { _nestedPt = innerRingPt; return(false); } } } return(true); }
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)); }
private void CheckIsValidSTR(String wkt, bool expected) { IGeometry geom = FromWKT(wkt); IsValidOp validator = new IsValidOp(geom); validator.IsSelfTouchingRingFormingHoleValid = true; 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 CheckIsValid(Geometry geom, bool expected) { IsValidOp validator = new IsValidOp(geom); bool isValid = validator.IsValid; Assert.IsTrue(isValid == expected); }