Creating Interactive Maps of UKCS Oil and Fuel Subject Outlines
Folium is a superb python library that makes it straightforward to visualise geospatial knowledge on interactive maps utilizing the facility of Leaflet.js. In my earlier article, I coated learn how to show particular person markers on a folium map, however we are able to use folium additionally show knowledge that has been saved inside a GeoJSON file.
GeoJSON is a generally used file format for storing geospatial knowledge and makes use of JavaScript Object Notation. These information can retailer location knowledge, shapes, factors, surfaces, and so forth.
Inside this text, we are going to see learn how to show polygons of UK North Sea oil and gasoline fields which have been saved inside a GeoJSON file format.
The info for this text is sourced from knowledge.gov.uk and is licenced beneath the Open Authorities Licence. The info will be seen and downloaded from the next web site.
Putting in Folium
For those who don’t have already got folium put in, you’ll be able to set up it through pip:
pip set up folium
Or Anaconda:
conda set up folium
After you have the library put in, step one is to import the folium library into our Jupyter Pocket book:
import folium
To maintain issues easy, we are going to assign the placement of the GeoJSON file to a variable. This makes issues easier once we need to name upon it later or change it for an additional file with out altering the remainder of the code instantly.
field_locations = ‘geodata/NSTA_Offshore_Fields_WGS84.geojson’
Subsequent, we have to initialise a folium map with some primary parameters.
The created map might be centred round a latitude of 58 levels N and a longitude of 5 levels E. We may even set the zoom_start to six to permit us to view a lot of the UK North Sea.
There are a number of different parameters we are able to use when making a folium map. If you wish to be taught extra, try the assistance documentation on the folium.map class.
m = folium.Map(location=[58, 5], zoom_start=6, control_scale=True)m
After we name upon the folium map object utilizing the variable m we are going to get the next map displayed:
This generated map seems naked, so the subsequent step is so as to add some shapes to establish the UK offshore oil and gasoline fields.
To show the info from a GeoJSON file, we have to name upon folium.geojson and go in just a few parameters.
The primary parameter is the placement of the GeoJSON file, which we assigned to the variable field_locations. That is then adopted by the tooltip parameter, which permits us to show data within the tooltip when any of the shapes are hovered over. On this instance, we are going to set the fields to be exhibited to the identify of the oil or gasoline discipline (FIELDNAME).
Lastly, to make the objects seem, we have to add the extension add_to(m) on the finish.
folium.GeoJson(field_locations,tooltip=folium.GeoJsonTooltip(fields=[‘FIELDNAME’])).add_to(m)
We’re offered with the next map once we name upon the folium map object: m.
From the generated map, we are able to see the areas of the entire UK North Sea oil and gasoline fields.
If we need to add some styling to the shapes on the map, we are able to accomplish that by first making a perform which might be used to regulate the color of the form.
From this dataset, we might be utilizing the kind of discipline to decide on the colors that we need to show. Any oil fields might be displayed in inexperienced, gasoline fields proven in crimson, and condensate fields might be displayed in orange.
The next code was derived from this StackOverflow put up.
def field_type_colour(function):if function[‘properties’][‘FIELDTYPE’] == ‘COND’:return ‘orange’elif function[‘properties’][‘FIELDTYPE’] == ‘OIL’:return ‘inexperienced’elif function[‘properties’][‘FIELDTYPE’] == ‘GAS’:return ‘crimson’
Now that we’ve the conditional perform arrange, we have to add a brand new parameter to our name to folium.GeoJson referred to as style_function. Inside this parameter, we go in a lambda perform containing a dictionary for the styling properties.
On the subject of the fillColor property, we name upon the perform we created above and go in our function.
We will additionally go further styling properties to the dictionary. For this instance, we are going to set the fillOpacity to 0.9 and the burden, which controls the road across the shapes, to 0.
If we don’t need to embrace the shapes from the earlier part, we have to recreate the folium map once more.
m = folium.Map(location=[58, 5], zoom_start=6, control_scale=True)
folium.GeoJson(field_locations, identify=’geojson’, tooltip=folium.GeoJsonTooltip(fields=[‘FIELDNAME’]),style_function= lambda function: {‘fillColor’:field_type_colour(function), ‘fillOpacity’:0.9, ‘weight’:0}).add_to(m)m
After we name upon m, we’re offered with the next map.
We will now see that every form/discipline that’s on the map is colored primarily based on the first kind of hydrocarbon that’s contained inside the reservoir part.
Inside the GeoJSON file, we’ve a number of further properties for every form. These can simply be added to the prevailing tooltip by together with them inside the record for the fields parameter.
m = folium.Map(location=[58, 5], zoom_start=6, control_scale=True)
folium.GeoJson(field_locations, identify=’geojson’, tooltip=folium.GeoJsonTooltip(fields=[‘FIELDNAME’, ‘PROD_DATE’,’CURR_OPER’]),style_function= lambda function: {‘fillColor’:field_type_colour(function), ‘fillOpacity’:0.9, ‘weight’:0}).add_to(m)m
After we rerun the code, we are able to now see that we get the additional properties once we hover over every of the shapes. On this case, we are able to see the sphere identify, the date manufacturing began, and the present operator of the sphere.
Inside this quick article, we’ve seen how straightforward it’s to show knowledge saved inside a GeoJSON file on an interactive folium map. This enables us to shortly show shapes and descriptions that could be saved inside the sort of file.