Dear Lom,

Since you did not provide reproducible example, I can only guess...
You used merge(, all.y = TRUE). This might produce an sf object of type GEOMETRY and some "GEOMETRYCOLLECTION EMPTY" in the geometry column, if some of the key values of y (balance5) are not found in the key values of x (parcel1). ESRI shapefile cannot accept mixed geometries, this might be the reason that you cannot write the dataset to shp format.

HTH,
Ákos Bede-Fazekas
Hungarian Academy of Sciences


2020.06.20. 10:43 keltezéssel, Lom Navanyo írta:
Hello,

I have had to merge a shapefile that I read into R as an sf object with a
.csv data containing  some variables. Now I want to save the merged data to
a file (a folder on my pc). I am however getting following error:

Error in CPL_write_ogr(obj, dsn, layer, driver,
as.character(dataset_options),  :
   Write error

Below is a snippet of code used:
library(sf)
library(dplyr)
library(ggplot2)
library(stringr)
library(rgdal)
library(sp)

parcel1 <- st_read("parcels_all.shp")
balance5 <- read.csv("Balanced_5.csv")

mergedparcel <- merge(parcel1, balance5, by=c('PARCEL_ID','CAL_YEAR'),
all.x = FALSE, all.y=TRUE)

st_write(mergedparcel,"mergedparcel.shp")

I also used the shapefile function thus:

shapefile(mergedparcel , "D:/Documents/mergedparcel.shp")
  This also gives me:
Error in shapefile(mergedparcel, "D:/Documents/
Documents/mergedparcel.shp") :
   could not find function "shapefile"

Am I doing this right?
Any suggestion to resolve this issue would be appreciated.

-----------------
Lom

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to