【问题标题】:Transforming Individual Polygon Node Co-ordinates SQL Server 2008 (Spatial Geography)转换单个多边形节点坐标 SQL Server 2008(空间地理)
【发布时间】:2015-12-22 03:24:58
【问题描述】:

我在 SQL Server 2008 中以地理类型存储了一组多边形。我的目标是将这些多边形的坐标转换为不同的投影。

我有一个可以转换一组坐标的存储过程,但这只能转换同时具有 X 和 Y 值的单个点。

使用 WKT,我从多边形中提取了单个节点,然后我想单独转换每个节点。然后我可以用我的新转换坐标重建 WKT。

有没有人知道一种方法来解析每个单独的节点,以便我可以一个一个地转换它们?我的节点字符串如下所示(单个点用逗号分隔,空格分隔 x 和 y 值):

POLYGON((113.26456971466541 23.094733481094721,113.26615758240223 23.091891178768353,113.27456898987293 23.095562474614567,113.27557750046253 23.093292599234712,113.27634997665882 23.09356893393959,113.27379651367664 23.099440912063049,113.27501960098743 23.102179435943992,113.27381797134876 23.103023186104451,113.27116794884205 23.100940939266334,113.27231593430042 23.098562598885763,113.27319569885731 23.096588840457258,113.26798148453236 23.0943781965919,113.26761670410633 23.095024616306429,113.26671548187733 23.094624922040744,113.26613612473011 23.095503260961348 , 113.26456971466541 23.094733481094721))

【问题讨论】:

  • 您是否在寻求一种将众所周知的文本转换为一系列单独点的方法?
  • 您好,感谢您的回复。不完全是。我想使用我的存储过程来转换上面列出的所有单个点(我从 WKT 中提取的)。我正在使用存储过程来转换这些点,但我需要一种方法来解析这些点并逐个转换它们。
  • 那么您需要帮助将其从多点的单条记录转换为每条记录 1 点的 n 条记录吗?

标签: sql-server-2008 loops parsing polygon spatial


【解决方案1】:

我看起来像一个 SQL 游标和一个 while 循环来解开多边形中的点是你所要求的

CREATE PROCEDURE [dbo].[ReprojectPolygons]

AS
 DECLARE geography_cursor CURSOR
 FOR SELECT id, data FROM [MyPolygons] -- where [data] column contains geography data

 -- variables to store data cursor points to
 DECLARE @id INTEGER
 DECLARE @data sys.geography

 -- variables to loop through points in polygon
 DECLARE @pointcount INTEGER
 DECLARE @pointindex INTEGER
 DECLARE @point sys.geography

 -- result WKT from your reprojection
 DECLARE @result VARCHAR(MAX)

 OPEN geography_cursor

 FETCH NEXT FROM geography_cursor 
 INTO @id, @data

 -- loop through polygons    
 WHILE @@FETCH_STATUS = 0
 BEGIN
    SET @pointcount = @data.STNumPoints()
    SET @pointindex = 1 
    SET @result = ''
    -- iterate points in polygon
    WHILE @pointindex <= @pointcount
    BEGIN
        SET @point = @data.STPointN(@pointindex)
        -- process point reprojection here by calling your stored procedure
        -- assuming you're passing the point as an OUTPUT parameter, this example continues using @point as the reprojected value
        if(@pointindex > 1)
            SET @result = @result + ','
        SET @result = @result + CONVERT(VARCHAR, @point.Long) + ' ' + CONVERT(VARCHAR, @point.Lat)
        SET @pointindex = @pointindex + 1
    END
    SET @result = 'POLYGON((' + @result + '))'
    -- do something with reprojected polygon WKT in @result
    FETCH NEXT FROM geography_cursor 
    INTO @id, @data
 END
 CLOSE geography_cursor
 DEALLOCATE geography_cursor
RETURN 0

【讨论】:

    猜你喜欢
    • 2018-09-08
    • 2017-02-18
    • 2021-08-24
    • 1970-01-01
    • 2016-04-15
    • 1970-01-01
    • 1970-01-01
    • 2012-06-18
    • 1970-01-01
    相关资源
    最近更新 更多