[R-sig-Geo] Wrong reading of data type in readOGR ?
Patrick Giraudoux
patrick.giraudoux at univ-fcomte.fr
Fri Nov 25 18:45:20 CET 2016
Le 25/11/2016 à 16:18, Roger Bivand a écrit :
> On Fri, 25 Nov 2016, Patrick Giraudoux wrote:
>
>> Dear Listers,
>>
>> I meet a problem with readOGR on an ESRI shapefile which was
>> correctly read in the past (practical training with students). Now
>> all integer variables are read as "factors" although they should be
>> read as integer. With the argument stringsAsFactors=FALSE, the
>> reading gives "characters", but not the expected integers.
>
> Please see:
>
> https://stat.ethz.ch/pipermail/r-sig-geo/2016-October/025038.html
>
> https://stat.ethz.ch/pipermail/r-sig-geo/2016-November/025104.html
>
> This is the result of the antiquated way DBF handle numbers, and
> changes made in GDAL2 to accommodate 64-bit integers, which most often
> are IDs, not numbers. Maybe try the GDAL1_integer64_policy= argument,
> or re-write the shapefiles with the offending integer written as a
> double, or stop using shapefiles.
>
> Roger
For info, a command line like this (with GDAL1_integer64=TRUE)
2539<-readOGR(".","Arvicola2539maj11au", GDAL1_integer64=TRUE)
...works perfect and meet the expectations. May be useful to keep in
mind for old shapefiles left on a shelter in the attic...
Before Roger's response, during the training course (may day, may day,
etc.), the other way round had been to import with no arguments and then
use a loop such:
for(i in 18:75) d2539 at data[,i]<-as.numeric(as.character(d2539 at data[,i]))
but it is (not recommandable) ruffian's way (:-)
More information about the R-sig-Geo
mailing list