在 R 中使用“sf”的几何图形无效

问题描述

我正在 R 中处理几个凌乱的多边形数据集,分析它们的重叠。我一直在使用 st_make_valid()st_buffer(.,0),即使在操作之间也是如此,这使它在大部分时间都有效,但并非总是如此。有没有更好的方法解决这个问题?

在下面的示例中,您可以看到一堆警告文本,因为数据集的这一部分有一个我无法弄清楚的错误。有人看到如何解决这个问题吗?或者 sf 还不够成熟,无法处理凌乱的多边形?我希望不要回到 ArcGIS。

数据:https://drive.google.com/file/d/1jyjd0PUwas2rr65U673ARO3ioWSzAxNS/view?usp=sharing

> library(sf)
> sf_extSoftVersion()
          GEOS           GDAL         proj.4 GDAL_with_GEOS     USE_PROJ_H           PROJ 
       "3.9.0"        "3.2.1"        "7.2.1"         "true"         "true"        "7.2.1" 
> x <- readr::read_rds("test.rds")
> y <- st_difference(x)
CBR: result (after common-bits addition) is INVALID: Too few points in geometry component at or near point 524026.3165404615 6223127.0403868062 (524026.31654046149924 6223127.0403868062422)
<A>
GEOMETRYCOLLECTION (LInesTRING (524001.5199999995529652 6223032.5054999999701977,524001.5191995144705288 6223032.5073106214404106),LInesTRING (524007.1028370644198731 6223022.7976465718820691,524007.0999999996274710 6223022.8019999992102385),LInesTRING (524007.1931435726000927 6223022.6854006359353662,524007.1935000000521541 6223022.6850000005215406),LInesTRING (524041.2595223853131756 6222991.1174365654587746,LInesTRING (524015.1124787582666613 6223059.9388074651360512,524015.2295000003650784 6223060.1355000007897615),LInesTRING (524015.2497644042596221 6223060.1788564007729292,LInesTRING (524019.8307690470246598 6223102.2192002190276980,524018.0599999995902181 6223095.2699999995529652),LInesTRING (524020.9234999995678663 6223090.4824999999254942,524020.9233499504625797 6223090.4817951181903481),LInesTRING (524022.2457240846124478 6223094.3838984025642276,524020.9254999998956919 6223090.4885000009089708),LInesTRING (524023.7168598303687759 6223098.6682394389063120,524023.7034999998286366 6223098.6465000007301569),524027.7220000000670552 6223105.1854999996721745),LInesTRING (524026.3195156208821572 6223127.0397623647004366,524027.2690203536185436 6223126.8404755238443613),LInesTRING (524032.8603034563711844 6223107.7374670980498195,524027.9320000000298023 6223105.3745000008493662),LInesTRING (524032.8817323940456845 6223125.6623838022351265,524032.9014999996870756 6223125.6524999998509884),524041.2595889328513294 6222991.1173748988658190),LInesTRING (524071.9728900013142265 6222962.6565751768648624,524071.9785379960085265 6222962.6504228971898556),LInesTRING (524087.5360038708313368 6222942.4320639260113239,524100.0175000000745058 6222926.2074999995529652),LInesTRING (524100.0188377899467014 6222926.2062013642862439,LInesTRING (524105.4569151145406067 6222923.2712370948866010,524105.4714999999850988 6222923.2620000001043081),LInesTRING (524105.4840000001713634 6222923.2514999993145466,524105.4839687446365133 6222923.2515262542292476),LInesTRING (524106.0977202362264507 6222922.6621401924639940,524105.4840000001713634 6222923.2514999993145466),524116.4304999997839332 6222912.7394999992102385),LInesTRING (524116.4503666275413707 6222912.7214394286274910,524116.4524999996647239 6222912.7194999996572733),LInesTRING (524127.6898321119369939 6222903.1375498538836837,524127.7280000001192093 6222903.0960000008344650),LInesTRING (524130.0325920286704786 6222899.9333801884204149,LInesTRING (524135.3636843980057165 6222894.4254943942651153,524141.6929999999701977 6222890.3379999995231628),LInesTRING (524148.1844609992112964 6222876.5345951458439231,524148.1849999995902181 6222876.5339999999850988),LInesTRING (524148.2289352609659545 6222880.9919013828039169,524148.2240000003948808 6222881.0225000008940697),polyGON ((524000.1080000000074506 6223028.4930000007152557,524000.4507480477914214 6223030.1859161183238029,524001.7230000002309680 6223036.4590000007301569,524012.5257197991595604 6223075.3501139236614108,524001.7209999999031425 6223036.4600000008940697,524018.0599999995902181 6223095.2699999995529652,524001.7599999997764826 6223036.4499999992549419,524000.1081744458642788 6223028.4928188351914287,524000.1080000000074506 6223028.4930000007152557)),polyGON ((524001.3689999999478459 6223032.7685000002384186,524006.2970854074810632 6223040.4996708156540990,524006.2970000002533197 6223040.4995000008493662,524001.5319999996572733 6223033.0240000002086163,524001.4780000001192093 6223032.9094999991357327,524001.4534999998286366 6223032.7550000008195639,524001.4780000001192093 6223032.6005000006407499,524001.5191995144705288 6223032.5073106214404106,524001.3689999999478459 6223032.7685000002384186)),polyGON ((524007.1289999997243285 6223022.7575000002980232,524007.1931435726000927 6223022.6854006359353662,524007.1380000002682209 6223022.7365000005811453,524007.1028370644198731 6223022.7976465718820691,524007.1289999997243285 6223022.7575000002980232)),polyGON ((524011.1454999996349216 6223053.2709999997168779,524011.1074999999254942 6223053.1925000008195639,524010.1901262202300131 6223050.7691002739593387,524011.1229999996721745 6223053.2335000000894070,524015.1124787582666613 6223059.9388074651360512,524011.1454999996349216 6223053.2709999997168779)),polyGON ((524018.7157164540840313 6223070.1585281584411860,524018.7154999999329448 6223070.1575000006705523,524015.2510000001639128 6223060.1815000008791685,524015.2497644042596221 6223060.1788564007729292,524018.7157164540840313 6223070.1585281584411860)),polyGON ((524026.3165404614992440 6223127.0403868062421679,524026.3165404614992440 6223127.0403868062421679,524026.3191622742451727 6223127.0398365268483758,524026.3165404614992440 6223127.0403868062421679)),polyGON ((524025.2319999998435378 6223123.4010000005364418,524019.8307690470246598 6223102.2192002190276980,524019.8307691288646311 6223102.2192005403339863,524025.2319999998435378 6223123.4010000005364418)),polyGON ((524020.9021244112518616 6223090.3820844450965524,524020.9079999998211861 6223090.4364999998360872,524020.9233499504625797 6223090.4817951181903481,524020.9021244112518616 6223090.3820844450965524)),polyGON ((524023.6560000004246831 6223098.5449999999254942,524022.2457240846124478 6223094.3838984025642276,524023.6739999996498227 6223098.5985000003129244,524023.7034999998286366 6223098.6465000007301569,524023.6560000004246831 6223098.5449999999254942)),polyGON ((524032.8815000001341105 6223125.6624999996274710,524032.8817323940456845 6223125.6623838022351265,524027.2690203536185436 6223126.8404755238443613,524032.8815000001341105 6223125.6624999996274710)),polyGON ((524027.7989999996498227 6223105.3104999996721745,524027.9300743502099067 6223105.3733520172536373,524027.8540000002831221 6223105.3279999997466803,524027.7434999998658895 6223105.2174999993294477,524027.7240944462828338 6223105.1886173151433468,524027.7989999996498227 6223105.3104999996721745)),polyGON ((524032.8603034563711844 6223107.7374670980498195,524036.5909106002072804 6223109.5263463603332639,524036.5894999997690320 6223109.5254999995231628,524032.8603034563711844 6223107.7374670980498195)),polyGON ((524071.9725000001490116 6222962.6569999996572733,524071.9728900013142265 6222962.6565751768648624,524041.2595889328513294 6222991.1173748988658190,524071.9725000001490116 6222962.6569999996572733)),polyGON ((524057.6575345923774876 6222968.6392319900915027,524058.1434287040610798 6222967.6911763837561011,524058.1419999999925494 6222967.6929999999701977,524057.7542887106537819 6222968.4498661318793893,524057.6575345923774876 6222968.6392319900915027)),polyGON ((524072.0005000000819564 6222962.6264999993145466,524087.5360038708313368 6222942.4320639260113239,524071.9978973806719296 6222962.6293349955230951,524072.0005000000819564 6222962.6264999993145466)),polyGON ((524100.0839999997988343 6222926.1215000003576279,524100.0188377899467014 6222926.2062013642862439,524100.1200000001117587 6222926.1079999990761280,524100.1794999996200204 6222926.0710000004619360,524105.4565000003203750 6222923.2715000007301569,524105.4569151145406067 6222923.2712370948866010,524100.0839999997988343 6222926.1215000003576279)),polyGON ((524116.4414999997243285 6222912.7290000002831221,524116.4317362851579674 6222912.7383761033415794,524116.4503666275413707 6222912.7214394286274910,524116.4414999997243285 6222912.7290000002831221)),polyGON ((524119.5630740086780861 6222910.0672345766797662,524127.6885000001639128 6222903.1390000004321337,524127.6898321119369939 6222903.1375498538836837,524119.5630740086780861 6222910.0672345766797662)),polyGON ((524132.8205000003799796 6222896.1074999999254942,524132.9304999997839332 6222895.9975000005215406,524132.9534999998286366 6222895.9820000007748604,524135.3636843980057165 6222894.4254943942651153,524132.8750000000000000 6222896.0325000006705523,524130.0325920286704786 6222899.9333801884204149,524132.8205000003799796 6222896.1074999999254942)),polyGON ((524141.7374999998137355 6222890.2939999997615814,524145.4648219592636451 6222884.9712702017277479,524141.7368781244149432 6222890.2946148877963424,524141.7374999998137355 6222890.2939999997615814)),polyGON ((524148.2290000002831221 6222880.9914999995380640,524148.0180000001564622 6222876.9334999993443489,524148.0175000000745058 6222876.9075000006705523,524148.0420000003650784 6222876.7530000004917383,524148.1129999998956919 6222876.6135000009089708,524148.1844609992112964 6222876.5345951458439231,524148.0054999999701977 6222876.6940000001341105,524148.2289352609659545 6222880.9919013828039169,524148.2290000002831221 6222880.9914999995380640)),polyGON ((524163.1365000000223517 6222866.6154999993741512,524163.1370747597538866 6222866.6149252392351627,524152.4254999998956919 6222872.7569999992847443,524149.6855060355737805 6222875.1975783342495561,524152.3870000001043081 6222872.7915000002831221,524152.4254999998956919 6222872.7605000007897615,524152.4709999999031425 6222872.7310000006109476,524163.1365000000223517 6222866.6154999993741512)),polyGON ((524168.5807173670618795 6222858.8735520010814071,524168.5815000003203750 6222858.8719999995082617,524170.1799999997019768 6222853.0134999994188547,524170.1803817074978724 6222853.0115914605557919,524168.5807173670618795 6222858.8735520010814071)))
</A>
> all(st_is_valid(x))
[1] TRUE

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)