Chapter 1 — Spatial Data Introduction

GeoSense ✅
2 min readJan 4

Objects or entities in a GIS environment can be recorded in 2D or 3D. These spatial entities can be represented as a vector data model or a raster data model.

1.1 Vector Data

Vector features have three different geometric primitives: points, polylines and polygons.

a) Point

Load data points with geopandas and plot with matplotlib:

import geopandas as gpd
import matplotlib.pyplot as plt
from shapely.geometry import Point

d = {'name': ['Washington\n(38.90, -77.03)', 'Baltimore\n(39.29, -76.61)','Fredrick\n(39.41,-77.40)'],
'geometry': [Point(-77.036873,38.907192), Point(-76.612190,39.290386,), Point(-77.408456,39.412006)]}

gdf = gpd.GeoDataFrame(d, crs="EPSG:4326")
print(gdf)
                          name                    geometry
0 Washington\n(38.90, -77.03) POINT (-77.03687 38.90719)
1 Baltimore\n(39.29, -76.61) POINT (-76.61219 39.29039)
2 Fredrick\n(39.41,-77.40) POINT (-77.40846 39.41201)
plt.style.use('bmh') # better for plotting geometries vs general plots.

fig, ax = plt.subplots(figsize=(12, 6))
gdf.plot(ax=ax)
plt.ylim([38.8, 39.6])
plt.xlim([-77.5, -76.2])

for x, y, label in zip(gdf.geometry.x, gdf.geometry.y, gdf.name):
ax.annotate(label, xy=(x, y), xytext=(3, 3), textcoords="offset points")
plt.show()

b) Polylines

Load data polylines with geopandas, shapely and plot with matplotlib:

from shapely.geometry import LineString

d = {'name': ['Washington\n(38.90, -77.03)' ],
'geometry': [LineString([Point(-77.036873,38.907192), Point(-76.612190,39.290386,), Point(-77.408456,39.412006)])]}
gdf = gpd.GeoDataFrame(d, crs="EPSG:4326")
fig, ax = plt.subplots(figsize=(12, 6))
gdf.plot(ax=ax)

c) Polygons

Load data polygons with geopandas, shapely and plot with matplotlib:

from shapely.geometry import Polygon

d = {'name': ['Washington\n(38.90, -77.03)' ],
'geometry': [Polygon([(-77.036873,38.907192), (-76.612190,39.290386,)…
GeoSense ✅

🌏 Remote sensing | 🛰️ Geographic Information Systems (GIS) | ℹ️ https://www.tnmthai.com/medium