Skip to main content

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.

Python Version License Code style: black

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 names
  • metadata: 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 data
  • geometry: 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

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests and linting (make test lint)
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. 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

References

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

ifc2duckdb-0.1.0.tar.gz (844.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ifc2duckdb-0.1.0-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file ifc2duckdb-0.1.0.tar.gz.

File metadata

  • Download URL: ifc2duckdb-0.1.0.tar.gz
  • Upload date:
  • Size: 844.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for ifc2duckdb-0.1.0.tar.gz
Algorithm Hash digest
SHA256 70394e1fa2c35468c08b4f3315fa9a2da93d2d076323e022aa9e18bfd58b6717
MD5 c4ed357f9f7fd03879a2781282ac0709
BLAKE2b-256 19e02dfc41da511ed747693dd4b5f5320ff9351aa72237c6788b13be68d2c9de

See more details on using hashes here.

File details

Details for the file ifc2duckdb-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ifc2duckdb-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for ifc2duckdb-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a6da38c227adadbc0a782d6219705c6c782254601773dbf7e29c8344dd2c30b4
MD5 1457789b33dc4e6aa3e13aba9719a5fe
BLAKE2b-256 a5ebfd061d363319265829f52bcb2fa98d815aefd1db035f04d649f34af98729

See more details on using hashes here.

Supported by

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