Skip to main content

geo2glb

Compile GeoJSON and GeoPackage features into a 3D .glb scene, and view it in a single-file three.js viewer. Built for sites and urban design projects (up to a few km across).

geo2glb/            Python CLI (geopandas, shapely, trimesh)
viewer/index.html   three.js viewer, no build step
examples/           synthetic sample GeoPackage, its generator, and the QGIS style writer

Install and run

pip install -e .            # or: pip install geopandas pyogrio shapely pyproj trimesh mapbox-earcut pyyaml
geo2glb roads.geojson buildings.geojson landscape.gpkg -o out/site.glb
  • Inputs are GeoJSON (.geojson, .json) or GeoPackage (.gpkg) only. Shapefile is not accepted because it truncates field names to 10 characters.
  • Any number of inputs. A GeoPackage contributes every layer; use file.gpkg:layer for one. A folder contributes every GeoJSON and GeoPackage directly inside it, so the output of --to-geojson builds as is: geo2glb my_site_geojson -o site.glb.
  • Input CRS is EPSG:4326. A layer with no CRS is assumed to be 4326 (logged); other CRSs are reprojected.
  • The build report is written to .build_log next to the output (--log to change).
  • -c style.yaml overrides defaults and adds road classes (see geo2glb/config.py for every key).
  • --no-ground skips the ground plane.

To start a new site, write an empty template and draw into it in QGIS:

geo2glb --template my_site.gpkg     # --force to replace an existing file
Layer Geometry Fields
points Point name, type, colour, height, size
polygons Polygon name, type, colour, height, levels, base_height, layer
lines LineString name, type, colour, road_class, width_meter, road_total_lane, median_width, oneway, sidewalk_width, kerb_radius, layer, rail_tracks, rail_gauge, rail_track_spacing

Every field is optional and the layers are EPSG:4326 with the QGIS default styles already set. Empty layers are fine; build with geo2glb my_site.gpkg -o site.glb once you have drawn something.

Try it on the sample:

python examples/make_sample.py examples/sample
geo2glb examples/sample/sample.gpkg -o viewer/site.glb

sample.gpkg has three layers, points, polygons and lines. Non-spatial tables such as QGIS's layer_styles are skipped.

QGIS styles

The sample GeoPackage carries default QGIS styles in its layer_styles table, so the layers open already styled. Each layer gets a categorised renderer on the geo2glb type, using the same fallbacks and colours as the CLI:

Layer geometry Categorised on Notes
Lines coalesce(type, 'road') Roads are drawn at their real width in metres, resolved the same way as the CLI (width_meter, then road_class, then lanes x 3.5 m + 1 m, then 8 m). Railways are drawn at their ballast bed width with a black and white rail line
Polygons coalesce(type, 'building') Building, junction, each flat type, a red hatch for type: road polygons, and a category for any other type
Points coalesce(type, 'tree') Trees as green circles, anything else as a red square

The same styles set up the attribute form, so the main fields are dropdowns when you draw or edit a feature:

Layer Field Form widget
Lines type Dropdown: not set (road), road, railway
Lines road_class Dropdown of the PUPR classes with their kerb to kerb width, or not set
Lines oneway Dropdown: not set (two-way), yes, no
Polygons type Dropdown: not set (building), building, junction and the flat types
Points type Free text that suggests values already used in the layer (tree is the default, anything else is a marker)

A polygon type outside the list (such as retail, extruded like a building) can't be picked in the form; set it in the attribute table with the field calculator. Existing values outside the list are kept.

To style your own GeoPackage the same way (one style per spatial layer, chosen by geometry type):

python examples/qgis_styles.py my_site.gpkg

It adds a geo2glb style and makes it the default; existing styles are kept but no longer default. Remove and re-add the layer in QGIS to pick it up.

GeoPackage to GeoJSON and back

geo2glb --to-geojson my_site.gpkg                  # -> my_site_geojson/<layer>.geojson + <layer>.qml
geo2glb --to-gpkg my_site_geojson -o my_site.gpkg  # files or folders; --force to replace

QGIS applies a .qml with the same name as a GeoJSON automatically, so each file opens with the geo2glb style and the attribute dropdowns.

Direction What happens
To GeoJSON One .geojson per layer, with the layer's default style from the GeoPackage as its .qml (or the generated geo2glb style if it has none)
To GeoPackage One layer per .geojson, named after the file. Its .qml becomes the layer's default style, so style changes made in QGIS travel back. A file without a .qml gets the generated style. A file that mixes points, lines and polygons is split into <name>_points, <name>_lines and <name>_polygons
Fields GeoJSON has no schema, so on the way back the template fields are added where missing and their types restored (text, decimal, whole number). A value that isn't a number, such as levels: tall, is kept as text and reported, never dropped

An empty layer can't keep its fields in GeoJSON, so draw into the GeoPackage, or add at least one feature, before converting. The round trip back to GeoPackage still restores an empty layer's fields and geometry type (from its .qml).

Viewer

Open viewer/index.html and drop a .glb on it, or serve the folder and pass the file in the URL:

cd viewer && python -m http.server 8000
# http://localhost:8000/?file=site.glb
How the page is opened What loads
?file=some.glb That file
No ?file=, and a default.glb sits next to index.html default.glb
No ?file= and no default.glb Nothing; drop or choose a file

To publish a site with a model that opens straight away, build it as default.glb in the viewer folder (geo2glb site.gpkg -o viewer/default.glb) and serve the folder. The default only loads over http; opened from disk, the page shows the drop prompt.

Mouse: left or right drag rotates and tilts, middle (wheel button) drag moves the map, the wheel zooms. Without a middle button, Shift + left drag moves the map. Click a feature to see its attributes and the values geo2glb computed. The side panel has layer toggles by type, perspective and top views, a sun azimuth/elevation control with shadows, and a PNG screenshot. three.js 0.187 loads from jsDelivr, so the page needs internet access.

How features are classified

The geometry type decides the family; the type column decides the feature.

Geometry type missing type value Result
LineString road road Road
LineString railway Railway (see below)
LineString anything else Road (warning)
Polygon building building or any other value Extruded by height
Polygon road Building (warning: a road polygon makes no sense)
Polygon park, green, grass, water, plaza, pavement, parking, landuse Flat slab
Polygon junction Manual junction (see below)
Point tree tree Tree
Point anything else Box marker (size, height)

Multi-part geometries are split into parts, Z values are dropped, and invalid geometry is repaired with make_valid (logged).

Attribute schema

Attribute Applies to Meaning Fallback
type all Feature type, see above by geometry
colour all Hex, e.g. #c8c8c8 (color also accepted) default per type
height polygons, points Top height in metres levels x 3 m, else 4 m (tree 10 m)
levels polygons Storeys
base_height polygons Bottom of extrusion (podium gaps, overhangs) 0
road_class roads PUPR tipe jalan: 8/2-T, 6/2-T, 4/2-T, 4/2-TT, 2/2-TT, 1/1-TT
width_meter roads Kerb to kerb width, overrides everything from class or lanes
road_total_lane roads Total lanes from class or width
median_width roads Overrides the class median from class
oneway roads yes / true / 1: no centre line no
sidewalk_width roads Sidewalk each side, 15 cm kerb none (sidewalk=yes gives 1.85 m)
kerb_radius roads Junction corner radius 6 m
rail_tracks railways Number of parallel tracks 1
rail_gauge railways Track gauge in metres; values above 10 are read as millimetres 1.067 m
rail_track_spacing railways Centre to centre distance between tracks 4.0 m
width_meter railways Ballast bed width, overrides the computed one from tracks and gauge
layer roads, railways, junctions Grade separation; layer x 6 m elevation 0

Road widths (Permen PUPR No. 5 Tahun 2023)

Widths come from Lampiran II (secondary, urban network), design speed up to 60 km/h, new road with kerb and sidewalk.

road_class Carriageway Lanes Median Outer shoulder Kerb to kerb
8/2-T 2 x 14.00 8 1.50 0.50 30.50
6/2-T 2 x 10.50 6 1.50 0.50 23.50
4/2-T 2 x 7.00 4 1.50 0.50 16.50
4/2-TT 14.00 4 0.50 15.00
2/2-TT 7.00 2 0.50 8.00
1/1-TT 1.75 1 0.25 2.25

The median is Tipe 1 (0.50 inner shoulder, 0.50 raised island, 0.50 inner shoulder); the island is modelled 20 cm high and stops 2 m short of junctions. Width resolution order: width_meter > road_class > road_total_lane x 3.50 m (the lane width implied by the table) + shoulders > default 2/2-TT. Sidewalks narrower than the 1.85 m minimum (Pasal 29) are used as given and logged.

