我正在寻找组合多个多边形以减少点数的方法。这将是前进的方向:
var pol1 = DbGeography.PolygonFromText("POLYGON ((-2.91790532309701 53.3657440952224, -2.91790532309701 53.3567508791632, -2.90283703655041 53.3567508791632, -2.9028338560513 53.3657440952224, -2.91790532309701 53.3657440952224))", 4326);
var pol2 = DbGeography.PolygonFromText("POLYGON ((-2.90283703655041 53.3657440952224, -2.90283703655041 53.3567508791632, -2.88776875000381 53.3567508791632, -2.88776556950469 53.3657440952224, -2.90283703655041 53.3657440952224))", 4326);
var pol3 = DbGeography.PolygonFromText("POLYGON ((-2.91641048851245 53.3747373112816, -2.91641048851245 53.3657440952224, -2.90133902146673 53.3657440952224, -2.90133583925323 53.3747373112816, -2.91641048851245 53.3747373112816))", 4326);
var combined = (pol1.Union(pol2)).Union(pol3);
基本上,如果多边形相互接触,我希望将它们组合起来。不相交的多边形应保持不相交。
目前我不确定Union是否与TSQL函数STUnion()达到相同的效果。
PS:我只是在TSQL中运行STUnion并注意到它也没有产生预期的结果(即联合包含组合多边形内的点)。
答案 0 :(得分:0)
这不是我看到的结果。
这是一个查询:
declare @pol1 Geography, @pol2 Geography
set @pol1 = Geography::STPolyFromText('POLYGON ((-2.91790532309701 53.3657440952224, -2.91790532309701 53.3567508791632, -2.90283703655041 53.3567508791632, -2.9028338560513 53.3657440952224, -2.91790532309701 53.3657440952224))', 4326);
set @pol2 = Geography::STPolyFromText('POLYGON ((-2.90283703655041 53.3657440952224, -2.90283703655041 53.3567508791632, -2.88776875000381 53.3567508791632, -2.88776556950469 53.3657440952224, -2.90283703655041 53.3657440952224))', 4326);
select @pol1.STUnion(@pol2)
结果如下:
如果从问题中添加@ pol3,则可能会看到接缝形式。尝试使用“几何图形”而不是“地理图形”运行查询,接缝将消失。我怀疑那是将其推出的大地之堡,因此,如果使用“地理”,您可能需要更多点才能“缝合在一起”。
(我实际上是想让它不加入,as described here。)