How to convert Multipolygon column to sfc column? R

79 views Asked by At

I´m having trouble converting coordinates data to sf format. I exported a csv file from QGIS with attributes of several political units with their respective coordinates. Because I'm working with polygons I exported the csv file from QGIS as WKT (MultiPolygon Z).

However, when I import the csv file into R, it takes the coordinate column as a character instead of sfg.Therefore, I use the st_as_sf function, but it returns the following error:

all_sf <- all2 %>% st_as_sf(wkt = "geometry", crs = 4326) 
OGR: Corrupt data Error: OGR error
OBJECTID Distrito Año geometry
13939 Alberdi 1996 MULTIPOLYGON Z (((-60.32233429 -34.7621421809999 0,-6...
13939 Alberdi 1997 MULTIPOLYGON Z (((-60.32233429 -34.7621421809999 0,-6...

(1000 rows more)

str(all2)'data.frame':  1058 obs. of  5 variables:
$ OBJECTID : chr  "13939" "13939" "13939" "13939" ...
$ Distrito : chr  "Alberti" "Alberti" "Alberti" "Alberti" ...
$ Año      : chr  "1996" "1997" "1998" "1999" ...
$ toneladas: num  0 0 0 0 0 0 0 0 0 0 ...
$ geometry : chr  "MULTIPOLYGON Z (((-60.32233429 -34.7621421809999 0,-60.2506828309999 -34.8179740909999 0,-60.2398338319999 -34."| truncated "MULTIPOLYGON Z (((-60.32233429 -34.7621421809999 0,-60.2506828309999 -34.8179740909999 0,-60.2398338319999 -34."| truncated "MULTIPOLYGON Z (((-60.32233429 -34.7621421809999 0,-60.2506828309999 -34.8179740909999 0,-60.2398338319999 -34."| truncated "MULTIPOLYGON Z (((-60.32233429 -34.7621421809999 0,-60.2506828309999 -34.8179740909999 0,-60.2398338319999 -34."| truncated ...
0

There are 0 answers