0% found this document useful (0 votes)
16 views35 pages

Python Programming for Geomatics

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views35 pages

Python Programming for Geomatics

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PROGRAMMING Lecturer: K. N.

MATINGO
FOR GEOMATICS
matingok@[Link]

APPLICATIONS
HSVG245

GOAL OF THE
MODULE
What is expected of the student at the end of the
module HSVG245

- Proficiency in Python Programming skills


- Understanding of Spatial data handling
- Upskill in Spatial
data visualisation and
presentation
- Competence in Spatial data analysis
- Ability to automate geomatics tasks
- Proficiency in version control

HSVG245 - Programming for Geomatics Applications 2

COURSE OUTLINE
1. Computer Programming Paradigms

2. Introducing Object-Oriented Programming

(OOP)

3. Spatial Databases and Database Design

4. Spatial Data Queries, Analysis and


Processing
5. Version Control with Git and Github

HSVG245 - Programming for Geomatics Applications 3


COMPUTER
PROGRAMMIN
G
PARADIGM
S 4

• Introducing Programming Paradigms •


• Pseudocode
Imperative programming

• Declarative programming

• Algorithm design process LECTURE OUTLINE


• Flowcharts
HSVG245 - Programming for Geomatics Applications 5

INTRODUCTION TO PROGRAMMING PARADIGMS


• A programming paradigm is a “way” (style; pattern) of programming • It
should not be dependent on the programming language used; although
some languages are inherently classified according to paradigms •
Paradigms are not meant to be mutually exclusive; a single program can
feature multiple paradigms!
• Some paradigms are concerned mainly with implications for the
execution model e.g., allowing side effects
• Other paradigms are concerned mainly with the way that code is
organized e.g., grouping code into units
• Others are concerned mainly with the style of syntax and grammar

HSVG245 - Programming for Geomatics Applications 6

PROGRAMMING PARADIGMS (CONT’D)


HSVG245 - Programming for Geomatics Applications 7

IMPERATIVE PROGRAMMING
• It is a style of programming which expresses the flow of
computation step by step. Each step changesthe state of the
computation.
• Here the focus is on how a computation should be done. •
Control flow is explicit, programmer defines the sequence of
operationsto get the desired result.

HSVG245 - Programming for Geomatics Applications 8

DECLARATIVE PROGRAMMING
• It is a style of programming which expresses only the logic of
computation without focus on the flow of computation • Here
the focus is on what needs to be done i.e., how the desired
result should look like, rather than how it should be done
• Control flow is implicit, programmer only states the properties
of the desired result. The engine which interprets the code
just givesthe desired information using whatever approach of
execution is necessary

HSVG245 - Programming for Geomatics Applications 9

IMPERATIVE EXAMPLES
• Procedural is programming which uses sub-routines (i.e. a
series ofsequential computationalsteps) step by step. Solves
the problem by breaking it down into variables, data
structures and sub-routines.

• Object Oriented is programming which breaks down


problemsinto ‘objects’ with a state and methodsto modify the
state and behaviour
HSVG245 - Programming for Geomatics Applications 10

DECLARATIVE EXAMPLES
• Databases(e.g. SQL)

• Logic a.k.a rule-based is programming by specifying a set of


facts and rules. Here the desired result is declared as the
answer to a question about a system of facts and rules.

• Functional is programming with the use of function calls. The


result is obtained from a series of function application.
HSVG245 - Programming for Geomatics Applications 11

WHERE DOESPYTHON FIT IN?


• Rather than enforcing use of a particular coding style, it lets more
advanced developers use the style they feel is best suited to
solving a particular problem.
• With Python your code can follow any of the following three design
paradigms:
• Functional
• OOP
• Procedural
• We’ll have some examples designed to compute the sum of the
following list:
my_list = [1, 2, 3, 4, 5]
HSVG245 - Programming for Geomatics Applications 12
CODE EXAMPLES:
FUNCTIONAL • Every statement is
treated
as a mathematical
equation and any forms
of state or mutable data
are avoided
• The approach lendsitself
well to parallel processing
because there is no state
to consider
• Useful for recursion
HSVG245 - Programming for Geomatics Applications 13

CODE EXAMPLES:
PROCEDURAL • Tasks are treated as step- by-step iterations

where common tasks are placed in functions


that are

• ‘called’ as needed.

• This coding style favors iteration,


sequencing, selection, and
modularization

• 11
HSVG245 - Programming for Geomatics Applications 14

CODE EXAMPLES: OOP


• Here, create_sum is an
instance of ChangeList.
• The inner workings of
ChangeList don’t matter
to the user.
• What matters is that you
can create an instance
using a list and then call
the do_add() method to
output the sum
HSVG245 - Programming for Geomatics Applications 15

ALGORITHMS

• In mathematics and computer science, an algorithm is an


effective method expressed as a finite list of
well-defined instructionsfor calculating a function.
• Algorithms are used for calculation, data processing, and
automated reasoning.
• Starting from an initial state and initial input, the instructions
describe a computation that, when executed, will proceed
through a finite number of well-defined successive states,
eventually producing output and terminating at a final
ending state

HSVG245 - Programming for Geomatics Applications 16

