First, I created polygon using something like this:
var geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: 4326);
var vertices = new List<Coordinate>();
foreach (var coords in stringPolygon)
{
var coordinates = coords.Split(",");
var x = double.Parse(coordinates[0]);
var y = double.Parse(coordinates[1]);
var newCoordinate = new Coordinate(y,x);
vertices.Add(newCoordinate);
}
var outerRing = geometryFactory.CreateLinearRing(vertices.ToArray());
spatialData.FieldPolygon = geometryFactory.CreatePolygon(outerRing);
var vertices = new List<Coordinate>();
foreach (var trip in tripSegments.Data)
{
var newCoordinate = new Coordinate(trip.Lng, trip.Lat);
vertices.Add(newCoordinate);
}
spatialData.TripLine = geometryFactory.CreateLineString(vertices.ToArray());
var intersect = spatialData.FieldPolygon.Boundary.Intersection(spatialData.TripLine);
var intersect = spatialData.FieldPolygon.Boundary.Difference(spatialData.TripLine);
var reader = new WKTReader();
var targetMultiPolygon = reader.Read(spatialData.TripLine.ToString());
var bufferPolygon = reader.Read(spatialData.FieldPolygon.ToString());
var intersection = targetMultiPolygon.Intersection(bufferPolygon);
var targetClipped = targetMultiPolygon.Difference(intersection);
var wktTargetAfterClip = targetClipped.ToString();
TopologyException: found non-noded intersection between LINESTRING(26.563827556466403 43.52431484490672, 26.56386783617048 43.52429417990681) and LINESTRING(26.565492785081837 43.52349421574761, 26.56386783617048 43.52429417990681) [ (26.56386783617048, 43.52429417990681, NaN) ]
var gf = new GeometryFactory(new PrecisionModel(1e6));
var reader = new WKTReader(gf);
Von: nettopol...@googlegroups.com <nettopol...@googlegroups.com>
Im Auftrag von Neven
Gesendet: Mittwoch, 10. Juni 2020 09:04
An: NetTopologySuite <nettopol...@googlegroups.com>
Betreff: Re: Is it possible to intersect/clip line with polygon?
@FOber,aier can you please explain what dou you mean by
Create your WKTReader using a GeometryFactory with a scaled precision model. Could you provide me some example if it is possible?
Dana petak, 22. svibnja 2020. u 14:18:17 UTC+2, korisnik Neven napisao je:
Hi all. I have question regarding intersecting line segment with polygon. I have some line (green) that represents some walking path and some restriction polygon (black) that represents polygon.
You can see in image below:
I'm now wondering if it is possible to extract line segments that are outside polygon (red lines)
Something like this (red lines in upper left corner)
--
You received this message because you are subscribed to the Google Groups "NetTopologySuite" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
nettopologysui...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/nettopologysuite/cd1b763d-b16e-4e07-8f84-a5b34e4a8d50o%40googlegroups.com.