Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
shlang03
Contributor II
Contributor II

Унификация адресов при помощи Яндекс карт API

Здравствуйте! Прошу уважаемых участников помочь в решении следующей задачи:

есть перечень почтовых адресов, которые приходят от разных поставщиков и пишутся по-разному, являясь по сути одним и тем же адресом, есть необходимость их привести к одному названию. В Excel решение задачи давно найдено, например при помощи макроса (Получение адреса и координат из Yandex и Google - Excel Store).

Как подобную задачу реализовать в Qlik? Как написать запрос? Пример желаемого результата и исходных данных во вложении. Буду благодарен за любую помощь!

1 Solution

Accepted Solutions
shlang03
Contributor II
Contributor II
Author

Ответ найден.

Customer:

LOAD

     AddressLine1 as GeoKey,

     rowno() AS GeoCodeRows

FROM

(ooxml, embedded labels, table is Customer);

LET vMaxGeoCodes = 2400;

LET vNbRecords = IF(fieldvaluecount('GeoCodeRows')>$(vMaxGeoCodes),$(vMaxGeoCodes), fieldvaluecount('GeoCodeRows'));

IF $(vNbRecords) >0 THEN

FOR g=1 to $(vNbRecords) ;

LET vGeoInputForm = replace(replace(replace(replace(purgechar(peek('GeoKey',$(g)-1,'Customer'),'#'),'é','e'),'´','+'),'ö','o'),' ','+');

LET vGeoInputOrig = PEEK('GeoKey',$(g)-1,'Customer');

SLEEP 20;

TempGeoCode:

LOAD

'$(vGeoInputOrig)' as GeoKey,

[GeoObjectCollection/featureMember/GeoObject/metaDataProperty/GeocoderMetaData/text] as Адрес_унифицированный

FROM   [https://geocode-maps.yandex.ru/1.x/?geocode=$(vGeoInputForm)&format=xml&lang=ru_RU&results=1] (XmlSimple, Table is [ymaps]);

NEXT g ;

GeoCode:

LOAD DISTINCT *

RESIDENT TempGeoCode;

View solution in original post

5 Replies
danbakanov
Partner - Contributor
Partner - Contributor

Добрый день, внизу ссылка на API гугла с переменной в которой должен быть запрос,

и на  статью по этой теме, надеюсь поможет.

https://maps.googleapis.com/maps/api/geocode/xml?address=$(vGeoInputForm)&sensor=false

How To Get Qlik Geocoded Data for Your Apps

shlang03
Contributor II
Contributor II
Author

Подскажите, что я делаю неправильно в этом коде?

Table:

LOAD

     Адрес_исходный

FROM

(ooxml, embedded labels, table is Лист1);

let noRows = NoOfRows('Table')-1;

for i=0 to $(noRows)

let a=peek('Адрес_исходный',$(i),'Table');  

GeocodeResponse:

LOAD

'$(a)' as Адрес_исх,

([result/formatted_address]) as adress

FROM [http://maps.googleapis.com/maps/api/geocode/xml?address=$(a)&sensor=false&language=ru&region=ru] (XmlSimple, Table is [GeocodeResponse]);

next

выдает:

Unknown LOAD statment error

GeocodeResponse:

LOAD

'КИЕВ б-р Ивана Лепсе, 31' as Адрес_исх,

([result/formatted_address]) as adress

FROM [http://maps.googleapis.com/maps/api/geocode/xml?address=КИЕВ б-р Ивана Лепсе, 31&sensor=false&language=ru&region=ru] (XmlSimple, Table is [GeocodeResponse])

danbakanov
Partner - Contributor
Partner - Contributor

Если заменить

let a=peek('Адрес_исходный',$(i),'Table');

на

LET a = replace(replace(replace(replace(purgechar(peek('Адрес_исходный',$(i),'Table'),'#'),'é','e'),'´','+'),'ö','o'),' ','+');

то все работает.

Я бы использовал код доступный по ссылке с сохранением результатов в QVD. Особенно учитывая ограничения по количеству запросов в день и скорость обработки запросов гуглом.

shlang03
Contributor II
Contributor II
Author

Спасибо! Немного упростив, я добился результата в Гугле. Подскажите, как мне прописать запрос, чтобы такую же операцию сделать в Яндексе:

Customer:

LOAD

     AddressLine1 as GeoKey,

     rowno() AS GeoCodeRows

FROM

(ooxml, embedded labels, table is Customer);

LET vMaxGeoCodes = 2400;

LET vNbRecords = IF(fieldvaluecount('GeoCodeRows')>$(vMaxGeoCodes),$(vMaxGeoCodes), fieldvaluecount('GeoCodeRows'));

IF $(vNbRecords) >0 THEN

FOR g=1 to $(vNbRecords) ;

LET vGeoInputForm = replace(replace(replace(replace(purgechar(peek('GeoKey',$(g)-1,'Customer'),'#'),'é','e'),'´','+'),'ö','o'),' ','+');

LET vGeoInputOrig = PEEK('GeoKey',$(g)-1,'Customer');

SLEEP 20;

//TempGeoCode:

//LOAD

// '$(vGeoInputOrig)' as GeoKey,

// ([result/formatted_address]) as adress

//FROM [https://maps.googleapis.com/maps/api/geocode/xml?address=$(vGeoInputForm)&sensor=false&language=ru&r...] (XmlSimple, Table is [GeocodeResponse]);

TempGeoCode:

LOAD

'$(vGeoInputOrig)' as GeoKey,

([GeocoderMetaData/text]) as adress

FROM   [http://geocode-maps.yandex.ru/1.x/?geocode=$(vGeoInputForm)&format=xml&lang=ru_RU&results=1] (XmlSimple, Table is metaDataProperty);

NEXT g ;

GeoCode:

LOAD DISTINCT

GeoKey,

adress

RESIDENT TempGeoCode;

Что нужно написать в таблице TempGeoCode вместо


result/formatted_address


и


FROM [https://maps.googleapis.com/maps/api/geocode/xml?address=$(vGeoInputForm)&sensor=false&language=ru&r...] (XmlSimple, Table is [GeocodeResponse]);


Как вариант я предложил, но что-то не работает.


Спасибо за помощь!

shlang03
Contributor II
Contributor II
Author

Ответ найден.

Customer:

LOAD

     AddressLine1 as GeoKey,

     rowno() AS GeoCodeRows

FROM

(ooxml, embedded labels, table is Customer);

LET vMaxGeoCodes = 2400;

LET vNbRecords = IF(fieldvaluecount('GeoCodeRows')>$(vMaxGeoCodes),$(vMaxGeoCodes), fieldvaluecount('GeoCodeRows'));

IF $(vNbRecords) >0 THEN

FOR g=1 to $(vNbRecords) ;

LET vGeoInputForm = replace(replace(replace(replace(purgechar(peek('GeoKey',$(g)-1,'Customer'),'#'),'é','e'),'´','+'),'ö','o'),' ','+');

LET vGeoInputOrig = PEEK('GeoKey',$(g)-1,'Customer');

SLEEP 20;

TempGeoCode:

LOAD

'$(vGeoInputOrig)' as GeoKey,

[GeoObjectCollection/featureMember/GeoObject/metaDataProperty/GeocoderMetaData/text] as Адрес_унифицированный

FROM   [https://geocode-maps.yandex.ru/1.x/?geocode=$(vGeoInputForm)&format=xml&lang=ru_RU&results=1] (XmlSimple, Table is [ymaps]);

NEXT g ;

GeoCode:

LOAD DISTINCT *

RESIDENT TempGeoCode;