0% found this document useful (0 votes)
8 views5 pages

Midterm Dennis

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)
8 views5 pages

Midterm Dennis

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
You are on page 1/ 5

THE COPPERBELT UNIVERSITY

SCHOOL OF MINES AND MINERAL SCIENCES


GEOMATICS DEPARTMENT
MID TERM EXAMINATIONS
TAKE HOME ASSESSMENT

NAME: DENNIS MWILA CHULU

SIN: 22107409

COURSE CODE : GE 360

COURSE NAME : COMPUTING FOR GEOMATICS

PROGRAMME : BACHELORS OF ENGINEERING IN GEOMATICS ENGINEERING

LECTURER : EB

DUE DATE: 9TH AUGUST, 2024.

1|Page
QUESTION 1

a. Python is a popular programming language known for its simplicity and readability. It's like giving clear
instructions to a computer to perform tasks like solving problems, managing data, and creating websites.
Python is easy to learn for beginners and powerful enough for professionals to build complex
applications.
b. Python is incredibly versatile and can be used to build a wide range of applications, such as:
• Web Development: Creating websites and web applications.
• Data Analysis: Analyzing large datasets and creating visual reports.
• Machine Learning: Building predictive models and AI applications.
• Automation: Automating repetitive tasks.
• Software Development: Creating standalone software applications.
• Game Development: Developing games
c. Difference between Local and Global Variables

Local Variables: Variables defined within a function and accessible only within that function.

Example of a Local variable:

def my_function():
local_var = 20 # This is a local variable
print(local_var)
my_function()
# local_var is not accessible here

Global Variables: Variables defined outside of functions and accessible from any function within
the same module.
Example of Global variables:

global_var = 8 # This is a global variable

def my_function():
print(global_var)

my_function()
# global_var is accessible here

2|Page
d. 4 python input data types and their examples
• Integer (int): Whole numbers (e.g., 5, 100, -20).
• Float (float): Numbers with decimal points (e.g., 3.14, 0.001, -7.5).
• String (str): Sequences of characters (e.g., "Hello, world!", 'Python is great').
• Boolean (bool): True or False values (e.g., True, False).

e. Below is a code showing a List of Geoinformatics specializations. It is Showing us how we can retrieve
a sub list or elements from our list using indexes.

# Creating a list of geoinformatics specializations


geoinformatics_specializations = [
"Remote Sensing",
"Geographic Information Systems (GIS)",
"Cartography",
"Spatial Data Analysis",
"Geostatistics",
"Geodesy",
"Surveying",
"Photogrammetry"
]

# Retrieving a sublist using indexes


# For example, retrieving the first three specializations
sublist = geoinformatics_specializations[0:3]
print(sublist) # Output: ['Remote Sensing', 'Geographic Information Systems (GIS)',
'Cartography']

# Retrieving specific elements using indexes


# For example, the second and fourth specializations
element_2 = geoinformatics_specializations[1]
element_4 = geoinformatics_specializations[3]
print(element_2) # Output: Geographic Information Systems (GIS)
print(element_4) # Output: Spatial Data Analysis

3|Page
QUESTION 2

a. Problems solved by each of the following Python Libraries.


i. GDAL: GDAL acts as a translator between different geospatial data formats, allowing developers to
work with data from various sources without worrying about the underlying file structures. It
supports raster (e.g., GeoTIFF, JPEG2000) and vector (e.g., Shapefile, GeoJSON) formats and
provides functions for tasks like raster resampling, vector clipping, and georeferencing.

ii. FIONA: Fiona is built on top of GDAL, focusing specifically on vector data. It provides a higher-
level interface for interacting with vector datasets, making it easier to read and write features,
attributes, and geometry. Fiona supports a wide range of vector formats and offers features like
spatial indexing and query capabilities.

iii. SHAPELY: Shapely is a pure Python library for performing geometric operations on planar
geometries. It offers functions for creating, manipulating, and analyzing geometric objects like
points, lines, polygons, and multi-geometries. Shapely can be used for tasks such as calculating
distances, intersections, unions, and buffers between geometric features.

iv. GEOPANDAS: GeoPandas combines the power of pandas for data manipulation and analysis with
geospatial capabilities provided by Shapely and GDAL. It extends pandas DataFrames to include a
geometry column, allowing you to store and manipulate geospatial data within a familiar data
structure. GeoPandas provides functions for spatial joins, overlays, and visualizations of geospatial
data.
b. Pseudocode for Converting Angle to Decimal Degrees

#user input
d = int(input("Enter d: "))
m = int(input("Enter m: "))
s = float(input("Enter s: "))

def deg_min_sec_to_decimal(deg, min, sec):


decimal_m = min / 60
decimal_s = sec / 3600

4|Page
decimal_deg = deg + decimal_m + decimal_s
return decimal_d

decimal_d = deg_min_sec_to_decimal(d, m, s)
print(f"The angle in decimal deg is: {decimal_d:.5f}")

c. Python Function for Months in Words

def month_in_words(myNum):
months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November",
"December"]
if 1 <= myNum <= 12:
return months[number - 1]
else:
return "Invalid Month"

d. Python Function for Divisibility by 3 or 7

def divisible_by_3_or_7(number):
if number % 3 == 0 or number % 7 == 0:
return True
else:
return False

5|Page

You might also like