Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm currently using the following script to add some attribute data from a table to lots of individual shapefiles:

library(rgdal)
specieslist <- read.csv("SpeciesList1.txt", header=F)
attdata <- read.table("TestAtt.csv", sep = ",", header=T)
for (n in 1:dim(specieslist)[1]) 
{
speciesname <- specieslist[n,1]
shp <- readOGR("Mesoamerica_modified_polygons", speciesname)
shp$ENGL_NAME<-attdata[n,2]
writeOGR(shp, "PolygonsV2", speciesname, driver="ESRI Shapefile")
}

I get the following warning(s) at the end:

1: In writeOGR(shp, "PolygonsV2", speciesname, driver = "ESRI Shapefile") :
Field names abbreviated for ESRI Shapefile driver

When viewing the attribute table of the shapefiles after this process, the Field name has been shortened to 'ENGL_', but I want it to stay as 'ENGL_NAME'. Is there a way to turn this abbreviating off?

Any help much appreciated.

share|improve this question
    
Are any of the fieldnames in the shapefile > 10 characters? Looks like a bug in the R bindings to me. –  geographika Aug 2 '12 at 12:04
1  
Hi there, I just re-ran the script and now it isn't abbreviating. I'm not sure what's changed to cause this though... –  JPD Aug 2 '12 at 12:27

2 Answers 2

up vote 1 down vote accepted

You can't, it's a shapefile issue. See http://gdal.org/ogr/drv_shapefile.html under 'Creation Options'

share|improve this answer
    
so it is not an issue of writeOGR? Is it actually issue of the format? –  Tomas Dec 2 at 17:34
1  
Correct. dbf column name lengths are limited. Another format, for example sqlite/spatialite would not truncate the names (there are very large limits in sqlite, but many orders of magnitude above 10). –  kyle Dec 4 at 16:48
    
Well, there is a difference between normal abbreviation of column names when writing to dbf and what writeOGR is doing there! writeOGR is crippling even field names shorter than 10. My examples: My R-column name "ora_nachweis_id" becomes "or_nch_" while writeSpatilaPolygon does the normal abbreviation -> "ora_nachwe". Even my variable "LblColor" (8 characters !) becomes "LblColr". –  Bernd V. Dec 4 at 19:09

Your 'ENGL_NAME' shouldn't be abbreviated at all (less than 10 characters), but writeOGR has its own will, it seems.

Instead of

writeOGR(shp, "PolygonsV2", speciesname, driver="ESRI Shapefile")

you might try

currdir <- getwd() #store your current working directory
setwd(paste(currdir,"PolygonsV2",sep="/")) #switch to your desired folder

writeSpatialShape(shp, speciesname) # write shapefile

setwd(currdir) #switch back to parent folder

As writeSpatialShape seems not have a parameter for the destination, I found this workaround switching the working directory back and forth.

The other problem there is, that it does't produce a .prj-file, but thats a minor problem, compared to destroyed field names.

Waiting for the times when +*#-!(/ ESRI Shapefile format is finally dead and replaced by ... well?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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