Skip to main content
cad2geo logo

cad2geo

CI PyPI version Python version support Documentation License: GPL-2.0-or-later Code style: Ruff Test Coverage

Pure-Python Netcad NCZ/NCA CAD Inspection and High-Performance GeoJSON Conversion Engine.

📖 Open Interactive Web Manual (GitLab 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

  1. 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.
  2. $\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.
  3. 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).
  4. Mathematical Curve & Arc Discretization:
    • Converts circular arcs and curves into piecewise linear GIS LineStrings using exact sagitta chord tolerance ($\delta$) calculations.
  5. Cadastral & Zoning Attribute Preservation:
    • Captures parcel IDs (Ada / Parsel), zoning parameters (KAKS, TAKS, Yençok), layer styles, text labels, and geometric perimeters.
  6. 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://gitlab.com/geospacephilo/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://gitlab.com/geospacephilo/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.

Metadata

Release files for cad2geo 0.12.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cad2geo 0.12.0
File Size Uploaded
cad2geo-0.12.0.tar.gz 82.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cad2geo 0.12.0
File Interpreter ABI Platform
cad2geo-0.12.0-py3-none-any.whl Python 3 none any Details

Total release size: 160.4 kB

Release files / cad2geo-0.12.0.tar.gz

Download URL cad2geo-0.12.0.tar.gz
Size 82.4 kB
Tags Source
SHA-256 checksum
How to use checksums
6009f885f85a3e67c447eddaf2143ca60e1bc8980f74edb6d92fe928819c181e
BLAKE2b-256 checksum
How to use checksums
6637d2f393c132436199c63b6c4c4b0892260c5985c3e6ca5bb73738b0ce0d4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release files / cad2geo-0.12.0-py3-none-any.whl

Download URL cad2geo-0.12.0-py3-none-any.whl
Size 78.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
56d889ec794001278f9504ecbc575035a9e7753787a01cbd6a709899dced95f2
BLAKE2b-256 checksum
How to use checksums
584f22328ca89cd6b68226c9e8d06d0d537daeb43afb797b67ce41d153c7543a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release history Release notifications | RSS feed

This release

0.12.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page