Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server SQL语句,包括服务器的MakeValid()_Sql Server_Gis_Geospatial_Spatial_Sqlgeometry - Fatal编程技术网

Sql server SQL语句,包括服务器的MakeValid()

Sql server SQL语句,包括服务器的MakeValid(),sql-server,gis,geospatial,spatial,sqlgeometry,Sql Server,Gis,Geospatial,Spatial,Sqlgeometry,我认为这是SQL Server中的MakeValid()的一个有趣的错误,我在SQL Server 2016和2019中尝试过它。下面的SQL将压碎您的SQL Server,您必须终止SQL Server服务。这个几何体没有什么特别之处。在过去的5年中,我们一直在用数百万种几何图形进行这项工作,但却在大海捞针,导致服务器停机 declare @wkt nvarchar(max) = 'MULTILINESTRING ((-78.063088844296 39.0923128276227, -78

我认为这是SQL Server中的
MakeValid()
的一个有趣的错误,我在SQL Server 2016和2019中尝试过它。下面的SQL将压碎您的SQL Server,您必须终止SQL Server服务。这个几何体没有什么特别之处。在过去的5年中,我们一直在用数百万种几何图形进行这项工作,但却在大海捞针,导致服务器停机

declare @wkt nvarchar(max) = 'MULTILINESTRING ((-78.063088844296 39.0923128276227, -78.0629933704493 39.0924209049056, -78.0628537704575 39.0925804994165, -78.0626985415764 39.0927655959674, -78.0625776031863 39.0929093443343, -78.0624772451994 39.0930271271681, -78.0624404735616 39.093069429965, -78.06242230244 39.0931060149791, -78.062417726422 39.0931460260255, -78.0624230534316 39.0931855915373, -78.0624414338606 39.0932160425133, -78.0624617321928 39.0932363736011, -78.0624857549401 39.0932547887746, -78.0625955308645 39.0933174085555, -78.0628091268828 39.0934413211804, -78.0623615448858 39.0939008841112, -78.0618945628718 39.0943812788732, -78.0621603492116 39.094522628407, -78.0625166974101 39.0947133754383, -78.0627689030194 39.0948489021124, -78.0630246488892 39.0949866567258, -78.0632038915344 39.0950820335129, -78.0632954936423 39.095126900709, -78.0633505648608 39.0951567951925, -78.0635673364237 39.0952755726356, -78.063682189626 39.0953377527927), (-78.0636821896416 39.0953377528011, -78.063757905942 39.0953787442108, -78.0639711453292 39.0954941852792, -78.0641092846603 39.0955700222676, -78.0644398539051 39.0957485791264, -78.064783336432 39.0959347898128, -78.06514128453 39.096126566234, -78.0651655623989 39.0961381922841, -78.0654659698097 39.0958486496622, -78.0653479527409 39.0956841997381, -78.0648892954147 39.0954718713677, -78.0645701123162 39.0955967701995, -78.0644398539051 39.0957485791264, -78.0641092846603 39.0955700222676, -78.0639711453292 39.0954941852792, -78.063757905942 39.0953787442108, -78.0635673364393 39.095275572644, -78.0633505648764 39.0951567952009, -78.0632954936579 39.0951269007174, -78.06320389155 39.0950820335213, -78.0630246489048 39.0949866567342, -78.062768903035 39.0948489021208, -78.0625166974257 39.0947133754467, -78.0621603492272 39.0945226284154, -78.0618945628874 39.0943812788816, -78.0617054459606 39.0942782571458, -78.0615781367185 39.094207817123, -78.0613182406321 39.0940655626988, -78.0611270926144 39.0939594435658, -78.0609317701255 39.0938510242263, -78.0607352124531 39.0937393369615, -78.0605369866093 39.0936266643798, -78.0603537707155 39.0935248163208, -78.0602511013634 39.0934677492167), (-78.0602511013634 39.0934677492167, -78.0600742383553 39.0933694413094, -78.0604932584179 39.0928866824054, -78.0608162054575 39.0930709352344, -78.0610014102213 39.0931742989685, -78.0612692959238 39.093305320502, -78.061566316686 39.0934705247655, -78.0621024968246 39.0937608119971, -78.0622390120017 39.0938294697379, -78.0623615449014 39.0939008841196, -78.0618945628874 39.0943812788816, -78.0617054459606 39.0942782571458, -78.0615781367185 39.094207817123, -78.0613182406321 39.0940655626988, -78.0611270926144 39.0939594435658, -78.0609317701255 39.0938510242263, -78.0607352124531 39.0937393369615, -78.0605369866093 39.0936266643798, -78.0603537707155 39.0935248163208, -78.0603424456547 39.0935185213164), (-78.060342445643 39.0935185213101, -78.0600742383436 39.0933694413031, -78.0604932584062 39.0928866823991, -78.0608162054458 39.0930709352281, -78.0610014102096 39.0931742989622, -78.0612692959121 39.0933053204957, -78.0615663166743 39.0934705247592, -78.0621024968129 39.0937608119908, -78.06223901199 39.0938294697316, -78.0623615448897 39.0939008841133, -78.0618945628757 39.0943812788753, -78.0621603492155 39.0945226284091, -78.062516697414 39.0947133754404, -78.0627689030233 39.0948489021145, -78.0630246488931 39.0949866567279, -78.0632038915383 39.095082033515, -78.0632954936462 39.0951269007111, -78.0633505648647 39.0951567951946, -78.0635673364276 39.0952755726377, -78.0637579059303 39.0953787442045, -78.0639711453175 39.0954941852729, -78.0641092846486 39.0955700222613, -78.0644398538934 39.0957485791201, -78.0641672852732 39.0960441025072, -78.0636611852219 39.0965910448198), (-78.063661185218 39.0965910448177, -78.0636370870122 39.0966170875257, -78.0630339329776 39.0962933813165, -78.0621979068753 39.0958332797234, -78.0619819914069 39.0960652526533, -78.0619241515807 39.0961326818238, -78.0618918077389 39.0961804325525, -78.0618661401763 39.0962282083471, -78.0618577957256 39.0962822921137, -78.0618508382737 39.0963280558047, -78.0618559182467 39.0963707428539, -78.0618703344103 39.0964155450904, -78.0618861115217 39.0964561900775, -78.0619152375981 39.0964979254134, -78.0619444328449 39.0965282139131, -78.0619829777571 39.096558536561, -78.062052145339 39.0966029963687, -78.0634884796131 39.0973721601295, -78.0637108737313 39.0971400255744, -78.0637686336075 39.0970732038992, -78.0637898392381 39.0970442332728, -78.0638072674529 39.0970078001921, -78.0638219225684 39.0969557157526, -78.0638298699638 39.0969065851623, -78.0638283122851 39.0968484820183, -78.0638161769439 39.0968007672974, -78.0637944736466 39.0967545061364, -78.063758437729 39.0967074480832, -78.0637194975581 39.0966663375332, -78.0636871267668 39.0966453618572, -78.0636370870122 39.0966170875257, -78.0636920082121 39.0965577341202), (-78.0636920082121 39.0965577341202, -78.0638980790433 39.0963350337855), (-78.0638980790446 39.0963350337862, -78.0641672852706 39.0960441025058, -78.0644398538908 39.0957485791187, -78.0647833364177 39.0959347898051, -78.0651412845157 39.0961265662263, -78.0651655623846 39.0961381922764, -78.0654659697954 39.0958486496545, -78.0653479527266 39.0956841997304, -78.0648892954004 39.09547187136, -78.0645701123019 39.0955967701918, -78.0644398538908 39.0957485791187, -78.0641672852706 39.0960441025058, -78.0636370870135 39.0966170875264, -78.0636871267681 39.0966453618579, -78.0637194975594 39.0966663375339, -78.0637584377303 39.0967074480839, -78.0637944736479 39.0967545061371, -78.0638161769452 39.0968007672981, -78.0638283122864 39.096848482019, -78.0638298699651 39.096906585163, -78.0638219225697 39.0969557157533, -78.0638072674542 39.0970078001928, -78.0637898392394 39.0970442332735, -78.0637686336088 39.0970732038999, -78.0637108737326 39.0971400255751, -78.0634884796144 39.0973721601302, -78.0634166790704 39.0973337110302), (-78.0634166790938 39.0973337110428, -78.0624792296026 39.0968317033473), (-78.0624792296026 39.0968317033473, -78.0621042503451 39.0966308991288), (-78.0621042503425 39.0966308991274, -78.0620521453611 39.0966029963806, -78.0619829777792 39.0965585365729, -78.061944432867 39.096528213925, -78.0619152376202 39.0964979254253, -78.0618861115438 39.0964561900894, -78.0618703344324 39.0964155451023, -78.0618559182688 39.0963707428658, -78.0618508382958 39.0963280558166, -78.0618577957477 39.0962822921256, -78.0618661401984 39.096228208359, -78.061891807761 39.0961804325644, -78.0619241516028 39.0961326818357, -78.061981991429 39.0960652526652, -78.0621979068974 39.0958332797353, -78.0630339329997 39.0962933813284, -78.0636370870343 39.0966170875376, -78.0636871267889 39.0966453618691, -78.0637194975802 39.0966663375451, -78.0637584377511 39.0967074480951, -78.0637944736687 39.0967545061483, -78.063816176966 39.0968007673093, -78.0638283123072 39.0968484820302, -78.0638298699859 39.0969065851742, -78.0638219225905 39.0969557157644, -78.063807267475 39.097007800204, -78.0637898392602 39.0970442332847, -78.0637686336296 39.0970732039111, -78.0637108737534 39.0971400255863, -78.0634884796352 39.0973721601414, -78.0622917404204 39.0967313009596), (-78.0622917404204 39.0967313009596, -78.0620521453611 39.0966029963806, -78.0619829777792 39.0965585365729, -78.061944432867 39.096528213925, -78.0619152376202 39.0964979254253, -78.0618861115438 39.0964561900894, -78.0618703344324 39.0964155451023, -78.0618559182688 39.0963707428658, -78.0618508382958 39.0963280558166, -78.0618577957477 39.0962822921256, -78.0618661401984 39.096228208359, -78.061891807761 39.0961804325644, -78.0619241516028 39.0961326818357, -78.061981991429 39.0960652526652, -78.0621979068974 39.0958332797353, -78.0630339329997 39.0962933813284, -78.0636370870343 39.0966170875376, -78.0641672852914 39.096044102517, -78.0644398539116 39.0957485791299, -78.0641092846668 39.0955700222711, -78.0639711453357 39.0954941852827, -78.0637579059485 39.0953787442143, -78.0635673364458 39.0952755726475, -78.0633505648829 39.0951567952044, -78.0632954936644 39.0951269007209, -78.0632038915565 39.0950820335248, -78.0630246489113 39.0949866567377, -78.0627689030415 39.0948489021243, -78.0625166974322 39.0947133754502, -78.0623137733994 39.0946047536911), (-78.0623137733851 39.0946047536834, -78.0621603492194 39.0945226284112, -78.0618945628796 39.0943812788774, -78.061888890917 39.0943781889316), (-78.061888890917 39.0943781889316, -78.0617054459528 39.0942782571416, -78.0615781367107 39.0942078171189, -78.0613182406243 39.0940655626946, -78.0611270926066 39.0939594435616, -78.0609317701177 39.0938510242221, -78.0607352124453 39.0937393369573, -78.0605369866015 39.0936266643756, -78.0603537707077 39.0935248163166, -78.0600742383475 39.0933694413052, -78.0604932584101 39.0928866824012, -78.0608162054497 39.0930709352302, -78.0610014102135 39.0931742989643, -78.061269295916 39.0933053204978, -78.0615663166782 39.0934705247613, -78.0621024968168 39.0937608119929, -78.0622390119939 39.0938294697337, -78.0623615448936 39.0939008841154, -78.0618945628796 39.0943812788774, -78.0621603492194 39.0945226284112, -78.0625166974179 39.0947133754425, -78.0627689030272 39.0948489021166, -78.063024648897 39.09498665673, -78.0632038915422 39.0950820335171, -78.0632954936501 39.0951269007132, -78.0633505648686 39.0951567951967, -78.0635673364315 39.0952755726398, -78.0637579059342 39.0953787442066, -78.0639711453214 39.095494185275, -78.0641092846525 39.0955700222634, -78.0644398538973 39.0957485791222, -78.0641672852771 39.0960441025093, -78.06363708702 39.0966170875299, -78.0630339329854 39.0962933813207, -78.0621979068831 39.0958332797276, -78.0621805909577 39.0958241843748), (-78.062180590959 39.0958241843755, -78.0616206090586 39.0955300516351, -78.0621979068844 39.0958332797283, -78.061981991416 39.0960652526582, -78.0619241515898 39.0961326818287, -78.061891807748 39.0961804325574, -78.0618917260013 39.0961805838438), (-78.0618917260117 39.0961805838494, -78.0618661401958 39.0962282083576, -78.0618577957451 39.0962822921242, -78.0618508382932 39.0963280558152, -78.0618559182662 39.0963707428644, -78.0618703344298 39.0964155451009, -78.0618861115412 39.096456190088, -78.0619152376176 39.0964979254239, -78.0619444328644 39.0965282139236, -78.0619829777766 39.0965585365715, -78.0620521453585 39.0966029963792, -78.0634884796326 39.09737216014, -78.0637108737508 39.0971400255849, -78.063768633627 39.0970732039097, -78.0637898392576 39.0970442332833, -78.0638072674724 39.0970078002026, -78.0638219225879 39.096955715763, -78.0638298699833 39.0969065851728, -78.0638283123046 39.0968484820288, -78.0638161769634 39.0968007673079, -78.0637944736661 39.0967545061469, -78.0637584377485 39.0967074480937, -78.0637194975776 39.0966663375437, -78.0636871267863 39.0966453618677, -78.0636370870317 39.0966170875362, -78.0630339329971 39.096293381327, -78.0621979068948 39.0958332797339, -78.0621805900711 39.0958241843811), (-78.0621805900711 39.0958241843811, -78.061620609069 39.0955300516407, -78.0621979068948 39.0958332797339, -78.0630339329971 39.096293381327, -78.0636370870317 39.0966170875362, -78.0641672852888 39.0960441025156, -78.064439853909 39.0957485791285, -78.0641092846642 39.0955700222697, -78.0639711453331 39.0954941852813, -78.0637579059459 39.0953787442129, -78.0635673364432 39.0952755726461, -78.0633505648803 39.095156795203, -78.0632954936618 39.0951269007195, -78.0632038915539 39.0950820335234, -78.0630246489087 39.0949866567363, -78.0627689030389 39.0948489021229, -78.0625166974296 39.0947133754488, -78.0621603492311 39.0945226284175, -78.0618945628913 39.0943812788837, -78.0617054459645 39.0942782571479, -78.061321075719 39.094762278193, -78.06117171643 39.0949581928028, -78.0611668089336 39.0949645908619), (-78.0611668089323 39.0949645908612, -78.0609227959584 39.0952826908637, -78.0608782619782 39.0953392384941, -78.0608407240774 39.0953850090718, -78.060819789738 39.0954078863319, -78.0607980307452 39.0954240093091, -78.0607754336243 39.0954354026171, -78.0607554685671 39.095441404635, -78.0607268446489 39.0954466990153, -78.0606973861958 39.0954465895581, -78.0606688080916 39.0954444568864, -78.060639408029 39.0954348950704, -78.060603123278 39.0954178811002, -78.0599165840255 39.095049383042, -78.0595054754256 39.0948371970775, -78.0594492552619 39.0948081321096), (-78.0594492552541 39.0948081321054, -78.0590503242162 39.0946018903349, -78.0588067801629 39.0944747238768, -78.0586265790152 39.0943747998927, -78.058662242132 39.0943616292758, -78.0587202032307 39.0943388925086, -78.0588941314428 39.0942634564754, -78.0589635541463 39.0942316659499, -78.0590346342414 39.0941972246871, -78.0591063817849 39.0941612467963, -78.0591711000112 39.0941266109824, -78.0592624775402 39.0940737805097, -78.059423526606 39.0939658145222, -78.0595277491453 39.0938935412623, -78.0595912196117 39.0938476156364, -78.0596474577418 39.0938004664022, -78.059706574074 39.0937490537822, -78.0597932695837 39.0936726110627, -78.0598449245092 39.0936215120883, -78.0598954843883 39.0935698964531, -78.0599705548 39.093492897175, -78.0600742383501 39.0933694413066, -78.0603537707103 39.093524816318, -78.0605369866041 39.093626664377, -78.0607352124479 39.0937393369587, -78.0609317701203 39.0938510242235, -78.0611270926092 39.093959443563, -78.0613182406269 39.094065562696, -78.0615781367133 39.0942078171202, -78.0617054459554 39.094278257143, -78.0618945628822 39.0943812788788, -78.062160349222 39.0945226284126, -78.0625166974205 39.0947133754439, -78.0627689030298 39.094848902118, -78.0630246488996 39.0949866567314, -78.0632038915448 39.0950820335185, -78.0632954936527 39.0951269007146, -78.0636763667567 39.0947529812103, -78.063979456537 39.0946417743417, -78.0645934164061 39.0949256008234))'
declare @g geometry = geometry::STGeomFromText(@wkt, 4326)
select @g.MakeValid()
有人遇到过类似的情况吗?

根据文档:此输入形状不能作为单个
多字符串有效,因为它违反了以下两个条件:

要使多重约束实例有效,它必须满足以下条件:

  • 构成多重线串实例的所有实例必须是有效的线串实例

  • 构成多重线串实例的两个线串实例不能在一个间隔上重叠。线串实例只能在有限数量的点处与其自身或其他线串实例相交或接触。 ,也不能使其有效

因此,要使其有效,首先必须使所有元件线独立有效,然后可能仍会遇到第二个约束的问题,这很难在简单的证明中显示,但当单独渲染所有这些线时,很明显,它们中的大多数线直接相互重叠:

我们可以(也应该)使用
GEOGRAPHY
,而不是使用几何图形,因为这些点闻起来像GPS坐标,但我们可以很容易地使用
STBuffer()
生成线的exanded表示,以尝试详细描述相交区域:

因此,在这里,我尝试用括号中相同集合中的其他线的相交数来标记这些线,例如,
14:(4)
表示集合中的第14条线在某个点与其他4条线相交

第13行和第16行是最严重的违规行为,它们分别与其他13行相交

例如第13行:

我还没有研究它,但可能尝试了一些算法来强制使一条线或多行线有效。我们可以通过改变序列的起始点,检测闭包和重叠,或者反转序列的方向来进行假设

