[R-sig-Geo] R crash with readOGR
caspar hallmann
caspar.hallmann at gmail.com
Fri Feb 12 16:40:32 CET 2010
Hi Roger,
Thank you for your very quick response.
This surely helps...
Perhaps however I should have emphasized: "without" any warning, the
thing being that I 'suspected' this is a memory issue.
What happened is that after submitting the code to R, and after
waiting a few minutes, R just shuts down. No warnings, no errors,
nothing.
And this keeps coming up after clearing memory (other data) or
restarting R altogether.
What I want to do is retrieve a range of shapefiles, possibly
differing in their CRS's, homogenizing the reference system,
overlaying and finally creating a 'covariate' dataset for further
geostatistical analysis. Since this will eventually be called in a
batch mode for many spatial response variables, with each response
having differing set of covariates (and thus layers and projections),
I need to get this streamlined.
Anyway, the function 'OGRSpatialRef' worked fine, and in conjunction
with read.dbf from library 'foreign' (to get the data) I'm pretty
much sorted. So thanks again!
all the best,
Caspar
On Fri, Feb 12, 2010 at 3:47 PM, Roger Bivand <Roger.Bivand at nhh.no> wrote:
> 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