SQL 服务器地理空间数据类型转换
SQL Server geospatial data type conversion
我有一个名为 geospacial_valid 的列。以上是一行数据示例。字符串与数字混合。如何在 SQL Server.
中转换为多边形类型(如下所示)
我以前没见过这种数据类型。
那就是 Geography data type。您可以将其转换为 varchar,以查看其中的内容。或者在 SQL Server Management Studio 上查询它以在可缩放网格上查看结果。
select cast(geospacial_valid as varchar(max)) as geospacial_text
from yourtable
反过来可以使用方法 STGeomFromText 和 WKT 文本
select geography::STGeomFromText('LINESTRING(-54.58131719844993 -20.45660489081104,-54.58111516668011 -20.45626011843747,-54.58077717425282 -20.45629797598315,-54.58043210989845 -20.45624608494252,-54.58006804675164 -20.45605710601338,-54.57979694586932 -20.45559859144648,-54.57956697881578 -20.45544633843856,-54.57926463287518 -20.45543444657867,-54.57892335541956 -20.4556095564112,-54.57857366415873 -20.45551009035162,-54.57832720392111 -20.45505598280218,-54.57811952893173 -20.45478721734327,-54.57811148483986 -20.45440125813031,-54.57823707732479 -20.45436007710296,-54.57890072131422 -20.45426249664201,-54.57978607555457 -20.45433286264829,-54.58002818824167 -20.45424644022617,-54.58021461305431 -20.45396080506583,-54.58030464014957 -20.45353713162039,-54.58043848660239 -20.45344561076257,-54.58068343075388 -20.45344771080926,-54.58102235872894 -20.45372566908894,-54.58108724924297 -20.45400339908263,-54.58110296235578 -20.45442366920927,-54.58133764688335 -20.45479965526867,-54.58180482936485 -20.45514147909664,-54.58185396502873 -20.45538001658383,-54.58140336829726 -20.45607687660123,-54.58116574079844 -20.45623635869686,-54.58136236175516 -20.45658448017924)', 4674) as demo;
我有一个名为 geospacial_valid 的列。以上是一行数据示例。字符串与数字混合。如何在 SQL Server.
中转换为多边形类型(如下所示)我以前没见过这种数据类型。
那就是 Geography data type。您可以将其转换为 varchar,以查看其中的内容。或者在 SQL Server Management Studio 上查询它以在可缩放网格上查看结果。
select cast(geospacial_valid as varchar(max)) as geospacial_text
from yourtable
反过来可以使用方法 STGeomFromText 和 WKT 文本
select geography::STGeomFromText('LINESTRING(-54.58131719844993 -20.45660489081104,-54.58111516668011 -20.45626011843747,-54.58077717425282 -20.45629797598315,-54.58043210989845 -20.45624608494252,-54.58006804675164 -20.45605710601338,-54.57979694586932 -20.45559859144648,-54.57956697881578 -20.45544633843856,-54.57926463287518 -20.45543444657867,-54.57892335541956 -20.4556095564112,-54.57857366415873 -20.45551009035162,-54.57832720392111 -20.45505598280218,-54.57811952893173 -20.45478721734327,-54.57811148483986 -20.45440125813031,-54.57823707732479 -20.45436007710296,-54.57890072131422 -20.45426249664201,-54.57978607555457 -20.45433286264829,-54.58002818824167 -20.45424644022617,-54.58021461305431 -20.45396080506583,-54.58030464014957 -20.45353713162039,-54.58043848660239 -20.45344561076257,-54.58068343075388 -20.45344771080926,-54.58102235872894 -20.45372566908894,-54.58108724924297 -20.45400339908263,-54.58110296235578 -20.45442366920927,-54.58133764688335 -20.45479965526867,-54.58180482936485 -20.45514147909664,-54.58185396502873 -20.45538001658383,-54.58140336829726 -20.45607687660123,-54.58116574079844 -20.45623635869686,-54.58136236175516 -20.45658448017924)', 4674) as demo;