簡體   English   中英

從幾何點提取多邊形緯度/經度

[英]Extract Polygon Lat/Longs from Geometry Point

讓我先聲明一下,我已經查看了我遇到的幾乎所有 Stackoverflow 問題,但我似乎找不到任何有效的方法。 我開始覺得我做錯了。

我有存儲在Geometry類型中的形狀。 在我的 WPF 應用程序中,形狀應如下所示 -

在此處輸入圖像描述

問題是我的很多幾何點都是GEOMETRYCOLLECTION 在我的應用程序中,我需要多邊形緯度/經度點。 幾何集合也包含線串,我不需要。 我只需要多邊形點。

例子 -

在此處輸入圖像描述

我有沒有辦法通過 SQL 服務器提取多邊形緯度/經度點? 我們以前使用過Geom.STConvexHull() function,但是我需要比它提供的更多的定義點。

你可以像這樣使用一個小助手 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM