[R-sig-Geo] R crash with readOGR

Roger Bivand Roger.Bivand at nhh.no
Fri Feb 12 15:47:40 CET 2010


On Fri, 12 Feb 2010, caspar hallmann wrote:

> Dear All,
>
> Perhaps one can help me with the obvious, however I have been trying
> to import a shapefile using function readOGR as in:
> myshp<-readOGR("mydirectorypath", "shapefilename"), and without any
> warning (e.g. can't allocate memory size or something trivial) R
> crashes en shuts down. The shapefile itself does not seem too large
> though ( 42mb the .shp alone).

OK. You are on Windows, where memory management is not as capable as on 
Unix-based systems. If R say that it cannot allocate memory under Windows, 
it has not "crashed", only responded to the inadequacy of the system. If 
you read the R for Windows FAQ, you'll see some tricks for improving 
memory use. A 42MB shapefile is very large, you have not said what you 
need to use it for.

The R lists posting guide does say when you can term anything a crash, 
this is not one of those cases.

There is no separate function for reading a *.prj file. The so-called WKT 
spatial reference in the *.prj is read by the OGR driver, and converted to 
PROJ.4.

"OGRSpatialRef" <- function(dsn, layer) {
     .Call("ogrP4S", as.character(dsn), as.character(layer),
         PACKAGE="rgdal")
}

is a function that will return that representation without trying to read 
the features, I'll add it and one for GDAL rasters to the next release - 
the GDAL information is already in the object returned by GDALinfo(), but 
noy yet in that returned by ogrInfo().

Hope this helps,

Roger

> I wonder if anyone has encountered the same problem, or beter, the solution.
> For now, I have resorted to importing the .dbf of the shapefile (works
> fine), then converting it to some preferred spatial format. However,
> since now I am required to manually set the CRS this pretty much
> prevents me from applying batch analysis on a range of shapesfile
> differing in their CRS's. Note that the .prj are present, and would
> like to take advantage of readOGR's capability of recognizing the CRS
> of each shapefile.
>
> Thanks in advance
>
> Caspar
>
> PS: BTW: Is there a function like ''readprj()'' around ?
> PS2: sessionInfo:
> R version 2.10.1 (2009-12-14)
> i386-pc-mingw32
>
> locale:
> [1] LC_COLLATE=Dutch_Netherlands.1252  LC_CTYPE=Dutch_Netherlands.1252
>   LC_MONETARY=Dutch_Netherlands.1252 LC_NUMERIC=C
> [5] LC_TIME=Dutch_Netherlands.1252
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] RSAGA_0.9-6     rgdal_0.6-24    maptools_0.7-29 lattice_0.18-3
> sp_0.9-57       foreign_0.8-39
>
> loaded via a namespace (and not attached):
> [1] grid_2.10.1  proj4_1.0-4  tools_2.10.1
>>
>
> _______________________________________________
> 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



More information about the R-sig-Geo mailing list