[英]Extract Polygon Lat/Longs from Geometry Point
你可以像這樣使用一個小助手 function :
create or alter function GetGeometries(@geo geometry, @geometry_type varchar(200) = null)
returns @geometries table (i int primary key, geo geometry)
as
begin
declare @i int = 1;
while (1=1)
begin
declare @g geometry = @geo.STGeometryN(@i);
if @g is null break;
if (@geometry_type is null or @g.InstanceOf(@geometry_type)=1 )
begin
insert into @geometries(i,geo)values (@i, @g);
end
set @i += 1;
end
return;
end
go
create or alter function GetPoints(@geo geometry)
returns @geometries table (i int primary key, point geometry)
as
begin
declare @i int = 1;
while (1=1)
begin
declare @g geometry = @geo.STPointN(@i);
if @g is null break;
insert into @geometries(i,point)values (@i, @g);
set @i += 1;
end
return;
end
go
DECLARE @g geometry = 'GEOMETRYCOLLECTION(LINESTRING(1 1, 3 5),POLYGON((-1 -1, -1 -5, -5 -5, -5 -1, -1 -1)))';
SELECT g.i geometry_index, p.i point_index, p.point.STX X, p.point.STY Y
from dbo.GetGeometries(@g,'POLYGON') g
outer apply dbo.GetPoints(g.geo) p
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.