1

I created a georeferenced PDF using a shapefile and OK no problem, but I'd like to know if is possible to insert a title inside a pdf (in top position "My geo PDF"), points of interest (pts.sampling) and values too.

In my example:

Packages

require(rgdal)
require(maptools)

Create 2 polygons

sr <- SpatialPolygons(list(
Polygons(list(Polygon(cbind(c(180114, 180553, 181127, 181477, 181294, 181007, 180409,
  180162, 180114), c(332349, 332057, 332342, 333250, 333558, 333676,
  332618, 332413, 332349)))),'1'),
Polygons(list(Polygon(cbind(c(180042, 180545, 180553, 180314, 179955, 179142, 179437,
  179524, 179979, 180042), c(332373, 332026, 331426, 330889, 330683,
  331133, 331623, 332152, 332357, 332373)))),'2')))

Convert in spatial polygon

srdf=SpatialPolygonsDataFrame(sr, data.frame(row.names=c('1','2'), PIDS=1:2))
srdf@data
proj4string(srdf) <- CRS("+proj=utm +zone=21 +south +datum=WGS84 +units=m +no_defs")

Create shapefile

writeOGR(srdf, getwd(), 'ARS', 'ESRI Shapefile')

Read shapefile

contorno_line<- readShapeLines ("ARS.shp") 

Plot

plot(contorno_line, main="My geo PDF")

Points of interest and values

x<-c(180684.2,  179786.2,   180766.4,   180335.5,   181392.6,   180881.9,   181167.9,   180544.5,   180680.9,   180259.6)
y<-c(332264.8,  331057.3,   332190.5,   331643.7,   333384.4,   333444.8,   333381.6,   332607.9,   332625.9,   331867.7)
Class<-c(5,5,3,1,2,3,5,5,2,2)
pts<-cbind(x,y,Class)
pts.sampling = SpatialPoints(pts, proj4string=CRS("+proj=utm +zone=21 +south +datum=WGS84 +units=m +no_defs"))
points(pts.sampling, col="red")
text(pts.sampling,labels=paste(pts.sampling$Class), cex= 0.7,pos=3)

Create a geoPDF

writeOGR(contorno_line, dsn = "mygeoPDF", layer = "contorno_geo", driver = "PDF") 

But my problem is, how I can put main="My geo PDF", points(pts.sampling, col="red") and text(pts.sampling,labels=paste(pts.sampling$Class), cex= 0.7,pos=3) inside mygeoPDF.pdf created?

  • Have you seen this? Might be useful. Looks like you might be better off plotting the shapefile in R, adding the title in the plot window and then exporting it as an image/PDF, if you don't want to write it back as a shapefile. Might be easier that way. stackoverflow.com/questions/20615298/… – Vijay Ramesh Mar 17 '17 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.