Hello, <http://stackoverflow.com/questions/32717742/automatic-label-plotting-using-pointlabel-from-maptools-library-in-r#>
I am trying to solve automatic label placement problem for an engineering drawing using the Simulated Annealing algorithm. I came across the pointLabel() function in the maptools library in R. However, what I found was that while the function is able to optimally place the labels, it doesn't take into account the underlying drawing. I don't want the labels to overlap with the drawing lines. Is there some way I can achieve this? Also, my labels are of varying size in terms of width and height. Is there any way in which I can specify the dimension of each label apart from the point of origin of the labels? This is my code and a link to the requisite csv files: https://www.dropbox.com/s/85qqs4nlvm4crck/TextBoxData.rar?dl=0 library(dplyr) library(maptools) #Known Size of Sheet xmin <- -357.7 xmax <- 19.3 ymin <- -90.2 ymax <- 159.7 #Read in the data linescoords <- read.csv("Linecoords.csv") #Coordinates translation linescoords$X <- linescoords$X - xmin linescoords$Y <- linescoords$Y - ymin #Plot the figure xlimit <- c(-10, abs(xmin-xmax)+10 ) ylimit <- c(-10, abs(ymin-ymax)+10 ) plot(linescoords$X, linescoords$Y, "p", xlim=xlimit, ylim = ylimit) i <- seq(1, nrow(linescoords), 2)for(x in i){ segments(linescoords$X[x], linescoords$Y[x], linescoords$X[x+1], linescoords$Y[x+1])} #Read in text labels data labels <- read.csv("labels.csv") #Text labels Coordinates translation labels$x <- labels$x - xmin labels$y <- labels$y - ymin labels$xminl <- labels$xminl - xmin labels$xmaxl <- labels$xmaxl - xmin labels$yminl <- labels$yminl - ymin labels$ymaxl <- labels$ymaxl - ymin #Point of Origin for labels points(labels$x, labels$y, pch=16, col="red") #Width & Height of labels labels <- labels %>% mutate(width=abs(xminl-xmaxl), height=abs(yminl-ymaxl)) pointLabel(labels$x, labels$y, labels$Point) Regards Dhiraj Khanna Mob:09873263331 [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo