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

Lecture Note - GIS 821 - Programming in Geoinformatics - Weeks 3

The lecture notes for GIS 821 cover programming in geoinformatics, focusing on conditional statements, loops, file I/O, and geospatial data handling. Key objectives include processing geospatial data using Python, reading/writing files, and manipulating vector/raster data with libraries like GDAL and GeoPandas. Practical exercises involve classifying temperature data, converting CSV files, and visualizing geospatial data.

Uploaded by

Akeredolu Joshua
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)
7 views5 pages

Lecture Note - GIS 821 - Programming in Geoinformatics - Weeks 3

The lecture notes for GIS 821 cover programming in geoinformatics, focusing on conditional statements, loops, file I/O, and geospatial data handling. Key objectives include processing geospatial data using Python, reading/writing files, and manipulating vector/raster data with libraries like GDAL and GeoPandas. Practical exercises involve classifying temperature data, converting CSV files, and visualizing geospatial data.

Uploaded by

Akeredolu Joshua
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

Lecture Note: GIS 821 - Programming in Geoinformatics

Target: Conditional Statements, Loops, File I/O, Geospatial Data


Handling

Week 3: Conditional Statements, Loops, and Data Structures


Objective: Use conditional logic, loops, and lists to process geospatial data.
1. Conditional Statements & Branching
Python Example:

Practical Exercise:
⚫ Write a script to classify temperature data (e.g., "Hot", "Moderate",
"Cold") using thresholds.
2. Loops & Repetition
Python Example (For Loop):

Practical Exercise:
⚫ Use a loop to iterate over a list of coordinates and filter latitudes above
30 degrees.

3. Data in Lists/Arrays
Python (List Operations):

Week 4: File I/O, Libraries, and Scripts


Objective: Read/write files, import libraries, and organize code into
reusable scripts.

1. File Input/Output
Python Example (Read/Write CSV):

Practical Exercise:
⚫ Convert a CSV of river coordinates to a text file using Python.
2. Libraries and Scripts
Python Script Example (custom_geo.py):
```python
# Import custom functions
def calculate_distance(lat1, lon1, lat2, lon2):
# Haversine formula implementation
return distance

# Save as custom_geo.py and import in another script:


from custom_geo import calculate_distance
```
Week 5: Geospatial Data Handling & Processing
Objective: Manipulate vector/raster data using Python (GDAL, Pandas).

1. Geospatial Data Formats


- Vector: Shapefiles (points, lines, polygons).
- Raster: GeoTIFF, ASCII grids.
- Structured Data: GeoJSON, CSV with coordinates.

2. Loading & Visualizing Data


Python Example (Shapefile with GeoPandas):
```python
import geopandas as gpd

# Load shapefile
gdf = gpd.read_file('roads.shp')
print(gdf.head())

# Plot
gdf.plot(color='blue', edgecolor='black')
```
3. Data Conversion & Processing
Python (CSV to Shapefile):
```python
import geopandas as gpd
from geopandas import GeoDataFrame
from shapely.geometry import Point

# Read CSV
data = pd.read_csv('cities.csv')

# Create geometry
geometry = [Point(xy) for xy in zip(data.lon, data.lat)]
gdf = GeoDataFrame(data, geometry=geometry, crs="EPSG:4326")

# Save as shapefile
gdf.to_file('cities.shp')
```
Practical Exercises
1. Python:
- Load a GeoTIFF using GDAL, extract metadata, and convert it to a
CSV of elevation values.
- Use Pandas to clean a CSV with missing geospatial values.

Next Steps:
- Practice with real-world datasets (e.g., Natural Earth
(https://www.naturalearthdata.com/)).
Resources:
- GeoPandas Documentation (https://geopandas.org/)

You might also like