gws.plugin.alkis.data.index¶
ALKIS index tables: storage, search and loading of Flurstuecke and addresses.
Source code: gws.plugin.alkis.data.index
Module Contents¶
- gws.plugin.alkis.data.index.all_flat_keys()¶
Return all flat keys of the Flurstueck structure.
The keys are derived from the type annotations in
types, seeflatten_fs.- Returns:
A dict of flat keys and their types, sorted by key.
- gws.plugin.alkis.data.index.flatten_fs(fs: gws.plugin.alkis.data.types.Flurstueck, keys_to_extract: set[str]) list[dict]¶
Flatten a Flurstueck into a list of dicts.
The nested Flurstueck structure is turned into flat dicts whose keys are attribute paths joined with
_, starting withfs, e.g.fs_recs_gemarkung_text.EnumPairvalues give two keys,_codeand_text. For list values, the dicts are repeated for each list item, so the result is the product of all lists, for example:record: a:x, b:[1,2], c:[3,4] flat list: a:x, b:1, c:3 a:x, b:1, c:4 a:x, b:2, c:3 a:x, b:2, c:4
Only paths leading to
keys_to_extractare followed, which keeps the product small. Still, some combinations of keys produce many rows.- Parameters:
fs – Flurstueck to flatten.
keys_to_extract – Flat keys to include.
- Returns:
A list of dicts.
- gws.plugin.alkis.data.index.hausnummer_key(s, upper=False)¶
Create a sort key for a house number.
The key is the leading number, zero-padded to 6 digits, followed by the lower-cased rest, e.g.
000002bfor2 B. Keys sort by number first, then by suffix, when compared bytewise (COLLATE "C").- Parameters:
s – House number.
upper – Create the key for the upper bound of a range. A house number without a suffix then gets a
~suffix, which sorts after all letters, so that the bound5includes5ato5z.
- Returns:
The key, or
Noneif the house number does not start with a number.
- gws.plugin.alkis.data.index.make_fsnummer(r: gws.plugin.alkis.data.types.FlurstueckRecord)¶
Create a display number for a Flurstueck.
The format is
<gemarkung> <flur>-<zaehler>/<nenner> (<folge>). The Flur, the denominator and the sequence number are omitted if empty, the sequence number also if it is00.- Parameters:
r – Flurstueck record.
- Returns:
The display number.
- gws.plugin.alkis.data.index.normalize_hausnummer(s)¶
Normalize a house number by removing all whitespace.
- Parameters:
s – House number, e.g.
12 a.- Returns:
The normalized house number, e.g.
12a, an empty string forNone.
- class gws.plugin.alkis.data.index.Object¶
Bases:
gws.NodeALKIS index.
Manages the index tables in the index schema, reports their status, runs Flurstueck and address searches against them and loads the found objects with their related data.
- ALL_TABLES = ['place', 'flurstueck', 'lage', 'part', 'indexflurstueck', 'indexlage', 'indexgeom',...¶
All index tables.
- columnDct¶
Column definitions by table id.
- db: gws.plugin.postgres.provider.Object¶
Database provider.
- HAUSNUMMER_NOT_NULL_VALUE = '*'¶
House number value that matches any non-empty house number.
- saMeta: gws.lib.sa.MetaData¶
SQLAlchemy metadata for the index tables.
- TABLES_BASIC¶
Tables of the basic index.
- TABLES_BUCHUNG¶
Tables with land register data.
- TABLES_EIGENTUEMER¶
Tables with owner data.
- VERSION = '85'¶
Index version, part of the table names.
- activate()¶
- configure()¶
- count_all(qo: gws.plugin.alkis.data.types.FlurstueckQueryOptions) int¶
Count all Flurstueck records in the index.
- Parameters:
qo – Query options. Historic records are counted only with
withHistorySearch.- Returns:
The number of rows in the Flurstueck index table.
- create_table(table_id: str, values: list[dict])¶
Create an index table and fill it with rows.
- Parameters:
table_id – Table id.
values – Rows as dicts of column names and values.
- default_land()¶
Return the Land of a Gemarkung in the index.
The value is cached once found.
- Returns:
The Land as an
EnumPair, orNoneif there are no Gemarkungen.
- drop()¶
Drop all index tables.
- find_adresse(q: gws.plugin.alkis.data.types.AdresseQuery) list[gws.plugin.alkis.data.types.Adresse]¶
Find addresses.
- Parameters:
q – Search criteria and options.
- Returns:
A list of addresses, in the order of the search, after applying offset and page size.
- Raises:
gws.ResponseTooLargeError – If there are more results than the configured limit.
gws.BadRequestError – If the query is invalid, e.g. a house number without a street.
- find_flurstueck(q: gws.plugin.alkis.data.types.FlurstueckQuery) list[gws.plugin.alkis.data.types.Flurstueck]¶
Find Flurstuecke and load them with their related data.
- Parameters:
q – Search criteria and options.
- Returns:
A list of Flurstuecke, in the order of the search, after applying offset and page size.
- Raises:
gws.ResponseTooLargeError – If there are more results than the configured limit.
gws.BadRequestError – If the query is invalid, e.g. a house number without a street.
- has_table(table_id: str) bool¶
Check whether an index table exists and has data.
- Parameters:
table_id – Table id.
- Returns:
Trueif the table has at least one row.
- iter_all(qo: gws.plugin.alkis.data.types.FlurstueckQueryOptions) collections.abc.Iterable[gws.plugin.alkis.data.types.Flurstueck]¶
Iterate over all Flurstuecke in the index.
Flurstuecke are loaded in chunks of
qo.pageSize, with a new database connection for each chunk.- Parameters:
qo – Query options.
pageSizemust be set.- Yields:
Flurstuecke with their related data.
- load_flurstueck(fs_uids: list[str], qo: gws.plugin.alkis.data.types.FlurstueckQueryOptions) list[gws.plugin.alkis.data.types.Flurstueck]¶
Load Flurstuecke with their related data.
- Parameters:
fs_uids – Flurstueck uids.
qo – Query options, the display themes select the related data.
- Returns:
A list of Flurstuecke in the order of
fs_uids. Missing and, unlesswithHistoryDisplayis set, historic Flurstuecke are left out.
- status() gws.plugin.alkis.data.types.IndexStatus¶
Return the index status.
- Returns:
The status, computed from the number of rows in the index tables.
- strasse_list() list[gws.plugin.alkis.data.types.Strasse]¶
Return all streets in the index.
Each distinct combination of Gemeinde, Gemarkung and street name of current Flurstuecke and Lage records is returned once. The list is cached.
- Returns:
A list of streets.
- gws.plugin.alkis.data.index.parse_fsnummer(s)¶
Parse a Flurstueck display number into its parts.
The format is the one created by
make_fsnummer, all parts are optional.- Parameters:
s – Display number.
- Returns:
A dict with the keys
gemarkungCode,flurnummer,zaehler,nennerandflurstuecksfolgefor the parts found, orNoneif the string does not match the format.
- gws.plugin.alkis.data.index.serialize(o: gws.plugin.alkis.data.types.Object, encode_enum_pairs=True) dict¶
Convert an object to a JSON-compatible structure.
Objects become dicts with sorted keys, dates become
DD.MM.YYYYstrings. Empty values are kept as they are.- Parameters:
o – Object to convert.
encode_enum_pairs – If
True,EnumPairvalues are encoded as$code$textstrings, otherwise as dicts.
- Returns:
A dict.
- gws.plugin.alkis.data.index.strasse_key(s)¶
Normalize a street name for text search.
Works like
text_key, but also expands the abbreviationsstr.andpl.and separates common street name suffixes, so that for exampleHauptstr.andHaupt-Strassegive the same key.- Parameters:
s – Street name.
- Returns:
The normalized street name, an empty string for
None.
- gws.plugin.alkis.data.index.TABLE_BUCHUNGSBLATT = 'buchungsblatt'¶
- gws.plugin.alkis.data.index.TABLE_FLURSTUECK = 'flurstueck'¶
- gws.plugin.alkis.data.index.TABLE_INDEXBUCHUNGSBLATT = 'indexbuchungsblatt'¶
- gws.plugin.alkis.data.index.TABLE_INDEXFLURSTUECK = 'indexflurstueck'¶
- gws.plugin.alkis.data.index.TABLE_INDEXGEOM = 'indexgeom'¶
- gws.plugin.alkis.data.index.TABLE_INDEXLAGE = 'indexlage'¶
- gws.plugin.alkis.data.index.TABLE_INDEXPERSON = 'indexperson'¶
- gws.plugin.alkis.data.index.TABLE_LAGE = 'lage'¶
- gws.plugin.alkis.data.index.TABLE_PART = 'part'¶
- gws.plugin.alkis.data.index.TABLE_PLACE = 'place'¶
- gws.plugin.alkis.data.index.text_key(s)¶
Normalize a string for text search.
The string is lower-cased, umlauts are transliterated and punctuation is replaced by spaces.
- Parameters:
s – String to normalize.
- Returns:
The normalized string, an empty string for
None.
- gws.plugin.alkis.data.index.text_search_clause(column, val, tso: gws.TextSearchOptions)¶
Create a where clause that matches a column against a search string.
- Parameters:
column – Column to match.
val – Search string.
tso – Text search options. Without options, the value is matched exactly.
- Returns:
A clause, or
Noneif the value is empty or shorter than the minimum length.
- gws.plugin.alkis.data.index.unserialize(data: dict)¶
Convert a structure created by
serializeback to objects.Dicts become
types.Objectinstances and$code$textstrings becomeEnumPairvalues.- Parameters:
data – Serialized data.
- Returns:
The object.