[R-sig-Geo] problem with readOGR

Roger Bivand Roger.Bivand at nhh.no
Wed Feb 25 14:08:02 CET 2009


On Wed, 25 Feb 2009, "José M. Blanco Moreno" wrote:

> Dear list members,
> I have been trying to import a shapefile, but I am facing the following 
> problem:
>> readOGR('.','SOU-0')
> Error en ogrInfo(dsn = dsn, layer = layer, input_field_name_encoding = 
> input_field_name_encoding) :
> Multiple # dimensions: 2:1364727026
>> ogrInfo('.','SOU-0')
> Error en ogrInfo(".", "SOU-0") : Multiple # dimensions: 2:21374114
>
> The problem seems to be with:
>> ogrFIDs('.','SOU-0')
> [1]        0        1        2        3        4        5        6        7 
> 8        9
> [...snipped content...]
> [81]       80       81       82 21374112
>
> I don't know why, but an integer seems to be imported as if it were double 
> (or something like that!)
> If I open the dbf file and save it (with e.g. MS Excel) as a dbase IV file, 
> then it works. However, when I have to do this repeatedly it can be really 
> annoying. Is there any way to overcome it? It is a documented issue (if so, 
> excuse me)?

The issue is that the downloaded shapefile is (seriously) broken. There 
are 84 geometries (polygons), but only 83 rows in the DBF file. This 
might explain why reading it into a spreadsheet and saving helps. 
According to the ESRI specs, they should (of course) agree.

If the data provider can fix the shapefile, you'll be OK. If not, then I 
can modify readShapePoly() in maptools to accommodate this kind of 
breakage - over and above the legion it already handles, but would have to 
assume that the missing row is the final one, setting all values to NA. Of 
course, if the missing row is not the final one, all bets are off.

Roger

PS. two broken shapefiles in one day is enough, really.

>
> Thank you very much for any help that you can offer.
>
> José M.
>
> You can find the file here:
> http://www.maplibrary.org/stacks/Africa/South%20Africa/KwaZulu-Natal/SOU-0_admin_SHP.zip
>
> This is the information on the system:
>
>> sessionInfo()
> R version 2.8.1 (2008-12-22)
> i386-pc-mingw32
>
> locale:
> LC_COLLATE=Spanish_Spain.1252;LC_CTYPE=Spanish_Spain.1252;LC_MONETARY=Spanish_Spain.1252;LC_NUMERIC=C;LC_TIME=Spanish_Spain.1252
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base    > 
> library(rgdal)
> Loading required package: sp
> Geospatial Data Abstraction Library extensions to R successfully loaded
> Loaded GDAL runtime: GDAL 1.6.0, released 2008/12/04
> Path to GDAL shared files: C:/ARCHIV~1/R/R-28~1.1/library/rgdal/gdal
> Loaded PROJ.4 runtime: Rel. 4.6.1, 21 August 2008
> Path to PROJ.4 shared files: C:/ARCHIV~1/R/R-28~1.1/library/rgdal/proj
>> library(maptools)
> Loading required package: foreign
>> readOGR('.','SOU-0')
> Error en ogrInfo(dsn = dsn, layer = layer, input_field_name_encoding = 
> input_field_name_encoding) :
> Multiple # dimensions: 2:1364727026
>> ogrInfo('.','SOU-0')
> Error en ogrInfo(".", "SOU-0") : Multiple # dimensions: 2:21374114
>> ogrFIDs('.','SOU-0')
> [1]        0        1        2        3        4        5        6        7 
> 8        9
> [11]       10       11       12       13       14       15       16       17 
> 18       19
> [21]       20       21       22       23       24       25       26       27 
> 28       29
> [31]       30       31       32       33       34       35       36       37 
> 38       39
> [41]       40       41       42       43       44       45       46       47 
> 48       49
> [51]       50       51       52       53       54       55       56       57 
> 58       59
> [61]       60       61       62       63       64       65       66       67 
> 68       69
> [71]       70       71       72       73       74       75       76       77 
> 78       79
> [81]       80       81       82 21374112
>
>

-- 
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


More information about the R-sig-Geo mailing list