[R-sig-Geo] Problem connecting to GRASS via spgrass6 and plr - SOLVED

Mark Wynter mark at dimensionaledge.com
Tue Jul 17 07:00:53 CEST 2012


Thanks to Joe Conway and Greg Booma on the plr mailing list.  They saw the problem as a permissions issue.

The solution was to create a new GRASS mapset under the "postgres" user, due to the way mapset permissions work in GRASS.  I then changed initGRASS to the mapset="postgres" as per below. And presto!

For completeness, the following function now works when called from PostgreSQL.

CREATE OR REPLACE FUNCTION generate_viewshed() RETURNS text as 
$$
library(spgrass6)
initGRASS(gisBase = "/usr/local/grass-6.4.3svn/", home = tempdir(), gisDbase = "/usr/local/share/grassdata/", location = "aust_dem_1sec_wgs84", mapset = "postgres", SG="aust_dem_1sec", override = TRUE)
execGRASS("g.region", parameters = list(n="-34.9759927736275", s="-34.9985728860995", e="138.641896696527", w="138.619947232807", align="aust_dem_1sec"))
execGRASS("r.viewshed", parameters = list(input = "aust_dem_1sec", output = "viewshed_raster", coordinate = "138.630922,-34.987283", obs_elev = 25, max_dist = 1000), flags = c("b", "overwrite")) 
execGRASS("r.to.vect", parameters = list(input = "viewshed_raster", output = "viewshed_vector", feature = "area"), flags = c("overwrite")) 
execGRASS("v.out.ogr", parameters = list(input = "viewshed_vector", dsn = "PG:host=localhost dbname=test user=postgres password=password", olayer = "viewshed_vector", format = "PostgreSQL", type = "area"), flags = c("c")) 
$$
LANGUAGE 'plr';

- Mark


> 
> Message: 12
> Date: Mon, 16 Jul 2012 15:40:09 +1000
> From: Mark Wynter <mark at dimensionaledge.com>
> To: r-sig-geo at r-project.org
> Subject: [R-sig-Geo] Problem connecting to GRASS via spgrass6 and plr
> Message-ID: <887F9806-BBEB-46BE-A160-33EBC0CBB627 at dimensionaledge.com>
> Content-Type: text/plain
> 
> I'm trying to access GRASS functionality via spgrass6 and a plr script.
> 
> The following works (when executed directly from within R)...
> 
> library(spgrass6)
> initGRASS(gisBase = "/usr/local/grass-6.4.3svn/", home = tempdir(), gisDbase = "/usr/local/share/grassdata/", location = "aust_dem_1sec_wgs84", mapset = "ubuntu", SG="aust_dem_1sec", override = TRUE)
> execGRASS("g.region", parameters = list(n="-34.9759927736275", s="-34.9985728860995", e="138.641896696527", w="138.619947232807", align="aust_dem_1sec"))
> execGRASS("r.viewshed", parameters = list(input = "aust_dem_1sec", output = "viewshed_raster", coordinate = "138.630922,-34.987283", obs_elev = 25, max_dist = 1000), flags = c("b", "overwrite")) 
> execGRASS("r.to.vect", parameters = list(input = "viewshed_raster", output = "viewshed_vector", feature = "area"), flags = c("overwrite")) 
> execGRASS("v.out.ogr", parameters = list(input = "viewshed_vector", dsn = "PG:host=localhost dbname=test user=postgres password=password", olayer = "viewshed_vector", format = "PostgreSQL", type = "area"), flags = c("c")) 
> 
> But not so when called by a plr function...
> 
> CREATE OR REPLACE FUNCTION generate_viewshed() RETURNS text as $$
> library(spgrass6)
> initGRASS(gisBase = "/usr/local/grass-6.4.3svn/", home = tempdir(), gisDbase = "/usr/local/share/grassdata/", location = "aust_dem_1sec_wgs84", mapset = "ubuntu", SG="aust_dem_1sec", override = TRUE)
> execGRASS("g.region", parameters = list(n="-34.9759927736275", s="-34.9985728860995", e="138.641896696527", w="138.619947232807", align="aust_dem_1sec"))
> execGRASS("r.viewshed", parameters = list(input = "aust_dem_1sec", output = "viewshed_raster", coordinate = "138.630922,-34.987283", obs_elev = 25, max_dist = 1000), flags = c("b", "overwrite")) 
> execGRASS("r.to.vect", parameters = list(input = "viewshed_raster", output = "viewshed_vector", feature = "area"), flags = c("overwrite")) 
> execGRASS("v.out.ogr", parameters = list(input = "viewshed_vector", dsn = "PG:host=localhost dbname=test user=postgres password=password", olayer = "viewshed_vector", format = "PostgreSQL", type = "area"), flags = c("c")) 
> $$ LANGUAGE 'plr';
> 
> I get the following error.... which through a process of elimination the error occurs at the initGRASS() line...
> 
> ERROR:  R interpreter expression evaluation error
> DETAIL:  Error in parseGRASS(cmd) : g.region not parsed
> CONTEXT:  In PL/R function generate_viewshed
> 
> Is there a compatibility issue between plr and spgrass6, or is it due to something on my part?   Any suggestions?
> 
> BTW, I've also posted this on the plr mailing list.
> 
> Thanks
> 
> Mark
> 	[[alternative HTML version deleted]]
> 
> 
\


More information about the R-sig-Geo mailing list