漂泊雪狼的博客

思考,讨论,分享C#,JavaScript,.NET,Oracle,SQL Server……技术
posts - 159, comments - 284, trackbacks - 9, articles - 10

导航

公告

获取geometry边界范围的示例代码

Posted on 2018-03-08 14:15 漂泊雪狼 阅读(...) 评论(...) 编辑 收藏

根据sqlserver geometry数据定义获取空间类型边界范围

--获取指定街道边界的xy最大最小值
declare @point_cnt int,@i int,@point geometry,@jdcode nvarchar(50)

set @jdcode='440307006'--街道编码

create table #temp_point(id int identity,x float,y float)
select  @point_cnt =geom.STNumPoints()
from [dbo].[jd]
where jdcode=@jdcode

set @i=1
while @i<=@point_cnt
begin
    select @point = geom.STPointN(@i)
    from [dbo].[jd]
    where jdcode=@jdcode

    insert into #temp_point(x,y)
    values(@point.STX,@point.STY)
    set @i = @i+1
end

select min(x) as minx,min(y) as miny,max(x) as maxx,max(y) as maxy
from #temp_point

truncate table #temp_point;
drop table #temp_point