[英]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.