Coverage for gws-app/gws/plugin/alkis/data/__init__.py: 0%

1 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-05 13:35 +0200

1"""ALKIS data: reading, indexing, searching and exporting. 

2 

3This package holds the data layer of the ALKIS plugin. It reads ALKIS source 

4tables from a PostgreSQL database, builds a compact search index from them in 

5a separate schema, runs Flurstueck (parcel) and address searches against that 

6index, and exports search results to files. The ``alkis`` action and the 

7``gws alkis`` CLI commands are built on top of it. 

8 

9Submodules: 

10 

11- ``types``: the data model. ALKIS entities (``Flurstueck``, ``Lage``, 

12 ``Gebaeude``, ``Buchungsblatt``, ``Person``, ``Part`` and so on), their 

13 records, ``EnumPair`` code/text values, query objects 

14 (``FlurstueckQuery``, ``AdresseQuery`` and their options), the 

15 ``IndexStatus`` and the ``Reader`` interface for source data. 

16- ``norbit6``: a ``Reader`` for source tables in the GeoInfoDok 6 layout 

17 written by the norBIT ALKIS import. 

18- ``indexer``: builds the index. It reads all relevant ALKIS object types 

19 through a ``Reader``, links them together in memory and writes the result 

20 into the index tables. 

21- ``index``: the index node. It defines the index tables, reports the index 

22 status, finds Flurstuecke and addresses and loads them with their related 

23 data. It also holds helpers to serialize objects to JSON, to normalize 

24 search strings and to flatten a Flurstueck into rows for export. The index 

25 node is created by the ``alkis`` action, which passes the database, 

26 ``crs``, ``schema``, ``excludeGemarkung`` and ``gemarkungFilter`` options. 

27 If ``gemarkungFilter`` is set, searches and the street list are restricted 

28 to these Gemarkung codes. 

29- ``exporter``: a configurable exporter that writes Flurstuecke to CSV or 

30 GeoJSON, using models whose field names are flat keys 

31 (see ``index.flatten_fs``). If no models are configured, a default model 

32 with basic Flurstueck fields is used. 

33- ``geo_info_dok``: Python modules generated from the GeoInfoDok schema 

34 (``gid6``, ``gid7``) and the generator that creates them. 

35 

36Design: 

37 

38Every ALKIS object is represented by an *entity* with a list of *records* 

39(``recs``), one per version in the object's life span, sorted by start date. 

40A record is historic when its life span has ended; an entity is historic when 

41all of its records are. Code list values are stored as ``EnumPair`` objects 

42holding both the code and the display text. 

43 

44The indexer works in phases: places (Land, Kreis, Gemeinde, Gemarkung and so 

45on), Buchung (Buchungsblatt, Buchungsstelle, Namensnummer, Person, 

46Anschrift), Lage with Gebaeude, Flurstueck data, Parts (Nutzung, Festlegung, 

47Bewertung, computed by intersecting the source geometries with the 

48Flurstuecke) and finally the flat search tables. Each object is stored as a 

49JSONB document; the flat ``index*`` tables hold the searchable columns and 

50refer to Flurstuecke by their uid. Index tables are named 

51``alkis_<VERSION>_<table>`` and live in the configured index schema. 

52 

53A search selects matching Flurstueck uids from the flat tables, then loads the 

54JSONB documents and attaches related data depending on the requested display 

55themes, dropping historic objects unless history display is requested. 

56 

57Example:: 

58 

59 from gws.plugin.alkis.data import index, indexer, types as dt 

60 

61 # build the index from the source schema (ix is an ``index.Object``) 

62 indexer.run(ix, 'public', with_force=True) 

63 

64 # find a Flurstueck with its address and buildings 

65 q = dt.FlurstueckQuery( 

66 gemarkungCode='1234', 

67 flurnummer='5', 

68 zaehler='12', 

69 options=dt.FlurstueckQueryOptions( 

70 displayThemes=[dt.DisplayTheme.lage, dt.DisplayTheme.gebaeude], 

71 ), 

72 ) 

73 for fs in ix.find_flurstueck(q): 

74 print(fs.fsnummer, [la.recs[-1].strasse for la in fs.lageList]) 

75 

76Example:: 

77 

78 actions+ { 

79 type "alkis" 

80 dbUid "DB_ALKIS" 

81 dataSchema "public" 

82 indexSchema "gws8" 

83 crs 25832 

84 ui { useExport true } 

85 exporters+ { 

86 type "csv" 

87 title "Basisdaten (CSV)" 

88 models+ { 

89 fields [ 

90 { type "text" name "fs_flurstueckskennzeichen" title "Kennzeichen" } 

91 { type "float" name "fs_recs_amtlicheFlaeche" title "Flaeche" } 

92 ] 

93 } 

94 } 

95 } 

96""" 

97 

98from . import index, types