[R-sig-Geo] Error when saving an sf (data) object to file as a shapefile

Lom Navanyo |omn@v@@|@ @end|ng |rom gm@||@com
Sun Jun 21 09:15:43 CEST 2020


I have write permission to the folder. I have also now called the raster
package, coerced the sf object to Spatial and could save as a shapefile.
But just as you hinted and was further explained by Edzer and Tim, the
shapefile could not be used elsewhere.

Thank you all for the support.

--------
Lom

On Sat, Jun 20, 2020 at 8:46 AM Jose Ramon Martinez Batlle <
jmartinez19 using uasd.edu.do> wrote:

> Hello.
>
> The "Write error" seems a permissions issue. Do you have write
> permission to the folder you are trying to save the file? You can see
> the default path by typing getwd() in the console.
>
> Regarding the error message you got while trying to write the shape
> using the shapefile function, I guess you mean the function belonging
> to the raster package, which you may don't have installed in your
> computer. That may be the reason why R can't find the function after
> searching in your libraries.
>
> If you type ?raster::shapefile in the console, with the raster package
> installed, you will find the documentation of the function, where the
> argument x (the source) is defined as "character (a file name, when
> reading a shapefile) or Spatial* object (when writing a shapefile)".
> So if you provide an object (which you did), it must be an object of
> class Spatial*, but the one you provided seems to be an sf object. You
> can try to coerce the Spatial to an sf object, but I advise against
> that, because it is an unnecessary workaround when using the sf
> workflow.
>
> BTW, try to avoid using shapefile as the default format.
>
> Best regards.
>
>
>
> El sáb., 20 jun. 2020 a las 4:44, Lom Navanyo (<lomnavasia using gmail.com>)
> escribió:
> >
> > 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 using r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
>
> --
> José Ramón Martínez Batlle
> Investigador/Profesor Universidad Autónoma de Santo Domingo (UASD)
> Correo electrónico: jmartinez19 using uasd.edu.do
> Página web: http://geografiafisica.org
>

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list