I am working to re-aggregate population counts from one administrative level to another. One particular row keeps returning the error "replacement has 4 rows, data has 2".
I have tried validating the geometries, but it has not worked. Neither did a buffer with 0 distance.
I was preparing the dummy data for posting this question using dput(). After saving the dput() of the sf layers into a text file, the command line works after re-assigning the variables. This only works when using the dput output saved in a textfile, but it does not work if I directly do
st_interpolate_aw(dput(geography1),dput(geography2), extensive = TRUE).
This returns the same error.
Is there any known reason why the error might be happening, and how saving the dput() output into a .txt file might be removing the error?
note - Is there any way to share the features other than dput()? the high amount of vertices in one of the layers surpasses the character limit for the question
edit I think I managed to export a geojson with the error, in case you are interested in checking it: https://drive.google.com/file/d/1wF6AB1oHVEkcuI4iRAloLO56DL_8EZBr/view?usp=sharing
I believe the issue lies with the nature of the intersection of the two objects; it seems that the intersection produces two polygon type objects (perfectly OK) and two line type objects; these have by definition zero area which kind of messes up the interpolation process.
You have two options:
sf::st_interpolate_aw()to force a filter to polygon-geometries behind the scenes{s2}to trusty old GEOSI suggest doing the latter, as shown in the code bellow, but making a pull request to
{sf}would be the cowboy thing to do :)