Junctions

Junctions are generated from the road linestrings; you never draw them.

  1. Endpoints within 0.5 m of another road are snapped to it, then the network is noded.
  2. A junction is any node where 3 or more segments meet, or where two different roads meet end to end.
  3. The junction area is the union of the incident road buffers, clipped to a circle that covers all their overlaps plus 1.5 x kerb radius, then closed (buffer out and in) to round the kerb corners.
  4. Each road surface is its buffer minus all junctions, so nothing overlaps and every road keeps its attributes. Lane markings are generated on the clipped surface, so they stop at the junction mouth. Sidewalks follow the rounded corners.

To control a specific junction, add a polygon with type: junction. Any generated junction whose node falls inside it is replaced by your polygon.

Railways

A LineString with type: railway is built as a ballast bed (30 cm), concrete sleepers every 0.6 m, and two rails per track. The road_* attributes, median_width, oneway and sidewalk_width are ignored on a railway (logged).

Item Value
Gauge 1.067 m (Cape gauge, the KAI network) unless rail_gauge is set, e.g. 1435 for standard gauge
Sleeper length gauge + 2 x 0.47 m (2.0 m for Cape gauge)
Bed width (rail_tracks - 1) x rail_track_spacing + sleeper length + 2 x 0.50 m ballast shoulder, or width_meter
Level crossings Where a railway crosses a road on the same layer, the bed is cut out of the road, junction, sidewalk, marking and median surfaces, and a deck is laid flush with the road with the rails embedded
Grade separation A railway on a different layer from the road passes over or under it, with no crossing

Railways are not part of the road network, so they don't create road junctions. Track spacing and sleeper pitch are typical values after PM 60/2012; check them against the project's standard, and override them in -c style.yaml under railway.

Output structure

One glTF node per feature, named by its source (roads.geojson#3). Each mesh's extras, available in three.js as object.userData:

{
  "type": "road",
  "attributes": { "name": "Boulevard", "road_class": "4/2-T", "sidewalk_width": 3.0 },
  "geo2glb": { "feature": "roads.geojson#0", "width_meter": 16.5, "lanes": 4, "width_source": "road_class 4/2-T (PUPR 5/2023)" }
}

Attributes are nested because GLTFLoader overwrites userData.name with the node name. Scene extras hold the origin (lon/lat and projected), the UTM CRS used and the extent. Axes: x = east, y = up, -z = north, metres, centred on the data.

Markings, medians and sidewalks are merged into one mesh per layer to keep the node count down.

Known limitations (v1)

Limitation Note
Flat world No terrain
Flat roofs only
Elevated roads and railways (layer > 0) float No ramps or piers
Generated junctions are generic No splitter islands, slip lanes, stop lines or zebra crossings; draw a manual junction polygon where the design matters
Railways are plain track No turnouts, platforms, catenary or level crossing gates; where two railways cross, their beds simply overlap
No footpaths Footpaths are not a separate line type yet

Metadata

Release files for geo2glb 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for geo2glb 0.1.0
File Size Uploaded Provenance Actions
geo2glb-0.1.0.tar.gz 131.6 kB Without provenance Details for geo2glb-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for geo2glb 0.1.0
File Interpreter ABI Platform Actions
geo2glb-0.1.0-py3-none-any.whl Python 3 none any Details for geo2glb-0.1.0-py3-none-any.whl

Total release size: 170.2 kB

Release files / geo2glb-0.1.0.tar.gz

Download URL geo2glb-0.1.0.tar.gz
Size 131.6 kB
Tags Source
SHA-256 checksum
How to use checksums
9366391f601436834536f7b736d2493f3081408671f1a98f6f2b3a2a10646451
BLAKE2b-256 checksum
How to use checksums
77cf6b5f4d4b8946610a5cb61aab4dd0b5b87ec47e36cf6cb7faeeb5f849ef0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / geo2glb-0.1.0-py3-none-any.whl

Download URL geo2glb-0.1.0-py3-none-any.whl
Size 38.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
62072b0a1cf6ec975d9fa6af91f2457f060d2b68df51956a68e342c0d18a35af
BLAKE2b-256 checksum
How to use checksums
444d9f9fb3f34e5f579d691af6b73c73d3cb516ce9c9081067a62ced26e8d625
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Security for geo2glb 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page