GIS with Python: Introduction
and Practice
Bakht Ali
July 2025
GIS Python Libraries
• • geopandas - Handling vector data
(Shapefiles, GeoJSON)
• • shapely - Creating and manipulating
geometric shapes
• • fiona - Reading/writing spatial data formats
• • rasterio - Handling raster data
• • pyproj - Coordinate system transformations
• Example Q: Name two Python libraries used
for vector data processing in GIS.
Plotting Graphs in Python
• • Libraries: matplotlib, seaborn,
[Link]()
• • Example:
• import geopandas as gpd
• import [Link] as plt
• gdf = gpd.read_file('[Link]')
• [Link]()
• [Link]()
• Example Q: Which Python library is commonly
Reading CSV and JSON Files
• • Reading CSV:
• import pandas as pd
• df = pd.read_csv('[Link]')
• • Reading GeoJSON:
• import geopandas as gpd
• gdf = gpd.read_file('[Link]')
• Example Q: Which Python method is used to
read a `.csv` file?
Spatial Analysis and Buffering
• • Buffering example:
• gdf['buffered'] = [Link](100)
• • Other operations: overlay, clip, dissolve
• Example Q: What does the buffer() function
do in a GIS context?
Fiona API
• • Fiona is used to read/write spatial formats
like Shapefiles.
• • Example:
• import fiona
• with [Link]('[Link]') as file:
• print([Link])
• Example Q: What is the primary use of Fiona
in GIS Python scripting?
Creating Basic Geometries
• • Example using Shapely:
• from [Link] import Point,
LineString, Polygon
• point = Point(10, 20)
• line = LineString([(0, 0), (1, 1), (2, 2)])
• polygon = Polygon([(0, 0), (1, 1), (1, 0)])
• Example Q: Write code to create a Point
geometry at (10, 20).
Quiz / Recap
• 1. What is the use of geopandas in GIS
Python?
• 2. Which method is used to plot spatial data?
• 3. Define buffer operation with a code snippet.
• 4. How do you read a GeoJSON file?
• 5. Create a LineString geometry using Shapely.
Spatial Join and Overlay
• • Spatial join merges attributes based on
spatial relationship.
• • Example:
• gdf_joined = [Link](parcels, zones,
how='inner', predicate='intersects')
• • Overlay:
• gdf_overlay = [Link](layer1, layer2,
how='intersection')
• Example Q: What is the difference between
spatial join and overlay?
Reprojection and CRS Handling
• • Reproject data to a new coordinate
reference system (CRS):
• gdf = gdf.to_crs(epsg=32643)
• • Check CRS: [Link]
• Example Q: Why is it important to reproject
GIS data?
Reading Raster Data with Rasterio
• • Example:
• import rasterio
• with [Link]('[Link]') as src:
• arr = [Link](1)
• print([Link], [Link])
• • Useful for working with satellite imagery,
DEMs, etc.
• Example Q: What function is used to read
raster bands in Rasterio?
Exporting and Saving GeoData
• • Export GeoDataFrame to shapefile or
GeoJSON:
• gdf.to_file('[Link]')
• gdf.to_file('[Link]', driver='GeoJSON')
• • Export to CSV: gdf.to_csv('[Link]')
• Example Q: How do you save a GeoDataFrame
to a shapefile?
Folium for Web Mapping
• • Example map with markers:
• import folium
• m = [Link](location=[33.7, 73.1],
zoom_start=10)
• [Link]([33.7, 73.1],
popup='Islamabad').add_to(m)
• [Link]('[Link]')
• • Interactive maps with layers and tiles
• Example Q: Which Python library is used for