Error message when converting coordinates to WGS84

While attempting to convert a shape file I received an error message stating the following:

Error in wk_handle.wk_wkb(wkb, s2_geography_writer(oriented = oriented, :
Loop 15 is not valid: Edge 6 has duplicate vertex with edge 14

The shape file I am using is from the Los Angeles County GIS website (its a shapefile for all of the cities in Los Angeles County)

What does this error message mean? Is there an issue with the shape file?

Here is an example of my R code

 City_Boundaries_Lines_wgs84 <- City_Boundaries_Lines %>%
 st_buffer(0) %>% # Make invalid geometries valid
 st_transform(crs = 4326)  # Convert coordinates to WGS84

Hi @carmong
For accurate troubleshooting, we need the exact source of the shapefile (the link to download for example) for reproducibility.

Since I can’t reproduce it, I leave a suggestion for you to test:
add the st_make_valid() function to your command before any operation

City_Boundaries_Lines_wgs84 <- City_Boundaries_Lines %>%
 st_make_valid() %>%
 st_buffer(0) %>% # Make invalid geometries valid
 st_transform(crs = 4326)  # Convert coordinates to WGS84

Lucca

Here is the link to the shapefile

I used the code you suggested but when I attempted to join the city shape file with my data file I got the same error message

LA_county_hospital_data_sf <- hospcity_hd_city %>%
  st_as_sf(coords = c("LONGITUDE", "LATITUDE"), crs = 4326)


# Applied Epi Code for City Shape file ------------------------------------

City_Boundaries_Lines_wgs84 <- City_Boundaries_Lines %>%
  st_make_valid() %>%
  st_buffer(0) %>% # Make invalid geometries valid
  st_transform(crs = 4326)  # Convert coordinates to WGS84

occupation_map_sf <- City_Boundaries_Lines %>% st_join(., LA_county_hospital_data_sf) 

Error in wk_handle.wk_wkb(wkb, s2_geography_writer(oriented = oriented, :
Loop 15 is not valid: Edge 6 has duplicate vertex with edge 14

Maybe this is happening because you are using the object City_Boundaries_Lines , try using the object City_Boundaries_Lines_wgs84 which would theoretically be with the valid geometries

occupation_map_sf <- City_Boundaries_Lines_wgs84 %>% st_join(., LA_county_hospital_data_sf)

[image]

It looks like the error message is happening earlier in the code than i first thought

LA_county_hospital_data_sf <- hospcity_hd_city %>%
+   st_as_sf(coords = c("LONGITUDE", "LATITUDE"), crs = 4326)
> City_Boundaries_Lines_wgs84 <- City_Boundaries_Lines %>%
+   st_buffer(0) %>% # Make invalid geometries valid
+   st_transform(crs = 4326)  # Convert coordinates to WGS84
Error in wk_handle.wk_wkb(wkb, s2_geography_writer(oriented = oriented,  : 
  Loop 15 is not valid: Edge 6 has duplicate vertex with edge 14
> 

Here is a link to the geodata that I am attempting to use