Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 是否可以使用.NetTopologySuite将直线与多边形相交/剪裁?_C#_Asp.net_Asp.net Core_Gis_Nettopologysuite - Fatal编程技术网

C# 是否可以使用.NetTopologySuite将直线与多边形相交/剪裁?

C# 是否可以使用.NetTopologySuite将直线与多边形相交/剪裁?,c#,asp.net,asp.net-core,gis,nettopologysuite,C#,Asp.net,Asp.net Core,Gis,Nettopologysuite,我对线段与多边形相交有疑问。我有一些线(绿色)表示一些行走路径,一些限制多边形(黑色)表示多边形 您可以在下图中看到: 我现在想知道是否有可能提取多边形外部的线段(左上角的红线) 首先,我使用如下方式创建多边形: var vertices = new List<Coordinate>(); foreach (var trip in tripSegments.Data) { var newCoordinate

我对线段与多边形相交有疑问。我有一些线(绿色)表示一些行走路径,一些限制多边形(黑色)表示多边形

您可以在下图中看到:

我现在想知道是否有可能提取多边形外部的线段(左上角的红线)

首先,我使用如下方式创建多边形:

        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 geometryFactory=NtsGeometryServices.Instance.CreateGeometryFactory(srid:4326)

也有不同,但没有运气

var intersect = spatialData.FieldPolygon.Boundary.Difference(spatialData.TripLine);
还尝试了WKT Reader和交叉点与差异的组合(我想知道这是否是正确的方法):

但我得到了这样的错误(当使用WKT方法时)

更新

我已经用修复了WKT Reader的拓扑问题

var bufferPolygon = reader.Read(spatialData.FieldPolygon.Boundary.ToString());
在读卡器上,我添加了
Boundary
属性,并修复了拓扑问题。但从这里可以看出,主要问题仍然存在

我使用这段代码来提取不相交的线,这些线被添加到不同的层中,但正如您在红方块中看到的,有些线是绿色的,它们应该是紫色的(虚线),因为它们位于黑色多边形之外,但它们仍然是绿色的。

var outsideLines=new List();
foreach(几何体中的ILineString。几何体)
{                      
变量isIntersecting=lineString.Intersects(spatialData.FieldPolygon.Boundary);
如果(!isIntersecting)
{
外部线条。添加(线条字符串);
}  
}
spatialData.IntersectedMultiLine=geometryFactory.CreateMultiLineString(outsideLines.ToArray());

现在,我的主要问题是:是否可以提取多边形外部的线,并且我是否在正确的轨道上?

例外情况是,您的线字符串无效,并且如果数据无效,库无法处理dif或交点计算。您必须首先修复源数据(最有可能是自交线字符串),这是否回答了您的问题@谢谢你的评论。所以,如果我理解正确的话……如果我们忽略拓扑错误,上面的工作流程应该可以工作?。或者不可能用NetTopology套装提取多边形外部的线条。完全可以计算差异或交点,是的,在您的情况下,您基本上只需测试黑色多边形外部是否有线条的任何部分。@MichaC Ok,谢谢你…你可以发布一些链接或方法的例子,因为我没有找到任何。你可以把它贴出来作为答案,我会标记为有效。
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.Boundary.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 bufferPolygon = reader.Read(spatialData.FieldPolygon.Boundary.ToString());
                var outsideLines = new List<ILineString>();
                foreach (ILineString lineString in geometries.Geometries)
                {                      
                    var isIntersecting = lineString.Intersects(spatialData.FieldPolygon.Boundary);
                    if (!isIntersecting)
                    {
                        outsideLines.Add(lineString);
                    }  
                }
                spatialData.IntersectedMultiLine = geometryFactory.CreateMultiLineString(outsideLines.ToArray());