Adding SPATIALQUERY for feature limits, filters, joining tables expand/collapse all
Related Topics

SPATIALQUERY

Strategies for using feature limits

expand/collapse item About SPATIALQUERY

You may want to occasionally put constraints on your layer and data. Constraining your data not only protects it but is important when considering performance. The less data accessed, processed, and returned, the faster the response is. You can use SPATIALQUERY in your map configuration file to add constraints. Some common uses of SPATIALQUERY are:

  1. Showing only a subset of the full data set. You can constrain data through a where clause. You can also limit data to a specific geographic region.
  2. Limiting the number of features that can be queried per request. If a data layer contains thousands or millions of features, you do not want someone querying for every feature. To avoid this problem, you can set a feature limit to a reasonable number of features. Note that this feature limit is for retrieving the tabular data for a feature. The number of features displayed on a map is unaffected by this limit. For more information on feature limits, see Strategies for using feature limits.
  3. Limiting the number of fields available for querying. Your data may contain fields that do not need to be public. Unnecessary information clutters a page and slows down the response time.
  4. Setting whether the data is first searched by attribute or spatially. When using ArcSDE layers, performance can sometimes improve dramatically by the way the data is searched. In some cases, it is faster to search spatially first, and in other cases the data should be search first by attribute.
  5. Setting how records in a field should be ordered, such as alphabetizing them. This feature is available when using ArcSDE layers.

In addition to setting constraints, SPATIALQUERY is also used for joining tables in ArcSDE and with shapefiles. In general, joining tables decreases performance. Therefore, you should limit the number of joined tables in ArcIMS.

The values you set in the configuration file cannot be overridden by a request. This is an important consideration when trying to protect your data or your site.

For more information, see SPATIALQUERY.

Note: Once you have added SPATIALQUERY to a map configuration file, you should not open and save the file in Author. Your edits will be deleted by Author.

expand/collapse item How to use SPATIALQUERY

expand/collapse item Setting the feature limit for a layer

  1. Open your map configuration file in a text or XML editor.
  2. Search for the layer where you want to add a feature limit. Add SPATIALQUERY featurelimit. The value you set is the maximum number of features that can be queried in a request. The following example sets the limit to 100 features.

    <LAYER type="featureclass" name="Countries" visible="true" id="1">
      <DATASET name="countries" type="polygon" workspace="shp_ws-0" />
      <COORDSYS id="4326" />
      <SPATIALQUERY featurelimit="100" />
      <SIMPLERENDERER>
         <SIMPLEPOLYGONSYMBOL fillcolor="255,255,153"/>
      </SIMPLERENDERER>
    </LAYER>

  3. Save your changes to the map configuration file.

expand/collapse item Limiting the list of fields available for query

  1. Open your map configuration file in a text or XML editor.
  2. Search for the layer where you want to limit fields. Add SPATIALQUERY subfields, and include the list of fields you want. The subfield names should be all upper case, and each field should be delimited by a space. You should always include the fields #SHAPE# and #ID# or you may get unexpected results when trying to query or buffer features in the layer. In the following example, the fields NAME, POPULATION, #SHAPE#, and #ID# are included.

    <LAYER type="featureclass" name="Countries" visible="true" id="1">
      <DATASET name="countries" type="polygon" workspace="shp_ws-0" />
      <COORDSYS id="4326" />
      <SPATIALQUERY subfields="NAME POPULATION #SHAPE# #ID#" />
      <SIMPLERENDERER>
         <SIMPLEPOLYGONSYMBOL fillcolor="255,255,153"/>
      </SIMPLERENDERER>
    </LAYER>

  3. Save your changes to the map configuration file.

