Select by many attributes and then zoom to selected

2880
14
04-27-2018 02:38 AM
MichaelMichaelides
New Contributor II

simple model builderMore complex modelGUI

Hello. I need the help of the community and if possible the help of an ESRI’s staff.

After days and days of searching and reading different posts in the net and many dead ends (broken links) in ESRI’s site, I couldn’t find a solution to my problem.

My problem is that I’m trying to give a tool to some colleagues (ArcMap 10.5), that don’t have any experience with GIS software, which would help them to zoom to a selected parcel by selecting a value from various drop-down lists and not writing the SQL query themselves.

The tool which I’m trying to build in Model Builder (coding is not my strong background), will take the following variables: District, Town/Village, Quarter, Block, Sheet, Plan, and Parcel Number. Combining all those variables make the parcel selection unique.

Those Variables are different columns within a single Feature Class called “Parcels”.

In my model I used a tool that I had from an old search (now is a broken link) called “ChooseFieldValueToolbox10.tbx”. This tool let me expose as a list, the values from a field. Then I found the code (that actually works) from another post in the community (https://community.esri.com/thread/8396 - thanks Paul Lang), to zoom to selected feature.

Through my many failed attempts I decided to make the model (for testing purposes) with only one variable and not use all the aforementioned variables, just to see if it works, which it does (screenshot 1). For example the user to select a District or to select a Town as different models each time.

The problem is when I want to make combination of all those parameters. I can’t force the model to select from current selection and then zoom to final selection.

I attached a screenshot (screenshot 2) of my model, with the use of the first two variables (District and Town/Village).

When I run the tool, at the interface (screenshot 3), the second selection (Value (2)) does not populate the values based on the first selection (Value), instead it shows all the values of the field (Field(2)), and then nothing runs as it supposed to do. For example if in the second “Select by attributes” tool (screenshot 2), I have as a “Selection Type = SUBSET_SELECTION”, nothing gets selected so the zoom doesn’t work. If in the second “Select by attributes” tool (screenshot 2), I have as a “Selection Type = ADD_TO_SELECTION”, it selects all the rows that have the same “Dist_code” and doesn’t take account the Town/Village.

Sorry for the long post but I tried to make my problem as clear as possible.

Any ideas?

0 Kudos
14 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Michael,

I would recommend replacing your first Select Layer by Attribute with the Make Feature Layer tool.  You can apply an expression within this tool that will create a in-memory layer of only the features that apply to the expression.  You can then perform your second select by attribute using this in-memory layer as the input.

MichaelMichaelides
New Contributor II

Jake hello. Thanks for taking the time to answer my question.

First of all i would like to inform you that i found an error in my model. In the second "Select by attributes" in the expression there was an oversight. At first (screenshot 2 - first post), i wrote VIL_NM_E = '%Output Value% ' instead of VIL_NM_E = '%Output Value (2)% '  and there was something like a conflict with the first expression ("DIST_CODE" = %Output Value%). 

After that correction, my model still didn't populate the values in the second drop down list (Value(2)) based on the selected District and instead it showed all the villages but if i selected  a district and one village that belonged to that district after running the model, ArcMap zoomed in to the selected feature, correctly (screenshot 4 and 5).

screenshot4.JPGscreenshot5.JPG

Now if by a mistake i selected a village that it didn't belong to that district (due to the fact that i see all vilages from the list), instead of an error, ArcMap zoomed in to  a different  village that the one that i selected. That village as i noticed was the first village based on an alphabetical order,  that belongs to the district that i previously chose (screenshot 6 and 7).

screenshot6.JPG

screenshot7.JPg

Then i tried your recommendation (screenshot 8), but it didn't work at all. Also in the (Value(2)), i got only one value regardless the ditrict that i choose (screenshot 9). When i run the model i got an error (screenshot 10). In the "Make Feature Layer" expression, i used the expression from the first "Select by attributes", which was "DIST_CODE" = %Output Value%. I don't know what i might did wrong. 

screenshot8.JPG

screenshot9.JPG

screenshot10.JPG

I prepared some data containing  a feature class called "Vill_selected", the script tool that my model is based on, my model that i run and a model based on your recommendation. How can i send them to you (if you want to give it a try)?

0 Kudos
JakeSkinner
Esri Esteemed Contributor

You can add the data to this thread by clicking the 'Use Advanced Editor' in the top right of the reply.  You will then see an option to Attach files in the lower left corner.

MichaelMichaelides
New Contributor II

Hi Jake. Thanks for replying.

I attached as a zip file the data that i mentioned in my last comment.

Thanks again for your time and effort.

Regards 

Mike

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Michael,

I recreated the model and used references to all of the parameters (i.e. %Field%, %Value%) in the select by attributes and this worked for me.

0 Kudos
MichaelMichaelides
New Contributor II

Jake hello.

I saw your answer but I’m not at work to try it. 

Though if I understood correctly you did what I did and the model worked? Did I do something wrong? Please can you clarify this for me?

0 Kudos
MichaelMichaelides
New Contributor II

Jake good morning.

Ignore my previous answer. I couldn't see in my phone that you attached something.

So today,  i opened the zip file that you sent me and i used the "mymodel_test".

Still doesn't working correctly.

The values in the "Value(2)" drop down list shows all villages in the feature class regardless of the District Value selection. In the screenshot you can see from the attribute table that for the District Code = 3, the number of records are 8, but the drop down list in the model shows more than eight entities. 

Any more ideas?

Thank you and regards.

Mike

mymodel_test

0 Kudos
RandyBurton
MVP Alum

Hello Michael,

After reviewing you project, I think a script tool solution similar to one in Conditional Drop Down Lists - Tool Validator will work for you (see last code example in the discussion -- the ESRI forum you mentioned was also mentioned in this discussion).  In this specific example, the tool takes an input feature and would populate 3 drop down lists with values from 3 fields in that feature. The work of populating the lists is done in the updateParameters section of the ToolValidator.

As your needs call for using 7 fields, some blocks of code (such as this snippet) will need to be duplicated and modified to build the final where clause.  Each block will drill down to get the user closer to the desired parcel, and the fields will need to be processed in proper sequence.

fc, c_3 = str(self.params[0].value), 'Setting' # Check field 'Setting'
if fieldNames['HarvestArea'] == u'String':
    wc3 = "{} AND HarvestArea = '{}'".format(wc2, str(self.params[2].value)) # field is string type
else:
    wc3 = "{} AND HarvestArea = {}".format(wc2, str(self.params[2].value)) # field assumed to be a number field
self.params[3].filter.list = [str(val) for val in sorted(set(row.getValue(c_3) for row in arcpy.SearchCursor(fc,fields=c_3,where_clause=wc3)))]
if self.params[3].value not in self.params[3].filter.list:
    self.params[3].value = self.params[3].filter.list[0]

I'm not sure if the script tool really needs to be part of a model.   If the tool's only goal is to select and zoom to a parcel, perhaps you wouldn't need a model.

Regarding your tool, will users always be searching the same feature class for parcels?  Or if they are searching several features, is the structure of the feature always the same -- that is, do the features always contain the same fields (same field name and type)?

What are the field names that correspond to District, Town/Village, Quarter, Block, Sheet, Plan, and Parcel Number?  In one of the photos above I see the fields: VILL_CCD, DIST_CODE, VIL_NM_E, VIL_MN_G, VIL_CODE.  Are these the field names?

If you are able to attach a few rows of sample data from your "parcels" layer, that would be helpful.

MichaelMichaelides
New Contributor II

Mr Burton hello and thank you for your answer.

Before contacting you, I did try to use the final code that you provided  for the tool validator  in the  Conditional Drop Down Lists - Tool Validator, replacing "Forest" with "DIST_CODE", "HarvestArea" with "VIL_CODE" and "Setting" with "QRTR_NM_E". Also i replaced the py script with the one that you provided but there i didn't change anything, since "forestVal", "harvestVal", and "settingVal" where not refering with these names in the code before, so i assumed would be ok if i used the original. So after doing this i tried to run the script but i got the following screenshots.  tool_screenshottool_screenshot2

Forgive me for my ignorance but something that bothered me (and could be the problem), was the answer that you provided at the 21st of April and you had this code before the tool validator class block. Should i use this code in the py script merging it with the py code from your last comment? Don't use it at all? 

The reason that i want to make it a model is that i'm not familiar with programming. 

My department has two feature classes for parcels so i would like them to use the tool depending on what their need is.

The column name and field types are the same for both Feature classes. I attached some test data. The fields that will be used based on ierarchy are DIST_CODE, VIL_CODE, QRTR_CODE, BLCK_CODE, SHEET, PLAN, PARCEL_NBR.

Also I have two questions:

1. Will I be able to use this tool with an SDE Feature class that will have a joined table and some of the fields will be from that table?

2. Let's say that the script is ready with no problems, how will I use all the Values that the user selected to make them as one input for zoom in? The original tool that I found and used (ChooseFieldValueToolbox10.tbx) had one Value, one Output and that's why in my first post i used it twice in my model.

Thanks again

Mike

0 Kudos