Difference between revisions of "OpasnetUtils/Drafts"

From Testiwiki
Jump to: navigation, search
(Answer)
(Answer: function MyRmap moved here)
Line 219: Line 219:
 
}
 
}
  
objects.store(ograph, fillna, collapsemarg, MyPointKML, ova2spat)
+
# MyRmap is a function for creating static Google maps as png.
 +
# It is based on MyMap function without the "file destination" parameter
 +
# Requires RgoogleMaps package
  
cat("The following objects are stored: ograph, fillna, collapsemarg, MyPointKML, ova2spat.\n")
+
MyRmap <- function (
 +
shp, # a spatial data object
 +
plotvar, # Name of the column that has the values to be illustrated on the map
 +
pch = 19, # Shape of the point (19: circle)
 +
cex = 0.3, # Size of the point
 +
legend_title = "", # Title of the legend
 +
legend_position = "topleft",
 +
numbins = 8, # Number of colour bins in graph
 +
center, # center of the map
 +
size = c(640, 480), # size of the map. This produces the right dimensions in Opasnet.
 +
MINIMUMSIZE = FALSE,
 +
RETURNIMAGE = TRUE,
 +
GRAYSCALE = FALSE,
 +
NEWMAP = TRUE,
 +
zoom,
 +
verbose = 1,
 +
...
 +
) {
 +
plotvar <- shp[[plotvar]]
 +
plotclr <- brewer.pal(numbins, "Spectral")
 +
classes <- classIntervals(plotvar, numbins, style = "quantile")
 +
colcode <- findColours(classes, plotclr)
 +
latR <- shp@coords[ , 2]
 +
lonR <- shp@coords[ , 1]
 +
 
 +
#get the bounding box:
 +
 
 +
bb <- qbbox(lat = latR, lon = lonR)
 +
 
 +
if (missing(zoom))
 +
zoom <- min(MaxZoom(latR, lonR, size))
 +
if (missing(center)) {
 +
lat.center <- mean(latR)
 +
lon.center <- mean(lonR)
 +
}
 +
else {
 +
lat.center <- center[1]
 +
lon.center <- center[2]
 +
}
 +
if (MINIMUMSIZE) {
 +
ll <- LatLon2XY(latR[1], lonR[1], zoom) # I think the latR and lonR are used here differently than how they
 +
ur <- LatLon2XY(latR[2], lonR[2], zoom) # are used elsewhere. Thus, if MINIMUMSIZE = TRUE, you may see problems.
 +
cr <- LatLon2XY(lat.center, lon.center, zoom)
 +
ll.Rcoords <- Tile2R(ll, cr)
 +
ur.Rcoords <- Tile2R(ur, cr)
 +
if (verbose > 1) {
 +
cat("ll:")
 +
print(ll)
 +
print(ll.Rcoords)
 +
cat("ur:")
 +
print(ur)
 +
print(ur.Rcoords)
 +
cat("cr:")
 +
print(cr)
 +
}
 +
size[1] <- 2 * max(c(ceiling(abs(ll.Rcoords$X)), ceiling(abs(ur.Rcoords$X)))) + 1
 +
size[2] <- 2 * max(c(ceiling(abs(ll.Rcoords$Y)), ceiling(abs(ur.Rcoords$Y)))) + 1
 +
 
 +
if (verbose) cat("new size: ", size, "\n")
 +
}
 +
 
 +
MyMap <- GetMap(
 +
center = c(lat.center, lon.center),
 +
zoom = zoom,
 +
size = size,
 +
RETURNIMAGE = RETURNIMAGE,
 +
GRAYSCALE = GRAYSCALE,
 +
verbose = verbose,
 +
...
 +
)
 +
 
 +
PlotOnStaticMap(MyMap) # Plot an empty map.
 +
 
 +
PlotOnStaticMap( # Plot the data points on the map.
 +
MyMap,
 +
lat = latR,
 +
lon = lonR,
 +
pch = pch,
 +
cex = cex,
 +
col = colcode,
 +
add = T
 +
)
 +
 
 +
legend( # Plot the legend on the map.
 +
legend_position,
 +
legend = names(attr(colcode, "table")),
 +
title = legend_title,
 +
fill = attr(colcode, "palette"),
 +
cex = 1.0,
 +
bty = "y",
 +
bg = "white"
 +
)
 +
}
 +
 
 +
objects.store(ograph, fillna, collapsemarg, MyPointKML, ova2spat, MyRmap)
 +
 
 +
cat("The following objects are stored: ograph, fillna, collapsemarg, MyPointKML, ova2spat, MyRmap.\n")
  
 
</rcode>
 
</rcode>

Revision as of 14:15, 23 December 2013



Question

Which functions are so useful that they should be taken into OpasnetUtils package? This page contains draft function which will be included when they are good enough and found important.

Answer

+ Show code

See also

References


Related files

<mfanonymousfilelist></mfanonymousfilelist>