Welcome to the tutorial page of the rcityviews
package!
The aim of this page is to show you how you can use this package to
create stylized images of the world’s cities. For this tutorial, I will
focus on rendering one of my favorite cities in the world: Amsterdam. Of
course, feel free to adjust the code provided here to create an image of
any city of your choice.
First, allow me to shortly share the motivation behind the development of this package. I like the look of printed city posters. For instance, I think they are a nice present for a friend’s birthday or to use as a decoration for my own living space. However, the price tag and restricted options associated with buying such posters online often dissuaded me from making a purchase. Nevertheless, I wanted to have one depicting my hometown hanging on the wall in my living room. Luckily, we are fortunate enough to live in a fascinating era where open-source software can be used to accomplish almost anything. Thanks to the incredible efforts made by the OpenStreetMap contributors, a treasure trove of open geographical data is currently available, enabling everybody to effectively make high-quality city posters in R. Maybe even more important than that these posters cost no money, they are also free.
Before we start mapping, let’s introduce the star of this tutorial. Amsterdam is the capital and most populous city of the Netherlands and is well-known for its canals, museums, bicycles, and coffee shops (not the ones that sell coffee). The city is also incredibly diverse, with residents from over 180 different nationalities living within its limits. With much variety in its urban and natural features, Amsterdam makes for a pretty picture to look at from the sky.
To start mapping the city in R, you will first need to install the
rcityviews
package (see the home page for
installation instructions) and load the package into your current R
session.
#> Data by © OpenStreetMap contributors
The package contains a large internal database of cities names and
coordinates that you can access using the list_cities()
function. Let’s verify that the city of Amsterdam is included in the
internal database.
list_cities(match = "Amsterdam")
#> name country lat long
#> 1 Amsterdam The Netherlands 52.37 4.89
#> 2 New Amsterdam Guyana 6.25 -57.53
#> 3 Nieuw Amsterdam Suriname 5.91 -55.07
As you can see, there are three entries in the internal database
matched to the name “Amsterdam”. Since we want to make an image of
Amsterdam in the Netherlands (the first row of the output), we simply
need to remember that the name
of this city is denoted as
Amsterdam
in the internal database. Once you have matched
the name of the city to its database entry, you can create an image of
the city by providing the city name as a string to the
cityview()
function.
Please be aware that rendering times in RStudio can be quite long for
crowded spatial images. You can avoid the render time entirely by
specifying a file name as input for the filename
argument
in the cityview()
function. By doing so, the image will be
directly exported to your working directory in an appropriate format.
This is the recommended approach because it ensures that the image is
displayed properly at all times. Moreover, if you want to make a
high-quality poster (e.g., for printing), it is recommended to export
the image to a .pdf
or .svg
file.
cityview(
name = "Amsterdam",
filename = "Amsterdam.png"
)
The basic setup in the code block above is all you need to map any
city in the internal database. However, you can call the
cityview()
function with additional arguments to style the
image to your liking. For example, the theme
argument
enables you to set the color scheme and font used in the image, while
the border
argument enables you to set the type of border
that surrounds the city. You can find detailed documentation and
examples of these arguments on the home page.
For instance, if you want the image to be rendered in a more
minimalist style and you want the the city to be surrounded by a
circular border, you can use the cityview()
function with
the additional arguments theme = "original"
and
border = "circle"
.
cityview(
name = "Amsterdam",
border = "circle",
theme = "original",
filename = "Amsterdam2.png"
)
Now that you have learned how to create a city view of Amsterdam, let’s explore some specific districts within the city. Amsterdam is divided into seven main residential districts (i.e., not including the harbor area “Havengebied”), each with its own unique hotspots and features. You can use the various themes in the package to create images of some of these districts and stylize them according to what makes them unique.
First, let’s explore the center of Amsterdam. This specific location
is not featured in the internal database, which means that you will need
to create a new city instance for it using the new_city()
function.
amsterdam <- list_cities("Amsterdam")[1, ]
# Create instance
center <- new_city(
name = "Centrum, Amsterdam",
country = "The Netherlands",
lat = amsterdam[1, 3],
long = amsterdam[1, 4]
)
#> Discovered Centrum, Amsterdam, The Netherlands at 52.37° / 4.89°!
Instead of drawing a geometric border around this location, you can
isolate the center of Amsterdam by using the bounding box for the
district as a border (border = "bbox"
) for the image. Using
the bbox
border is slightly different from using any other
border style, since it attempts to retrieve a border polygon using the
Nominatim
API. This means that it is crucial that the name given to
new_city()
matches an entry in Nominatim. You can verify
this by searching for your city in the API. For instance, Nominatim
contains the center of Amsterdam as Centrum,
Amsterdam, which is why the name
argument in the code
above is specified as "Centrum, Amsterdam"
.
Next, you can use the created city instance as input for the
cityview()
function, while also providing the argument
border = "bbox"
. This will render the image of the center
of Amsterdam using the bounding box for the district. The center of
Amsterdam is a historical and cultural hub, known for its canals,
architecture, and tourist attractions. This district offers a unique
blend of historic charm and modern energy. To capture its historical
significance within the city, I found the vintage
theme
suits the district best.
# Create image
cityview(
name = center,
border = "bbox",
filename = "AmsterdamCenter.png"
)
Let’s expand the tour of Amsterdam to some of its other districts, like Amsterdam-Oost. Oost is a district located in the eastern part of Amsterdam, adjacent to the city center. It is well-known for its diverse neighborhoods, trendy cafes and cultural hotspots, creating a cultural melting pot with a lively atmosphere.
We can obtain the data for this district by creating a new city
instance using Oost, Amsterdam
, which is available in the
Nominatim API. Similar to before, after you have created a new city
instance using the new_city()
function, you can use the
cityview()
function with the border = "bbox"
argument to render the image using the bounding box for this district.
Because Oost offers such a diverse mix of cultural experiences, I found
the bright
theme to be most fitting for the district.
Let’s continue the tour of Amsterdam by visiting one of its other districts. Amsterdam-Zuid is a highly sought-after district nestled in the southern part of the city. This area is renowned for its beautiful architecture, featuring elegant homes and inspiring museums. The southern part of Amsterdam also boasts an abundance of beautiful parks, providing residents with ample green spaces to enjoy.
By creating a new city instance for Zuid, Amsterdam
,
which is available in the Nominatim API, you can obtain the necessary
data for this district. You probably know the drill by now, but you can
use the cityview()
function with the
border = "bbox"
argument to render the image using the
bounding box for this district. Because Zuid is a quite upscale, I
decided to render this image with the delftware
theme to
add a touch of elegance and traditional Dutch flair.
Let’s move on to Amsterdam-West, the fourth district to visit. Situated between two sprawling parks and in close proximity to the city center, this once-working-class area has transformed into a hub of historic architecture, trendy concept stores, and lively local bars where residents of all ages like to spend their free time.
Since you arere already familiar with the process of creating a new
city instance using the Nominatim API, I won’t go into the details again
on how to do this for West, Amsterdam
. Due to its trendy
vibes, I believe the modern
theme is a good fit for the
district.
Finally, let’s visit Amsterdam-Noord, a district situated across the
IJ river to the north of the city center. As a former shipyard area,
Noord is gaining prominence as an upcoming district, known for its
creative energy and artistic scene. This dynamic district presents a
captivating blend of modern architecture, fashionable waterfront cafes
and vibrant cultural hubs. I found the comic
theme to be
most fitting of the creative scene in this district, as it gives the
image a bit of a playful touch.
# Create instance
north <- new_city(
name = "Noord, Amsterdam",
country = "The Netherlands",
lat = amsterdam[1, 3],
long = amsterdam[1, 4]
)
# Create image
cityview(
name = north,
border = "bbox",
theme = "comic",
filename = "AmsterdamNorth.png"
)
That wraps up the tour of Amsterdam in this tutorial. Two districts, namely Nieuw-West and Zuidoost, have not been covered here. I encourage the interested reader to explore and map these districts on their own.
I hope you found this tutorial informative and inspiring to create
your own personalized city maps using the rcityviews
package. If you have created something you’re proud of, I would love to
hear about it. Happy mapping!
This package is largely made possible by the invaluable contributions and unwavering dedication of the OpenStreetMap contributors and the developers who have made these data available to R users. Their tireless efforts continue to improve the accessibility of open data for mapping worldwide. A heartfelt thank you to everyone involved!