Chapter 2 — Practice Spatial Vector Data with GeoPandas

GeoSense ✅
2 min readJan 6

GeoPandas library is to make working with spatial data in python easier that combining the capabilities of pandas and shapely, providing spatial operations in pandas and a high-level interface to multiple geometries to shapely.

2.1 Data Structures

GeoPandas implements two main data structures, a GeoSeries and a GeoDataFrame. These are subclasses of pandas Series and DataFrame, respectively.

a) GeoSeries

A GeoSeries is a vector where each entry in the vector is a set of shapes corresponding to one observation.

Geopandas has three basic classes of geometric objects (which are actually shapely objects): Points / Multi-Points, Lines / Multi-Lines, Polygons / Multi-Polygons.

Examples: Points, Lines and Polygons

import geopandas
from shapely.geometry import Point
s = geopandas.GeoSeries([Point(1, 1), Point(2, 2), Point(3, 3)])
0    POINT (1.00000 1.00000)
1 POINT (2.00000 2.00000)
2 POINT (3.00000 3.00000)
dtype: geometry
from shapely.geometry import LineString
l= geopandas.GeoSeries([LineString([Point(-77.036873,38.907192), Point(-76.612190,39.290386,), Point(-77.408456,39.412006)])])
0    LINESTRING (-77.03687 38.90719, -76.61219 39.2...
dtype: geometry
from shapely.geometry import Polygon
p= geopandas.GeoSeries([Polygon([(-77.036873,38.907192), (-76.612190,39.290386,), (-77.408456,39.412006)])])
0    POLYGON ((-77.03687 38.90719, -76.61219 39.290...
dtype: geometry

b) GeoDataFrame

A GeoDataFrame is a tabular data structure that contains a GeoSeries.

A GeoDataFrame may also contain other columns with geometrical (shapely) objects, but only one column can be the active geometry at a time. To change which column is the active geometry column, use the GeoDataFrame.set_geometry() method.


world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
 pop_est      continent                      name iso_a3  gdp_md_est  \
0 889953.0 Oceania Fiji FJI 5496
1 58005463.0 Africa Tanzania TZA 63177
2 603253.0…
GeoSense ✅

🌏 Remote sensing | 🛰️ Geographic Information Systems (GIS) | ℹ️

Recommended from Medium


See more recommendations