[R-sig-Geo] Scale Bar

Roger Bivand Roger.Bivand at nhh.no
Fri May 2 19:49:07 CEST 2008


On Fri, 2 May 2008, PUJAN RAJ REGMI wrote:

>
>
> Dear list,
> Thanks to Mr. Roger, I have now able to plot my data using image and sp 
> packages. Everything now seems ok for one type of data set where X and Y 
> coordinates are regularly spaced with tolerance less than 0.000002. Now 
> I tried to plot with another data set then soon I realize that X 
> coordinates have tolerance about 0.02. This thing I realize when I get 
> the error message as follows: ?gridded(A)<- TRUE suggested tolerance 
> minimum: 0.00212314227724164Error in points2grid(points, tolerance) : 
> dimension 1 : coordinate intervals are not constant? Then I tried to use 
> points2grid to overcome this problem but it did not work.

Do you know where the irregular values came from - type of file written by 
what software? Are they just rounding at some stage - I feel that it would 
be helpful to rule out real causes before correcting something that might 
be an actual mistake, if you see what I mean.

>
> One more question my data has a projection system UTM (European1950) ZONE31.
> How can I incorporate this information while converting spatial data?

proj4string(A) <- CRS("+proj=utm +zone=31 +ellps=intl")

but because ED50 is not well defined, there is no +towgs84= value in the 
EPSG database in the rgdal package. If you need to datum-transform spatial 
data (not the grid, obviously), you'll need the +towgs84 values for your 
location.

Roger

> Thanking you
> Pujan
>
>> Date: Fri, 2 May 2008 11:29:37 +0200> From: Roger.Bivand at nhh.no> To: regmi_pujan at hotmail.com> CC: r-sig-geo at stat.math.ethz.ch> Subject: Re: [R-sig-Geo] Scale Bar> > On Thu, 1 May 2008, PUJAN RAJ REGMI wrote:> > > Dear,> > > I followed the instruction given by Roger. But i got the following error > > message; coordinates(A) <- c("x", "y")> gridded(A) <- TRUE> > > greenchannel<-matrix(A[,3],nrow=155,ncol=191,byrow=TRUE)Error in > > as.vector(x, mode) : cannot coerce to > > vectorredchannel<-matrix(A[,4],nrow=155,ncol=191,byrow=TRUE)Error in > > as.vector(x, mode) : cannot coerce to vector> > > nearinfraredchannel<-matrix(A[,5],nrow=155,ncol=191,byrow=TRUE)Error in > > `[.data.frame`(x at data, i, j, ..., drop = FALSE) : undefined columns > > selected> > > midinfraredchannel<-matrix(A[,6],nrow=155,ncol=191,byrow=TRUE)Error in > > `[.data.frame`(x at data, i, j, ..., drop = FALSE) : undefined columns > > selectedThe image plot was black background with x and y axis values.> > You are not reading what is being sent to you carefully enough, but at > least this is a fresh thread, so some progress. Above, you have mixed up > my answer with your own attempt to use rimage classes and functions. If > you have spatial data, use spatial classes and functions, which permit > integration with other spatial data.> > Using the data you sent me offline (but *.rar compressed, please use gzip > or zip, rar is not portable), I have:> > > A <- read.table("test.txt", skip=8, header=FALSE)> names(A) <- c("x", "y", "greenchannel", "redchannel",> "nearinfraredchannel", "midinfraredchannel")> coordinates(A) <- c("x", "y")> gridded(A) <- TRUE> > I note that you have not given the projection of your data (UTM?), so > registering this data with other data (stream channel patterns?) is not > made any easier.> > A$red <- as.double(A$nearinfraredchannel)> A$green <- as.double(A$redchannel)> A$blue <- as.double(A$greenchannel)> summary(A)> > The values appear to be in the 0-255 range, but do not go much beyond > halfway - do they need stretching? Muliplying the values by 1.79 -> 1/(max(c(A$red, A$green, A$blue))/255) rounded down a touch - gave a more > pleasing image, but I don't know the origins of your data.> > image(A, red="red", green="green", blue="blue", axes=TRUE)> > which shows the majority of your study area as 0 coded black, and the > remainder is not very differentiated. It ought to be possible to code > these 0 values as NA, but currently the underlying method in sp does not > handle NAs gracefully for rgb input - this will be improved in the next > release. So, we recode 0 as 255 to get white:> > A$red <- ifelse(A$red < 1, 255, A$red)> A$green <- ifelse(A$green < 1, 255, A$green)> A$blue <- ifelse(A$blue < 1, 255, A$blue)> image(A, red="red", green="green", blue="blue", axes=TRUE)> > So now to your scale bar:> > SpatialPolygonsRescale(layout.scale.bar(), offset = c(566500, 5698000),> scale = 500, fill=c("transparent","black"), plot.grid=FALSE)> text(566500, 5698075, "0", cex=0.7)> text(567000, 5698075, "500 m", cex=0.7)> > You can complete the north arrow in the same way using examples on the > help page for spplot, if you really want one.> > Finally, as a geographer, I would point out that the scale bar and north > arrow are not needed when the axes show the scale and the direction of > north. Anyone who tells you that they have to be there (your supervisor?), > should read up on analytical graphics - extra details distract attention > from what the data are saying. Probably using grid() is less intrusive, > and gives good placing control across the whole graphic. When was the last > time anyone actually used a map scale bar to read off distances from a > map?> > Roger> > > > Any help?> > Thanking you> > Pujan> > _________________________________________________________________> > Back to work after baby?how do you know when you?re ready?> >> > 5797498&ocid=T067MSN40A0701A> > [[alternative HTML version deleted]]> >> >> > -- > 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
> _________________________________________________________________
> Get Free (PRODUCT) RED?  Emoticons, Winks and Display Pics
> http://joinred.spaces.live.com?ocid=TXT_HMTG_prodredemoticons_052008

-- 
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 R-sig-Geo mailing list