public void PolygonizerTest() { const string wkt = @"MULTILINESTRING( (595435.592 663003.43, 595329.952 663070.947), (595435.592 663003.43, 595422.128 662982.365), (595422.128 662982.365, 595408.755 662961.281), (595408.755 662961.281, 595324.534 663015.109), (595324.534 663015.109, 595324.534 663015.109), (595326.792 663018.656, 595324.534 663015.109), (595324.534 663015.109, 595324.534 663015.109), (595324.534 663015.109, 595311.111 662994.018), (595311.111 662994.018, 595299.143 662975.215), (595299.143 662975.215, 595297.687 662972.927), (595297.687 662972.927, 595284.264 662951.837), (595284.264 662951.837, 595270.782 662930.654), (595299.143 662975.215, 595302.092 663071.747), (595302.092 663071.747, 595302.098 663071.926), (595329.289 663070.966, 595327.933 663042.567), (595327.933 663042.567, 595327.933 663042.567), (595327.933 663042.567, 595326.792 663018.656), (595327.933 663042.567, 595422.128 662982.365), (595355.101 662876.893, 595341.661 662855.813), (595341.661 662855.813, 595232.906 662925.154), (595232.906 662925.154, 595257.509 662928.727), (595257.509 662928.727, 595257.509 662928.727), (595257.509 662928.727, 595270.782 662930.654), (595270.782 662930.654, 595355.101 662876.893), (595301.269 662789.679, 595290.846 662792.619), (595290.846 662792.619, 595229.883 662829.806), (595229.883 662829.806, 595231.001 662867.129), (595314.822 662813.628, 595314.822 662813.628), (595314.822 662813.628, 595231.001 662867.129), (595301.269 662789.679, 595314.822 662813.628), (595314.822 662813.628, 595314.822 662813.628), (595237.314 663073.714, 595237.311 663073.607), (595237.311 663073.607, 595234.348 662973.758), (595234.348 662973.758, 595232.906 662925.154), (595232.906 662925.154, 595231.955 662896.179), (595231.955 662896.179, 595231.955 662896.179), (595231.955 662896.179, 595231.001 662867.129), (595395.292 662940.216, 595311.111 662994.018), (595381.829 662919.151, 595297.687 662972.927), (595368.365 662898.086, 595284.264 662951.837), (595328.272 662834.701, 595231.955 662896.179), (595231.955 662896.179, 595231.955 662896.179), (595408.755 662961.281, 595395.292 662940.216), (595395.292 662940.216, 595395.292 662940.216), (595395.292 662940.216, 595381.829 662919.151), (595381.829 662919.151, 595381.829 662919.151), (595381.829 662919.151, 595368.365 662898.086), (595368.365 662898.086, 595355.101 662876.893), (595341.661 662855.813, 595328.272 662834.701), (595328.272 662834.701, 595328.272 662834.701), (595328.272 662834.701, 595314.822 662813.628), (595314.822 662813.628, 595314.822 662813.628), (595229.059 662774.178, 595229.883 662829.806), (595301.269 662789.679, 595292.309 662772.342), (595210.495 662868.477, 595216.033 662860.79), (595217.835 662853.417, 595216.033 662860.79), (595208.232 662974.501, 595234.348 662973.758), (595212.331 663074.324, 595237.311 663073.607), (595237.311 663073.607, 595262.33 663072.888), (595262.33 663072.888, 595302.092 663071.747), (595302.092 663071.747, 595329.289 663070.966), (595329.289 663070.966, 595329.952 663070.947), (595329.952 663070.947, 595404.571 663068.804), (595404.571 663068.804, 595455.568 663034.686), (595455.568 663034.686, 595435.592 663003.43), (595257.509 662928.727, 595257.509 662928.727), (595257.509 662928.727, 595262.33 663072.888), (595262.33 663072.888, 595262.333 663073.001), (595177.856 662775.665, 595229.059 662774.178), (595229.059 662774.178, 595229.059 662774.178), (595229.059 662774.178, 595292.309 662772.342), (595217.835 662853.417, 595215.34 662774.577))"; // Arrange var geom = new WKTReader(new GeometryFactory(new PrecisionModel(1000))).Read(wkt); var op = new NetTopologySuite.Operation.Polygonize.Polygonizer(); op.Add(geom); // Act var res = op.GetGeometry(); // Assert Assert.That(res, Is.Not.Null, "geom != null"); Assert.That(res.IsValid, Is.True, "IsValid"); Assert.That(res.IsSimple, Is.True, "IsSimple"); Assert.That(new RepeatedPointTester().HasRepeatedPoint(res), Is.False, "No repeated points"); Assert.That(CoordinateArrays.HasRepeatedPoints(res.Coordinates), Is.False, "No repeated points"); }
public static IGeometry PolygonizeInvalidRingLines(IGeometry g) { var lines = LineStringExtracter.GetLines(g); var polygonizer = new Polygonizer(); polygonizer.Add(lines); var geom = polygonizer.GetInvalidRingLines(); return g.Factory.BuildGeometry(geom); }
public static IGeometry PolygonizeCutEdges(IGeometry g) { var lines = LineStringExtracter.GetLines(g); var polygonizer = new Polygonizer(); polygonizer.Add(lines); var geom = polygonizer.GetCutEdges(); return g.Factory.BuildGeometry(CollectionUtil.Cast<ILineString, IGeometry>(geom)); }
public static IGeometry polygonizeInvalidRingLines(IGeometry g) { var lines = LineStringExtracter.GetLines(g); Polygonizer polygonizer = new Polygonizer(); polygonizer.Add(CollectionUtil.Cast<ILineString, IGeometry>(lines)); var geom = polygonizer.GetInvalidRingLines(); return g.Factory.BuildGeometry(geom); }
public static IGeometry Polygonize(IGeometry g) { var lines = LineStringExtracter.GetLines(g); var polygonizer = new Polygonizer(); polygonizer.Add(lines); var polys = polygonizer.GetPolygons(); var polyArray = GeometryFactory.ToPolygonArray(polys); return g.Factory.CreateGeometryCollection(polyArray); }
/// <summary> /// Filters all <see cref="LineString"/> geometry instances /// </summary> /// <param name="g">The geometry instance</param> public void Filter(Geometry g) { var lineString = g as LineString; if (lineString != null) { _container.Add(lineString); } }
public static IGeometry PolygonizeAllErrors(IGeometry g) { var lines = LineStringExtracter.GetLines(g); var polygonizer = new Polygonizer(); polygonizer.Add(lines); var errs = new List<ILineString>(); errs.AddRange(polygonizer.GetDangles()); errs.AddRange(polygonizer.GetCutEdges()); errs.AddRange(CollectionUtil.Cast<IGeometry, ILineString>(polygonizer.GetInvalidRingLines())); return g.Factory.BuildGeometry(CollectionUtil.Cast<ILineString, IGeometry>(errs)); }
private static IGeometry Polygonize(IGeometry g, bool extractOnlyPolygonal) { var lines = LineStringExtracter.GetLines(g); var polygonizer = new Polygonizer(extractOnlyPolygonal); polygonizer.Add(lines); return polygonizer.GetGeometry(); /* Collection polys = polygonizer.getPolygons(); Polygon[] polyArray = GeometryFactory.toPolygonArray(polys); return g.getFactory().createGeometryCollection(polyArray); */ }
public static IGeometry Polygonize(IGeometry geometry) { if (geometry == null) throw new ArgumentNullException("geometry"); var lines = LineStringExtracter.GetLines(geometry); var geoms = lines.ToList(); var polygonizer = new Polygonizer(); polygonizer.Add(geoms); var polys = polygonizer.GetPolygons(); return geometry.Factory.BuildGeometry(polys); }
internal static IGeometry PolygonizeForClip(IGeometry geometry, IPreparedGeometry clip) { var lines = LineStringExtracter.GetLines(geometry); var clippedLines = new List<IGeometry>(); foreach (ILineString line in lines) { if (clip.Contains(line)) clippedLines.Add(line); } var polygonizer = new Polygonizer(); polygonizer.Add(clippedLines); var polys = polygonizer.GetPolygons(); var polyArray = GeometryFactory.ToGeometryArray(polys); return geometry.Factory.CreateGeometryCollection(polyArray); }
internal virtual void Run() { WKTReader rdr = new WKTReader(); IList<IGeometry> lines = new List<IGeometry> { rdr.Read("LINESTRING (0 0 , 10 10)"), rdr.Read("LINESTRING (185 221, 100 100)"), rdr.Read("LINESTRING (185 221, 88 275, 180 316)"), rdr.Read("LINESTRING (185 221, 292 281, 180 316)"), rdr.Read("LINESTRING (189 98, 83 187, 185 221)"), rdr.Read("LINESTRING (189 98, 325 168, 185 221)") }; Polygonizer polygonizer = new Polygonizer(); polygonizer.Add(lines); var polys = polygonizer.GetPolygons(); Console.WriteLine("Polygons formed (" + polys.Count + "):"); foreach(var obj in polys) Console.WriteLine(obj); }
public static DotSpatial.Data.FeatureSet Execute(DotSpatial.Data.Raster rst, ContourType contourType, string FieldName = "Value", double[] levels = null) { double[] lev = levels; noData = rst.NoDataValue; type = contourType; DotSpatial.Data.Raster iRst = RasterCheck(rst, lev); ; string field; if (FieldName == null) { field = "Value"; } else { field = FieldName; } double[] x = new double[rst.NumColumns]; double[] y = new double[rst.NumRows]; for (int i = 0; i < rst.NumColumns; i++) { x[i] = rst.Extent.MinX + rst.CellWidth * i + rst.CellWidth / 2; } for (int i = 0; i < rst.NumRows; i++) { y[i] = rst.Extent.MaxY - rst.CellHeight * i - rst.CellHeight / 2; } DotSpatial.Data.FeatureSet fs = null; switch (type) { case ContourType.Line: { fs = new DotSpatial.Data.FeatureSet(DotSpatial.Topology.FeatureType.Line); fs.DataTable.Columns.Add(field, typeof(double)); for (int z = 0; z < levels.Count(); z++) { IList<IGeometry> cont = GetContours(ref iRst, x, y, lev[z]); foreach (Geometry g in cont) { DotSpatial.Data.Feature f = (DotSpatial.Data.Feature)fs.AddFeature(ToDotSpatialLineString((ILineString)g)); f.DataRow[field] = lev[z]; } } } break; case ContourType.Polygon: { fs = new DotSpatial.Data.FeatureSet(DotSpatial.Topology.FeatureType.Polygon); fs.DataTable.Columns.Add("Lev", typeof(int)); fs.DataTable.Columns.Add("Label", typeof(string)); Collection<IGeometry> Contours = new Collection<IGeometry>(); for (int z = 0; z < levels.Count(); z++) { IList<IGeometry> cont = GetContours(ref iRst, x, y, lev[z]); foreach (Geometry g in cont) { Contours.Add(new LineString(g.Coordinates)); } } Coordinate[] Boundary = new Coordinate[5]; Boundary[0] = new Coordinate(x[0], y[0]); Boundary[1] = new Coordinate(x[0], y[rst.NumRows - 1]); Boundary[2] = new Coordinate(x[rst.NumColumns - 1], y[rst.NumRows - 1]); Boundary[3] = new Coordinate(x[rst.NumColumns - 1], y[0]); Boundary[4] = new Coordinate(x[0], y[0]); Contours.Add(new LineString(Boundary)); Collection<IGeometry> NodedContours = new Collection<IGeometry>(); GeometryNoder geomNoder = new GeometryNoder(new PrecisionModel(1000d)); foreach (LineString c in geomNoder.Node(Contours)) { NodedContours.Add(c); } Polygonizer polygonizer = new Polygonizer(); polygonizer.Add(NodedContours); foreach (Polygon p in polygonizer.GetPolygons()) { Point pnt = (Point)p.InteriorPoint; int c = (int)((pnt.X - iRst.Extent.MinX) / iRst.CellWidth); int r = (int)((iRst.Extent.MaxY - pnt.Y) / iRst.CellHeight); double z = ((DotSpatial.Data.Raster)iRst).Value[r, c]; int Cls = GetLevel(z, lev); string label = "Undefined"; if (Cls == -1) label = "< " + lev[0].ToString(); if (Cls == lev.Count()) label = "> " + lev[lev.Count() - 1].ToString(); if (Cls >= 0 & Cls < lev.Count()) label = lev[Cls].ToString() + " - " + lev[Cls + 1].ToString(); DotSpatial.Topology.Polygon dsp = ToDotSpatialPolygon(p); DotSpatial.Data.Feature f = (DotSpatial.Data.Feature)fs.AddFeature(dsp); f.DataRow["Lev"] = Cls; f.DataRow["Label"] = label; } } break; } return fs; }
/* [TestAttribute] public void Test2() { doTest(new String[]{ "LINESTRING(20 20, 20 100)", "LINESTRING (20 100, 20 180, 100 180)", "LINESTRING (100 180, 180 180, 180 100)", "LINESTRING (180 100, 180 20, 100 20)", "LINESTRING (100 20, 20 20)", "LINESTRING (100 20, 20 100)", "LINESTRING (20 100, 100 180)", "LINESTRING (100 180, 180 100)", "LINESTRING (180 100, 100 20)" }, new String[]{}); } */ private void DoTest(String[] inputWKT, String[] expectedOutputWKT) { var polygonizer = new Polygonizer(); polygonizer.Add(ToGeometries(inputWKT)); Compare(ToGeometries(expectedOutputWKT), polygonizer.GetPolygons()); }
public void IsPointInRingTest() { const string wkt1 = @"LINESTRING(159084.138183715 215384.465334836,159085.255551952 215382.299118879,159084.287081382 215380.125720536,159081.909029527 215380.063184668,159080.685184241 215382.030015885,159081.870080819 215384.260803017,159084.138183715 215384.465334836)"; const string wkt2 = @"LINESTRING(159081.417 215432.901,159081.484 215412.286,159069.343 215411.729,159063.929 215411.79,159063.765 215441.011,159055.84 215440.909,159055.756 215439.794,159050.254 215439.759,159050.231 215426.571,159029.91 215426.438,159029.894 215420.862,159028.749 215420.841,159028.787 215412.904,159050.376 215412.995,159050.394 215404.475,159051.839 215404.512,159051.721 215397.907,159050.448 215397.876,159050.48 215385.756,159037.29 215385.669,159037.274 215380.139,159036.129 215380.118,159036.18 215372.161,159050.58 215372.256,159050.641 215357.846,159061.806 215357.884,159061.764 215355.578,159063.703 215355.583,159063.834 215344.331,159062.797 215344.264,159062.878 215338.481,159063.885 215338.48,159063.94 215333.569,159062.002 215333.52,159062.061 215329.565,159063.973 215329.565,159064.019 215324.529,159063.008 215324.569,159062.948 215318.85,159064.078 215318.847,159064.229 215304.453,159074.999 215304.543,159074.895 215315.988,159082.789 215316.117,159082.751291265 215325.067329746,159076.257853729 215325.010585012,159076.145672787 215330.246673065,159077.726943351 215330.292687136,159077.64265916 215336.096838446,159075.46670601 215336.028874838,159075.17015073 215349.460814847,159091.770139291 215349.583804507,159091.835913025 215356.268745225,159114.649 215356.642,159114.529 215396.632,159109.671 215396.625,159109.501 215398.902,159112.021 215398.92,159111.982 215404.407,159112.999 215404.421,159113.001 215412.415,159095.019 215412.366,159094.928 215434.091,159086.987 215433.984,159086.928 215432.972,159081.417 215432.901)"; const string wkt3 = @"LINESTRING(159063.929280482 215399.247659686,159103.333615111 215398.947801304,159103.342074891 215397.380179598,159101.054815857 215397.403687265,159101.283398228 215370.145108237,159064.458615271 215370.009119945,159063.929280482 215399.247659686)"; var reader = new WKTReader(GeometryFactory.Fixed); var wkts = new[] { wkt1, wkt2, wkt3,}; var polygonizer = new Polygonizer(); foreach (var wkt in wkts) { var geom = (ILineString) reader.Read(wkt); Assert.IsNotNull(geom); Assert.IsTrue(geom.IsValid); Assert.AreEqual(geom.Factory.PrecisionModel, GeometryFactory.Fixed.PrecisionModel); polygonizer.Add(geom); } var polys = polygonizer.GetPolygons(); Console.WriteLine("Polygons formed (" + polys.Count + "):"); foreach (var obj in polys) { Assert.IsNotNull(obj); Console.WriteLine(obj); } }
private void CheckPolygonize(bool extractOnlyPolygonal, String[] inputWKT, String[] expectedWKT) { var polygonizer = new Polygonizer(extractOnlyPolygonal); polygonizer.Add(ReadList(inputWKT)); var expected = ReadList(expectedWKT); var actual = polygonizer.GetPolygons(); CheckEqual(expected, actual); }