Convert CAD DXF data into geospatial formats and visualisations using GeoPandas/Pyogrio.
Project description
dxf2geo
[!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
dxf2geo uses the GDAL Python bindings (osgeo.*).
On supported platforms, pip install dxf2geo will pull a compatible GDAL
wheel from PyPI.
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:
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.
# 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)
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).
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
# 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
# (minx, miny, maxx, maxy)
FilterOptions(bbox=(430000.0, 420000.0, 435000.0, 425000.0))
Attribute-value exclusions (exact match)
# Exclude features where fields have disallowed values
FilterOptions(exclude_field_values={
"EntityType": {"TEXT", "MTEXT"},
"Linetype": {"HIDDEN"},
})
Geometry type selection (at extraction call)
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 license.
Funding
This package is being developed as part of work on the EPSRC Digital Health Hub for Antimicrobial Resistance (EP/X031276/1).
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 dxf2geo-0.1.4.tar.gz.
File metadata
- Download URL: dxf2geo-0.1.4.tar.gz
- Upload date:
- Size: 19.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40686ba58c014afd8d2971700fae33ed95495a3ed57193041231db00febe1f30
|
|
| MD5 |
f0bd09c1843b4c084be7a19c5fdfb284
|
|
| BLAKE2b-256 |
5713b0613dae4f21a4174ae3626759d811a0e4d5148f47266eade46632bf416b
|
Provenance
The following attestation bundles were made for dxf2geo-0.1.4.tar.gz:
Publisher:
publish.yml on ksuchak1990/dxf2geo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dxf2geo-0.1.4.tar.gz -
Subject digest:
40686ba58c014afd8d2971700fae33ed95495a3ed57193041231db00febe1f30 - Sigstore transparency entry: 973533873
- Sigstore integration time:
-
Permalink:
ksuchak1990/dxf2geo@2bdf40b85bf808ac71458ae8c295abc3b0dfb393 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/ksuchak1990
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2bdf40b85bf808ac71458ae8c295abc3b0dfb393 -
Trigger Event:
push
-
Statement type:
File details
Details for the file dxf2geo-0.1.4-py3-none-any.whl.
File metadata
- Download URL: dxf2geo-0.1.4-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49d87e6a65d4da3988404c7fcda7264d78a4c171b594b724b105d6183827b692
|
|
| MD5 |
4b8616afaad0f3c85ce342270b350bd5
|
|
| BLAKE2b-256 |
78bf05a54efbc62cf6354df0f26b2dc9f00a466b990717613c88a82c8e6b4d55
|
Provenance
The following attestation bundles were made for dxf2geo-0.1.4-py3-none-any.whl:
Publisher:
publish.yml on ksuchak1990/dxf2geo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dxf2geo-0.1.4-py3-none-any.whl -
Subject digest:
49d87e6a65d4da3988404c7fcda7264d78a4c171b594b724b105d6183827b692 - Sigstore transparency entry: 973533874
- Sigstore integration time:
-
Permalink:
ksuchak1990/dxf2geo@2bdf40b85bf808ac71458ae8c295abc3b0dfb393 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/ksuchak1990
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2bdf40b85bf808ac71458ae8c295abc3b0dfb393 -
Trigger Event:
push
-
Statement type: