Invalid geometry using ´sf´ in R - r

I am working with several messy polygon dataset in R, analysing thir overlap. I keep using st_make_valid() and st_buffer(., 0), even between operations, which makes it work most of the time, but not always. Is there a better way of solving this?
In the example below you can see a bunch of warning text, because this part of the dataset has an error in it that I cannot figure out. Does anybody see how to solve this? Or is sf not mature enough to work with messy polygons yet? I am hoping not to fall back to ArcGIS.
Data: 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, 524007.1935000000521541 6223022.6850000005215406), LINESTRING (524015.1124787582666613 6223059.9388074651360512, 524015.2295000003650784 6223060.1355000007897615), LINESTRING (524015.2497644042596221 6223060.1788564007729292, 524015.2295000003650784 6223060.1355000007897615), 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), LINESTRING (524023.7168598303687759 6223098.6682394389063120, 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), LINESTRING (524041.2595223853131756 6222991.1174365654587746, 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, 524100.0175000000745058 6222926.2074999995529652), 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), LINESTRING (524106.0977202362264507 6222922.6621401924639940, 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, 524127.7280000001192093 6222903.0960000008344650), 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

Related

radius in nn2() function in RANN r-package

I was trying to use the solution offered here to find all the location from df which are within the 70 km distance from my point of interest userLocation=c(6.9,55.2), but it does not work properly !
df = structure(list(lng = c(6.2694184, 6.25737207, 6.23839104, 6.25844252,
6.22595901, 6.21351832, 6.2010845, 6.1886414, 6.1762058, 6.1637609,
6.15132287, 6.13887619, 6.12643637, 6.14361895, 6.16332364, 6.18302157,
6.2027276, 6.22242688, 6.24213488, 6.26842752, 6.26745135, 6.24518597,
6.26645948, 6.24420242, 6.22357831, 6.26548171, 6.24321746, 6.2226023,
6.20041884, 6.18070459, 6.16099845, 6.16716672, 6.17960629, 6.18686265,
6.2078525, 6.19203657, 6.20447434, 6.21691835, 6.2293537, 6.24179593,
6.26009321, 6.26448764, 6.2422317, 6.21927538, 6.20186455, 6.26350828,
6.24124514, 6.22028969, 6.26251321, 6.2402584, 6.23404584, 6.26153227,
6.22171658, 5.94065657, 6.10363006, 6.11606487, 6.12850589, 6.14093826,
6.15337749, 6.16582359, 6.17826103, 6.19070472, 6.20313974, 6.20009703,
5.96044213, 5.96988333, 5.98023582, 5.98966667, 5.99910246, 6.00003829,
6.00947365, 6.01889843, 6.02832882, 6.01983402, 6.02925771, 6.038687,
6.0481219, 6.05754688, 6.03963788, 6.04906608, 6.05848435, 6.06792377,
6.07735326, 6.08677283, 6.05941948, 6.06885218, 6.07829049, 6.08771889,
6.09713671, 6.10657633, 6.11600538, 6.07922538, 6.08864707, 6.10756108,
6.12000483, 6.13243993, 6.12019786, 6.14488189, 6.15733073, 6.16977091,
6.16621949, 6.13805015, 6.13652024, 5.941545, 6.20491484, 6.18423897,
6.17806466, 6.16355552, 6.15738696, 6.14558294, 6.14286638, 6.13670293,
6.12217027, 6.11601258, 6.10148275, 6.09533146, 6.08080511, 6.07464337,
6.06011984, 6.03729438, 6.05394895, 6.02546329, 6.0136389, 6.03674112,
6.05743408, 6.07812006, 6.09879971, 6.11948795, 6.11063647, 6.08914275,
6.08440881, 6.0018212, 6.02491713, 5.98999461, 6.01308427, 5.97815849,
6.00125809, 5.96632973, 5.98943792, 5.9995124, 6.02119838, 6.04364466,
6.0223476, 6.04560587, 6.03821257, 6.06131821, 6.06046748, 5.97888909,
5.95766873, 6.24771247, 6.04931495, 6.25538943, 6.23227728, 6.25434093,
6.25329159, 6.25225759, 6.25120656, 6.25015469, 6.24911757, 6.06338238,
6.08539205, 6.10756976, 6.12975108, 6.15193667, 6.17411029, 6.19630377,
6.21848591, 6.22602495, 6.23123663, 6.20931486, 6.23019515, 6.20826628,
6.22915282, 6.20721685, 6.22810966, 6.21962063, 6.20209266, 6.20618216,
6.19702482, 6.1799057, 6.15772301, 6.13554395, 6.11336914, 6.09118237,
6.09738412, 6.11958004, 6.12698723, 6.14767387, 6.16835417, 6.18613747,
6.185096, 6.165456, 6.14476821, 6.15765091, 6.23561071, 6.08001353,
6.22353732, 6.2376767, 6.21143885, 6.19936347, 6.18727866, 6.17520066,
6.16311385, 6.15103386, 6.13894506, 6.12686243, 6.11478725, 6.10270261,
6.09818625, 6.12128852, 6.2468456, 6.22571713, 6.24558662, 6.22445138,
6.24434288, 6.22320086, 6.24308194, 6.22194875, 6.24182062, 6.22068065,
6.24057332, 6.21942655, 6.2113264, 6.22341814, 6.19699748, 6.18490568,
6.1988361, 6.17283631, 6.16074252, 6.14867115, 6.13657473, 6.13954049,
6.16263694, 6.18482009, 6.20327221, 6.20009595, 6.19278885, 6.17005571
), lat = c(54.67598304, 54.83924292, 54.83162024, 54.82483795,
54.82033259, 54.80904336, 54.79775292, 54.78646988, 54.77517665,
54.76389082, 54.75260377, 54.74131515, 54.73002531, 54.72096456,
54.71392047, 54.70687309, 54.69983176, 54.69278713, 54.68573957,
54.68934722, 54.7027117, 54.69910571, 54.71606682, 54.71246092,
54.70614626, 54.72943123, 54.72582507, 54.71951053, 54.71576339,
54.72280423, 54.72985112, 54.74274399, 54.75402944, 54.73569581,
54.72983408, 54.7653223, 54.77660496, 54.78789538, 54.79918423,
54.81047187, 54.80230996, 54.74279524, 54.73918917, 54.74155047,
54.75043676, 54.75615956, 54.75255324, 54.75849353, 54.76951451,
54.76590829, 54.77879358, 54.78287875, 54.84106585, 54.79004116,
54.73264696, 54.7439301, 54.755221, 54.76651031, 54.77779842,
54.78908531, 54.80037062, 54.81166369, 54.82295519, 54.83631649,
54.78306731, 54.79535153, 54.77609951, 54.7883729, 54.80065457,
54.76912877, 54.78140068, 54.7936805, 54.80595963, 54.7621547,
54.77443373, 54.78671208, 54.79898973, 54.81126633, 54.75518666,
54.76746422, 54.77974071, 54.7920169, 54.80429202, 54.81656608,
54.74821493, 54.76049101, 54.7727664, 54.78504073, 54.79732298,
54.80959594, 54.82187682, 54.74124062, 54.75351485, 54.76118719,
54.77247897, 54.78376916, 54.79513973, 54.79505815, 54.80634591,
54.8176321, 54.8309898, 54.82587825, 54.81251828, 54.80340625,
54.85043439, 54.85669012, 54.84379843, 54.8629602, 54.85006754,
54.83850747, 54.86921769, 54.85633303, 54.87548056, 54.86259492,
54.88174916, 54.86885358, 54.88800555, 54.8751176, 54.89427628,
54.89688611, 54.88137801, 54.88534048, 54.87379377, 54.87235508,
54.86608859, 54.85982748, 54.85356275, 54.84730376, 54.83491117,
54.82992904, 54.84309445, 54.86224596, 54.86080945, 54.85069668,
54.84926234, 54.8391549, 54.83771415, 54.82760306, 54.82617384,
54.81401612, 54.81866848, 54.82193287, 54.83203, 54.85454492,
54.8418856, 54.84463218, 54.83126946, 54.807705, 54.81314447,
54.95082492, 54.90870481, 54.85261135, 54.8544958, 54.86597391,
54.87933643, 54.89269028, 54.90605271, 54.91941509, 54.93277779,
54.91930405, 54.92337651, 54.92712528, 54.93087901, 54.93462874,
54.93838307, 54.94213376, 54.94588009, 54.93325056, 54.86785843,
54.86365241, 54.88122101, 54.87701472, 54.89458354, 54.890377,
54.90794604, 54.9204011, 54.92916856, 54.90373959, 54.91606989,
54.92541899, 54.92166542, 54.91791682, 54.91416421, 54.91041621,
54.89753741, 54.90128459, 54.88863077, 54.8823668, 54.87609923,
54.88468492, 54.89804726, 54.89094652, 54.89720452, 54.90830415,
55.08370977, 54.93641839, 55.07226944, 55.06170442, 55.06083624,
55.04939327, 55.03795778, 55.02652115, 55.01508302, 55.00364374,
54.99220296, 54.98077001, 54.96932695, 54.95789135, 54.94469353,
54.94333719, 54.96418243, 54.9585686, 54.97754901, 54.9719349,
54.99090692, 54.98529252, 55.00427341, 54.99865908, 55.01763087,
55.01201625, 55.03099761, 55.02538271, 55.03790915, 55.04934232,
55.02208092, 55.01064489, 54.99998971, 54.99920808, 54.98776941,
54.97632995, 54.9648976, 54.95153594, 54.95007267, 54.95382515,
54.96186591, 54.98662348, 54.97394968, 54.97118391)), class = "data.frame", row.names = c(NA,
-238L))
What I have done is as follow :
Add the point of interest to the beginning of df
df = rbind(userLocation,df)
Set the radius to 0.64 since according to here, every 0.1 is equivalent to 11.1 km !
radius <- 0.64
#Identifying neighbors
res <- nn2(df, k=nrow(df), searchtype="radius", radius = radius)
Since my point of interest is the first row in df I would expect all the non zero index in the first row are the points within my 70 km threshold
Ind <- res$nn.idx[1,][res$nn.idx[1,]>0]
My Ind object has just one value!
Ind
[1] 1
but if I plot the data, all of the points are within 70 km distance :
I would appreciate it if someone could help me here.

Calculating polygon intersecting area with gArea and gIntersection error in R

