numeric fields imported as factors by readOGR()

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

numeric fields imported as factors by readOGR()

alobo
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
--
Dr. Agustin Lobo
Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
LLuis Sole Sabaris s/n
08028 Barcelona
Spain
Tel. 34 934095410
Fax. 34 934110012
email: Agustin.Lobo at ija.csic.es
http://www.ija.csic.es/gt/obster



Reply | Threaded
Open this post in threaded view
|

numeric fields imported as factors by readOGR()

James Nylen
An embedded and charset-unspecified text was scrubbed...
Name: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20081205/ab611ae8/attachment.pl>

Reply | Threaded
Open this post in threaded view
|

numeric fields imported as factors by readOGR()

Roger Bivand
Administrator
On Fri, 5 Dec 2008, James Nylen wrote:

> This happens to me as well.  I just create a new column in the shapefile
> object's data, like:
>
> shp$AreaNum = as.numeric(as.vector(shp$AREA))
>
> If all you want to know is "why is it coded this way" then I have no idea,
> sorry.

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

>
> -James
>
> On Fri, Dec 5, 2008 at 10:29 AM, Agustin Lobo <aloboaleu at gmail.com> wrote:
>
>> 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
>> --
>> Dr. Agustin Lobo
>> Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
>> LLuis Sole Sabaris s/n
>> 08028 Barcelona
>> Spain
>> Tel. 34 934095410
>> Fax. 34 934110012
>> email: Agustin.Lobo at ija.csic.es
>> http://www.ija.csic.es/gt/obster
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at stat.math.ethz.ch
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway
Reply | Threaded
Open this post in threaded view
|

numeric fields imported as factors by readOGR()

Agustin Lobo-2
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:

> On Fri, 5 Dec 2008, James Nylen wrote:
>
>> This happens to me as well.  I just create a new column in the shapefile
>> object's data, like:
>>
>> shp$AreaNum = as.numeric(as.vector(shp$AREA))
>>
>> If all you want to know is "why is it coded this way" then I have no
>> idea,
>> sorry.
>
> 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
>
>>
>> -James
>>
>> On Fri, Dec 5, 2008 at 10:29 AM, Agustin Lobo <aloboaleu at gmail.com>
>> wrote:
>>
>>> 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
>>> --
>>> Dr. Agustin Lobo
>>> Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
>>> LLuis Sole Sabaris s/n
>>> 08028 Barcelona
>>> Spain
>>> Tel. 34 934095410
>>> Fax. 34 934110012
>>> email: Agustin.Lobo at ija.csic.es
>>> http://www.ija.csic.es/gt/obster
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo at stat.math.ethz.ch
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>
>>     [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at stat.math.ethz.ch
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>

--
Dr. Agustin Lobo
Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
LLuis Sole Sabaris s/n
08028 Barcelona
Spain
Tel. 34 934095410
Fax. 34 934110012
email: Agustin.Lobo at ija.csic.es
http://www.ija.csic.es/gt/obster