I want to compute the center coordinate in a group of coordinate but failed.
I use centroid()
function from geosphere
package.
The error says:
Error in .pointsToMatrix(x, poly = TRUE) : longitude > 360
centroid(shp_df_32[, c('long', 'lat')])
My data is from a .shp
file and I can make sure there is nothing wrong with longitude and latitude.
The data like this:
shp_df_32<-structure(list(long=c(432160.383200001,432160.4243,438190.699499998,
440661.0451,443819.3279,447998.9793,453969.978599999,457552.598900001,
457254.103500001,453372.979400001,449790.375799999,445013.5777,
442326.6472,442406.403099999,442723.2401,442508.252300002,
442508.2522,442397.620999999,442508.252099998,441711.732799999,
440806.212299999,439310.837200001,437198.180599999,436313.156300001,
434764.386799999,433215.608899999,431113.707800001,429011.7991,
427463.021299999,427131.144499999,427241.775800001,427794.906599998,
428790.545400001,429343.676199999,429233.053399999,428237.414700001,
426024.883299999,423591.089499999,421516.319600001,414628.938499998,
409306.8497,406176.2148,407428.447700001,409619.853,415254.9527,
419950.863899998,420890.011300001,420639.389899999,424485.255800001,
435084.911200002,436506.9692,440058.313299999,439920.870000001,
436856.204,432160.326299999,432160.383200001,409784.918099999,
402022.6371,399335.673999999,401687.016600002,404895.1877,
407882.104800001,412471.7916,415158.697799999,418442.733100001,
417949.1327,417617.2557,414561.715300001,409784.918099999),
lat=c(1338055.4351,1334631.8951,1334985.9718,1336925.9833,
1339406.2481,1342688.6348,1342688.6182,1340898.207,1336720.6226,
1334930.2354,1334930.2437,1334930.2595,1333438.2682,1329697.3513,
1327849.6704,1325176.7333,1322964.2036,1320419.7974,1318096.6358,
1315707.1044,1314364.083,1312953.6828,1313229.0686,1314445.9604,
1315552.2209,1315884.1058,1315994.7284,1316879.7436,1318539.1429,
1320198.5431,1321636.6886,1322411.0728,1323406.7107,1324512.9798,
1325840.4942,1327278.6406,1329159.2937,1330545.7319,1330545.7402,
1330545.7568,1331797.3977,1332736.119,1335865.1701,1338368.4044,
1341184.5351,1344000.6658,1348381.3344,1348520.4888,1349512.1621,
1352245.318,1352426.6858,1352879.6216,1352753.6966,1349945.8151,
1343374.8251,1338055.4351,1312848.7767,1310760.0011,1312848.8091,
1317432.873,1320309.165,1320862.3114,1320905.5647,1324784.7607,
1326276.7436,1320972.9269,1314224.7059,1313147.1568,1312848.7767
),order=1:69,hole=c(FALSE,FALSE,FALSE,FALSE,FALSE,
FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,
FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,
FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,
FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,
FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,
FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,
FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,
FALSE),piece=structure(c(1L,1L,1L,1L,1L,1L,1L,1L,
1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,
1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,
1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,
1L,1L,1L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,
2L),.Label=c("1","2","3","4","5","6","7","8","9",
"10","11","12","13","14","15","16","17","18","19",
"20","21"),class="factor"),group=structure(c(84L,
84L,84L,84L,84L,84L,84L,84L,84L,84L,84L,84L,84L,
84L,84L,84L,84L,84L,84L,84L,84L,84L,84L,84L,84L,
84L,84L,84L,84L,84L,84L,84L,84L,84L,84L,84L,84L,
84L,84L,84L,84L,84L,84L,84L,84L,84L,84L,84L,84L,
84L,84L,84L,84L,84L,84L,84L,85L,85L,85L,85L,85L,
85L,85L,85L,85L,85L,85L,85L,85L),.Label=c("0.1",
"1.1","2.1","2.2","3.1","4.1","5.1","5.2","5.3","5.4",
"5.5","5.6","5.7","5.8","5.9","6.1","7.1","8.1","8.2",
"8.3","9.1","9.2","10.1","10.2","10.3","10.4","10.5",
"10.6","10.7","10.8","10.9","10.10","10.11","10.12",
"10.13","10.14","10.15","10.16","10.17","10.18","10.19",
"10.20","10.21","11.1","12.1","12.2","12.3","12.4",
"12.5","12.6","12.7","12.8","13.1","14.1","15.1","16.1",
"17.1","18.1","18.2","18.3","18.4","18.5","18.6","18.7",
"18.8","18.9","18.10","18.11","19.1","20.1","21.1",
"22.1","23.1","24.1","25.1","26.1","27.1","28.1","29.1",
"30.1","31.1","31.2","31.3","32.1","32.2"),class="factor"),
id=c("32","32","32","32","32","32","32","32","32",
"32","32","32","32","32","32","32","32","32","32",
"32","32","32","32","32","32","32","32","32","32",
"32","32","32","32","32","32","32","32","32","32",
"32","32","32","32","32","32","32","32","32","32",
"32","32","32","32","32","32","32","32","32","32",
"32","32","32","32","32","32","32","32","32","32"
)),row.names=c(NA,-69L),class=c("tbl_df","tbl","data.frame"
))
How can I compute the center coordinate?
Do I need to reshape my data, if so, how can I do this?
Any help will be highly appreciated!