将类 sfc_MULTIPOLYGON/sfc 对象转换为 R 中的 sf/data.frame 对象

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

我有一个具有许多不同特征的 sf 对象,我正在尝试使用

sf::st_union()
合并成一个单一的特征。

library(dplyr)
library(sf)

streams <- structure(list(Cell = c(422, 61, 378, 307), Cluster = c(2L, 2L, 
3L, 1L), buff.area = c(314, 314, 314, 314), FEATURE_ID = c("ff8f986484cf48d58e5c46fc4236ec6e", 
"995647eea2cf4c6ead3d76a3b257c919", "5fbe3e130064495182c9fdbb4e39aa2d", 
"3a63895df52143ed81114faed3fed01e"), MD_ID = c(NA_character_, 
NA_character_, NA_character_, NA_character_), MD_TEMPORAL_EXTENT_DATE_MIN = c("2000", 
"2000", "2002", "2000"), MD_TEMPORAL_EXTENT_DATE_MAX = c("2000", 
"2000", "2002", "2000"), MD_HORIZ_POSITION_ACCURACY_MIN = c(26, 
28, 28, 30), MD_HORIZ_POSITION_ACCURACY_MAX = c(26, 28, 28, 30
), PERMANENCY = c(59L, 59L, 59L, 59L), LEVEL_PRIORITY = c(44L, 
44L, 44L, 44L), WATER_DEFINITION = c(91L, 91L, 91L, 91L), FLOW_DIRECTION = c(32L, 
32L, 32L, 32L), NAME_DB = c("CGNDB", NA, "CGNDB", NA), NAME_ID = c("41e2c322d05411d892e2080020a0f4c9", 
NA, "32db4cf3d05511d892e2080020a0f4c9", NA), NAME_EN = c("Medrick Creek", 
NA, "Ruby Creek", NA), NAME_FR = c("Medrick Creek", NA, "Ruby Creek", 
NA), NAME_OTHER = c(NA_character_, NA_character_, NA_character_, 
NA_character_), NAME_1_ID = c("41e2c322d05411d892e2080020a0f4c9", 
NA, "32db4cf3d05511d892e2080020a0f4c9", NA), NAME_1_EN = c("Medrick Creek", 
NA, "Ruby Creek", NA), NAME_1_FR = c("Medrick Creek", NA, "Ruby Creek", 
NA), NAME_2_ID = c(NA_character_, NA_character_, NA_character_, 
NA_character_), NAME_2_EN = c(NA_character_, NA_character_, NA_character_, 
NA_character_), NAME_2_FR = c(NA_character_, NA_character_, NA_character_, 
NA_character_), MAP_SELECTION = c(71L, 71L, 71L, 71L), COUNTRY = c(140L, 
140L, 140L, 140L), MD_TOPONYMIC_LINK_QUALITY = c(20L, 20L, 20L, 
20L), MD_NETWORK_QUALITY = c(20L, 20L, 20L, 20L), Shape_Length = c(2187.19525415184, 
1011.82351705742, 3836.56163228017, 1906.2275415346), geometry = structure(list(
    structure(list(structure(c(215898.808564305, 215898.278870635, 
    215897.75579585, 215897.240868751, 215896.735594327, 215896.241449357, 
    215895.759878087, 215895.292288019, 215894.840045787, 215894.404473171, 
    215894.335960294, 215893.931243147, 215893.544461947, 215893.176676835, 
    215892.828895884, 215892.502072338, 215892.197101997, 215891.914820763, 
    215891.656002351, 215891.421356163, 215891.211525348, 215891.027085038, 
    215890.86854077, 215890.736327105, 215890.630806429, 215890.552267969, 
    215890.500926992, 215890.476924221, 215890.480325445, 215890.511121342, 
    215890.569227503, 215890.654484662, 215890.766659136, 215890.905443462, 
    215891.070457242, 215891.261248185, 215891.477293346, 215891.71800056, 
    215891.982710065, 215892.270696312, 215892.581169949, 215892.913279991, 
    215893.266116146, 215893.638711315, 215894.030044242, 215894.439042308, 
    215894.86458448, 215895.305504376, 215895.760593465, 215896.228604378, 
    215896.708254332, 215897.198228639, 215897.697184313, 215898.203753751, 
    215898.716548482, 215899.234162971, 215899.755178473, 215900.27816692, 
    215900.801694838, 215901.324327273, 215901.844631725, 215902.361182077, 
    215902.872562499, 215903.054063105, 215919.267596484, 215919.78064163, 
    215920.287525218, 215920.786857913, 215921.277271081, 215921.757420532, 
    215922.22599021, 215922.681695798, 215923.123288239, 215923.549557159, 
    215923.959334185, 215924.351496145, 215924.724968151, 215925.078726543, 
    215925.411801694, 215925.723280666, 215926.012309719, 215926.278096644, 
    215926.519912937, 215926.737095796, 215926.929049939, 215927.095249232, 
    215927.235238135, 215927.348632948, 215927.435122864, 215927.494470819, 
    215927.526514146, 215927.531165015, 215927.508410679, 215927.458313506, 
    215927.381010808, 215927.276714468, 215927.145710354, 215926.98835754, 
    215926.805087318, 215926.596402019, 215926.362873635, 215926.105142252, 
    215925.823914293, 215925.519960585, 215925.194114243, 215924.84726839, 
    215924.480373705, 215924.094435823, 215923.690512571, 215923.269711075, 
    215922.833184724, 215922.382130004, 215921.917783227, 215921.441417134, 
    215920.954337411, 215920.457879111, 215919.953402991, 215919.442291784, 
    215918.925946412, 215918.40578214, 215917.883224704, 215917.359706396, 
    215916.836662144, 215916.315525577, 215915.797725092, 215898.808564305, 
    1060947.47954998, 1060947.58770217, 1060947.72432225, 1060947.88901093, 
    1060948.08128687, 1060948.30058809, 1060948.54627365, 1060948.81762546, 
    1060949.11385045, 1060949.43408283, 1060949.48736533, 1060949.81947538, 
    1060950.17231153, 1060950.5449067, 1060950.93623963, 1060951.34523769, 
    1060951.77077987, 1060952.21169976, 1060952.66678885, 1060953.13479976, 
    1060953.61444972, 1060954.10442402, 1060954.6033797, 1060955.10994914, 
    1060955.62274387, 1060956.14035836, 1060956.66137386, 1060957.18436231, 
    1060957.70789022, 1060958.23052266, 1060958.75082711, 1060959.26737746, 
    1060959.77875789, 1060960.28356672, 1060960.78042032, 1060961.26795685, 
    1060961.74484, 1060962.20976266, 1060962.66145053, 1060963.09866555, 
    1060963.52020934, 1060963.92492649, 1060964.31170769, 1060964.6794928, 
    1060965.02727375, 1060965.3540973, 1060965.65906764, 1060965.94134887, 
    1060966.20016728, 1060966.43481347, 1060966.64464429, 1060966.8290846, 
    1060966.98762886, 1060967.11984253, 1060967.2253632, 1060967.30390166, 
    1060967.35524264, 1060967.37924541, 1060967.37584419, 1060967.34504829, 
    1060967.28694213, 1060967.20168497, 1060967.0895105, 1060967.03961153, 
    1060964.18335259, 1060964.07905625, 1060963.94805213, 1060963.79069932, 
    1060963.6074291, 1060963.3987438, 1060963.16521541, 1060962.90748403, 
    1060962.62625607, 1060962.32230236, 1060961.99645602, 1060961.64961017, 
    1060961.28271548, 1060960.8967776, 1060960.49285435, 1060960.07205285, 
    1060959.6355265, 1060959.18447178, 1060958.72012501, 1060958.24375891, 
    1060957.75667919, 1060957.26022089, 1060956.75574477, 1060956.24463356, 
    1060955.72828819, 1060955.20812392, 1060954.68556648, 1060954.16204818, 
    1060953.63900392, 1060953.11786736, 1060952.60006687, 1060952.08702172, 
    1060951.58013814, 1060951.08080544, 1060950.59039227, 1060950.11024282, 
    1060949.64167315, 1060949.18596756, 1060948.74437512, 1060948.3181062, 
    1060947.90832917, 1060947.51616721, 1060947.1426952, 1060946.78893681, 
    1060946.45586166, 1060946.14438269, 1060945.85535364, 1060945.58956671, 
    1060945.34775042, 1060945.13056756, 1060944.93861342, 1060944.77241412, 
    1060944.63242522, 1060944.51903041, 1060944.43254049, 1060944.37319254, 
    1060944.34114921, 1060944.33649834, 1060944.35925268, 1060944.40934985, 
    1060944.48665255, 1060947.47954998), dim = c(126L, 2L))), class = c("XY", 
    "POLYGON", "sfg")), structure(list(structure(c(216223.172290931, 
    216223.207408595, 216223.224405453, 216223.21399355, 216223.176201422, 
    216223.111132656, 216223.018965599, 216222.899952877, 216222.754420694, 
    216222.582767945, 216222.385465116, 216222.163053002, 216221.916141219, 
    216221.645406535, 216221.351591015, 216221.035499986, 216220.697999832, 
    216220.340015618, 216219.962528554, 216219.566573305, 216219.153235157, 
    216218.723647042, 216218.27898643, 216217.820472105, 216217.349360823, 
    216216.866943868, 216216.374543511, 216215.873509386, 216215.365214795, 
    216214.851052936, 216214.332433091, 216213.810776763, 216213.287513774, 
    216212.764078351, 216212.241905196, 216211.722425548, 216211.207063265, 
    216210.697230919, 216210.194325925, 216209.699726711, 216209.214788939, 
    216208.740841789, 216208.279184318, 216207.831081897, 216207.397762743, 
    216206.980414554, 216206.580181253, 216206.198159851, 216205.835397442, 
    216205.492888333, 216205.171571317, 216204.872327102, 216204.595975896, 
    216204.343275158, 216204.114917523, 216203.911528904, 216203.733666774, 
    216203.581818642, 216203.456400712, 216203.357756747, 216203.286157123, 
    216203.241798089, 216203.153294747, 216203.136118023, 216203.155592511, 
    216203.211646834, 216205.289576461, 216205.367387407, 216205.472187314, 
    216205.603688934, 216205.76153183, 216205.945283366, 216206.15443989, 
    216206.388428121, 216206.646606711, 216206.928268013, 216207.232640011, 
    216207.558888443, 216207.906119085, 216208.273380202, 216208.659665156, 
    216209.063915168, 216209.485022216, 216209.921832075, 216210.37314748, 
    216210.837731407, 216211.314310462, 216211.801578377, 216212.298199584, 
    216212.802812877, 216213.314035149, 216213.830465173, 216214.350687451, 
    216214.873276091, 216215.396798711, 216215.919820375, 216216.440907515, 
    216216.958631868, 216217.471574388, 216217.978329134, 216218.477507128, 
    216218.967740156, 216219.447684525, 216219.916024741, 216220.371477114, 
    216220.812793282, 216221.238763629, 216221.648220598, 216222.040041897, 
    216222.413153571, 216222.766532946, 216223.099211435, 216223.410277188, 
    216223.698877597, 216223.964221627, 216224.20558199, 216224.422297132, 
    216224.613773053, 216224.77948493, 216224.91897856, 216225.031871599, 
    216225.117854616, 216225.176691937, 216225.208222292, 216225.212359261, 
    216225.189091503, 216225.138482794, 216223.172290931, 1076404.91789056, 
    1076404.31982046, 1076403.79655747, 1076403.27312205, 1076402.75094889, 
    1076402.23146925, 1076401.71610696, 1076401.20627462, 1076400.70336962, 
    1076400.20877041, 1076399.72383264, 1076399.24988549, 1076398.78822802, 
    1076398.34012559, 1076397.90680644, 1076397.48945825, 1076397.08922495, 
    1076396.70720355, 1076396.34444114, 1076396.00193203, 1076395.68061501, 
    1076395.3813708, 1076395.10501959, 1076394.85231886, 1076394.62396122, 
    1076394.4205726, 1076394.24271047, 1076394.09086234, 1076393.96544441, 
    1076393.86680044, 1076393.79520082, 1076393.75084179, 1076393.73384493, 
    1076393.74425683, 1076393.78204896, 1076393.84711773, 1076393.93928478, 
    1076394.0582975, 1076394.20382969, 1076394.37548244, 1076394.57278526, 
    1076394.79519738, 1076395.04210916, 1076395.31284385, 1076395.60665937, 
    1076395.92275039, 1076396.26025055, 1076396.61823476, 1076396.99572183, 
    1076397.39167708, 1076397.80501522, 1076398.23460334, 1076398.67926395, 
    1076399.13777828, 1076399.60888956, 1076400.09130651, 1076400.58370687, 
    1076401.08474099, 1076401.59303559, 1076402.10719744, 1076402.62581729, 
    1076403.14747362, 1076404.65472658, 1076405.25988584, 1076405.86497552, 
    1076406.46777789, 1076423.27655363, 1076423.79427798, 1076424.3072205, 
    1076424.81397524, 1076425.31315324, 1076425.80338627, 1076426.28333064, 
    1076426.75167085, 1076427.20712322, 1076427.64843939, 1076428.07440974, 
    1076428.48386671, 1076428.87568801, 1076429.24879968, 1076429.60217906, 
    1076429.93485755, 1076430.2459233, 1076430.53452371, 1076430.79986774, 
    1076431.0412281, 1076431.25794324, 1076431.44941916, 1076431.61513104, 
    1076431.75462467, 1076431.86751771, 1076431.95350073, 1076432.01233805, 
    1076432.0438684, 1076432.04800537, 1076432.02473761, 1076431.9741289, 
    1076431.89631796, 1076431.79151805, 1076431.66001643, 1076431.50217353, 
    1076431.318422, 1076431.10926547, 1076430.87527724, 1076430.61709865, 
    1076430.33543735, 1076430.03106535, 1076429.70481692, 1076429.35758628, 
    1076428.99032516, 1076428.60404021, 1076428.1997902, 1076427.77868315, 
    1076427.34187329, 1076426.89055788, 1076426.42597396, 1076425.9493949, 
    1076425.46212699, 1076424.96550578, 1076424.46089249, 1076423.94967022, 
    1076423.43324019, 1076422.91301791, 1076422.39042927, 1076421.86690665, 
    1076421.34388499, 1076420.82279785, 1076404.91789056), dim = c(128L, 
    2L))), class = c("XY", "POLYGON", "sfg")), structure(list(
        structure(c(166948.302569464, 166951.957876553, 166952.311104777, 
        166952.684072739, 166953.075758162, 166953.485087462, 
        166953.910938697, 166954.352144638, 166954.80749597, 
        166955.275744607, 166955.755607111, 166956.245768214, 
        166956.744884417, 166957.251587677, 166957.764489157, 
        166958.282183029, 166958.80325033, 166959.32626285, 166959.849787049, 
        166960.372387984, 166960.892633241, 166961.409096865, 
        166961.920363264, 166962.425031093, 166962.921717093, 
        166963.409059881, 166963.885723685, 166964.350402002, 
        166964.801821183, 166965.238743917, 166965.65997263, 
        166966.064352764, 166966.450775941, 166966.818183001, 
        166967.165566908, 166967.491975506, 166967.796514132, 
        166968.078348067, 166968.336704823, 166968.570876263, 
        166968.780220539, 166968.964163853, 166969.122202029, 
        166969.253901896, 166969.358902472, 166969.43691596, 
        166969.487728529, 166969.511200906, 166969.507268754, 
        166969.475942852, 166969.417309061, 166969.331528092, 
        166969.218835066, 166969.079538866, 166968.914021293, 
        166968.722736019, 166968.506207344, 166968.265028759, 
        166967.999861316, 166967.711431821, 166967.40053084, 
        166967.06801053, 166962.596866988, 166962.263061562, 
        166961.911525635, 166961.543122341, 166961.158756226, 
        166960.759371033, 166952.087626784, 166951.650414856, 
        166951.198729831, 166950.733809746, 166950.256928914, 
        166949.769394434, 166949.272542602, 166948.767735256, 
        166948.256356036, 166947.739806599, 166947.21950277, 
        166946.696870666, 166946.173342784, 166945.650354079, 
        166945.129338027, 166944.611722695, 166944.098926833, 
        166943.592355976, 166943.093398602, 166942.603422317, 
        166942.123770113, 166941.655756682, 166941.200664818, 
        166940.759741894, 166940.334196451, 166939.925194879, 
        166939.533858223, 166939.161259108, 166938.808418805, 
        166938.476304422, 166938.165826263, 166937.877835327, 
        166937.613120977, 166937.372408776, 166937.156358501, 
        166936.965562329, 166936.80054322, 166936.661753479, 
        166936.54957352, 166936.464310821, 166936.406199079, 
        166936.375397577, 166936.371990737, 166936.395987899, 
        166936.447323287, 166936.525856196, 166936.631371371, 
        166936.763579603, 166936.922118519, 166937.106553574, 
        166937.316379244, 166937.551020412, 166937.809833943, 
        166938.092110447, 166938.397076224, 166938.723895384, 
        166939.071672137, 166939.439453253, 166939.826230669, 
        166940.230944254, 166940.652484717, 166948.302569464, 
        1041773.45172956, 1041777.66701958, 1041778.05344276, 
        1041778.42084982, 1041778.76823373, 1041779.09464233, 
        1041779.39918095, 1041779.68101489, 1041779.93937164, 
        1041780.17354308, 1041780.38288736, 1041780.56683067, 
        1041780.72486885, 1041780.85656872, 1041780.96156929, 
        1041781.03958278, 1041781.09039535, 1041781.11386773, 
        1041781.10993557, 1041781.07860967, 1041781.01997588, 
        1041780.93419491, 1041780.82150189, 1041780.68220569, 
        1041780.51668811, 1041780.32540284, 1041780.10887416, 
        1041779.86769558, 1041779.60252814, 1041779.31409864, 
        1041779.00319766, 1041778.67067735, 1041778.31744913, 
        1041777.94448116, 1041777.55279574, 1041777.14346644, 
        1041776.71761521, 1041776.27640927, 1041775.82105793, 
        1041775.3528093, 1041774.87294679, 1041774.38278569, 
        1041773.88366949, 1041773.37696623, 1041772.86406475, 
        1041772.34637087, 1041771.82530357, 1041771.30229105, 
        1041770.77876685, 1041770.25616592, 1041769.73592066, 
        1041769.21945704, 1041768.70819064, 1041768.20352281, 
        1041767.70683681, 1041767.21949402, 1041766.74283022, 
        1041766.2781519, 1041765.82673272, 1041765.38980999, 
        1041764.96858127, 1041764.56420114, 1041759.40809078, 
        1041759.04188614, 1041758.69266646, 1041758.36128917, 
        1041758.04856791, 1041757.75527051, 1041751.71188596, 
        1041751.42389503, 1041751.15918068, 1041750.91846848, 
        1041750.7024182, 1041750.51162203, 1041750.34660292, 
        1041750.20781318, 1041750.09563322, 1041750.01037052, 
        1041749.95225878, 1041749.92145728, 1041749.91805044, 
        1041749.9420476, 1041749.99338299, 1041750.07191589, 
        1041750.17743107, 1041750.3096393, 1041750.46817822, 
        1041750.65261327, 1041750.86243894, 1041751.09708011, 
        1041751.35589364, 1041751.63817015, 1041751.94313592, 
        1041752.26995508, 1041752.61773184, 1041752.98551295, 
        1041753.37229037, 1041753.77700395, 1041754.19854442, 
        1041754.63575634, 1041755.08744137, 1041755.55236145, 
        1041756.02924229, 1041756.51677677, 1041757.0136286, 
        1041757.51843594, 1041758.02981516, 1041758.5463646, 
        1041759.06666843, 1041759.58930053, 1041760.11282842, 
        1041760.63581712, 1041761.15683317, 1041761.6744485, 
        1041762.18724437, 1041762.69381522, 1041763.1927726, 
        1041763.68274888, 1041764.16240109, 1041764.63041452, 
        1041765.08550638, 1041765.52642931, 1041765.95197475, 
        1041766.36097632, 1041766.75231298, 1041767.12491209, 
        1041767.4777524, 1041767.80986678, 1041768.12034494, 
        1041773.45172956), dim = c(130L, 2L))), class = c("XY", 
    "POLYGON", "sfg")), structure(list(structure(c(219029.923763594, 
    219029.701917934, 219029.505194673, 219029.334133016, 219029.189201833, 
    219029.070798367, 219028.979247157, 219028.914799136, 219028.877630953, 
    219028.867844482, 219028.885466549, 219028.930448851, 219029.002668096, 
    219029.101926336, 219029.227951511, 219029.380398195, 219029.558848541, 
    219029.76281343, 219029.991733808, 219030.244982221, 219030.521864531, 
    219030.821621825, 219031.143432488, 219031.486414459, 219031.849627648, 
    219032.232076515, 219032.632712792, 219033.050438363, 219033.484108272, 
    219033.932533861, 219034.394486024, 219034.868698584, 219035.353871757, 
    219035.848675717, 219036.351754241, 219036.861728425, 219037.377200466, 
    219037.89675749, 219038.418975429, 219038.942422918, 219039.465665225, 
    219039.987268179, 219040.505802102, 219041.01984573, 219041.527990103, 
    219042.028842435, 219042.521029922, 219043.003203515, 219043.474041607, 
    219043.932253666, 219044.376583763, 219044.80581402, 219045.218767948, 
    219045.614313668, 219045.991367017, 219046.348894518, 219046.685916213, 
    219047.001508348, 219047.294805908, 219047.565004985, 219047.811364981, 
    219055.926402316, 219056.148247976, 219056.344971237, 219056.516032893, 
    219056.660964077, 219056.779367543, 219056.870918753, 219056.935366774, 
    219056.972534957, 219056.982321428, 219056.964699361, 219056.919717059, 
    219056.847497814, 219056.748239574, 219056.622214399, 219056.469767715, 
    219056.291317369, 219056.08735248, 219055.858432102, 219055.605183689, 
    219055.328301379, 219055.028544085, 219054.706733422, 219054.363751451, 
    219054.000538262, 219053.618089395, 219053.217453118, 219052.799727547, 
    219052.366057637, 219051.917632049, 219051.455679886, 219050.981467326, 
    219050.496294153, 219050.001490193, 219049.498411669, 219048.988437485, 
    219048.472965444, 219047.95340842, 219047.431190481, 219046.907742992, 
    219046.384500685, 219045.862897731, 219045.344363808, 219044.83032018, 
    219044.322175807, 219043.821323475, 219043.329135988, 219042.846962395, 
    219042.376124303, 219041.917912244, 219041.473582147, 219041.04435189, 
    219040.631397962, 219040.235852242, 219039.858798893, 219039.501271392, 
    219039.164249697, 219038.848657562, 219038.555360002, 219038.285160925, 
    219038.038800929, 219029.923763594, 1026885.21341266, 1026885.68762522, 
    1026886.17279839, 1026886.66760235, 1026887.17068087, 1026887.68065506, 
    1026888.1961271, 1026888.71568412, 1026889.23790206, 1026889.76134955, 
    1026890.28459186, 1026890.80619481, 1026891.32472874, 1026891.83877236, 
    1026892.34691674, 1026892.84776907, 1026893.33995656, 1026893.82213015, 
    1026894.29296824, 1026894.7511803, 1026895.1955104, 1026895.62474065, 
    1026896.03769458, 1026896.4332403, 1026896.81029365, 1026897.16782115, 
    1026897.50484285, 1026897.82043498, 1026898.11373254, 1026898.38393162, 
    1026898.63029161, 1026898.85213727, 1026899.04886053, 1026899.21992219, 
    1026899.36485338, 1026899.48325684, 1026899.57480805, 1026899.63925607, 
    1026899.67642426, 1026899.68621073, 1026899.66858866, 1026899.62360636, 
    1026899.55138711, 1026899.45212887, 1026899.3261037, 1026899.17365701, 
    1026898.99520667, 1026898.79124178, 1026898.5623214, 1026898.30907299, 
    1026898.03219068, 1026897.73243338, 1026897.41062272, 1026897.06764075, 
    1026896.70442756, 1026896.32197869, 1026895.92134242, 1026895.50361684, 
    1026895.06994694, 1026894.62152135, 1026894.15956918, 1026877.93376846, 
    1026877.4595559, 1026876.97438272, 1026876.47957876, 1026875.97650024, 
    1026875.46652605, 1026874.95105401, 1026874.43149699, 1026873.90927905, 
    1026873.38583156, 1026872.86258925, 1026872.3409863, 1026871.82245238, 
    1026871.30840875, 1026870.80026438, 1026870.29941204, 1026869.80722456, 
    1026869.32505096, 1026868.85421287, 1026868.39600081, 1026867.95167072, 
    1026867.52244046, 1026867.10948653, 1026866.71394081, 1026866.33688746, 
    1026865.97935996, 1026865.64233827, 1026865.32674613, 1026865.03344857, 
    1026864.76324949, 1026864.5168895, 1026864.29504384, 1026864.09832058, 
    1026863.92725892, 1026863.78232774, 1026863.66392427, 1026863.57237306, 
    1026863.50792504, 1026863.47075686, 1026863.46097039, 1026863.47859245, 
    1026863.52357476, 1026863.595794, 1026863.69505224, 1026863.82107742, 
    1026863.9735241, 1026864.15197445, 1026864.35593933, 1026864.58485971, 
    1026864.83810812, 1026865.11499044, 1026865.41474773, 1026865.73655839, 
    1026866.07954036, 1026866.44275355, 1026866.82520242, 1026867.2258387, 
    1026867.64356427, 1026868.07723418, 1026868.52565976, 1026868.98761193, 
    1026885.21341266), dim = c(123L, 2L))), class = c("XY", "POLYGON", 
    "sfg"))), n_empty = 0L, precision = 0, crs = structure(list(
    input = "EPSG:3578", wkt = "PROJCRS[\"NAD83 / Yukon Albers\",\n    BASEGEOGCRS[\"NAD83\",\n        DATUM[\"North American Datum 1983\",\n            ELLIPSOID[\"GRS 1980\",6378137,298.257222101,\n                LENGTHUNIT[\"metre\",1]]],\n        PRIMEM[\"Greenwich\",0,\n            ANGLEUNIT[\"degree\",0.0174532925199433]],\n        ID[\"EPSG\",4269]],\n    CONVERSION[\"Yukon Albers\",\n        METHOD[\"Albers Equal Area\",\n            ID[\"EPSG\",9822]],\n        PARAMETER[\"Latitude of false origin\",59,\n            ANGLEUNIT[\"degree\",0.0174532925199433],\n            ID[\"EPSG\",8821]],\n        PARAMETER[\"Longitude of false origin\",-132.5,\n            ANGLEUNIT[\"degree\",0.0174532925199433],\n            ID[\"EPSG\",8822]],\n        PARAMETER[\"Latitude of 1st standard parallel\",61.6666666666667,\n            ANGLEUNIT[\"degree\",0.0174532925199433],\n            ID[\"EPSG\",8823]],\n        PARAMETER[\"Latitude of 2nd standard parallel\",68,\n            ANGLEUNIT[\"degree\",0.0174532925199433],\n            ID[\"EPSG\",8824]],\n        PARAMETER[\"Easting at false origin\",500000,\n            LENGTHUNIT[\"metre\",1],\n            ID[\"EPSG\",8826]],\n        PARAMETER[\"Northing at false origin\",500000,\n            LENGTHUNIT[\"metre\",1],\n            ID[\"EPSG\",8827]]],\n    CS[Cartesian,2],\n        AXIS[\"(E)\",east,\n            ORDER[1],\n            LENGTHUNIT[\"metre\",1]],\n        AXIS[\"(N)\",north,\n            ORDER[2],\n            LENGTHUNIT[\"metre\",1]],\n    USAGE[\n        SCOPE[\"Territory-wide spatial data management.\"],\n        AREA[\"Canada - Yukon.\"],\n        BBOX[59.99,-141.01,69.7,-123.91]],\n    ID[\"EPSG\",3578]]"), class = "crs"), class = c("sfc_POLYGON", 
"sfc"), bbox = structure(c(xmin = 166936.371990737, ymin = 1026863.46097039, 
xmax = 219056.982321428, ymax = 1076432.04800537), class = "bbox"))), row.names = c(68L, 
7L, 58L, 55L), sf_column = "geometry", agr = structure(c(Cell = NA_integer_, 
Cluster = NA_integer_, buff.area = NA_integer_, FEATURE_ID = NA_integer_, 
MD_ID = NA_integer_, MD_TEMPORAL_EXTENT_DATE_MIN = NA_integer_, 
MD_TEMPORAL_EXTENT_DATE_MAX = NA_integer_, MD_HORIZ_POSITION_ACCURACY_MIN = NA_integer_, 
MD_HORIZ_POSITION_ACCURACY_MAX = NA_integer_, PERMANENCY = NA_integer_, 
LEVEL_PRIORITY = NA_integer_, WATER_DEFINITION = NA_integer_, 
FLOW_DIRECTION = NA_integer_, NAME_DB = NA_integer_, NAME_ID = NA_integer_, 
NAME_EN = NA_integer_, NAME_FR = NA_integer_, NAME_OTHER = NA_integer_, 
NAME_1_ID = NA_integer_, NAME_1_EN = NA_integer_, NAME_1_FR = NA_integer_, 
NAME_2_ID = NA_integer_, NAME_2_EN = NA_integer_, NAME_2_FR = NA_integer_, 
MAP_SELECTION = NA_integer_, COUNTRY = NA_integer_, MD_TOPONYMIC_LINK_QUALITY = NA_integer_, 
MD_NETWORK_QUALITY = NA_integer_, Shape_Length = NA_integer_), class = "factor", levels = c("constant", 
"aggregate", "identity")), class = c("sf", "data.frame"))

