Convert IFC files to DuckDB format for fast analysis and querying
Project description
ifc2duckdb
Convert IFC files to DuckDB format for fast analysis and querying of Building Information Modeling (BIM) data.
Features
- Fast Conversion: Convert IFC files to DuckDB format for high-performance querying
- Full Schema Support: Create complete IFC schema tables or only those present in the file
- Geometry Support: Extract and store 3D geometry data with materials
- Property Sets: Include IFC property set data
- Inverse Relationships: Store entity relationships for complex queries
- Command Line Interface: Easy-to-use CLI for batch processing
- Python API: Programmatic access for integration into larger workflows
Installation
From PyPI (recommended)
pip install ifc2duckdb
From source
git clone https://github.com/chuongmep/ifc-2-duckdb.git
cd ifc-2-duckdb
pip install -e .
Development installation
git clone https://github.com/chuongmep/ifc-2-duckdb.git
cd ifc-2-duckdb
pip install -e ".[dev]"
Requirements
- Python 3.10+
- ifcopenshell >= 1.0.0
- duckdb >= 0.7.0
- numpy >= 1.20.0
- ifcpatch >= 0.1.0
Quick Start
Command Line Usage
# Basic conversion
ifc2duckdb input.ifc output.duckdb
# With options
ifc2duckdb input.ifc --database output.duckdb --no-geometry --verbose
# Help
ifc2duckdb --help
Python API Usage
import ifc2duckdb
import ifcopenshell
# Open IFC file
ifc_file = ifcopenshell.open("racbasicsampleproject.ifc")
# Create patcher with default settings
patcher = ifc2duckdb.Patcher(
ifc_file,
database="output.duckdb"
)
# Convert to DuckDB
patcher.patch()
# Get output path
output_path = patcher.get_output()
print(f"Database created at: {output_path}")
Advanced Usage
import ifc2duckdb
import ifcopenshell
# Open IFC file
ifc_file = ifcopenshell.open("racbasicsampleproject.ifc")
# Create patcher with custom settings
patcher = ifc2duckdb.Patcher(
ifc_file,
database="output.duckdb",
full_schema=False, # Only create tables for classes in the file
is_strict=True, # Strict data type validation
should_expand=True, # Expand entity lists into separate rows
should_get_inverses=True, # Include inverse relationships
should_get_psets=True, # Include property set data
should_get_geometry=True, # Include geometry data
should_skip_geometry_data=False # Include geometry for representation tables
)
# Convert to DuckDB
patcher.patch()
Database Schema
The converted DuckDB database contains several types of tables:
Core Tables
id_map: Maps IFC entity IDs to their class namesmetadata: Contains IFC file metadata (schema, preprocessor info)
IFC Entity Tables
- One table per IFC class (e.g.,
IfcWall,IfcDoor,IfcWindow) - Each table contains all attributes of the IFC entity
- Primary key is
ifc_id(the IFC entity ID)
Geometry Tables
shape: Contains placement and transformation datageometry: Contains mesh data (vertices, edges, faces, materials)
Property Set Tables
psets: Contains property set data in key-value format
Querying Examples
-- Find all walls
SELECT * FROM "IfcWall";
-- Find walls with specific properties
SELECT w.*, p.name, p.value
FROM "IfcWall" w
JOIN psets p ON w.ifc_id = p.ifc_id
WHERE p.pset_name = 'Pset_WallCommon';
-- Get geometry for all elements
SELECT s.*, g.verts, g.faces
FROM shape s
JOIN geometry g ON s.geometry = g.id;
-- Find elements by material
SELECT s.ifc_id, g.materials
FROM shape s
JOIN geometry g ON s.geometry = g.id
WHERE g.materials LIKE '%concrete%';
Development
Running Tests
# Run all tests
pytest
# Run with coverage
pytest --cov=ifc2duckdb --cov-report=html
# Run specific test file
pytest tests/test_patcher.py
Code Formatting
# Format code
black ifc2duckdb tests
isort ifc2duckdb tests
# Check formatting
black --check ifc2duckdb tests
isort --check-only ifc2duckdb tests
Type Checking
mypy ifc2duckdb --ignore-missing-imports
Linting
flake8 ifc2duckdb tests
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests and linting (
make test lint) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the GNU Lesser General Public License v3.0 or later (LGPL-3.0-or-later) - see the LICENSE file for details.
Acknowledgments
- Based on the Ifc2Sql recipe from IfcOpenShell
- Inspired by the XbimEssentials project
- Built on top of IfcOpenShell and DuckDB
References
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ifc2duckdb-0.1.2.tar.gz.
File metadata
- Download URL: ifc2duckdb-0.1.2.tar.gz
- Upload date:
- Size: 844.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96a3c2a9f7f97983aa0a261143cf31dccfc7505e1b537f43d90cfe0a42d1fe05
|
|
| MD5 |
d1f4a346bb0d629149dfd4feed099fc4
|
|
| BLAKE2b-256 |
3e3e9514c0da549c0acad6fb56e987d0f1db22b1683be0237bd644775a7f5c31
|
File details
Details for the file ifc2duckdb-0.1.2-py3-none-any.whl.
File metadata
- Download URL: ifc2duckdb-0.1.2-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36306fbbb71f8564d7019b9c6c2e548b8fc034c73adc384b02558d57071d2965
|
|
| MD5 |
8f6e60dacf74edcf3cb2e7c7cb5a8d7a
|
|
| BLAKE2b-256 |
c6c2a3fa952e759a71d9d6cc5ba8b67d80e0b7d2f4d22e3b549bd70c991069ac
|