I have two polygons
coords1[,1]
-15.99719 -16.01133 -16.04000 -16.08308 -16.14041 -16.21175 -16.29681 -16.39525 -16.50668 -16.63064 -16.76664 -16.91413 -17.07252 -17.24116 -17.41939 -17.60647 -17.80166 -18.00417 -18.21319 -18.42788 -18.64736 -18.87076 -19.09718 -19.32570 -19.55541 -19.78538 -20.01468 -20.24240 -20.46760 -20.68940 -20.90688 -21.11919 -21.32546 -21.52486 -21.71659 -21.89988 -22.07399 -22.23822 -22.39191 -22.53443 -22.66522 -22.78374 -22.88953 -22.98215 -23.06124 -23.12646 -23.17757 -23.21435 -23.23666 -23.24441 -23.23756 -23.21615 -23.18025 -23.13002 -23.06566 -22.98742 -22.89562 -22.79063 -22.67288 -22.54283 -22.40101 -22.24800 -22.08440 -21.91088 -21.72813 -21.53690 -21.33795 -21.13208-20.92012 -20.70293 -20.48137 -20.25635 -20.02876 -19.79953 -19.56958 -19.33983 -19.11120 -18.88463 -18.66102 -18.44127 -18.22626 -18.01687 -17.81393 -17.61826 -17.43066 -17.25187 -17.08262 -16.92358 -16.77540 -16.63868 -16.51396 -16.40174 -16.30249 -16.21659 -16.14440 -16.08620 -16.04224 -16.01268 -15.99764 -15.99719
coords1[,2]
6.225418 6.262789 6.300443 6.338229 6.375996 6.413591 6.450863 6.487662 6.523839 6.559250 6.593750 6.627202 6.659471 6.690426 6.719943 6.747904 6.774196 6.798712 6.821354 6.842031 6.860660 6.877166 6.891481 6.903550 6.913322 6.920758 6.925830 6.928515 6.928804 6.926696 6.922198 6.915329 6.906116 6.894597 6.880818 6.864834 6.846711 6.826520 6.804343 6.780269 6.754396 6.726828 6.697675 6.667055 6.635091 6.601912 6.567652 6.532448 6.496442 6.459780 6.422608 6.385077 6.347338 6.309542 6.271842 6.234389 6.197335 6.160829 6.125017 6.090044 6.056051 6.023174 5.991546 5.961295 5.932541 5.905401 5.879985 5.856394 5.834723 5.815060 5.797484 5.782066 5.768867 5.757941 5.749333 5.743075 5.739195 5.737707 5.738617 5.741922 5.747609 5.755654 5.766025 5.778680 5.793569 5.810631 5.829798 5.850993 5.874129 5.899115 5.925849 5.954224 5.984126 6.015434 6.048021 6.081758 6.116508 6.152130 6.188483 6.225418
coords1.sys[,1]
-17.27076 -17.28943 -17.32370 -17.37346 -17.43849 -17.51853 -17.61326 -17.72229 -17.84520 -17.98148 -18.13059 -18.29192 -18.46483 -18.64862 -18.84254 -19.04583 -19.25765 -19.47717 -19.70348 -19.93569 -20.17285 -20.41402 -20.65821 -20.90445 -21.15175 -21.39911 -21.64554 -21.89003 -22.13161 -22.36931 -22.60216 -22.82924 -23.04962 -23.26241 -23.46677 -23.66187 -23.84692 -24.02117 -24.18394 -24.33455 -24.47241 -24.59695 -24.70769 -24.80416 -24.88599 -24.95284 -25.00445 -25.04060 -25.06116 -25.06603 -25.05520 -25.02871 -24.98667 -24.92926 -24.85668 -24.76926 -24.66732 -24.55129 -24.42163 -24.27886 -24.12357 -23.95636 -23.77792 -23.58897 -23.39027 -23.18261 -22.96683 -22.74380 -22.51443 -22.27962 -22.04034 -21.79754 -21.55219 -21.30530 -21.05785 -20.81083 -20.56525 -20.32209 -20.08233 -19.84693 -19.61685 -19.39301 -19.17632 -18.96763 -18.76781 -18.57764 -18.39789 -18.22930 -18.07253 -17.92822
-17.79696 -17.67926 -17.57560 -17.48640 -17.41203 -17.35277 -17.30887 -17.28050 -17.26778 -17.27076
coords1.sys[,2]
6.465179 6.538004 6.611223 6.684541 6.757663 6.830295 6.902143 6.972919 7.042338 7.110120 7.175992 7.239689 7.300955 7.359542 7.415215 7.467750 7.516935 7.562573 7.604478 7.642483 7.676435 7.706197 7.731648 7.752688 7.769230 7.781208 7.788574 7.791299 7.789371 7.782798 7.771606 7.755841 7.735567 7.710864 7.681832 7.648589 7.611267 7.570018 7.525007 7.476416 7.424440 7.369288 7.311183 7.250359 7.187060 7.121542 7.054068 6.984910 6.914346 6.842661 6.770143 6.697084 6.623779 6.550522 6.477608 6.405332 6.333984 6.263851 6.195216 6.128355 6.063538 6.001025 5.941069 5.883910 5.829778 5.778892 5.731457 5.687664 5.647688 5.611692 5.579819 5.552199 5.528941 5.510141 5.495874 5.486197 5.481149 5.480751 5.485003 5.493890 5.507375 5.525404 5.547904 5.574784 5.605938 5.641238 5.680543 5.723695 5.770520 5.820829 5.874419 5.931076 5.990571 6.052663 6.117104 6.183634 6.251984 6.321880 6.393041 6.465179
plot(1,1,ylim=c(0,15),xlim=c(-30,-10), t="n", xlab="", ylab="")
polygon(coords1[,1], coords1[,2], border=2,col=alpha("red",0.5))
polygon(coords1.sys[,1], coords1.sys[,2], border=2,col=alpha("black",0.5))
I am trying to calculate the percent overlap, as shown using gArea and gIntersection here.
kt.small.g=data.frame(coords1[,1], coords1[,2])
names(kt.small.g)=c("x","y")
summary(kt.small.g)
kt.small.s=data.frame(coords1.sys[,1], coords1.sys[,2])
names(kt.small.s)=c("x","y")
kt.small.g_pol <- Polygons(list(Polygon(kt.small.g)), "small.g")
kt.small.s_pol <- Polygons(list(Polygon(kt.small.s)), "small.s")
kt.small.g_area <- gArea(shape["small.g"])
kt.small.intersections <- gIntersection(shape["small.g"], shape["small.s"])
but after running kt.small.g_area <- gArea(shape["small.g"]) or kt.small.intersections <- gIntersection(shape["small.g"], shape["small.s"]) I get the error:
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'obj' in selecting a method for function 'is.projected': NAs not permitted in row index
I have run through the code in the linked example without error. I have checked my data for NAs, parallel structure to the example, and tried to change the names in shape[] to smaller strings or strings without "." and I still get the same error.
Thank you for your help.
Not sure what percentage you're after, but all of the areas are listed below for you to do the math on.
The following solution uses the sf library to work with the spatial objects.
If you're working with sp objects (SpatialPolygonsDataframes, etc), they can usually be changed to sf using as(x, 'sf').
library(dplyr)
library(ggplot2)
library(sf)
# Cleaning your data pasted from SO
poly1_x <- as.numeric(c("-15.99719", "-16.01133", "-16.04000", "-16.08308", "-16.14041", "-16.21175", "-16.29681", "-16.39525", "-16.50668", "-16.63064", "-16.76664", "-16.91413", "-17.07252", "-17.24116", "-17.41939", "-17.60647", "-17.80166", "-18.00417", "-18.21319", "-18.42788", "-18.64736", "-18.87076", "-19.09718", "-19.32570", "-19.55541", "-19.78538", "-20.01468", "-20.24240", "-20.46760", "-20.68940", "-20.90688", "-21.11919", "-21.32546", "-21.52486", "-21.71659", "-21.89988", "-22.07399", "-22.23822", "-22.39191", "-22.53443", "-22.66522", "-22.78374", "-22.88953", "-22.98215", "-23.06124", "-23.12646", "-23.17757", "-23.21435", "-23.23666", "-23.24441", "-23.23756", "-23.21615", "-23.18025", "-23.13002", "-23.06566", "-22.98742", "-22.89562", "-22.79063", "-22.67288", "-22.54283", "-22.40101", "-22.24800", "-22.08440", "-21.91088", "-21.72813", "-21.53690", "-21.33795", "-21.13208","-20.92012", "-20.70293", "-20.48137", "-20.25635", "-20.02876", "-19.79953", "-19.56958", "-19.33983", "-19.11120", "-18.88463", "-18.66102", "-18.44127", "-18.22626", "-18.01687", "-17.81393", "-17.61826", "-17.43066", "-17.25187", "-17.08262", "-16.92358", "-16.77540", "-16.63868", "-16.51396", "-16.40174", "-16.30249", "-16.21659", "-16.14440", "-16.08620", "-16.04224", "-16.01268", "-15.99764", "-15.99719"))
poly1_y <- c(6.225418, 6.262789, 6.300443, 6.338229, 6.375996, 6.413591, 6.450863, 6.487662, 6.523839, 6.55925, 6.59375, 6.627202, 6.659471, 6.690426, 6.719943, 6.747904, 6.774196, 6.798712, 6.821354, 6.842031, 6.86066, 6.877166, 6.891481, 6.90355, 6.913322, 6.920758, 6.92583, 6.928515, 6.928804, 6.926696, 6.922198, 6.915329, 6.906116, 6.894597, 6.880818, 6.864834, 6.846711, 6.82652, 6.804343, 6.780269, 6.754396, 6.726828, 6.697675, 6.667055, 6.635091, 6.601912, 6.567652, 6.532448, 6.496442, 6.45978, 6.422608, 6.385077, 6.347338, 6.309542, 6.271842, 6.234389, 6.197335, 6.160829, 6.125017, 6.090044, 6.056051, 6.023174, 5.991546, 5.961295, 5.932541, 5.905401, 5.879985, 5.856394, 5.834723, 5.81506, 5.797484, 5.782066, 5.768867, 5.757941, 5.749333, 5.743075, 5.739195, 5.737707, 5.738617, 5.741922, 5.747609, 5.755654, 5.766025, 5.77868, 5.793569, 5.810631, 5.829798, 5.850993, 5.874129, 5.899115, 5.925849, 5.954224, 5.984126, 6.015434, 6.048021, 6.081758, 6.116508, 6.15213, 6.188483, 6.225418)
poly2_x <- c("-17.27076 -17.28943 -17.32370 -17.37346 -17.43849 -17.51853 -17.61326 -17.72229 -17.84520 -17.98148 -18.13059 -18.29192 -18.46483 -18.64862 -18.84254 -19.04583 -19.25765 -19.47717 -19.70348 -19.93569 -20.17285 -20.41402 -20.65821 -20.90445 -21.15175 -21.39911 -21.64554 -21.89003 -22.13161 -22.36931 -22.60216 -22.82924 -23.04962 -23.26241 -23.46677 -23.66187 -23.84692 -24.02117 -24.18394 -24.33455 -24.47241 -24.59695 -24.70769 -24.80416 -24.88599 -24.95284 -25.00445 -25.04060 -25.06116 -25.06603 -25.05520 -25.02871 -24.98667 -24.92926 -24.85668 -24.76926 -24.66732 -24.55129 -24.42163 -24.27886 -24.12357 -23.95636 -23.77792 -23.58897 -23.39027 -23.18261 -22.96683 -22.74380 -22.51443 -22.27962 -22.04034 -21.79754 -21.55219 -21.30530 -21.05785 -20.81083 -20.56525 -20.32209 -20.08233 -19.84693 -19.61685 -19.39301 -19.17632 -18.96763 -18.76781 -18.57764 -18.39789 -18.22930 -18.07253 -17.92822 -17.79696 -17.67926 -17.57560 -17.48640 -17.41203 -17.35277 -17.30887 -17.28050 -17.26778 -17.27076")
poly2_x <- stringr::str_split(poly2_x, pattern = ' ') %>% unlist()
poly2_y <- c(6.465179, 6.538004, 6.611223, 6.684541, 6.757663, 6.830295, 6.902143, 6.972919, 7.042338, 7.11012, 7.175992, 7.239689, 7.300955, 7.359542, 7.415215, 7.46775, 7.516935, 7.562573, 7.604478, 7.642483, 7.676435, 7.706197, 7.731648, 7.752688, 7.76923, 7.781208, 7.788574, 7.791299, 7.789371, 7.782798, 7.771606, 7.755841, 7.735567, 7.710864, 7.681832, 7.648589, 7.611267, 7.570018, 7.525007, 7.476416, 7.42444, 7.369288, 7.311183, 7.250359, 7.18706, 7.121542, 7.054068, 6.98491, 6.914346, 6.842661, 6.770143, 6.697084, 6.623779, 6.550522, 6.477608, 6.405332, 6.333984, 6.263851, 6.195216, 6.128355, 6.063538, 6.001025, 5.941069, 5.88391, 5.829778, 5.778892, 5.731457, 5.687664, 5.647688, 5.611692, 5.579819, 5.552199, 5.528941, 5.510141, 5.495874, 5.486197, 5.481149, 5.480751, 5.485003, 5.49389, 5.507375, 5.525404, 5.547904, 5.574784, 5.605938, 5.641238, 5.680543, 5.723695, 5.77052, 5.820829, 5.874419, 5.931076, 5.990571, 6.052663, 6.117104, 6.183634, 6.251984, 6.32188, 6.393041, 6.465179)
# Make polygons as sf objects
poly1 <- data.frame(x = poly1_x, y = poly1_y) %>%
st_as_sf(coords = c('x', 'y')) %>%
st_combine() %>%
st_cast('POLYGON')
poly2 <- data.frame(x = poly2_x, y = poly2_y) %>%
st_as_sf(coords = c('x', 'y')) %>%
st_combine() %>%
st_cast('POLYGON')
# Plot
ggplot() +
geom_sf(data = poly1, fill = 'red', alpha = .5) +
geom_sf(data = poly2, fill = 'blue', alpha = .5)
# Area of polygon1: (red)
st_area(poly1)
#> [1] 6.62603
# Area of polygon2: (blue)
st_area(poly2)
#> [1] 13.88645
# Area covered only by BOTH polygons (purple)
st_intersection(poly1, poly2) %>%
st_area
#> [1] 5.678321
Created on 2020-12-30 by the reprex package (v0.3.0)

Change SpatialLinesDataFrame coordinates to fit into a shapefile

