[GRASS-stats] Re: [R-sig-Geo] Fail to load a vector layer using spgrass6

Pierre Roudier pierre.roudier at gmail.com
Wed Dec 15 16:00:49 EST 2010


Thanks for your answer Roger - many  interesting points for a GRASS
newbie like I am,

> I would suggest that you try to install the GRASS plugin for GDAL/OGR, and
> try to use that, since an intermediate file solution with the standard
> driver seems undesirable.

I actually got the GRASS plugin for OGR - I just realized ogrDrivers()
displays the writing capabilities. As it is read-only, it shows FALSE.

As a result, foo <- readVECT6('ph_cl', plugin=F) works:

> foo <- readVECT6('ph_cl', plugin=F)
Exporting 355021 areas (may take some time)...
 100%
118174 features found without category were skipped
v.out.ogr complete. 236847 features written to <ph_cl> (ESRI_Shapefile).
OGR data source with driver: ESRI Shapefile
Source: "/home/roudierp/Documents/GRASSDATA/NZTM2000/nitrif_inhib/.tmp/A208_RoudierP",
layer: "ph_cl"
with 236847 features and 14 fields
Feature type: wkbPolygon with 2 dimensions

Sorry about that - my bad :(

> I'm also very unsure about what you want to do with the data in R.
> Visualising will be painfully slow, and if you need to do analysis on the
> attribute data alone, you may as well transfer just that, not the
> geometries.
>

This is a very good point. I do not want to plot that data in R (I'm
not sure anybody would want to do that!), just some statistics on the
attributes. So, I guess loading the full geometry is a waste of time
and resources.

Is there a way for spgrass6 to read the attribute table of a layer as
a data.frame, modify it in R and then write it back in GRASS?

> Have you considered using a database back-end?
>

Another very good point. I guess that would speed up things.
Unfortunately, I have no experience whatsoever in DB. I'd be glad to
learn though!  Dylan's blog has a nice entry about that [1].

I think the readVECT6() worked out because I got 7Gb RAM on my
workstation. I wouldn't try the same thing on my laptop. BTW, I'm
lacking memory when I'm trying to write my result:
> writeVECT6(foo, 'deleteme')
Error in system(syscmd, intern = intern, ignore.stderr = ignore.stderr,  :
  cannot popen 'g.tempfile pid=999', probable reason 'Cannot allocate memory'

> Note that you have problems in ph_cl which require the c flag.
>

BTW, I got that problem on GRASS 6.4 but not on GRASS 7svn.

Thanks again - and sorry for the misunderstanding on the GRASS plugin,

Pierre

[1] http://casoilresource.lawr.ucdavis.edu/drupal/node/733

>>> If that doesn't work, please move thread only to grass-stats, and try
>>> using
>>> v.out.ogr to export the vector to the GRASS mapset temporary directory
>>> manually - use g.tempfile to find out what the path to that directory is.
>>> If
>>> v.out.ogr appears to complete without problems, do check the temporary
>>> directory to be sure.
>>>
>>
>> The output of g.tempfile is:
>>
>>
>> /home/roudierp/Documents/GRASSDATA/NZTM2000/nitrif_inhib/.tmp/A208_RoudierP/18058.0
>>
>> When using that tempfile for export as Shapefile it fails:
>>
>> v.out.ogr in=ph_cl
>>
>> dsn='/home/roudierp/Documents/GRASSDATA/NZTM2000/nitrif_inhib/.tmp/A208_RoudierP/18058.0'
>> format=ESRI_Shapefile
>> WARNING: The map contains islands. To preserve them in the output map, use
>>        the -c flag
>> ERROR 1:
>> /home/roudierp/Documents/GRASSDATA/NZTM2000/nitrif_inhib/.tmp/A208_RoudierP/18058.0
>> is not a directory.
>>
>> ERROR: Unable to open OGR data source
>>
>>  '/home/roudierp/Documents/GRASSDATA/NZTM2000/nitrif_inhib/.tmp/A208_RoudierP/18058.0'
>>
>> However, if I specify the tmp folder that works:
>> v.out.ogr in=ph_cl
>>
>> dsn='/home/roudierp/Documents/GRASSDATA/NZTM2000/nitrif_inhib/.tmp/A208_RoudierP/'
>> format=ESRI_Shapefile
>>
>> BUT - and that's where it gets tricky, if I want to use the GML
>> driver, this is the opposite situation:
>>
>> v.out.ogr in=ph_cl
>>
>> dsn='/home/roudierp/Documents/GRASSDATA/NZTM2000/nitrif_inhib/.tmp/A208_RoudierP/'
>> format=GML
>> ERROR 4: Failed to create GML file
>>
>> /home/roudierp/Documents/GRASSDATA/NZTM2000/nitrif_inhib/.tmp/A208_RoudierP/.
>> ERROR: Unable to open OGR data source
>>
>>  '/home/roudierp/Documents/GRASSDATA/NZTM2000/nitrif_inhib/.tmp/A208_RoudierP/'
>>
>> While this works:
>>
>> v.out.ogr in=ph_cl
>>
>> dsn='/home/roudierp/Documents/GRASSDATA/NZTM2000/nitrif_inhib/.tmp/A208_RoudierP/18628.0'
>> format=GML
>> Exporting 355021 areas (may take some time)...
>>
>> Any idea?
>>
>> Pierre
>>
>>> Roger
>>>
>>>>
>>>>> And GDAL 1.7.1 is not the current
>>>>> version, which is 1.7.3. Did you install GDAL and/or GRASS from source,
>>>>> or
>>>>> from binaries (in my experience, installing from source ensures more
>>>>> consistency, and the GDAL/OGR GRASS plugins are often the source of
>>>>> problems
>>>>> because of version mismatch).
>>>>
>>>> I installed both GRASS 6.4 and GDAL/OGR from binaries, yes.
>>>>
>>>>> PS. The best list is probably:
>>>>>
>>>>> http://grass.osgeo.org/statsgrass/index.php
>>>>
>>>> OK. I am sending that message to that list, and keep R-sig-geo for
>>>> consistency. Sorry for cross-posting.
>>>>
>>>> Thanks again,
>>>>
>>>> Pierre
>>>>
>>>>>
>>>>> Roger
>>>>>
>>>>>
>>>>> as it is more specific, and also seen by GRASS developers.
>>>>>
>>>>>>
>>>>>> I tried to play with the different options but I did not succeed>
>>>>>> Here's more info about my data and platform:
>>>>>>
>>>>>> Here is the output of v.info for the data I want to load:
>>>>>> GRASS 7.0.svn (NZTM2000):~ > v.info ph_cl
>>>>>>
>>>>>>
>>>>>>
>>>>>> +----------------------------------------------------------------------------+
>>>>>> | Name:            ph_cl
>>>>>>   |
>>>>>> | Mapset:          nitrif_inhib
>>>>>>    |
>>>>>> | Location:        NZTM2000
>>>>>>    |
>>>>>> | Database:        /home/roudierp/Documents/GRASSDATA
>>>>>>    |
>>>>>> | Title:
>>>>>>   |
>>>>>> | Map scale:       1:1
>>>>>>   |
>>>>>> | Map format:      native
>>>>>>    |
>>>>>> | Name of creator: roudierp
>>>>>>    |
>>>>>> | Organization:
>>>>>>    |
>>>>>> | Source date:     Mon Dec 13 11:30:11 2010
>>>>>>    |
>>>>>>
>>>>>>
>>>>>>
>>>>>> |----------------------------------------------------------------------------|
>>>>>> |   Type of map: vector (level: 2)
>>>>>>   |
>>>>>> |
>>>>>>    |
>>>>>> |   Number of points:       0               Number of centroids:
>>>>>>  236847
>>>>>>   |
>>>>>> |   Number of lines:        0               Number of boundaries:
>>>>>> 892041
>>>>>>   |
>>>>>> |   Number of areas:        355021          Number of islands:
>>>>>>  79124
>>>>>>    |
>>>>>> |
>>>>>>    |
>>>>>> |   Map is 3D:              No
>>>>>>   |
>>>>>> |   Number of dblinks:      1
>>>>>>    |
>>>>>> |
>>>>>>    |
>>>>>> |   Projection: Transverse Mercator
>>>>>>    |
>>>>>> |
>>>>>>    |
>>>>>> |               N:  6190887.80270169    S:  4823266.04395524
>>>>>>   |
>>>>>> |               E:  2091804.65744429    W:   1170289.3071784
>>>>>>   |
>>>>>> |
>>>>>>    |
>>>>>> |   Digitization threshold: 0
>>>>>>    |
>>>>>> |   Comment:
>>>>>>   |
>>>>>> |
>>>>>>    |
>>>>>>
>>>>>>
>>>>>>
>>>>>> +----------------------------------------------------------------------------+
>>>>>>
>>>>>> And finally some metadata about the software packages I used:
>>>>>>
>>>>>> here's the sessionInfo():
>>>>>>
>>>>>>> sessionInfo()
>>>>>>
>>>>>> R version 2.12.0 (2010-10-15)
>>>>>> Platform: x86_64-unknown-linux-gnu (64-bit)
>>>>>>
>>>>>> locale:
>>>>>> [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C
>>>>>> [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8
>>>>>> [5] LC_MONETARY=C              LC_MESSAGES=en_GB.UTF-8
>>>>>> [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C
>>>>>> [9] LC_ADDRESS=C               LC_TELEPHONE=C
>>>>>> [11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C
>>>>>>
>>>>>> attached base packages:
>>>>>> [1] stats     graphics  grDevices utils     datasets  methods   base
>>>>>>
>>>>>> other attached packages:
>>>>>> [1] spgrass6_0.6-21 XML_3.2-0       rgdal_0.6-31    sp_0.9-74
>>>>>>
>>>>>> loaded via a namespace (and not attached):
>>>>>> [1] grid_2.12.0     lattice_0.19-13
>>>>>>
>>>>>>> library(spgrass6)
>>>>>>
>>>>>> Loading required package: sp
>>>>>> Loading required package: rgdal
>>>>>> Geospatial Data Abstraction Library extensions to R successfully
>>>>>> loaded
>>>>>> Loaded GDAL runtime: GDAL 1.7.1, released 2010/02/08
>>>>>> Path to GDAL shared files: /usr/share/gdal
>>>>>> Loaded PROJ.4 runtime: Rel. 4.7.1, 23 September 2009
>>>>>> Path to PROJ.4 shared files: /usr/share/proj/
>>>>>> Loading required package: XML
>>>>>> GRASS GIS interface loaded with GRASS version: 7.0.svn
>>>>>> and location: NZTM2000
>>>>>>
>>>>>> I got the last CRAN version of sp.
>>>>>>
>>>>>> This runs on a linux machine:
>>>>>> GRASS 7.0.svn (NZTM2000):~ > uname -a
>>>>>> Linux A208_RoudierP 2.6.34.7-0.5-xen #1 SMP 2010-10-25 08:40:12 +0200
>>>>>> x86_64 x86_64 x86_64 GNU/Linux
>>>>>>
>>>>>>
>>>>>> Cheers,
>>>>>>
>>>>>> Pierre
>>>>>>
>>>>>> _______________________________________________
>>>>>> R-sig-Geo mailing list
>>>>>> R-sig-Geo at r-project.org
>>>>>> 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
>>> 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
> 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 grass-stats mailing list