0

This question already has an answer here:

I need to design a Python script that will take a CSV input, search for a matching polygon in our SDE data for each line, and then extract certain information about data that intersects with the polygon.

This is straightforward, except that about 5% of the input values will not be exact matches (e.g. a parcel number will have hyphens in the CSV, but the SDE value has no hyphens). I've got a few tests in there to handle these cases, but it will inevitably result in some situations where the script returns multiple possible candidate polygons and the user needs to be able to indicate which is correct. For example, the number may pull up Polygon A and Polygon B as possibilities, and it's up to the GIS analyst to visually examine to decide which is in the correct region.

If I was running the script in IDLE, then I could simply use raw_input to get that user input and proceed with the rest of the steps. Is there an equivalent mid-script method in ArcMap that accepts user input? I am only aware of the initial tool parameters, which wouldn't be useful for this issue.

marked as duplicate by ianbroad, Brad Nesom, radouxju, PolyGeo Jan 6 '15 at 22:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Good catch @ian. I did search, but didn't find that somehow. – Erica Jan 6 '15 at 18:10
3

Here is a really jankety solution using wxPython:

import wx
import os

def get_pid(parcels):
    app = wx.App(False)
    frame = MyForm(parcels)
    frame.Show()
    app.MainLoop()
    txt = os.path.join(os.environ['USERPROFILE'], r'Desktop\temp_parcel_Id.txt')
    with open(txt, 'r') as f:
        pid = f.readlines()[0].strip()
    os.remove(txt)
    return pid


########################################################################
class MyForm(wx.Frame):

    #----------------------------------------------------------------------
    def __init__(self, pars):
        wx.Frame.__init__(self, None, wx.ID_ANY, "Choose Parcel")

        # Add a panel so it looks the correct on all platforms
        panel = wx.Panel(self, wx.ID_ANY)

        sampleList = []
        self.cb = wx.ComboBox(panel,
                              size=wx.DefaultSize,
                              choices=sampleList)
        self.widgetMaker(self.cb, pars)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.cb, 0, wx.ALL, 5)
        panel.SetSizer(sizer)


    #----------------------------------------------------------------------
    def widgetMaker(self, widget, objects):
        """"""
        for obj in objects:
            widget.Append(obj)
        widget.Bind(wx.EVT_COMBOBOX, self.onSelect)

    #----------------------------------------------------------------------
    def onSelect(self, event):
        """"""
        self.selection = self.cb.GetStringSelection()
        txt = os.path.join(os.environ['USERPROFILE'], r'Desktop\temp_parcel_Id.txt')
        with open(txt, 'w') as f:
            f.write(self.cb.GetStringSelection())

# Run the program
if __name__ == "__main__":

    parcels = ['110120031', '180170020', '180150041']
    pid = get_pid(parcels)
    print pid

There are probably better ways out there, but I do not have much experience with making GUI's in Python, but this worked for me. You can call the get_pid() from your module and pass in your parcel ID's. The way this works is the user hits the dropdown and selects a parcel ID then closes the box. The PID is then returned.

enter image description here

This isn't the prettiest UI, but if you play with the code a bit it can be resized.

  • One disclaimer...everyone who uses this will also have to install wxPython on their machines or you can put the wx-3.0msw folder in a shared location along with the wx.pth and wxversion.py and use sys.append(path) to make sure it is always imported properly in the script. – crmackey Jan 6 '15 at 17:34
1

If I remember correctly, there is no arcpy equivalent to raw_input that can be used in an ArcGIS environment. I would suggest a workaround. One thing you might do is have a second script for these instances. Save any intermediate data at the point where the user needs to make his or her choice. Have your second script reference the saved data as needed and have its input be the choice that needs to be made by the user.

Not the answer you're looking for? Browse other questions tagged or ask your own question.