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

Roger Bivand Roger.Bivand at nhh.no
Thu Dec 16 16:37:18 EST 2010


On Fri, 17 Dec 2010, Pierre Roudier wrote:

> Thanks Roger,
>
>> OK, so we know now that the use of intermediate files with the "ESRI
>> Shapefile" driver works, but the plugin does not work for you. We don't know
>> why your plugin doesn't work (and I'm not sure which versions of GRASS,
>> GDAL, or the plugin are involved).
>>
>
> The GRASS version is 7svn, however I had the same problem on the 6.4.
> I can't manage to check the plugin version, but it is here:
>
> roudierp at A208_RoudierP:~> ls /usr/lib/gdalplugins/
> gdal_GRASS.so  ogr_GRASS.so
> roudierp at A208_RoudierP:~> gdalinfo --formats | grep -i grass
>  GRASS (ro): GRASS Database Rasters (5.7+)
>
> My GDAL version is 1.7.1:
>
> roudierp at A208_RoudierP:~> gdalinfo --version
> GDAL 1.7.1, released 2010/02/08
>
> Form your post I understand I should remove my binaries and compile
> GDAL and the GRASS plugin from source.

If you compile yourself, you get more control, but more responsibility 
too. It depends on your specific needs and capabilities - if you are 
completely comfortable installing from source, then it makes sense, but if 
not, finding other "ways round" with the binaries you have may be sensible 
too.

Roger

>
>>> 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?
>>
>> res <- execGRASS("v.db.select", parameters=list(map="bugsites",
>>  layer="1"), intern=TRUE)
>> con <- textConnection(res)
>> df <- read.table(con, header=TRUE, sep="|")
>> close(con)
>> str(df)
>>
>> for reading. This may not scale well, in which case try:
>>
>> execGRASS("v.out.ogr", parameters=list(input="bugsites", layer="1",
>>  dsn=paste(td, "bugsites.csv", sep="/"), format="CSV"))
>> df <- read.csv(paste(td, "bugsites.csv", sep="/"))
>> str(df)
>>
>> Could others with more experience of updating vector attribute tables add
>> the return trip? I suspect that using a database back-end which both R and
>> GRASS can update is the cleanest solution, but is there a way of inputting
>> hundreds of thousands of values into a column of a vector attribute table?
>> Should one create a new table and join it?
>>
>
> Thanks, I will use that then,
>
> Pierre
>
>>>> 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
>>>>
>>>
>>
>> --
>> 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