这个问题是关于this问题的概括。上述问题适用于没有漏洞的点。在本问题中,我想得到近似规则网格点的子集的周界(外边界),其中多边形中的一些网格点缺失(即,带孔的多边形)。
网格上的示例数据集可用here。
我在上面提到的问题中使用了R代码作为答案(没有漏洞)。
现在我希望它忽略点集内部的洞,并且想要将点集的外边界视为所需的多边形。
任何建议!!感谢。
答案 0 :(得分:1)
如果在找到所有循环并且仅使用具有最大X坐标的循环(必须是外部循环)之前存在漏洞,那么我之前的代码上的这个轻微变体就可以工作。除非循环接触......严格来说也许它应该采用最大面积的循环...还要注意,由于igraph包中的一个错误(我已经报道),需要在其中一个函数中使用X和Y.
declare @Table1 table (pk int identity(1,1) primary key, i int, j int, k int)
declare @Table2 table (pk int identity(1,1) primary key, i int, j int, k int)
insert into @Table1
values(1, 2, 3), (3, 1, 2), (4, 5, 6), (9,9,9)
insert into @Table2
values (2, 1, 3), (6, 4, 5)
--since the order is unimportant, concatenate the columns into a sorted array
--note how 1,2,3 and 3,1,2 both result in the same compare value:
select *
from @Table1 o
cross
apply ( select cast(value as varchar) + '/'
from @Table1
unpivot (value for c in (i,j,k)) as u
where pk = o.pk
order
by value
for xml path('')
)d(compare)
--now, bring in the 2nd table
select [src] = 1, pk, compare
from @Table1 o
cross
apply ( select cast(value as varchar) + '/'
from @Table1
unpivot (value for c in (i,j,k)) as u
where pk = o.pk
order
by value
for xml path('')
)d(compare)
union all
select [src] = 2, pk, compare
from @Table2 o
cross
apply ( select cast(value as varchar) + '/'
from @Table2
unpivot (value for c in (i,j,k)) as u
where pk = o.pk
order
by value
for xml path('')
)d(compare)
--now just group them to find the matching rows
select min(src), min(pk), compare
from (
select [src] = 1, pk, compare
from @Table1 o
cross
apply ( select cast(value as varchar) + '/'
from @Table1
unpivot (value for c in (i,j,k)) as u
where pk = o.pk
order
by value
for xml path('')
)d(compare)
union all
select [src] = 2, pk, compare
from @Table2 o
cross
apply ( select cast(value as varchar) + '/'
from @Table2
unpivot (value for c in (i,j,k)) as u
where pk = o.pk
order
by value
for xml path('')
)d(compare)
)grouped
group
by compare
having count(*) > 1;