0

我在 SQL Server 2008 R2 中有一些表。

我想创建视图以在 Geoserver 上发布它。但我对几何有疑问。我有线段的几何形状。例如,来自同一行的这些段:

0xE610000001040C000000F01472A59E5A524032C7F2AE7AAA4E40AC1E300F995A52403C889D2974AA4E408C666
5FB905A5240213F1BB96EAA4E406A12BC218D5A5240B7F0BC546CAA4E404A404CC2855A5240ACAA97DF69AA4E40
4E2A1A6B7F5A5240D7A546E867AA4E402B85402E715A5240BAC0E5B166AA4E400EA0DFF76F5A52405AB8ACC266A
A4E402E3883BF5F5A5240D7A546E867AA4E403AE63C635F5A5240D7A546E867AA4E40043A9336555A5240D2393F
C571AA4E405CCCCF0D4D5A5240A75B76887FAA4E4001000000010000000001000000FFFFFFFF0000000002

0xE610000001040A000000F01472A59E5A524032C7F2AE7AAA4E4011C47938815A52401DE4F56052AA4E40145D1
77E705A52401364045438AA4E404B00FE29555A5240DE74CB0EF1A94E4059130B7C455A5240FED2A23EC9A94E40
C9B08A37325A52407444BE4BA9A94E402B323A20095A524049D576137CA94E408B1A4CC3F0595240342C465D6BA
94E40E0F3C308E1595240F487669E5CA94E40B169A510C8595240CBBA7F2C44A94E400100000001000000000100
0000FFFFFFFF0000000002

要选择段,我使用此查询:

SELECT  

    Segment_ID = Segment_ID.Segment_ID,
    GEOMETRY::STGeomFromText(Track.Track.STAsText(),4326) as the_geom,
    Road.Name as Road_Name,
    Road.Road_ID as Road_Id



FROM dbo.Road
LEFT JOIN Segment_ID  ON Road.Road_ID = Segment_ID.Road_ID
LEFT JOIN Track ON Segment_ID.Segment_ID = Track.Segment_ID

是否可以在单个查询中将段连接到一个功能中?

更新

我找到了函数STUnion,但不知道如何在单个查询中使用它来连接段。

更新2

我想我会谈谈表结构。我有 3 张桌子:

追踪

Segment_ID(character),
Track (geometry)

Segment_ID

Segment_ID(character),
Road_ID(character)

Road_ID(character),
Road_Name(character)

在查询结果中,我想获得 Road_Name 和该道路的单个要素中连接的所有路段。
但仍然不能写不能查询(

更新3

答案中的解决方案有效,但需要很多时间。我的意思是当我按下执行查询时,我会在 2 秒内得到结果,但查询仍然工作大约 5 分钟。它可以使它更快。Bercouse 我从此查询创建视图并将其添加到 Geoserver 但我无法在图层预览中获取图层,因为出现超时错误。

我看到了一些有趣的东西。在 table Road 我有 76 行。当我按下执行查询时,我得到 75 行,5 分钟后我得到所有 76 行。所以最后一次迭代的问题。有什么问题?

4

1 回答 1

1

STUnion 确实是您的救赎之路(哈!)。STUnion 是几何和地理 CLR 类型的一种方法。您通常将其调用为gInstance.STUnion(othergInstance). 也就是说,假设您上面的查询生成了适当的几何实例,这个递归 CTE 解决方案应该可以工作:

with by_segment as (
SELECT  
    Road.Road_Id,
    GEOMETRY::STGeomFromText(Track.Track.STAsText(),4326) as the_geom,
    row_number() over (partition by Road.road_id order by Road.Segment_Id) as [rn],
    count(*) over (partition by Road.road_id) as [c]
FROM dbo.Road
LEFT JOIN Segment_ID  ON Road.Road_ID = Segment_ID.Road_ID
LEFT JOIN Track ON Segment_ID.Segment_ID = Track.Segment_ID
),
roads_by_segment as (
select 
   road_id,
   the_geom,
   [rn],
   [c]
from by_segment
where [rn] = 1

union all

select 
   [a].road_id,
   [a].the_geom.STUnion([b].the_geom),
   [b].[rn],
   [b].[c]
from by_segment as [a]
inner join roads_by_segment as [b]
   on [a].Road_ID = b.Road_ID
   and [a].[rn] = [b].[rn]+1
)

select * from roads_by_segment where [rn] = [c]
于 2013-02-19T03:57:02.263 回答