📜 ⬆️ ⬇️

How to move from KLADR to FIAS and do not break anything

GNIVTS FTS informs that since the beginning of 2018 KLADR will cease to exist and will not be able to download it.

Disclaimer:
If you do not understand at all what these sets of letters mean, do not worry. Below we describe the realities of working with addresses in Russia. If you are not interested, read about topographical quibbles .

Correct addresses are needed for companies that love their customers. Familiar banks, insurance and online stores, which now use the KLADR directory, ask us what to do next. Therefore, we wore out and wrote a step-by-step guide on the transition from one letter to another from KLADR to FIAS.



Why are address classifiers needed?


Companies need customer addresses to send letters, specify in contracts and agreements. But it is not enough just to send a letter: it is desirable that it be received and read. Therefore, the addresses must be correct and understandable.
')

What do you think, what state body is most interested in receiving letters from him? Right! Tax. Therefore, the Federal Tax Service of Russia has been developing and supporting the departmental all-Russian address classifiers for many years. And since there are no more complete directories, they have been used everywhere.

First there was KLADR, and there were 6 levels in it:

Region → District → City → Town → Street → House with buildings and buildings

Since 2012, a new classifier, FIAS, has been commissioned. We wrote about the main differences three years ago in the article “FIAS or KLADR: we choose the reference book of addresses” . In the FTS, the development of a new classifier approached more thoroughly and tried to take into account all the mistakes of KLADR. From the interesting added date of the beginning and end of the recording, entered a fixed ID for each house (it is assumed that it will not change).

Both classifiers are still being updated, but compatibility is becoming more difficult to maintain. Last year, new levels began to be added to FIAS. For example, planning structures are all kinds of country partnerships and microdistricts, in the classifier there are already more than 81,000. Finally, the Federal Tax Service made a logical decision to stop supporting KLADR and remove it at the end of 2017.



How addresses are stored in FIAS and KLADR


We have seen many ways to store addresses in the KLADR structure. Basically they boil down to two options:

  1. Code KLADR to the street + house part of the form "house 1 building 3 apartment 33 ", as parts of the houses in the classifier are stored as ranges
  2. Address in the form of text - one field or divided by structure KLADR.

Since there is no part of houses in FIAS, we recommend storing the address as:

  1. FIAS code to the street + house + apartment to identify the address ( detailed recommendations ).
  2. Address in one line in FIAS format. It is better to keep the original address. FIAS is still a tax reference book, and not everything is there.

That is, the task of migration is reduced to translating the code or text address in the KLADR format into the FIAS code.

Classification codes look like this:

  • KLADR : SS + PPP + YYY + PPP + UUUU + DDDD;
  • FIAS : SS + PPP + YYY + PPP + SSSS + UUUU + DDDD (or ZZZZ) + OOOO.

It looks scary, consider an example: Leningrad region, Vsevolozhsk district, the village of Kudrovo, md New Okkervil. The address really exists, here it is on Yandex.Maps . At first glance, the classification code of KLADR and FIAS looks the same for it: 470050000550023 . We decompose it into components.
NoLevelExampleFIAS codecode KLADR
oneRegionLeningrad regionSS : 47SS : 47
2Autonomous District
3AreaVsevolozhsk districtPPP : 005PPP : 005
fourCityYYY : 000YYY : 000
fiveUrban territory
6Localityvillage KudrovoSPT : 055SPT : 055
65Planning structuremd New OkkervilSCCS : 0023
7The outsideWooooWOW : 0023
75Land plot
eightBuilding, structure, object under constructionDDDDDDDD
9The room within the buildingOOOO
90Additional territory
91Subordinate additional areas
We spread the address on the FIAS and KLADR levels

It is clear from the example that even in simple situations there is a misunderstanding between classifiers. But there is another very important point.

The classification code reflects the current address structure, and it may change. For example, at Okkervil the area will change and all code will become invalid, we will not find it any more.

To get rid of this, a FIAS identification code was added to FIAS . This is a global identifier for each object: city, street, district, etc. It looks like a set of letters and numbers, which is formed according to the GUID standard (Globally Unique Identifier). A typical GUID in FIAS looks like this: f77948dc-7bc8-42cb-979e-2c958d162d63 .

KLADR code → FIAS identification code


If your address is stored as KLADR street code + house part (“house 1 building 3 apartment 44”), then everything is relatively simple for it.


The ADDROBJ table stores all address objects with their identifiers.

For the work, you will need the table ADDROBJ from the FIAS download in xml or dbf format. It stores all objects (cities, streets, etc.) in a row with unique GUIDs.
We will use the following columns:

  • KLADR code (PlainCode);
  • name and type of text (FormalName and ShortName);
  • the relevance of the object (CurrStatus);
  • zip code (PostalCode);
  • own and parent identifier of FIAS (AoGuid and ParentGuid);
  • level (AoLevel).

Example: Moscow, Alexander Solzhenitsyn st . KLADR code: 77000000000151900 .

Step 1. Select from the code KLADR code to the street, that is, take the first 15 digits: 770000000001519 00 .


Step 2. We are looking for the KLADR code in the PlainCode field. If one record is found, then save the value of the AoGuid field and skip the next item. But according to our code 770000000001519 there are three records, we need additional verification.

Step 3. Find the current entry. A field value of CurrStatus = 0 means that the entry is current. Select it and save the value of the AoGuid field. FIAS identification code found!


As a bonus, let's collect a text address from the AoGuid found:


But you can do even easier and use the ready-made service. DaData.ru is able to suggest addresses in specific regions, districts, cities and localities. Understands the names (" Peterhof "), the KLADR codes (" 7800000800000 ") and FIAS (" 8f238984-812b-4bb1-850b-49749fb5c56d ").


Line address KLADR → FIAS code


The easiest option is to use DaData.ru . The service will do everything for you automatically. But you can have fun yourself.

Single line addresses


If your addresses are stored in one line, like this:
Mr. Moscow, Bolshaya Kommunisticheskaya Street, Building 3, congratulations, this is the most interesting task. You need to write your own address parser, which will divide the string in KLADR format into parts, look for each of its components in FIAS, taking into account typos, abbreviations, historical names and determine the FIAS-code from them. It is easier to do this with a ready-made address parser. How to choose an algorithm for the address filter , we told earlier.

Addresses on KLADR


If your addresses are stored in KLADR, the task is a little easier.
Type of regionName of the regionStreet typeStreet nameHouse typeHouse number
gMoscowthe outsideCommunist B.house3
Something like this looks like the address spread out on KLADR

The FIAS code can be collected using the same ADDROBJ table. But in this case you need to move through the levels from larger to smaller.

Step 1. We take the name of the region and look for it in the FormalName field of the ADDROBJ table.

FormalName = Moscow →
AoGuid = 0c5b2444-70a0-4932-980c-b4dc0d3f02b5


Step 2. Go further down the levels and look for FormalName with a fixed parent - found by AoGuid in the previous step. In our case, the “city” and “settlement” levels are empty, and the next non-empty level is the street.

ParentGuid = 0c5b2444-70a0-4932-980c-b4dc0d3f02b5 ,
FormalName = Communist B. → AoGuid = f77948dc-7bc8-42cb-979e-2c958d162d63


Step 3. If you reach the street, you can find a house. To do this, look at the HOUSE table for a house number with a fixed street AoGuid. FIAS is not full of houses, so do not be discouraged if the desired number is not found.

AoGuid = f77948dc-7bc8-42cb-979e-2c958d162d63 ,
house number 3 →
HouseGuid = bce8be1f-f2f7-4cce-836e-08daac0b931e


Underwater rocks


Can something go wrong? Of course. For example, the name can easily find several objects. "Moscow, Tverskaya" - is it about the square or about the street? Then you need to compare types, but not everything is so simple.
LEVELSCNAMESOCRNAMEKOD_T_ST
7tractTract727
7dumbDead end728
7streetThe outside729
7uch-toPlot730
7f / xFarm789
7farmFarm769
7xThe farm758
7shHighway731
The SOCRBASE table stores the full and abbreviated object types.

The KLADR type can be abbreviated and complete: “ul” - “Street”, “x” - “Khutor”. Only abbreviated type is stored in FIAS explicitly (in the field ShortName). A full type into an abbreviated type can be turned using the SOCRBASE table, for each level it stores the correspondence of abbreviated and full types.

§ § §

And finally, the good news for those who are too lazy to bother with all of the above. In the near future, we plan to release FIAS in the KLADR format for those who do not have time to switch to the FIAS format by the end of the year. Follow the news :-)

PS Thank you for the invaluable help in creating this article by my colleagues on HFLabs, Mikhail Berezin , Elena Rastorguev and Anton Zhiyanov .

Source: https://habr.com/ru/post/333736/


All Articles