NetTopologySuite : Detect Boundary from Intersecting linestrings

27 views
Skip to first unread message

Harilal

unread,
Jan 1, 2023, 10:44:35 AM1/1/23
to NetTopologySuite
I have three LineStrings as shown in the picture attached. I want to extract the enclosed area  formed by the intersection of these lines, as a single LinearRing. Could someone kindly give a clue on how to do this?
ExtractPolygon.png

FObermaier

unread,
Jan 2, 2023, 3:12:10 AM1/2/23
to NetTopologySuite
This is the way to go:

// sample geometries
var rdr = new WKTReader();
var geoms = new[] {rdr.Read("LINESTRING (0 0, 20 0)"),
    rdr.Read("LINESTRING (20 -5, 9 15)"),
    rdr.Read("LINESTRING (11 15, 0 -5)")};

// node the geometries by performing a union
var geom = OverlayNGRobust.Union(geoms);

// create a polygonizer, add noded boundary lines
var polygonizer = new Polygonizer();
polygonizer.Add(LineStringExtracter.GetLines(geom));

// Get the polygon
var polys = polygonizer.GetPolygons();
Reply all
Reply to author
Forward
0 new messages