public void TestLineairRingContainsRing() { LineairRing inner = new LineairRing(new GeoCoordinate(1, 1), new GeoCoordinate(1, 0.2), new GeoCoordinate(0.2, 1), new GeoCoordinate(1, 1)); LineairRing outer = new LineairRing(new GeoCoordinate(0, 0), new GeoCoordinate(2, 0), new GeoCoordinate(2, 2), new GeoCoordinate(0, 2), new GeoCoordinate(0, 0)); Assert.IsTrue(outer.Contains(inner)); }
public void TestLineairRingContainsPoint() { LineairRing ring = new LineairRing(new GeoCoordinate(0, 0), new GeoCoordinate(3, 0), new GeoCoordinate(0, 3), new GeoCoordinate(0, 0)); foreach (GeoCoordinate ringCoordinate in ring.Coordinates) { Assert.IsTrue(ring.Contains(ringCoordinate)); } GeoCoordinate coordinate = new GeoCoordinate(1, 1); Assert.IsTrue(ring.Contains(coordinate)); coordinate = new GeoCoordinate(2, 2); Assert.IsFalse(ring.Contains(coordinate)); coordinate = new GeoCoordinate(-1, 1); Assert.IsFalse(ring.Contains(coordinate)); coordinate = new GeoCoordinate(0, 1); Assert.IsTrue(ring.Contains(coordinate)); coordinate = new GeoCoordinate(1, 0); Assert.IsTrue(ring.Contains(coordinate)); }
private Geometry GroupRings(List <KeyValuePair <bool, LineairRing> > rings) { Geometry geometry1 = (Geometry)null; bool[][] containsFlags = new bool[rings.Count][]; KeyValuePair <bool, LineairRing> ring; for (int index1 = 0; index1 < rings.Count; ++index1) { containsFlags[index1] = new bool[rings.Count]; for (int index2 = 0; index2 < index1; ++index2) { bool[] flagArray = containsFlags[index1]; int index3 = index2; ring = rings[index1]; LineairRing lineairRing1 = ring.Value; ring = rings[index2]; LineairRing lineairRing2 = ring.Value; int num = lineairRing1.Contains(lineairRing2) ? 1 : 0; flagArray[index3] = num != 0; } } bool[] used = new bool[rings.Count]; MultiPolygon multiPolygon = (MultiPolygon)null; while (((IEnumerable <bool>)used).Contains <bool>(false)) { LineairRing outline = (LineairRing)null; int index = -1; for (int ringIdx = 0; ringIdx < rings.Count; ++ringIdx) { if (!used[ringIdx] && this.CheckUncontained(rings, containsFlags, used, ringIdx)) { ring = rings[ringIdx]; if (!ring.Key) { Log.TraceEvent("OsmSharp.Osm.Interpreter.SimpleGeometryInterpreter", TraceEventType.Error, "Invalid multipolygon relation: an 'inner' ring was detected without an 'outer'."); } index = ringIdx; ring = rings[ringIdx]; outline = ring.Value; used[ringIdx] = true; break; } } if (outline != null) { List <LineairRing> lineairRingList1 = new List <LineairRing>(); for (int ringIdx = 0; ringIdx < rings.Count; ++ringIdx) { if (!used[ringIdx] && containsFlags[index][ringIdx] && this.CheckUncontained(rings, containsFlags, used, ringIdx)) { List <LineairRing> lineairRingList2 = lineairRingList1; ring = rings[ringIdx]; LineairRing lineairRing = ring.Value; lineairRingList2.Add(lineairRing); used[ringIdx] = true; } } bool flag = !((IEnumerable <bool>)used).Contains <bool>(false); if (((multiPolygon != null ? 0 : (lineairRingList1.Count == 0 ? 1 : 0)) & (flag ? 1 : 0)) != 0) { geometry1 = (Geometry)outline; break; } if (multiPolygon == null & flag) { geometry1 = (Geometry) new Polygon(outline, (IEnumerable <LineairRing>)lineairRingList1); break; } multiPolygon = new MultiPolygon(); geometry1 = (Geometry)multiPolygon; Polygon geometry2 = new Polygon(outline, (IEnumerable <LineairRing>)lineairRingList1); multiPolygon.Add(geometry2); } else { Log.TraceEvent("OsmSharp.Osm.Interpreter.SimpleGeometryInterpreter", TraceEventType.Error, "Invalid multipolygon relation: Unassigned rings left."); break; } } return(geometry1); }