cad2geo
Pure-Python Netcad NCZ/NCA CAD Inspection and High-Performance GeoJSON Conversion Engine.
📖 Open Interactive Web Manual (GitHub Pages) • 📦 PyPI Package • 🐛 Issue Tracker
🌟 Overview
cad2geo is a lightweight, zero-dependency Python library for inspecting Netcad NCZ (compressed archive) and NCA (raw binary CAD drawing stream) files and converting CAD geometries into OGC-compliant GeoJSON datasets.
Extracted from the high-value headless core of the 02CadGis and PlanX geospatial ecosystem, cad2geo operates 100% headless using only Python's standard library (struct, zlib, dataclasses, json). It requires zero proprietary CAD installations, zero QGIS runtimes, and zero GDAL C-extensions.
🔬 Key Capabilities
- Pure-Python NCZ/NCA Binary Block Scanner:
- Directly decompresses zlib archive containers and parses binary stream records for Points, Lines, Polylines, Arcs, Circles, Text annotations, and Polygons.
- $\mathcal{O}(1)$ Fast Layer Catalog Inspection:
- Scans file headers in under 5 milliseconds, extracting layer codes, layer names, line types, display colors, and record counts without decompressing coordinates.
- Selective Layer Decoding & Memory Optimization:
- Skips unneeded byte blocks in the binary stream when decoding specific layers (e.g.
layers=[1, 3, 7]), saving up to 90% RAM on massive municipal zoning plans (100MB+ NCZ files).
- Skips unneeded byte blocks in the binary stream when decoding specific layers (e.g.
- Mathematical Curve & Arc Discretization:
- Converts circular arcs and curves into piecewise linear GIS LineStrings using exact sagitta chord tolerance ($\delta$) calculations.
- Cadastral & Zoning Attribute Preservation:
- Captures parcel IDs (Ada / Parsel), zoning parameters (KAKS, TAKS, Yençok), layer styles, text labels, and geometric perimeters.
- Standard GeoJSON FeatureCollection Serialization:
- Generates clean, standards-compliant GeoJSON with CRS headers and styling properties for immediate GIS web mapping.
📦 Installation
pip install cad2geo
🚀 Quickstart & Python API
1. Fast Layer Catalog Inspection
Inspect drawing layers and entity counts in milliseconds without loading full geometry:
from cad2geo import inspect_source
layers = inspect_source("imar_plani.ncz")
for layer in layers:
print(f"Layer #{layer.layer_code:02d}: {layer.layer_name:<25} | Entities: {layer.record_count}")
2. Selective Decoding & GeoJSON Export
Decode only specific zoning boundaries and save directly as GeoJSON:
from cad2geo import parse_netcad, write_geojson
# Decode only layers 1, 3, and 7
result = parse_netcad("imar_plani.ncz", target_layers=[1, 3, 7])
print(f"Successfully decoded {len(result.entities)} entities across {len(result.layers)} layers.")
# Export to OGC GeoJSON FeatureCollection
write_geojson(result.entities, "zoning_boundaries.geojson")
3. In-Memory Parsing & Custom Processing
Integrate into FastAPI endpoints, AWS Lambda, or Jupyter Notebooks:
from cad2geo import parse_bytes, entities_to_feature_collection
with open("parcels.ncz", "rb") as f:
raw_bytes = f.read()
result = parse_bytes(raw_bytes)
geojson_dict = entities_to_feature_collection(result.entities)
print(f"Features in GeoJSON: {len(geojson_dict['features'])}")
💻 Command Line Interface (CLI)
cad2geo comes with a high-performance CLI utility:
# 1. Quick inspection of NCZ layer definitions
cad2geo inspect imar_plani.ncz
# 2. Output layer metadata as machine-readable JSON
cad2geo inspect imar_plani.ncz --json
# 3. Convert full drawing to GeoJSON
cad2geo convert imar_plani.ncz master_plan.geojson
# 4. Selective layer extraction with pretty-printed JSON formatting
cad2geo convert imar_plani.ncz road_centerlines.geojson --layers 2,5 --pretty
📊 Netcad Entity Mapping Matrix
| Netcad CAD Entity | Internal Type | GeoJSON Target | Extracted Properties & Attributes |
|---|---|---|---|
| Point / Nokta | TYPE_POINT |
Point |
Point name, point code, elevation ($Z$), layer ID |
| Line / Çizgi | TYPE_LINE |
LineString |
Length, line style, color, layer code |
| Polyline / Çoklu Doğru | TYPE_PLINE |
LineString / Polygon |
Closed flag, vertices, perimeter, area |
| Arc / Yay | TYPE_ARC |
LineString (Tessellated) |
Center, radius, start angle, end angle |
| Circle / Çember | TYPE_CIRCLE |
Polygon (Tessellated) |
Center, radius, circumference, area |
| Text / Yazı | TYPE_TEXT |
Point |
Text string, height, rotation angle, justification |
| Polygon / Alan | TYPE_POLYGON |
Polygon / MultiPolygon |
Parcel number (Ada/Parsel), zoning attribute table |
⚡ Performance Benchmarks
Benchmarked on complex municipal zoning drawings (100MB+ NCZ archives):
| Operation | Dataset Size | Entities | cad2geo Execution Time | Throughput |
|---|---|---|---|---|
| Layer Catalog Inspection | 50 MB NCZ Plan | 150,000 Entities | 4.2 ms | $\mathcal{O}(1)$ Header Scan |
| Selective Layer Decode | 50 MB NCZ Plan | 12,500 Entities | 48.6 ms | 257,000 entities/sec |
| Full GeoJSON Conversion | 25 MB NCZ Cadastre | 85,000 Entities | 182.4 ms | 466,000 entities/sec |
🧪 Development & Testing
# Clone the repository
git clone https://github.com/YusufEminoglu/cad2geo.git
cd cad2geo
# Install in editable mode with development dependencies
pip install -e ".[dev]"
# Run test suite
pytest tests/ -v --cov=cad2geo
# Run linter and type checks
ruff check .
mypy src
📄 Academic Citation
If you use cad2geo in scientific research, GIS data engineering pipelines, or academic publications, please cite:
@software{eminoglu2026cad2geo,
author = {Emino{\u{g}}lu, Yusuf},
title = {{cad2geo: Pure-Python Netcad NCZ/NCA CAD Parser and High-Performance GeoJSON Engine}},
year = {2026},
publisher = {PyPI - Python Package Index},
version = {0.1.0},
url = {https://github.com/YusufEminoglu/cad2geo}
}
📜 License & Lineage
Distributed under the GPL-2.0-or-later license. The NCZ decoding lineage and third-party notices are documented in THIRD_PARTY_NOTICES.md.
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 cad2geo-0.2.0.tar.gz.
File metadata
- Download URL: cad2geo-0.2.0.tar.gz
- Upload date:
- Size: 46.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd904a3e8f95b06cfab572abdd7071cafdfebe9369ca38676ae41ff1dc765363
|
|
| MD5 |
1a5b6776dda34142315999393b37cf93
|
|
| BLAKE2b-256 |
bc789e6efbac701a2f9444f1441507e7ee6189b1bc4ab46be89b1dae71ecdb31
|
Provenance
The following attestation bundles were made for cad2geo-0.2.0.tar.gz:
Publisher:
publish.yml on YusufEminoglu/cad2geo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cad2geo-0.2.0.tar.gz -
Subject digest:
bd904a3e8f95b06cfab572abdd7071cafdfebe9369ca38676ae41ff1dc765363 - Sigstore transparency entry: 2590529931
- Sigstore integration time:
-
Permalink:
YusufEminoglu/cad2geo@44410c182b82b5879b7560efec9502f626108996 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/YusufEminoglu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@44410c182b82b5879b7560efec9502f626108996 -
Trigger Event:
release
-
Statement type:
File details
Details for the file cad2geo-0.2.0-py3-none-any.whl.
File metadata
- Download URL: cad2geo-0.2.0-py3-none-any.whl
- Upload date:
- Size: 41.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d566a4b23337ebb45b90e6f6867da4990980687cd95040aed6b5324b08dda809
|
|
| MD5 |
c7dfdd95c1136599c77a217c92c8893a
|
|
| BLAKE2b-256 |
564d6d33aad86206e04119c0c272e1470023c16ede002f0539f94ce41ae69156
|
Provenance
The following attestation bundles were made for cad2geo-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on YusufEminoglu/cad2geo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cad2geo-0.2.0-py3-none-any.whl -
Subject digest:
d566a4b23337ebb45b90e6f6867da4990980687cd95040aed6b5324b08dda809 - Sigstore transparency entry: 2590530532
- Sigstore integration time:
-
Permalink:
YusufEminoglu/cad2geo@44410c182b82b5879b7560efec9502f626108996 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/YusufEminoglu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@44410c182b82b5879b7560efec9502f626108996 -
Trigger Event:
release
-
Statement type: