[R-sig-Geo] adding a scale

Gilles Benjamin Leduc gbl1 at hi.is
Mon Apr 27 16:59:23 CEST 2015


 
 Not to bad hint :p

So From this one, I modified the function to get it work correctly: 

#############################################################################################################################################################################
####                                                            		         Scale				                                                                     ####
#############################################################################################################################################################################

scalebar <- function(loc,length,unit="km" ,degrees = TRUE,cex=par("cex"), ...) { 
	if(missing(loc)) stop("loc is missing") 
	if(missing(length)) stop("length is missing") 
	z <- c(0,length/c(4,2,4/3,1),length*1.1)+loc[1] 
	if(degrees == TRUE) length<-180*(acos((cos(length/6371)-sin(loc[2]*pi/180)*sin(loc[2]*pi/180))/(cos(loc[2]*pi/180)*cos(loc[2]*pi/180))))/pi
	x <- c(0,length/c(4,2,4/3,1),length*1.1)+loc[1] 
	y <- c(0,length/(10*3:1))+loc[2] 
	cols <- rep(c("black","white"),2) 
	for (i in 1:4) rect(x[i],y[1],x[i+1],y[2],col=cols[i])
	 for (i in 1:5) segments(x[i],y[2],x[i],y[3]) 
	 labels <- z[c(1,3)]-loc[1]
labels <- append(labels,paste(z[5]-loc[1],unit)) 
text(x[c(1,3,5)],y[4],labels=labels,cex,pos=3,offset=0) }


and pushed it in my package https://github.com/giby/Linarius if someone wanna try. I could do some improve to support other units, I'll do that latter on.  

Thanks a lot for help 

Benjamin 
 
On Saturday, April 25, 2015 10:36 GMT, Guido Schulz <gosz at gmx.de> wrote: 
 
> You may want to check out this paper "Auxiliary Cartographic Functions
> in R: North Arrow, Scale Bar, and Label with a Leader Arrow"
> (http://www.jstatsoft.org/v19/c01/paper).
> 
> It provides functions to add arrow and scale bar for plot.
> 
> 
> Am 24.04.2015 um 14:10 schrieb Gilles Benjamin Leduc:
> > Hi again, > > So, I use the plot() function. > I read a shapefile, that I convert in GPS coordinates like this: > > readOGR(dsn=S50V_STRANDLINA_24122014_ISN2004/IS50V_STRANDLINA_SHP", layer="is50v_strandlina_flakar_24122014")->IslHD
> > spTransform(IslHD,CRS(" +proj=nglat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 "))->IslHD > > then plot : plot(IslHD) > > I tried several stuff for making a scale, results were either ugly or wrong… > The function Scalebar make a cute scale but really absurd… > > Any idea? > > Best regards
> > > Benjamin   >  >  > On Thursday, April 23, 2015 05:18 GMT, Frede Aakmann Tøgersen <frtog at vestas.com> wrote: >  >> Hi Benjamin
> >>
> >> Yes, there are several ways to do that. But it depends on which kind of plotting function you used. Usually it is a setting of an argument of the plotting function.
> >>
> >> I cannot help you more since I don't more than the information you provided in your email.
> >>
> >> If you want more help from this list please provide a small example showing which functions you used with information on which package(s) they belong. Then you'll probably get more help.
> >>
> >> The small example you can probably find in the example section on the help page for the plotting function.
> >>
> >> Best Regards
> >>
> >> Frede Aakmann Tøgersen
> >> Specialist, M.Sc., Ph.D.
> >> Plant Performance & Modeling
> >>
> >> Technology & Service Solutions
> >> T +45 9730 5135
> >> M +45 2547 6050
> >> frtog at vestas.com
> >> http://www.vestas.com
> >>
> >> Company reg. name: Vestas Wind Systems A/S
> >> This e-mail is subject to our e-mail disclaimer statement.
> >> Please refer to www.vestas.com/legal/notice
> >> If you have received this e-mail in error please contact the sender.
> > >>
> >> -----Original Message-----
> >> From: R-sig-Geo [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of Gilles Benjamin Leduc
> >> Sent: 23. april 2015 02:46
> >> To: r-sig-geo at r-project.org
> >> Subject: [R-sig-Geo] adding a scale
> >>
> >> Hi all,
> >>
> >> I am ploting map from shapefiles (curently read with readOGR from rgdal). >> My PhD supervisor asked me to add a scale… Before going in crazy computation and the arrow function I wonder… Is there a function that can do it automatically (or easily) >>
> >> Thanks in advance >>
> >> Benjamin
> >>
> >> _______________________________________________
> >> R-sig-Geo mailing list
> >> R-sig-Geo at r-project.org
> >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> > >
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list