Open TripleEmma opened 6 months ago
Yes, but the number of polygons returned is the same. Maybe some grid cells touching the pole become triangles in geographical coordinates, and loose one node, hence the smaller number of coordinates?
Sorry to ask the very basic question but how to fix this then? Thank you!
Fix what?
There is error when applying st_join() on grid4326.
geneCoor <- geneMetaUsed %>% dplyr::select(ID, longitude, latitude)
geneMetaUsed.sf <- st_as_sf(geneCoor, coords=c("longitude", "latitude"))
st_crs(geneMetaUsed.sf) <- 4326
gridGenes <- st_join(grid4326, geneMetaUsed.sf) # grid4326 resulted from grid4326 <- st_transform(grid, 'EPSG:4326')
Error in wk_handle.wk_wkb(wkb, s2_geography_writer(oriented = oriented, Loop 0 is not valid: Non-empty, non-full loops must have at least 3 vertices
Please modify your reproducible example such that it exposes the error; geneMetaUsed
is not known.
geneMetaUsed
is a data frame with several columns. Here I just selected three of them, including 'longitude' and 'latitude'.
geneCoor <- geneMetaUsed %>% dplyr::select(ID, longitude, latitude)
head(geneCoor)
> head(geneCoor) # A tibble: 6 × 3 ID longitude latitude
1 MK262583_2309838992 172. -40.4 2 MK262588_2308522646 172. -43.2 3 MK262601_2311115935 172. -40.4 4 GQ481466_2309171845 50.4 58.4 5 GQ481467_2310943848 178. 64.2 6 GQ481468_2308837004 34.9 69.0
I once did it as following, and it works fine, no error.
geneCoor <- geneMetaUsed %>% dplyr::select(ID, longitude, latitude)
geneMetaUsed.sf <- st_as_sf(geneCoor, coords=c("longitude", "latitude"))
st_crs(geneMetaUsed.sf) <- 4326
geneMetaUsed.sf <- st_transform(geneMetaUsed.sf, "ESRI:54017")
gridGenes <- st_join(grid, geneMetaUsed.sf) # CRS of grid is "ESRI:54017"
@edzer I am sorry if I misunderstood your idea. I had a mistake in the original code, the final geneMetaUsed.sf
should be derived from geneCoor
(fixed in previous posts). geneCoo
has three columns, including "longitude" and "latitude".
I have a sf object created like the following (I need the polygons to be equal size), and in order to accommodate with other downloaded data, I convert these polygons back to 'EPSG:4326'. Both objects have the same number of polygons, but different coordinates. Specifically, the latter sf has some polygons with missing vertices. I noticed this when applying st_join() on the latter polygons (grid4326). There is error: Error in wk_handle.wk_wkb(wkb, s2_geography_writer(oriented = oriented, Loop 0 is not valid: Non-empty, non-full loops must have at least 3 vertices'.