Skip to main content

Mesh data processing

Project description


MDAL Python integration allows you to access and manipulation geospatial mesh data sets using MDAL in Python.

Currently, this integration can:

  • read and write all MDAL compatible file formats

  • access vertex, face, edge and volume data as numpy arrays

  • write vertex, face, edge and volume data from numpy arrays

  • access and write scalar and vector datasets

  • beta level read and write integration with meshio

  • beta level read integration with Open3D


[‘2DM Mesh File’, ‘XMS Tin Mesh File’, ‘Selafin File’, ‘Esri TIN’, ‘Stanford PLY Ascii Mesh File’, ‘Flo2D’, ‘HEC-RAS 2D’, ‘TUFLOW FV’, ‘AnuGA’, ‘UGRID Results’, ‘GDAL NetCDF’, ‘GDAL Grib’, ‘DAT’, ‘Binary DAT’, ‘TUFLOW XMDF’, ‘XDMF’]



MDAL Python support is installable via Conda:

conda install -c conda-forge mdal-python


MDAL Python support can be installed using pip

pip install mdal

This will ONLY work if there is a valid and working installation of MDAL on the device and accessible through the device library search path.


The repository for MDAL’s Python extension is available at


The basic usage can be seen in this code snippet:

from mdal import Datasource, Info, last_status, PyMesh, drivers, MDAL_DataLocation

print(f"MDAL Version:  {Info.version}")
print(f"MDAL Driver Count :{Info.driver_count}")

for driver in Info.drivers:

ds = Datasource("data/ply/test_mesh.ply")

with ds.load(0) as mesh:
    print(f"Driver : {mesh.driver_name}")
    print(f"Format : {mesh.get_metadata('format')}")
    print(f"Vertex Count : {mesh.vertex_count}")
    print(f"Face Count : {mesh.face_count}")
    print(f"Largest Face: {mesh.largest_face}")
    print(f"Edge Count : {mesh.edge_count}")
    print(f"CRS : {mesh.projection}")
    print(f"Mesh extent : {mesh.extent}")
    print(f"Metadata : {mesh.metadata}")
    print(f"CRS Metadata : {mesh.get_metadata('crs')}")
    mesh.add_metadata("test", "value")
    print(f"Metadate set eqiuality : {mesh.get_metadata('test') == 'value'}")

    vertex = mesh.vertices
    print(f"Vertex Array Shape : {vertex.shape}")

    faces = mesh.faces
    print(f"Face Array Shape : {faces.shape}")

    edges = mesh.edges
    print(f"Edges Array Shape : {edges.shape}")


    group =
    print(f"DatasetGroup Name : {}")
    print(f"DatasetGroup Location : {}")
    print(f"Dataset Count : {group.dataset_count}")
    print(f"Group has scalar values : {group.has_scalar}")
    print(f"Group has temporal values : {group.is_temporal}")
    print(f"Reference Time : {group.reference_time}")
    print(f"Maximum Vertical Level Count : {group.level_count}")
    print(f"Minimum / Maximum ; {group.minmax}")
    print(f"Metadata : {group.metadata}")
    print(f"Name Metadata : {group.get_metadata('name')}")
    group.add_metadata("test", "value")
        f"Metadate set eqiuality : {group.get_metadata('test') == 'value'}")

    for i in range(0, group.dataset_count):
        data =
        time = group.dataset_time(i)
        print(f"Dataset Shape for time {time} : {data.shape}")


    test = PyMesh()
    test.vertices = mesh.vertices
    test.faces = mesh.faces
    test.edges = mesh.edges
    print(f"Mesh Copy Equality : {test == mesh}")
        f"Mesh Vertex Size equality: {test.vertex_count == mesh.vertex_count}")
    print(f"Mesh Face Size equality: {test.face_count == mesh.face_count}")"data/")

    test2 = PyMesh(drivers()[0])
    print(f"Mesh created by Driver : {test2.driver_name}")

    ds2 = Datasource("data/")
    test4 = ds2.load(0)
    print(f"Save equality : {test4 == test}")


with Datasource("data/ply/all_features.ply").load(0) as mesh:"save_test_2.ply")

    with Datasource("save_test_2.ply").load(0) as mesh2:
        print(f"Save equality 2 : {mesh == mesh2}")

with Datasource("data/tuflowfv/withMaxes/").load() as mesh:
    group = mesh.groups[1]
    a, b, c = group.volumetric(0)

    ds2 = Datasource("test_vol.ply")
    with ds2.add_mesh() as mesh2:
        mesh2.vertices = mesh.vertices
        mesh2.faces = mesh.faces

        print(f"Vertex Count :{mesh.vertex_count}")
        print(f"Face Count : {mesh.face_count}")

        group2 = mesh2.add_group(
            "test", location=MDAL_DataLocation.DataOnVolumes)
        group2.add_volumetric(, a, b)

        print(f"Level Count: {group2.level_count}")
        print(f"Location: {group2.location}")
        print(f"MinMax: {group2.minmax}")

        print(f"Dataset Count: {group2.dataset_count}")

        data =
        print(f"Data Value Count: {len(data)}")


        a, b, c = group2.volumetric(0)
        print(f"Number of Extrusion values : {len(b)}")
        with ds2.load() as mesh3:
            group3 = mesh3.groups[1]
            d, e, f = group3.volumetric(0)
            print("Mesh Equality : {mesh2 == mesh3}")

