Search a Table for Features Nearest to a Geometry


Searches a named table within the repository for features that are nearest to a specified geometry, within a certain distance. You have the options of returning all of the attribute data, specific attribute data, and ordering the returned data by an attribute. Here are some basic rules for the searchNearest method:

This operation returns a feature collection JSON that can be passed to a render map or render legend request in the Mapping service.


The following format is used for HTTP GET requests:

HTTP GET /tables/tablename/features.rep;[attributes=attname];[orderBy=attname dir]
&q=searchNearest&geometry=geom,srs&[withinDistance=distance unit]


For information on the parameter types listed below, see Request URL Data Types.

Parameter Type Required Description
tablename String yes The name of the table to return metadata. The table is specified by a Regex for the named table to render based on the location of the named table in the Repository. The name of the named table is defined between the /tables portion of the URL and the /metadata.rep portion of the URL. For example, to return the metadata for a named table located at /Samples/NamedTables/WorldTable in the Repository, the following URL would be used:
rep String yes The representation to be returned. Supported representation is json.
attributes=attname String no The attribute names of the table to be returned in the response. By default all attributes are returned. More than one attribute is defined by a comma separated list. This is a simple way of limiting the amount of information in the response to include only the information requested. Each feature in the resulting feature collection will only contain the specified attributes. For example, if the table contains four attributes, but only two are required in the response, those two attribute names can be specified here (separated by a comma) and the values for the other two will not be returned.
orderBy=attname dir String no The attribute name and direction to order the returned results. By default the results are ordered from closest to farthest based on the distance from the specified point. When specifying an attribute to order the results, you must include both the attribute name and the ordering direction (A for ascending(low to high) or D for descending(high to low)).
q=searchNearest String yes The query method to perform. This must be searchNearest.
geometry=geom,srs String yes The geometry used as the starting location for the search. The geometry must include the geometry type, coordinates and the spatial reference system for the geometry. For example:
Note: If no CRS property is specified, then EPSG:4326 is considered the default CRS.


String no The distance to search around the geometry. When specified, the distance must include the distance value and distance unit. The distance values returned in the response will be in the units specified in the request (default is meters).


String no The name of the distance attribute to be returned in the response. This attribute is used to return the distance value from the geometry to the found nearest features. If the distanceAttributeName parameter is not specified, the distance value to each feature will not be returned in the response.


String no The geometry definition attribute from the table that should be used for processing the spatial query. This attribute is only required for tables that contain more than one geometry attribute definition.
l=locale String no The locale in which to return the table information. Uses the Java Locale format consisting of an ISO two letter language code and an ISO two letter country code. If not specified then assumes server default.
destinationSrs String no The coordinate system to return the resulting geometries. The default is the coordinate system of the data used (for example: epsg:4326).
page=pagenumber String no The page number to return.
pageLength=pagelength String no The number of features returned on each page. If the page parameter is specified in the request, you must define pageLength.


String no The total number of features returned in the response. If the maxFeatures parameter is not specified in the request, the maxCandidates parameter in the Feature Service configuration is used. By default this value is 1000 features.


Returns metadata for a named table in the repository.


Returns the nearest world capitals that are within 5000 miles from the specified point geometry.


Returns the closest three state capitals in the USA that are within 5000 miles from the specified geometry.


Returns the closest three state capitals in the USA that are within 1000 miles from the specified point geometry. The distance to each feature will be returned in the withinDistanceFromGeometry attribute in the response and the calculation will be based on the geometries in the GEOLOC column in the USA_CAPS named table.