SPATIALQUERY

Used in

CONFIG  REQUEST  

Servers

Image  Query  Feature  Extract  

Parent elements

BUFFER  GET_FEATURES  LAYER  LAYERDEF 

Syntax

<SPATIALQUERYAttribute Description Table

     When using Image, Extract, Query, or Feature Server:
     accuracy="Distance between points" [0]
     featurelimit="integer" [All that meet criteria]
     joinexpression="string"
     jointables="string"
     searchorder="optimize | spatialfirst | attributefirst" [optimize]
     subfields="#ALL# | #ID# | #SHAPE# | Other fields in database" [#ALL#]
     where="string"

     When using Query Server:
     order_by="string"
>


     When parent element is BUFFER:
     <FEATURECOORDSYS... />
     <FILTERCOORDSYS... />
     <SPATIALFILTER... />

     When parent element is GET_FEATURES:
     <BUFFER... />
     <FEATURECOORDSYS... />
     <FILTERCOORDSYS... />
     <SPATIALFILTER... />

     When parent element is LAYER and LAYERDEF in GET_IMAGE:
     <BUFFER... />
     <SPATIALFILTER... />

     When parent element is LAYER in CONFIG:
     <FILTERCOORDSYS... />
     <SPATIALFILTER... />

</SPATIALQUERY >

Description

Queries a dataset in one of three ways:
  1. A tabular query based on the value of attributes. For example, an attribute query asks for all cities in Canada where the population is greater than 500,000.
  2. A spatial query based on features selected on a map. For example, a rectangle might be dragged over the eastern United States to select a group of cities.
  3. A combination of a tabular and spatial query. For example, a group of cities might be selected, but only cities with a population greater than 500,000 are displayed.

SPATIALQUERY is also used to join DBF files to shapefiles and to relate tables in ArcSDE.

Restrictions


Notes


Attribute Descriptions for SPATIALQUERY

AttributeUsage
accuracyUsed in GET_FEATURES requests only. Points are generalized within a feature based on the distance specified and the resolution of the image. Units are the same as the service. A value of 0 for accuracy returns all points of a feature, whereas higher values return a feature with fewer points thus making the feature more generalized. Note that given a non-zero value used for accuracy, and depending on the geometry layout of features in a layer, polylines or polygons may become self-intersecting. When this happens, the geomtery is invalid, the feature is ignored, and no result is returned for the spatial query. Accuracy cannot be used on a point layer; only polygon and polyline layers are valid. It is recommended to use accuracy="0" during any BUFFER operation.
featurelimitMaximum number of features to be extracted that meet criteria. See Notes section for more information.
joinexpressionProvides the join expression for queries on shapefiles and DBF files. Not required when a jointable is done on ArcSDE.

String must form expression: "To=[master table (shapefile DBF) column which will be used for joining], From=[external DBF table column which will be joined], Type=[exact or scan]".
jointablesList of joined table names separated by blank spaces; for ArcSDE, table name is full name including database name (e.g., DATA.STATE); for shapefiles, use the DBF filename without the extension (e.g., STATES).
searchorderUsed with ArcSDE layers only. Determines whether the attribute or spatial part of an ArcSDE query is processed first. "Spatialfirst" processes the spatial part of the query before the attribute part. "Attributefirst" processes the attribute part of the query first. If "optimize" is used, ArcSDE will make the judgment whether to pick "spatialfirst" or "attributefirst".
subfieldsList of fields available for querying or extracting. Multiple fields can be included in the subfields list. Fields must be separated by blank space.

If subfields is not used, all fields are returned. If subfields is used, only listed fields are returned. The subfields #SHAPE# or #ALL# must be included if geometry is to be returned in a FEATURES response. In addition, the GET_FEATURES geometry attribute must be set to true.

The subfields list can include fields from the layer table or a joined table.
  • For shapefiles with no joined tables, the field can be referenced using the short format.
    field="AREA"
  • For shapefiles with joined tables, the name of the joined table must be included along with the field.
    field="JOINEDTABLE.AREA"
  • For ArcSDE layers with or without joined tables, the field must be referenced using the full long format.
    field="ARCSDENAME.TABLE.AREA"
Performance is generally better if the field names are all upper case.
whereDefines 'where' part of SQL expression. Required when jointables attribute for ArcSDE tables is used. See Notes section for information on querying dates.
order_byDefines the 'order by' part of an SQL expression. You must include "ORDER BY" as part of the attribute value.

order_by="ORDER BY DB.COUNTRIES.NAME"

This attribute is valid only with GET_FEATURES requests.
Back to top 

Examples for SPATIALQUERY

Example 1: Setting a spatial query in a GET_IMAGE request. Note in this example that the DATASET fromlayer is "Countries". This refers to the LAYER id in the map configuration file, not the LAYER name.
<?xml version="1.0" encoding="UTF-8"?>
<ARCXML version="1.1">
<REQUEST>
  <GET_IMAGE>
    <PROPERTIES>
      <ENVELOPE minx="-180" miny="-90" maxx="180" maxy="90" />
      <IMAGESIZE width="643" height="502" />
    </PROPERTIES>
    <LAYER type="featureclass" name="select layer" visible="true" id="300">
      <DATASET fromlayer="Countries" />
      <SPATIALQUERY>
        <SPATIALFILTER relation="area_intersection">
          <ENVELOPE maxy="30" maxx="30" miny="0" minx="0" />
        </SPATIALFILTER>
      </SPATIALQUERY>
      <SIMPLERENDERER>
        <SIMPLEPOLYGONSYMBOL fillcolor="255,255,255" filltype="cross" />
      </SIMPLERENDERER>
    </LAYER>
  </GET_IMAGE>
</REQUEST>
</ARCXML>

Example 2: Setting a spatial query in a GET_FEATURES request.
<?xml version="1.0" encoding="UTF-8"?>
<ARCXML version="1.1">
    <REQUEST>
      <GET_FEATURES outputmode="xml" geometry="false">
        <LAYER id="Countries" />
           <SPATIALQUERY >
             <SPATIALFILTER relation="area_intersection">
                <POLYGON>
                <RING>
                   <POINT x="-87.73640582356195" y="41.84726275" />
                   <POINT x="-87.73640582356195" y="41.884308250000004" />
                   <POINT x="-87.68764017643805" y="41.884308250000004" />
                   <POINT x="-87.68764017643805" y="41.84726275" />
                   <POINT x="-87.73640582356195" y="41.84726275" />
                </RING>
                </POLYGON>
             </SPATIALFILTER>
           </SPATIALQUERY>
      </GET_FEATURES>
    </REQUEST>
</ARCXML>

Example 3: Joining DBF files in CONFIG.
<?xml version="1.0" encoding="UTF-8"?>
<ARCXML version="1.1">
  <CONFIG>
    <ENVIRONMENT>
      <LOCALE country="US" language="en" variant="" />
      <UIFONT color="0,0,0" name="Arial" size="12" style="regular" />
      <SCREEN dpi="96" />
    </ENVIRONMENT>
    <MAP>
      <PROPERTIES>
        <ENVELOPE minx="-178.215027" miny="18.924782" maxx="-66.969849" maxy="71.406647" name="Initial_Extent" />
        <MAPUNITS units="decimal_degrees" />
        <FILTERCOORDSYS id="4326" />
        <FEATURECOORDSYS id="4326"/>
      </PROPERTIES>
      <WORKSPACES>
         <SHAPEWORKSPACE name="shp_ws-0" directory="<path to USA ESRIDATA>" />
      </WORKSPACES>

      <LAYER type="featureclass" name="counties" visible="true" id="0">
        <DATASET name="COUNTIES" type="polygon" workspace="shp_ws-0" />

          <SPATIALQUERY where="counties.STATE_NAME=&apos;Nevada&apos;" jointables="countyinfo" joinexpression="To=[counties.FIPS],From=[countyinfo.FIPS],Type=[scan]" >  
            <SPATIALFILTER relation="area_intersection">
                  <ENVELOPE minx="-126" miny="31" maxx="-108" maxy="46" />
            </SPATIALFILTER>
          </SPATIALQUERY>

        <SIMPLERENDERER>
          <SIMPLEPOLYGONSYMBOL fillcolor="27,127,27" filltype="solid" />
        </SIMPLERENDERER>
      </LAYER>

    </MAP>
  </CONFIG>
</ARCXML>

Example 4: Joining ArcSDE tables in CONFIG.
<?xml version="1.0" encoding="UTF-8"?>
<ARCXML version="1.1">
  <CONFIG>
    <ENVIRONMENT>
      <LOCALE country="US" language="en" variant="" />
      <UIFONT color="0,0,0" name="Arial" size="12" style="regular" />
      <SCREEN dpi="96" />
    </ENVIRONMENT>
    <MAP>
      <PROPERTIES>
      <ENVELOPE minx="-175.2" miny="-90.0" maxx="179.2" maxy="83.6" name="Initial_Extent" />
      <MAPUNITS units="decimal_degrees" />
      <FILTERCOORDSYS id="4326" />
      <FEATURECOORDSYS id="4326"/>
      </PROPERTIES>
      <WORKSPACES>
      <SDEWORKSPACE name="sde_ws-4" server="sierra" instance="esri_sde" database="" user="world_data" encrypted="true" password="LXEMUR" />
      </WORKSPACES>
      <LAYER type="featureclass" name="WORLD.CITY" visible="true" id="0">
      <DATASET name="WORLD.CITY" type="point" workspace="sde_ws-4" />

        <SPATIALQUERY where="WORLD.CITY.FIPS_CNTRY = WORLD.COUNTRYP.FIPS_CNTRY and WORLD.COUNTRYP.FIPS_CNTRY=&apos;CA&apos; " jointables="WORLD.COUNTRYP" >  
          <SPATIALFILTER relation="area_intersection">
           <ENVELOPE maxy="30" maxx="30" miny="0" minx="0" />
          </SPATIALFILTER>
        </SPATIALQUERY>

      <SIMPLERENDERER>
        <SIMPLEMARKERSYMBOL color="27,227,27" width="8" />
      </SIMPLERENDERER>
      </LAYER>
    </MAP>
  </CONFIG>
</ARCXML>

Example 5: Using both an attribute query and a spatial filter in CONFIG.
<?xml version="1.0" encoding="UTF-8"?>
<ARCXML version="1.1">
  <CONFIG>
    <ENVIRONMENT>
      <LOCALE country="US" language="en" variant="" />
      <UIFONT color="0,0,0" name="Arial" size="12" style="regular" />
      <SCREEN dpi="96" />
    </ENVIRONMENT>
    <MAP dynamic="true">
      <PROPERTIES>
        <ENVELOPE minx="-180" miny="-90" maxx="180" maxy="90" name="Initial_Extent" />
      <MAPUNITS units="decimal_degrees" />
      <FILTERCOORDSYS id="4326" />
      <FEATURECOORDSYS id="4326"/>
      </PROPERTIES>
      <WORKSPACES>
        <SHAPEWORKSPACE name="shp_ws-0" directory="<path to WORLD ESRIDATA>"/>
      </WORKSPACES>
      <LAYER type="featureclass" name="CITIES" visible="true" id="2">
      <DATASET name="CITIES" type="point" workspace="shp_ws-0" />
      <SPATIALQUERY where="POPULATION &gt; 2000000">
        <SPATIALFILTER relation="area_intersection">
          <ENVELOPE maxy="30" maxx="30" miny="0" minx="0" />
        </SPATIALFILTER>
      </SPATIALQUERY>
      <SIMPLERENDERER>
        <SIMPLEMARKERSYMBOL type="square" width="5" />
      </SIMPLERENDERER>
      </LAYER>
    </MAP>
  </CONFIG>
</ARCXML>

Example 6: Using a date query in a GET_FEATURES request.
<?xml version="1.0" encoding="UTF-8" ?>
<ARCXML version="1.1">
  <REQUEST>
    <GET_FEATURES featurelimit="25" beginrecord="0" outputmode="xml" geometry="false" envelope="true" compact="true">
      <LAYER id="0" />
      <SPATIALQUERY subfields="#ALL#" where="MYDATE = {ts '2000-01-07'}" />
    </GET_FEATURES>
  </REQUEST>
</ARCXML>

Back to top