3

I have a problem using "writeOGR" with the R Package Rgdal. The strange thing is, that this worked just a few weeks ago, but when I tried to start the R script today, it didn't work.

The Error is: "Error in writeOGR(dat, dsn = "Zones.tab", layer = "Zones", driver = "MapInfo File") : Failed to create feature"

The MapInfo Files are stored, but they are empty (just the column Names are there).

I wrote this, so you guys can have a look. Same Error when I start the code:

library(rgdal)
setwd("G:/Löschen")

(dat <- data.frame(Number=c(1,2,3,4,5,6),
                    East=c(371008,371124,371346,371276,371051,371344),
                    North=c(5720763,5720567,5720761,5720493,5720506,5720490),
                    BW=c(320,350,300,380,275,390)))

coordinates(dat) <- ~East+North

proj4string(dat) <- "+proj=utm +zone=32 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"

writeOGR(dat, dsn = "Zones.tab", layer = "Zones", driver = "MapInfo File")
4
  • Have you tried leaving the ".tab" file extension off? You are specifying a driver so may not need an extension. Commented Oct 11, 2016 at 15:31
  • Yes, Zones.tab will be a directory. Use "." For current directory. Also fwiw there's are dsn creation options for FORMAT=MIF for that variant.
    – mdsumner
    Commented Oct 11, 2016 at 21:16
  • 1
    I trieed it without .tab extension and it doesn't work either. I also tried MIF Format - same Problem. When I use the MID Format there is no Error Masage, but I can`t use this Format. Exporting the Data as ESRI Shape works, but thats not what I Commented Oct 12, 2016 at 10:49
  • 1
    In writeOGR{rgdal} documentation, there is an inline comment which says #For GDAL >= 2, the TAB driver may need a BOUNDS layer option. It would suggest an option layer_options = "BOUNDS" (or something like this) but it seems this has not been implemented yet in rgdal. A possible workaround is; (1) Save your data as ESRI Shapefile by writeOGR(), then (2) library(gdalUtils) ogr2ogr() to convert it to Zones.tab... if it is ok to use other packages.
    – Kazuhito
    Commented Nov 5, 2016 at 15:30

1 Answer 1

2

MapInfo file export using writeOGR never worked for me even with clean ESRI source files exported by writeOGR.

There is a handy package called sf, which writes out MapInfo files. Unlike gdalUtils::ogr2ogr it does not rely on an external application, which is not possible to install on the shinyapps.io server, for example.

To save your example in MapInfo format, execute the following:

library(sf)
st_write(st_as_sf(dat), dsn = "Zones", layer = "Zones", driver = "MapInfo File")

One perhaps undesirable side effect is the creation of a sub-folder named after the last part of the dsn so you'll end up with a path like this:

G:\Löschen\Zones\Zones.TAB

I've checked the resulting files in MapInfo Professional 8 and everything looks correct:

enter image description here

enter image description here

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.