10 Replies Latest reply on Jun 4, 2014 8:00 AM by esri_bing

    Multiple Query

    amanda_hutsel
      Is it possible to perform multiple queries at the same time?  For example, the application user might need to search for homes given $20,000 in 2009.  These are two different attribute fields.  I looked for example code and could find none for querying multiple attributes.  Thanks, Amanda
        • Re: Multiple Query
          rscheitlin
          Amanda,

             Sure the QueryTask and Query supports most basic SQL styntax in the where attribute of the Query object.

          So if you take the "Query results on map" sample and change the query object like this it will work:

          http://help.arcgis.com/en/webapi/flex/samples/index.html#/Query_result_on_Map/01nq0000003q000000/

          <fx:Declarations>
                  <!-- Layer with US States -->
                  <esri:QueryTask id="queryTask"
                                  showBusyCursor="true"
                                  url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5"
                                  useAMF="false"/>
                  
                  <esri:Query id="query"
                              outSpatialReference="{myMap.spatialReference}"
                              returnGeometry="true"
                              where="STATE_NAME like '{qText.text}%' AND POP2007 &gt; 500000">
                      <esri:outFields>
                          <fx:String>MED_AGE</fx:String>
                          <fx:String>POP2007</fx:String>
                      </esri:outFields>
                  </esri:Query>
              </fx:Declarations>


          Don't forget to click the Mark as answer check on this post and to click the top arrow (promote) as shown below:
          • Re: Multiple Query
            amanda_hutsel
            Is it possible to do this with a Feature Layer search or does it need to be a Graphics Layer Query?
            • Re: Multiple Query
              rscheitlin
              Amanda,

                 Yes a FeatureLayer has a queryFeatures method on it just look at the documentation:

              http://help.arcgis.com/en/webapi/flex/apiref/com/esri/ags/layers/FeatureLayer.html

              Don't forget to click the Mark as answer check on this post and to click the top arrow (promote) as shown below:
              • Re: Multiple Query
                esri_bing
                I also have a question here. I am using the Viewer to build a Property Info System. I need to query 10 layers( from one dynamic map service) to get about 30 fields, then sort and display the data in a grid/table.
                Do you think I should use your eSearch widget or the original Search widget, Robert? (I downloaded eSearch too, thank you for the great work)

                Also, should I use query task or queryFeatures? The Search widget uses queryFeatures method. As far as efficiency, Is there any difference between query and queryFeatures? I have been searching but no results found yet.

                Huge thanks for the help.
                • Re: Multiple Query
                  rscheitlin
                  Bing Jing,

                     Because you want to display the data sorted in a datagrid I would suggest the eSearch over using the OTB search widget and the Attribute table widget.

                     When I see people say they need to query more than a couple of layers I wonder way. Web mapping apps should be focused (have a specific purpose) and not just be a general do everything one stop shop.

                  As far a query task versus a feature layers query features, it really depends. If you already have your data loaded as a featurelayer in the map then using a queryfeatures method is the natural choice. As far as one being faster/better than the other, I believe both are optimized, both will have to make a round trip to the server. The eSearch widget uses selectFeatures, so that the user can add to or remove from the current selection or just create a new selection.
                  • Re: Multiple Query
                    esri_bing
                    Robert, Thank you for the reply.

                    First, our base map service has 30+ layers.  If user types in an address, we can find the property value, sale date on one layer. But, we need to query the "Flood Zone" layer to get flood information, then query "Street Sweeping" Layer to get sweeping schedule, .... etc. These information are on different layers so they can be turned on/off.

                    Our GIS manager and planning staff wants to see all information related to this address,  all these are in different layers.

                    So is there a better solution, or the map should be made differently? I sincerely want to know too.

                    Thank you again.
                    • Re: Multiple Query
                      rscheitlin
                      Bing Jing,

                         Yes there is a better solution. You could create a dataset that contains all the info. I do this on a nightly basis using SQL Server Integration Service to combine multiple datasets to one polygon featureclass that will be used in all my querying. If you know that a certain piece of data is needed each time for a parcel than why not have that data contained in that parcel polygons attributes?
                      • Re: Multiple Query
                        esri_bing
                        Robert
                        I am trying to digest your information. I need to learn how to do it. Without spending too much of your time, could you give a little more details about how to start? or what to search on?
                        • Re: Multiple Query
                          rscheitlin
                          Bing Jing,

                            This is a very involved process that would take a lot of time to explian and is not flex related. Google is your best friend in this sitiuation.
                          • Re: Multiple Query
                            esri_bing
                            Thank you Robert. I brought the idea to our GIS staff.  Unfortunately it is not feasible. So I will still query multiple layers.
                            We appreciate your help though.