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")
  • Have you tried leaving the ".tab" file extension off? You are specifying a driver so may not need an extension. – Jeffrey Evans Oct 11 '16 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 Oct 11 '16 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 – Christian Hoppe Oct 12 '16 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 Nov 5 '16 at 15:30
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, privacy policy and cookie policy

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