dxf2geo


Namedxf2geo JSON
Version 0.1.3 PyPI version JSON
download
home_pageNone
SummaryConvert CAD DXF data into geospatial formats and visualisations using GeoPandas/Pyogrio.
upload_time2025-08-22 18:45:00
maintainerNone
docs_urlNone
authorKeiran Suchak
requires_python>=3.10
licenseNone
keywords gdal dxf geospatial gis vector conversion
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # dxf2geo

[![PyPI - Version](https://img.shields.io/pypi/v/dxf2geo.svg)](https://pypi.org/project/dxf2geo)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/dxf2geo.svg)](https://pypi.org/project/dxf2geo)
[![Tests](https://github.com/ksuchak1990/dxf2geo/actions/workflows/test.yml/badge.svg)](https://github.com/ksuchak1990/dxf2geo/actions/workflows/test.yml)
[![Lint](https://github.com/ksuchak1990/dxf2geo/actions/workflows/clean_code.yml/badge.svg)](https://github.com/ksuchak1990/dxf2geo/actions/workflows/clean_code.yml)

> [!WARNING]  
> This package is in the early stages of development and should not be installed unless you are one of the developers.

**dxf2geo** is a small Python package for converting CAD `.dxf` files into
geospatial formats such as Shapefiles and GeoPackages, and for producing
interactive visualisations of the extracted geometry.

It is designed to automate the process of extracting geometry by type (point,
line, polygon, etc.), filtering or cleaning the results, and inspecting the
output spatially.

-----

## Table of contents

- [Installation](#installation)
- [Features](#features)
- [Example usage](#example-usage)
- [Filtering options](#layer-filtering)
- [License](#license)

## Installation

`dxf2geo` uses the GDAL Python bindings (`osgeo.*`). 
On supported platforms, `pip install dxf2geo` will pull a compatible `GDAL`
wheel from PyPI.

```bash
pip install dxf2geo
```

If your platform does not have a prebuilt GDAL wheel, install GDAL from your
system/package manager first (or via Conda), then install dxf2geo:

```
sudo apt install gdal-bin libgdal-dev
pip install dxf2geo
```

Before usage, it may be worth verifying your installation to ensure that GDAL is
installed:

```bash
python -c "from osgeo import gdal, ogr; print('GDAL', gdal.VersionInfo(), 'DXF driver:', bool(ogr.GetDriverByName('DXF')))"
```

If the installation has worked, you should see something like `GDAL ##### DXF
driver: True`.

## Features

- Converts DXF files to common vector formats (e.g. Shapefile, GeoPackage),
- Supports geometry filtering by type (e.g., LINESTRING, POLYGON),
- Skips invalid geometries,
- Visualises output geometries in an interactive Plotly-based HTML map,
- Filters out short, axis-aligned DXF gridding lines (optional cleanup step).

## Example usage

Below is an example of using the functionality of this package on a CAD file
`example.dxf`.
This creates a set of shapefiles for of the types of geometry in a new `output/`
directory.

```python
# Imports
from dxf2geo.extract import extract_geometries
from dxf2geo.visualise import (
    load_geometries,
    plot_geometries,
)
from pathlib import Path

# Define paths
input_dxf = Path("./example.dxf").expanduser()
output_dir = Path("output")

# Process CAD file
extract_geometries(input_dxf, output_dir)

# Produce `plotly` html figure
gdf = load_geometries(output_dir)
plot_geometries(gdf, output_dir / "geometry_preview.html")
```

Following this, we would have an output folder that looks like:

```
output/
├── point/
│   └── point.shp
├── linestring/
│   └── linestring.shp
├── polygon/
│   └── polygon.shp
...
└── export.log
```

## Layer filtering

At present we can filter CAD layers based on a number of different criteria.

### Layer name (exact, case-insensitive)

```python
FilterOptions(
    include_layers=("roads", "buildings"),
    exclude_layers=("defpoints", "tmp"),
)
```

### Layer name (regular expressions)

We can also filter layers using **regular expressions** (applied to the CAD
layer name).

```python
FilterOptions(
    # Include any "roads" or "road" layer (case-insensitive), and any layer starting with "bldg_"
    include_layer_patterns=(r"(?i)^roads?$", r"^bldg_.*"),
    # Exclude layers named "defpoints" (any case) or prefixed with "tmp_"
    exclude_layer_patterns=(r"(?i)^defpoints$", r"^tmp_"),
)
```

### Geometry size/structure

```python
# Drop empty geometries and zero-area/length features
FilterOptions(drop_empty=True, drop_zero_geom=True)

# Minimum polygon area
FilterOptions(min_area=5.0)

# Minimum line length
FilterOptions(min_length=10.0)
```

### Spatial bounding box

```python
# (minx, miny, maxx, maxy)
FilterOptions(bbox=(430000.0, 420000.0, 435000.0, 425000.0))
```

### Attribute-value exclusions (exact match)

```python
# Exclude features where fields have disallowed values
FilterOptions(exclude_field_values={
    "EntityType": {"TEXT", "MTEXT"},
    "Linetype": {"HIDDEN"},
})
```

### Geometry type selection (at extraction call)

```python
extract_geometries(
    dxf_path,
    output_root,
    geometry_types=("POINT", "LINESTRING", "POLYGON", "MULTILINESTRING", "MULTIPOLYGON"),
    filter_options=FilterOptions(...),
)
```

## License

`dxf2geo` is distributed under the terms of the
[MIT](https://spdx.org/licenses/MIT.html) license.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "dxf2geo",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "GDAL, DXF, geospatial, GIS, vector, conversion",
    "author": "Keiran Suchak",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/97/1e/ad6e05086e711e328ad9ff9b552afcddb174835ad787603fb86cf7edc558/dxf2geo-0.1.3.tar.gz",
    "platform": null,
    "description": "# dxf2geo\n\n[![PyPI - Version](https://img.shields.io/pypi/v/dxf2geo.svg)](https://pypi.org/project/dxf2geo)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/dxf2geo.svg)](https://pypi.org/project/dxf2geo)\n[![Tests](https://github.com/ksuchak1990/dxf2geo/actions/workflows/test.yml/badge.svg)](https://github.com/ksuchak1990/dxf2geo/actions/workflows/test.yml)\n[![Lint](https://github.com/ksuchak1990/dxf2geo/actions/workflows/clean_code.yml/badge.svg)](https://github.com/ksuchak1990/dxf2geo/actions/workflows/clean_code.yml)\n\n> [!WARNING]  \n> This package is in the early stages of development and should not be installed unless you are one of the developers.\n\n**dxf2geo** is a small Python package for converting CAD `.dxf` files into\ngeospatial formats such as Shapefiles and GeoPackages, and for producing\ninteractive visualisations of the extracted geometry.\n\nIt is designed to automate the process of extracting geometry by type (point,\nline, polygon, etc.), filtering or cleaning the results, and inspecting the\noutput spatially.\n\n-----\n\n## Table of contents\n\n- [Installation](#installation)\n- [Features](#features)\n- [Example usage](#example-usage)\n- [Filtering options](#layer-filtering)\n- [License](#license)\n\n## Installation\n\n`dxf2geo` uses the GDAL Python bindings (`osgeo.*`). \nOn supported platforms, `pip install dxf2geo` will pull a compatible `GDAL`\nwheel from PyPI.\n\n```bash\npip install dxf2geo\n```\n\nIf your platform does not have a prebuilt GDAL wheel, install GDAL from your\nsystem/package manager first (or via Conda), then install dxf2geo:\n\n```\nsudo apt install gdal-bin libgdal-dev\npip install dxf2geo\n```\n\nBefore usage, it may be worth verifying your installation to ensure that GDAL is\ninstalled:\n\n```bash\npython -c \"from osgeo import gdal, ogr; print('GDAL', gdal.VersionInfo(), 'DXF driver:', bool(ogr.GetDriverByName('DXF')))\"\n```\n\nIf the installation has worked, you should see something like `GDAL ##### DXF\ndriver: True`.\n\n## Features\n\n- Converts DXF files to common vector formats (e.g. Shapefile, GeoPackage),\n- Supports geometry filtering by type (e.g., LINESTRING, POLYGON),\n- Skips invalid geometries,\n- Visualises output geometries in an interactive Plotly-based HTML map,\n- Filters out short, axis-aligned DXF gridding lines (optional cleanup step).\n\n## Example usage\n\nBelow is an example of using the functionality of this package on a CAD file\n`example.dxf`.\nThis creates a set of shapefiles for of the types of geometry in a new `output/`\ndirectory.\n\n```python\n# Imports\nfrom dxf2geo.extract import extract_geometries\nfrom dxf2geo.visualise import (\n    load_geometries,\n    plot_geometries,\n)\nfrom pathlib import Path\n\n# Define paths\ninput_dxf = Path(\"./example.dxf\").expanduser()\noutput_dir = Path(\"output\")\n\n# Process CAD file\nextract_geometries(input_dxf, output_dir)\n\n# Produce `plotly` html figure\ngdf = load_geometries(output_dir)\nplot_geometries(gdf, output_dir / \"geometry_preview.html\")\n```\n\nFollowing this, we would have an output folder that looks like:\n\n```\noutput/\n\u251c\u2500\u2500 point/\n\u2502   \u2514\u2500\u2500 point.shp\n\u251c\u2500\u2500 linestring/\n\u2502   \u2514\u2500\u2500 linestring.shp\n\u251c\u2500\u2500 polygon/\n\u2502   \u2514\u2500\u2500 polygon.shp\n...\n\u2514\u2500\u2500 export.log\n```\n\n## Layer filtering\n\nAt present we can filter CAD layers based on a number of different criteria.\n\n### Layer name (exact, case-insensitive)\n\n```python\nFilterOptions(\n    include_layers=(\"roads\", \"buildings\"),\n    exclude_layers=(\"defpoints\", \"tmp\"),\n)\n```\n\n### Layer name (regular expressions)\n\nWe can also filter layers using **regular expressions** (applied to the CAD\nlayer name).\n\n```python\nFilterOptions(\n    # Include any \"roads\" or \"road\" layer (case-insensitive), and any layer starting with \"bldg_\"\n    include_layer_patterns=(r\"(?i)^roads?$\", r\"^bldg_.*\"),\n    # Exclude layers named \"defpoints\" (any case) or prefixed with \"tmp_\"\n    exclude_layer_patterns=(r\"(?i)^defpoints$\", r\"^tmp_\"),\n)\n```\n\n### Geometry size/structure\n\n```python\n# Drop empty geometries and zero-area/length features\nFilterOptions(drop_empty=True, drop_zero_geom=True)\n\n# Minimum polygon area\nFilterOptions(min_area=5.0)\n\n# Minimum line length\nFilterOptions(min_length=10.0)\n```\n\n### Spatial bounding box\n\n```python\n# (minx, miny, maxx, maxy)\nFilterOptions(bbox=(430000.0, 420000.0, 435000.0, 425000.0))\n```\n\n### Attribute-value exclusions (exact match)\n\n```python\n# Exclude features where fields have disallowed values\nFilterOptions(exclude_field_values={\n    \"EntityType\": {\"TEXT\", \"MTEXT\"},\n    \"Linetype\": {\"HIDDEN\"},\n})\n```\n\n### Geometry type selection (at extraction call)\n\n```python\nextract_geometries(\n    dxf_path,\n    output_root,\n    geometry_types=(\"POINT\", \"LINESTRING\", \"POLYGON\", \"MULTILINESTRING\", \"MULTIPOLYGON\"),\n    filter_options=FilterOptions(...),\n)\n```\n\n## License\n\n`dxf2geo` is distributed under the terms of the\n[MIT](https://spdx.org/licenses/MIT.html) license.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Convert CAD DXF data into geospatial formats and visualisations using GeoPandas/Pyogrio.",
    "version": "0.1.3",
    "project_urls": {
        "Homepage": "https://github.com/ksuchak1990/dxf2geo",
        "Issues": "https://github.com/ksuchak1990/dxf2geo/issues",
        "Repository": "https://github.com/ksuchak1990/dxf2geo"
    },
    "split_keywords": [
        "gdal",
        " dxf",
        " geospatial",
        " gis",
        " vector",
        " conversion"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "6d6b18fbe9b108eecb9d1badf76cf5daddb760ea470d8c099df16151c0234244",
                "md5": "309d5ef5772430fbd2d9095aa54a7529",
                "sha256": "a430ba45cdcc9688e81502d0bc1cc6bb17b9e0539078ddd4cc901138390def12"
            },
            "downloads": -1,
            "filename": "dxf2geo-0.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "309d5ef5772430fbd2d9095aa54a7529",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 14657,
            "upload_time": "2025-08-22T18:44:59",
            "upload_time_iso_8601": "2025-08-22T18:44:59.130651Z",
            "url": "https://files.pythonhosted.org/packages/6d/6b/18fbe9b108eecb9d1badf76cf5daddb760ea470d8c099df16151c0234244/dxf2geo-0.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "971ead6e05086e711e328ad9ff9b552afcddb174835ad787603fb86cf7edc558",
                "md5": "40432136ef1427b09720a9782860311b",
                "sha256": "c03fc5029045aaab1f4e5087e95c1e28de7a70989baec67d02bd3c014487fa0c"
            },
            "downloads": -1,
            "filename": "dxf2geo-0.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "40432136ef1427b09720a9782860311b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 16391,
            "upload_time": "2025-08-22T18:45:00",
            "upload_time_iso_8601": "2025-08-22T18:45:00.622027Z",
            "url": "https://files.pythonhosted.org/packages/97/1e/ad6e05086e711e328ad9ff9b552afcddb174835ad787603fb86cf7edc558/dxf2geo-0.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-22 18:45:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ksuchak1990",
    "github_project": "dxf2geo",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "dxf2geo"
}
        
Elapsed time: 1.06525s