Geocode filters

When used with a standard attribute of type geocode, the EQL DISTANCE function indicates a filter based on the distance of that geocode attribute from a given reference point.

The DISTANCE function returns the distance (in kilometers) between two geocodes. The syntax for DISTANCE is:
DISTANCE(geoAttribute, TO_GEOCODE(latitude,longtitude))
where geoAttribute is a standard attribute of type geocode.
The TO_GEOCODE function creates a geocode from a given latitude and longitude pair, both of which must be of type double:
  • The latitude of the location is specified in whole and fractional degrees (positive values indicate north latitude, and negative values indicate south latitude).
  • The longitude of the location in whole and fractional degrees (positive values indicate east longitude, and negative values indicate west longitude).

The distance limits in geocode filters are always expressed in kilometers. The records are filtered by the distance from the geocode reference point to the latitude/longitude pair.

Note that both DISTANCE and TO_GEOCODE operate only on single-assign geocode attributes.

Between geocode filters

Use the BETWEEN operator to indicate that the distance from the geocode attribute to the reference point is between two bounds:
  • The lower bound specifies a greater-than distance (in kilometers) from the geocode attribute to the reference point.
  • The upper bound specifies a less-than distance (in kilometers) from the geocode attribute to the reference point.
The following example uses the BETWEEN operator:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
      <Request xmlns="http://www.endeca.com/MDEX/conversation/3/0">
        <Language>en</Language>
        <State>
          <DataSourceFilterString>
            COUNTRY_NAME = 'United States of America'
          </DataSourceFilterString>
          <SelectionFilterString>
            DISTANCE(Location, TO_GEOCODE(40.758224, -73.917404)) BETWEEN 1 AND 500
          </SelectionFilterString>
        </State>
        <RecordListConfig Id="RecordList MaxPages="20">
           <RecordsPerPage>5</RecordsPerPage>
        </RecordListConfig>
      </Request>
    </soapenv:Body>
</soapenv:Envelope>

The query returns only records whose location (in the Location property) is between 1 and 500 kilometers from the reference point.

Less-than and greater-than geocode filters

You can make queries that return records that are less-than or greater-than a specific number of kilometers from the reference point:
  • To make a less-than geocode query, use only the < (less-than) operator. Because you are specifying only the upper bound of the distance from the reference point, all returned records will fall below this bound.
  • To make a greater-than geocode query, use only the > (greater-than) operator. Because you are specifying only the lower bound of the range, all returned records will be above this bound.
The following is an example of a greater-than geocode query:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
      <Request xmlns="http://www.endeca.com/MDEX/conversation/3/0">
        <State>
          <DataSourceFilterString>
            COUNTRY_NAME = 'United States of America'
          </DataSourceFilterString>
          <SelectionFilterString>
            DISTANCE(Location, TO_GEOCODE(40.758224, -73.917404)) > 200
          </SelectionFilterString>
        </State>
        <RecordListConfig Id="RecordList MaxPages="20">
           <RecordsPerPage>5</RecordsPerPage>
        </RecordListConfig>
      </Request>
    </soapenv:Body>
</soapenv:Envelope>

The query returns only records whose location (in the Location property) is equal to or greater than 200 kilometers from the reference point.

An example of a less-than query would be the same except for the use of the < (less-than) operator.