[R-sig-Geo] Scale Bar
Roger Bivand
Roger.Bivand at nhh.no
Fri May 2 20:34:06 CEST 2008
On Fri, 2 May 2008, PUJAN RAJ REGMI wrote:
>
>
> Dear sir,
> My data has been acquired from ENVI 4.0 and it has the following information regarding pixel size and projection system:
> samples = 596lines = 440bands = 21
> pixel size: 4.710294*4.70871
> file type = ENVI Standard
> header offset = 0
> map info = {UTM, 1.000, 1.000, 564761.521, 5699816.363, 4.7102936126e+000, 4.7087100663e+000, 31, North, WGS-84, units=Meters}
>
> vitotagprojectionsystem = Universal_Transverse_Mercatorvitotagprojectiondatum = WGS_84vitotagprojectionzone = 31
> I was mistaken earlier that projection datum was Eueropean1950 instead it is WGS84
> so I think the projection code should be:
> proj4string(A) <- CRS("+proj=utm +zone=31 +ellps=WGS84")
Or perhaps
proj4string(A) <- CRS("+proj=utm +zone=31 +datum=WGS84")
to fix the datum and ellipse at one go.
> Regarding the tolerance problem; The difference in the X coordinates
> (column 1 out of 21 column)varies from 4.7019876 to 4.719234 so the
> default tolerance 0.00212314227724164 does not incorporate those
> variation. This is my source of error. Thanking you in advance Pujan
The given value is an internal value, but indicates what may be set to
correct the problem. Do you know why the differences in the x coordinates
vary? These look too big to be rounding error. I believe that the current
points2grid will not solve the problem, but am working on a solution.
Another question is whether you could transfer data from ENVI to R using a
different file format, for example as a GTiff, and the read it using
readGDAL() in rgdal?
Roger
>
>> Date: Fri, 2 May 2008 19:49:07 +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 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
> _________________________________________________________________
> Stay in touch when you're away with Windows Live Messenger.
> http://www.windowslive.com/messenger/overview.html?ocid=TXT_TAGLM_WL_Refresh_messenger_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