Building Information Models in polars DataFrames with geometry columns.
A BimDataFrame is one BIM model: a polars DataFrame with one row per
element, with or without geometry, and the coordinate reference system of that geometry, the
BIM CRS, in a bim_crs column of
PROJJSON text. Meshes and bounding
boxes are plain nested columns and footprints are WKB, so the whole model filters, joins and
aggregates like any other DataFrame, keeps its CRS while it does, and round-trips through
Parquet, as GeoParquet once it has footprints.
import polars as pl
import bimpolars
bdf = bimpolars.read_ifc("sixty5_O-S1-CON-structural-engineering.ifc")
bdf.schema
# id: String, name: String, class: Categorical, properties: Struct, container: String,
# elevation: Float64, native_geom: List(Struct), mesh: Struct, bbox: Struct, bim_crs: Categorical
columns = bdf.filter(pl.col("class") == "IfcColumn") # a BimDataFrame, CRS and all
columns.select(
"id",
"name",
load_bearing=pl.col("properties").struct.field("Pset_ColumnCommon").struct.field("LoadBearing"),
triangles=pl.col("mesh").struct.field("faces").list.len() // 3,
)
# Outline the elements, not the voids of the openings; the storeys stay to place the footprints
elements = bdf.filter(pl.col("class") != "IfcOpeningElement")
bdf = bimpolars.simple_features(elements)
bdf.schema # + footprint_ref: String, footprint: Binary (ISO WKB)
bdf.write_parquet("sixty5.parquet") # GeoParquet: footprint is the primary geometry
bimpolars.read_parquet("sixty5.parquet").equals(bdf) # True, CRS included
# The structural-analysis model: beams and columns as lines, slabs and walls as midplanes
analysis = bimpolars.simple_features(bdf, lightbim=True)
analysis.select("id", "lightbim", "lightbim_kind", "lightbim_qa")
from pathlib import Path
Path("sixty5.glb").write_bytes(bimpolars.element_meshes_glb(bdf)) # glTF, one material per style
import geopandas
geopandas.read_parquet("sixty5.parquet", columns=["id", "class", "footprint"]).crs
# <Engineering CRS: {"$schema": ...}> Name: MM16169 model coordinates, millimetre axesThe demo page, bedrock-engineer.github.io/bimpolars,
shows the Sixty5 structural model read with read_ifc and placed on earth with
georeferenced_bim_crs in specklewidgets'
GeoSpeckleViewer, among PDOK's 3D BAG, beside a map of the clicked element's footprint (its
geog). The page is built from specklestuff's site/ (.github/workflows/pages.yml).
uv add bimpolars # or: pip install bimpolars
uv add "bimpolars[ifc]" # with ifcopenshell, for read_ifc
uv add "bimpolars[speckle]" # with specklepy, for Speckle bundlesThe core depends on polars, numpy, shapely and pyproj, so georeferencing needs no extra.
Reading IFC (ifcopenshell) is the extra [ifc]: import bimpolars does not import
ifcopenshell, bimpolars.read_ifc does on first use. Reading a Speckle version from its v3
objects needs no specklepy; building those objects from a Speckle bundle does, and is the
extra [speckle] (see Speckle).
A CRS goes in in any form pyproj reads: PROJJSON, a pyproj.CRS, "EPSG:7415", an EPSG code
or WKT (bimpolars.CRSLike). A BimDataFrame stores it as PROJJSON text in its bim_crs
column, the same value on every row of one model, which is what its GeoParquet and glTF
metadata carry, and hands it out as a pyproj.CRS (bdf.crs), like GeoDataFrame.crs, and
as a PROJJSON dict (bdf.projjson). bim_crs covers the BIM geometry columns (mesh,
bbox, native_geom, footprint, lightbim), not geog, which is always OGC:CRS84h.
Since the CRS travels with the rows, polars works on the BimDataFrame itself: bdf.filter(...),
bdf.join(...) and bdf.with_columns(...) give a BimDataFrame, bdf["id"] is the Series,
"id" in bdf and for column in bdf go over the columns, and pl.DataFrame(bdf) and DuckDB
read it through the Arrow stream. The bimpolars functions also take the plain polars frames
that bdf.pipe(...) and a group_by loop hand out, as long as they kept bim_crs.
bimpolars.concat(bdfs) stacks models, every row keeping its own CRS; a frame whose rows are
in more than one CRS, or that has no rows, has no bdf.crs (it raises and says why) and
to_crs refuses it. A notebook shows each row's CRS by its name in the bim_crs column and
the WKB columns as WKT, display only; mo.ui.table(bdf) works too, with the raw values.
read_ifc(source, *, threads=None): reads every product of an IFC into aBimDataFrame, tessellated by ifcopenshell in the model's own coordinates and length unit. The columns:id,name,class(Categorical IFC class). EveryIfcProductis a row, openings included: anIfcOpeningElementrow carries the solid mesh of the void it cuts, so filterclass != "IfcOpeningElement"before outlining or rendering elements.properties: a Struct of property and quantity sets (the type's included), each a Struct of values. A property whose type differs between rows becomes a String. The setattributesholds the entity'sPredefinedType(its type's, orObjectTypewhen it is USERDEFINED), which tells a base slab from a floor.container: theidof the spatial element the row sits in (the storey for most elements, the building for a storey; null for the site, for elements in no container and for ports);elevation: the storey's level in model coordinates.native_geom(NATIVE_GEOM_DTYPE): the extruded solids (IfcExtrudedAreaSolid) of the body, mapped items resolved and both operands of a union kept, as a list of sweeps:placement(a row-major 4x4 matrix from the sweep's coordinates to the BIM CRS),profile(a 2D WKB polygon with its voids),profile_type,profile_name,depth,directionandclipped(the IFC cut the solid afterwards, by a difference or an intersection). Breps and other solids are left out, so a list can describe part of a body; null when there is no sweep. LightBIM takes a member's axis or midplane from it.mesh:{vertices, faces, styles}with flat vertices, faces sorted by style, and each style'sname,rgbaandface_count;bbox:{xmin, ymin, zmin, xmax, ymax, zmax}. Rows without geometry have a nullmeshandbbox.
simple_features(bdf, *, lightbim=False, kind=None): adds the plan footprint of every row with a mesh, in two columns, and withlightbim=Truethe three columns of LightBIM:footprint: the outline of the mesh in plan, the union of its triangles projected to the XY plane, asPOLYGON ZorMULTIPOLYGON Zin ISO WKB (Binary), lying flat at the level of thefootprint_refrow. Holes and separate parts survive. A mesh with no plan area (all triangles vertical) getsPOLYGON Z EMPTY; a row without a mesh gets null. Every mesh is outlined, anIfcOpeningElement's void included: filter openings out first for a plan of the elements.footprint_ref: theidof the row whose level the footprint lies at: the row'scontainerwhen that has anelevation(the storey, for most elements), else the row itself at the lowest z of its mesh. Every row'scontainermust be in the frame: filter the elements, but keep the spatial rows, orsimple_featuresraises. Decode the column withshapely.from_wkb(bdf["footprint"].to_numpy()).
bimpolars.lightbim.lightbim_features(bdf, *, kind=None): the LightBIM columns on their own, for a frame that has its footprints. The class table isbimpolars.lightbim.CLASSES.plan_outline(vertices, faces): the plan outline of one triangle mesh as a 2D shapely Polygon or MultiPolygon, the union of its triangles projected to XY, for a mesh outside a frame. Slivers (triangles with less plan area than 1e-9 of the extent squared) are left out.element_meshes_glb(bdf, *, normals=True): the meshes as binary glTF (bytes), in metres, one primitive and material per style (nameandrgbaof the mesh'sstyles), without theIfcOpeningElementrows. See glTF.triangles_glb(groups): any triangles in metres, z up, as flat-shaded binary glTF: per material name an(n, 3, 3)array of corners and an RGB or RGBA colour in 0..1.BimDataFrame(frame, crs=None): the wrapper of a frame with abim_crscolumn, or of one without it and a CRS in any form, which becomes the column. It has.frame,.crs(apyproj.CRS),.projjson,.with_frame()(a frame withoutbim_crsin this model's CRS),.equals(),.write_parquet()andBimDataFrame.read_parquet(), and every polars DataFrame method.concat(bdfs, *, how="vertical"): stacks BimDataFrames (or polars frames withbim_crs) likepl.concat, every row keeping its CRS (howis"vertical","diagonal"or their_relaxedvariants).read_parquet(source): reads aBimDataFrameback, CRS included: it is thebim_crscolumn. Thebimpolarskey of the Parquet file metadata holds the layout version,{"version": 2}; a file of version 1, which kept the CRS there, gets the column on read.engineering_crs(name, *, unit, datum): a plain EngineeringCRS as PROJJSON in a given length unit (a known name, aLinearUnit(name, conversion_factor), or a CRS or a model whose unit it copies), which a model without georeferencing gets.bdf.crs.axis_info[0].unit_namereads the unit back.properties_series(rows): the Struct column of property sets thatread_ifcandread_speckleuse, with the dtype per property inferred across rows, for any reader with named sets of values.read_speckle(objects, bundle=None, *, name=None): reads the v3 objects of a Speckle version into aBimDataFrame, instances expanded, with the Revit categories, parameters and levels of the version's bundle when one is given. See Speckle.version_objects(source, version): the v3 objects of one version, root first, from a local copy: a Parquet file withversion_id,object_id,is_rootandcontentcolumns, or a SQLite database withversions(version_id, v3_root_id)andobjects(hash, content).bimpolars.bundle.bundle_objects(bundle): the v3 objects of a bundle-only version, built from its bundle (a folder of<name>.<table>.parquetfiles, or the bundle's URL in the bimpolars bucket) with specklepy, the[speckle]extra; the placed elements keep the geometry they carry themselves and definition geometry keeps its materials.bimpolars.bundle.bundle_model(bundle)opens such a bundle as a specklepyModel. See Speckle.bimpolars.data.fetch(key, *, download=True): the path of a test or example model, downloaded fromhttp://r2.eu.bedrock.engineer/bimpolars/on first use intobimpolars.data.data_dir():BIMPOLARS_DATA_DIR, else$XDG_CACHE_HOME/bimpolars, else~/.cache/bimpolars. The key may be given as its URL in the bucket.bimpolars.data.fetch_bundle(prefix)fetches the tables of a Speckle bundle (bimpolars.data.BUNDLE_TABLES) the same way and gives their folder; a bundle's overflow geometry shards (<name>.geometries.<N>.parquet, past 1.5 GiB of geometry) are not among them, so read such a bundle from a complete folder.bimpolars.data.bucket_key(key_or_url): the key of a URL in the bucket (httporhttps, percent-encoded or not), whichfetchandfetch_bundleuse; a URL outside the bucket, or a key that would leave the data folder (absolute, a drive or..), raisesValueError.bimpolars.speckle.bundle_folder(bundle): the local folder of a bundle given as a folder or as its URL in the bucket (fetched withfetch_bundle), asread_speckleandbimpolars.bundletake it.
The georeferencing functions live in bimpolars.geobim and on the package itself. A model from
a reader sits in its own coordinates; georeferencing says where that is on earth:
import bimpolars as bpl
bdf = bpl.simple_features(bpl.read_ifc("sixty5.ifc"))
# Sixty5: the site origin at RD New (160071.5, 384156.5), NAP +18.625 m, the site's y-axis
# 50.36 degrees clockwise from grid north, in the model's own unit (millimetres)
crs = bpl.georeferenced_bim_crs(
"EPSG:7415", 160071.5, 384156.5, 18.625, -50.36, unit=bdf, name="Sixty5"
)
site = bpl.set_crs(bdf, crs) # the same geometry, now in a georeferenced BIM CRS
rd = bpl.to_crs(site, "EPSG:7415") # meshes, footprints, bbox and levels in RD New + NAP metres
rd.write_parquet("sixty5_rd.parquet") # GeoParquet with EPSG:7415
geographic = bpl.to_crs(site, "OGC:CRS84h") # the whole model in lon, lat, ellipsoidal height
site = bpl.with_geog(site) # + geog: the footprints in OGC:CRS84h, next to the site's own
site.write_parquet("sixty5_geog.parquet") # GeoParquet with geog as the primary geometry
geopandas.read_parquet("sixty5_geog.parquet", columns=["id", "class", "geog"]).to_json() # GeoJSONgeoreferenced_bim_crs(compound_crs, easting, northing, orthometric_height, rotation, *, unit, name): a BIM CRS placed on a compound CRS of a projected and a vertical CRS such as EPSG:7415 (RD New + NAP height), as apyproj.CRSnamedf"{name} georeferenced BIM CRS"; any other CRS raises aValueErrorthat names what it got. It is a compound of a DerivedProjectedCRS with an Affine parametric transformation (EPSG:9624) and a DerivedVerticalCRS with a Vertical Offset (EPSG:9616), with the axes in the model'sunit(unit=bdfcopies it); it keeps the datums ofcompound_crs, so in ISO 19111 terms it is not an EngineeringCRS. The site origin lands on(easting, northing, orthometric_height)and the model's y-axis pointsrotationdegrees counterclockwise from grid north (for an IfcMapConversion:degrees(atan2(XAxisOrdinate, XAxisAbscissa))). PROJ then chains BIM CRS → compound CRS → anything.set_crs(bdf, crs): declares the CRS the coordinates are in (PROJJSON, apyproj.CRSor user input such as"EPSG:7415"): it rewritesbim_crsand leaves the geometry alone, likeGeoDataFrame.set_crs. The CRS must have three axes.to_crs(bdf, crs): moves the model to another CRS with one pyproj transformation, likeGeoDataFrame.to_crs: themeshvertices, the WKB columns in the BIM CRS (footprintandlightbim; nevergeog) and the storeyelevations (at the plan centre of the model) move together,bboxis recomputed from the moved meshes (from the moved corners of the oldbboxwhen the frame has nomeshcolumn) and the footprints are kept inside it. The target must have three axes, so that the meshes keep one unit per axis:"EPSG:7415", not"EPSG:28992".native_geomkeeps its sweeps only under an affine transformation (to thecompound_crsof a georeferenced BIM CRS, for instance): the matrix is composed onto each sweep'splacement, scale included, and the profile and depth stay in the sweep's own unit. A geographic, geocentric or differently projected target nulls it.lightbim_qa.deviation, a length, is scaled by the same matrix into the target's unit (1500 mm becomes 1.5 m in EPSG:7415), and nulled when the transformation is not affine. A derived CRS is passed through its base CRS, because PROJ otherwise applies a 3D Helmert transformation to heights still in the model's unit. A frame whosebim_crsholds more than one CRS is refused; move each CRS's rows on their own (for example overbdf.group_by("bim_crs")).with_geog(bdf): addsgeog, thefootprintof every row in OGC:CRS84h (longitude and latitude in degrees, ellipsoidal height in metres on WGS 84:bimpolars.crs.CRS84H), as ISO WKB, null exactly whenfootprintis. That is the CRS GeoJSON means by its coordinates, so the column exports to GeoJSON as it is (GeoDataFrame.to_json(),shapely.to_geojson, DuckDB'sST_AsGeoJSON), and the written GeoParquet takes it as the primary geometry (see GeoParquet). The model keeps its own CRS andfootprint, andto_crsnever movesgeog. A model in a plain EngineeringCRS raises:set_crsit first. GDAL's WKT1 cannot say a 3D geographic CRS, soGeoDataFrame.to_file(pyogrio) refuses the column's CRS; label the frameOGC:CRS84first (gdf.set_crs("OGC:CRS84", allow_override=True)), which keeps the heights.affine_transformation(bdf, crs): the 4x4 matrixto_crswould apply to a placement, or None when the transformation is not affine over the model (withinAFFINE_TOLERANCE, 1 µm).linearized_site_to_ecef(crs): the 4x4 matrix from site metres to ECEF metres (EPSG:4978), linearized at the site origin, for CesiumJS and 3D Tiles.
Transformations to ETRS89 (EPSG:4937, OGC:CRS84h, ECEF) should follow RDNAPTRANS™2018,
which PROJ does only with the NSGI grids nl_nsgi_rdtrans2018.tif and nl_nsgi_nlgeo2018.tif
(install them, or enable the PROJ network). Without them PROJ falls back to a Helmert
transformation that is good to about a metre, and passes NAP heights off as ellipsoidal heights;
to_crs warns when that happens.
write_parquet on a frame with a geog, footprint or lightbim column writes
GeoParquet 1.1: the file metadata gets a geo entry
(bimpolars.geoparquet.geo_metadata) that lists each of them WKB encoded with its geometry
types and its CRS as PROJJSON: footprint in the BIM CRS, geog in OGC:CRS84h. The first
one present is the primary geometry column (bimpolars.geoparquet.GEOMETRY_COLUMNS): geog
when with_geog added it, so that a reader that takes the primary column has longitude and
latitude, else footprint. When the frame has its bbox column, the entry also names that
column as the covering of the footprints: a pointer that tells a reader that each row's
footprint lies within bbox.xmin..xmax and bbox.ymin..ymax, so that a spatial filter can
skip row groups. A GeoParquet covering has those four slots and no z; the bbox column itself
keeps all six fields. The entry's own bounding box, one for the whole file, is x and y only
for another reason: the footprints lie flat at their storey's elevation, which is often
outside the mesh's zmin..zmax, so the mesh's z range would not contain them. geog is in
degrees, which bbox does not cover, so its entry gets the bounds of its own coordinates and
no covering (geopandas.read_parquet(..., bbox=...) filters on the primary column's covering
and refuses a file whose primary column has none). Readers that understand GeoParquet then
find the footprints with their CRS, and can skip row groups with the bbox:
geopandas.read_parquet("sixty5.parquet", columns=["id", "footprint"], bbox=(0, 0, 10_000, 10_000))LOAD spatial; -- DuckDB
SELECT id, ST_Area(footprint) FROM read_parquet('sixty5.parquet') WHERE bbox.xmax < 10000;lightbim is a GeoParquet geometry column too, listed after footprint with the same CRS and
covering: every reduction lies within its row's bbox. mesh and native_geom are not GeoParquet
geometries; they share the BIM CRS of bim_crs.
simple_features(bdf, lightbim=True) reduces every element the way a structural analysis model
does, next to its footprint:
bdf = bimpolars.simple_features(bimpolars.read_ifc("sixty5.ifc"), lightbim=True)
bdf.select(
"name",
pl.col("lightbim_kind").struct.unnest(), # member, role, load_bearing
pl.col("lightbim_qa").struct.unnest(), # rule, source, deviation
)lightbim: ISO WKB with Z in the BIM CRS. Thememberoflightbim_kindsets it: acurve(beam, column, brace, pile) is aLINESTRING Zalong its axis, asurface(slab, wall, plate, roof) aPOLYGON Zon its midplane with the holes and parts of its mesh (a wall with windows), asupport(footing, raft) the footprint at its bearing level (the bottom of the mesh), amassthe footprint at the height of its centre of gravity.lightbim_kind:{member, role, load_bearing}withmemberandroleEnums. The member comes from, in order: thekindexpression the caller passes (a Struct of any of the three fields, or a String member, null where it has no say); the class tablebimpolars.lightbim.CLASSES(IFC classes, with the predefined type where it matters:IfcSlab.BASESLABis a raft, and Revit categories); the shape of the mesh (the tightest of an upright box and a box along its principal axes, snapped to the model axes within 5 degrees: a surface when the smallest extent is 4 times smaller than the middle one, else a curve when the middle is 4 times smaller than the largest, else a mass). A role the table leaves open (IfcMember, RevitStructural Framing), or that akindmember other than the table's drops, follows the angle of the axis;load_bearingcomes from theLoadBearingof aPset_set (Pset_WallCommon), else of any other set, else the RevitStructuralparameter, else the table. Openings, spaces and reinforcement are no members: their columns are null, as they are for rows without a mesh. The class table andload_bearingreadproperties: keep its setsattributesandPset_*Common(or Revit'sStructural) when you slim a large frame, since withoutattributesa base slab is a floor.lightbim_qa:{rule, source, deviation}.rulesays what decided the member (kind,classorshape),sourcewhat placed the axis or plane (extrusionfromnative_geom,extrusion, cuts ignoredwhen the IFC clipped the sweep, ormeshfrom the box around it), anddeviationhow far, in CRS units, the farthest vertex of the mesh lies from the axis (half the section's diagonal) or the plane (half the thickness), or above the bearing level (the height of a footing), or from the centre of gravity's height (a mass; the centre of the box around the mesh when the mesh is not closed).
The axis or the plane comes from the element's largest sweep where native_geom has one,
else from the box; the extent always comes from the mesh, so a clipped beam ends where its
mesh ends. On the Sixty5 structural model every beam, column and pile is a curve on its axis,
every floor and wall a surface on its midplane, and every footing and base slab a support at
its bottom; the reduction takes 1.3 s on top of the 4 s of the footprints.
Known limitations. One straight axis or one flat plane per element: walls with a bent midline (L, T, curved) and folded slabs or curved beams are reduced wrongly (bimpolars#3). Only extruded sweeps are read from the IFC; other bodies place their axis from the box around the mesh.
element_meshes_glb writes the meshes as binary glTF 2.0
(.glb), the format CesiumJS, three.js, Blender and most 3D viewers load:
from pathlib import Path
structure = bdf.filter(pl.col("class").is_in(["IfcColumn", "IfcBeam"]))
Path("structure.glb").write_bytes(bimpolars.element_meshes_glb(structure))- One primitive and one material per style: the faces of every mesh are grouped by the
(name, rgba)of their style, so a viewer colours the model as its authoring tool did (translucent styles getalphaModeBLEND).IfcOpeningElementrows are left out: their mesh is the void they cut. - Metres, from the model's unit (
bdf.crs.axis_info[0]), as glTF requires. The root node carries the BIM CRS asextras.crsand, next to it,extras.unit("metre"): the CRS keeps its own unit, the vertex data under the node does not. - The vertex data keeps the model's z-up coordinates; the root node, named after the CRS,
rotates the scene to glTF's y-up (
bimpolars.gltf.Y_UP_ROTATION, the 3D Tiles convention: model(x, y, z)is scene(x, z, -y)). A child node at the centre of the written vertices' bounding box holds the mesh, so that the float32 vertices stay precise for a model far from the origin. In CesiumJS, place the model withModel.fromGltfAsync({url, modelMatrix, forwardAxis: Cesium.Axis.X})(the default up axis) and the matrix oflinearized_site_to_ecef. normals=True(the default) writes flat-shaded triangles: every triangle gets its own three vertices with the face normal, because the meshes share vertices between faces of different orientation.normals=Falsewrites the vertices and faces as themeshcolumn holds them, indexed and about a quarter of the size, without normals: a glTF reader then computes flat normals (the specification requires it), though CesiumJS renders such a model unlit and three.js smooths it.
read_speckle reads a Speckle version without specklepy, from the
version's v3 objects: the JSON graph of a root collection, DataObjects with their
displayValue meshes, and instances (InstanceProxy, InstanceDefinitionProxy). The objects
come from a local copy of a Speckle download (version_objects), or from the version's
bundle, the Parquet tables Speckle 4 publishes instead, built into objects with specklepy by
bimpolars.bundle.bundle_objects (the [speckle] extra).
import polars as pl
import bimpolars
from bimpolars import data
arch = data.RVT_SPECKLE_ARCH # the Revit Advanced Sample, architecture
objects = bimpolars.version_objects(data.fetch(data.RVT_SPECKLE_V3_OBJECTS), arch.version_id)
bdf = bimpolars.read_speckle(objects, data.fetch_bundle(arch.bundle))
bdf.filter(pl.col("class") == "Walls").select(
"id",
"name",
"container", # the level: a row with class "Levels" and the elevation
family=pl.col("properties").struct.field("object").struct.field("family"),
volume=pl.col("properties")
.struct.field("properties.Parameters.Instance Parameters.Dimensions")
.struct.field("Volume"),
)
from bimpolars.bundle import bundle_objects # the [speckle] extra
bundle = f"{data.DATA_URL}{arch.bundle}" # the bundle's folder, or its URL in the bucket
same = bimpolars.read_speckle(bundle_objects(bundle), bundle)
same.equals(bdf) # True: the bucket's objects were built the same way- One row per element: the objects under the root's
elements, collections traversed, the objects that belong to an instance definition left out. AnInstanceProxyis expanded in place: its definition's meshes (nested instances included), moved by its transform and scaled from theirunitsto the model's. A placement named<applicationId>-instance-Nfolds into the row of<applicationId>, so an element placed several times is one row with one merged mesh.idis theapplicationId(the Revit UniqueId),namethe object's name. - With a bundle, the elements the bundle knows but the version has no object for (Revit
elements specklepy builds no object for: curtain walls, room separations, MEP systems, wires and
circuits) get rows too, with the bundle's category, name, properties and level and a null
mesh, so thatread_speckleandread_ifcboth give one row per element of the model. class: the object'scategory, else the Revit category the bundle has for it, else thespeckle_type. The bundle is where the instances get theirs: specklepy'sModel.to_base()gives anInstanceProxynothing but its transform.properties: a Struct of sets, each a group of the property tree named by its dotted path:propertiesholds the values directly in the object's property bag (elementId,typeId),properties.Parameters.Instance Parameters.Dimensionsa group's values (Volume), andobjectthe object's own fields (family,type). The path is the bundle's eavpathcolumn, so a value is found atf"{set}.{name}". The bundle's values (type parameters included, instance values winning) fill the rows the objects leave bare. A property is a number only when the bundle has a number for every value of it (elementId); otherwise it is text, also where the object carries a number, so a Mark"129"stays text next to"104A"andnamenever becomes a number. A value keeps the unit Revit states for its parameter (the eavunitcolumn: lengths in millimetres, areas in square metres, volumes in cubic metres, theVolumeabove included); it is not scaled to the model unit.- With a bundle, the levels (the envelope's level nodes) become rows of class
Levelswith theirelevationand the idlevel-<node id>, and every element'scontainerpoints at its level, sosimple_featuresplaces the footprints at the level. Without one,containerandelevationare null. meshandbboxin the model's units; quads and n-gons are fan-triangulated. A style is theRenderMaterialthe root'srenderMaterialProxiesgive the mesh, its element or its instance; a definition's mesh without one gets, with a bundle, the material the envelope attaches to the bundle geometry it came from (def-geo-<geometry index>). The first proxy that targets an element wins when several do, and specklepy gives every mesh of an element the element's applicationId, so a layered wall, floor or ceiling (one proxy per layer) is painted in its first layer's material; a material per layer needs the bundle'sDISPLAYorder (bimpolars#20).- The CRS is a plain engineering CRS in the root's
units(else the bundle's, else the unit most meshes name, else metres), anchored at Revit's project base point: the model's own coordinates. The geolocation of a Revit model is never used (the MEP sample sits at Revit's Munich default). Revit exports IFC in shared coordinates, so to compare withread_ifc, move the Speckle model by the bundle'smodelPlacement.options.sharedCoordinates.transform; on the RVT Advanced Sample the plan extents then agree to the micrometre and 85 % of the elements matched by IfcGUID within 1 mm. bundle_objectsbuilds the objects from a bundle on disk with specklepy'sModel.to_base()(specklepy calls it a projection), serialized as a Speckle send would, and restores two thingsto_baseloses. An element placed as an instance keeps the geometry it carries itself: Revit puts structural framing, columns and foundations on the element with an empty definition (841 of the 935 elements of the structural sample), whichto_baseleaves without geometry; it becomes a DataObject under the element's id, the first placement is renamed<id>-instance-0, and the two fold into one row. And the geometry of an instance definition gets the material the envelope attaches to it, so family instances are coloured without the bundle at hand. The bucket'sspeckle-v3-objects.parquetwas built this way, so both routes give equal frames.
uv sync
uv run pytest # BIMPOLARS_DATA_DIR=/path/to/mirror to use local test data
uv run pytest -m slow # only the slow tests, such as the 343 MB architectural model
uv run mypy src
uv run ruff check && uv run ruff format --check