class(streams) ## output is '[1] "sf"         "data.frame"'

streams_merged <- streams %>% sf::st_union() 
class(streams_merged) ## output is [1] "sfc_MULTIPOLYGON" "sfc"  

然后,我想将其转换为与

streams
相同的对象类型(
[1] "sf"         "data.frame"
所以我可以执行以下操作:

water <- streams_merged %>% 
mutate(water.area = st_area(geometry))

但是,我收到以下错误消息:

Error in UseMethod("mutate") :  no applicable method for 'mutate' applied to an object of class "c('sfc_MULTIPOLYGON', 'sfc')"

如何将其转换为具有可用于计算面积的“几何”字段的数据框?

谢谢! (对于定义

streams
的非常长的代码块表示歉意;它只有 4 行长,但 sf 对象有很多事情要做!)

r gis sf
1个回答
0
投票

在您的用例中,我建议使用

dplyr::summarise()
- 没有任何 group_by - 将所有功能合并为一个。它将在引擎盖下运行聚合,隐藏在视线之外。

还可以考虑使用 {magrittr} 管道语法中定义的点占位符来计算面积。我发现它比指定几何列更简洁 - 也更安全,因为您不能依赖名为“几何”的几何列。

streams_merged <- streams %>% 
  summarise() %>% # not an obvious geometry merge tool, but quite effective :)
  mutate(water_area = st_area(.)) # note the dot

streams_merged
# Simple feature collection with 1 feature and 1 field
# Geometry type: MULTIPOLYGON
# Dimension:     XY
# Bounding box:  xmin: 166936.4 ymin: 1026863 xmax: 219057 ymax: 1076432
# Projected CRS: NAD83 / Yukon Albers
#                         geometry     water_area
# 1 MULTIPOLYGON (((219029.5 10... 2682.296 [m^2]
© www.soinside.com 2019 - 2024. All rights reserved.