ALGORITHM DESIGN

• Consider a simple •

An example code:-
program to add 2
numbers.
• An algorithm to add two
numbers would be:-

Start the program


Enter 2 numbers (A and Stop the program
B)

Calculate sum using:


������ = �� + ��

Display the result


HSVG245 - Programming for Geomatics Applications 17

FLOWCHARTS
• A flowchart is a type of diagram that represents an algorithm or
process. This diagrammatic representation gives a step-by-step
solution to a given problem.

• Data flows are not typically represented in a flowchart, in


contrast with data flow diagrams; rather, they are implied by
the sequencing of operations.

• Flowcharts are used in analyzing, designing, documenting or


managing a process or program in various fields.

HSVG245 - Programming for Geomatics Applications 18

FLOWCHART SYMBOLS

• Terminal
• An oval which shows the beginning or end of a program(algorithm)
• The oval can be used with labels like START, BEGIN, EXIT, END,
RETURN etc.
END

START

BEGIN EXIT

HSVG245 - Programming for Geomatics Applications 19

FLOWCHART SYMBOLS

• Arrow
• Shows the direction of flow of the program (unidirectional) •
Flowcharts are usually drawn from top to bottom or left to right

HSVG245 - Programming for Geomatics Applications 20

FLOWCHART SYMBOLS

• Process
• A rectangle showing a process/task/operation.
• The text phrase used for labelling should always contain a verb
Calculate the angle

Check the order

Capitalize the name Insert the address

HSVG245 - Programming for Geomatics Applications 21

FLOWCHART SYMBOLS

• Decision
• A diamond which is usually phrased as a question.
• The answer to the question will determine the direction (arrow) to
follow to the next step.

No Yes Cash Ecocash


What is the method

of payment? Is it raining?

Zipit
HSVG245 - Programming for Geomatics Applications 22

FLOWCHART SYMBOLS

• Input/Output
• A parallelogram showing either input or output data.
• The data can be text, file, audio, visual etc.
Buffer
Coordinate file in CSV polygon as
Image file in shapefile
PNG
HSVG245 - Programming for Geomatics Applications 23
Example flowchart for a Hospital Management System
HSVG245 - Programming for Geomatics Applications 24

PSEUDOCODE not associated with any


specific programming
• Pseudocode is the plain English language.
representation of a computer •It is not a programming
language. •It cannot be

Some important points: executed or compiled by any

program or algorithm, which compiler, interpreter or


specifies the flow and assembler.
operation of the program.
• It is generally used to •Unlike actual code, it does not
represent the structural follow a strict structure or
flow of a program, and it is
syntax.

HSVG245 - Programming for Geomatics Applications 25

PSEUDOCODEEXAMPLE1

• Let’s refer to the previous example of the sum


algorithm • Appropriate pseudocode for the program
would be written as:

Start Program
Enter two numbers, A
and B Add the numbers
together Print Sum
End Program
HSVG245 - Programming for Geomatics Applications 26

PSEUDOCODEEXAMPLE2

• Another example is one for a program to compute the


perimeter of a rectangle:
Enter length, l
Enter width, w
Compute Perimeter = 2*l + 2*w
Display Perimeter of the rectangle

• Remember Pseudocode can be written how you want. Just


keep it simple and not language-specific!
HSVG245 - Programming for Geomatics Applications 27

PSEUDOCODE BEST PRACTICES


• Pseudocode does not follow a standard way of being
written. • However, there are some standard conventionsthat
every programmer follows while writing one:
1. Use capital words for reserved keywords, e.g., if writing
IF…ELSE statements make sure IF and ELSE are in upper case. 2.
Write only one statement per line.
3. Use indentation for the block body. It keeps the body of every
component isolated and will indicate that those pieces of
pseudocode go under a less intended section.
4. Be specific while writing a statement, use plain English to
provide a particular description.
HSVG245 - Programming for Geomatics Applications 28

PSEUDOCODEEXAMPLE3

• Another example using IF ELSE


statements: age = INPUT : “Enter Your age”
IF age is equal to 18 THEN
PRINT “under check”
ELSE IF age is greater than 18
PRINT “Give entry”
ELSE
PRINT “under age”
ENDIF
HSVG245 - Programming for Geomatics Applications 29

SUMMARY
• We looked at the different programming paradigms, and
which ones can be implemented in Python.
• Choice of paradigm is up to the programmer and usually
depends on the problem being solved.
• Flowcharts and Pseudocode are effective toolsto communicate
the algorithm design process
• Whichever design tool, whichever paradigm or whichever
programming language is used, commenting (and
documentation) is essential and it completesthe algorithm
design process.
HSVG245 - Programming for Geomatics Applications 30

ASSIGNMENT ONE
You’ve been tasked to develop systems that perform basic survey
operations by a client in the geomatics industry. The application consists of
two tools which:
- Computes a Join
- Computes a Polar

As the programmer, you are required to produce the following:


1. Flowcharts to outline how each program will work
2. Pseudocode for each program
3. Basic Python code for each tool.

**All code is supposed to be submitted via a GitHub Repository.


HSVG245 - Programming for Geomatics Applications 31

You might also like