I am trying to check if my points are within polygons. And I struggle with wkt converting despite reading many post around it.
I have points list (flare) which I manage to convert to spatial and assign projection.
This is very difficult to debug without having access to the data. When I face this kind of mysterious error, I try to identify which line exactly fails. Since you mention that a random line works, you could try all lines until one fails.
for (i in seq_len(nrow(poly.df)) {
st_as_sfc(poly.df[i, 3])
}
When the loop stops, compare it with the previous lines
poly.df[i - 2:0, 3]
Make sure that the WKT field was not truncated by Excel and that it is complete with matching parenthesis. Polygon WKT can be quite long. If that's the case, then having access to the original data (preferably not in xlsx, but in a spatial format) is the best solution, but you could still work around the issue by finding all the offending lines and filtering them from poly.df.
Thank you for your reply and support on this topic. Indeed some rows in my excel data set are not complete with matching parenthesis. I could maybe try to call for API containing data directly from R but it will be still WKT format.
Now a total dummy (which I am with R) question when I use the code you provided for loops and poly.df[i - 2:0, 3] this prints the lines with data but not the number of row in data frame it is... how would I get a list of all number of rows in dataframe which cause issue ?
Kind regards and one more time big thank you!
Dorota
Thanks again for help. I seem to be achieving some results however still confusing. My output seem to only indicate number of row of polygon the point match but not actual ID this seems not that simple excercise after all