[STATSGRASS] CRS(): PROJ4 argument-value pairs must begin with +

Roger Bivand Roger.Bivand at nhh.no
Wed Sep 28 02:50:11 EDT 2005


On Wed, 28 Sep 2005, rsadler at cyllene.uwa.edu.au wrote:

> Hi,
> 
> I have just installed grass6.0 on a new machine, and come up with a new
> error (for me!).
> 
> 
>  test5x<-readCELL6sp("test.product5")
> Error in CRS(system("g.proj -j -f", intern = TRUE)) :
>         PROJ4 argument-value pairs must begin with +: XY location
> (unprojected)

Thanks, the current code assumes that g.proj -j -f always returns a valid 
PROJ.4 string, which isn't the case for XY locations. The next release 
will check more carefully, and will set the coordinate reference system to 
NA if it doesn't look like a valid string.

> 
> It looks like the CRS function in readCELL6sp is not liking the projection
> information (or lack thereof), hence can't provide a projection when
> reading in ascii.grid format.  When I exclude P4<-CRS(...) and just use
> CRS(as.char(NA)) my later functions that process the coverage bug out.
> 

Since I can't see where the "later functions that process the coverage" 
might hit trouble, I'm attaching a file with the modified code to source() 
- could you then report details of what happens next (you will also need 
to install the maptools package and upgrade sp to >= 0.8)?

Roger

> What do I do from here?
> 
> The raster coverage has worked on a previous machine using readCELL6sp.
> 
> The coverage does have nodata values amongst other integer category values
> 
> Regards
> rohan sadler
> 
> 
> system("g.proj -j")
> XY location (unprojected)
> 
> r.info map=test.product5
>  +----------------------------------------------------------------------------+
>  | Layer:    test.product5                  Date: Wed Sep 28 11:48:57 2005
>    |
>  | Mapset:   rsadler                        Login of Creator: rsadler     
>    |
>  | Location: bananabrains                                                 
>    |
>  | DataBase: /home/rohan/simulations                                      
>    |
>  | Title:     ( test.product5 )                                           
>    |
>  |----------------------------------------------------------------------------|
>  |                                                                        
>    |
>  |   Type of Map:  cell                Number of Categories: 393          
>    |
>  |   Data Type:    CELL                                                   
>    |
>  |   Rows:         250                                                    
>    |
>  |   Columns:      250                                                    
>    |
>  |   Total Cells:  62500                                                  
>    |
>  |        Projection: x,y (zone 0)                                        
>    |
>  |            N:          1    S:          0   Res: 0.004                 
>    |
>  |            E:          1    W:          0   Res: 0.004                 
>    |
>  |   Range of data:    min =  1 max = 393                                 
>    |
>  |                                                                        
>    |
>  |   Data Source:                                                         
>    |
>  |                                                                        
>    |
>  |                                                                        
>    |
>  |                                                                        
>    |
>  |   Data Description:                                                    
>    |
>  |    generated by r.mapcalc                                              
>    |
>  |                                                                        
>    |
>  |   Comments:                                                            
>    |
>  |    test51 * test52                                                     
>    |
>  |                                                                        
>    |
>  +----------------------------------------------------------------------------+
> 
> Regards
> Rohan
> 
> _______________________________________________
> statsgrass mailing list
> statsgrass at grass.itc.it
> http://grass.itc.it/mailman/listinfo/statsgrass
> 

-- 
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

-------------- next part --------------
# Interpreted GRASS 6 interface functions
# Copyright (c) 2005 Roger S. Bivand
#



readCELL6sp <- function(vname, cat=FALSE) {
	tmpfl <- tempfile()
	system(paste("r.out.arc input=", vname, " output=", tmpfl, sep=""))
#	library(sp)
	library(maptools)
# too strict assumption on g.proj Rohan Sadler 20050928
	projstr <- system("g.proj -j -f", intern=TRUE)
	if (length(grep("XY location (unprojected)", projstr)) > 1)
		projstr <- as.character(NA)
	if (length(grep("latlong", projstr)) > 1)
		projstr <- sub("latlong", "longlat", projstr)
    	if (is.na(projargs)) uprojargs <- projstr
    	else uprojargs <- paste(unique(unlist(strsplit(projargs, " "))), 
		collapse=" ")
    	if (length(grep("= ", uprojargs)) != 0) {
		warning(paste("No spaces permitted in PROJ4",
			"argument-value pairs:", uprojargs))
		uprojargs <- as.character(NA)
	}
    	if (length(grep(" [:alnum:]", uprojargs)) != 0) {
		warning(paste("PROJ4 argument-value pairs",
			"must begin with +:", uprojargs))
		uprojargs <- as.character(NA)
	}
	p4 <- CRS(uprojargs)
	res <- readAsciiGrid(tmpfl, colname=vname, proj4string=p4)
	if (cat) {
		cats <- strsplit(system(paste("r.stats -l -q", vname), 
			intern=TRUE), " ")
		catnos <- sapply(cats, function(x) x[1])
		catlabs <- sapply(cats, function(x) paste(x[-1], collapse=" "))
		if (any(!is.na(match(catnos, "*")))) {
			isNA <- which(catnos == "*")
			catnos <- catnos[-isNA]
			catlabs <- catlabs[-isNA]
		}
		res at data[[1]] <- factor(res at data[[1]], levels=catnos, labels=catlabs)
	} else {
		res at data[[1]] <- as.integer(res at data[[1]])
	}
	res
}

readFLOAT6sp <- function(vname) {
	tmpfl <- tempfile()
	system(paste("r.out.arc input=", vname, " output=", tmpfl, sep=""))
#	library(sp)
	library(maptools)
# too strict assumption on g.proj Rohan Sadler 20050928
	projstr <- system("g.proj -j -f", intern=TRUE)
	if (length(grep("XY location (unprojected)", projstr)) > 1)
		projstr <- as.character(NA)
	if (length(grep("latlong", projstr)) > 1)
		projstr <- sub("latlong", "longlat", projstr)
    	if (is.na(projargs)) uprojargs <- projstr
    	else uprojargs <- paste(unique(unlist(strsplit(projargs, " "))), 
		collapse=" ")
    	if (length(grep("= ", uprojargs)) != 0) {
		warning(paste("No spaces permitted in PROJ4",
			"argument-value pairs:", uprojargs))
		uprojargs <- as.character(NA)
	}
    	if (length(grep(" [:alnum:]", uprojargs)) != 0) {
		warning(paste("PROJ4 argument-value pairs",
			"must begin with +:", uprojargs))
		uprojargs <- as.character(NA)
	}
	p4 <- CRS(uprojargs)
	res <- readAsciiGrid(tmpfl, colname=vname, proj4string=p4)
	res
}




More information about the grass-stats mailing list