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

rsadler at cyllene.uwa.edu.au rsadler at cyllene.uwa.edu.au
Thu Sep 29 03:54:22 EDT 2005


Your updated code works fine.

Now, its time for me to see to what is not working in the rest of my
code!!

Rohan

> On running readCELL6sp we have an error
>
> >system("r.mapcalc test.product5=test51*test52")
> >  test.junk<-readCELL6sp("test.product5")
>  Error in readCELL6sp("test.product5") : Object "projargs" not found
>
> This arises on line 12 & 13 of readCELL6sp (and readFLOAT6sp) where
> projargs is used but not previously defined.
>
> if (is.na(projargs)) uprojargs <- projstr
>     else uprojargs <- paste(unique(unlist(strsplit(projargs, " "))),
>                                     collapse=" ")

Sorry, I added some extra checks to prevent the creation of the CRS object
throwing an error, setting the projection string to NA instead, without
checking. The attached works for me on spearfish and on a vanilla XY
location (where the projection is set to NA).

Roger

>
> sp and maptools upgraded
>
> Rohan
>
>
> >> 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
>
>
>
> _______________________________________________
> 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



----- End forwarded message -----

-------------- 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", projstr)) > 0)
		projstr <- as.character(NA)
	if (length(grep("latlong", projstr)) > 0)
		projstr <- sub("latlong", "longlat", projstr)
    	if (is.na(projstr)) uprojargs <- projstr
    	else uprojargs <- paste(unique(unlist(strsplit(projstr, " "))), 
		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", projstr)) > 0)
		projstr <- as.character(NA)
	if (length(grep("latlong", projstr)) > 0)
		projstr <- sub("latlong", "longlat", projstr)
    	if (is.na(projstr)) uprojargs <- projstr
    	else uprojargs <- paste(unique(unlist(strsplit(projstr, " "))), 
		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