Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

st_intersection fails with census data #2489

Open
kmichelson opened this issue Dec 13, 2024 · 1 comment
Open

st_intersection fails with census data #2489

kmichelson opened this issue Dec 13, 2024 · 1 comment

Comments

@kmichelson
Copy link

Describe the bug
When attempting to use st_intersection with a multipolygon downloaded directly from the US Census representing two Florida cities and a multipolygon representing a single Florida ZIP, the following error is given:
Error in [[<-.data.frame(*tmp*, attr(x, "sf_column"), value = list( :
replacement has 4 rows, data has 2

To Reproduce
Load the two SFCs and perform st_intersection(x,y) - I have attached a ZIP containing x and y as SHP files and both SFCsh in an rdata file

Additional context
The polygons are attached to this bug report

R version 4.4.0 (2024-04-24) Platform: aarch64-apple-darwin20 Running under: macOS 15.1.1

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Chicago
tzcode source: internal

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] sf_1.0-18

loaded via a namespace (and not attached):
[1] compiler_4.4.0 magrittr_2.0.3 class_7.3-22 s2_1.1.6
[5] DBI_1.2.2 tools_4.4.0 units_0.8-5 proxy_0.4-27
[9] rstudioapi_0.16.0 wk_0.9.1 Rcpp_1.0.12 KernSmooth_2.23-22
[13] grid_4.4.0 e1071_1.7-14 classInt_0.4-10

[mwe.zip](https://github.com/user-attachments/files/18129047/mwe.zip)
@kadyb
Copy link
Contributor

kadyb commented Dec 13, 2024

I think you have two options:

  1. Indicate that only polygons are to be returned (using S2 engine):
st_intersection(x, y, dimensions = "polygon")
  1. Reproject to a planar coordinate system and use the GEOS engine:
xx = st_transform(x, "EPSG:6439")
yy = st_transform(y, "EPSG:6439")
st_intersection(xx, yy)

BTW: You only sent .shp file in the attachment, but in fact it should be several related files (https://www.reddit.com/r/gis/comments/sbp8r9/please_find_the_shapefile_attached/). If you want to use one file, see geopackage (.gpkg) format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants