1

I performed an intersection of two SpatialPolygonsDataFrame on R (3.5.1) using raster::intersect. Here's the structure of the resulting SPDF attributes table

> str(shp@data)
'data.frame':   944 obs. of  7 variables:
 $ COD5      : chr  "1122" "1122" "1122" "1122" ...
 $ LIV_1     : chr  "1" "1" "1" "1" ...
 $ LIV_2     : chr  "1" "1" "1" "1" ...
 $ LIV_3     : chr  "2" "2" "2" "2" ...
 $ LIV_4     : chr  "2" "2" "2" "2" ...
 $ LIV_5     : chr  NA NA NA NA ...
 $ SHAPE_AREA: num  23499 10474 5227 13752 71721 ...

enter image description here

I exported the SPDF with rgdal::writeOGR

writeOGR(shp, 'C:/foo', 'shp', 'ESRI Shapefile', overwrite_layer=T)

but QGIS 3.4 LTR was unable to display attributes correctly

enter image description here

Is it an enconding problem with rgdal::writeOGR? I read the documentation of the function but I didn't figure out how to solve it. I tried with

writeOGR(shp, 'C:/foo', 'shp', 'ESRI Shapefile', layer_options="ENCODING=UTF-8", overwrite_layer=T)

but the result didn't change. I also tried with the updated rgdal package version (1.4-4).

4
  • 1
    are you sure that you're passing the encoding to writeOGR as intended? Usage writeOGR(obj, dsn, layer, driver, dataset_options = NULL, layer_options=NULL, verbose = FALSE, check_exists=NULL, overwrite_layer=FALSE, delete_dsn=FALSE, morphToESRI=NULL, encoding=NULL) see: rdocumentation.org/packages/rgdal/versions/1.4-4/topics/…
    – vagvaf
    Aug 7 '19 at 9:08
  • Can you use another output format? I know some people are restricted to use what is locally mandated, but if you can at least try something like a "Geopackage" and that works then you might have a good argument for change.
    – Spacedman
    Aug 7 '19 at 10:48
  • 1
    Possibly related: gis.stackexchange.com/questions/219092/…
    – Spacedman
    Aug 7 '19 at 10:49
  • Thank you @Spacedman, the solution described in the post you suggested works actually. It is an issue of QGIS rather than R then.
    – Quechua
    Aug 7 '19 at 11:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.