I have a SpatialPolygonsDataFrame in R that I want to export to shapefile. I used writeOGR to export but the cells with that contain text values with accents (é, è, à, ê, etc) are blank. When I export only the data slot as a csv file, the values are preserved.

I have used the following when exporting:

writeOGR(obj=for.ana, dsn=".", layer="for_export",driver="ESRI Shapefile", encoding="UTF-8")

When I want to import a similar shapefile with French accents, I use the following code that works:

readOGR(".","file", use_iconv=TRUE, encoding="UTF-8")

What is the equivalent code for exporting?

enter image description here

  • For sure you could share test data that has one random polygon with attributes and values which are alike your real data.
    – user30184
    Mar 15, 2018 at 15:02

1 Answer 1



writeOGR(obj=for.ana, dsn=".", layer="for_export",driver="ESRI Shapefile", layer_options = "ENCODING=UTF-8")

Instead of:

writeOGR(obj=for.ana, dsn=".", layer="for_export",driver="ESRI Shapefile", encoding="UTF-8")

With layer_options, you add the parameters to ogr2ogr shell command. Check GDAL documentation for more options.

  • @user3386170 ok. Edited and tested
    – aldo_tapia
    Mar 16, 2018 at 16:05
  • When I opened the file in QGIS, I had to set encoding to system in order for the accents to display correctly (instead of UTF-8). An easy fix but odd given that the encoding is set to UTF-8. Mar 16, 2018 at 19:30
  • Weird, I tested it with success. What is the output of Sys.getenv('LC_CTYPE') from R?
    – aldo_tapia
    Mar 16, 2018 at 19:34
  • And for Sys.getlocale()?
    – aldo_tapia
    Mar 16, 2018 at 19:49
  • "LC_COLLATE=French_Canada.1252;LC_CTYPE=French_Canada.1252;LC_MONETARY=French_Canada.1252;LC_NUMERIC=C;LC_TIME=French_Canada.1252" Mar 16, 2018 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.