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 (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

  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://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

cad2geo-0.2.0.tar.gz (46.4 kB view details)

Uploaded Source

Built Distribution

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

cad2geo-0.2.0-py3-none-any.whl (41.7 kB view details)

Uploaded Python 3

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

Hashes for cad2geo-0.2.0.tar.gz
Algorithm Hash digest
SHA256 bd904a3e8f95b06cfab572abdd7071cafdfebe9369ca38676ae41ff1dc765363
MD5 1a5b6776dda34142315999393b37cf93
BLAKE2b-256 bc789e6efbac701a2f9444f1441507e7ee6189b1bc4ab46be89b1dae71ecdb31

See more details on using hashes here.

Provenance

The following attestation bundles were made for cad2geo-0.2.0.tar.gz:

Publisher: publish.yml on YusufEminoglu/cad2geo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for cad2geo-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d566a4b23337ebb45b90e6f6867da4990980687cd95040aed6b5324b08dda809
MD5 c7dfdd95c1136599c77a217c92c8893a
BLAKE2b-256 564d6d33aad86206e04119c0c272e1470023c16ede002f0539f94ce41ae69156

See more details on using hashes here.

Provenance

The following attestation bundles were made for cad2geo-0.2.0-py3-none-any.whl:

Publisher: publish.yml on YusufEminoglu/cad2geo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.0

2 files

Supported by

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