无法在 SQL Server 中将 GEOMETRY 转换为 GEOGRAPHY

问题描述 投票:0回答:1

我在 SQL 中有 1000 个 GEOMETRY 形状,我想将它们即时转换为 GEOGRAPHY,但我很难做到这一点。到目前为止,已使用此示例多边形尝试过此代码,但它不会转换,有人可以帮忙吗?为英国创建的多边形的空间索引为 27700。

我看过其他示例,但似乎没有任何效果。

DECLARE @geom GEOMETRY = GEOMETRY::STGeomFromText('POLYGON ((504054.23767468269 190071.72173089156, 505813.11129655468 185472.8035423081, 503685.54075405968 175355.9981328373, 507253.77978382393 174216.25938161451, 507489.74964891712 172164.33598178398, 512053.64872956288 170507.53072195337, 512235.06355625519 169174.58426819154, 517279.41365762183 167400.16799258033, 516682.21395118721 159943.25024809066, 522341.16424903134 166036.59936337324, 524330.77126607031 162256.27646162518, 523560.981423564 161153.45304210181, 525761.223679451 162064.65506047735, 528183.38976260694 160641.28638215654, 528804.942998553 157430.82825067663, 531009.08508161048 155871.24439688114, 536880.04694983736 161805.58071599656, 539708.2543248646 160817.26427053183, 540708.25309913908 156687.706208831, 541907.89132032567 158471.89839944438, 542615.167033463 156839.11281826871, 545632.79666787141 156969.71905623408, 545513.98954904068 159519.30155310372, 549984.10962378886 165475.63902978919, 550075.9449814473 172434.70595853234, 553300.05589681759 175140.44664343144, 555426.96334860369 182441.398546184, 562071.2036211309 185005.45425784116, 554138.66561618762 194913.98157619208, 543758.01318548992 191595.58909580507, 540172.93112553644 195552.09929559036, 537736.96637033508 196054.3598052563, 537714.67473160767 199909.09250794561, 531254.8891526002 200949.73740318842, 527157.01893182076 200439.45619117847, 520791.79263801157 195132.22247772769, 516688.84480769577 194891.7095061373, 511025.60892158444 191745.7825997594, 507035.26809888578 191536.1737523356, 504219.57552253146 193633.94495181396, 504054.23767468269 190071.72173089156))', 27700)

select GEOGRAPHY::STPolyFromText(@geom.STAsText(), 4326)
select GEOGRAPHY::STPolyFromWKB(@geom.STAsBinary(), 4326)
select GEOGRAPHY::STGeomFromWKB(@geom.STAsBinary(), 4326)

我收到的错误消息是

Msg 6522, Level 16, State 1, Line 3
A .NET Framework error occurred during execution of user-defined routine or aggregate "geography": 
System.FormatException: 24201: Latitude values must be between -90 and 90 degrees.
System.FormatException: 
   at Microsoft.SqlServer.Types.GeographyValidator.ValidatePoint(Double x, Double y, Nullable`1 z, Nullable`1 m)
   at Microsoft.SqlServer.Types.Validator.BeginFigure(Double x, Double y, Nullable`1 z, Nullable`1 m)
   at Microsoft.SqlServer.Types.ForwardingGeoDataSink.BeginFigure(Double x, Double y, Nullable`1 z, Nullable`1 m)
   at Microsoft.SqlServer.Types.CoordinateReversingGeoDataSink.BeginFigure(Double x, Double y, Nullable`1 z, Nullable`1 m)
   at Microsoft.SqlServer.Types.WellKnownTextReader.ParseLineStringText()
   at Microsoft.SqlServer.Types.WellKnownTextReader.ParsePolygonText()
   at Microsoft.SqlServer.Types.WellKnownTextReader.ParseTaggedText(OpenGisType type)
   at Microsoft.SqlServer.Types.WellKnownTextReader.Read(OpenGisType type, Int32 srid)
   at Microsoft.SqlServer.Types.SqlGeography.ParseText(OpenGisType type, SqlChars taggedText, Int32 srid)
   at Microsoft.SqlServer.Types.SqlGeography.GeographyFromText(OpenGisType type, SqlChars taggedText, Int32 srid)

我还有一些其他形状的例子,有些不是多边形,但我想一旦我破解了一个,它们都会起作用

