netcad-ncz 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- netcad_ncz-1.0.0/LICENSE +21 -0
- netcad_ncz-1.0.0/PKG-INFO +55 -0
- netcad_ncz-1.0.0/README.md +42 -0
- netcad_ncz-1.0.0/ncz/README.md +36 -0
- netcad_ncz-1.0.0/ncz/__init__.py +11 -0
- netcad_ncz-1.0.0/ncz/ncz_reader.py +178 -0
- netcad_ncz-1.0.0/netcad_ncz.egg-info/PKG-INFO +55 -0
- netcad_ncz-1.0.0/netcad_ncz.egg-info/SOURCES.txt +12 -0
- netcad_ncz-1.0.0/netcad_ncz.egg-info/dependency_links.txt +1 -0
- netcad_ncz-1.0.0/netcad_ncz.egg-info/entry_points.txt +2 -0
- netcad_ncz-1.0.0/netcad_ncz.egg-info/top_level.txt +1 -0
- netcad_ncz-1.0.0/pyproject.toml +42 -0
- netcad_ncz-1.0.0/setup.cfg +4 -0
- netcad_ncz-1.0.0/tests/test_ncz.py +101 -0
netcad_ncz-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Samet Hüseyin Can
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: netcad-ncz
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Netcad NCZ (8.x) dosya okuyucu: katmanlar, nokta, çizgi, poligon, yazı; GeoJSON çıktısı.
|
|
5
|
+
Author: Samet Hüseyin Can
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://samethcan.github.io/netcad-araclari/
|
|
8
|
+
Project-URL: Source, https://github.com/samethcan/netcad-araclari
|
|
9
|
+
Project-URL: Documentation, https://samethcan.github.io/netcad-araclari/ncz-bicimi/
|
|
10
|
+
Keywords: netcad,ncz,cbs,gis,kadastro,harita,geojson
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Natural Language :: Turkish
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: GIS
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# netcad-ncz
|
|
21
|
+
|
|
22
|
+
Netcad 8.x **NCZ** dosyalarını Python ile okur: katmanlar, noktalar, çizgiler, poligonlar ve yazılar. Sonucu **GeoJSON** olarak verir, böylece QGIS, ArcGIS ya da herhangi bir CBS yazılımında açılabilir.
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
pip install netcad-ncz
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Komut satırı
|
|
29
|
+
```
|
|
30
|
+
ncz-oku dosya.ncz
|
|
31
|
+
ncz-oku dosya.ncz --geojson dosya.geojson
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Python
|
|
35
|
+
```python
|
|
36
|
+
import netcad_ncz
|
|
37
|
+
|
|
38
|
+
r = netcad_ncz.read("dosya.ncz")
|
|
39
|
+
print(netcad_ncz.summary(r)) # katmanlar ve nesne sayıları
|
|
40
|
+
for f in r["feats"]:
|
|
41
|
+
print(f["layer"], f["type"], f.get("label"), f["pts"][:2])
|
|
42
|
+
|
|
43
|
+
gj = netcad_ncz.to_geojson(r) # FeatureCollection (dict)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
- Koordinatlar dosyadaki projeksiyonda kalır; sıra **(Y doğu, X kuzey)**, yani Netcad ekranındaki sağa/yukarı.
|
|
47
|
+
- Metinler Türkçe Windows kod sayfasıyla (cp1254) çözülür.
|
|
48
|
+
- Bağımlılık yoktur, yalnızca Python standart kütüphanesi.
|
|
49
|
+
|
|
50
|
+
## Uyarı
|
|
51
|
+
NCZ biçimi resmî olarak belgelenmemiştir; bu okuyucu Netcad 8.5.x dosyaları incelenerek yazılmıştır. Biçim notları: [NCZ dosya biçimi](https://samethcan.github.io/netcad-araclari/ncz-bicimi/).
|
|
52
|
+
|
|
53
|
+
Netcad, Netcad Yazılım A.Ş.'nin markasıdır. Bu paket bağımsızdır, Netcad ile resmî bir ilişkisi yoktur.
|
|
54
|
+
|
|
55
|
+
Kaynak kod ve diğer araçlar: https://github.com/samethcan/netcad-araclari · Lisans: MIT
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# netcad-araclari
|
|
2
|
+
|
|
3
|
+
[](https://github.com/samethcan/netcad-araclari/actions/workflows/tests.yml)
|
|
4
|
+
|
|
5
|
+
Netcad kullanan harita büroları, kurumlar ve tüm harita mühendisi ve teknikerleri için küçük, bağımsız araçlar. Depoda **yalnızca kod ve belge** vardır; hiçbir kuruma ait parsel, pafta, koordinat, belge ya da görüntü verisi yoktur. Örnekler tamamen uydurmadır.
|
|
6
|
+
|
|
7
|
+
**Canlı demo (kurulum gerekmez):** https://samethcan.github.io/netcad-araclari/
|
|
8
|
+
- [Aplikasyon Alan Hesabı](https://samethcan.github.io/netcad-araclari/aplikasyon/aplikasyon_alan_hesabi.html)
|
|
9
|
+
- [3B Pafta İndeksi (uydurma veri)](https://samethcan.github.io/netcad-araclari/demo/pafta-indeksi-3b/)
|
|
10
|
+
- [Netcad NCZ dosya biçimi (Türkçe anlatım)](https://samethcan.github.io/netcad-araclari/ncz-bicimi/)
|
|
11
|
+
|
|
12
|
+
**NCZ okuyucu Python paketi:** `pip install netcad-ncz` → `ncz-oku dosya.ncz --geojson dosya.geojson`
|
|
13
|
+
|
|
14
|
+
| Klasör | İçerik |
|
|
15
|
+
|---|---|
|
|
16
|
+
| `ncz/` | `ncz_reader.py`: Netcad 8.x NCZ okuyucu (katmanlar, nokta, çizgi, poligon, yazı, pafta çerçevesi). `NCZ_FORMAT.md`: biçim notları. |
|
|
17
|
+
| `aplikasyon/` | `aplikasyon_alan_hesabi.html`: Aplikasyon belgesinden köşe koordinatlarını alıp alan hesabı, tapu–hesap alanı ve yanılma sınırı kontrolü yapan, **doğrudan NCZ** (ve DXF/NCN/rapor) üreten tek dosyalık sayfa. |
|
|
18
|
+
| `pafta-indeksi-3b/` | Parselin hangi paftalara girdiğini gösteren, telefonda da çalışan 3B pafta indeksi (MapLibre). `ornek_veri.py` uydurma veriyle deneme paketi üretir. |
|
|
19
|
+
| `kadastro/` | `kad.py`: Açık kadastro pafta çizgilerinden numaralı pafta alanları üretir (düğümleme + boşluk kapatma). |
|
|
20
|
+
| `geodezi/` | ITRF 1/1000 pafta adı hesabı ve tapu alanı yanılma sınırı. |
|
|
21
|
+
|
|
22
|
+
## Gereksinimler
|
|
23
|
+
- Python 3.10+, `shapely>=2.0` (kadastro ve örnek veri için)
|
|
24
|
+
- Pafta indeksi derlemesi için `maplibre-gl@4.7.1` paketi (`npm pack maplibre-gl@4.7.1`)
|
|
25
|
+
|
|
26
|
+
## Pafta indeksini uydurma veriyle denemek
|
|
27
|
+
```
|
|
28
|
+
cd pafta-indeksi-3b
|
|
29
|
+
python ornek_veri.py ornek.b64
|
|
30
|
+
python build.py --veri ornek.b64 --maplibre <maplibre-gl/package/dist>
|
|
31
|
+
```
|
|
32
|
+
`cikti/index.html` tarayıcıda açılır.
|
|
33
|
+
|
|
34
|
+
## Uyarılar
|
|
35
|
+
- NCZ biçimi resmî olarak belgelenmemiştir; notlar tersine mühendisliktir. Üretilen dosyaları Netcad'de kontrol edin.
|
|
36
|
+
- Yanılma sınırı fonksiyonundaki 0–10 m² kuralı doğrulanmamıştır.
|
|
37
|
+
|
|
38
|
+
## Lisans
|
|
39
|
+
MIT açık kaynak yazılım lisansı (yazılım kullanım izni; üniversite ile ilgisi yoktur): kod ücretsiz kullanılabilir, değiştirilebilir ve dağıtılabilir, yeter ki telif notu korunsun. Ayrıntı için `LICENSE`. `demo/pafta-indeksi-3b/` içindeki derlenmiş demo MapLibre GL JS (BSD-3) içerir; lisansı `MAPLIBRE_LICENSE.txt`.
|
|
40
|
+
|
|
41
|
+
## English
|
|
42
|
+
Open-source tools for surveyors and GIS professionals working with **Netcad**: a Python reader for the undocumented Netcad 8.x **NCZ** format (`pip install netcad-ncz`, GeoJSON export), a browser tool that computes parcel areas from cadastral setting-out (aplikasyon) documents and writes NCZ/DXF files, and a mobile-friendly 3D map-sheet index. No institutional data is included; all samples are synthetic. Live demo: https://samethcan.github.io/netcad-araclari/
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# netcad-ncz
|
|
2
|
+
|
|
3
|
+
Netcad 8.x **NCZ** dosyalarını Python ile okur: katmanlar, noktalar, çizgiler, poligonlar ve yazılar. Sonucu **GeoJSON** olarak verir, böylece QGIS, ArcGIS ya da herhangi bir CBS yazılımında açılabilir.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
pip install netcad-ncz
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Komut satırı
|
|
10
|
+
```
|
|
11
|
+
ncz-oku dosya.ncz
|
|
12
|
+
ncz-oku dosya.ncz --geojson dosya.geojson
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Python
|
|
16
|
+
```python
|
|
17
|
+
import netcad_ncz
|
|
18
|
+
|
|
19
|
+
r = netcad_ncz.read("dosya.ncz")
|
|
20
|
+
print(netcad_ncz.summary(r)) # katmanlar ve nesne sayıları
|
|
21
|
+
for f in r["feats"]:
|
|
22
|
+
print(f["layer"], f["type"], f.get("label"), f["pts"][:2])
|
|
23
|
+
|
|
24
|
+
gj = netcad_ncz.to_geojson(r) # FeatureCollection (dict)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
- Koordinatlar dosyadaki projeksiyonda kalır; sıra **(Y doğu, X kuzey)**, yani Netcad ekranındaki sağa/yukarı.
|
|
28
|
+
- Metinler Türkçe Windows kod sayfasıyla (cp1254) çözülür.
|
|
29
|
+
- Bağımlılık yoktur, yalnızca Python standart kütüphanesi.
|
|
30
|
+
|
|
31
|
+
## Uyarı
|
|
32
|
+
NCZ biçimi resmî olarak belgelenmemiştir; bu okuyucu Netcad 8.5.x dosyaları incelenerek yazılmıştır. Biçim notları: [NCZ dosya biçimi](https://samethcan.github.io/netcad-araclari/ncz-bicimi/).
|
|
33
|
+
|
|
34
|
+
Netcad, Netcad Yazılım A.Ş.'nin markasıdır. Bu paket bağımsızdır, Netcad ile resmî bir ilişkisi yoktur.
|
|
35
|
+
|
|
36
|
+
Kaynak kod ve diğer araçlar: https://github.com/samethcan/netcad-araclari · Lisans: MIT
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""Netcad NCZ (8.x) okuyucu.
|
|
2
|
+
|
|
3
|
+
import netcad_ncz
|
|
4
|
+
r = netcad_ncz.read('dosya.ncz')
|
|
5
|
+
print(netcad_ncz.summary(r))
|
|
6
|
+
gj = netcad_ncz.to_geojson(r)
|
|
7
|
+
"""
|
|
8
|
+
from .ncz_reader import blocks, layer_names, main, read, summary, to_geojson
|
|
9
|
+
|
|
10
|
+
__all__ = ['blocks', 'layer_names', 'main', 'read', 'summary', 'to_geojson']
|
|
11
|
+
__version__ = '1.0.0'
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"""Netcad NCZ okuyucu (8.x düzeni, tersine mühendislik bilgisiyle).
|
|
2
|
+
|
|
3
|
+
Blok düzeni: [kind u8][len u32 LE][payload], blok toplamı = len + 5.
|
|
4
|
+
Geometri blokları: kind 21 (düz) / 22 (GIS nesnesi, +28 kayma).
|
|
5
|
+
Kayıt içinde (blok başına göre): tip +6, katman kodu +7, ilk koordinat +8/+16 (X kuzey, Y doğu).
|
|
6
|
+
Tip 7 (çoklu çizgi/poligon): köşeler +113(+kayma)'dan, her biri 24 bayt (f64 X, f64 Y, f64 Z).
|
|
7
|
+
Tip 1 (nokta): ad uzunluğu +86, ad +87.
|
|
8
|
+
Tip 5 (yazı): yükseklik f32 +86, dönüklük f32 +90, metin uzunluğu +97, metin +98 (cp1254).
|
|
9
|
+
Tip 7 etiket: uzunluk +86, metin +87 (kayıt içinde en çok 10 karakter; daha uzun ad bir önceki kind 33 bloğunda tam olarak durur); bayrak i32 +101 (1 kapalı, 2 dolgu, 16 adlı).
|
|
10
|
+
Tip 15 (akıllı nesne): len alanı 81 B eksik — blocks() düzeltir. Katman için +7 kullan (her sürümde güvenilir).
|
|
11
|
+
Katman tablosu: kind 6, adet u16 @+16, 29 baytlık kayıtlar @+18 (ad uzunluğu r[4], ad r[5:]).
|
|
12
|
+
Çıktı koordinatları: (Y doğu, X kuzey) — Netcad ekranındaki sağa/yukarı.
|
|
13
|
+
"""
|
|
14
|
+
import struct
|
|
15
|
+
from collections import Counter
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def u32(b, o):
|
|
19
|
+
return int.from_bytes(b[o:o + 4], 'little')
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
KNOWN_KINDS = {1, 2, 3, 4, 5, 6, 8, 10, 11, 12, 13, 14, 15, 16, 21, 22, 23, 25, 26, 27, 28, 29, 30, 31, 33}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _ok_next(b, q):
|
|
26
|
+
"""q konumunda geçerli bir blok başlığı var mı (ya da dosya sonu mu)?"""
|
|
27
|
+
if q == len(b):
|
|
28
|
+
return True
|
|
29
|
+
return q + 5 <= len(b) and b[q] in KNOWN_KINDS and q + u32(b, q + 1) + 5 <= len(b)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def blocks(b):
|
|
33
|
+
"""Blok yürüyüşü. Tip 15 (akıllı nesne) kayıtlarında len alanı gövdeden sonra gelen
|
|
34
|
+
81 baytlık başlığı saymaz (8.5.1 gerçek dosyada doğrulandı); sonraki başlık geçerli
|
|
35
|
+
değilse +81 denenir."""
|
|
36
|
+
out, p = [], 0
|
|
37
|
+
while p + 5 <= len(b):
|
|
38
|
+
n = u32(b, p + 1) + 5
|
|
39
|
+
if b[p] in (21, 22) and p + 7 <= len(b) and b[p + 6] == 15 and not _ok_next(b, p + n) and _ok_next(b, p + n + 81):
|
|
40
|
+
n += 81
|
|
41
|
+
if n < 5 or p + n > len(b):
|
|
42
|
+
out.append((p, None, len(b) - p))
|
|
43
|
+
break
|
|
44
|
+
out.append((p, b[p], n))
|
|
45
|
+
p += n
|
|
46
|
+
return out
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _s(b, o, maxlen=255):
|
|
50
|
+
L = b[o]
|
|
51
|
+
if maxlen < L or o + 1 + L > len(b):
|
|
52
|
+
return None
|
|
53
|
+
return b[o + 1:o + 1 + L].decode('cp1254', 'replace')
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def layer_names(b, bl):
|
|
57
|
+
for o, k, _n in bl:
|
|
58
|
+
if k == 6:
|
|
59
|
+
cnt = int.from_bytes(b[o + 16:o + 18], 'little')
|
|
60
|
+
names = []
|
|
61
|
+
for i in range(cnt):
|
|
62
|
+
r = b[o + 18 + i * 29:o + 18 + (i + 1) * 29]
|
|
63
|
+
if len(r) < 29:
|
|
64
|
+
break
|
|
65
|
+
names.append(r[5:5 + r[4]].decode('cp1254', 'replace'))
|
|
66
|
+
return names
|
|
67
|
+
return []
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def read(path):
|
|
71
|
+
with open(path, 'rb') as fh:
|
|
72
|
+
b = fh.read()
|
|
73
|
+
bl = blocks(b)
|
|
74
|
+
names = layer_names(b, bl)
|
|
75
|
+
feats, kinds, broken = [], Counter(), [x for x in bl if x[1] is None]
|
|
76
|
+
ext = None # kind 33: sonraki nesnenin tam adı (nokta/alan) ya da yazı devamı
|
|
77
|
+
for o, k, n in bl:
|
|
78
|
+
kinds[k] += 1
|
|
79
|
+
if k == 33:
|
|
80
|
+
ext = _s(b, o + 11)
|
|
81
|
+
continue
|
|
82
|
+
if k not in (21, 22) or n < 30:
|
|
83
|
+
ext = None if k not in (21, 22) else ext
|
|
84
|
+
continue
|
|
85
|
+
sh = 0 if k == 21 else 28
|
|
86
|
+
t, lc = b[o + 6], b[o + 7]
|
|
87
|
+
f = {'off': o, 'kind': k, 'type': t, 'lcode': lc,
|
|
88
|
+
'layer': names[lc] if lc < len(names) else f'#{lc}'}
|
|
89
|
+
try:
|
|
90
|
+
if t == 7:
|
|
91
|
+
cnt = (n - 113 - sh) // 24
|
|
92
|
+
v = [struct.unpack_from('<dd', b, o + 113 + sh + 24 * i) for i in range(cnt)]
|
|
93
|
+
f['pts'] = [(y, x) for x, y in v]
|
|
94
|
+
f['label'] = _s(b, o + 86 + sh, 30)
|
|
95
|
+
elif t == 1:
|
|
96
|
+
x, y = struct.unpack_from('<dd', b, o + 8)
|
|
97
|
+
f['pts'] = [(y, x)]
|
|
98
|
+
f['label'] = _s(b, o + 86 + sh, 40)
|
|
99
|
+
elif t == 5:
|
|
100
|
+
x, y = struct.unpack_from('<dd', b, o + 8)
|
|
101
|
+
f['pts'] = [(y, x)]
|
|
102
|
+
f['h'], f['rot'] = struct.unpack_from('<ff', b, o + 86 + sh)
|
|
103
|
+
f['text'] = _s(b, o + 97 + sh)
|
|
104
|
+
else:
|
|
105
|
+
x, y = struct.unpack_from('<dd', b, o + 8)
|
|
106
|
+
f['pts'] = [(y, x)]
|
|
107
|
+
except struct.error:
|
|
108
|
+
f['err'] = True
|
|
109
|
+
if ext:
|
|
110
|
+
if t in (1, 7) and f.get('label') and ext.startswith(f['label']):
|
|
111
|
+
f['label'] = ext # kayıt içi ad 10 karakterde kesilir; tam ad kind 33'te
|
|
112
|
+
elif t == 5 and f.get('text') is not None:
|
|
113
|
+
f['text'] = f['text'] + ext # yazı kaydı 50 karakterde biter; devamı kind 33'te
|
|
114
|
+
ext = None
|
|
115
|
+
feats.append(f)
|
|
116
|
+
return {'bytes': len(b), 'blocks': len(bl), 'broken': broken, 'kinds': kinds,
|
|
117
|
+
'layers': names, 'feats': feats}
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def summary(r):
|
|
121
|
+
c = Counter((f['layer'], f['type'], f['kind']) for f in r['feats'])
|
|
122
|
+
lines = [f"{r['bytes']} bayt, {r['blocks']} blok, kırık: {len(r['broken'])}",
|
|
123
|
+
'katmanlar: ' + ', '.join(r['layers'])]
|
|
124
|
+
for (lay, t, k), m in sorted(c.items(), key=lambda z: (-z[1])):
|
|
125
|
+
lines.append(f' {lay:<20} tip={t:<3} kind={k} adet={m}')
|
|
126
|
+
return '\n'.join(lines)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def to_geojson(r):
|
|
130
|
+
"""read() sonucunu GeoJSON FeatureCollection'a çevirir.
|
|
131
|
+
|
|
132
|
+
Koordinatlar dosyadaki projeksiyonda kalır (dönüşüm yapılmaz), sıra (Y doğu, X kuzey).
|
|
133
|
+
Tip 7: ilk ve son köşe aynıysa Polygon, değilse LineString. Diğer tipler: Point.
|
|
134
|
+
"""
|
|
135
|
+
feats = []
|
|
136
|
+
for f in r['feats']:
|
|
137
|
+
pts = f.get('pts')
|
|
138
|
+
if not pts or f.get('err'):
|
|
139
|
+
continue
|
|
140
|
+
props = {'katman': f['layer'], 'tip': f['type']}
|
|
141
|
+
if f.get('label'):
|
|
142
|
+
props['ad'] = f['label']
|
|
143
|
+
if f.get('text') is not None:
|
|
144
|
+
props.update(yazi=f['text'], yukseklik=f.get('h'), donukluk=f.get('rot'))
|
|
145
|
+
if f['type'] == 7 and len(pts) >= 2:
|
|
146
|
+
if len(pts) >= 4 and pts[0] == pts[-1]:
|
|
147
|
+
geom = {'type': 'Polygon', 'coordinates': [[list(q) for q in pts]]}
|
|
148
|
+
else:
|
|
149
|
+
geom = {'type': 'LineString', 'coordinates': [list(q) for q in pts]}
|
|
150
|
+
else:
|
|
151
|
+
geom = {'type': 'Point', 'coordinates': list(pts[0])}
|
|
152
|
+
feats.append({'type': 'Feature', 'geometry': geom, 'properties': props})
|
|
153
|
+
return {'type': 'FeatureCollection', 'features': feats}
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def main(argv=None):
|
|
157
|
+
"""Komut satırı: ncz-oku dosya.ncz [dosya2.ncz ...] [--geojson cikti.geojson]"""
|
|
158
|
+
import argparse
|
|
159
|
+
import json
|
|
160
|
+
ap = argparse.ArgumentParser(prog='ncz-oku', description='Netcad NCZ dosyasının özetini yazar, isteğe bağlı GeoJSON üretir.')
|
|
161
|
+
ap.add_argument('dosya', nargs='+', help='.ncz dosya(lar)ı')
|
|
162
|
+
ap.add_argument('--geojson', metavar='CIKTI', help='tek dosya için GeoJSON çıktı yolu')
|
|
163
|
+
a = ap.parse_args(argv)
|
|
164
|
+
if a.geojson and len(a.dosya) != 1:
|
|
165
|
+
ap.error('--geojson yalnızca tek dosyayla kullanılabilir')
|
|
166
|
+
for p in a.dosya:
|
|
167
|
+
r = read(p)
|
|
168
|
+
print(p)
|
|
169
|
+
print(summary(r))
|
|
170
|
+
if a.geojson:
|
|
171
|
+
with open(a.geojson, 'w', encoding='utf-8') as fh:
|
|
172
|
+
json.dump(to_geojson(r), fh, ensure_ascii=False)
|
|
173
|
+
print(f'GeoJSON yazıldı: {a.geojson}')
|
|
174
|
+
return 0
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
if __name__ == '__main__':
|
|
178
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: netcad-ncz
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Netcad NCZ (8.x) dosya okuyucu: katmanlar, nokta, çizgi, poligon, yazı; GeoJSON çıktısı.
|
|
5
|
+
Author: Samet Hüseyin Can
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://samethcan.github.io/netcad-araclari/
|
|
8
|
+
Project-URL: Source, https://github.com/samethcan/netcad-araclari
|
|
9
|
+
Project-URL: Documentation, https://samethcan.github.io/netcad-araclari/ncz-bicimi/
|
|
10
|
+
Keywords: netcad,ncz,cbs,gis,kadastro,harita,geojson
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Natural Language :: Turkish
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: GIS
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# netcad-ncz
|
|
21
|
+
|
|
22
|
+
Netcad 8.x **NCZ** dosyalarını Python ile okur: katmanlar, noktalar, çizgiler, poligonlar ve yazılar. Sonucu **GeoJSON** olarak verir, böylece QGIS, ArcGIS ya da herhangi bir CBS yazılımında açılabilir.
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
pip install netcad-ncz
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Komut satırı
|
|
29
|
+
```
|
|
30
|
+
ncz-oku dosya.ncz
|
|
31
|
+
ncz-oku dosya.ncz --geojson dosya.geojson
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Python
|
|
35
|
+
```python
|
|
36
|
+
import netcad_ncz
|
|
37
|
+
|
|
38
|
+
r = netcad_ncz.read("dosya.ncz")
|
|
39
|
+
print(netcad_ncz.summary(r)) # katmanlar ve nesne sayıları
|
|
40
|
+
for f in r["feats"]:
|
|
41
|
+
print(f["layer"], f["type"], f.get("label"), f["pts"][:2])
|
|
42
|
+
|
|
43
|
+
gj = netcad_ncz.to_geojson(r) # FeatureCollection (dict)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
- Koordinatlar dosyadaki projeksiyonda kalır; sıra **(Y doğu, X kuzey)**, yani Netcad ekranındaki sağa/yukarı.
|
|
47
|
+
- Metinler Türkçe Windows kod sayfasıyla (cp1254) çözülür.
|
|
48
|
+
- Bağımlılık yoktur, yalnızca Python standart kütüphanesi.
|
|
49
|
+
|
|
50
|
+
## Uyarı
|
|
51
|
+
NCZ biçimi resmî olarak belgelenmemiştir; bu okuyucu Netcad 8.5.x dosyaları incelenerek yazılmıştır. Biçim notları: [NCZ dosya biçimi](https://samethcan.github.io/netcad-araclari/ncz-bicimi/).
|
|
52
|
+
|
|
53
|
+
Netcad, Netcad Yazılım A.Ş.'nin markasıdır. Bu paket bağımsızdır, Netcad ile resmî bir ilişkisi yoktur.
|
|
54
|
+
|
|
55
|
+
Kaynak kod ve diğer araçlar: https://github.com/samethcan/netcad-araclari · Lisans: MIT
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
ncz/README.md
|
|
5
|
+
ncz/__init__.py
|
|
6
|
+
ncz/ncz_reader.py
|
|
7
|
+
netcad_ncz.egg-info/PKG-INFO
|
|
8
|
+
netcad_ncz.egg-info/SOURCES.txt
|
|
9
|
+
netcad_ncz.egg-info/dependency_links.txt
|
|
10
|
+
netcad_ncz.egg-info/entry_points.txt
|
|
11
|
+
netcad_ncz.egg-info/top_level.txt
|
|
12
|
+
tests/test_ncz.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
netcad_ncz
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "netcad-ncz"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Netcad NCZ (8.x) dosya okuyucu: katmanlar, nokta, çizgi, poligon, yazı; GeoJSON çıktısı."
|
|
9
|
+
readme = "ncz/README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
authors = [{ name = "Samet Hüseyin Can" }]
|
|
13
|
+
requires-python = ">=3.10"
|
|
14
|
+
keywords = ["netcad", "ncz", "cbs", "gis", "kadastro", "harita", "geojson"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
"Natural Language :: Turkish",
|
|
19
|
+
"Topic :: Scientific/Engineering :: GIS",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[project.urls]
|
|
23
|
+
Homepage = "https://samethcan.github.io/netcad-araclari/"
|
|
24
|
+
Source = "https://github.com/samethcan/netcad-araclari"
|
|
25
|
+
Documentation = "https://samethcan.github.io/netcad-araclari/ncz-bicimi/"
|
|
26
|
+
|
|
27
|
+
[project.scripts]
|
|
28
|
+
ncz-oku = "netcad_ncz.ncz_reader:main"
|
|
29
|
+
|
|
30
|
+
[tool.setuptools]
|
|
31
|
+
packages = ["netcad_ncz"]
|
|
32
|
+
package-dir = { netcad_ncz = "ncz" }
|
|
33
|
+
|
|
34
|
+
[tool.ruff]
|
|
35
|
+
line-length = 130
|
|
36
|
+
|
|
37
|
+
[tool.ruff.lint]
|
|
38
|
+
select = ["E4", "E7", "E9", "F", "I", "SIM", "B"]
|
|
39
|
+
ignore = ["E701", "E702", "E741"]
|
|
40
|
+
|
|
41
|
+
[tool.pytest.ini_options]
|
|
42
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""netcad_ncz okuyucu testleri.
|
|
2
|
+
|
|
3
|
+
fixtures/ornek_100.ncz: depodaki aplikasyon aracının NCZ yazıcısıyla, uydurma
|
|
4
|
+
örnek veriden (100 ada, 3 parsel, 8 köşe) üretilmiştir; kurum verisi içermez.
|
|
5
|
+
"""
|
|
6
|
+
import json
|
|
7
|
+
import struct
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
import netcad_ncz as ncz
|
|
11
|
+
import pytest
|
|
12
|
+
|
|
13
|
+
FIX = Path(__file__).parent / 'fixtures' / 'ornek_100.ncz'
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def shoelace(pts):
|
|
17
|
+
return abs(sum(x1 * y2 - x2 * y1 for (x1, y1), (x2, y2) in zip(pts, pts[1:], strict=False))) / 2
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@pytest.fixture(scope='module')
|
|
21
|
+
def r():
|
|
22
|
+
return ncz.read(FIX)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test_blok_zinciri_tam(r):
|
|
26
|
+
assert r['broken'] == []
|
|
27
|
+
assert r['bytes'] == FIX.stat().st_size
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_katmanlar(r):
|
|
31
|
+
assert r['layers'] == ['0', 'PARSEL', 'NOKTA']
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_parseller_ve_alanlar(r):
|
|
35
|
+
parseller = {f['label']: f for f in r['feats'] if f['layer'] == 'PARSEL' and f['type'] == 7}
|
|
36
|
+
assert sorted(parseller) == ['100/1', '100/2', '100/3']
|
|
37
|
+
for f in parseller.values():
|
|
38
|
+
assert f['pts'][0] == f['pts'][-1]
|
|
39
|
+
assert shoelace(f['pts']) == pytest.approx(150.0)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def test_noktalar(r):
|
|
43
|
+
noktalar = {f['label']: f['pts'][0] for f in r['feats'] if f['layer'] == 'NOKTA' and f['type'] == 1}
|
|
44
|
+
assert sorted(noktalar) == [f'K{i}' for i in range(1, 9)]
|
|
45
|
+
assert noktalar['K1'] == (1000.0, 2015.0) # (Y doğu, X kuzey)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_geojson(r):
|
|
49
|
+
gj = ncz.to_geojson(r)
|
|
50
|
+
tipler = [f['geometry']['type'] for f in gj['features']]
|
|
51
|
+
assert tipler.count('Polygon') == 3
|
|
52
|
+
assert tipler.count('Point') >= 8
|
|
53
|
+
json.dumps(gj) # JSON'a yazılabilir olmalı
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def test_komut_satiri(tmp_path, capsys):
|
|
57
|
+
out = tmp_path / 'c.geojson'
|
|
58
|
+
assert ncz.main([str(FIX), '--geojson', str(out)]) == 0
|
|
59
|
+
assert 'PARSEL' in capsys.readouterr().out
|
|
60
|
+
assert len(json.loads(out.read_text(encoding='utf-8'))['features']) >= 11
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _blok(kind, govde):
|
|
64
|
+
return bytes([kind]) + struct.pack('<I', len(govde)) + govde
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _katman_tablosu(adlar):
|
|
68
|
+
g = bytearray(11) + struct.pack('<H', len(adlar)) # adet @+16 (5 baytlık blok başı + 11)
|
|
69
|
+
for ad in adlar:
|
|
70
|
+
b = ad.encode('cp1254')
|
|
71
|
+
r = bytearray(29)
|
|
72
|
+
r[4] = len(b)
|
|
73
|
+
r[5:5 + len(b)] = b
|
|
74
|
+
g += r
|
|
75
|
+
return _blok(6, bytes(g))
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _nesne(tip, katman, x, y, etiket='', koseler=()):
|
|
79
|
+
g = bytearray(108) # gövde: blok başından +5
|
|
80
|
+
g[1], g[2] = tip, katman # tip @+6, katman @+7
|
|
81
|
+
g[3:19] = struct.pack('<dd', x, y) # X @+8, Y @+16
|
|
82
|
+
e = etiket.encode('cp1254')
|
|
83
|
+
g[81] = len(e) # etiket uzunluğu @+86
|
|
84
|
+
g[82:82 + len(e)] = e
|
|
85
|
+
for kx, ky in koseler: # köşeler @+113
|
|
86
|
+
g += struct.pack('<ddd', kx, ky, 0.0)
|
|
87
|
+
return _blok(21, bytes(g))
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def test_elle_kurulan_dosya(tmp_path):
|
|
91
|
+
kare = [(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)] # (X kuzey, Y doğu)
|
|
92
|
+
veri = (_blok(1, bytes(90)) + _katman_tablosu(['0', 'YAPI', 'Şev'])
|
|
93
|
+
+ _nesne(7, 1, 0, 0, 'B1', kare) + _nesne(1, 2, 5.0, 7.0, 'N1'))
|
|
94
|
+
p = tmp_path / 'elle.ncz'
|
|
95
|
+
p.write_bytes(veri)
|
|
96
|
+
r = ncz.read(p)
|
|
97
|
+
assert r['broken'] == [] and r['layers'] == ['0', 'YAPI', 'Şev']
|
|
98
|
+
poli, nokta = [f for f in r['feats']]
|
|
99
|
+
assert (poli['layer'], poli['label'], len(poli['pts'])) == ('YAPI', 'B1', 5)
|
|
100
|
+
assert shoelace(poli['pts']) == pytest.approx(100.0)
|
|
101
|
+
assert (nokta['layer'], nokta['label'], nokta['pts']) == ('Şev', 'N1', [(7.0, 5.0)])
|