我有一个Shapefile(* .shp),我将其加载到数据库中。我有一个名为Point的列,它将数据存储在形状中。例如
POLYGON ((1543297.7815 5169880.9468, 1543236.7046 5169848.3834,
1543195.0218 5169930.2767, 1543104.4989 5170101.6818,
1543056.805 5170191.9835, 1542969.1187 5170358.1396,
1542820.9656 5170638.8525, 1542820.6605 5170639.7223,
1542816.1912 5170647.8707, 1543158.2618 5170829.6437,
1543318.4126 5170915.6562, 1543559.2078 5171043.8001,
1543840.2014 5171192.4698, 1544108.917 5171336.1306,
1544271.7972 5171422.313, 1544357.0262 5171263.5454,
1544447.9779 5171091.3804, 1544468.04 5171054.3179,
1544529.7931 5170936.192, 1544583.3416 5170837.5321,
1544658.3376 5170696.5608, 1544699.0638 5170622.0859,
1543985.6169 5170245.4526, 1543618.4129 5170050.7422,
1543297.7815 5169880.9468))
“Point”列的数据类型为nvarchar(max)
。
问题是当Polygon的大小超过时,列会截断并且不会存储所有值。我无法将点转换为几何,因为我想将点转换为从多边形转换为纬度/长度。
答案 0 :(得分:3)
我建议将整个多边形存储为几何类型。如果/当您需要将其“转换”为地理位置时,请使用地理方法STNumPoints和STPointN按顺序提取各个点并根据需要进行转换。
说到转换,您现在的数据格式是什么?我没有看到拉/长信息,但也许我错过了什么。
编辑:这是我刚刚编写的解决方案。
use tempdb;
create table tally (i int not null);
with
a as (select 1 as [i] union select 0),
b as (select 1 as [i] from a as [a1] cross join a as [a2]),
c as (select 1 as [i] from b as [a1] cross join b as [a2]),
d as (select 1 as [i] from c as [a1] cross join c as [a2]),
e as (select 1 as [i] from d as [a1] cross join d as [a2])
insert into tally
select row_number() over (order by i) from e
create unique clustered index [CI_Tally] on tally (i)
create table ace (g geometry)
insert into ace (g)
values (geometry::STGeomFromText(<<your polygon string here>>, 0));
select i, g.STPointN(t.i), g.STPointN(t.i).STAsText()
from ace as [a]
cross join tally as [t]
where t.i <= g.STNumPoints()