I am currently working with MapInfo files in the .tab
format. I am using R (3.1.0 for Windows) to read and write files in this format, however, I am encountering an issue with writeOGR()
from the rgdal
package. When I write a MapInfo file in the .tab
format, all the string fields are being assigned a width of 254 characters. This is very problematic for larger datasets with numerous string fields, as it dramatically increases the size of the output .dat
file.
Below is an example:
require(rgdal)
shape <- readOGR(dsn = directory, layer = "Up")
writeOGR(obj = shape, dsn = directory, layer = "Up2", driver = "MapInfo File")
Here's an excerpt from the original Up.tab
file:
!table
!version 300
!charset WindowsLatin1
Definition Table
Type NATIVE Charset "WindowsLatin1"
Fields 52
ID Integer Index 1 ;
unid_planejamento Char (4) ;
codigo2 Char (4) ;
descricao Char (100) ;
And one from my modified Up2.tab
file:
!table
!version 300
!charset Neutral
Definition Table
Type NATIVE Charset "Neutral"
Fields 52
ID Integer ;
unid_planejamento Char (254) ;
codigo2 Char (254) ;
descricao Char (254) ;
Note that all the string fields have now been assigned a width of 254 characters. I should also note that the .dat
file has gone from 43KB to 93KB.
I understand there are some creation issues when writing MapInfo files, however, it is not clear to me whether or not this can be resolved by somehow controlling the string field width.
I have searched for ways to do so using dataset_options
and layer_options
, but have not been successful.
Is there a way of controlling the string field width using writeOGR()
? And if not, is there a way of using R to write a new .dat
file (from my understanding, this is a dBase III DBF file) with the appropriate string widths?
No comments:
Post a Comment