mapgis2shp 2.2.0__tar.gz → 2.3.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.
Files changed (26) hide show
  1. {mapgis2shp-2.2.0 → mapgis2shp-2.3.0}/CITATION.cff +2 -2
  2. {mapgis2shp-2.2.0 → mapgis2shp-2.3.0}/PKG-INFO +122 -11
  3. {mapgis2shp-2.2.0 → mapgis2shp-2.3.0}/README.md +120 -10
  4. {mapgis2shp-2.2.0 → mapgis2shp-2.3.0}/docs/MapGIS_Vector_Format.md +43 -11
  5. {mapgis2shp-2.2.0 → mapgis2shp-2.3.0}/pyproject.toml +12 -1
  6. mapgis2shp-2.3.0/src/pymapgis/__init__.py +59 -0
  7. {mapgis2shp-2.2.0 → mapgis2shp-2.3.0}/src/pymapgis/_version.py +1 -1
  8. mapgis2shp-2.3.0/src/pymapgis/cli.py +262 -0
  9. mapgis2shp-2.3.0/src/pymapgis/linesty.py +539 -0
  10. {mapgis2shp-2.2.0 → mapgis2shp-2.3.0}/src/pymapgis/reader.py +58 -27
  11. mapgis2shp-2.3.0/src/pymapgis/slib.py +331 -0
  12. mapgis2shp-2.3.0/src/pymapgis/writer.py +1102 -0
  13. {mapgis2shp-2.2.0 → mapgis2shp-2.3.0}/verify_pymapgis.py +243 -170
  14. mapgis2shp-2.2.0/src/pymapgis/__init__.py +0 -23
  15. mapgis2shp-2.2.0/src/pymapgis/cli.py +0 -50
  16. mapgis2shp-2.2.0/src/pymapgis/rendering/__init__.py +0 -40
  17. mapgis2shp-2.2.0/src/pymapgis/rendering/ir.py +0 -56
  18. mapgis2shp-2.2.0/src/pymapgis/rendering/palette.py +0 -94
  19. mapgis2shp-2.2.0/src/pymapgis/rendering/pattern_engine.py +0 -136
  20. mapgis2shp-2.2.0/src/pymapgis/rendering/pdf_writer.py +0 -1216
  21. mapgis2shp-2.2.0/src/pymapgis/rendering/symbol_engine.py +0 -587
  22. {mapgis2shp-2.2.0 → mapgis2shp-2.3.0}/.gitignore +0 -0
  23. {mapgis2shp-2.2.0 → mapgis2shp-2.3.0}/LICENSE +0 -0
  24. {mapgis2shp-2.2.0 → mapgis2shp-2.3.0}/docs/sld_export.md +0 -0
  25. {mapgis2shp-2.2.0 → mapgis2shp-2.3.0}/pymapgis_baseline.json +0 -0
  26. {mapgis2shp-2.2.0 → mapgis2shp-2.3.0}/src/pymapgis/__main__.py +0 -0
@@ -8,7 +8,7 @@ abstract: >-
8
8
  reference system, reconstructs polygon topology, and returns GeoPandas
9
9
  GeoDataFrames / shapefiles, enabling Chinese geological-survey data locked
10
10
  in the proprietary MapGIS format to enter the open-source geospatial stack.
11
- version: "2.2.0"
11
+ version: "2.2.1"
12
12
  date-released: 2026-09-05
13
13
  license: Apache-2.0
14
14
  repository-code: https://github.com/leecugb/mapgis2shp
@@ -68,7 +68,7 @@ preferred-citation:
68
68
  - given-names: Zengyun
69
69
  family-names: Zuo
70
70
  affiliation: Xi'an Mineral Resources Survey, China Geological Survey
71
- version: "2.2.0"
71
+ version: "2.2.1"
72
72
  date-released: 2026-09-05
73
73
  license: Apache-2.0
74
74
  repository-code: https://github.com/leecugb/mapgis2shp
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: mapgis2shp
3
- Version: 2.2.0
3
+ Version: 2.3.0
4
4
  Summary: MapGIS is a widely used closed-source GIS platform in China, especially in geological surveying, engineering, and scientific research. pymapgis provides a lightweight, open-source reader for its native point, line, and polygon vector formats.
5
5
  Project-URL: Homepage, https://github.com/leecugb/mapgis2shp
6
6
  Project-URL: Repository, https://github.com/leecugb/mapgis2shp.git
@@ -212,6 +212,7 @@ Requires-Python: >=3.9
212
212
  Requires-Dist: geopandas>=0.12
213
213
  Requires-Dist: numpy>=1.21
214
214
  Requires-Dist: pandas>=1.3
215
+ Requires-Dist: pyogrio>=0.8
215
216
  Requires-Dist: pyproj>=3.2
216
217
  Requires-Dist: shapely>=2.0
217
218
  Provides-Extra: dev
@@ -229,23 +230,28 @@ Description-Content-Type: text/markdown
229
230
  [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)
