...

/

Tabular Coordinates: GeoSeries and Geometry Collections

Tabular Coordinates: GeoSeries and Geometry Collections

Learn how to transform tabular coordinates into a GeoSeries and how to combine different geometries using Geometry Collections.

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
Press + to interact
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 ...