0% found this document useful (0 votes)
16 views11 pages

Visualizing 3D Maps with Pydeck

The document introduces the Python package PyDeck for creating 3D maps, using a dataset of building models from Budapest. It details the process of accessing, filtering, and visualizing the data, culminating in a 3D map representation of the city's central district. The author emphasizes the utility of Python in geospatial data visualization and promotes their book on geospatial data science skills.

Uploaded by

Brou Brou
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views11 pages

Visualizing 3D Maps with Pydeck

The document introduces the Python package PyDeck for creating 3D maps, using a dataset of building models from Budapest. It details the process of accessing, filtering, and visualizing the data, culminating in a 3D map representation of the city's central district. The author emphasizes the utility of Python in geospatial data visualization and promotes their book on geospatial data science skills.

Uploaded by

Brou Brou
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

[Link] Sauvegarde de [Link] rechercher 25 juil.

2025 10:31:31 UTC


sauvegarde de page web aucun autre cliché pour cette url
Tous les clichés de l'hôte [Link]

Page web Capture d'écran partager télécharger .zip signaler une erreur ou un abus Achetez-moi un café

Search Write Sign up Sign in

TDS Archive

Member-only story

Visualizing 3D Spatial Data With


Pydeck
How to create building model maps in Python

Milan Janosov Follow 5 min read · Jul 29, 2024

185

In this piece, I would like to introduce you to the Python package called
PyDeck, which is a great tool to create 3D maps in Python. As an example, I
will use a 3D building model data base covering the city of Budapest.

All images were created by the author.

Accessing the building data


The data is sourced from the publicly available Budapest Open Data Atlas,
which you may access here. While the site is in Hungarian, once you find the
section ‘Épületmagasság’ and click on the button starting with ‘geojson’, you
should be able to download the geojson file, which is perfectly readable in
English and with Python as well.

Source

After a quick download, let’s open the file and take a quick look:

# import geopandas
import geopandas as gpd

# parse the building height data set


gdf = gpd.read_file('[Link]')
[Link]()
len(gdf)

The output of this cell:


The image shows that the building footprints — more than 350k altogether —
are scattered all around the city of Budapest. Now, let’s take a quick look at
the data structure more directly:

[Link](3)

For further use, two things to take from this table: the column DN containing
the building height information, and the geometry containing the building
footprint geometries.

Data preparation
Once you parse the GeoDataframe with 350k rows, you will also realize that
for quick demonstrations, this is a bit too much. So, to make sure we can
focus on a cool and efficient visual here, I decided to narrow down the data
set to the central district of Budapest, District 5. For that, let’s download the
admin boundaries of this district using OSMnx and then carve out the
corresponding footprints.
#Import all the libraries we use
import osmnx as ox

# Download the administrative boundary of the 1st district of Budapest


admin_district = ox.geocode_to_gdf('5th district, Budapest')
admin_district.plot()

The outline of District 5:

# filter out the bulding footprints that fall into my selected districts
gdf2 = [Link](gdf, admin_district)

len(gdf2)

This overlaid GeoDataFrame shows that we were successful in filtering the


data — now we only have about 8k footprints.

By the way, the following quick histogram tells us that there are just three
footprints above 60m in the district — which, after filtering the data frame,
turn out to be two buildings — the Basilica and the Parliament. Matching this
to my local knowledge, indeed, they are the two signature — and tallest —
buildings in the area.
[Link]()
gdf2[[Link]>60][['DN', 'name_1']]

Creating the visual


First, let’s create a more basic version of the 3D building map by setting the
coloring of each building to be red. With Pydeck, it’s best to use RGB codes.
Additionally, by changing the view_state, we can set up the center of the map
as well as the zooming level.

import pydeck as pdk

layer = [Link](
'PolygonLayer',
data=gdf2,
get_polygon='[Link]',
extruded=True,
get_elevation='DN',
get_fill_color = [255, 0, 0],
)

view_state = [Link](
latitude=47.499919,
longitude=19.0530236,
zoom=13,
)

# Create the 3D map


r = [Link](layers=[layer], initial_view_state=view_state)
r

