Hi, welcome again and in this lecture I'll show you how to add another layer to
this map. Currently we have two layers we have the base map which are map tiles by
map box you can see here and the data are served by Open Street Map and you
also have your custom layer as well which is a layer containing circle
markers. So in GIS, geographic information systems these are referred to as layers.
Now I'd like to add a third layer to my map and that will be a polygon layer.
So this current layer with markers, this can be referred to as a point layer.
You also have line layers and polygon layers so with points, points are better
to represent locations and you have lines, lines are best for representing
geographical features which resembles lines such as roads and rivers and then
we have polygons. Polygons are best to represent areas so for instance in this
lecture what I'll show you is how to add a layer, a polygon layer that represents
world population by country, so countries are represented as areas and what we're
going to do is each of the countries will have a specific color which will
indicate the population of that country so points for locations lines, for lines,
and polygons for areas. Now of course you need to have some data to create
a polygon layer. You know just like as we did with markers we had some data in CSV
in text format and then we used those data, we opened them with Pandas and then
we iterated through those lines of data and we added the markers to the map.
Now for polygons the way to add polygons via Folium is by
using the folium.GeoJson method, so basically let me make some space here
the way this would work is you want to add to feature group the variable here.
You want to add a child which will be a folium.GeoJson object. So this is the
method with brackets here that creates a GeoJSON object and for GeoJSON data we
will use this world.JSON file. You can find this attached in this lecture
and let me explain what this is, but careful, don't open it on Atom
because if your computer is a bit slow your atom may crash, so try to open
it with a lighter editor such as notepad for instance, or cat on a Linux terminal
or Mac. Anyway this is the JSON file you can refer to it as JSON or GeoJson.
Actually GeoJSON is a special case of JSON. Basically the format is always the
same, it starts with curly brackets and basically it contains a string which is
like a Python dictionary with keys and values. Keys, key and value where this
curly bracket ends somewhere here I believe. If I'm not wrong. This one ends
in here, yeah. Then you have the other key, geometry. So what is geometry? When the
type of geometry is multi polygon so basically you have this kind of
attributes that describe the data. Type multi polygon or coordinates.
So this is now starting to describe the features, the polygons so these are the
coordinates over the first polygon that will be displayed on the map. Let's say
this is one specific country and that's that's, that's Antigua and Barbuda, yeah.
A small country but anyway and these are the coordinates that will determine the
location of the polygon in your map so basically Folium will read all this
information and it will decide where to put the polygons and then you can also use
other attributes of this such as population which is here, yeah. You will use
this population value to put a color for that population and so on and so forth.
You have all countries of the world in this JSON file, so spend a few minutes
looking at this file to understand its structure and in the next lecture I'll
go ahead and load the JSON file into Python and display the polygon layer.
See you there!