[R-sig-Geo] Error in converting SpatialPointsDataFrame object to ESRI shape file using writeOGR from rgdal package

Alex Mandel tech_dev at wildintellect.com
Tue Jun 17 09:40:39 CEST 2008


Roger Bivand wrote:
> On Mon, 16 Jun 2008, Debarchana Ghosh wrote:
> 
>> Hi,
>>
>> I am using R 2.7 on windows with 4GB ram.
>>
>> I am trying to convert the SpatialPointsDataFrame object (SDF) from the
>> "gwr" output ( spgwr package) to ESRI shapefile using the writeOGR 
>> function
>> from the rgdal package. The function is able to write the shape file with
>> correct geometry but showing errors when trying to view the attribute 
>> table.
>> The attribute table is empty. But the data slot of the
>> SpatialPointsDataFrame object has values for all the columns. Below I 
>> paste
>> my codes:
> 
> The issue seems to be that the underlying DBF format cannot handle field 
> names which are longer than 11 characters. I've looked at:
> 
> names(test500.gwr$SDF) <- make.names(names(test500.gwr$SDF))
> 
> and tried abbreviate() too, and toupper() without much luck. Maybe:
> 
> toupper(gsub("\\.", "_", make.names(substring(names(test500.gwr$SDF), 1,
>   7), unique=TRUE)))
> 
> or even less than 7 if need be?
> 
> What else apart from shapefiles can Arc read that writeOGR can write 
> that would let us get round using DBF?
> 
> Roger
> 
>

It's well known that DBF doesn't support more than 8 characters in field 
names and that Arc doesn't really support much else.

A few options,
1. Create a shp with OGR and put the attributes in something like a csv 
then do a join operation in ArcGIS
2. Create a geodatabase in ArcGIS (mdb format), write the attributes to 
a table via ODBC, import the separately created shp and join.
3. KML, problem again of course is that everything gets converted to shp 
  and hence truncated until you get it into a geodatabase.

Really they are all terrible solutions. In all of them it will have to 
enter shp format at some point which will require the altering of column 
names.

To truly skirt the issue would be to not use Arc at all and use 
something like QGIS,gvSIG or OpenJump which can all read OGR layers - 
GML, KML are a few of the easy ones.

Alex




More information about the R-sig-Geo mailing list