消除地理上的差距

时间:2015-12-02 14:19:43

标签: sql-server sql-server-2014 geography

我有一个由17个独立多边形组成的地理区域。 STNumGeometries()为它返回17。然而,在最大的多边形上,我可以看到多边形内的一些窄边界/裂缝/间隙。我似乎可以使用STBuffer隐藏它们(见下文),但几何数量会增加。如何在不使地理位置更复杂的情况下消除间隙?

select 
    myGeography.STNumGeometries() --Result: 17
    myGeography.STBuffer(+0.01).STBuffer(-0.01) --Result: I can no longer see lines within the largest polygon
    myGeography.STBuffer(+0.01).STBuffer(-0.01).STNumGeometries() --Result: 26

原始

Original Original zoomed

固定

Fixed Fixed zoomed

1 个答案:

答案 0 :(得分:0)

这是一种删除"戒指"的方法。来自地理区域非常小的区域。您可以通过修改Reduce()函数的参数来设置灵敏度。

use myDB;

SELECT 
    myTable.pk
,   geography::UnionAggregate(      --Union polygons into a single geography
        geography::STGeomFromWKB(   --Linestring --> polygon
            0x01 + 0x03000000 + 0x01000000 + SUBSTRING(myTable.myGeography.STGeometryN(geometryN.number).RingN(ringN.number).STAsBinary(),6,2147483647) 
        ,   myTable.myGeography.STSrid
        )  
    )                                           as  shapeClean
FROM    mySchema.myTable
    inner join master.dbo.spt_values    as  geometryN
        on  geometryN."type"    =   'P' --only integers
        and geometryN.number    between 1 and myTable.myGeography.STNumGeometries()  --Number of geometries
    inner join master.dbo.spt_values    as  ringN
        on  ringN."type"        =   'P' --only integers
        and ringN.number        between 1 and myTable.myGeography.STGeometryN(geometryN.number).NumRings()   --Number of rings
where   myTable.pk = 4722
    and myTable.myGeography.STGeometryN(geometryN.number).RingN(ringN.number).Reduce(0.1).STNumPoints()  >   2   --Keep only rings that have some area even after "reducing" slightly
group by     myTable.pk
;