230
231
  [![DOI](https://img.shields.io/badge/DOI-10.5281%2Fzenodo.21487339-blue.svg)](https://doi.org/10.5281/zenodo.21487339)
231
232
 
232
- Read MapGIS 6.x/67 vector files (`.wt`, `.wl`, `.wp`) into [GeoPandas](https://geopandas.org/) GeoDataFrames.
233
+ Read **and write** MapGIS 6.x/67 vector files (`.wt`, `.wl`, `.wp`) with [GeoPandas](https://geopandas.org/) GeoDataFrames.
233
234
 
234
- MapGIS is a widely used closed-source GIS platform in China, especially in geological surveying, engineering, and scientific research. `pymapgis` provides a lightweight, open-source reader for its native point, line, and polygon vector formats.
235
+ MapGIS is a widely used closed-source GIS platform in China, especially in geological surveying, engineering, and scientific research. `pymapgis` provides a lightweight, open-source reader **and writer** for its native point, line, and polygon vector formats.
235
236
 
236
237
  > **Relationship to prior work:** This package (`mapgis2shp`, import name `pymapgis`) is the matured, validated successor to the first author's earlier [`pymapgis`](https://github.com/leecugb/pymapgis) (2022) single-file reader — both developed by **Shijie Li** (leecugb). The present version adds coordinate-reference inference, vectorised parsing, polygon-topology reconstruction, and independent validation against the official MapGIS export.
237
238
 
238
239
  ## Features
239
240
 
240
241
  - Read **point** (`.wt`), **line** (`.wl`), and **polygon** (`.wp`) files
242
+ - **Write** GeoDataFrames back to native `.wt` / `.wl` / `.wp` binaries (round-trip lossless)
241
243
  - Decode GBK-encoded attribute fields and field names
242
244
  - Decode point graphic parameters (text/symbol kind, subgraph number, glyph size, rotation angle)
243
- - Decode line graphic parameters (style number, width in mm, pattern coefficients)
245
+ - Decode line graphic parameters (style and auxiliary style numbers, colour index, width in mm, pattern coefficients)
244
246
  - Decode polygon graphic parameters (fill colour / pattern numbers from the head_9 section)
245
- - Reconstruct polygon topology from arc records
247
+ - Parse the MapGIS 6.x graphic libraries themselves — `SubgraphLib` for
248
+ `Subgraph.lib` point-symbol definitions (including chained records past
249
+ the index table) and `LinestyLib` for `LINESTY.lib` line-style definitions
250
+ (sublines, element templates, dot/dash rhythm, pen tables)
251
+ - Reconstruct polygon topology from arc records — and regenerate it on write (shared boundaries stored as single arcs)
246
252
  - Preserve or repair invalid polygon geometries with `shapely.make_valid`
247
253
  - Export to any format supported by GeoPandas / Fiona (Shapefile, GeoJSON, GeoPackage, etc.)
248
- - Simple command-line interface for quick conversions
254
+ - Simple command-line interface for quick conversions in both directions
249
255
 
250
256
  ## Installation
251
257
 
@@ -283,9 +289,23 @@ pymapgis input.wl output.geojson --driver GeoJSON
283
289
 
284
290
  # Keep raw (possibly invalid) polygon geometries
285
291
  pymapgis input.wp output.shp --no-make-valid
292
+
293
+ # Convert a Shapefile (or GeoJSON/GeoPackage) back to MapGIS
294
+ pymapgis input.shp output.wp
295
+ pymapgis input.geojson output.wl --encoding GBK
296
+
297
+ # Also decode graphic parameters (style/colour numbers, width, symbol
298
+ # number, angle, ...) into extra attribute columns
299
+ pymapgis input.wp output.gpkg --graphic-params
300
+
301
+ # Inspect a MapGIS graphic library (symbol / line-style definitions)
302
+ pymapgis lib Subgraph.lib # symbol counts (indexed + tail chain)
303
+ pymapgis lib Subgraph.lib --symbol 1960 # decode one symbol's geometry
304
+ pymapgis lib LINESTY.lib # whole-library census
305
+ pymapgis lib LINESTY.lib --style 211 --aux 0 # decode one line style
286
306
  ```
287
307
 
288
- The same interface is available as `python -m pymapgis input.wp output.shp`.
308
+ The direction is chosen from the **input** extension: `.wt`/`.wl`/`.wp` input reads MapGIS; any other input writes MapGIS. The same interface is available as `python -m pymapgis input.wp output.shp`.
289
309
 
290
310
  ## API
291
311
 
@@ -320,6 +340,14 @@ file type — point parameters for `.wt` (as above), line parameters for
320
340
  **Methods**
321
341
 
322
342
  - `to_file(filepath, **kwargs)` — forward to `GeoDataFrame.to_file`
343
+ - `len(reader)` — number of features
344
+ - `str(reader)` — summary (`"n features (type POINT)"`); `repr(reader)` shows the constructor arguments
345
+ - Context manager: `with Reader(...) as r:` (the file is fully parsed and closed in the constructor)
346
+
347
+ ### Constants
348
+
349
+ - `POINT_TYPE_TEXT` (0) / `POINT_TYPE_SYMBOL` (1) — values of the `point_type` column for `.wt` graphic parameters
350
+ - `pymapgis.__version__` — package version string
323
351
 
324
352
  ### Exceptions
325
353
 
@@ -327,6 +355,52 @@ file type — point parameters for `.wt` (as above), line parameters for
327
355
  - `InvalidFileError` — unsupported or unrecognized file
328
356
  - `TopoError` — polygon topology reconstruction error
329
357
  - `InvalidDirectoryError` — reserved for project/directory errors
358
+ - `WriterError` — a GeoDataFrame cannot be encoded as a MapGIS file
359
+
360
+ ### `Writer(geodataframe, *, make_valid=True, map_scale=1000.0, snap_tolerance=0.0, graphic_params=True, geometry_type=None)`
361
+
362
+ Encode a GeoDataFrame as a MapGIS binary file. One geometry type per file:
363
+ Point/MultiPoint for `.wt` (MultiPoint is exploded with a warning),
364
+ LineString/MultiLineString for `.wl` (exploded likewise), and
365
+ Polygon/MultiPolygon for `.wp` (a MultiPolygon stays one polygon feature,
366
+ matching the reader).
367
+
368
+ ```python
369
+ from pymapgis import Writer, write
370
+
371
+ Writer(gdf).to_file("out.wp") # or the shortcut: write(gdf, "out.wp")
372
+ ```
373
+
374
+ - `make_valid` — repair invalid polygons before arc decomposition (.wp only)
375
+ - `map_scale` — map-scale denominator for projected CRS (coordinates are
376
+ stored as `value * 1000 / map_scale`); ignored for longitude/latitude data
377
+ - `snap_tolerance` — coordinate quantisation step applied before topology
378
+ construction so that shared boundaries coincide byte-exactly (0 = exact)
379
+ - `graphic_params` — when the frame carries the reader's graphic-parameter
380
+ columns (`point_type`/`symbol_no`/..., `linetype`/...,
381
+ `fill_color`/`pattern`/`pattern_color`), write them back into the
382
+ graphic-parameter areas instead of the attribute table, giving
383
+ mapgis → shp → mapgis parameter fidelity
384
+ - `geometry_type` — explicit `"POINT"`/`"LINE"`/`"POLYGON"` for empty frames
385
+
386
+ Writing regenerates polygon topology: adjacent polygons share single arcs,
387
+ with left/right polygon IDs derived from ring orientation, so the output
388
+ re-reads losslessly with `Reader`. Attributes are encoded with MapGIS field
389
+ types inferred from pandas dtypes (GBK strings, dates, times, numbers);
390
+ unsupported columns raise `WriterError`.
391
+
392
+ **Write-side limitations**
393
+
394
+ - `.wt` label text stored in auxiliary annotation sections is not produced;
395
+ written `.wt` files carry geometry, attributes, and symbol points only
396
+ - Shapefile's 10-character field-name limit truncates long parameter columns
397
+ (e.g. `pattern_color` → `pattern_col`) when passing through `.shp`, which
398
+ disables the matching parameter group on write; GeoJSON/GeoPackage or a
399
+ direct GeoDataFrame hand-off is unaffected
400
+ - Longitude/latitude, Transverse Mercator, Albers, and Lambert CRS are
401
+ written; other projections raise `WriterError`
402
+ - CGCS2000 has no MapGIS ellipsoid code and is written as WGS84 with a
403
+ warning (they agree to better than 0.1 mm)
330
404
 
331
405
  ## Reading graphic parameters
332
406
 
@@ -342,9 +416,11 @@ with Reader("points.wt", read_graphic_params=True) as r:
342
416
  symbols = r.geodataframe[r.geodataframe.point_type == POINT_TYPE_SYMBOL]
343
417
  print(symbols[["symbol_no", "height", "width", "angle"]].head())
344
418
 
345
- # Line files: style number, width in millimetres, pattern coefficients
419
+ # Line files: style and auxiliary style numbers, colour index, width in
420
+ # millimetres, pattern coefficients
346
421
  with Reader("lines.wl", read_graphic_params=True) as r:
347
- print(r.geodataframe[["linetype", "width", "x_coef", "y_coef"]].head())
422
+ print(r.geodataframe[["linetype", "aux_linetype", "color",
423
+ "width", "x_coef", "y_coef"]].head())
348
424
 
349
425
  # Polygon files: fill colour / pattern numbers (head_9 section)
350
426
  with Reader("polygons.wp", read_graphic_params=True) as r:
@@ -359,6 +435,32 @@ with Reader("polygons.wp", read_graphic_params=True) as r:
359
435
  > layouts were reverse-engineered and validated on the layers of map sheet
360
436
  > J43C001002 — verify against your own data before relying on them.
361
437
 
438
+ ## Parsing the graphic libraries
439
+
440
+ The library files referenced by the graphic parameters can be parsed
441
+ directly (the same parsers back the `pymapgis lib` subcommand):
442
+
443
+ ```python
444
+ from pymapgis import LinestyLib, SubgraphLib, classify_form, compose_feature_style
445
+
446
+ # Subgraph.lib: point-symbol geometry (mm coordinates, subpaths, fitted circles)
447
+ lib = SubgraphLib("Subgraph.lib")
448
+ print(lib.n_indexed, "indexed +", lib.n_tail, "tail-chain symbols")
449
+ sym = lib.decode(1960) # None when out of range
450
+ for sp in sym.subpaths:
451
+ print(len(sp.points), "points", sp.circle) # circle = (cx, cy, r) fit
452
+
453
+ # LINESTY.lib: line styles (1-based, as stored in .wl linetype fields)
454
+ styles = LinestyLib("LINESTY.lib")
455
+ style = styles.decode(211)
456
+ print(classify_form(style)) # form label + evidence
457
+ main, aux = compose_feature_style(styles, 211, 0) # (style, aux) pair rule
458
+ ```
459
+
460
+ Line-style style numbers and symbol numbers are *library-local*: they
461
+ resolve only against the same (or a byte-identical) library that produced
462
+ the data.
463
+
362
464
  ## Supported formats
363
465
 
364
466
  | Extension | Geometry type | Graphic parameters | Notes |
@@ -728,6 +830,15 @@ String fields are read up to the first `\x00`. Date fields are year (int16) + mo
728
830
 
729
831
  ## Changelog
730
832
 
833
+ ### Unreleased
834
+ - **Writer**: encode GeoDataFrames back to native MapGIS `.wt` / `.wl` / `.wp` binaries — attribute table (GBK strings, dates, times, typed numerics), graphic parameters (with mapgis → shp → mapgis fidelity when the reader's parameter columns are present), CRS (longitude/latitude, Transverse Mercator, Albers, Lambert), and regenerated polygon topology (shared boundaries stored as single arcs with left/right polygon IDs). New public API: `Writer`, `write()`, and `WriterError`
835
+ - CLI converts in both directions based on the input extension (`.shp`, `.geojson`, `.gpkg`, ... → `.wt`/`.wl`/`.wp`); new `--encoding` option
836
+ - New runtime dependency: `pyogrio>=0.8` (reading shapefiles is now a runtime feature)
837
+ - `verify_pymapgis.py --roundtrip`: Reader → Writer → Reader regression over all local MapGIS files (not recorded in the baseline)
838
+
839
+ ### 2.2.1
840
+ - Packaging fix: `pymapgis.rendering` is under active development and is not yet ready for distribution (it is also undocumented and requires matplotlib, which is not a declared dependency). It is now excluded from the wheel and sdist; the published package again focuses on reading/conversion. The module remains in the source repository and will be published as a separate package or extra once it stabilises
841
+
731
842
  ### 2.2.0
732
843
  - `read_graphic_params=True`: decode line graphic parameters (`.wl`: `linetype`, `aux_linetype`, `width`, `x_coef`, `y_coef`) and polygon graphic parameters (`.wp` head_9 section: `fill_color`, `pattern`, `pattern_color`), exposed as `line_params` / `polygon_params` and joined into the GeoDataFrame
733
844
  - Format documentation: line graphic-parameter area (bytes 18–56), polygon head_9 section, additional `.wl` index sections
@@ -745,8 +856,8 @@ String fields are read up to the first `\x00`. Date fields are year (int16) + mo
745
856
  Clone the repository and install in editable mode with dev dependencies:
746
857
 
747
858
  ```bash
748
- git clone https://github.com/pymapgis/pymapgis.git
749
- cd pymapgis
859
+ git clone https://github.com/leecugb/mapgis2shp.git
860
+ cd mapgis2shp
750
861
  pip install -e ".[dev]"
751
862
  ```
752
863
 
@@ -5,23 +5,28 @@
5
5
  [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)
6
6
  [![DOI](https://img.shields.io/badge/DOI-10.5281%2Fzenodo.21487339-blue.svg)](https://doi.org/10.5281/zenodo.21487339)
7
7
 
8
- Read MapGIS 6.x/67 vector files (`.wt`, `.wl`, `.wp`) into [GeoPandas](https://geopandas.org/) GeoDataFrames.
8
+ Read **and write** MapGIS 6.x/67 vector files (`.wt`, `.wl`, `.wp`) with [GeoPandas](https://geopandas.org/) GeoDataFrames.
9
9
 
10
- MapGIS is a widely used closed-source GIS platform in China, especially in geological surveying, engineering, and scientific research. `pymapgis` provides a lightweight, open-source reader for its native point, line, and polygon vector formats.
10
+ MapGIS is a widely used closed-source GIS platform in China, especially in geological surveying, engineering, and scientific research. `pymapgis` provides a lightweight, open-source reader **and writer** for its native point, line, and polygon vector formats.
11
11
 
12
12
  > **Relationship to prior work:** This package (`mapgis2shp`, import name `pymapgis`) is the matured, validated successor to the first author's earlier [`pymapgis`](https://github.com/leecugb/pymapgis) (2022) single-file reader — both developed by **Shijie Li** (leecugb). The present version adds coordinate-reference inference, vectorised parsing, polygon-topology reconstruction, and independent validation against the official MapGIS export.
13
13
 
14
14
  ## Features
15
15
 
16
16
  - Read **point** (`.wt`), **line** (`.wl`), and **polygon** (`.wp`) files
17
+ - **Write** GeoDataFrames back to native `.wt` / `.wl` / `.wp` binaries (round-trip lossless)
17
18
  - Decode GBK-encoded attribute fields and field names
18
19
  - Decode point graphic parameters (text/symbol kind, subgraph number, glyph size, rotation angle)
19
- - Decode line graphic parameters (style number, width in mm, pattern coefficients)
20
+ - Decode line graphic parameters (style and auxiliary style numbers, colour index, width in mm, pattern coefficients)
20
21
  - Decode polygon graphic parameters (fill colour / pattern numbers from the head_9 section)
21
- - Reconstruct polygon topology from arc records
22
+ - Parse the MapGIS 6.x graphic libraries themselves — `SubgraphLib` for
23
+ `Subgraph.lib` point-symbol definitions (including chained records past
24
+ the index table) and `LinestyLib` for `LINESTY.lib` line-style definitions
25
+ (sublines, element templates, dot/dash rhythm, pen tables)
26
+ - Reconstruct polygon topology from arc records — and regenerate it on write (shared boundaries stored as single arcs)
22
27
  - Preserve or repair invalid polygon geometries with `shapely.make_valid`
23
28
  - Export to any format supported by GeoPandas / Fiona (Shapefile, GeoJSON, GeoPackage, etc.)
24
- - Simple command-line interface for quick conversions
29
+ - Simple command-line interface for quick conversions in both directions
25
30
 
26
31
  ## Installation
27
32
 
@@ -59,9 +64,23 @@ pymapgis input.wl output.geojson --driver GeoJSON
59
64
 
60
65
  # Keep raw (possibly invalid) polygon geometries
61
66
  pymapgis input.wp output.shp --no-make-valid
67
+
68
+ # Convert a Shapefile (or GeoJSON/GeoPackage) back to MapGIS
69
+ pymapgis input.shp output.wp
70
+ pymapgis input.geojson output.wl --encoding GBK
71
+
72
+ # Also decode graphic parameters (style/colour numbers, width, symbol
73
+ # number, angle, ...) into extra attribute columns
74
+ pymapgis input.wp output.gpkg --graphic-params
75
+
76
+ # Inspect a MapGIS graphic library (symbol / line-style definitions)
77
+ pymapgis lib Subgraph.lib # symbol counts (indexed + tail chain)
78
+ pymapgis lib Subgraph.lib --symbol 1960 # decode one symbol's geometry
79
+ pymapgis lib LINESTY.lib # whole-library census
80
+ pymapgis lib LINESTY.lib --style 211 --aux 0 # decode one line style
62
81
  ```
63
82
 
64
- The same interface is available as `python -m pymapgis input.wp output.shp`.
83
+ The direction is chosen from the **input** extension: `.wt`/`.wl`/`.wp` input reads MapGIS; any other input writes MapGIS. The same interface is available as `python -m pymapgis input.wp output.shp`.
65
84
 
66
85
  ## API
67
86
 
@@ -96,6 +115,14 @@ file type — point parameters for `.wt` (as above), line parameters for
96
115
  **Methods**
97
116
 
98
117
  - `to_file(filepath, **kwargs)` — forward to `GeoDataFrame.to_file`
118
+ - `len(reader)` — number of features
119
+ - `str(reader)` — summary (`"n features (type POINT)"`); `repr(reader)` shows the constructor arguments
120
+ - Context manager: `with Reader(...) as r:` (the file is fully parsed and closed in the constructor)
121
+
122
+ ### Constants
123
+
124
+ - `POINT_TYPE_TEXT` (0) / `POINT_TYPE_SYMBOL` (1) — values of the `point_type` column for `.wt` graphic parameters
125
+ - `pymapgis.__version__` — package version string
99
126
 
100
127
  ### Exceptions
101
128
 
@@ -103,6 +130,52 @@ file type — point parameters for `.wt` (as above), line parameters for
103
130
  - `InvalidFileError` — unsupported or unrecognized file
104
131
  - `TopoError` — polygon topology reconstruction error
105
132
  - `InvalidDirectoryError` — reserved for project/directory errors
133
+ - `WriterError` — a GeoDataFrame cannot be encoded as a MapGIS file
134
+
135
+ ### `Writer(geodataframe, *, make_valid=True, map_scale=1000.0, snap_tolerance=0.0, graphic_params=True, geometry_type=None)`
136
+
137
+ Encode a GeoDataFrame as a MapGIS binary file. One geometry type per file:
138
+ Point/MultiPoint for `.wt` (MultiPoint is exploded with a warning),
139
+ LineString/MultiLineString for `.wl` (exploded likewise), and
140
+ Polygon/MultiPolygon for `.wp` (a MultiPolygon stays one polygon feature,
141
+ matching the reader).
142
+
143
+ ```python
144
+ from pymapgis import Writer, write
145
+
146
+ Writer(gdf).to_file("out.wp") # or the shortcut: write(gdf, "out.wp")
147
+ ```
148
+
149
+ - `make_valid` — repair invalid polygons before arc decomposition (.wp only)
150
+ - `map_scale` — map-scale denominator for projected CRS (coordinates are
151
+ stored as `value * 1000 / map_scale`); ignored for longitude/latitude data
152
+ - `snap_tolerance` — coordinate quantisation step applied before topology
153
+ construction so that shared boundaries coincide byte-exactly (0 = exact)
154
+ - `graphic_params` — when the frame carries the reader's graphic-parameter
155
+ columns (`point_type`/`symbol_no`/..., `linetype`/...,
156
+ `fill_color`/`pattern`/`pattern_color`), write them back into the
157
+ graphic-parameter areas instead of the attribute table, giving
158
+ mapgis → shp → mapgis parameter fidelity
159
+ - `geometry_type` — explicit `"POINT"`/`"LINE"`/`"POLYGON"` for empty frames
160
+
161
+ Writing regenerates polygon topology: adjacent polygons share single arcs,
162
+ with left/right polygon IDs derived from ring orientation, so the output
163
+ re-reads losslessly with `Reader`. Attributes are encoded with MapGIS field
164
+ types inferred from pandas dtypes (GBK strings, dates, times, numbers);
165
+ unsupported columns raise `WriterError`.
166
+
167
+ **Write-side limitations**
168
+
169
+ - `.wt` label text stored in auxiliary annotation sections is not produced;
170
+ written `.wt` files carry geometry, attributes, and symbol points only
171
+ - Shapefile's 10-character field-name limit truncates long parameter columns
172
+ (e.g. `pattern_color` → `pattern_col`) when passing through `.shp`, which
173
+ disables the matching parameter group on write; GeoJSON/GeoPackage or a
174
+ direct GeoDataFrame hand-off is unaffected
175
+ - Longitude/latitude, Transverse Mercator, Albers, and Lambert CRS are
176
+ written; other projections raise `WriterError`
177
+ - CGCS2000 has no MapGIS ellipsoid code and is written as WGS84 with a
178
+ warning (they agree to better than 0.1 mm)
106
179
 
107
180
  ## Reading graphic parameters
108
181
 
@@ -118,9 +191,11 @@ with Reader("points.wt", read_graphic_params=True) as r:
118
191
  symbols = r.geodataframe[r.geodataframe.point_type == POINT_TYPE_SYMBOL]
119
192
  print(symbols[["symbol_no", "height", "width", "angle"]].head())
120
193
 
121
- # Line files: style number, width in millimetres, pattern coefficients
194
+ # Line files: style and auxiliary style numbers, colour index, width in
195
+ # millimetres, pattern coefficients
122
196
  with Reader("lines.wl", read_graphic_params=True) as r:
123
- print(r.geodataframe[["linetype", "width", "x_coef", "y_coef"]].head())
197
+ print(r.geodataframe[["linetype", "aux_linetype", "color",
198
+ "width", "x_coef", "y_coef"]].head())
124
199
 
125
200
  # Polygon files: fill colour / pattern numbers (head_9 section)
126
201
  with Reader("polygons.wp", read_graphic_params=True) as r:
@@ -135,6 +210,32 @@ with Reader("polygons.wp", read_graphic_params=True) as r:
135
210
  > layouts were reverse-engineered and validated on the layers of map sheet
136
211
  > J43C001002 — verify against your own data before relying on them.
137
212
 
213
+ ## Parsing the graphic libraries
214
+
215
+ The library files referenced by the graphic parameters can be parsed
216
+ directly (the same parsers back the `pymapgis lib` subcommand):
217
+
218
+ ```python
219
+ from pymapgis import LinestyLib, SubgraphLib, classify_form, compose_feature_style
220
+
221
+ # Subgraph.lib: point-symbol geometry (mm coordinates, subpaths, fitted circles)
222
+ lib = SubgraphLib("Subgraph.lib")
223
+ print(lib.n_indexed, "indexed +", lib.n_tail, "tail-chain symbols")
224
+ sym = lib.decode(1960) # None when out of range
225
+ for sp in sym.subpaths:
226
+ print(len(sp.points), "points", sp.circle) # circle = (cx, cy, r) fit
227
+
228
+ # LINESTY.lib: line styles (1-based, as stored in .wl linetype fields)
229
+ styles = LinestyLib("LINESTY.lib")
230
+ style = styles.decode(211)
231
+ print(classify_form(style)) # form label + evidence
232
+ main, aux = compose_feature_style(styles, 211, 0) # (style, aux) pair rule
233
+ ```
234
+
235
+ Line-style style numbers and symbol numbers are *library-local*: they
236
+ resolve only against the same (or a byte-identical) library that produced
237
+ the data.
238
+
138
239
  ## Supported formats
139
240
 
140
241
  | Extension | Geometry type | Graphic parameters | Notes |
@@ -504,6 +605,15 @@ String fields are read up to the first `\x00`. Date fields are year (int16) + mo
504
605
 
505
606
  ## Changelog
506
607
 
608
+ ### Unreleased
609
+ - **Writer**: encode GeoDataFrames back to native MapGIS `.wt` / `.wl` / `.wp` binaries — attribute table (GBK strings, dates, times, typed numerics), graphic parameters (with mapgis → shp → mapgis fidelity when the reader's parameter columns are present), CRS (longitude/latitude, Transverse Mercator, Albers, Lambert), and regenerated polygon topology (shared boundaries stored as single arcs with left/right polygon IDs). New public API: `Writer`, `write()`, and `WriterError`
610
+ - CLI converts in both directions based on the input extension (`.shp`, `.geojson`, `.gpkg`, ... → `.wt`/`.wl`/`.wp`); new `--encoding` option
611
+ - New runtime dependency: `pyogrio>=0.8` (reading shapefiles is now a runtime feature)
612
+ - `verify_pymapgis.py --roundtrip`: Reader → Writer → Reader regression over all local MapGIS files (not recorded in the baseline)
613
+
614
+ ### 2.2.1
615
+ - Packaging fix: `pymapgis.rendering` is under active development and is not yet ready for distribution (it is also undocumented and requires matplotlib, which is not a declared dependency). It is now excluded from the wheel and sdist; the published package again focuses on reading/conversion. The module remains in the source repository and will be published as a separate package or extra once it stabilises
616
+
507
617
  ### 2.2.0
508
618
  - `read_graphic_params=True`: decode line graphic parameters (`.wl`: `linetype`, `aux_linetype`, `width`, `x_coef`, `y_coef`) and polygon graphic parameters (`.wp` head_9 section: `fill_color`, `pattern`, `pattern_color`), exposed as `line_params` / `polygon_params` and joined into the GeoDataFrame
509
619
  - Format documentation: line graphic-parameter area (bytes 18–56), polygon head_9 section, additional `.wl` index sections
@@ -521,8 +631,8 @@ String fields are read up to the first `\x00`. Date fields are year (int16) + mo
521
631
  Clone the repository and install in editable mode with dev dependencies:
522
632
 
523
633
  ```bash
524
- git clone https://github.com/pymapgis/pymapgis.git
525
- cd pymapgis
634
+ git clone https://github.com/leecugb/mapgis2shp.git
635
+ cd mapgis2shp
526
636
  pip install -e ".[dev]"
527
637
  ```
528
638
 
@@ -149,6 +149,13 @@ point_count = coord_volume / 93 - 1
149
149
  > 图形库(Slib)的索引,字形定义并不存储在数据文件中;换用不同或定制的
150
150
  > 图形库后,同一编号可能对应不同字形,旋转角为 0 时符号的姿态也取决于
151
151
  > 字形设计。这些参数只有在产出数据的图形库(及其版本)语境下才可完整解释。
152
+ >
153
+ > **子图颜色字段未定位(如实挂账)。** MapGIS 官方点参数含"子图颜色/可变
154
+ > 颜色",但 2026-10-14 的锚定探针失败:选定的锚符号(库符号 7/15/27/30/43/56,
155
+ > 对应用户裁定色号 青3/黑4/品红2/品红2/黑4)在本项目 9 个数据根的全部
156
+ > .WT 文件中零使用(实际高频符号为 #1859/#1771/#1762/#1844/#1764/#208 等
157
+ > 尾段高位号),无法从数据侧锁定一致偏移。待取得实际在用符号的裁定色后
158
+ > 再锚定。
152
159
 
153
160
  ---
154
161
 
@@ -196,14 +203,18 @@ line_count = line_volume / 57 - 1
196
203
  |------|----------------|--------|------|------|
197
204
  | 保留 | 18–21 | 4 | - | 未使用 |
198
205
  | 线型号 | 22–23 | 2 | int16 | MapGIS 线型库索引(1 = 普通实线) |
199
- | 辅助线型号 | 24–25 | 2 | int16 | 辅助线型库索引 |
200
- | 类码 | 26–27 | 2 | int16 | 按图层类别变化,确切含义未定 |
206
+ | 辅助线型号 | 24–25 | 2 | int16 | 辅助线型库索引("线型号-辅助线型号"双参数的第二参数;0 = 不叠加) |
207
+ | 线颜色 | 26–27 | 2 | int16 | Colorlib 颜色索引(1-based;2026-10-14 由"类码"改判——LYGREBA001 全部图元恒 194=青绿,与裁定对 ("211","0") 色互证;18 层值域 [1,546] ⊂ 870 色) |
201
208
  | 保留 | 28–29 | 2 | - | 未使用 |
202
209
  | 线宽 | 30–33 | 4 | float32 | 单位毫米(mm) |
203
210
  | 保留 | 34 | 1 | - | 填充 |
204
- | X 系数 | 35–38 | 4 | float32 | 线型图案 X 比例(非 4 字节对齐) |
205
- | Y 系数 | 39–42 | 4 | float32 | 线型图案 Y 比例(非 4 字节对齐) |
206
- | 未解译 | 43–56 | 14 | - | 按类变化的小值,布局尚未确定 |
211
+ | X 系数 | 35–38 | 4 | float32 | 线型图案 X 比例(非 4 字节对齐;官方语义=沿线伸缩) |
212
+ | Y 系数 | 39–42 | 4 | float32 | 线型图案 Y 比例(非 4 字节对齐;官方语义=垂线/线宽方向伸缩) |
213
+ | 未解译 | 43–56 | 14 | - | 官方字段序中辅助色/覆盖方式/线种类的候选区(挂账待扫) |
214
+
215
+ > 2026-09 版曾将 @26 记为"类码(含义未定)";2026-10-14 官方文档审计
216
+ > (MapGIS67 编辑器字段序:线型号/辅助线型号/线颜色/线宽度/线种类/
217
+ > 覆盖方式/辅助色)+ 211 号线型图元恒值锚定后改判为**线颜色**。
207
218
 
208
219
  > 线型号、颜色号为 MapGIS 线型库索引,图形库不在数据文件中——与点图形
209
220
  > 参数相同,这些参数不是独立参数(见 3.3 节注意)。
@@ -269,8 +280,12 @@ topo_count = poly_volume / 24 - 1
269
280
 
270
281
  ### 5.5 区图形参数区(head_9)
271
282
 
272
- > 本节内容为逆向工程结果(2026-09,在 J43C001002 图幅全部 13 个区图层上验证:
273
- > 每区一条记录,字段在各地质单元内 100% 一致)。
283
+ > 本节布局 **2026-10-14 修订定版**(字节级实证:库尔干/英吉沙/新疆115 三幅
284
+ > + 库尔干全部 13 个区图层——@4、@8 恒为 0,@7 逐层恒定)。2026-09 版的
285
+ > int16 @4/@6/@8 读法为**错位**:int16 高字节取自恒 0 的邻字节,得值=
286
+ > 真值×256 型垃圾(如真值 14 读成 3584)。按本表修正后,旧版"沉积
287
+ > 3866–3931/侵入 384–388/变质 751–758"的图案聚类相应订正为 26–91/
288
+ > 128–132/239–246(岩性分组规律不变,正好互为移位验证)。
274
289
 
275
290
  该区每 **40 字节** 存储一个区的图形参数,**第一个 40 字节为空记录**,
276
291
  第 *i* 条记录(空记录后 0 起)对应区号 *i + 1*:
@@ -279,10 +294,12 @@ topo_count = poly_volume / 24 - 1
279
294
  |------|--------------|--------|------|------|
280
295
  | 类标 | 0 | 1 | uint8 | 观测值为 1 |
281
296
  | 类码 | 1 | 1 | uint8 | 按地质单元变化,含义未定 |
282
- | 保留 | 2–3 | 2 | - | 未使用 |
283
- | 填充色 | 4–5 | 2 | int16 | 填充颜色索引(候选解释) |
284
- | 填充图案号 | 6–7 | 2 | int16 | 图案库索引,按岩性类别聚类(沉积 3866–3931、侵入岩 384–388、变质岩 751–758) |
285
- | 图案颜色 | 8–9 | 2 | int16 | 图案颜色索引(候选解释) |
297
+ | 保留 | 2–4 | 3 | - | 恒为 0 |
298
+ | 填充色 | 5 | 1 | uint8 | Colorlib 填充色索引(1-based;0=默认) |
299
+ | 填充图案号 | 6 | 1 | uint8 | 图案库索引,按岩性类别聚类(沉积 26–91、侵入岩 128–132、变质岩 239–246) |
300
+ | 标志 | 7 | 1 | uint8 | 逐层恒定(0/1/2/3/15),角色未裁定 |
301
+ | 保留 | 8 | 1 | - | 恒为 0 |
302
+ | 图案颜色 | 9 | 1 | uint8 | 图案颜色索引 |
286
303
  | 未解译 | 10–39 | 30 | - | 带花纹单元的图案子参数,布局尚未确定 |
287
304
 
288
305
  > 颜色号与图案号为 MapGIS 颜色/图案库索引,图形库不在数据文件中——与
@@ -358,3 +375,18 @@ topo_count = poly_volume / 24 - 1
358
375
  2. **区拓扑容错**:弧段端点可能存在微小偏差,且部分源数据本身存在拓扑缝隙或自相交。读取后建议调用几何有效性修复。
359
376
  3. **编码**:字段名与字符串属性值使用 GBK 编码,若存在非法字节通常截断至首个非法字节处。
360
377
  4. **比例尺**:投影坐标系下内部坐标常以毫米为单位,需按 `scale / 1000` 换算为米;经纬度坐标系下 `scale` 通常为 1。
378
+
379
+ ---
380
+
381
+ ## 8. 写出侧补充(pymapgis.writer 实测验证的布局细节)
382
+
383
+ 以下细节在读取侧不敏感、但对写出原生兼容文件必要(2026-09 对 J43C001002 真实文件 hexdump 实测):
384
+
385
+ 1. **索引区为 16 条 × 10 字节**(本文 §1 述 10 条为有效条目数):`data_start` 恒为 657,索引区自 657 起占 160 字节(10 条有效 + 6 条全零),每条为 `pack("<2i", start, volume) + b"\xff\xff"`(末 2 字节恒为 FF FF);首个子数据区自 817 起,各区按 head 编号升序紧密排列,无文件尾结构。
386
+ 2. **属性记录首字节为 0x01 标志**,每条记录(含首条空记录)均有;字段存储偏移从 1 起紧凑排列、无字节对齐。
387
+ 3. **字段描述符未解字节语义**(§6.2 的"保留/显示宽度"14 字节):@25–26 = 存储字节数(string = 声明容量 + 1,数值 = 类型宽度);@27–28 = 声明长度(string = GBK 容量字节数,int = 8,double = 15);@29–32 = 标志(string = 256,数值 = 512 + 小数位数,如 double 6 位 = 518);@33–34 = 0 基字段序号;@35–38 = 全零。
388
+ 4. **322 字节属性前缀**:@0–1 与 @320–321 为 `` `D `` 签名(0x60 0x44),@2–5 为属性表日期(年 int16 + 月 + 日),@12/@16 各一个 int32 计数(读取侧忽略),@46 起为 GBK 工作目录路径。
389
+ 5. **.wp 拓扑记录**(24 字节):@0–7 为结点号(写出可置 0,无独立结点表),@8–11 = 左区号、@12–15 = 右区号,@16–23 保留;方向无标志位,由"弧段存储方向 + 左右区号"表达。
390
+ 6. **.wp head_9 区图形参数**首条"空"记录的字节 0 为 0x04(非全零);.wt 注记文本存于附加段(entry1 文本池/entry3 标注框/entry4),写出器不产出(MapGIS 中无注记文字,符号点不受影响)。
391
+ 7. 写出器对未反向解析的附加段(.wl head_4/7/8、.wp head_3 等)一律写空条目,Reader 兼容;MapGIS 原生软件打开写出文件的兼容性按 §7 之外另行验收。
392
+ 8. **head_9 写出采用修订后的 u8 布局**(2026-10-14):fill_color/pattern/pattern_color 写于 @5/@6/@9(Reader 同步修订);@7 标志原生文件逐层恒定(0/1/2/3/15),写出器留 0。线记录 @26 写出线颜色(默认 1,round-trip 时回填读取值)。
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "mapgis2shp"
7
- version = "2.2.0"
7
+ version = "2.3.0"
8
8
  description = "MapGIS is a widely used closed-source GIS platform in China, especially in geological surveying, engineering, and scientific research. pymapgis provides a lightweight, open-source reader for its native point, line, and polygon vector formats."
9
9
  readme = "README.md"
10
10
  license = { file = "LICENSE" }
@@ -30,6 +30,7 @@ dependencies = [
30
30
  "geopandas>=0.12",
31
31
  "numpy>=1.21",
32
32
  "pandas>=1.3",
33
+ "pyogrio>=0.8",
33
34
  "pyproj>=3.2",
34
35
  "shapely>=2.0",
35
36
  ]
@@ -60,9 +61,19 @@ include = [
60
61
  "/pymapgis_baseline.json",
61
62
  "/docs",
62
63
  ]
64
+ exclude = [
65
+ "/src/pymapgis/rendering",
66
+ "/src/pymapgis/semantics",
67
+ "/src/pymapgis/linesty_adjudicated.py",
68
+ ]
63
69
 
64
70
  [tool.hatch.build.targets.wheel]
65
71
  packages = ["src/pymapgis"]
72
+ exclude = [
73
+ "src/pymapgis/rendering",
74
+ "src/pymapgis/semantics",
75
+ "src/pymapgis/linesty_adjudicated.py",
76
+ ]
66
77
 
67
78
  [tool.hatch.build.targets.wheel.sources]
68
79
  "src" = ""
@@ -0,0 +1,59 @@
1
+ """pymapgis - Read and write MapGIS vector files with GeoPandas GeoDataFrames.
2
+
3
+ Also provides parsers for the MapGIS 6.x graphic libraries (Subgraph.lib
4
+ symbol library and LINESTY.lib line-style library) that the graphic
5
+ parameters of .wt/.wl features reference.
6
+ """
7
+
8
+ from pymapgis._version import __version__
9
+ from pymapgis.linesty import (
10
+ Element,
11
+ LineStyle,
12
+ LinestyLib,
13
+ SubLine,
14
+ census,
15
+ classify_form,
16
+ compose_feature_style,
17
+ dotline_params,
18
+ linedot_params,
19
+ )
20
+ from pymapgis.reader import (
21
+ POINT_TYPE_SYMBOL,
22
+ POINT_TYPE_TEXT,
23
+ InvalidDirectoryError,
24
+ InvalidFileError,
25
+ MapGISError,
26
+ Reader,
27
+ TopoError,
28
+ )
29
+ from pymapgis.slib import SubgraphLib, SubPath, Symbol, fit_circle, symbol_geometries
30
+ from pymapgis.writer import Writer, WriterError, write
31
+
32
+ __all__ = [
33
+ "Reader",
34
+ "Writer",
35
+ "write",
36
+ "WriterError",
37
+ "MapGISError",
38
+ "InvalidFileError",
39
+ "InvalidDirectoryError",
40
+ "TopoError",
41
+ "POINT_TYPE_TEXT",
42
+ "POINT_TYPE_SYMBOL",
43
+ # MapGIS graphic-library parsers (Subgraph.lib / LINESTY.lib)
44
+ "SubgraphLib",
45
+ "SubPath",
46
+ "Symbol",
47
+ "fit_circle",
48
+ "symbol_geometries",
49
+ "LinestyLib",
50
+ "LineStyle",
51
+ "SubLine",
52
+ "Element",
53
+ "classify_form",
54
+ "census",
55
+ "compose_feature_style",
56
+ "dotline_params",
57
+ "linedot_params",
58
+ "__version__",
59
+ ]
@@ -1,3 +1,3 @@
1
1
  """pymapgis version information."""
2
2
 
3
- __version__ = "2.2.0"
3
+ __version__ = "2.3.0"