You are on page 1of 11

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/367479097

Keyline Design: Efficient agricultural water management through algorithm-


based cultivation patterns

Conference Paper · January 2023

CITATIONS READS

0 421

1 author:

Diego Gil Cordeiro


Zurich University of Applied Sciences
2 PUBLICATIONS 1 CITATION

SEE PROFILE

All content following this page was uploaded by Diego Gil Cordeiro on 27 January 2023.

The user has requested enhancement of the downloaded file.


Keyline Design: Efficient agricultural water management through
algorithm-based cultivation patterns

Gil Cordeiro, Diego *1


1
Institute of Natural Resource Sciences, Zurich University of Applied Sciences, ZHAW

January 22, 2023

Summary
Agricultural production systems are increasingly impacted by the effects of global climate change.
This study investigates an aspect of the agricultural cultivation practice known as Keyline Design,
which is currently being researched as a promising alternative to conventional cultivation methods.
As a contribution to automation of Keyline practices, a modular tool was developed by integrating a
line simplification algorithm into a Python script. This tool allows for the reduction of contour line
complexity to create a basis for Keyline cultivation patterns in the context of a broader automation
scheme.

KEYWORDS: Keyline Design, Ramer Douglas Peucker Algorithm, Polyline Simplification,


Cultivation Patterns, Water Management

1. Introduction

Agricultural cultivation patterns dictate the directions in which cultivation operations, such as tillage
and planting of permanent crops and trees, are performed. Conventional agriculture often employs a
standard grid layout for cultivation patterns, primarily for practical and habitual reasons. However, this
type of layout does not take into account the topographic properties of the landscape, resulting in water
management related negative side effects. In response to irregular weather patterns in Australia, an
alternative concept to conventional cultivation practices was developed in the late 1940s by the late
Australian engineer and geologist P. A. Yeomans. This concept, known as Keyline Design, aims to
increase the regeneration of topsoil and improve water use efficiency within agricultural production
systems.

1.1. Keyline Design

The focus of Keyline Design as a water management system is to slow down surface runoff of water
and redistribute it to the ridges of the landscape, which are naturally more susceptible to drought
(Yeomans, 1954). This is achieved by designing a cultivation pattern that is aligned with the
geomorphological features of the landscape, while still allowing for mechanical cultivation of
agricultural fields. The latter requires a simple and mostly uniform cultivation pattern with minimal
directional changes and a low level of complexity. The challenge in designing an optimal Keyline
cultivation pattern for any type of landscape lies in finding an appropriate balance between usability
and effectiveness in water management, based on the characteristics of the project (Pavlov, 2015).

1.2. Adapted method for creating Keyline patterns

While still effective in rolling hills † landscapes – like the ones predominant in Australia, the home of

*
gilcodie@students.zhaw.ch

Terrain of undulating gently sloped low hills.

Page | 1
inventor P. A. Yeomans – the original method for creating Keyline cultivation patterns as described in
“The Keyline plan” (Yeomans, 1954) and “The challenge of landscape” (Yeomans, 1958) has been
reshaped and simplified over the past few decades, resulting in an adapted method that is easier to
implement (Gil Cordeiro, 2023). This newly adapted method heavily relies on the use of digital
elevation models and specialized cartography software such as CAD ‡ or GIS §. However, there is still
much room for improvement in terms of ensuring maximum water management efficiency while
maintaining usability and practicality for cultivation purposes.

1.3. Development process of a Keyline layout

The Keyline layout is created by copying a baseline in a parallel manner throughout a predefined area.
The baseline represents a simplified contour line, ideally positioned in the middle section of a field, and
shaped in accordance with the geometric Keyline principles, namely downslope from valley to ridge
and upslope from ridge to valley.

First, the extent of the area is defined (Step 1). Secondly, a suitable contour line in the middle section
of the field is selected (Step 2) which will act as the baseline for the pattern. After its simplification
(Step 3), the new polyline must then be reshaped in order to achieve conformity with the geometric
Keyline principles (Step 4). After copying the baseline throughout the entire field (Step 5), the layout’s
general congruence with the topographic property of the landscape is analyzed (Step 6).

