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

2020-06-21 Thread Lom Navanyo
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 <
jmartine...@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 ()
> 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@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: jmartine...@uasd.edu.do
> Página web: http://geografiafisica.org
>

[[alternative HTML version deleted]]

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


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

2020-06-20 Thread Tim Salabim
And for anyone looking for arguments:

http://switchfromshapefile.org/


On Sat, Jun 20, 2020, 18:20 Edzer Pebesma 
wrote:

>
>
> On 6/20/20 12:28 PM, Lom Navanyo wrote:
> > Unknown field name `Act_Depthtwtr': updating a layer with improper field
> > name(s)?
>
> Shapefiles have funny restrictions as to the length and form of variable
> names, you probably ran into that, as the message suggests.
>
> A general advice is to not use shapefiles for writing; there are better
> alternatives, geopackage comes to mind. Shapefiles make life unnecessary
> complicated, you've now run into two of the many problems they have. The
> days of creating shapefiles are over. If someone asks you to create
> shapfiles, explain them it is a bad idea.
> --
> Edzer Pebesma
> Institute for Geoinformatics
> Heisenbergstrasse 2, 48149 Muenster, Germany
> Phone: +49 251 8333081
> ___
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

[[alternative HTML version deleted]]

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


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

2020-06-20 Thread Edzer Pebesma


On 6/20/20 12:28 PM, Lom Navanyo wrote:
> Unknown field name `Act_Depthtwtr': updating a layer with improper field
> name(s)?

Shapefiles have funny restrictions as to the length and form of variable
names, you probably ran into that, as the message suggests.

A general advice is to not use shapefiles for writing; there are better
alternatives, geopackage comes to mind. Shapefiles make life unnecessary
complicated, you've now run into two of the many problems they have. The
days of creating shapefiles are over. If someone asks you to create
shapfiles, explain them it is a bad idea.
-- 
Edzer Pebesma
Institute for Geoinformatics
Heisenbergstrasse 2, 48149 Muenster, Germany
Phone: +49 251 8333081


pEpkey.asc
Description: application/pgp-keys
___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


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

2020-06-20 Thread Jose Ramon Martinez Batlle
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 () 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@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: jmartine...@uasd.edu.do
Página web: http://geografiafisica.org

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


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

2020-06-20 Thread Lom Navanyo
Dear Bede-Fazekas,

Thank you for the swift response.
I confirm that all key values in y (balance5) are in x (parcel1). I used
all.y=TRUE because y the IDs (key values in y) are actually a subset of x.
However, what I cannot confirm is if the key variables combination
c('PARCEL_ID','CAL_YEAR') match perfectly from the two data sets.
I therefore changed the merging as:
mergedparcel2 <- merge(parcel1, balance5, by=c('PARCEL_ID','CAL_YEAR'))

I still get the following error:
> st_write(mergedparcel2,"mergedparcel2.shp")
Writing layer `mergedparcel2' to data source `mergedparcel2.shp' using
driver `ESRI Shapefile'
Writing 4682 features with 204 fields and geometry type Multi Polygon.
Unknown field name `Act_Depthtwtr': updating a layer with improper field
name(s)?
Error in CPL_write_ogr(obj, dsn, layer, driver,
as.character(dataset_options),  :
  Write error
In addition: There were 21 warnings (use warnings() to see them)

-
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


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

2020-06-20 Thread Bede-Fazekas Ákos

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


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

2020-06-20 Thread Lom Navanyo
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