[R-sig-Geo] Help on pointLabel() function for engineering drawings

Dhiraj Khanna dhirajkhanna at gmail.com
Thu Sep 24 19:23:55 CEST 2015



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:

#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)


Dhiraj Khanna

	[[alternative HTML version deleted]]

More information about the R-sig-Geo mailing list