但是在这个给定的数据集中,重叠的行表示了实际上应该是堆栈溢出异常的情况,因为有无限多的排列试图解决冲突

我能捕捉到的最接近的错误是
内存不足,无法继续执行程序


将其报告为bug的问题是,我们只有在它失败后才真正知道它是bug,在运行时增加一些复杂性来处理它是违反直觉的,或者至少会引入或使用环境变量或查询提示,如
MAXDOP
MAXRECURSION
,以允许调用方控制MakeValid()失败之前应允许的工作量或时间

在这种情况下,如果多条直线明显相交于多个线段,
MultiLineString
不是表示此数据的有效形状类型,而是应将其处理为
LineString


此证明中使用了以下SQL,最初我发现只有2行本身是隐式有效的,以下内容覆盖了这些行,因此我们可以看到它们仍然会违反多行限制条件,无论其有效性如何:

WITH lines as (SELECT * FROM
(VALUES (1,geography::STGeomFromText('LINESTRING (-78.063088844296 39.0923128276227, -78.0629933704493 39.0924209049056, -78.0628537704575 39.0925804994165, -78.0626985415764 39.0927655959674, -78.0625776031863 39.0929093443343, -78.0624772451994 39.0930271271681, -78.0624404735616 39.093069429965, -78.06242230244 39.0931060149791, -78.062417726422 39.0931460260255, -78.0624230534316 39.0931855915373, -78.0624414338606 39.0932160425133, -78.0624617321928 39.0932363736011, -78.0624857549401 39.0932547887746, -78.0625955308645 39.0933174085555, -78.0628091268828 39.0934413211804, -78.0623615448858 39.0939008841112, -78.0618945628718 39.0943812788732, -78.0621603492116 39.094522628407, -78.0625166974101 39.0947133754383, -78.0627689030194 39.0948489021124, -78.0630246488892 39.0949866567258, -78.0632038915344 39.0950820335129, -78.0632954936423 39.095126900709, -78.0633505648608 39.0951567951925, -78.0635673364237 39.0952755726356, -78.063682189626 39.0953377527927)', 4326))
       ,(2,geography::STGeomFromText('LINESTRING (-78.0636821896416 39.0953377528011, -78.063757905942 39.0953787442108, -78.0639711453292 39.0954941852792, -78.0641092846603 39.0955700222676, -78.0644398539051 39.0957485791264, -78.064783336432 39.0959347898128, -78.06514128453 39.096126566234, -78.0651655623989 39.0961381922841, -78.0654659698097 39.0958486496622, -78.0653479527409 39.0956841997381, -78.0648892954147 39.0954718713677, -78.0645701123162 39.0955967701995, -78.0644398539051 39.0957485791264, -78.0641092846603 39.0955700222676, -78.0639711453292 39.0954941852792, -78.063757905942 39.0953787442108, -78.0635673364393 39.095275572644, -78.0633505648764 39.0951567952009, -78.0632954936579 39.0951269007174, -78.06320389155 39.0950820335213, -78.0630246489048 39.0949866567342, -78.062768903035 39.0948489021208, -78.0625166974257 39.0947133754467, -78.0621603492272 39.0945226284154, -78.0618945628874 39.0943812788816, -78.0617054459606 39.0942782571458, -78.0615781367185 39.094207817123, -78.0613182406321 39.0940655626988, -78.0611270926144 39.0939594435658, -78.0609317701255 39.0938510242263, -78.0607352124531 39.0937393369615, -78.0605369866093 39.0936266643798, -78.0603537707155 39.0935248163208, -78.0602511013634 39.0934677492167)', 4326))
       ,(3,geography::STGeomFromText('LINESTRING (-78.0602511013634 39.0934677492167, -78.0600742383553 39.0933694413094, -78.0604932584179 39.0928866824054, -78.0608162054575 39.0930709352344, -78.0610014102213 39.0931742989685, -78.0612692959238 39.093305320502, -78.061566316686 39.0934705247655, -78.0621024968246 39.0937608119971, -78.0622390120017 39.0938294697379, -78.0623615449014 39.0939008841196, -78.0618945628874 39.0943812788816, -78.0617054459606 39.0942782571458, -78.0615781367185 39.094207817123, -78.0613182406321 39.0940655626988, -78.0611270926144 39.0939594435658, -78.0609317701255 39.0938510242263, -78.0607352124531 39.0937393369615, -78.0605369866093 39.0936266643798, -78.0603537707155 39.0935248163208, -78.0603424456547 39.0935185213164)',4326))
       ,(4,geography::STGeomFromText('LINESTRING (-78.060342445643 39.0935185213101, -78.0600742383436 39.0933694413031, -78.0604932584062 39.0928866823991, -78.0608162054458 39.0930709352281, -78.0610014102096 39.0931742989622, -78.0612692959121 39.0933053204957, -78.0615663166743 39.0934705247592, -78.0621024968129 39.0937608119908, -78.06223901199 39.0938294697316, -78.0623615448897 39.0939008841133, -78.0618945628757 39.0943812788753, -78.0621603492155 39.0945226284091, -78.062516697414 39.0947133754404, -78.0627689030233 39.0948489021145, -78.0630246488931 39.0949866567279, -78.0632038915383 39.095082033515, -78.0632954936462 39.0951269007111, -78.0633505648647 39.0951567951946, -78.0635673364276 39.0952755726377, -78.0637579059303 39.0953787442045, -78.0639711453175 39.0954941852729, -78.0641092846486 39.0955700222613, -78.0644398538934 39.0957485791201, -78.0641672852732 39.0960441025072, -78.0636611852219 39.0965910448198)',4326))
       ,(5,geography::STGeomFromText('LINESTRING (-78.063661185218 39.0965910448177, -78.0636370870122 39.0966170875257, -78.0630339329776 39.0962933813165, -78.0621979068753 39.0958332797234, -78.0619819914069 39.0960652526533, -78.0619241515807 39.0961326818238, -78.0618918077389 39.0961804325525, -78.0618661401763 39.0962282083471, -78.0618577957256 39.0962822921137, -78.0618508382737 39.0963280558047, -78.0618559182467 39.0963707428539, -78.0618703344103 39.0964155450904, -78.0618861115217 39.0964561900775, -78.0619152375981 39.0964979254134, -78.0619444328449 39.0965282139131, -78.0619829777571 39.096558536561, -78.062052145339 39.0966029963687, -78.0634884796131 39.0973721601295, -78.0637108737313 39.0971400255744, -78.0637686336075 39.0970732038992, -78.0637898392381 39.0970442332728, -78.0638072674529 39.0970078001921, -78.0638219225684 39.0969557157526, -78.0638298699638 39.0969065851623, -78.0638283122851 39.0968484820183, -78.0638161769439 39.0968007672974, -78.0637944736466 39.0967545061364, -78.063758437729 39.0967074480832, -78.0637194975581 39.0966663375332, -78.0636871267668 39.0966453618572, -78.0636370870122 39.0966170875257, -78.0636920082121 39.0965577341202)',4326))
       ,(6,geography::STGeomFromText('LINESTRING (-78.0636920082121 39.0965577341202, -78.0638980790433 39.0963350337855)',4326))
       ,(7,geography::STGeomFromText('LINESTRING (-78.0638980790446 39.0963350337862, -78.0641672852706 39.0960441025058, -78.0644398538908 39.0957485791187, -78.0647833364177 39.0959347898051, -78.0651412845157 39.0961265662263, -78.0651655623846 39.0961381922764, -78.0654659697954 39.0958486496545, -78.0653479527266 39.0956841997304, -78.0648892954004 39.09547187136, -78.0645701123019 39.0955967701918, -78.0644398538908 39.0957485791187, -78.0641672852706 39.0960441025058, -78.0636370870135 39.0966170875264, -78.0636871267681 39.0966453618579, -78.0637194975594 39.0966663375339, -78.0637584377303 39.0967074480839, -78.0637944736479 39.0967545061371, -78.0638161769452 39.0968007672981, -78.0638283122864 39.096848482019, -78.0638298699651 39.096906585163, -78.0638219225697 39.0969557157533, -78.0638072674542 39.0970078001928, -78.0637898392394 39.0970442332735, -78.0637686336088 39.0970732038999, -78.0637108737326 39.0971400255751, -78.0634884796144 39.0973721601302, -78.0634166790704 39.0973337110302)',4326))
       ,(8,geography::STGeomFromText('LINESTRING (-78.0634166790938 39.0973337110428, -78.0624792296026 39.0968317033473)',4326))
       ,(9,geography::STGeomFromText('LINESTRING (-78.0624792296026 39.0968317033473, -78.0621042503451 39.0966308991288)',4326))
       ,(10,geography::STGeomFromText('LINESTRING (-78.0621042503425 39.0966308991274, -78.0620521453611 39.0966029963806, -78.0619829777792 39.0965585365729, -78.061944432867 39.096528213925, -78.0619152376202 39.0964979254253, -78.0618861115438 39.0964561900894, -78.0618703344324 39.0964155451023, -78.0618559182688 39.0963707428658, -78.0618508382958 39.0963280558166, -78.0618577957477 39.0962822921256, -78.0618661401984 39.096228208359, -78.061891807761 39.0961804325644, -78.0619241516028 39.0961326818357, -78.061981991429 39.0960652526652, -78.0621979068974 39.0958332797353, -78.0630339329997 39.0962933813284, -78.0636370870343 39.0966170875376, -78.0636871267889 39.0966453618691, -78.0637194975802 39.0966663375451, -78.0637584377511 39.0967074480951, -78.0637944736687 39.0967545061483, -78.063816176966 39.0968007673093, -78.0638283123072 39.0968484820302, -78.0638298699859 39.0969065851742, -78.0638219225905 39.0969557157644, -78.063807267475 39.097007800204, -78.0637898392602 39.0970442332847, -78.0637686336296 39.0970732039111, -78.0637108737534 39.0971400255863, -78.0634884796352 39.0973721601414, -78.0622917404204 39.0967313009596)',4326))
       ,(11,geography::STGeomFromText('LINESTRING (-78.0622917404204 39.0967313009596, -78.0620521453611 39.0966029963806, -78.0619829777792 39.0965585365729, -78.061944432867 39.096528213925, -78.0619152376202 39.0964979254253, -78.0618861115438 39.0964561900894, -78.0618703344324 39.0964155451023, -78.0618559182688 39.0963707428658, -78.0618508382958 39.0963280558166, -78.0618577957477 39.0962822921256, -78.0618661401984 39.096228208359, -78.061891807761 39.0961804325644, -78.0619241516028 39.0961326818357, -78.061981991429 39.0960652526652, -78.0621979068974 39.0958332797353, -78.0630339329997 39.0962933813284, -78.0636370870343 39.0966170875376, -78.0641672852914 39.096044102517, -78.0644398539116 39.0957485791299, -78.0641092846668 39.0955700222711, -78.0639711453357 39.0954941852827, -78.0637579059485 39.0953787442143, -78.0635673364458 39.0952755726475, -78.0633505648829 39.0951567952044, -78.0632954936644 39.0951269007209, -78.0632038915565 39.0950820335248, -78.0630246489113 39.0949866567377, -78.0627689030415 39.0948489021243, -78.0625166974322 39.0947133754502, -78.0623137733994 39.0946047536911)',4326))
       ,(12,geography::STGeomFromText('LINESTRING (-78.0623137733851 39.0946047536834, -78.0621603492194 39.0945226284112, -78.0618945628796 39.0943812788774, -78.061888890917 39.0943781889316)',4326))
       ,(13,geography::STGeomFromText('LINESTRING (-78.061888890917 39.0943781889316, -78.0617054459528 39.0942782571416, -78.0615781367107 39.0942078171189, -78.0613182406243 39.0940655626946, -78.0611270926066 39.0939594435616, -78.0609317701177 39.0938510242221, -78.0607352124453 39.0937393369573, -78.0605369866015 39.0936266643756, -78.0603537707077 39.0935248163166, -78.0600742383475 39.0933694413052, -78.0604932584101 39.0928866824012, -78.0608162054497 39.0930709352302, -78.0610014102135 39.0931742989643, -78.061269295916 39.0933053204978, -78.0615663166782 39.0934705247613, -78.0621024968168 39.0937608119929, -78.0622390119939 39.0938294697337, -78.0623615448936 39.0939008841154, -78.0618945628796 39.0943812788774, -78.0621603492194 39.0945226284112, -78.0625166974179 39.0947133754425, -78.0627689030272 39.0948489021166, -78.063024648897 39.09498665673, -78.0632038915422 39.0950820335171, -78.0632954936501 39.0951269007132, -78.0633505648686 39.0951567951967, -78.0635673364315 39.0952755726398, -78.0637579059342 39.0953787442066, -78.0639711453214 39.095494185275, -78.0641092846525 39.0955700222634, -78.0644398538973 39.0957485791222, -78.0641672852771 39.0960441025093, -78.06363708702 39.0966170875299, -78.0630339329854 39.0962933813207, -78.0621979068831 39.0958332797276, -78.0621805909577 39.0958241843748)',4326))
       ,(14,geography::STGeomFromText('LINESTRING (-78.062180590959 39.0958241843755, -78.0616206090586 39.0955300516351, -78.0621979068844 39.0958332797283, -78.061981991416 39.0960652526582, -78.0619241515898 39.0961326818287, -78.061891807748 39.0961804325574, -78.0618917260013 39.0961805838438)',4326))
       ,(15,geography::STGeomFromText('LINESTRING (-78.0618917260117 39.0961805838494, -78.0618661401958 39.0962282083576, -78.0618577957451 39.0962822921242, -78.0618508382932 39.0963280558152, -78.0618559182662 39.0963707428644, -78.0618703344298 39.0964155451009, -78.0618861115412 39.096456190088, -78.0619152376176 39.0964979254239, -78.0619444328644 39.0965282139236, -78.0619829777766 39.0965585365715, -78.0620521453585 39.0966029963792, -78.0634884796326 39.09737216014, -78.0637108737508 39.0971400255849, -78.063768633627 39.0970732039097, -78.0637898392576 39.0970442332833, -78.0638072674724 39.0970078002026, -78.0638219225879 39.096955715763, -78.0638298699833 39.0969065851728, -78.0638283123046 39.0968484820288, -78.0638161769634 39.0968007673079, -78.0637944736661 39.0967545061469, -78.0637584377485 39.0967074480937, -78.0637194975776 39.0966663375437, -78.0636871267863 39.0966453618677, -78.0636370870317 39.0966170875362, -78.0630339329971 39.096293381327, -78.0621979068948 39.0958332797339, -78.0621805900711 39.0958241843811)',4326))
       ,(16,geography::STGeomFromText('LINESTRING (-78.0621805900711 39.0958241843811, -78.061620609069 39.0955300516407, -78.0621979068948 39.0958332797339, -78.0630339329971 39.096293381327, -78.0636370870317 39.0966170875362, -78.0641672852888 39.0960441025156, -78.064439853909 39.0957485791285, -78.0641092846642 39.0955700222697, -78.0639711453331 39.0954941852813, -78.0637579059459 39.0953787442129, -78.0635673364432 39.0952755726461, -78.0633505648803 39.095156795203, -78.0632954936618 39.0951269007195, -78.0632038915539 39.0950820335234, -78.0630246489087 39.0949866567363, -78.0627689030389 39.0948489021229, -78.0625166974296 39.0947133754488, -78.0621603492311 39.0945226284175, -78.0618945628913 39.0943812788837, -78.0617054459645 39.0942782571479, -78.061321075719 39.094762278193, -78.06117171643 39.0949581928028, -78.0611668089336 39.0949645908619)',4326))
       ,(17,geography::STGeomFromText('LINESTRING (-78.0611668089323 39.0949645908612, -78.0609227959584 39.0952826908637, -78.0608782619782 39.0953392384941, -78.0608407240774 39.0953850090718, -78.060819789738 39.0954078863319, -78.0607980307452 39.0954240093091, -78.0607754336243 39.0954354026171, -78.0607554685671 39.095441404635, -78.0607268446489 39.0954466990153, -78.0606973861958 39.0954465895581, -78.0606688080916 39.0954444568864, -78.060639408029 39.0954348950704, -78.060603123278 39.0954178811002, -78.0599165840255 39.095049383042, -78.0595054754256 39.0948371970775, -78.0594492552619 39.0948081321096)',4326))
       ,(18,geography::STGeomFromText('LINESTRING (-78.0594492552541 39.0948081321054, -78.0590503242162 39.0946018903349, -78.0588067801629 39.0944747238768, -78.0586265790152 39.0943747998927, -78.058662242132 39.0943616292758, -78.0587202032307 39.0943388925086, -78.0588941314428 39.0942634564754, -78.0589635541463 39.0942316659499, -78.0590346342414 39.0941972246871, -78.0591063817849 39.0941612467963, -78.0591711000112 39.0941266109824, -78.0592624775402 39.0940737805097, -78.059423526606 39.0939658145222, -78.0595277491453 39.0938935412623, -78.0595912196117 39.0938476156364, -78.0596474577418 39.0938004664022, -78.059706574074 39.0937490537822, -78.0597932695837 39.0936726110627, -78.0598449245092 39.0936215120883, -78.0598954843883 39.0935698964531, -78.0599705548 39.093492897175, -78.0600742383501 39.0933694413066, -78.0603537707103 39.093524816318, -78.0605369866041 39.093626664377, -78.0607352124479 39.0937393369587, -78.0609317701203 39.0938510242235, -78.0611270926092 39.093959443563, -78.0613182406269 39.094065562696, -78.0615781367133 39.0942078171202, -78.0617054459554 39.094278257143, -78.0618945628822 39.0943812788788, -78.062160349222 39.0945226284126, -78.0625166974205 39.0947133754439, -78.0627689030298 39.094848902118, -78.0630246488996 39.0949866567314, -78.0632038915448 39.0950820335185, -78.0632954936527 39.0951269007146, -78.0636763667567 39.0947529812103, -78.063979456537 39.0946417743417, -78.0645934164061 39.0949256008234)',4326))
) as Line(rn, geo))
, ValidLines as 
(
   SELECT rn, geo = geo.MakeValid() FROM Lines
)
SELECT src.*
, Label = CAST(rn as varchar) + ': (' + CAST((SELECT COUNT(1) FROM ValidLines lkp WHERE src.geo.STIntersects(lkp.geo) = 1) as VARCHAR) + ')'
, src.geo.STBuffer(rn)
FROM ValidLines src

您是否正在使用CU9运行最新版本的SQL Server 2019?报告SQL Server错误的地方是。如果有人受到启发,您可以尝试通过直接在.NET中调用类来复制甚至调试它;如果代码不完全是SQL Server使用的(实际上我认为是的,因为地理类型是用托管代码实现的),那么它至少在道德上是等价的(我自己没有这样做)。请注意,此类型仍然是封闭源代码。@YitzhakKhabinsky,是的,我们正在使用CU9运行2019年的最新版本。@Jeroenmoster,从.NET中的类调用相同的几何体文本不会失败。示例代码(作为要点)。@ChrisMiller:注意,我的原始注释中有一个输入错误:正在使用的类是
SqlGeometry
,而不是
SqlGeography
。使用MakeValid的原因是获取一个无效的地理实例并将其转换为有效的实例。即使多重字符串无效,对MakeValid()的SQL调用也不会崩溃。对具有相同值的MakeValid()的C#调用不会崩溃。9行完全重叠的行不能被设置为有效,文档甚至明确声明在这种情况下它不能被设置为有效。@ChrisMiller需要编辑我以前的注释,文档间接声明此实例无法生效,因为当您有一个无法生效的地理实例时,重叠线在无穷多的点7处交叉,连接不应崩溃。对于原始帖子中的wkt字符串,从C#调用MakeValid()将返回一个有效实例。我更新了我的[ID]以包含该代码。