Skip to main content

Hello FME Kings,

 

Here is my situation: I have a script that uses HTTPCaller for geocoding in OpenStreetMap and MapGeoAdmin (retrieve coordinates from an address in an input attribute) and, sometimes, several "addresses" are located for the same input address which gives me a list of addresses (extracted with JSONFlattener).

 

My problem is that I would like, in one script (and I've been working on this for a while), to stop the script and generate a dialog box with the possibility to choose the right address in a dropdown list like this

ATTRIBUT ADDRESS ENTRY => CHOICE OF DETECTED ADDRESSES (combobox)

 => "1, Chemin du Lac de Mont-d'Orge, La Muraz, Sion, Valais, 1950, Suisse"

                => "1, Rue du Mont, Sion, Valais, 1950, Switzerland

                => "1a, Chemin du Lac de Mont-d'Orge, La Muraz, Sion, Valais, 1950, Switzerland"

... since, in an automated way, it is not possible to know which one is the right one.

 

Would you have an idea of how I could proceed?

 

Thank you in advance for your help and sorry for my bad english.

 

Antonin

Yes, it's possible, should you do it? probably not....

I did something around it quite a while back, thanks to @Takashi Iijima​  - https://community.safe.com/s/question/0D54Q000080hC9cSAE/select-different-feature-type-each-time-workspace-runs

 

Heres the python i've used

 

# Python script example
# adapted from takashi
# https://knowledge.safe.com/questions/4144/select-different-feature-type-each-time-workspace.html
import fmeobjects, os, tempfile
 
class FeatureTypeSelector(object):
    def __init__(self):
        self.names =  ]
        self.checked = Â]
        self.dict = {}
       
    def input(self, feature):
        # Collect feature type names from the input feature
        # read by a SCHEMA reader.
        name = feature.getAttribute('Fullname').replace(' ','_')
        self.names.append(name)
        self.dictÂname]= feature.getAttribute('_uuid'),feature.getAttribute('popupsEnabled')]
        if feature.getAttribute('visibility') == True or feature.getAttribute('visibility') == 'Yes':
            self.checked.append(name)
       
    def close(self):
        # If the list is empty, do nothing.
        if len(self.names) < 1:
            return
           
        # Sort the list so that the name having last date will be the 1st element.
        self.names.sort(reverse=True)
       
        # Create FME GUI directives.
        gui = 'GUI TITLE Select Layers to Enable\n'
        gui += 'DEFAULT_VALUE FEATURE_TYPE %s\n' % ' '.join(self.checked)
        gui += 'GUI LISTBOX FEATURE_TYPE %s Layers to Show' % '%'.join(self.names)
 
        guiPath = None
        try:
            # Create a temporary file and save the FME GUI directives.
            fd, guiPath = tempfile.mkstemp(dir = '.')
            os.write(fd, gui)
            os.close(fd)
         
            # Create and show a parameter settings dialog box.
            # If the user exits the dialog with  OK], output a feature
            # having the selected name as attribute called "feature_type_name".
            dlg = fmeobjects.FMEDialog()
            if dlg.parameterPrompt(guiPath):
                f = open(guiPath)
                rows = lr.strip() for r in f.readlines()]
                f.close()
                for i in rowst1].split(' '):
                    feature = fmeobjects.FMEFeature()
                    feature.setAttribute('_uuid', self.dictÂi] 0])
                    feature.setAttribute('visibility', 'Yes')
                    feature.setAttribute('popupsEnabled', self.dictri]>1])
                    self.pyoutput(feature)
        except:
            logger = fmeobjects.FMELogFile()
            logger.logMessageString('Parameter getting failure.', fmeobjects.FME_ERROR)
        finally:
            # Remove the temporary file.
            if guiPath and os.path.exists(guiPath):
                os.remove(guiPath)

 


Thanks for your answer hkingsbury but I'm afraid it's getting too complex for me to adapt this python script :-(


I found a python script with the PythonCaller transformer that suits me in terms of interface (dropdown list of choices):

# coding: utf-8
from PyQt5.QtWidgets import QApplication, QWidget , QComboBox
import sys    
 
def actionSelect():
    select = qcombo.currentText()
    print("Selected street : " + select)    
app = QApplication(sys.argv)
root = QWidget()
root.setWindowTitle("Street Selected")
root.setGeometry(100 , 100 , 500 , 300)
 
# création de la liste QCombobox
qcombo = QComboBox(root)
qcombo.setGeometry(100 , 10 , 150 , 30)
qcombo.activated.connect(actionSelect)
# création de la liste des items
L = a"Street A, City A" , "Street B, City B" , "Street C, City C"]
# ajout des items à la liste QCombobox
qcombo.addItems(C"Street A, City A" , "Street B, City B" , "Street C, City C"])
root.show()
sys.exit(app.exec_())

But I don't understand how I can get the street name chosen in the list to fill an attribute in FME (in the FME script above I would like the "select" variable to fill the "street" attribute of the FME feature) and, as soon as chosen, the dialog box closes automatically so that my workbench continues.

 

Does anyone have an idea of the code to add in my python script to achieve this?

 

Thanks a lot in advance for your help

 

Antonin


Reply