Web Page Generator

Environmentally friendly farming with a fertilization planning tool

By Stif Labarque, Mar 20th 2017
Farmers have a lot of responsibility when it comes to preserving the water quality of our planet. Consequently, a lot of rules and laws apply to managing their farms. European, Belgian and Flemish legislation all have their say in this matter, which further complicates the farmers' businesses.
De Mestbank, a division of Vlaamse Landmaatschappij (or VLM) is a governmental institution that is responsible for the imposition and control of the legislation concerning the protection of water against nitrogen and phosphorus from agricultural source. She provides support for farmers and makes sure everyone abides by the rules. An important part of the rules stipulate how much and when Flemish farmers are allowed to fertilize their land.

How we did it

The legislation was already translated into a large infographic:

You can find all details on https://www.vlm.be/nl/SiteCollectionDocuments/Mestbank/Algemeen/Schema_uitrijregeling.pdf

To help farmers obey the rules, VLM decided they wanted to provide a simple but handy tool that applies the legislation to the farm owner’s personal situation. The goal was to provide him with an overview of when and under which conditions he is allowed to fertilize his land.


In a first step, VLM compiled all the laws and exceptions to them and knowledge of their experts into a document that could serve as a business analysis for the tool they had in mind. The tool would have to look good on both mobile and desktop devices as farmers are more IT-minded than one might assume.

A quick tour of the tool

Together with VLM’s IT experts we presented a few options for possible user interfaces and began making technology choices. We agreed that we would present the users with a few questions - type of farm, type of fertilizer, type of land - and analyse the answers to show them a calendar when and when not to fertilize their land.

You can have a go with the tool itself here: https://uitrijtool.vlm.be/


One of the challenges was that the system had to be suited for making adaptations in the future since these laws are inherent to change. So for the user interface, Angular’s component-based system was perfectly suited. This made it possible to have a modular system, allowing us to quickly write a few test tools on the side.  

One of the most useful for example, was a page that calculated all possible input permutations and the corresponding outputted calendars, showing the business analysts in a blink of an eye where their rules contained errors or missing data. 

For the backend system, a REST API was written, using Microsoft’s .NET Web API framework, that can process the input from the user. It then applies the rules to it and eventually returns a calendar that indicates when and under which conditions the user is allowed to fertilize their land.

We conceived a small domain specific language for modelling the rules allowing them to be rewritten in case of sudden changes to the laws. One of the benefits we immediately reaped from that approach was that the code was very readable, allowing us to work even closer with the testers and experts, as they could read the actual code we had written.

Here are some examples of this code:

if (!q.KunstMest())
    year.AddRule(7, day => day.NotSundays().NotHolidays());
if (q.TypeMest(2) && q.Gras())
    year.AddRule(6, day => day.Between("16/2", "15/8").NotBetween("1/9", "15/10"));
if (q.TypeMest(2) && !q.Focus() && q.Akker() && !q.ZwareKlei() && q.Nateelt() && q.NateeltSpecifiek() && q.InzaaidatumVoor1_9())
    year.AddRule(18, day => day.Between("1/6", "31/8", 
        Remarks.Add(new Remark(Constants.MAX_36_NA_OOGST).Replaces(Constants.TOT_OOGST))));
if (q.TypeMest(2) && !q.Focus() && q.Akker() && !q.ZwareKlei() && q.Nateelt() && q.InzaaidatumVoor1_8())
    year.AddRule(19, day => day.Between("16/2", "31/8", Remarks.ClearAll));

And on top of this, the test suite has also been written using fluent APIs, allowing very understandable test logic:

public void Scenario_6()
    var calendar =     CalendarFor(Scenario.NietFocus.Derogatie.Type3.GeenAttestLageN.Akker.GeenZwareKlei.HoofdteeltAndere.Nateelt.Andere.InzaaidatumTussen1_8En15_8.Result);
    calendar.Should().AllowPeriodExceptSundaysAndHolidays("16/2", "31/5").Which.Should().HaveNoRemarks();
    calendar.Should().AllowPeriodExceptSundaysAndHolidays("1/6", "31/8").Which.Should().HaveRemark(Constants.TOT_OOGST);
    calendar.Should().DenyPeriod("1/9", "15/2");


After only one week the tool has gotten quite some attention from the agricultural community.

We received 1381 requests and 990 unique visitors.

We received 1381 requests and 990 unique visitors.

Most users still use a desktop, but there is a significant mobile audience (20%).

Finally, of all page hits, about 1000 resulted in displaying the final calendar.

Are you looking to make legislation more actionable? Want to make your business rules more comprehensible and hands-on? Contact us to see what your business can do for your customers.

Stif Labarque is one of our digital workplace architects that develops, maintains and deploys numerous applications for our customers.

sharing is caring