# stdnum.es.referenciacatastral

Referencia Catastral (Spanish real estate property id)

The cadastral reference code is an identifier for real estate in Spain. It is issued by Dirección General del Catastro (General Directorate of Land Registry) of the Ministerio de Hacienda (Tresury Ministry).

It has 20 digits and contains numbers and letters including the Spanish Ñ. The number consists of 14 digits for the parcel, 4 for identifying properties within the parcel and 2 check digits. The parcel digits are structured differently for urban, non-urban or special (infrastructure) cases.

More information:

- https://www.catastro.meh.es/ (Spanish)

- https://www.catastro.meh.es/documentos/05042010_P.pdf (Spanish)

- https://es.wikipedia.org/wiki/Catastro#Referencia_catastral

    >>> validate('7837301-VG8173B-0001 TT')  # Lanteira town hall
    '7837301VG8173B0001TT'
    >>> validate('783301 VG8173B 0001 TT')  # missing digit
    Traceback (most recent call last):
        ...
    InvalidLength: ...
    >>> validate('7837301/VG8173B 0001 TT')  # not alphanumeric
    Traceback (most recent call last):
        ...
    InvalidFormat: ...
    >>> validate('7837301 VG8173B 0001 NN')  # bad check digits
    Traceback (most recent call last):
        ...
    InvalidChecksum: ...
    >>> format('4A08169P03PRAT0001LR')  # BCN Airport
    '4A08169 P03PRAT 0001 LR'

stdnum.es.referenciacatastral.calc_check_digits(number: str) → str

  Calculate the check digits for the number.

stdnum.es.referenciacatastral.compact(number: str) → str

  Convert the number to the minimal representation. This strips the number of any valid separators and removes surrounding whitespace.

stdnum.es.referenciacatastral.format(number: str) → str

  Reformat the number to the standard presentation format.

stdnum.es.referenciacatastral.is_valid(number: str) → bool

  Check if the number is a valid Cadastral Reference.

stdnum.es.referenciacatastral.validate(number: str) → str

  Check if the number is a valid Cadastral Reference. This checks the length, formatting and check digits.