Display and query burnt areas data from 2000 to 2016¶

Create a simple interface using ipywidgets to display and query data about burnt areas in the mediterranian region over many years

Import all needed modules:

In [ ]:
from jeodpp.imap import Marker
from ipywidgets import Layout, interact
import ipywidgets as widgets
from IPython.core.display import display, HTML, clear_output

Define a custom identify function that outputs an HTML table with some attributes of the vector layer:

In [ ]:
gyear = 2016

def identify(map, vector):
    global gyear
    year_clause = "YearSeason = " + str(gyear)
    vector.parameter("Identify","all")
    vector.parameter("IdentifyFilter",year_clause)
    vector.parameter("IdentifyField","FireDate Place_Name Province Country Area_HA")
    vector.parameter("IdentifySeparator","#")
    vector.parameter("IdentifySortField","FireDate")
    
    def OnChangedLocation(event, location):
        values = unicode(vector.identifyPoint(location[1],location[0],4326,map.zoom), encoding="utf-8", errors="ignore")
        clear_output()
        valueslist = values.split('#')
        if len(valueslist) > 4:
            html = '<table style="width:100%"> <tr> <th>Date</th> <th style="width:40%">Place</th>'
            html += '<th style="width:30%">Province</th> <th>Country</th> <th>Hectares</th> </tr>'
            for i in range(0,len(valueslist),5):
                html += '<tr>'
                for j in range(i,i+5):
                    html += '<td>' + valueslist[j] + '</td>'
                html += '</tr>'
            html += '</table>'
            display(HTML(html))

    mark = Marker(location=map.center,opacity=0.9)
    map += mark
    mark.on_move(OnChangedLocation)
    return mark

def activate_identify(map,v):
    if 'mark' in locals():
        mark.visible = False
        mark.close()
    mark = identify(map, v)

Display a Map:

In [ ]:
map = Map()
map

Create a simple integer slider to select a year and display the polygons of burnt areas for that year:

In [ ]:
v = inter.VectorLayer("BurntAreas").opacity(255)

def setyear(year):
    global gyear
    gyear = year
    year_clause = "[YearSeason] = " + str(year)
    v.reset()
    v.remove('default','all')
    v.set('default',year_clause,'poly','fill','#ff000055')
    v.set('default',year_clause,'line','stroke','#000000')
    map.clear()
    map.addLayer(v.toLayer())
    
s=interact(setyear,year=widgets.IntSlider(min=2000,max=2016,value=2016,description='Select year:'), continuous_update=False)

Activate identify marker:

In [ ]:
activate_identify(map,v)

Use an integer range slider widget to select a range of years:

In [ ]:
map = Map()
map
In [ ]:
def update(minyear,maxyear):
    v = inter.VectorLayer("BurntAreas").opacity(255)
    year_clause = "[YearSeason] >= " + str(minyear) + " and [YearSeason] <= " + str(maxyear)
    v.remove('default','all')
    v.set('default',year_clause,'poly','fill','#ff0000')
    v.set('default',year_clause,'line','stroke','#000000')
    map.clear()
    map.addLayer(v.toLayer())

def on_value_change(change):
    indexes = change['new']
    update(indexes[0],indexes[1])
    
r = widgets.IntRangeSlider(value=[2000,2016],min=2000,max=2016,step=1,description='Range of years:',
                           layout=Layout(width='70%'), continuous_update=False)
display(r)
r.observe(on_value_change, names='value')
update(2000,2016)
In [ ]: