R maps

January 28, 2015

Nice world map

library(rgdal) # depends on 'sp'
library(maptools)

# Get the countries' outlines
path_of_shape_file <- "D:\\maps\\shapefiles\\vdstech.com\\world"
name_of_shape_file <- "world"
world <- readOGR(dsn=path_of_shape_file, name_of_shape_file)
#
plot(world)
box()

missing image: world map wgs-84

Projection for Europe

# Change projection
#
# Step 1: 
# summary(world) => proj4string : [NA]
# So no projection is given :-(
# From http://www.vdstech.com/world-data.aspx I read that it should be WGS84
#   more info http://spatialreference.org/ref/epsg/4326/
#   more info http://georepository.com/crs_4326/WGS-84.html
crs.old <- CRS("+init=epsg:4326") # World Geodetic System 1984 - Geographic 2D CRS used in World
proj4string(world) <- crs.old
#
# Step 2:
# Change projection to ETRS89 / LAEA Europe
# Europäisches Terrestrisches Referenzsystem 1989
# European Terrestrial Reference System 1989
#   more info http://spatialreference.org/ref/epsg/3035/
#   more info http://georepository.com/crs_3035/ETRS89-LAEA-Europe.html
#   LAEA = Lambert azimuthal equal-area projection
crs.new <- CRS("+init=epsg:3035") # ETRS89 / LAEA Europe - Projected CRS used in Europe
world <- spTransform(world, crs.new)
#
plot(world)
box()

missing image: map europe etrs89

Zoom in and output to PNG

colCountryDefault <- "#cacaca"
colCountryDefaultBorder <- "white"
colWater <- "white"
borderWidth <- 0.8
#
lon_range <- c(1.6e+06, 6.0e+06) # W -> E
lat_range <- c(0.9e+06, 5.3e+06) # S -> N
my_width  <- 600 # Pixel
my_height <- (  my_width  *  abs(diff(lat_range))  /  abs(diff(lon_range))  )
#
ts <- format(Sys.time(), "%Y%m%d-%H%M%S")
FilePathName <- paste(c(getwd(), "/map", ts, ".png"), collapse='')
png(filename=FilePathName, width=my_width, height=my_height, pointsize = 12, bg="transparent", res=72)
par(mai=c(0,0,0,0)) # sets margins in inches
par(mar=c(0,0,0,0)) # sets margins in number of lines of text
plot(world, xlim=lon_range, ylim=lat_range, bg=colWater, col=colCountryDefault, border=colCountryDefaultBorder, lwd=borderWidth)
box()
dev.off()

missing image: map europe etrs89 zoomed

Projections

Who knows which projection to choose for which map extract? Great helper: Projection Wizard

missing image: projection wizard website screenshot

That website helped me so far for the following maps:

# World, Compromise, Natural Earth
crs.new <- CRS("+proj=natearth +lon_0=0")
world <- spTransform(world, crs.new)
lon_range <- c(-12.8e+06, 15.0e+06) # W -> E
lat_range <- c( -6.0e+06,  9.0e+06) # S -> N

missing image: map world natearth

# Middle & South America, Conformal, Oblique Stereographic
crs.new <- CRS("+proj=stere +lat_0=-15 +lon_0=-65")
world <- spTransform(world, crs.new)
lon_range <- c(-5.0e+06, 3.5e+06) # W -> E
lat_range <- c(-5.0e+06, 6.0e+06) # S -> N

missing image: map south america stere

# North America, Conformal, Lambert conformal conic
crs.new <- CRS("+proj=lcc +lat_1=20.83 +lat_2=64.16 +lon_0=-110")
world <- spTransform(world, crs.new)
lon_range <- c(-3.0e+06, 4.0e+06) # W -> E
lat_range <- c( 3.0e+06, 8.5e+06) # S -> N

missing image: map north america lcc

# Europe, Conformal, Lambert conformal conic
crs.new <- CRS("+proj=lcc +lat_1=36.83 +lat_2=64.16 +lon_0=15")
world <- spTransform(world, crs.new)
lon_range <- c(-3.1e+06, 2.4e+06) # W -> E
lat_range <- c( 4.0e+06, 8.5e+06) # S -> N

missing image: map europe lcc

Ausweiskopien

Sind Ausweiskopien in Deutschland erlaubt oder nicht? Continue reading

Access Jedox H2 Console

Published on March 21, 2016