Skip to content
solomonsealedPublic

About

A jupyter notebook demonstrating how you can convert raw las data into a 3D printable obj file

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

las2obj

Convert raw LiDAR (.las / .laz) tiles into coloured, 3D-printable OBJ meshes using OSM data for classification.


Setup

Prerequisites

  • Python 3.10 (see options below)
  • Git
  • ~1 GB free disk space (dependencies + osmdata land polygons)

Option 1 — GitHub Codespaces (easiest cloud option)

No local installation required. Runs JupyterLab in the browser using GitHub's cloud machines.

  1. Push this repo to GitHub (or fork it)
  2. Click Code → Codespaces → Create codespace on main
  3. Wait ~2 min for the container to build
  4. JupyterLab opens automatically in a browser tab

Free tier: 60 hours/month on a 2-core machine. Upgrade for more cores/RAM.

LAS files: upload them via the Codespaces file explorer or use the terminal to download them. They are not committed to the repo.


Option 2 — Docker (local)

No Python installation required. Build time is ~2 min (pre-built wheels, no compilation).

  1. Install Docker: follow the official guide
  2. Clone this repo and cd into it
  3. Run:
# Build image (~2 min — uses pre-built manylinux wheels, no apt compilation)
docker compose build

# Start JupyterLab in the background
docker compose up -d

# Open in browser
xdg-open http://localhost:8888   # Linux
open http://localhost:8888        # macOS

LAS files are mounted read-only at /data/whangarei/ and /data/hope/ inside the container. Edit the paths in docker-compose.yml to point at your own data directories.

Output files (output/) are written directly to the project folder on the host — no copy step needed.

To stop: docker compose down


Option 3 — Conda

Conda manages both Python and binary system libraries (GDAL, PROJ, GEOS) in one step, which avoids most platform-specific build issues.

1. Install Miniforge (recommended over Anaconda)

Linux / WSL:

curl -L https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh -o miniforge.sh
bash miniforge.sh -b -p "$HOME/miniforge3"
eval "$($HOME/miniforge3/bin/conda shell.bash hook)"

macOS (Apple Silicon):

curl -L https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh -o miniforge.sh
bash miniforge.sh -b -p "$HOME/miniforge3"
eval "$($HOME/miniforge3/bin/conda shell.bash hook)"

2. Create the environment

conda create -n las2obj python=3.10 -y
conda activate las2obj

3. Install dependencies

pip install -r requirements.txt

4. Register the Jupyter kernel

python -m ipykernel install --user --name las2obj --display-name "Python 3.10 (las2obj)"

5. Launch JupyterLab

jupyter lab

Open the URL printed in the terminal. Select the Python 3.10 (las2obj) kernel when prompted.


Option 4 — venv (standard Python virtual environment)

Use this if you already have Python 3.10 installed and prefer not to use Conda.

1. Ensure Python 3.10 is installed

python3 --version   # must show 3.10.x

If not, install it:

Ubuntu / Debian:

sudo add-apt-repository ppa:deadsnakes/ppa -y
sudo apt update
sudo apt install python3.10 python3.10-venv python3.10-dev -y

macOS:

brew install python@3.10

Windows: download the installer from python.org/downloads

2. Create the virtual environment

# Linux / macOS
python3.10 -m venv .venv

# Windows
py -3.10 -m venv .venv

3. Activate it

# Linux / macOS
source .venv/bin/activate

# Windows (PowerShell)
.venv\Scripts\Activate.ps1

# Windows (cmd)
.venv\Scripts\activate.bat

You should see (.venv) prepended to your prompt.

4. Install dependencies

pip install --upgrade pip
pip install -r requirements.txt

Note (Linux): if rasterio or pyproj fail to build, install system libraries first:

sudo apt install libgdal-dev libgeos-dev libproj-dev

then re-run pip install -r requirements.txt.

5. Register the Jupyter kernel

python -m ipykernel install --user --name las2obj --display-name "Python 3.10 (las2obj)"

6. Launch JupyterLab

jupyter lab

Select the Python 3.10 (las2obj) kernel when prompted.


Usage

  1. Open las2obj.ipynb
  2. Edit the Config cell at the top:
    • LAS_FILE — path to your .las or .laz file
    • LAND_FILE — path to the osmdata land-polygon zip (optional; auto-downloaded if None)
    • RESOLUTION — grid cell size in metres (default 1.0)
  3. Run all cells top-to-bottom (Kernel → Restart & Run All)
  4. Outputs are written to output/

Output files

File Description
output/<stem>.obj 3D mesh with embedded vertex colours
output/cell*.png Visualisation snapshots from each cell
cache/ OSM and ocean mask caches (delete to force re-fetch)

LAS file paths inside Docker

Host path Container path
~/Downloads/whangarei/ /data/whangarei/
~/Downloads/hope/ /data/hope/
Project folder /notebook/

Notebook cells

Cell Description
Config File paths, resolution, tuning variables
1 Load LiDAR — density, classification map, RGB colour
2 Remove vegetation (ASPRS classes 3–5), re-visualise
3 Download OSM land polygons, derive ocean mask
4 Ocean classification (intensity + LiDAR class-9 + RGB)
5 Download OSM buildings, roads, waterways, greenspaces
6 Building raster (LiDAR class-6 + OSM footprints + border)
7 Full classification raster (building > road > green > water > ocean > ground)
8 Heightfield (95th pct buildings, 10th pct water, 50th pct terrain)
9 Export self-contained OBJ with embedded vertex colours

Tuning variables (quick reference)

Variable Cell Default Effect
RESOLUTION Config 1.0 Grid cell size in metres
BUILDING_BORDER_M 6 5 Border buffer around all buildings (m)
ROAD_BUFFER_M 7 6.0 Road linestring buffer radius (m)
MIN_WATER_CELLS 7 200 Min inland water patch size before → road
MIN_GREEN_CELLS 7 200 Min green space patch size before → road
MIN_GROUND_CELLS 7 200 Min ground patch size before → road
MIN_ROAD_CELLS 7 200 Min road patch size before → building
OCEAN_INTENSITY_PCT 4 20 Intensity percentile threshold for water signal
BUILDING_OPEN_SIZE 8 7 Opening kernel — strips antenna/cable spikes
BUILDING_CLOSE_SIZE 8 15 Closing kernel — fills dome/roof voids
BUILDING_SMOOTH_SIZE 8 9 Median kernel — final roof smoothing
TARGET_XY_MM 9 200.0 Longest print dimension (mm)
BASE_MM 9 4.0 Base plate thickness (mm)
BUILDING_PAD_PX 9 1 Extra colour dilation on building walls

About

A jupyter notebook demonstrating how you can convert raw las data into a 3D printable obj file

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages