I'd like to convert a shapefile (sel_stands_CMPC.shp) to geoJSON and after to data.frame, but the the list to data.frame I have the error of differing number of rows. I need geoJSON and dataframe data, then is not the case of shapefile to dataframe simple conversion. I try to do:
library(sf)
library(geojsonsf)
library(plyr)
library(geojsonR)
# get AOI in shapefile
download.file(
"https://github.com/Leprechault/trash/raw/main/sel_stands_CMPC.zip",
zip_path <- tempfile(fileext = ".zip")
)
unzip(zip_path, exdir = tempdir())
# Open the file
setwd(tempdir())
stands_sel <- st_read("sel_stands_CMPC.shp")
# Reading layer `sel_stands_CMPC' from data source `C:\Users\fores\AppData\Local\Temp\Rtmp6l1bGx\sel_stands_CMPC.shp' using driver `ESRI Shapefile'
# Simple feature collection with 2 features and 16 fields
# Geometry type: MULTIPOLYGON
# Dimension: XY
# Bounding box: xmin: -52.3284 ymin: -30.43305 xmax: -51.21323 ymax: -30.35118
# Geodetic CRS: GCS_unknown
# Open as geoJSON
geo <- sf_geojson(stands_sel)
# Convert to data frame for *CSV export
geo_js_df <- plyr::ldply(FROM_GeoJson(geo), data.frame)
# Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, :
# arguments imply differing number of rows: 144, 62, 29