I have a column named geospacial_valid. Above is one row data example. The string mixed with string and number. How do I convert to a polygon type(shown below) in SQL Server.
I have not seen this datatype before.
Advertisement
Answer
That’s the Geography data type. You can just cast it to varchar, to see what it’s in it. Or query it on SQL Server Management Studio to see the result on a zoomable grid.
select cast(geospacial_valid as varchar(max)) as geospacial_text from yourtable
And the reverse can be done using the method STGeomFromText, and a WKT text
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;