"""deep copy test"""

with Datasource("data/ply/all_features.ply").load() as mesh:
    with ds.add_mesh("test") as mesh2:

print("all finished !")

Integration with meshio

There is read and write integration with the meshio package. Any MDAL mesh can be converted to a meshio object and vice versa.

This integration is beta at the moment.

There are the following constraints:

  • MDAL_transform.to_meshio can take as an argument either a Mesh or a Dataset Group,

  • Only scalar MDAL datasets can be converted to meshio,

  • Volumetric data must be passed as a Dataset Group,

  • Volumetric meshio meshes and data are not currently converted, and

  • MDAL_transform.from_meshio only converts cells of types [“line”, “triangle”, “quad”].

from mdal import Datasource,MDAL_transform

"""meshio tests"""
with Datasource("data/ply/all_features.ply").load() as mesh:

    mio = MDAL_transform.to_meshio(mesh)

    group =

    mio2 = MDAL_transform.to_meshio(group)

    mesh2 = MDAL_transform.from_meshio(mio)

with Datasource("test_vol.ply").load() as mesh:
    group =
    mio2 = MDAL_transform.to_meshio(group)

print("all finished !")

Integration with Open3D

There is read-only integration with Open3D.

The MDAL_transform.to_triangle_mesh function converts any MDAL mesh to an Open3D TriangleMesh. The function can take as an argument an MDAL mesh or Dataset Group. In the former case if there are colour Datasets then these are converted to the TraingleMesh colours. In the later case, the data is converted to a false colur using a simple process - scalar data is loaded into the red values and vector data to the red and blue values.

The MDAL_transform.to_point_cloud converts a MDAL volumetric DatasetGroup to an Open3D PointCloud with the data values converted to color as above.

This integration is beta at the moment.

from mdal import Datasource, MDAL_transform

import numpy as np
import open3d as o3d

Open3d Tests
with Datasource("data/ply/test_mesh.ply").load() as mesh:
    tm = MDAL_transform.to_triangle_mesh(mesh)
    tm2 ="data/ply/test_mesh.ply")
    tmc = np.asarray(tm.vertex_colors)
    tmc2 = np.asarray(tm2.vertex_colors)
    for i in range(len(tmc)):
        value = tmc[i] - tmc2[i]
        if not (value == [0, 0, 0]).all():

with Datasource("test_vol.ply").load() as mesh:
    pc = MDAL_transform.to_point_cloud(

print("all finished !")


The documentation is currently WIP and can be found at


  • MDAL 0.9.0 +

  • Python >=3.8

  • Cython (eg pip install cython)

  • Numpy (eg pip install numpy)

  • Packaging (eg pip install packaging)

  • scikit-build (eg pip install scikit-build)


This package borrowed heavily from the PDAL-Python package.



  • fix debug message error (#15)

  • Deprecate mdal-python (#16)


  • fix memory leaks and inconsistencies around the Datagroup object (#11)


  • Add the PyPI package


First Read / Write Release

  • read and write all MDAL compatible file formats

  • access vertex, face, edge and volume data as numpy arrays

  • write vertex, face, edge and volume data from numpy arrays

  • access and write scalar and vector datasets

  • beta level read and write integration with meshio

  • beta level read integration with Open3D


First release. This is beta software and has not been completely tested yet:

Currently, this integration can:

  • read all MDAL compatible file formats,

  • access the metadata for the source,

  • access the vertex, face and edge data as numpy arrays,

  • access ‘double’ datasets (both scalar and vector) as numpy arrays, and

  • convert the MDAL source mesh into a meshio mesh object (with some restrictions currently).

This version does not currently allow the MDAL source mesh to be written or ammended.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mdal-1.0.3.tar.gz (56.1 MB view hashes)

Uploaded Source

Built Distributions

mdal-1.0.3-cp312-cp312-win_amd64.whl (123.6 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

mdal-1.0.3-cp312-cp312-macosx_12_0_x86_64.whl (143.7 kB view hashes)

Uploaded CPython 3.12 macOS 12.0+ x86-64

mdal-1.0.3-cp311-cp311-win_amd64.whl (126.2 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

mdal-1.0.3-cp311-cp311-macosx_12_0_x86_64.whl (146.0 kB view hashes)

Uploaded CPython 3.11 macOS 12.0+ x86-64

mdal-1.0.3-cp310-cp310-win_amd64.whl (125.6 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

mdal-1.0.3-cp310-cp310-macosx_12_0_x86_64.whl (144.1 kB view hashes)

Uploaded CPython 3.10 macOS 12.0+ x86-64

mdal-1.0.3-cp39-cp39-win_amd64.whl (125.9 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

mdal-1.0.3-cp39-cp39-macosx_12_0_x86_64.whl (144.7 kB view hashes)

Uploaded CPython 3.9 macOS 12.0+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page