Then, we can further fine-tune the plot, for instance, by changing the
elevation scale to make the height differences more pronounced, deriving a
scaling parameter, which we can incorporate in the coloring. This way, we
can color the building models based on any parameter, or changing the line
color as well.

import math

# do the scaling
max_val = max([Link])
gdf2['scaled'] = [0.2 + (d/max_val) for d in [Link].to_list()]

# add the data


layer = [Link](
'PolygonLayer',
data=gdf2,
get_polygon='[Link]',
extruded=True,
get_elevation='DN',
elevation_scale=4,
get_line_color=[255, 255, 255],
get_fill_color="[255, 0, scaled * 255]"

# set the view state


view_state = [Link](
latitude=47.499919,
longitude=19.0530236,
zoom=13,
)

# Create the 3D map


r = [Link](layers=[layer], initial_view_state=view_state)
r
Finally, tweak the view state a little further with camera direction settings,
and save the output as an html file.

import math

# do the scaling
max_val = max([Link])
gdf2['scaled'] = [0.2 + (d/max_val) for d in [Link].to_list()]

# add the data


layer = [Link](
'PolygonLayer',
data=gdf2,
get_polygon='[Link]',
extruded=True,
get_elevation='DN',
elevation_scale=4,
get_line_color=[255, 255, 255],
get_fill_color="[255, 0, scaled * 255]"

# set the view state


view_state = [Link](
latitude=47.499919,
longitude=19.0530236,
zoom=14,
pitch=45, # controls the angle of the camera relative to the ground
bearing = 30 # controls the rotation of the camera around the vertical axis

# Create the 3D map


r = [Link](layers=[layer], initial_view_state=view_state)
r.to_html('[Link]')
r
Conclusion
As this example shows, Python can be surprisingly useful in creating visuals
that reveal various insights, such as building heights and other parameters,
embedded in three dimensions.

If you would like to further advance your geospatial Python skills, check out
my brand new book, Geospatial Data Science Essentials — 101 Practical
Python Tips and Tricks!

Data Science Python Data Visualization Maps Geospatial

185

Published in TDS Archive Follow


827K followers · Last published Feb 3, 2025

An archive of data science, data analytics, data engineering, machine learning,


and artificial intelligence writing from the former Towards Data Science Medium
publication.

Written by Milan Janosov Follow


2K followers · 9 following

🎯 Network scientist | 🌏 Geospatial data and data viz expert | ✈️ Chief data
scientist @Baoba | #1 Best Seller Author on Amazon | 🎖️ Forbes 30u30

No responses yet

Write a response

What are your thoughts?


More from Milan Janosov and TDS Archive

Milan Janosov In TDS Archive by Steve Hedden

38 Network Analysis Tools How to Implement Graph RAG


As I did my PhD in network science, this field Using Knowledge Graphs and…
within data science is particularly dear to m… A Step-by-Step Tutorial on Implementing
Retrieval-Augmented Generation (RAG),…

Jan 26, 2024 154 1 Sep 6, 2024 1.93K 19

In TDS Archive by Thuwarakesh Murallie In TDS Archive by Milan Janosov

How to Build a Knowledge Graph in Public Transport Accessibility in


Minutes (And Make It Enterprise-… Python
I tried and failed creating one—but it was In this piece, I explore the availability of public
when LLMs were not a thing! transport by using GTFS data and Python-…

Jan 13 1.2K 9 Apr 27, 2024 419

See all from Milan Janosov See all from TDS Archive

Recommended from Medium


Williams Adaji-Agbane Neha Sharma

Geospatial Machine Learning Smart Buildings and Cities with


Episode 7: Evaluating Geospatial ML Models Remote Sensing and GIS: First-of…
with Real-World Data Edited by: Dr. Shiv Mohan, Dr. Navneet
Munoth, Ar. Neha Sharma Edition: 1st Edition…

Feb 27 25 2 Jun 8 11

In Python in Plain English by Tarık Emre Yorulmaz In Data Science Collective by Erdogan T

Streamlining Raster Data Create Beautiful Stand-Alone and


Reclassification: A Python… Interactive [Link] Charts with…
Raster reclassification is a fundamental With application to D3 force-directed
operation in Geographic Information Syste… network graphs.

Jul 12 1 Jul 17 45 2

Prachi Sarode In Neo4j Developer Blog by Matthew Wood

From Code to Climate Action — Part Exploring Neo4j Spatial:


1: How I Built My First Urban Heat… Installation, Data Loading, and…
A beginner’s journey in building a data Integrate spatial analytics into Cypher graph
pipeline, combining GeoAI, Remote Sensing… queries

Jun 1 2 1 2d ago 4

See more recommendations


Help Status About Careers Press Blog Privacy Rules Terms Text to speech

Common questions

Powered by AI

First, you need to access and parse the data into a GeoDataFrame. For large datasets, such as the building footprints of Budapest, it's effective to limit the data to specific regions to manage resource use efficiently. In this example, data was narrowed down to Budapest's District 5 using city boundaries from OSMnx . Next, create a visualization with Pydeck by defining a layer for the data, configuring the view state with the map's center and zoom level, and accounting for building height data to control visual elevation. To optimize for clarity, scale the elevation and adjust visual parameters like fill color depending on further-style choices .

Public data sources like the Budapest Open Data Atlas are crucial for developing comprehensive urban visualizations as they provide a wealth of accurate, up-to-date geospatial data. Such data supports transparency, fosters innovation, and allows researchers to undertake detailed analysis and visualizations without needing to conduct costly primary data collection. This accessibility enhances research capabilities in urban planning and data science .

Filtering is crucial to manage computational resources and improve visualization clarity with large datasets. In the 3D mapping of Budapest, data was filtered to focus only on District 5 by downloading administrative boundaries with OSMnx. This process reduced the dataset from 350,000 to about 8,000 records, ensuring efficient data management and clear representation .

The process involves using OSMnx to download geographic boundary data by querying open-source map services. This method is beneficial due to its ease of access, accuracy, and detail in representing regions like city districts, which are essential for urban visualizations. The approach enables focusing data analysis on specific areas, which optimizes computational resources and enhances visualization relevance, as demonstrated in the Budapest map .

Scaling building heights in visual maps emphasizes structural differences by making variations in height more visually pronounced, allowing significant structures to stand out. This can also help users quickly identify notable geographic or architectural features within data subsets. For instance, in Budapest’s District 5, scaling highlights taller buildings such as the Basilica and the Parliament building, which are notable for their height .

Challenges include resource constraints, data complexity, and rendering performance. Pydeck can address these via filtering techniques to reduce data size, efficient rendering with optimized library functions, and customization features to focus on essential data parts. This enhances computation efficiency and visualization clarity, particularly when narrowing down areas like Budapest's District 5 for concise analysis .

Adjusting elevation scales in 3D maps enhances user perception by making nuances in height more visible, thus highlighting significant differences within the dataset. This modification helps in emphasizing detailed geographic and structural variations, making the map more informative and aiding decision-making processes. For instance, scaling in the Budapest map revealed height variations critical for understanding skyline characteristics and highlighting landmark buildings .

RGB color coding in spatial data visualization helps differentiate structures based on custom attributes. This can enhance the depth of the visual information by assigning particular colors to different data segments. For instance, in Pydeck, buildings can be color-coded to visually depict height variations or other attributes, thus allowing viewers to quickly interpret data patterns and differences, such as distinguishing significant elevations or structures .

Adjusting view states in Pydeck sets the map's center, zoom, pitch, and bearing, defining the orientation and framing of the visualization. This influences the narrative by highlighting specific features, aiding in analysis by focusing on critical areas, and improving interpretability by providing a natural perspective, enhancing user engagement with the visual data .

Geometric data types in GeoDataFrames facilitate the representation of spatial characteristics by providing structured data that can be readily used by visualization libraries like Pydeck. These geometries, such as polygons representing building footprints, enable accurate rendering of three-dimensional visualizations by defining the spatial extent and dimensions of objects in the map .

You might also like