Search⌘ K
AI Features

Tabular Coordinates: GeoSeries and Geometry Collections

Explore how to spatialize tabular coordinate data by converting latitude and longitude into GeoSeries and GeoDataFrames using GeoPandas. Understand how to combine different geometries such as points and polygons into GeometryCollections for advanced geospatial analysis and visualization, including filtering and plotting techniques with real-world datasets.

Spatializing tabular coordinates

When working with points, it is common for our data to come in .csv files with geographic coordinates representing simple points. In such scenarios, we need to spatialize these coordinates in GeoPandas to create the corresponding Point geometries. For that, GeoPandas has a handy method called .points_from_xy. Let's see how it works.

widget
Python 3.8
import pandas as pd
# get the data. Note that pandas can read the data directly from the url
df = pd.read_csv('ozone_stations.csv')
# convert the dataframe to html format
print(df.head().to_html())

We can see that the last two columns, X and Y, are expressed in geographic coordinates (i.e., latitude and longitude, respectively). Now, let’s convert them to a GeoSeries and set it as a geometry in a GeoDataFrame.

The result of the points_from_xy() method is a GeoSeries object. In the next ...