I have a SpatialLinesDataFrame of streets in Malawi and Shapefile of Malawi country. The problem is that the coordinates of some parts of one of the streets are located in the Malawi lake (and it's clearly not possible in the reality), so I think there are some problems between the shapefile and the SpatialLinesDataFrame. How can I correct the coordinates of the SpatialLinesDataFrame so that they can overlap correctly? The shapefile I am using for Malawi can be found here : mwi_adm_nso_20181016_SHP.zip (the name of the file I am using is mwi_admbnda_adm3_nso_20181016.shp).
Here the code to create the SpatialLinesDataframe of the street that has segments in the lake.
# download the shapefile of Malawi
mySHPM <-
shapefile(
paste(
path,
"/mwi_admbnda_adm3_nso_20181016.shp",
sep = ""
)
)
# subset to focus on the area where the street is
mySHP <- mySHPM[mySHPM$ADM2_EN %in% c("Karonga", "Rumphi"), ]
# define the SpatialLinesDataframe for the street that goes in the lake
Xline <- c(34.21031,34.21031,34.21027,34.21026,34.21023,34.21022,34.21006,34.20951,34.20848,34.20763,
34.20712,34.20624,34.20524,34.20443,34.20412,34.20409,34.20409,34.20421,34.20418,34.20414,
34.20403,34.20437,34.20503,34.20548,34.20598,34.20625,34.20589,34.20493,34.20467,34.20449,
34.20376,34.20349,34.20377,34.20444,34.20598,34.20694,34.20912,34.20978,34.20999,34.20985,
34.20950,34.20864,34.20822,34.20820,34.20838,34.20890,34.20905,34.20876,34.20798,34.20697,
34.20599,34.20399,34.20219,34.20074,34.19889,34.19631,34.19428,34.19126,34.18883,34.18757,
34.18614,34.18343,34.18179,34.17895,34.17602,34.17429,34.17208,34.17101,34.16972,34.16955,
34.16949,34.16944,34.16954,34.16986,34.16973,34.16935,34.16908,34.16896,34.16874,34.16783,
34.16684,34.16574,34.16509,34.16471,34.16463,34.16445,34.16422,34.16420,34.16399,34.16386,
34.16358,34.16319,34.16275,34.16217,34.16153,34.16145,34.16154,34.16207,34.16210,34.16196,
34.16145,34.16095,34.16044,34.15993,34.15940,34.15889,34.15835,34.15780,34.15720,34.15652,
34.15592,34.15546,34.15524,34.15497,34.15463,34.15426,34.15387,34.15335,34.15306,34.15270,
34.15222,34.15185,34.15141,34.15107,34.15080,34.15071,34.15080,34.15120,34.15137,34.15167,
34.15143,34.15091,34.15038,34.14988,34.14946,34.14922,34.14899,34.14851,34.14815,34.14800,
34.14762,34.14732,34.14697,34.14715,34.14691,34.14640,34.14608,34.14568,34.14541,34.14543,
34.14590,34.14617,34.14634,34.14649,34.14670,34.14647,34.14623,34.14614,34.14628,34.14649,
34.14633,34.14608,34.14591,34.14556,34.14515,34.14494,34.14472,34.14444,34.14414,34.14378,
34.14354,34.14322,34.14309,34.14320,34.14355,34.14380,34.14419,34.14451,34.14485,34.14522,
34.14538,34.14530,34.14525,34.14522,34.14522,34.14520,34.14521,34.14487,34.14455,34.14419,
34.14378,34.14341,34.14304,34.14306,34.14355,34.14411,34.14461,34.14485,34.14480,34.14468,
34.14448,34.14448,34.14438,34.14445,34.14449,34.14443,34.14419,34.14395,34.14341,34.14293,
34.14259,34.14268,34.14319,34.14367,34.14371,34.14401,34.14402,34.14379,34.14326,34.14281,
34.14225,34.14182,34.14130,34.14082,34.14021,34.14002,34.13975,34.13975,34.14023,34.14068,
34.14111,34.14147,34.14145,34.14144,34.14097,34.14035,34.13982,34.13912,34.13863,34.13819,
34.13769,34.13761,34.13751,34.13746,34.13699,34.13661,34.13670,34.13716,34.13736,34.13718,
34.13663,34.13655,34.13655,34.13662,34.13683,34.13707,34.13728,34.13741,34.13740,34.13761,
34.13824,34.13843,34.13842,34.13796,34.13723,34.13716,34.13718,34.13709,34.13689,34.13702,
34.13744,34.13761,34.13754,34.13755,34.13722,34.13682,34.13665,34.13634,34.13631,34.13623,
34.13625,34.13639,34.13652,34.13656,34.13695,34.13717,34.13716,34.13694,34.13683,34.13632,
34.13584,34.13532,34.13487,34.13437,34.13384,34.13348,34.13303,34.13258,34.13235,34.13206,
34.13204,34.13173,34.13134,34.13130,34.13102,34.13098,34.13089,34.13066,34.13052,34.13049,
34.13005,34.13001,34.12955,34.12952,34.12938,34.12859,34.12828,34.12784,34.12704,34.12610,
34.12483,34.12405,34.12284,34.12198,34.12105,34.11939,34.11927,34.11853,34.11828,34.11751,
34.11658,34.11550,34.11403,34.11364,34.11339,34.11303,34.11240,34.11173,34.11087,34.11034,
34.10987,34.10982,34.11021,34.11024,34.11016,34.10976,34.10923,34.10895,34.10898,34.10904,
34.10887,34.10870,34.10847,34.10803,34.10774,34.10691,34.10652,34.10620,34.10544,34.10540,
34.10547,34.10630,34.10641,34.10682,34.10677,34.10665,34.10664,34.10727,34.10819,34.10943,
34.11040,34.11054,34.11062,34.11087,34.11081,34.11079,34.11079)
Yline <-
c(-10.45258, -10.45259, -10.45294, -10.45369, -10.45489, -10.45648, -10.45859, -10.46091, -10.46452, -10.46747,
-10.46972, -10.47282, -10.47625, -10.47942, -10.48181, -10.48305, -10.48489, -10.48688, -10.49033, -10.49375,
-10.49606, -10.49860, -10.50286, -10.50589, -10.50926, -10.51182, -10.51374, -10.51642, -10.51806, -10.52037,
-10.52250, -10.52405, -10.52527, -10.52634, -10.52831, -10.52905, -10.53041, -10.53148, -10.53272, -10.53478,
-10.53576, -10.53710, -10.53811, -10.53825, -10.53968, -10.54224, -10.54315, -10.54454, -10.54563, -10.54692,
-10.54783, -10.54895, -10.54994, -10.55071, -10.55176, -10.55325, -10.55491, -10.55747, -10.55951, -10.56054,
-10.56163, -10.56337, -10.56472, -10.56799, -10.57132, -10.57269, -10.57448, -10.57609, -10.57886, -10.58046,
-10.58276, -10.58438, -10.58613, -10.58850, -10.59053, -10.59210, -10.59307, -10.59355, -10.59357, -10.59333,
-10.59312, -10.59287, -10.59279, -10.59252, -10.59238, -10.59253, -10.59336, -10.59393, -10.59408, -10.59396,
-10.59353, -10.59313, -10.59288, -10.59271, -10.59255, -10.59260, -10.59274, -10.59306, -10.59316, -10.59317,
-10.59296, -10.59305, -10.59316, -10.59342, -10.59353, -10.59358, -10.59341, -10.59330, -10.59337, -10.59367,
-10.59402, -10.59435, -10.59463, -10.59494, -10.59532, -10.59560, -10.59559, -10.59548, -10.59519, -10.59497,
-10.59484, -10.59461, -10.59478, -10.59503, -10.59486, -10.59503, -10.59509, -10.59530, -10.59564, -10.59584,
-10.59583, -10.59578, -10.59600, -10.59620, -10.59639, -10.59614, -10.59587, -10.59588, -10.59584, -10.59549,
-10.59499, -10.59452, -10.59414, -10.59381, -10.59365, -10.59368, -10.59346, -10.59331, -10.59317, -10.59330,
-10.59354, -10.59390, -10.59430, -10.59461, -10.59489, -10.59503, -10.59519, -10.59505, -10.59496, -10.59479,
-10.59466, -10.59449, -10.59425, -10.59387, -10.59365, -10.59346, -10.59352, -10.59341, -10.59355, -10.59355,
-10.59316, -10.59312, -10.59314, -10.59323, -10.59332, -10.59374, -10.59384, -10.59372, -10.59391, -10.59422,
-10.59455, -10.59488, -10.59493, -10.59490, -10.59490, -10.59477, -10.59437, -10.59416, -10.59399, -10.59421,
-10.59427, -10.59405, -10.59378, -10.59391, -10.59426, -10.59459, -10.59435, -10.59452, -10.59462, -10.59500,
-10.59540, -10.59564, -10.59566, -10.59519, -10.59477, -10.59469, -10.59481, -10.59492, -10.59478, -10.59458,
-10.59454, -10.59468, -10.59489, -10.59522, -10.59558, -10.59608, -10.59612, -10.59612, -10.59556, -10.59541,
-10.59550, -10.59559, -10.59540, -10.59518, -10.59522, -10.59529, -10.59534, -10.59547, -10.59551, -10.59564,
-10.59592, -10.59610, -10.59623, -10.59621, -10.59598, -10.59587, -10.59586, -10.59580, -10.59568, -10.59572,
-10.59554, -10.59546, -10.59492, -10.59453, -10.59403, -10.59389, -10.59357, -10.59333, -10.59308, -10.59286,
-10.59283, -10.59279, -10.59239, -10.59197, -10.59184, -10.59131, -10.59120, -10.59101, -10.59062, -10.59048,
-10.59021, -10.59022, -10.59011, -10.59019, -10.59054, -10.59093, -10.59098, -10.59106, -10.59102, -10.59058,
-10.59023, -10.59009, -10.59001, -10.59002, -10.59028, -10.59057, -10.59101, -10.59129, -10.59150, -10.59152,
-10.59151, -10.59108, -10.59072, -10.59039, -10.59010, -10.58976, -10.58972, -10.58904, -10.58882, -10.58845,
-10.58838, -10.58833, -10.58859, -10.58851, -10.58845, -10.58817, -10.58790, -10.58771, -10.58768, -10.58799,
-10.58799, -10.58738, -10.58720, -10.58723, -10.58757, -10.58774, -10.58812, -10.58875, -10.58917, -10.58920,
-10.58930, -10.58927, -10.58915, -10.58919, -10.58933, -10.58968, -10.58981, -10.58970, -10.58913, -10.58871,
-10.58863, -10.58875, -10.58869, -10.58857, -10.58840, -10.58776, -10.58771, -10.58709, -10.58688, -10.58693,
-10.58698, -10.58680, -10.58643, -10.58626, -10.58621, -10.58628, -10.58687, -10.58748, -10.58799, -10.58860,
-10.58908, -10.58929, -10.59015, -10.59142, -10.59176, -10.59204, -10.59191, -10.59216, -10.59234, -10.59253,
-10.59294, -10.59297, -10.59298, -10.59285, -10.59288, -10.59313, -10.59308, -10.59325, -10.59455, -10.59463,
-10.59521, -10.59622, -10.59643, -10.59773, -10.59809, -10.59836, -10.59890, -10.60086, -10.60199, -10.60337,
-10.60447, -10.60461, -10.60458, -10.60432, -10.60430, -10.60432, -10.60433)
coords <- as.data.frame(cbind(x = Xline, y = Yline))
Slo1 <- Line(coords)
Sli1 <- Lines(list(Slo1),ID="ID")
HMline <- SpatialLines(list(Sli1))
class(HMline)
proj4string(HMline) <- proj4string(mySHP)
plot(mySHP)
plot(HMline, add = T, col = "red")
# you can notice a small segment going outside the shapefile. if you can't, look at this:
# crop the street to save in "cropped" just the segments that are not overlapping the shapefile
cropped <- gDifference(HMline, mySHP)
plot(HMline)
plot(cropped, add = T, col = "red", lwd = 4)
Thanks for your help!

Clip polygon using linestring

I'm trying to figure out how to clip a polygon based on a linestring. I have estimated the range of a terrestrial animal and this range estimate extends into the ocean. I'd like to clip out any parts that extend into the ocean.
I'm using rnaturalearth to get the coastline, which returns a series of linestrings
library(lwgeom)
library(rnaturalearth)
library(rnaturalearthhires)
library(sf)
cl10 <- ne_coastline(scale=10,returnclass='sf')
poly1 is an sf polygon of the home range estimate. (To load this from wkt below, you need to add the final ')"', which is not displaying for some reason.)
wkt <- "SRID=4326;POLYGON((-64.73304 10.46291,-64.73375 10.46797,-64.73479 10.47601,-64.73529 10.48397,-64.73576 10.49193,-64.73613 10.49987,-64.73632 10.50779,-64.73639 10.51569,-64.73616 10.52355,-64.73585 10.5314,-64.73544 10.53924,-64.73476 10.54703,-64.73389 10.5548,-64.73279 10.56254,-64.7315 10.57025,-64.72998 10.57793,-64.7282 10.58557,-64.72634 10.5932,-64.72428 10.6008,-64.72188 10.60836,-64.71932 10.61589,-64.7167 10.62341,-64.71385 10.6309,-64.71074 10.63836,-64.70741 10.64578,-64.7061 10.64831,-64.70363 10.65314,-64.69975 10.66049,-64.6955 10.66779,-64.69131 10.67509,-64.68678 10.68235,-64.68541 10.68422,-64.6816 10.68951,-64.6763 10.69666,-64.67129 10.70384,-64.66619 10.71008,-64.6655 10.71092,-64.65921 10.71793,-64.65313 10.72497,-64.64775 10.73055,-64.64641 10.73191,-64.63922 10.7388,-64.63234 10.74572,-64.62976 10.74793,-64.62443 10.7525,-64.61667 10.7593,-64.61211 10.76288,-64.6081 10.76599,-64.59965 10.77269,-64.59471 10.77621,-64.59032 10.77927,-64.58079 10.78582,-64.57753 10.78797,-64.57081 10.79231,-64.56069 10.79877,-64.56047 10.7989,-64.54971 10.80512,-64.54362 10.80837,-64.53795 10.81135,-64.52681 10.81755,-64.52662 10.81765,-64.51376 10.82373,-64.5102 10.82536,-64.50063 10.82977,-64.49363 10.83293,-64.48692 10.83573,-64.47717 10.83971,-64.4725 10.84159,-64.46074 10.84626,-64.45774 10.8474,-64.4444 10.85221,-64.44196 10.85306,-64.42813 10.85767,-64.42525 10.8586,-64.41193 10.86269,-64.40758 10.86399,-64.39577 10.86735,-64.38903 10.86927,-64.37966 10.87175,-64.36964 10.87442,-64.36356 10.876,-64.34914 10.87941,-64.34754 10.87978,-64.33158 10.88309,-64.32668 10.88413,-64.31564 10.88629,-64.3033 10.88871,-64.29971 10.88941,-64.28386 10.89201,-64.27782 10.89299,-64.26801 10.89454,-64.25219 10.89691,-64.2509 10.89707,-64.23644 10.89877,-64.22147 10.90079,-64.22066 10.9009,-64.20497 10.90236,-64.18942 10.90414,-64.18923 10.90416,-64.17358 10.90532,-64.15793 10.90653,-64.15312 10.90687,-64.1423 10.9076,-64.12671 10.90837,-64.11307 10.90908,-64.11112 10.90917,-64.09558 10.90962,-64.08004 10.91004,-64.06644 10.91034,-64.06452 10.91038,-64.04903 10.91044,-64.03357 10.91035,-64.0181 10.91033,-64.01038 10.91024,-64.00265 10.91018,-63.98724 10.90971,-63.97184 10.90917,-63.95645 10.90859,-63.94106 10.90802,-63.93825 10.90785,-63.92572 10.90714,-63.91037 10.90623,-63.89506 10.90515,-63.87976 10.90399,-63.86445 10.9028,-63.84918 10.90147,-63.83391 10.90008,-63.81903 10.8987,-63.81864 10.89867,-63.80341 10.89699,-63.7882 10.89524,-63.77299 10.89341,-63.75779 10.89158,-63.7426 10.88963,-63.72743 10.88756,-63.71228 10.88539,-63.69713 10.88315,-63.682 10.88083,-63.66689 10.87837,-63.65179 10.87589,-63.63669 10.87336,-63.6216 10.87073,-63.61213 10.86901,-63.60653 10.86801,-63.59148 10.86514,-63.57644 10.86224,-63.56141 10.85928,-63.54637 10.85631,-63.53137 10.85314,-63.51636 10.85002,-63.50136 10.84683,-63.48638 10.84351,-63.48076 10.84219,-63.47142 10.84005,-63.45647 10.83653,-63.44153 10.83301,-63.4266 10.82935,-63.41166 10.82575,-63.39778 10.82232,-63.39674 10.82206,-63.38185 10.81815,-63.36696 10.81424,-63.35207 10.81034,-63.3372 10.80631,-63.33254 10.80498,-63.32234 10.80218,-63.30749 10.79802,-63.29265 10.79381,-63.27782 10.78953,-63.27544 10.78881,-63.263 10.78512,-63.24821 10.78062,-63.23339 10.77621,-63.22532 10.77365,-63.21862 10.77158,-63.20383 10.767,-63.18906 10.76236,-63.17885 10.759,-63.17431 10.75754,-63.15955 10.75275,-63.14481 10.74792,-63.13611 10.74489,-63.1301 10.74286,-63.11538 10.73783,-63.10067 10.73277,-63.0963 10.73121,-63.08598 10.7276,-63.07129 10.72239,-63.05827 10.71777,-63.0566 10.71719,-63.04194 10.7118,-63.02729 10.70637,-63.02302 10.70474,-63.01265 10.70089,-62.99799 10.69546,-62.98886 10.69186,-62.98338 10.68977,-62.96876 10.68412,-62.95604 10.67917,-62.95415 10.67845,-62.93956 10.67261,-62.92496 10.66686,-62.92449 10.66666,-62.91039 10.66088,-62.89582 10.65498,-62.89434 10.65436,-62.88127 10.64888,-62.86671 10.64284,-62.86525 10.6422,-62.85219 10.63661,-62.83765 10.63045,-62.83703 10.63017,-62.82315 10.62408,-62.80972 10.61828,-62.80863 10.61781,-62.79415 10.6113,-62.78359 10.60655,-62.77966 10.60483,-62.76517 10.59834,-62.75771 10.59486,-62.75071 10.5917,-62.73626 10.58505,-62.73248 10.58325,-62.72181 10.57832,-62.70751 10.57169,-62.70736 10.57162,-62.69295 10.56463,-62.68404 10.56034,-62.67853 10.55777,-62.66412 10.55078,-62.66045 10.54898,-62.64972 10.54377,-62.63741 10.53769,-62.63533 10.53669,-62.62095 10.52957,-62.61505 10.5265,-62.6066 10.52224,-62.59248 10.51528,-62.59221 10.51515,-62.57788 10.50774,-62.57134 10.50427,-62.56355 10.50026,-62.54973 10.49319,-62.54921 10.49291,-62.53488 10.48542,-62.52902 10.48223,-62.52059 10.47776,-62.50833 10.47128,-62.50628 10.4702,-62.49198 10.46256,-62.48799 10.46038,-62.47771 10.45474,-62.46826 10.44957,-62.46343 10.44698,-62.44915 10.43922,-62.44823 10.43871,-62.43489 10.43133,-62.42892 10.42796,-62.42065 10.42334,-62.40985 10.41724,-62.40641 10.41534,-62.39216 10.40741,-62.39054 10.40649,-62.37794 10.39929,-62.37191 10.39583,-62.36372 10.39116,-62.35334 10.38518,-62.34951 10.38301,-62.33529 10.37489,-62.33463 10.37451,-62.32108 10.3667,-62.31637 10.36391,-62.30691 10.3583,-62.29852 10.35336,-62.29272 10.35002,-62.28024 10.34275,-62.27852 10.34175,-62.26434 10.33344,-62.26222 10.33218,-62.25017 10.32501,-62.24453 10.32165,-62.236 10.31657,-62.2268 10.31112,-62.22183 10.3082,-62.20897 10.30057,-62.20766 10.2998,-62.19349 10.29139,-62.19126 10.29004,-62.17934 10.28291,-62.17367 10.27953,-62.16518 10.27442,-62.1561 10.26902,-62.15101 10.26602,-62.13829 10.25847,-62.13685 10.25762,-62.12268 10.24922,-62.12053 10.24792,-62.10853 10.24076,-62.10291 10.2374,-62.09437 10.2323,-62.08513 10.22685,-62.0802 10.22397,-62.06689 10.21623,-62.06601 10.21572,-62.05185 10.20731,-62.04914 10.20569,-62.03767 10.19903,-62.03092 10.19507,-62.02349 10.19073,-62.01251 10.18443,-62.00929 10.18259,-61.99507 10.17458,-61.99352 10.17369,-61.98087 10.16643,-61.97491 10.16301,-61.96667 10.15833,-61.95575 10.15225,-61.95243 10.15042,-61.93818 10.14263,-61.93598 10.1414,-61.92394 10.13476,-61.91622 10.13054,-61.90969 10.12701,-61.89539 10.11953,-61.89538 10.11953,-61.88112 10.11185,-61.87506 10.10859,-61.86685 10.10421,-61.85337 10.09744,-61.85251 10.09701,-61.8382 10.08965,-61.83157 10.08627,-61.82387 10.08238,-61.8095 10.07537,-61.80865 10.07494,-61.79516 10.06823,-61.7856 10.06359,-61.78078 10.0613,-61.76637 10.0546,-61.76101 10.052,-61.75198 10.04772,-61.73753 10.04123,-61.73543 10.04026,-61.72311 10.03459,-61.7087 10.02835,-61.70864 10.02832,-61.6942 10.02178,-61.68151 10.01636,-61.67971 10.01561,-61.66523 10.00934,-61.65243 10.00409,-61.6507 10.0034,-61.6362 9.997307,-61.62164 9.99159,-61.62152 9.991541,-61.60713 9.985571,-61.59255 9.979943,-61.59 9.978896,-61.57801 9.974096,-61.56341 9.968638,-61.55666 9.965975,-61.54884 9.962998,-61.53424 9.957559,-61.52083 9.952675,-61.51962 9.952241,-61.50503 9.94675,-61.49039 9.941541,-61.48417 9.939246,-61.47577 9.936246,-61.46114 9.930998,-61.44647 9.925975,-61.44499 9.925432,-61.43184 9.920747,-61.41718 9.9157,-61.40508 9.911503,-61.40253 9.910635,-61.38788 9.905512,-61.37319 9.900693,-61.36373 9.897351,-61.35854 9.895561,-61.34387 9.890574,-61.3292 9.885642,-61.32195 9.883129,-61.31453 9.880637,-61.29986 9.875668,-61.28519 9.870744,-61.27963 9.86882,-61.27052 9.865749,-61.25586 9.860781,-61.24118 9.855888,-61.23711 9.854474,-61.22652 9.85087,-61.21187 9.845786,-61.19718 9.840917,-61.19522 9.840219,-61.18254 9.835801,-61.16788 9.830773,-61.15422 9.826093,-61.15323 9.825755,-61.1386 9.820518,-61.12394 9.815556,-61.11459 9.812168,-61.10932 9.810305,-61.0947 9.805046,-61.08007 9.799867,-61.0761 9.798413,-61.06545 9.794565,-61.05085 9.78923,-61.03888 9.784847,-61.03624 9.783904,-61.02166 9.778431,-61.00706 9.773077,-61.00293 9.77147,-60.99249 9.767492,-60.97791 9.762033,-60.96837 9.7583,-60.96335 9.756394,-60.9488 9.750703,-60.93426 9.745196,-60.93423 9.745184,-60.91972 9.739281,-60.90518 9.733539,-60.90262 9.732464,-60.89068 9.727559,-60.87616 9.721668,-60.872 9.719885,-60.86168 9.715605,-60.84717 9.709654,-60.842 9.707398,-60.83271 9.703463,-60.81823 9.697355,-60.81315 9.695084,-60.80379 9.691013,-60.78933 9.684754,-60.78533 9.682925,-60.77491 9.678298,-60.76049 9.671856,-60.75845 9.670908,-60.7461 9.665213,-60.7321 9.65897,-60.73167 9.658779,-60.71732 9.651903,-60.70756 9.647305,-60.70294 9.645179,-60.68855 9.638528,-60.68272 9.635594,-60.67423 9.631448,-60.65988 9.624584,-60.65873 9.624011,-60.64557 9.61742,-60.63594 9.61261,-60.63126 9.610311,-60.61696 9.603115,-60.61339 9.601244,-60.60269 9.595709,-60.59153 9.589984,-60.58841 9.588402,-60.57415 9.580942,-60.57023 9.578807,-60.55993 9.573282,-60.54972 9.56775,-60.5457 9.565604,-60.53148 9.557961,-60.52921 9.556691,-60.5173 9.550029,-60.50987 9.545813,-60.50313 9.542042,-60.49044 9.534919,-60.48895 9.534081,-60.47481 9.525925,-60.47183 9.524149,-60.46069 9.517625,-60.45374 9.513459,-60.44659 9.509217,-60.43578 9.502788,-60.43248 9.50082,-60.4184 9.492318,-60.41815 9.492165,-60.40434 9.483605,-60.40132 9.481666,-60.39031 9.474767,-60.38466 9.471192,-60.3763 9.465832,-60.36857 9.460806,-60.3623 9.456769,-60.35256 9.450432,-60.34831 9.447676,-60.33671 9.440079,-60.33434 9.438494,-60.32149 9.429825,-60.3204 9.429087,-60.30646 9.419666,-60.30634 9.41958,-60.29257 9.409966,-60.2918 9.409429,-60.2787 9.400191,-60.27746 9.399307,-60.26484 9.390272,-60.26347 9.389241,-60.25107 9.379837,-60.25035 9.379307,-60.23727 9.369608,-60.23688 9.369319,-60.22353 9.359348,-60.22347 9.359308,-60.21077 9.349469,-60.20974 9.348667,-60.1981 9.339603,-60.19601 9.337965,-60.18581 9.329795,-60.18233 9.32698,-60.17361 9.320001,-60.16866 9.315952,-60.16169 9.31025,-60.15501 9.304783,-60.14981 9.300504,-60.14138 9.293462,-60.13819 9.290799,-60.12779 9.281922,-60.12688 9.28114,-60.11608 9.27156,-60.11427 9.26995,-60.10532 9.261987,-60.10077 9.257853,-60.09468 9.252432,-60.08726 9.245799,-60.08403 9.242874,-60.07381 9.2334,-60.07379 9.233381,-60.06412 9.223975,-60.06046 9.220393,-60.05442 9.214564,-60.04711 9.207419,-60.04475 9.205157,-60.03548 9.195813,-60.03381 9.194076,-60.02643 9.186502,-60.02054 9.180567,-60.01712 9.177151,-60.00845 9.167899,-60.00733 9.166661,-60.00008 9.158693,-59.9942 9.152287,-59.99151 9.149456,-59.98346 9.1403,-59.98113 9.137586,-59.97541 9.131143,-59.96807 9.122774,-59.96738 9.121988,-59.95999 9.112935,-59.95513 9.10723,-59.9521 9.103803,-59.94515 9.094816,-59.94227 9.091182,-59.93789 9.085782,-59.93084 9.076779,-59.92945 9.074836,-59.92431 9.067857,-59.91741 9.058879,-59.91674 9.057898,-59.9111 9.049991,-59.90461 9.041076,-59.90412 9.040324,-59.89875 9.032259,-59.89263 9.0234,-59.89166 9.021814,-59.88706 9.014628,-59.88132 9.005828,-59.87932 9.002556,-59.87579 8.997061,-59.87057 8.988344,-59.86712 8.982396,-59.86547 8.979644,-59.86056 8.970973,-59.85553 8.962285,-59.85506 8.96136,-59.85105 8.953681,-59.84658 8.945079,-59.84328 8.93859,-59.84219 8.93649,-59.83827 8.927974,-59.83428 8.919446,-59.8318 8.913986,-59.83032 8.910925,-59.82676 8.902464,-59.82329 8.894018,-59.82061 8.887526,-59.81977 8.885564,-59.81674 8.877187,-59.8138 8.868823,-59.81079 8.860449,-59.80996 8.857668,-59.80819 8.852137,-59.80582 8.843862,-59.80346 8.83559,-59.80117 8.827328,-59.8001 8.822896,-59.79912 8.819102,-59.79725 8.810907,-59.79569 8.802758,-59.79427 8.794631,-59.7929 8.786513,-59.79169 8.779063,-59.79157 8.7784,-59.79072 8.770362,-59.78986 8.762324,-59.78943 8.754351,-59.78887 8.746359,-59.7887 8.738428,-59.78843 8.73048,-59.78862 8.722606,-59.78885 8.714736,-59.78924 8.706892,-59.78982 8.699077,-59.79062 8.691298,-59.79158 8.683543,-59.79283 8.675833,-59.79433 8.668163,-59.796 8.660518,-59.79793 8.652914,-59.80006 8.645342,-59.80233 8.637792,-59.80473 8.630261,-59.8076 8.622805,-59.81042 8.61534,-59.81348 8.607913,-59.8168 8.600525,-59.82026 8.59316,-59.82173 8.590491,-59.82426 8.585879,-59.8284 8.57862,-59.83288 8.571415,-59.83719 8.564181,-59.84206 8.557036,-59.84255 8.556397,-59.84738 8.549962,-59.85295 8.542925,-59.85856 8.535895,-59.86182 8.531992,-59.86439 8.5289,-59.87096 8.522018,-59.87739 8.515115,-59.88035 8.512257,-59.88442 8.508307,-59.8916 8.50152,-59.89846 8.495194,-59.89894 8.49476,-59.90745 8.48818,-59.91534 8.481505,-59.91611 8.480966,-59.92454 8.475032,-59.93315 8.468469,-59.93352 8.468237,-59.94303 8.462103,-59.95068 8.457075,-59.95281 8.45572,-59.96335 8.449455,-59.96767 8.446971,-59.9744 8.44327,-59.98454 8.437626,-59.98551 8.437093,-59.99773 8.431089,-60.00122 8.429466,-60.01038 8.425151,-60.01783 8.421737,-60.02355 8.419294,-60.03434 8.414641,-60.03712 8.413498,-60.05079 8.407928,-60.05118 8.407778,-60.06655 8.402262,-60.0671 8.40207,-60.08257 8.396844,-60.08335 8.396588,-60.09931 8.391539,-60.09955 8.391468,-60.11565 8.386966,-60.11751 8.386458,-60.1317 8.382737,-60.13651 8.381502,-60.14772 8.378738,-60.15622 8.376653,-60.16369 8.375004,-60.17752 8.372051,-60.17961 8.371606,-60.19546 8.368661,-60.20054 8.367714,-60.21128 8.365889,-60.22469 8.363549,-60.2271 8.363133,-60.24281 8.361066,-60.25156 8.359805,-60.25854 8.358832,-60.27421 8.357012,-60.28009 8.356314,-60.28988 8.355213,-60.30547 8.353862,-60.31165 8.353291,-60.32107 8.352488,-60.3366 8.351552,-60.34694 8.350841,-60.35215 8.350489,-60.36761 8.349978,-60.38311 8.349196,-60.38672 8.349081,-60.39857 8.348733,-60.41396 8.34863,-60.42941 8.348205,-60.43238 8.348222,-60.44478 8.348302,-60.4601 8.348646,-60.47546 8.348801,-60.48958 8.349137,-60.49078 8.349162,-60.50607 8.349757,-60.52133 8.350551,-60.53657 8.351422,-60.55181 8.35234,-60.56705 8.353243,-60.56826 8.353347,-60.58223 8.354513,-60.5974 8.355799,-60.61255 8.357305,-60.62767 8.358933,-60.64279 8.360605,-60.6579 8.362359,-60.673 8.364125,-60.68807 8.366088,-60.70312 8.36823,-60.71816 8.370405,-60.73318 8.372689,-60.74819 8.375073,-60.76319 8.377516,-60.77817 8.380075,-60.79312 8.382838,-60.80806 8.385652,-60.823 8.388466,-60.83791 8.391453,-60.85282 8.394445,-60.86772 8.397519,-60.88259 8.400786,-60.89328 8.403199,-60.89745 8.404125,-60.91228 8.407674,-60.92711 8.411204,-60.94193 8.414806,-60.95675 8.418429,-60.97154 8.422183,-60.97937 8.424254,-60.98632 8.426057,-61.00108 8.430073,-61.01582 8.434144,-61.03057 8.43819,-61.04403 8.442022,-61.0453 8.442378,-61.06 8.446784,-61.07469 8.451253,-61.08938 8.45568,-61.09653 8.457925,-61.10405 8.460222,-61.1187 8.464963,-61.13337 8.469533,-61.14367 8.473004,-61.14799 8.474436,-61.16259 8.479449,-61.17723 8.484284,-61.18571 8.487301,-61.19181 8.489429,-61.20638 8.494624,-61.22097 8.499763,-61.2246 8.501115,-61.23552 8.505124,-61.25007 8.510523,-61.26054 8.514476,-61.2646 8.515997,-61.27911 8.521607,-61.29364 8.527151,-61.29461 8.527549,-61.30811 8.53304,-61.32262 8.538679,-61.32637 8.54027,-61.33707 8.544705,-61.35155 8.550573,-61.3567 8.552769,-61.366 8.556609,-61.38043 8.562742,-61.38571 8.565066,-61.39485 8.56896,-61.40927 8.575185,-61.41367 8.577202,-61.42366 8.581633,-61.43807 8.587938,-61.44078 8.589207,-61.45244 8.594548,-61.46683 8.600956,-61.46712 8.601093,-61.48117 8.607758,-61.49191 8.612743,-61.49553 8.614386,-61.50987 8.621131,-61.51657 8.624371,-61.52419 8.628053,-61.53852 8.634882,-61.54055 8.635894,-61.55281 8.641982,-61.56365 8.647283,-61.56712 8.648972,-61.58142 8.656042,-61.58636 8.658612,-61.59567 8.663394,-61.6089 8.669913,-61.60997 8.670443,-61.62423 8.677782,-61.63042 8.68106,-61.63846 8.68529,-61.65229 8.692257,-61.65274 8.692484,-61.66696 8.700033,-61.67293 8.703267,-61.68117 8.707694,-61.69384 8.714316,-61.69542 8.715144,-61.70964 8.722702,-61.71437 8.725309,-61.72383 8.730533,-61.73432 8.736211,-61.73804 8.738198,-61.75226 8.7458,-61.75472 8.74718,-61.76644 8.753654,-61.77439 8.758038,-61.78063 8.761465,-61.79445 8.768953,-61.79484 8.769164,-61.80901 8.777071,-61.81376 8.779755,-61.82317 8.785094,-61.83304 8.790551,-61.83736 8.792919,-61.85155 8.800729,-61.85273 8.801407,-61.86571 8.808746,-61.87173 8.812159,-61.87987 8.816762,-61.89117 8.822974,-61.89407 8.824567,-61.90826 8.832401,-61.91071 8.833805,-61.92243 8.840391,-61.9299 8.844581,-61.9366 8.848328,-61.9496 8.855433,-61.95081 8.856088,-61.96499 8.863957,-61.96915 8.86626,-61.97918 8.871832,-61.98875 8.877094,-61.99338 8.879601,-62.00761 8.887224,-62.00907 8.888036,-62.02182 8.894998,-62.02905 8.898924,-62.03603 8.902689,-62.05005 8.909962,-62.05029 8.910091,-62.06453 8.917704,-62.07048 8.920915,-62.07875 8.925356,-62.09206 8.932038,-62.09305 8.932536,-62.10732 8.939863,-62.11376 8.943178,-62.12159 8.94722,-62.13592 8.954215,-62.1364 8.954457,-62.15022 8.961379,-62.15909 8.96574,-62.16455 8.96839,-62.1789 8.975253,-62.18281 8.977177,-62.19324 8.98214,-62.20764 8.98867,-62.20798 8.988827,-62.22201 8.995404,-62.23342 9.000515,-62.23643 9.001826,-62.25085 9.008245,-62.26033 9.01242,-62.26528 9.014573,-62.27974 9.020734,-62.28868 9.024536,-62.29421 9.026849,-62.3087 9.032805,-62.31877 9.036909,-62.3232 9.038696,-62.33772 9.044497,-62.35092 9.049583,-62.35226 9.050092,-62.3668 9.055778,-62.38138 9.061171,-62.38496 9.062535,-62.39595 9.066626,-62.41054 9.071913,-62.42165 9.075877,-62.42515 9.077108,-62.43976 9.082321,-62.4544 9.087303,-62.46095 9.089601,-62.46903 9.092345,-62.4837 9.097211,-62.49837 9.101977,-62.5042 9.103905,-62.51305 9.106755,-62.52774 9.11144,-62.54244 9.116015,-62.55107 9.118738,-62.55715 9.120593,-62.57186 9.125143,-62.5866 9.12951,-62.60134 9.13385,-62.6027 9.134266,-62.61607 9.138303,-62.63081 9.142658,-62.64559 9.146787,-62.65738 9.150236,-62.66034 9.151083,-62.67508 9.1554,-62.68985 9.159601,-62.70463 9.163695,-62.71505 9.166639,-62.71941 9.167835,-62.73417 9.172075,-62.74895 9.176171,-62.76375 9.18018,-62.77516 9.183388,-62.77852 9.184314,-62.7933 9.18848,-62.80808 9.192556,-62.82288 9.196537,-62.836 9.200234,-62.83766 9.200696,-62.85243 9.204911,-62.86721 9.209034,-62.88201 9.213008,-62.89616 9.216968,-62.89679 9.217144,-62.91154 9.221455,-62.92631 9.225656,-62.94111 9.2297,-62.95345 9.233272,-62.95587 9.233962,-62.97061 9.238331,-62.98538 9.242572,-63.00014 9.246852,-63.00793 9.249151,-63.01489 9.251149,-63.02964 9.255538,-63.04439 9.259863,-63.05913 9.264312,-63.0605 9.264743,-63.07385 9.268831,-63.08858 9.273324,-63.1033 9.277867,-63.10941 9.279791,-63.11802 9.282416,-63.13273 9.287043,-63.14745 9.291602,-63.15654 9.294572,-63.16214 9.296362,-63.17684 9.301113,-63.19154 9.305801,-63.20073 9.308917,-63.20621 9.310728,-63.22088 9.315602,-63.23556 9.32047,-63.24252 9.322906,-63.25021 9.325509,-63.26486 9.330543,-63.27952 9.335516,-63.28258 9.336637,-63.29414 9.340751,-63.30879 9.345801,-63.32073 9.350086,-63.32342 9.351025,-63.33803 9.356325,-63.35264 9.361644,-63.35683 9.363232,-63.36724 9.367056,-63.38185 9.372398,-63.39172 9.376198,-63.39643 9.377946,-63.41101 9.383481,-63.4256 9.388971,-63.42577 9.389038,-63.44015 9.394689,-63.45471 9.400371,-63.45759 9.401552,-63.46925 9.406195,-63.48379 9.411991,-63.48841 9.413916,-63.49831 9.41794,-63.51286 9.42373,-63.51856 9.42618,-63.52735 9.42987,-63.54188 9.435778,-63.54756 9.438275,-63.55636 9.442068,-63.57086 9.448139,-63.57554 9.45022,-63.58533 9.45446,-63.59981 9.460716,-63.60279 9.462057,-63.61427 9.467086,-63.62873 9.47348,-63.62943 9.473802,-63.64316 9.480068,-63.65492 9.48538,-63.6576 9.486572,-63.67203 9.493176,-63.6798 9.496868,-63.68644 9.499925,-63.70085 9.506698,-63.70415 9.508277,-63.71525 9.513514,-63.72796 9.519605,-63.72964 9.520394,-63.74402 9.527342,-63.75079 9.530792,-63.75836 9.534523,-63.77274 9.541507,-63.77367 9.541982,-63.78707 9.548808,-63.79536 9.553001,-63.80142 9.556009,-63.81575 9.563295,-63.81715 9.564031,-63.83005 9.570831,-63.83765 9.574875,-63.84435 9.578359,-63.85816 9.585719,-63.85863 9.585973,-63.87291 9.593655,-63.87799 9.596464,-63.88717 9.601486,-63.89757 9.607171,-63.90143 9.609239,-63.91569 9.617038,-63.91721 9.617886,-63.92993 9.625015,-63.936 9.628477,-63.94415 9.633087,-63.95447 9.639021,-63.95837 9.641233,-63.97259 9.64932,-63.97303 9.649577,-63.98678 9.65757,-63.99082 9.660021,-64.00093 9.666158,-64.00796 9.670372,-64.0151 9.674615,-64.02515 9.680728,-64.02925 9.683219,-64.04222 9.691066,-64.0434 9.691781,-64.05754 9.700479,-64.05895 9.701355,-64.07166 9.709306,-64.07515 9.711566,-64.08574 9.718353,-64.09098 9.721724,-64.09982 9.727477,-64.1065 9.731836,-64.11388 9.736659,-64.1218 9.741916,-64.12793 9.745953,-64.13703 9.751986,-64.14198 9.75527,-64.152 9.762018,-64.15601 9.764757,-64.16645 9.771974,-64.17001 9.774424,-64.18087 9.781926,-64.184 9.784119,-64.19493 9.791825,-64.19797 9.793979,-64.20878 9.801693,-64.21193 9.803951,-64.2223 9.811514,-64.22586 9.81411,-64.23582 9.821334,-64.23979 9.82428,-64.24886 9.831085,-64.25367 9.834726,-64.26173 9.840811,-64.26756 9.84523,-64.27455 9.850529,-64.28141 9.855888,-64.28697 9.86019,-64.29526 9.866617,-64.2994 9.869852,-64.30908 9.877549,-64.31154 9.879472,-64.32289 9.888574,-64.32349 9.889065,-64.33499 9.898592,-64.33665 9.899977,-64.34649 9.90812,-64.35039 9.911459,-64.35765 9.917599,-64.36412 9.92306,-64.36883 9.92708,-64.37781 9.93489,-64.37971 9.936518,-64.39048 9.94594,-64.39149 9.946851,-64.40087 9.955307,-64.40511 9.959195,-64.41121 9.964667,-64.41873 9.971496,-64.42154 9.974026,-64.43141 9.983318,-64.43231 9.984178,-64.44103 9.992575,-64.44583 9.997226,-64.45074 10.00184,-64.45937 10.01015,-64.46035 10.0111,-64.46952 10.02029,-64.47282 10.02367,-64.47852 10.02946,-64.48627 10.03726,-64.48765 10.03864,-64.49632 10.04776,-64.49963 10.05139,-64.50479 10.05685,-64.51301 10.06547,-64.5135 10.06598,-64.52155 10.07501,-64.52628 10.08025,-64.52987 10.08408,-64.53768 10.09308,-64.53952 10.09529,-64.54538 10.10206,-64.55274 10.11049,-64.55324 10.11106,-64.56054 10.11998,-64.56584 10.12647,-64.56791 10.12892,-64.57498 10.13781,-64.5789 10.14274,-64.58219 10.14672,-64.58887 10.15556,-64.59188 10.15957,-64.59568 10.16441,-64.602 10.17319,-64.60477 10.17703,-64.60859 10.18202,-64.61467 10.19077,-64.61759 10.19498,-64.62091 10.19954,-64.62659 10.20823,-64.63029 10.2138,-64.63247 10.21695,-64.638 10.22563,-64.6429 10.23321,-64.64365 10.23431,-64.64869 10.24292,-64.65392 10.25155,-64.65532 10.25399,-64.65907 10.26016,-64.66367 10.2687,-64.66761 10.27563,-64.6686 10.27729,-64.67296 10.2858,-64.67743 10.29432,-64.67966 10.2989,-64.6817 10.30281,-64.68575 10.31127,-64.68969 10.31972,-64.69148 10.3238,-64.69352 10.32815,-64.69708 10.33654,-64.70046 10.34491,-64.70297 10.351,-64.70398 10.3533,-64.70694 10.36161,-64.70995 10.36992,-64.71297 10.37824,-64.71397 10.38155,-64.71559 10.3865,-64.71798 10.39473,-64.72045 10.40297,-64.72271 10.41118,-64.72426 10.41703,-64.72493 10.41938,-64.72683 10.42754,-64.72828 10.43564,-64.72991 10.44376,-64.73126 10.45184,-64.73266 10.45993,-64.73304 10.46291))"
poly1 <- st_sf(st_as_sfc(wkt))
I use this to extract out the relevant linestring.
box <- poly1 %>% st_bbox %>% st_as_sfc
sa_coast <- cl10[st_intersects(box,cl10,sparse=FALSE),] %>%
mutate(len=st_length(geometry)) %>%
filter(len==max(len))
From here, I want to clip poly1 using sa_coast. However I can't figure out how this can be done. Here is what the coast and range look like. The northern part of the map is ocean, the southern part is land.
ggplot() +
geom_sf(data=poly1,fill=NA,color='red') +
geom_sf(data=sa_coast) +
xlim(st_bbox(poly1)['xmin'],st_bbox(poly1)['xmax']) +
ylim(st_bbox(poly1)['ymin'],st_bbox(poly1)['ymax']) +
theme_classic()
I don't think that st_intersection() works, because this returns the multiline string that intersects with poly1
What I want is a multipolygon that has the water (top area of the figure) clipped out. See below, the geom returned by st_intersection() is in blue.
intr <- st_intersection(poly1,sa_coast)
ggplot() +
geom_sf(data=poly1,fill=NA,color='red') +
geom_sf(data=sa_coast) + #,mapping=aes(color=rowid)
geom_sf(data=intr,color='blue') +
xlim(st_bbox(polys)['xmin'],st_bbox(polys)['xmax']) +
ylim(st_bbox(polys)['ymin'],st_bbox(polys)['ymax']) +
theme_classic()
Here is the solution I finally figured out. Thanks to #JindaLacko who gave me the idea to use st_polygonize on a linestring. My linestring did not close however, so st_polygonize did not work. The trick is to clip the linestring using the polygon's bounding box, then use the min corner of the bounding box as a point on the linestring, and then close the linestring with it's first point. You can then turn this into a polygon.
Clip the coastline to size of the bounding box of the polygon.
sa_clip <- st_intersection(st_as_sfc(st_bbox(poly1)),sa_coast)
ggplot() +
geom_sf(data=st_as_sfc(st_bbox(poly1)),fill=NA) +
geom_sf(data=sa_clip) +
theme_classic()
Get the min corner of bounding box
corner <- st_bbox(poly1)[c('xmin','ymin')] %>% st_point %>% st_sfc(crs=4326)
Cast the linestring to points, append the corner, close the linestring, turn into polygon.
pts <- sa_clip %>% st_geometry %>% st_cast("POINT")
sa_poly <- c(pts,corner,pts[1]) %>% st_combine %>% st_cast('LINESTRING') %>% st_polygonize
Now, you can clip the polygon.
clipped <- st_intersection(sa_poly,poly1)
ggplot() +
geom_sf(data=sa_poly,fill='red',alpha=.2) +
geom_sf(data=poly1,fill='blue',alpha=.2) +
geom_sf(data=clipped,fill='purple',alpha=.2) +
theme_classic()
For clipping a linestring & a polygon use sf::st_intersection()
Consider the example on RStudio Community site, where I used it to determine an intersection of polygons of some random North Carolina (a popular dataset) counties with the 36th parallel.
https://community.rstudio.com/t/how-to-change-color-of-polyline-when-it-is-passing-a-polygon-in-leaflet-package-using-r/37033/3?u=jlacko
Edit: an intersection of linestring and polygon will be a linestring.
If the desired output is a polygon consider calling sf::st_polygonize() on your linestring. It will turn it into a polygon, which will return a polygon upon intersection with the other polygon.

Selecting a range of latitudes and longitudes for plotting

I am trying to select a range of latitude and longitudes (and all grid cells within that range) to plot y-axis values (precipitation) as a function of x-axis values (emissions) based on aggregating (averaging) each of those grid cells. Thus, let's say that I wanted to aggregate/average each of the values of these grid cells and plot this as a function x-axis values. The values already computed for each grid cell for the y-axis correspond to average precipitation and consist of 140 values per grid cell. So, the idea would be the average the first value of each grid cell, then the second value of each grid cell, then the third value of each grid cell.....all the way to value #140 of each grid cell. This would yield 140 values that would be plotted as a single line plot. The variable containing these y-axis values is called "RCP1pctCO2Mean", which is 3-dimensional and has the following attributes:
class : RasterBrick
dimensions : 64, 128, 8192, 140 (nrow, ncol, ncell, nlayers)
resolution : 2.8125, 2.789327 (x, y)
extent : -181.4062, 178.5938, -89.25846, 89.25846 (xmin, xmax, ymin,
ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
data source : in memory
names : layer.1, layer.2, layer.3, layer.4, layer.5,
layer.6, layer.7, layer.8, layer.9, layer.10, layer.11, layer.12,
layer.13, layer.14, layer.15, ...
min values : 0.5261063, 0.5625295, 0.5301681, 0.6019284, 0.5177065,
0.6775601, 0.5336965, 0.5213086, 0.5971723, 0.5305891, 0.5514522,
0.5481200, 0.4681806, 0.5437223, 0.5988844, ...
max values : 113.13776, 114.50780, 94.93643, 100.35409, 102.65459,
101.80622, 104.95480, 99.17839, 104.68667, 119.48342, 100.60391,
108.91896, 104.38969, 99.35735, 99.30752, ...
dput(head(RCP1pctCO2ModelMean,5))
structure(c(8.06056747436523, 7.75062637329102, 7.73271865844727,
7.65678634643555, 7.75580596923828, 8.74016799926758, 8.28938064575195,
8.10810775756836, 8.10339508056641, 7.86748199462891, 10.6165672302246,
11.057600402832, 11.9450210571289, 12.3012786865234, 12.1853874206543,
8.51755447387695, 9.16703491210938, 7.79627380371094, 7.53922271728516,
8.14367599487305, 7.83845596313477, 8.22455596923828, 8.21650848388672,
8.186181640625, 8.34122924804688, 9.1652702331543, 9.03225784301758,
9.04341430664062, 8.98676376342774, 9.0090087890625, 10.5393569946289,
11.1039672851562, 11.2379959106445, 11.333048248291, 12.0459312438965,
10.0039085388184, 9.90224914550781, 9.24856033325195, 9.26007308959961,
9.17901306152344, 9.55168991088867, 10.1229606628418, 10.4827072143555,
11.0505676269531, 12.1166931152344, 9.01049194335937, 9.39016952514648,
10.1307640075684, 9.67219467163086, 9.63750610351562, 8.14553070068359,
8.06989059448242, 7.88368453979492, 7.78139190673828, 7.76021575927734,
8.09026031494141, 8.47544021606445, 8.53607864379883, 9.07613296508789,
8.45474319458008, 9.91985092163086, 10.0807098388672, 9.90288009643555,
10.3433769226074, 10.349861907959, 11.2688484191895, 11.9406700134277,
12.0929878234863, 11.8347038269043, 10.4144630432129, 12.5179420471191,
13.8380874633789, 14.6360946655273, 14.0480010986328, 13.3910736083984,
9.96924514770508, 10.3363311767578, 10.7060684204102, 10.889599609375,
10.6653129577637, 10.5626991271973, 10.047868347168, 10.2751319885254,
10.8663063049316, 11.7612907409668, 8.94287414550781, 9.23690567016602,
8.96449661254883, 8.62908248901367, 8.30552215576172, 8.18369979858398,
7.69772872924805, 7.5989143371582, 7.7111930847168, 7.66501693725586,
10.2653533935547, 9.95307464599609, 9.71684875488281, 9.06423645019531,
9.75586776733399, 9.83898010253906, 9.89386901855469, 9.82217864990234,
9.5716667175293, 9.0698844909668, 9.32229309082031, 9.11556243896484,
8.89283828735352, 9.28563232421875, 9.30773696899414, 7.3968879699707,
7.93817901611328, 7.98456954956055, 7.95158386230469, 8.098583984375,
8.80923156738281, 8.49755935668945, 8.15531387329102, 8.46451263427734,
8.68563690185547, 8.89066619873047, 9.1489013671875, 9.33551254272461,
10.1721000671387, 11.0765029907227, 8.04215698242188, 8.19046478271484,
8.40826110839844, 8.67290573120117, 9.18575973510742, 8.3109245300293,
9.11093368530273, 9.81162109375, 9.86040802001953, 9.50505447387695,
10.5363166809082, 9.481689453125, 9.08926620483398, 9.52505798339844,
8.68244476318359, 8.98393630981445, 10.1831520080566, 10.5507629394531,
10.1666023254395, 9.69676284790039, 8.34152221679688, 8.42654571533203,
8.35252838134766, 8.00343780517578, 7.82494201660156, 9.53874359130859,
9.61768341064453, 9.41213912963867, 9.64521713256836, 10.2018295288086,
10.4372673034668, 10.2102493286133, 11.5178192138672, 10.6066253662109,
8.7693229675293, 10.0142112731934, 10.0218872070313, 9.85999298095703,
9.61988754272461, 9.6459342956543, 8.68394012451172, 8.94484100341797,
8.99103088378906, 9.28208084106445, 9.25485153198242, 9.43952713012695,
9.46648941040039, 9.29736251831055, 9.17809677124023, 9.15292205810547,
9.86052169799805, 9.73173980712891, 9.56215209960937, 9.07076568603516,
8.6406623840332, 9.93644332885742, 10.4607345581055, 10.7315849304199,
10.8101539611816, 10.7245536804199, 8.11333770751953, 8.19898986816406,
9.07229690551758, 8.52103500366211, 8.86794967651367, 13.8089904785156,
14.1628616333008, 14.1612731933594, 13.8391723632812, 13.4812423706055,
10.3034606933594, 10.3893714904785, 10.6155006408691, 10.7073356628418,
10.2250640869141, 10.7160522460937, 10.9937141418457, 11.4714202880859,
11.451326751709, 11.2873542785645, 10.1245864868164, 10.7054138183594,
11.2963111877441, 11.2652069091797, 11.1456642150879, 10.2463417053223,
10.7579162597656, 10.9033828735352, 10.8239326477051, 10.9808113098145,
9.11014785766602, 9.57601928710938, 9.13134765625, 8.95542297363281,
9.004345703125, 10.011986541748, 10.4038223266602, 10.7760765075684,
10.8257308959961, 11.1445190429687, 10.5380798339844, 10.2488784790039,
10.957502746582, 10.7088333129883, 10.6826118469238, 8.83894119262695,
9.23114776611328, 8.83077545166016, 8.79364471435547, 9.5740608215332,
9.49266204833984, 9.36201629638672, 8.86088562011719, 8.70853042602539,
8.84630584716797, 8.54691619873047, 9.06980133056641, 9.68758087158203,
10.2382141113281, 11.163306427002, 8.64593887329102, 8.68509368896484,
9.1695442199707, 9.96113128662109, 10.5646827697754, 10.6185249328613,
11.3931076049805, 11.984349822998, 12.3294868469238, 12.6237396240234,
9.07107849121094, 8.50119094848633, 8.165673828125, 8.46488571166992,
8.7583610534668, 9.64865646362305, 11.1105819702148, 11.4002655029297,
10.5027854919434, 10.1196365356445, 9.72924041748047, 10.009349822998,
10.326407623291, 9.36514053344727, 7.79587249755859, 9.68682708740234,
9.97370910644531, 10.053092956543, 10.0790946960449, 9.88732604980469,
8.5629150390625, 8.67814178466797, 8.62764282226562, 8.40693130493164,
8.43646850585938, 8.18491287231445, 8.28544006347656, 8.32042083740234,
8.37117156982422, 8.74075393676758, 10.0410667419434, 9.86564865112305,
9.83465423583984, 10.2372169494629, 10.6772819519043, 10.7158340454102,
11.1418548583984, 11.3801231384277, 12.3574913024902, 12.7044395446777,
10.933625793457, 10.1660957336426, 8.9215690612793, 9.42180328369141,
10.0563125610352, 10.6793243408203, 10.605298614502, 10.532593536377,
10.4527519226074, 10.4930633544922, 9.60543518066406, 9.36136474609375,
9.02150115966797, 8.90760498046875, 9.39027709960937, 11.475407409668,
11.8939018249512, 12.2665367126465, 12.3773796081543, 12.2639549255371,
12.1986907958984, 12.9296035766602, 14.6138290405273, 12.5118690490723,
11.1584533691406, 11.6089347839355, 12.184122467041, 12.7126617431641,
12.8846618652344, 12.7170280456543, 10.4427520751953, 11.0104148864746,
11.0574317932129, 10.7889305114746, 11.428002166748, 12.8730773925781,
13.0610855102539, 13.9772033691406, 14.7699234008789, 15.2759140014648,
11.0441619873047, 12.8132598876953, 13.1194686889648, 13.3944534301758,
13.439665222168, 11.8274314880371, 12.5198951721191, 13.1492401123047,
13.310026550293, 13.7720932006836, 10.7566696166992, 11.1153205871582,
10.8651023864746, 10.8898574829102, 11.1934638977051, 10.3416526794434,
10.3679290771484, 10.5599853515625, 10.4897705078125, 10.3551536560059,
10.7984680175781, 9.9300895690918, 9.24563140869141, 8.82577590942383,
8.11003036499023, 9.96226196289063, 10.2302505493164, 10.1707107543945,
9.78019790649414, 9.43962249755859, 11.1743797302246, 11.4034492492676,
10.9475212097168, 11.3065505981445, 11.3690071105957, 9.07691192626953,
8.84776763916016, 8.99648666381836, 9.46799697875977, 10.1394309997559,
9.5390739440918, 9.72808990478516, 10.1971199035645, 10.3575813293457,
10.6958648681641, 12.1900230407715, 11.986629486084, 12.139289855957,
12.308757019043, 12.2176116943359, 10.5569931030273, 10.2808883666992,
9.90982055664062, 9.57319793701172, 9.34677658081055, 9.55350112915039,
9.78641738891602, 10.0147956848145, 10.3079559326172, 10.7283164978027,
8.64087753295899, 8.30433197021484, 8.60956497192383, 8.60016937255859,
8.54900741577148, 9.71597595214844, 8.8296272277832, 8.63880462646484,
8.47726745605469, 8.84029846191406, 10.1157096862793, 9.88607330322266,
9.32783508300781, 9.36255416870117, 10.1161201477051, 11.8296203613281,
12.8728881835937, 13.2580642700195, 13.5822448730469, 14.2079498291016,
8.7088752746582, 8.82841796875, 9.62056427001953, 9.44509429931641,
8.63022689819336, 10.438533782959, 10.7936264038086, 11.1668098449707,
11.4698097229004, 11.6895088195801, 10.657413482666, 10.6490295410156,
10.6090156555176, 10.7308578491211, 10.2125785827637, 8.9413688659668,
8.8182373046875, 8.83381042480469, 8.8937255859375, 8.81535415649414,
9.55851669311523, 9.21836166381836, 9.18197784423828, 9.25029678344726,
9.27070083618164, 8.93240661621094, 8.90249099731445, 9.04313659667969,
9.20108184814453, 9.35103607177734, 10.5618942260742, 11.06572265625,
11.445832824707, 11.9180442810059, 11.9453758239746, 12.2584243774414,
11.9192649841309, 11.7775825500488, 11.8008255004883, 12.2185432434082,
9.08272094726562, 9.66560821533203, 9.48288192749023, 9.70498886108398,
9.56975555419922, 10.349006652832, 10.0300796508789, 9.5968864440918,
9.54965896606445, 9.00812759399414, 10.6454582214355, 10.7713653564453,
11.4645782470703, 11.8325187683105, 10.4740211486816, 9.41022796630859,
9.07474822998047, 8.61860656738281, 8.40045318603516, 8.653662109375,
9.65197830200195, 9.63723449707031, 9.51137924194336, 9.57775497436523,
9.69926528930664, 8.98936157226563, 9.40332794189453, 9.6757568359375,
9.79740600585938, 9.78034057617188, 10.2542152404785, 10.1619010925293,
10.3302688598633, 10.5525291442871, 10.7628135681152, 10.2399101257324,
10.7667839050293, 10.9936302185059, 10.8458152770996, 10.6235733032227,
9.24678955078125, 9.91125411987305, 9.86469879150391, 10.2658912658691,
10.1045028686523, 8.5959098815918, 8.49214401245117, 8.39304656982422,
8.6228157043457, 8.61747360229492, 8.91071395874024, 8.69116439819336,
8.56472625732422, 8.52434997558594, 8.64141616821289, 11.7017639160156,
12.3285125732422, 12.0996276855469, 11.056103515625, 10.7624618530273,
11.0327911376953, 12.0061622619629, 11.4006072998047, 10.8051193237305,
9.97594757080078, 10.138427734375, 10.6871589660645, 11.5516906738281,
12.4771171569824, 12.7644668579102, 9.02487182617188, 8.8429817199707,
9.50254135131836, 9.22763977050781, 8.60505981445312, 9.68806610107422,
9.77085647583008, 9.95944061279297, 10.3024574279785, 10.7512054443359,
8.78317031860352, 8.94360504150391, 9.19855346679688, 9.44350967407227,
10.2734016418457, 11.8314613342285, 12.4076805114746, 12.5829055786133,
12.3372856140137, 11.6992652893066, 8.82733459472656, 8.83338012695313,
9.01612014770508, 9.31243057250976, 9.52871017456055, 9.1939811706543,
9.20086669921875, 9.17466049194336, 9.3692512512207, 9.51042022705078,
9.55322723388672, 9.08766632080078, 9.01230697631836, 9.08840942382812,
8.89073867797851, 10.0157516479492, 9.88614654541016, 9.88927917480469,
9.89448471069336, 9.81435546875, 10.0982810974121, 10.8838890075684,
12.3737106323242, 12.0203163146973, 12.3476577758789, 8.12273559570312,
8.38578720092773, 8.5104736328125, 8.67580947875977, 8.8884521484375,
11.280297088623, 9.81758041381836, 9.12517623901367, 9.57337417602539,
9.93379745483398, 9.97190170288086, 9.9986442565918, 10.1007339477539,
10.368416595459, 10.8695823669434, 10.6418167114258, 10.1072540283203,
9.56202163696289, 10.1464050292969, 11.0315299987793, 15.5208480834961,
16.458154296875, 16.6033325195312, 16.9603851318359, 17.5446258544922,
11.6627197265625, 11.2967132568359, 11.0439735412598, 10.7337928771973,
10.724112701416, 10.414665222168, 10.1816375732422, 10.0053001403809,
10.0604530334473, 10.3831871032715, 12.5386772155762, 12.61123046875,
11.556861114502, 10.815104675293, 10.3798713684082, 12.8164276123047,
12.5301361083984, 12.1416007995605, 11.1006622314453, 10.5525985717773,
12.7033218383789, 13.5069030761719, 14.3273956298828, 14.1952850341797,
13.8862731933594, 11.5364295959473, 11.4725784301758, 11.4327659606934,
11.6338516235352, 11.9929733276367, 10.9388458251953, 10.3944259643555,
10.7864356994629, 10.4639877319336, 10.4192794799805, 10.584090423584,
11.0457565307617, 11.1049293518066, 11.2156471252441, 11.2940994262695,
11.5789703369141, 11.3852058410645, 11.312281036377, 10.8983863830566,
10.7498306274414, 11.648999786377, 12.1443000793457, 12.3075752258301,
12.4243774414062, 12.5793846130371, 9.53582992553711, 10.3421630859375,
10.6005973815918, 10.7018409729004, 10.1489151000977, 15.3236968994141,
16.6732727050781, 17.0259368896484, 16.9183380126953, 18.6379180908203,
11.5663963317871, 13.1421661376953, 15.772624206543, 15.2286743164063,
14.1305938720703, 10.4395881652832, 10.3302070617676, 10.3431907653809,
10.6234725952148, 10.6850440979004, 10.1355682373047, 10.7770133972168,
11.2220344543457, 11.121208190918, 10.9759727478027, 10.4280487060547,
11.4163436889648, 11.5880157470703, 11.367276763916, 11.7584564208984,
12.3622993469238, 12.8618209838867, 13.0096267700195, 12.7293991088867,
12.3698738098145, 13.4502487182617, 13.9361175537109, 14.3981384277344,
14.8455154418945, 14.7898071289063, 10.8285942077637, 11.0353393554688,
13.0554183959961, 11.4933654785156, 10.6509674072266, 12.3171768188477,
11.9701278686523, 11.7984405517578, 11.3652336120605, 11.2212104797363,
11.7747032165527, 12.0631629943848, 11.609635925293, 12.5300575256348,
12.5889640808105, 14.9442291259766, 15.244026184082, 15.1138778686523,
14.8327117919922, 14.0672607421875, 13.8624649047852, 14.0361633300781,
13.746142578125, 13.3890182495117, 12.7229309082031, 11.7338531494141,
12.4392601013184, 12.6126739501953, 12.3359680175781, 12.0300300598145,
13.0475494384766, 13.4870010375977, 13.1330673217773, 12.8889770507812,
11.5218353271484, 12.9545684814453, 12.6848930358887, 12.5185249328613,
12.1927146911621, 12.1243927001953, 13.6282653808594, 13.0329132080078,
14.021321105957, 12.7892906188965, 11.5679710388184, 12.4451988220215,
12.6035362243652, 12.8059692382812, 13.2598541259766, 14.1865646362305,
11.4154563903809, 12.0055801391602, 12.315015411377, 12.8833023071289,
13.0320266723633, 11.3923133850098, 12.2035797119141, 12.3115371704102,
12.4416717529297, 12.8906295776367, 11.4880004882812, 11.4702560424805,
11.063402557373, 11.520093536377, 11.4941116333008, 10.2884147644043,
10.4248268127441, 10.2943084716797, 10.4938522338867, 10.171199798584,
10.8181655883789, 10.7096382141113, 10.3980682373047, 9.85380783081055,
9.06302337646484, 11.087833404541, 11.297770690918, 11.4384208679199,
11.8333045959473, 12.6423866271973, 11.0677742004395, 11.1663566589355,
14.6535186767578, 12.696688079834, 11.9809646606445, 12.5395179748535,
13.5047088623047, 13.6589874267578, 13.3168762207031, 13.8064010620117,
13.2664398193359, 12.1466331481934, 11.7755020141602, 11.2214569091797,
11.967204284668, 13.3286544799805, 13.0230804443359, 12.4111663818359,
11.5664184570313, 11.507154083252, 10.7482841491699, 10.2523262023926,
10.5137763977051, 10.6416915893555, 10.925708770752, 12.1461143493652,
12.5572776794434, 13.0962661743164, 14.0371612548828, 15.6014785766602,
12.1392105102539, 12.4931434631348, 12.5056259155273, 12.1932655334473,
12.1573226928711, 12.3337669372559, 12.2943237304688, 12.3938110351563,
12.3535987854004, 12.2837997436523, 11.199015045166, 11.0299026489258,
11.4233680725098, 11.3639068603516, 10.776929473877, 15.9578018188477,
18.5940185546875, 16.6747985839844, 12.2459892272949, 11.7588233947754,
10.8550109863281, 9.30074844360352, 9.1522102355957, 9.23973083496094,
9.94997406005859, 21.4329086303711, 20.6476043701172, 20.4366928100586,
19.5227752685547, 18.6518371582031, 13.4605987548828, 13.7962448120117,
14.7393859863281, 14.0098480224609, 13.7022705078125, 13.8268768310547,
13.9131362915039, 14.1420150756836, 14.5985153198242, 15.3337585449219,
10.2976509094238, 10.6874450683594, 10.6152442932129, 10.3048629760742,
10.0026962280273, 10.8500930786133, 12.313077545166, 12.8156112670898,
12.4003845214844, 12.062833404541, 11.8806510925293, 11.9595237731934,
12.7401191711426, 13.2080368041992, 12.648217010498, 14.9934814453125,
16.2576446533203, 16.2247314453125, 15.6419891357422, 14.6681213378906,
10.2608001708984, 10.204532623291, 10.8466209411621, 10.8580635070801,
10.5870002746582, 12.5249855041504, 13.235661315918, 13.3415161132812,
13.2680938720703, 13.6001312255859, 10.9847831726074, 10.9526977539062,
12.1701835632324, 10.9867134094238, 9.62559356689453, 14.671305847168,
15.7670822143555, 16.5200897216797, 17.2838760375977, 18.5971923828125,
12.4218063354492, 11.5890487670898, 11.3723731994629, 11.5280731201172,
12.0742370605469, 11.0745147705078, 10.6635795593262, 10.507258605957,
10.358984375, 10.2047622680664, 11.231372833252, 11.1456260681152,
10.8480117797852, 10.3289199829102, 9.81418380737305, 13.1054672241211,
13.3634078979492, 13.6211837768555, 14.0335067749023, 13.8940582275391,
11.4586517333984, 11.3107444763184, 12.1839057922363, 11.6442543029785,
10.0313461303711, 11.5685440063477, 13.461506652832, 13.9238220214844,
12.9616546630859, 12.0961059570313, 15.3089569091797, 14.529133605957,
12.9434677124023, 11.6556198120117, 10.7868843078613, 13.7810775756836,
14.6285568237305, 14.3505905151367, 12.6306495666504, 11.0644081115723,
13.6406951904297, 13.0658325195313, 11.6025444030762, 10.8227111816406,
10.6873641967773, 14.1373397827148, 15.3703903198242, 16.4337646484375,
16.3727081298828, 16.0835571289062, 9.32263946533203, 9.81831588745117,
10.2201850891113, 10.4734298706055, 10.432006072998, 9.83030319213867,
9.97000503540039, 10.0799949645996, 10.1364440917969, 10.2572006225586,
11.0884750366211, 11.7081008911133, 11.6705154418945, 11.3407791137695,
10.8895950317383, 12.5218650817871, 14.0942642211914, 14.4718688964844,
13.89228515625, 13.6701507568359, 12.1981781005859, 12.0445930480957,
13.2136001586914, 12.3655586242676, 11.3412635803223, 12.4833915710449,
11.7754150390625, 11.693514251709, 12.1434707641602, 12.578157043457,
10.8240905761719, 10.6200454711914, 10.1548942565918, 9.93075942993164,
10.2509727478027, 15.1843124389648, 15.0255569458008, 14.8466598510742,
15.1112106323242, 16.322314453125, 13.0618423461914, 14.1408599853516,
13.0202850341797, 13.6123336791992, 14.1315383911133, 12.7721778869629,
12.7291236877441, 13.1240371704102, 13.9317779541016, 14.8634048461914,
11.2654998779297, 12.3573486328125, 13.258935546875, 12.5885932922363,
12.298176574707, 13.9735443115234, 14.5013107299805, 15.1036834716797,
15.3642013549805, 15.3964065551758, 11.2573120117187, 11.9989395141602,
12.0881286621094, 12.2077728271484, 12.2564170837402, 10.4119132995605,
10.5908760070801, 10.9370986938477, 10.9051147460937, 11.1913566589355,
12.3859100341797, 12.3887336730957, 13.8762435913086, 14.5053375244141,
14.3133880615234, 13.3645736694336, 12.5263206481934, 12.3438980102539,
12.354638671875, 13.1039337158203, 11.9940643310547, 11.8350044250488,
12.025373840332, 12.0098609924316, 12.8584075927734, 13.5398986816406,
13.7642166137695, 14.2189575195312, 14.8441345214844, 15.6326904296875,
14.128108215332, 13.0739379882812, 11.9704299926758, 11.3222679138184,
12.2943817138672, 13.596760559082, 13.6019485473633, 13.8898880004883,
14.744856262207, 15.6628112792969, 12.945686340332, 13.7123504638672,
...
.Dim = c(10L, 140L), .Dimnames = list(NULL,
c("layer.1", "layer.2", "layer.3", "layer.4", "layer.5",
"layer.6", "layer.7", "layer.8", "layer.9", "layer.10", "layer.11",
"layer.12", "layer.13", "layer.14", "layer.15", "layer.16",
"layer.17", "layer.18", "layer.19", "layer.20", "layer.21",
"layer.22", "layer.23", "layer.24", "layer.25", "layer.26",
"layer.27", "layer.28", "layer.29", "layer.30", "layer.31",
"layer.32", "layer.33", "layer.34", "layer.35", "layer.36",
"layer.37", "layer.38", "layer.39", "layer.40", "layer.41",
"layer.42", "layer.43", "layer.44", "layer.45", "layer.46",
"layer.47", "layer.48", "layer.49", "layer.50", "layer.51",
"layer.52", "layer.53", "layer.54", "layer.55", "layer.56",
"layer.57", "layer.58", "layer.59", "layer.60", "layer.61",
"layer.62", "layer.63", "layer.64", "layer.65", "layer.66",
"layer.67", "layer.68", "layer.69", "layer.70", "layer.71",
"layer.72", "layer.73", "layer.74", "layer.75", "layer.76",
"layer.77", "layer.78", "layer.79", "layer.80", "layer.81",
"layer.82", "layer.83", "layer.84", "layer.85", "layer.86",
"layer.87", "layer.88", "layer.89", "layer.90", "layer.91",
"layer.92", "layer.93", "layer.94", "layer.95", "layer.96",
"layer.97", "layer.98", "layer.99", "layer.100", "layer.101",
"layer.102", "layer.103", "layer.104", "layer.105", "layer.106",
"layer.107", "layer.108", "layer.109", "layer.110", "layer.111",
"layer.112", "layer.113", "layer.114", "layer.115", "layer.116",
"layer.117", "layer.118", "layer.119", "layer.120", "layer.121",
"layer.122", "layer.123", "layer.124", "layer.125", "layer.126",
"layer.127", "layer.128", "layer.129", "layer.130", "layer.131",
"layer.132", "layer.133", "layer.134", "layer.135", "layer.136",
"layer.137", "layer.138", "layer.139", "layer.140")))
For the x-axis, I already have 140 values to be plotted. The x variable is called "RCP1pctCO2cumulative" and is 1-dimensional. Here are the values:
dput(RCP1pctCO2cumulative)
c(0, 0.00697490638121963, 0.0139075990766287, 0.021697436273098,
0.0302329704165459, 0.0389980841428041, 0.0486239280551672,
0.0591636016964912,
0.0698652867227793, 0.0806971430778503, 0.0917696304619312,
0.102874741703272,
0.115288959443569, 0.127942492067814, 0.140930585563183, 0.154951927065849,
0.169483987987041, 0.18332038372755, 0.197460225224495, 0.211912712454796,
0.227608525753021, 0.243575794994831, 0.257900005578995, 0.273098181188107,
0.288984017074108, 0.305822652578354, 0.321933174133301, 0.338437202572823,
0.356079193949699, 0.373604437708855, 0.389580103754997, 0.406976979970932,
0.423514771461487, 0.440741804242134, 0.459019854664803, 0.477243804931641,
0.494844323396683, 0.511731442809105, 0.529583910107613, 0.54879242181778,
0.568029862642288, 0.587030050158501, 0.606201952695847, 0.626413214206696,
0.645859175920486, 0.66550235748291, 0.685490393638611, 0.705517685413361,
0.725719237327576, 0.74520371556282, 0.764879602193832, 0.78538470864296,
0.806885379552841, 0.827258145809174, 0.847640424966812, 0.869502395391464,
0.891108268499374, 0.912525850534439, 0.934271132946014, 0.956432664394379,
0.977902102470398, 0.999574398994446, 1.02313443422317, 1.0449088037014,
1.06765602231026, 1.09229186177254, 1.11614397168159, 1.13850414156914,
1.16062269210815, 1.18386173844337, 1.2078672170639, 1.23217906951904,
1.25505521297455, 1.27949770689011, 1.30394254922867, 1.32788743972778,
1.35124933719635, 1.37474408149719, 1.39838930368423, 1.42129179239273,
1.44566521644592, 1.47075144052506, 1.49397988319397, 1.51616193056107,
1.54051134586334, 1.56606665849686, 1.59053231477737, 1.61592463254929,
1.64096541404724, 1.66613935232162, 1.69049085378647, 1.71510955095291,
1.73991868495941, 1.76491104364395, 1.79114699363708, 1.81589571237564,
1.84101955890656, 1.864857172966, 1.8899533867836, 1.91575677394867,
1.9422261595726, 1.96840007305145, 1.99298502206802, 2.01899757385254,
2.04547454118729, 2.07122528553009, 2.09852977991104, 2.12717348337173,
2.15352830886841, 2.17984690666199, 2.20684263706207, 2.23266286849976,
2.25915194749832, 2.28647100925446, 2.31463184356689, 2.34280925989151,
2.36965861320496, 2.39779574871063, 2.42558825016022, 2.45266799926758,
2.48168079853058, 2.50962221622467, 2.53702754974365, 2.56574511528015,
2.59377150535583, 2.62192821502686, 2.6505597114563, 2.68051118850708,
2.70983340740204, 2.73927145004272, 2.76805067062378, 2.79780313968658,
2.8272668838501, 2.85747616291046, 2.88714888095856, 2.91689431667328,
2.94743349552155, 2.97868416309357, 3.00965495109558, 3.03861720561981
I tried doing something like this to start:
expansion <- expand.grid(103:116, 3:16) #to specify a range of longitudes
and latitudes
lonlat <- extract(RCP1pctCO2Mean, expansion)
plot(RCP1pctCO2cumulative, lonlat, type="l",col="green", lwd="3",
xlab="Cumulative emissions (TtC)", ylab="One-day maximum precipitation
(mm/day)", main="Test model")
But this yields the error:
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' and 'y' lengths differ
If it helps, here are the dimensions of the new variables created:
dim(lonlat)
[1] 196 140
dim(expansion)
[1] 196 2
What could I be doing wrong (the lengths appear to be the same)? Ultimately, the goal would be to plot the 140 values as a function of emissions (i.e. "RCP1pctCO2Mean" as a function of "RCP1pctCO2cumulative" once each of those selected grid cells are aggregated). The above works absolutely fine when just selecting "one" specific grid cell, but not an aggregate of grid cells. Is this possible to do for an aggregate of grid cells?
Thanks, and any assistance would be greatly appreciated!

Resources