In case of a strong discrepancy between the resulting pattern and the landscape’s properties, the original
keyline is reshaped and subsequently copied again throughout the entire field (Option a), thereby
recreating the pattern. If the discrepancy only affects a certain area of the field, a new pattern section
can be introduced into the field’s Keyline layout (Option b1) or depending on the size and location of
the anomaly, the diverging area can also be excluded entirely from the field area (Option b2). If the
discrepancy only affects a small area, the disruption in the layout can be ignored in sake of uniformity
in the resulting layout (Option c1). The described process will be repeated in an iterative manner until
there is no room for further improvement (Option d or c1). All the described steps are displayed in the
following flowchart for a better overview and understanding of the process (Figure 1).


Computer-aided design
§
Geographical information system

Page | 2
Figure 1 Flowchart displaying the overall development process for Keyline layouts.

1.4. Objectives

The objective of this study is to contribute to the development of an efficient, algorithm-based method
for creating Keyline cultivation patterns. This paper provides a visual overview of the steps involved
in the creation process of Keyline patterns and aims to develop an algorithm-based approach for the
simplification of selected contour lines (Step 3 in Figure 1) that enables integration with databases and
GIS through a Python module.

Page | 3
2. Study area and source of data

The study area encompasses the perimeter of the farm Grüezi Garten located in Zug, Switzerland ** and
has been chosen due to the already available Keyline model for this farm. The digital elevation model
used in this study is obtained from the Swiss Federal Office of Topography
(https://www.swisstopo.admin.ch/en/geodata/height/alti3d.html).

3. Methods

As a first step, the contour lines were exported from ESRI ArcGIS into a PostgreSQL Geodatabase as
Shapefiles (Step 1) and converted afterward to the Dataframe format (Step 2). The simplification of the
contour line was then achieved by executing a line simplification algorithm (Step 3). After
simplification of the polyline, the Dataframe was converted back to Shapefile format (Step 4) and
exported into the DB (Step 5) to be imported back into the GIS application (Step 6).

Figure 2 Flowchart overview of the contour line simplification process. Steps 1 and 6 are executed manually
through GIS, while steps 2 – 5 are executed through a Python script.

**
WGS84 Coordinates in decimal degrees: 8.5541288°E, 47.1614840°N.

Page | 4
3.1. Datatransfer between between GIS and Database

A connection between ESRI ArcGIS Pro †† and the PostgreSQL database was established and utilized
for the data transfer. The export of the contour lines was achieved by storing and exporting them as
shapefiles with the native tool “Export features”.

3.2. Database

The database used for storing data was hosted locally with PostgreSQL ‡‡ and the spatial database
extender PostGIS §§ was installed for geographic data support. In order to enable full functionality of
the interface, a new schema on the database had to be created with an identical name as the username
utilized to connect ArcGIS to the database.

3.3. Simplification algorithm

The Ramer–Douglas–Peucker (RDP) algorithm (Douglas & Peucker, 1973; Ramer, 1972) was used for
the polyline simplification of the contour lines. It is an algorithm for reducing the number of points in
a curve that is approximated by a series of points. The polyline is considered as a whole object and the
algorithm proceeds to finer approximations. To do this, the output sequence is suitably divided into two
sections, which then in turn run through the algorithm in a recursive manner. The algorithm thus
implements an approach based on the divide-and-conquer principle. The algorithm works as follows:

Given is the starting curve C as an ordered set of n points

𝐶𝐶 = (𝑃𝑃1 , 𝑃𝑃2 , 𝑃𝑃3 , ⋯ , 𝑃𝑃𝑛𝑛 ) (3.1)

and the distance dimension (tolerance) ε with

ε > 0. (3.2)

The first approximation of C is the line segment 𝑃𝑃1 P𝑛𝑛 . The algorithm marks the first and last point to
be kept. Now all n – 2 inner points are looked at, to find the point 𝑃𝑃𝑚𝑚 that is furthest from that line
segment with

𝑑𝑑𝑚𝑚𝑚𝑚𝑚𝑚 = max 𝑑𝑑(𝑃𝑃𝑖𝑖 , 𝑃𝑃1 P𝑛𝑛 ). (3.3)


𝑖𝑖 = 2 ⋯ 𝑛𝑛 − 1

If 𝑑𝑑𝑚𝑚𝑚𝑚𝑚𝑚 is within the tolerance

𝑑𝑑𝑚𝑚𝑚𝑚𝑚𝑚 ≤ ε (3.4)

then the simplification is finished, and all inner points can be discarded without the simplified curve
being worse than ε. Else, 𝑃𝑃𝑚𝑚 must be kept and the algorithm recursivly processes the new parts

𝐶𝐶1 = (𝑃𝑃1 , ⋯ , 𝑃𝑃𝑚𝑚 ) (3.5)


𝐶𝐶2 = (𝑃𝑃𝑚𝑚 , ⋯ , 𝑃𝑃𝑛𝑛 ).

Those parts are then again processed recursively. The result of the algorithm is the line defined by the
sequence of non-rejected points.

††
Version 3.0.3
‡‡
Version 1.5.1
§§
Version 3.2.1

Page | 5
3.4. Python modular requirements

A readily available Python/NumPy implementation of the RDP algorithm was used, in order to run it
in Jupyter Lab *** by installing the Python package rdp (Hirschmann, 2022).

Apart from rdp, the following PIP-packages have been used in this paper and are listed in Table 1 with
their version numbers. The list can be copied into a text file and all required PIP-packages conveniently
installed with the following command:

pip install -r folder\requirements.txt (4.1)

Table 1 List of required PIP-packages to run the python script.


attrs==22.2.0 certifi==2022.12.7 click==8.1.3 click-plugins==1.1.1
cligj==0.7.2 Fiona==1.8.22 GeoAlchemy2==0.13.0 geopandas==0.12.2
greenlet==2.0.1 munch==2.5.0 numpy==1.24.1 packaging==23.0
pandas==1.5.2 psycopg2- pyproj==3.4.1 python-
binary==2.9.5 dateutil==2.8.2
pytz==2022.7.1 rdp==0.8 shapely==2.0.0 six==1.16.0
SQLAlchemy==1.4.46 tqdm==4.64.1

3.5. Python source code

The entire source code of the Python script can be found in the appendix. The functionality of each line
of the code is described as follows.

First the required Python modules ††† are imported (Code 1, 1–6) and then the credentials for the
database are defined (Code 1, 10–14), as well as the desired tolerance value ε (Code 1, 8) as displayed
in Formula 3.2.

Code 1 First section of contour line simplification script

***
Version 2.2.10
†††
A module corresponds to a .py file containing Python code.

Page | 6
The function simplify is defined in the next section (Code 2, 17–22), and a geo data frame created
through geopandas (Code 2, 22) with the given database location as the data source (Code 2, 19–21).

Code 2 Second section of contour line simplification script

In the next section, an empty list is created to store all new geometries (Code 3,24). Afterwards a for
loop is created and the progress visualized in an iterable progress bar meter (Code 3, 25).

Code 3 Third section of contour line simplification script

A specific geometry is selected (Code 4, 23) and an array created (Code 4, 24) to make the data frame
compatible with the rdp line simplification algorithm which is then executed (Code 4, 25). Then the
geometric format of the object is defined (Code 4, 26) and a list with the already simplified geometries
created (Code 4, 27)

Code 4 Fourth section of contour line simplification script

The data is exported back to the defined table of the database and existing entries overwritten (Code 5,
34-36).

Code 5 Fifth section of contour line simplification script

As a last step, for allowing the code to be executed as a script or from other code, a conditional block
is added (Code 6, 38-40).

Code 6 Sixth section of contour line simplification script

3.6. Results analysis

The simplification output was analyzed by the number of remaining vertices with the ArcGIS native
tool “Feature Vertices to Points” as well as by visual comparison with the original contour line.

Page | 7
4. Results

When choosing an ε value of 0.5, a total amount of 30 vertices remained (Figure 4), from originally
1635 (Figure 3). With an ε value of 5, the number of vertices was reduced to 9 (Figure 5).

Figure 3 Original contour line (highlighted) with 1635 vertices.

Figure 4 Contour line simplified (green line) with ε value of 0.5. 30 vertices (red dots) remained.

Figure 5 Contour line simplified (green line) with ε value of 5. 9 vertices (red dots) remained.

Page | 8
5. Discussion

The outputs of this research have provided systematic insight into the creation process of Keyline
layouts, as well as a general outline of the potential for automation. As a novel approach, a contribution
was made to an algorithm-based method for creating Keyline layouts by integrating an existing line
simplification algorithm into a modular Python script, which allows for a geospatial database to act as
its data source and storage medium.

The Python script's variable input ε determines the degree to which the line simplification algorithm
will run. In the results displayed in Figure 5, it is clearly visible that the ε value of 5 led to a strong
reduction in the number of indices, without abandoning the original contour line's general shape.
Whereas in Figure 4, the ε value of 0.5 resulted in a more complex line structure with an overabundance
of data points. Therefore, Figure 5 could act as a suitable starting point for the Keyline pattern's
baseline.

Due to the assumption that the ideal ε value depends on the topographic characteristics of the selected
area, future research should further investigate whether the most suitable ε value can be derived in an
automated manner. A possible approach would be analyzing the percentage of vertices that remain in
the center area of major topographic formations, such as ridgelines and valleys, throughout the entire
pattern, to measure the suitability of the selected ε value.

6. Biography

Diego Gil Cordeiro is an environmental engineering student in the final semester of his bachelor's
degree program, with a focus on agricultural practices. He holds a Federal Diploma of Vocational
Education and Training in Information Technology and has over 10 years of professional experience in
this field. He wrote his bachelor thesis, "Keyline design as a water management strategy in agriculture,"
on the concept of Keyline Design and the different methods of Keyline pattern development. This paper
represents a continuation of where the bachelor thesis left off, laying the groundwork for the automation
process for creating Keyline layouts.

References

Douglas, D. H., & Peucker, T. K. (1973). Algorithms for the reduction of the number of points required
to represent a digitized line or its caricature. Cartographica: The International Journal for Geographic
Information and Geovisualization, 10(2), 112–122. https://doi.org/10.3138/FM57-6770-U75U-7727

Gil Cordeiro, D. (2023). Keyline-Design als Wassermanagementstrategie in der Landwirtschaft.


Zürcher Hochschule für Angewandte Wissenschaften ZHAW.

Hirschmann, F. (2022). Ramer-Douglas-Peucker Algorithm [Python].


https://github.com/fhirschmann/rdp

Pavlov, G. (2015). Understanding the Application of Keyline Geometry. http://permatronc.ressources-


permaculture.fr/Ajoute-des-fichiers-
ici/EBOOK_Understanding_the_Application_of_Keyline_Geometry_%5BENGLISH%5D.pdf

Ramer, U. (1972). An iterative procedure for the polygonal approximation of plane curves. Computer
Graphics and Image Processing, 1(3), 244–256. https://doi.org/10.1016/S0146-664X(72)80017-0

Yeomans, P. A. (1954). The Keyline Plan. P. A. Yeomans.

Yeomans, P. A. (1958). The challenge of landscape: The development and practice of keyline (First
Edition). Keyline Pub. Pty.

Page | 9
Appendix

Source code of the python contour line simplification script.

import geopandas as gpd

from rdp import rdp

from shapely.geometry import LineString

import numpy as np

from tqdm import tqdm

from sqlalchemy import create_engine

epsilon = 5

username = ''

password = ''

database = ''

server = ''

port = ''

def simplify(epsilon,str_engine):

engine = create_engine(str_engine)

query = 'SELECT * FROM mytable'

column_name = 'shape'

gdf = gpd.read_postgis(query,engine,geom_col=column_name)

geoms = []

for i in tqdm(gdf.index):

geom = gdf['shape'][i]

g = np.array([[x,y] for x,y in zip(geom.xy[0],geom.xy[1])])

g = rdp(g,epsilon=epsilon)

geom2 = LineString(g)

geoms.append(geom2)

gdf['shape'] = geoms

engine = create_engine(str_engine)

output_table_name = 'mytable'

gdf.to_postgis(output_table_name, engine,if_exists='replace')

if __name__=="__main__":

str_engine = f"postgresql://{username}:{password}@{server}:{port}/{database}"

simplify(epsilon,str_engine)

View publication stats

You might also like