MULTIPOLYGON (((540887.321028966 339564.10319703317, 542305.85513866891 339918.95561415743, 542950.753968176 340420.58527888521, 540887.321028966 339564.10319703317)), ((455368.21978374536 231321.45830771606, 459632.59803489666 233587.49464571389, 460415.80290818639 238920.27463369505, 466924.92344200989 241126.39344343415, 465855.42338718585 242191.65867795178, 470950.17143440741 241924.96853891684, 472025.29344736005 243122.19421296916, 475105.21360300307 236570.66458759736, 477206.94655983621 237455.45455576165, 478170.16538084461 240917.52952839254, 480304.51470912737 242188.48623564112, 476413.29281243589 246823.49224858778, 476822.30270833021 248173.48989548691, 480148.8139291121 248778.69075948637, 483786.12609902333 253012.35359712987, 491238.66266148846 256065.66012406541, 493276.89782885526 259695.75473988708, 492500.52421487815 264544.59527421487, 495519.06339551415 265461.68320649461, 498112.74071065383 262698.96945325634, 499832.72757759766 263107.91143868893, 501097.69180309412 269905.75197135244, 504840.21049792855 270770.1365927938, 502582.88156968961 276816.11200124933, 506823.55941150966 278719.402162085, 511536.88825301465 283021.75896481832, 512866.95168578508 286770.47525739262, 511900.25939450908 291150.25875891023, 507831.31801673851 293194.30406430742, 507581.21417343611 299094.25772302313, 503294.63559274731 298434.69908929453, 501987.49794822308 299876.96023300115, 503722.50357380416 303374.73910083895, 502749.41389128106 306488.60399855347, 508067.26329756831 306818.98397958762, 512782.32350031275 309909.92762521637, 517872.87270540075 307419.33730138023, 521519.78310778382 309363.03243744915, 522453.97923067538 307646.14093650162, 525961.162972183 307631.73099502461, 531122.74526872288 310408.61432555341, 533357.88411723485 308944.14375250967, 536886.97905347077 309403.7903973654, 538712.58572335413 311346.29234471556, 538292.04597572 314964.69762953627, 539566.29251567123 316449.25207895966, 547825.00534199085 317578.95405668369, 553492.04634626745 321924.8097573581, 551621.64236670826 323170.75736001914, 553365.35073652258 327646.04429603176, 549639.5428979086 327976.3895209746, 548981.495611914 334260.48694608925, 546306.514676103 337447.74598643515, 547891.59093466366 338351.54150368425, 548604.16156749078 337025.29217524815, 548404.74958779814 339417.56224347424, 545273.29274144873 336878.9896866476, 544887.05674643768 338351.05224889913, 543272.67449875979 337486.26004503685, 549470.77378502244 342262.86810667493, 548966.82670208858 343783.44253345532, 547381.753789668 343822.25135845831, 541946.63071630138 337109.93093163904, 541013.424653073 336700.58627462632, 543410.00421450718 340195.163261014, 542305.85513866891 339918.95561415743, 536544.03095180728 335437.16435817815, 548009.63172900549 347590.16649661533, 549981.24913130119 347057.79312288488, 554891.67957382556 350517.35949513485, 557629.091540157 359783.31039400614, 557712.37654751714 368524.23769419017, 555528.85501777427 376666.10385517223, 548739.57461437257 392680.23481640528, 543091.46351712069 401794.53334770643, 534687.73366263637 406097.4659201944, 531841.75510988454 403955.0409492873, 528757.01408685173 404346.8929831165, 525808.07091377466 398724.88245812134, 527564.059138964 396688.65436062857, 524312.21527980547 394907.38757967437, 522776.03473869665 398179.52923827077, 518939.523437955 400376.18658211245, 518195.26068253792 405513.75555697759, 519962.46844905661 409550.19915785326, 517919.54598373995 409448.89429665642, 512600.87413787213 414703.7888474685, 510435.11337942246 408222.8867919934, 504231.43825086445 409851.6925222525, 499577.11055179656 405732.45389921009, 504190.32089412573 406713.24479718896, 505717.889172567 405163.36195191077, 505957.5030770803 403555.58384482248, 500463.59654333885 402015.93445615919, 501638.41250552965 398703.16299929307, 491186.557949591 396637.17402166652, 491418.7037437231 402720.84308182716, 483771.6674133187 403369.34661076765, 480054.82871130871 396085.46124336048, 472158.96116029716 396541.13968292618, 473181.1786396582 398210.51233812957, 470806.33417017775 401219.35165393539, 467510.85347067483 397738.98587004497, 465697.34050690744 392663.83516460494, 461304.35864783294 392668.95017273939, 458962.58634394611 390467.41589769121, 457538.61056485935 384725.68099557294, 455934.93493695464 384810.80181536474, 457546.2074406895 383109.50525106495, 453295.92332793697 378925.05660426489, 448040.34909054171 379452.43301804748, 446417.37909796834 382141.23600528529, 444319.44074524706 380127.2278283576, 441053.6833409883 380296.65992953815, 439412.71241555235 382993.4616758381, 430902.95657658827 378763.02677094896, 427848.43405213795 380642.04747743078, 424963.38162544748 380044.53730555222, 427456.80175014841 383347.24310230522, 422652.57667162124 385564.40083182213, 423166.14663611539 388557.73242064036, 417036.88227636507 392211.06238144293, 417108.10915409343 396228.9054030379, 413371.50573505921 398316.34202802472, 413408.02307591407 401697.51711433206, 408579.60004866641 404918.98827027727, 406034.91791365267 404648.47519987385, 405370.03405841265 401523.4273904594, 402079.56875039177 400896.46974866209, 401138.24664298561 395431.37446486688, 398375.73061324144 392884.40263405128, 400704.58291363285 390976.97949114454, 397923.29718620621 385711.63196191349, 399743.05346575461 384232.0392913681, 399565.79396347771 373777.98903085268, 401875.03588609997 370463.11471003504, 400894.23173657805 368773.29182749748, 402707.32760444866 369954.05936979665, 411077.31611991359 364349.076149669, 414676.09457412671 356244.09632705146, 416141.60866149113 344792.32464281429, 411826.83022857009 342246.46801425726, 409915.49060616881 335953.3715155946, 412094.7197449574 331732.60558329738, 425329.62427976495 328654.51400883513, 428131.33347594808 326126.38468819106, 426445.77171923511 324421.892658485, 427916.32574560272 322594.93439642468, 426426.45312371186 320532.61233990657, 422687.04764938331 320883.16438241035, 420204.65065373818 314763.29935321293, 423390.09822349017 313880.29293825885, 423506.62044241 311325.06738224183, 427849.68175836006 311264.18663154246, 431151.42406357283 306344.529501679, 429210.80217311357 304327.1112053328, 429953.76881861512 299939.14667431521, 447239.22917758313 288740.62566617026, 456575.70760444691 274048.07446483377, 450467.32167926268 270977.45624604815, 454104.51216557925 268891.90974061115, 452460.1239263037 266106.70517310768, 453715.05205581558 263181.18100875564, 449041.82701243582 260299.47963056737, 451119.73740094336 255802.47119096009, 447152.49959368125 254944.0963346705, 445859.15324520873 252920.77662215329, 451707.06557451887 244609.1363343657, 446710.91106774041 243431.72134091845, 448341.58912082558 242450.20791599576, 447313.26484125387 239480.78350584628, 449737.81233530387 235368.12750598235, 449409.76355917938 231503.79738219461, 455368.21978374536 231321.45830771606)))

GEOMETRYCOLLECTION (POINT (463745.85731712653 97152.501680457572), POINT (465661.16552534158 94931.544886879172), POINT (464073.88630714506 93756.717008685126), POINT (464946.56827492407 89901.69111035268), POLYGON ((431904.52966800641 89714.909951794834, 434321.70157557644 93738.3270790848, 446212.73674619512 98444.8075858779, 449289.17840181326 101384.62012957995, 448500.00319314661 102850.88535547133, 447672.50921151874 102127.30543761954, 447611.71449751651 106139.44928556046, 460681.12152757257 97440.859757594459, 469019.90396954655 99101.297183384871, 469910.52114802657 97323.57766843916, 470164.06260491547 98865.23818206384, 476793.72737670032 98004.377328721821, 485615.47494007659 92064.255930467451, 491517.14126283285 98217.331951748463, 524364.56687703531 104687.41339720142, 545921.05190370115 100108.00795630268, 549790.9950046778 97485.1321546319, 559498.23289082933 95294.065179627753, 566352.49178510963 104171.59600072596, 587294.95891204954 111026.81987446017, 595542.34741142963 117977.03769187017, 609454.09078105574 116656.95506005178, 609333.7623429856 126486.47908923845, 612895.9287988008 131829.53700771224, 617113.22042491729 134343.21882947921, 624011.10702901962 135607.7250155317, 626116.10832937842 138248.51943179319, 633152.729802214 139959.0734513803, 632369.49800250726 141237.3175415165, 636619.880979829 143386.69000382206, 638294.072303607 147307.21742786228, 636051.67566188064 161626.10817529718, 636228.55803707778 163296.73820639178, 639881.71266758023 165676.44326244266, 640404.43515426887 170106.18003131248, 638970.73464495421 172230.16988464631, 611411.10310779046 168021.50267537593, 607467.05496413517 165876.35562609043, 605236.5920424005 170642.62434105034, 601731.28405502124 172971.57421209474, 590826.976200715 175616.78828367344, 590244.59009285015 178233.90358379658, 586146.440096423 179989.41978867957, 586068.94240947312 181728.00459570016, 572065.29406703287 180386.01031816963, 569860.13264990016 175880.21985620988, 567284.748085676 174941.02405746875, 562807.95347031089 174940.24015404217, 560889.34677491465 177131.49205820519, 558223.25021238206 175683.73909178321, 554182.21035362629 178031.41786553012, 550075.94498144707 172434.70595853243, 549414.93277371139 163495.11898995479, 545513.989549041 159519.3015531041, 545346.26517093636 156821.2961779414, 542615.1670334629 156839.11281826944, 541907.89132032555 158471.89839944473, 540708.2530991392 156687.70620883131, 539708.254324865 160817.26427053215, 536880.04694983724 161805.58071599744, 531009.08508161036 155871.24439688184, 528804.94299855316 157430.82825067732, 528183.38976260729 160641.2863821575, 525761.223679451 162064.65506047811, 523560.98142356367 161153.45304210231, 524330.77126607008 162256.27646162605, 522267.15675086604 166052.10694230921, 516682.21395118843 159943.25024809106, 517279.41365762264 167400.16799258022, 512235.06355625635 169174.58426819165, 512053.64872956363 170507.53072195343, 507489.7496489177 172164.335981784, 507253.77978382446 174216.25938161448, 503685.54075406073 175355.99813283741, 505808.7083715364 185601.52098145778, 501290.84691831312 194282.80175975728, 501404.46892969019 196797.97936545097, 503574.71420826908 198227.4303200827, 500539.72877801611 199231.893100576, 500337.47645672737 204559.73930381343, 497784.1039919774 206906.40605230839, 492041.25602439971 208335.92412877371, 490852.25562877522 212125.2038634604, 486654.70937662647 216283.37826478452, 489976.17518454109 218559.58109767304, 492072.07929611276 213885.19712952489, 497979.94279357255 213006.38340778204, 500973.08657496778 215799.07660193948, 497722.94122284354 220057.85518496236, 489480.54898261826 224220.85322679125, 493235.28583951469 231311.21362418856, 492079.26960761996 234350.55363574112, 493281.32433212391 238546.82176390645, 491479.32882363733 239789.45991162158, 496637.91680067027 246782.71225483218, 493589.393148293 249902.77485015834, 494048.36418555473 254617.19463188475, 490280.456505748 256139.67054584742, 483786.126099024 253012.35359712894, 482846.31777732179 251055.84087274072, 481775.70446700894 251666.70730284019, 480312.82653541549 248874.40334095457, 476822.30270833021 248173.48989548633, 476413.29281243577 246823.49224858719, 480304.51470912772 242188.48623564048, 475267.930925644 236459.75344903549, 472025.29344736075 243122.1942129684, 470950.17143440765 241924.96853891647, 465855.42338718631 242191.65867795114, 466924.92344201042 241126.39344343328, 460415.80290818657 238920.27463369418, 459632.59803489636 233587.49464571293, 455368.21978374582 231321.45830771531, 449465.39256079495 231469.00043688377, 449737.8123353041 235368.1275059816, 447313.26484125364 239480.78350584608, 448341.5891208261 242450.20791599486, 446710.91106774029 243431.72134091746, 451707.0655745191 244609.13633436506, 445892.2509219377 252486.8327686699, 444775.61779808463 248766.32073508884, 441738.07646246487 246941.23252535058, 444188.54062395985 244998.60505851166, 442302.52786522434 244185.22483425582, 439509.62767834659 246843.7277255893, 437623.82182110136 246246.16954729767, 438066.26137079846 244538.17816641554, 435286.55186899484 244109.74350955887, 432790.13454896741 232846.40205141096, 427650.16797777812 231045.12717326582, 426835.77078184043 228644.86193984811, 423148.57370315085 232195.67130836402, 423382.18907407607 229584.4793718071, 426650.54273787164 226672.54920346415, 424572.80783641041 224950.35935785074, 425443.99342456914 222388.57635789766, 423683.69231269596 222082.54652457693, 421756.76981300057 218619.87201909168, 422126.48607713426 211779.81259910436, 419545.49744695972 209457.67006001555, 421751.61206852994 201550.49142693853, 424513.00288085535 198453.23567720622, 421150.42735549243 198154.41032391513, 421507.55669223552 194888.95287978774, 423729.29441759229 192996.13737282658, 421597.03915625589 187254.40396913092, 422613.646114416 185692.13474397978, 424612.32755091233 185978.9468142426, 427754.52435548796 180028.46265421365, 429002.53136848344 180780.76458567471, 429194.34501156176 177346.68727762913, 433273.52202246868 172183.88097579771, 433115.81522177672 169568.92254432867, 430031.6618669756 168584.77490680426, 436014.03314722877 161102.86661312878, 435151.23352907383 159060.64851073903, 433109.51026060351 160058.16062232471, 432578.71414321585 150051.46062658672, 427581.35670509475 150496.44452522806, 425789.65451700112 146563.59788046294, 421868.52160851914 146246.57767609204, 421565.98094570462 145045.83974410221, 424389.47258278012 139746.25057321787, 423779.59722155338 136507.89171081188, 426349.07665863191 135424.1629609777, 425973.49873338 126017.62671149534, 428291.75061792182 125023.10302993588, 428432.65968105767 123280.60860266462, 426237.21610226482 122265.50489028651, 428071.04091099929 119991.9708650987, 426647.44356734789 117330.06042494735, 423964.54752866866 116276.15517118141, 419882.357714164 119763.41506674045, 413149.76806437614 120758.28678356145, 411712.5214743581 123368.48341079627, 409039.0196316354 120584.88201587246, 408999.91768721328 123019.35448517336, 403223.27935735852 121177.56888388793, 409075.59656027734 113109.45506762038, 411308.14099259238 114721.32392804333, 413500.98167637165 114228.56256108178, 410500.93214181089 107132.48986415171, 413768.89245457138 107123.87965823333, 414938.40755869768 104124.14231933803, 413430.628367555 100832.8858740487, 415321.92373767623 96166.558782507316, 417901.40922862804 97814.240075638154, 418243.53824325604 94252.1445329532, 422640.81896152144 94757.779937595289, 421920.13997282018 93095.394539140441, 431904.52966800641 89714.909951794834)), POINT (429258.81744862651 84875.961972042482), POINT (429137.89845284319 84856.4658506085), POLYGON ((449770.64175562421 75253.227022876992, 458068.98562646011 77874.127016130427, 459727.7194808551 83759.131670999355, 466394.78301809932 87625.404172703973, 460699.012120612 93704.827683764117, 461895.75633102556 94077.045536897713, 455629.46217130776 93035.515686517814, 451535.23438232625 96521.2099235977, 448830.66484548344 96661.297120087562, 445677.86627182405 93553.414862245132, 433858.94044400612 89824.695072385759, 429417.73243294365 84923.682177487251, 436564.62260187929 85356.691398595518, 449770.64175562421 75253.227022876992)))

但是,如果我使用 NetTopologySuite 在 C# 中执行此操作,我可以将这些形状点转换为长/纬度。

sql sql-server geospatial spatial
1个回答
0
投票

问题是您的形状不是采用纬度/经度坐标(我们在行业中称为 EPSG:4326 或 WGS:84),这是 SQL Server 在您将几何图形转换(或以其他方式)转换为地理图形时所期望的。

不幸的是,正如这个问题所讨论的,如果没有一些第三部分软件,就不可能重新投影你的几何形状,在这个问题的答案中提出了几种可能性。我会推荐行业领先(且开源)

ogr2ogr
来执行此操作。

© www.soinside.com 2019 - 2024. All rights reserved.