2

I am new to Python and want to create a script inside the ArcMap Python window. My current workspace is a series of rivers portrayed in the state of Ohio. I have a list of fish and the rivers (from my series of rivers) they are found in. Ideally, I would like the user to be able to enter the name of a fish and have the script highlight or select the rivers in the map.

For example, if I were a fisherman who was not from this area and wanted to catch a certain fish (such as a smallmouth bass) I could type the fish into the script as a raw input and have the map highlight the rivers where this fish could be caught.

I have an excel sheet with column titles as fish (i.e. largemouth bass, smallmouth bass, etc) and each row is a river name that they can be found in

How might I go about doing this?

Excel format:

Largemouth Bass (Col 1. Title)           Smallmouth Bass (Col 2. Title)
Ashtabula River                          Ashtabula River
Chagrin River                            Chagrin River
Cuyahoga River                           Conneaut Creek
Grand River                              Grand River           
Huron River                              Huron River
Rocky River                              Rocky River
Sandusky River                           Vermillion River
Vermillion River
  • 1
    Welcome to GIS SE! I have edited the title of your post to make it more clear to other users of this site what you are asking. If you feel that this title does not serve the purpose of your question, feel free to edit it. – Conor Dec 9 '13 at 19:24
  • What version of ArcGIS for Desktop are you using? You can edit your Question to include this important detail. – PolyGeo Dec 9 '13 at 20:17
  • Could you describe more specifically what data you have, its design, purpose, and what you would like to do with it? A specific example where you work through it manually might be helpful. – blah238 Dec 9 '13 at 20:23
  • I am using 10.1. The purpose is mostly for practice and understanding. For example, if I were to use the script as a fisherman who is not from this area and wanted to catch a certain fish, I would like to be able to enter that fish and see what rivers on which they could be caught (highlighted on the map) – Tim Dec 9 '13 at 20:30
  • Could you post an example of the Excel data? You can use the preformatted <pre></pre> tags to make it show up correctly. Also, assuming you have actually used the data before, could you describe your current process? – blah238 Dec 9 '13 at 21:12
1

The ArcMap Python window is simply for interacting with Python and the current ArcMap session programmatically, not so much for your users to interact with a tool you create. For that, you might look into Python toolboxes, script tools and Python add-ins.

If you really want to get user input from the Python window, you could try using raw_input.

Perhaps you could clarify what your goals are. If you are just learning for yourself then by all means use the Python window to interact with the current ArcMap session. If you want to save your code to a file then use a text editor or preferably a Python IDE such as PyScripter or Eclipse with PyDev. You could then import this file into the Python window if you like, or use it in one of the aforementioned customization types.

If you are specifically looking for help on how to create a select statement (actually just the WHERE clause part of a select statement, since that's all you need most of the time), see this question: Including variable in where clause of arcpy.Select_analysis()?

|improve this answer|||||
0

That sounds like a simple query. Are the fish and rivers in the same feature class or separate tables? Take a look at the arcpy or arcgisscripting nomenclature for makefeaturelayer, selectlayerbyattribute and selectlayerbylocation. For example:

query = "[SPECIES] = " + userinput
gp.MakeFeatureLayer("FISH", "lyr1")
gp.MakeFeatureLayer("RIVERS", "lyr2")
gp.SelectLayerByAttribute("lyr1", "NEW_SELECTION", query)
gp.SelectLayerbyLocation("lyr2", "HAVE_THEIR_CENTER_IN", "lyr1", "", "NEW_SELECTION")
|improve this answer|||||
  • I have an excel sheet with column titles as fish (i.e. largemouth bass, smallmouth bass, etc) and each row is a river name that they can be found in – Tim Dec 9 '13 at 20:24
  • @Tim, please edit your question to include this information and any other clarifying information you can provide, rather than adding it as comments. – blah238 Dec 9 '13 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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