Class ria.search.FeatureService

The FeatureService class provides methods to query Spatial Server tables for features. Search results are returned as GeoJSON FeatureCollections. The search call is performed asynchronously and is handled by a Dojo deferred object. Callers must register callbacks with the deferred object using addCallback(...) to handle the returned results and, optionally, addErrback(...) to handle any errors returned.

For example:

                function doSearch() {
                    ...
                    var deferredResult = featureSearch.searchAtPoint(point, srs, tableparam);
                    deferredResult.addCallback(handleResults);
                    deferredResult.addErrback(handleError);
                }

                function handleResults(output) {
                    if (output.features) {
                       ...
                    }
                }

                function handleError(error) {
                    ...
                } 
 

Please note that due to the lack of built-in support for arbitrary-precision numeric values in JavaScript, numeric literals sent by the Spatial Server REST API will be rounded to the nearest double value, if necessary.

Method Summary
Method Attributes Method Name and Description
searchAtPoint(point, srs, table)
Searches for features at a given geographic location.
searchById(tableName, attributes, id, destinationSrs)
Searches for features on a table based on the Id.
searchBySQL(query)
Searches for features on a table using an SQL query.
searchNearest(parameters)
Search for features nearby a given geometry.
Constructor Detail
ria.search.FeatureService(url, restService)
Parameters:
{String} url
Base URL of the Spatial Server REST Service
restService
Method Detail
{dojo.Deferred} searchAtPoint(point, srs, table)
Searches for features at a given geographic location. It is possible to provide a tolerance value in order to include features that are in the immediate vicinity of the given location, but do not overlap with it. This is particularly important for point and line features.
Parameters:
{OpenLayers.Geometry.Point} point
Geographic location
{String} srs
Coordinate system of point
{Object} table
Object with the following properties:
{String} table.name
Name of the table
{String} table.tolerance
Value used to create a buffer around the given point. The search result contains all features intersecting with that buffer. Valid examples are 100 m, or 20 mi. Supported unit valus are ft, km, m, mi, and nm.
{String[]} table.attributes
Subset of the attributes to return for each feature. If not specified, all attributes are returned. Optional.
Returns:
{dojo.Deferred} Handle to manage the asynchronous method call

{dojo.Deferred} searchById(tableName, attributes, id, destinationSrs)
Searches for features on a table based on the Id.
Parameters:
{String} tableName
Name of the table
{String[]} attributes
Columns in the table to be returned in the search results.
{String} id
Value of the primary key to perform the search.
{String} destinationSrs
the spatial reference system to convert returned geometries into. Optional.
Returns:
{dojo.Deferred} Handle to manage the asynchronous method call

{dojo.Deferred} searchBySQL(query)
Searches for features on a table using an SQL query. The query needs to be a full SQL query which contains 'Select' and 'From' as a minimum. The query can also contain 'WHERE' and 'ORDER BY'. The table name which follows the From statement needs to include its full repository path with double quotes, i.e "/NamedTables/UKTable".

For example:

var query = "SELECT * FROM \"/NamedTables/UKCTY215\" WHERE Place_Name = 'LONDON' OR Place_Name = 'Liverpool'";
var deferredResult = featureSearch.searchBySQL(query);
Parameters:
{String} query
SQL query to search for features against an table
Returns:
{dojo.Deferred} Handle to manage the asynchronous method call

{dojo.Deferred} searchNearest(parameters)
Search for features nearby a given geometry.
Parameters:
{Object} parameters
Parameter object with the following properties
{String} parameters.table
Name of the table. Required.
{OpenLayers.Geometry} parameters.geometry
Geometry to search from. Required.
{String} parameters.srs
Spatial reference system of the geometry. Required.
{String[]} parameters.attributes
Subset of the attributes to return for each feature. If not specified, all attributes are returned. Optional.
{String[]} parameters.orderBy
Array of attributes to order the result by. If not specified no ordering is done. Optional.
{String} parameters.withinDistance
Distance value used to create a buffer around the given geometry. The search will be limited to the resulting buffer. Valid examples are 100 m, or 20 mi. Supported distance units are ft, km, m, mi, and nm. Optional.
{String} parameters.distanceAttributeName
Name of the attribute that contains the distance of each returned feature from the given geometry. If not specified, no distance values will be returned. The unit of the returned attribute values is taken from the withinDistance attribute or defaults to mi if withinDistance is not specified. Optional.
parameters.maxFeatures
Maximum number of features returned by this search. Defaults to 1 if not specified. Optional.
parameters.destinationSrs
The spatial reference system to convert returned geometries into. Optional.
Returns:
{dojo.Deferred} Handle to manage the asynchronous method call