expand/collapse item Setting a filter on your data

  1. Open your map configuration file in a text or XML editor.
  2. Search for the layer where you want to use a filter. Use SPATIALQUERY where to set a tabular filter. Use SPATIALFILTER to set a geographic filter. You can use tabular filters, geographic filters, or both together. The following example limits the data to cities with a population greater than five million within a spatial filter envelope that encompasses part of North America.

    Some symbols must be "escaped" inside a where expression:
          ampersand (&) is escaped to &amp;
          double quotes (") are escaped to &quot;
          single quotes (') are escaped to &apos;
          greater than (>) is escaped to &gt;
          less than (<) is escaped to &lt;

    <LAYER type="featureclass" name="Countries" visible="true" id="1">
      <DATASET name="countries" type="polygon" workspace="shp_ws-0" />
      <COORDSYS id="4326" />
      <SPATIALQUERY where= "POPULATION &gt; 5000000" >
         <SPATIALFILTER relation="area_intersection">
          <ENVELOPE maxy="-140" maxx="30" miny="-60" minx="70" />
        </SPATIALFILTER>
      </SPATIALQUERY>

      <SIMPLERENDERER>
         <SIMPLEPOLYGONSYMBOL fillcolor="255,255,153"/>
      </SIMPLERENDERER>
    </LAYER>

  3. Save your changes to the map configuration file.

expand/collapse item Setting the search order for ArcSDE layers

  1. Open your map configuration file in a text or XML editor.
  2. Search for the layer where you want to change the attribute search order. Add SPATIALQUERY searchorder. Use "spatialfirst" to process the spatial part of the query before the attribute part. Use "attributefirst" to process the attribute part of the query first. If "optimize" is used, ArcSDE will make the judgment whether to pick "spatialfirst" or "attributefirst". The following examples uses "attributefirst".

    <LAYER type="featureclass" name="Countries" visible="true" id="1">
      <DATASET name="countries" type="polygon" workspace="shp_ws-0" />
      <COORDSYS id="4326" />
      <SPATIALQUERY where="POPULATION > 5000000" searchorder="attributefirst" />
      <SIMPLERENDERER>
         <SIMPLEPOLYGONSYMBOL fillcolor="255,255,153"/>
      </SIMPLERENDERER>
    </LAYER>

  3. Save your changes to the map configuration file.

expand/collapse item Setting the order records are displayed for an ArcSDE layer

  1. Open your map configuration file in a text or XML editor.
  2. Search for the ArcSDE layer where you want set the record order. Use SPATIALQUERY order_by to set the record order. Note that you must include "ORDER BY" as part of the attribute value.

    <LAYER type="featureclass" name="Countries" visible="true" id="1">
      <DATASET name="DB.COUNTRIES" type="polygon" workspace="shp_ws-0" />
      <COORDSYS id="4326" />
      <SPATIALQUERY order_by="ORDER BY DB.COUNTRIES.NAME" />
      <SIMPLERENDERER>
         <SIMPLEPOLYGONSYMBOL fillcolor="255,255,153"/>
      </SIMPLERENDERER>
    </LAYER>

  3. Save your changes to the map configuration file.

expand/collapse item Joining tables when using shapefiles

  1. Open your map configuration file in a text or XML editor.
  2. Search for the shapefile layer where you want to join tables. Add SPATIALQUERY joinexpression and jointables. When using shapefiles, all joined tables must be in DBF format in the same directory as the shapefile. You cannot join to a DBF file from another shapefile that is used in a service.

    Follow the syntax carefully for the join expression. In the following example, "COUNTRIES" refers to the shapefile DBF name. "CITIES" refers to the DBF file you want to join. "ID" is the name of the fields being joined. The jointables attribute lists all the tables you want to join, separated by a space.

    <LAYER type="featureclass" name="Countries" visible="true" id="1">
      <DATASET name="countries" type="polygon" workspace="shp_ws-0" />
      <COORDSYS id="4326" />
      <SPATIALQUERY joinexpression="To=[COUNTRIES.ID],From=[CITIES.ID],Type=[scan]" jointables="CITIES" />
      <SIMPLERENDERER>
         <SIMPLEPOLYGONSYMBOL fillcolor="255,255,153"/>
      </SIMPLERENDERER>
    </LAYER>

  3. Save your changes to the map configuration file.

expand/collapse item Joining tables when using ArcSDE

  1. Open your map configuration file in a text or XML editor.
  2. Search for the ArcSDE layer where you want to join tables. Add SPATIALQUERY where and jointables. ArcSDE tables are joined in the where expression using common SQL syntax. In the following example, the COUNTRIES table is joined to COUNTRIES_INFO. The jointables attribute lists all the tables you want to join, separated by a space.

    <LAYER type="featureclass" name="Countries" visible="true" id="1">
      <DATASET name="DB.COUNTRIES" type="polygon" workspace="shp_ws-0" />
      <COORDSYS id="4326" />
      <SPATIALQUERY where="DB.COUNTRIES.FIPS = DB.COUNTRIES_INFO.FIPS" jointables="DB.COUNTRIES_INFO" />
      <SIMPLERENDERER>
         <SIMPLEPOLYGONSYMBOL fillcolor="255,255,153"/>
      </SIMPLERENDERER>
    </LAYER>

  3. Save your changes to the map configuration file.


Search code: @config_spatialquery