Skip to content

numeric fields imported as factors by readOGR()

4 messages · James Nylen, Roger Bivand, Agustin Lobo

#
I often get some numeric fields (i.e, AREA in this case) imported
as factors by readOGR() from shp files. WHy could it be?
I've reviewed the field in the dbf file and do not
see any non-numeric value.

Thanks
Agus
#
On Fri, 5 Dec 2008, James Nylen wrote:

            
You could look at ogrInfo() for the same dsn= and layer= before you 
import. In principle, if the driver reports "Integer", "Real", or 
"String", this should be respected, so I'd be interested in seeing a case.

Roger

  
    
#
Roland, James, Roger and Carson

ogrInfo() provides info consistent with the behaviour of readOGR()
and editing the dbf with OO as suggested by Roland reveals
that the field is labeled as "C,80" (which I do not understand
as values are areas written by fTools in QGIS, Carson, could this be
a bug?)
Substitution of "C,80" by "N,15,3" in the dbf file for that field with OO
does not work (all values imported as 0). I think that this is because
all values for that field in the dbf have a "'" which is what makes
the field to be character and which I had overlooked. I've tried 
replacing all "'" for that field in OO but, oddly, OO claims that
that no "'" are present.

Anyway, the problem is clearly in the dbf file and not in rgdal.

Also, the quick fix suggested by James works fine.

Thank you all.

Agus
Roger Bivand wrote: