SQL 服务器多边形格式
SQL Server Polygon format
SELECT TOP 1 KMLLocation FROM Polygon
结果:0xE61000000104210000004ACE893DB4BF19403EB2B96A9EFF534082919735B1C0194039807EDFBFFF534052F17F4754C81940976F7D586F0054405AD76839D0D31940AED3484BE50054409E961FB8CAD3194087BF266BD40054403F90BC7328D3194071C806D2C5005440844A5CC7B8D21940E4D70FB1C100544014CE6E2D93D1194062BF27D6A90054404FB2D5E594D01940E27668588C005440E910381268D01940E7E26F7B820054409AEAC9FCA3CF1940A54E4013610054409432A9A10DD01940CD902A8A5700544015E126A3CAD01940FE0E45813E0054407FBDC282FBD11940C30DF8FC30005440EB1B98DC28D2194038312427130054403065E08096CE19404A7CEE04FBFF534082035ABA82CD1940C2F7FE06EDFF5340462234828DCB19409373620FEDFF534031B2648EE5CD1940E338F06AB9FF5340CFDC43C2F7CE1940321EA5129EFF5340B98C9B1A68CE194055A3570394FF5340A8E15B5837CE1940639CBF0985FF53403868AF3E1ECA1940001FBC7669FF534029CB10C7BAC81940ED9C668176FF5340C6DB4AAFCDC61940AD18AE0E80FF534047CCECF318C51940F390291F82FF5340EDB776A224C41940FD851E317AFF5340E4F90CA837C31940C440D7BE80FF5340DF1AD82AC1C21940462234828DFF53409C69C2F693C1194007D2C5A695FF5340C5387F130AC119406AFB57569AFF5340D1E7A38CB8C01940574277499CFF53404ACE893DB4BF19403EB2B96A9EFF534001000000020000000001000000FFFFFFFF0000000003
SELECT TOP 1 KMLLocation .ToString() FROM Polygon
结果:
POLYGON ((79.994044 6.437211, 79.996086 6.438176, 80.006796 6.445634, 80.013995 6.456849...
预期结果:
POLYGON ((6.437211 79.994044, 6.438176 79.996086, 6.445634 80.006796, 6.456849, 80.013995...
如何从地理多边形交换纬度和经度?
这是我想出的:
DECLARE @g GEOGRAPHY = /* your hex representation from above */
@new VARCHAR(MAX);
WITH points AS (
SELECT @g.STPointN(n.n) AS p, n
FROM tempdb.dbo.Numbers AS n
WHERE n <= @g.STNumPoints()
)
SELECT @new = CONCAT('POLYGON((', (
SELECT STRING_AGG(CONCAT(p.Lat, ' ', p.Long), ',') WITHIN GROUP (ORDER BY p.n)
FROM points AS p
), '))')
SELECT geography::STGeomFromText(@new, @g.STSrid).ReorientObject();
这很简单。我正在创建一个通用 table 表达式 (CTE),以使用数字(或计数)table 将现有多边形分解为其组成角。所有这一切都是 table 一列,整数从 1 到某个大数。这对这种情况很有帮助。从那里开始,我交换点的纬度和经度,然后将它们重新组装到多边形的 WKT 中。最后,我正在从 WKT 创建一个实际的地理实例。注意 - 我打电话给 ReorientObject()
是因为新的多边形似乎遇到了环形方向问题,因为它定义了整个地球,其中有一个小孔(多边形的形状)。
SELECT TOP 1 KMLLocation FROM Polygon
结果:0xE61000000104210000004ACE893DB4BF19403EB2B96A9EFF534082919735B1C0194039807EDFBFFF534052F17F4754C81940976F7D586F0054405AD76839D0D31940AED3484BE50054409E961FB8CAD3194087BF266BD40054403F90BC7328D3194071C806D2C5005440844A5CC7B8D21940E4D70FB1C100544014CE6E2D93D1194062BF27D6A90054404FB2D5E594D01940E27668588C005440E910381268D01940E7E26F7B820054409AEAC9FCA3CF1940A54E4013610054409432A9A10DD01940CD902A8A5700544015E126A3CAD01940FE0E45813E0054407FBDC282FBD11940C30DF8FC30005440EB1B98DC28D2194038312427130054403065E08096CE19404A7CEE04FBFF534082035ABA82CD1940C2F7FE06EDFF5340462234828DCB19409373620FEDFF534031B2648EE5CD1940E338F06AB9FF5340CFDC43C2F7CE1940321EA5129EFF5340B98C9B1A68CE194055A3570394FF5340A8E15B5837CE1940639CBF0985FF53403868AF3E1ECA1940001FBC7669FF534029CB10C7BAC81940ED9C668176FF5340C6DB4AAFCDC61940AD18AE0E80FF534047CCECF318C51940F390291F82FF5340EDB776A224C41940FD851E317AFF5340E4F90CA837C31940C440D7BE80FF5340DF1AD82AC1C21940462234828DFF53409C69C2F693C1194007D2C5A695FF5340C5387F130AC119406AFB57569AFF5340D1E7A38CB8C01940574277499CFF53404ACE893DB4BF19403EB2B96A9EFF534001000000020000000001000000FFFFFFFF0000000003
SELECT TOP 1 KMLLocation .ToString() FROM Polygon
结果:
POLYGON ((79.994044 6.437211, 79.996086 6.438176, 80.006796 6.445634, 80.013995 6.456849...
预期结果:
POLYGON ((6.437211 79.994044, 6.438176 79.996086, 6.445634 80.006796, 6.456849, 80.013995...
如何从地理多边形交换纬度和经度?
这是我想出的:
DECLARE @g GEOGRAPHY = /* your hex representation from above */
@new VARCHAR(MAX);
WITH points AS (
SELECT @g.STPointN(n.n) AS p, n
FROM tempdb.dbo.Numbers AS n
WHERE n <= @g.STNumPoints()
)
SELECT @new = CONCAT('POLYGON((', (
SELECT STRING_AGG(CONCAT(p.Lat, ' ', p.Long), ',') WITHIN GROUP (ORDER BY p.n)
FROM points AS p
), '))')
SELECT geography::STGeomFromText(@new, @g.STSrid).ReorientObject();
这很简单。我正在创建一个通用 table 表达式 (CTE),以使用数字(或计数)table 将现有多边形分解为其组成角。所有这一切都是 table 一列,整数从 1 到某个大数。这对这种情况很有帮助。从那里开始,我交换点的纬度和经度,然后将它们重新组装到多边形的 WKT 中。最后,我正在从 WKT 创建一个实际的地理实例。注意 - 我打电话给 ReorientObject()
是因为新的多边形似乎遇到了环形方向问题,因为它定义了整个地球,其中有一个小孔(多边形的形状)。