The
QueryService can be used to perform queries and a number of other Map Related functions for an ArcGIS MapService.
ExportMap
The ExportMap function is used to get an image for a MapService given a set of parameters.
ExportMapOptions
Name | Type | Description |
---|
BoundingBox | MapExtent | The extent (bounding box) of the exported image. Unless the bboxSR parameter has been specified, the bbox is assumed to be in the spatial reference of the map. |
BoundingBoxSpatialReference | SpatialReference | The well-known ID of the spatial reference of the bbox. If the bboxSR is not specified, the bbox is assumed to be in the spatial reference of the map. |
Dpi | int | The device resolution of the exported image (dots per inch). If the dpi is not specified, an image with a default DPI of 96 will be exported. |
ImageFormat | ImageFormats? | The format of the exported image. The default format is png. |
ImageSpatialReference | SpatialReference | The well-known ID of the spatial reference of the exported image. If the imageSR is not specified, the image will be exported in the spatial reference of the map. |
LayerDefinitionExpressions | IEnumerable | Allows you to filter the features of individual layers in the exported map by specifying definition expressions for those layers. |
LayerIds | IEnumerable | Determines which layers appear on the exported map |
Size | Size | The size (width * height) of the exported image in pixels. If the size is not specified, an image with a default size of 400 * 400 will be exported. |
TransparentMap | bool | If true, the image will be exported with the background color of the map set as its transparent color. |
ExportMapResult
Name | Type | Description |
---|
Extent | Geometry | The extent of the map that will be exported. |
Height | int | The height in pixels of the map that will be exported. |
Href | string | The url of image that is being exported. |
Scale | double | The scale of the map being exported. |
Width | int | The width in pixels of the map that will be exported. |
Example
var exportOptions = new ExportMapOptions
{
BoundingBox = options.ViewExtent,
LayerIds = options.MapServiceLayers[i].VisibleLayerIds,
TransparentMap = true,
BoundingBoxSpatialReference =options.BoundingBoxSpatialReference,
ImageFormat = ImageFormats.PNG24,
Size =(options.ShowLegend)? new Size {Height = 1300, Width = 1500}
: new Size {Height = 995, Width = 1600}
};
var svs = new SpatialQueryService(options.MapServiceLayers[i].Url);
ExportMapResult result = svs.ExportMap(exportOptions,"URL FOR MAPSERVICE");
Find
The find operation performs a textual query across multiple layers in a MapService.
FindOperationOptions
Name | Type | Description |
---|
ExactMatchOnly | bool | If this false then query will use a contains. |
Layers | IEnumerable | This is the list of layers that will be queried against. |
ReturnGeometry | bool | Sets if the operation will return the geometry. |
SearchFields | IEnumerable | The fields to search on. |
SearchText | string | The text to search on. |
SpatialReference | SpatialReference | The spatial reference of the output geometry. |
Example
var options = new FindOperationOptions
{
ExactMatchOnly = parameters.ExactMatch,
Layers = _mapService.Layers.Where(l => layerIds.Contains(l.Id.ToString() ) ).Select(l => l.Layer).ToList(),
ReturnGeometry = true,
SearchFields = parameters.Attributes.Select(a => a.Name).ToList(),
SearchText = parameters.SearchValue,
SpatialReference = MapHandler.MapSpatialReference
};
var client = new QueryServiceClient();
var results = client.Find(options,"URL FOR MAPSERVICE");
GetAvailableLayers
Gets a list of all of the layers for a given MapService.
Example
QueryServiceClient querySvs = new QueryServiceClient();
var results= querySvs.GetAvailableLayers(Url);
Identify
The identify function allows the query of a point across layers in a MapService.
IdentifyOptions
Name | Type | Description |
---|
Geometry | Geometry | The geometry to identify on. The type of the geometry is specified by the geometryType parameter. |
GeometryType | GeometryTypes | The type of geometry specified by the geometry parameter. The geometry type could be a point, a line, a polygon or an envelope. The default geometry type is a point (esriGeometryPoint). |
ImageDisplay | ImageDisplay | The screen image display parameters (width, height and DPI) of the map being currently viewed. |
LayerOptions | LayerOptions | The layers to perform the identify operation on |
MapExtent | MapExtent | The extent or bounding box of the map currently being viewed. Unless the sr parameter has been specified, the mapExtent is assumed to be in the spatial reference of the map. |
ReturnGeometry | bool | If true, the resultset will include the geometries associated with each result |
SpatialReference | SpatialReference | The well-known ID of the spatial reference of the input and output geometries as well as the mapExtent. If sr is not specified, the geometry and the mapExtent are assumed to be in the spatial reference of the map, and the output geometries are also in the spatial reference of the map. |
Tolerance | int | The distance in screen pixels from the specified geometry within which the identify should be performed. |
Example
var options = new IdentifyOptions
{
Geometry = geometry,
GeometryType = GeometryTypes.Point,
ImageDisplay = new ImageDisplay
{
Dpi = (int)MapHandler.CurrentMap.Resolution,
Height = (int)MapHandler.CurrentMap.ActualHeight,
Width = (int)MapHandler.CurrentMap.ActualWidth
},
Tolerance = 5,
ReturnGeometry = true,
LayerOptions = new LayersOptions
{
IdentifyLayerLevel = IdentifyLayerLevels.All,
LayerIds = layerIds
},
MapExtent = GeometryTranslator.TranslateEnvelope(MapHandler.GetExtent()),
SpatialReference = new SpatialReference { WellKnownId = MapHandler.CurrentMap.SpatialReference.WKID.ToString() }
};
var client = new QueryServiceClient();
var results=client.Identify(options,"URL FOR MAPSERVICE");
Query
The query function allows ad-hoc queries against single layers in a MapService.
SpatialQueryOptions
Name | Type | Description |
---|
Criteria | Criteria | The textual criteria that is used for the query |
Geometry | Geometry | The geometry to apply as the spatial filter. |
InputSpatialReference | SpatialReference | The well-known ID of the spatial reference of the input geometry. |
Layer | Layer | The layer that is being queried against. |
OutputSpatialReference | SpatialReference | The well-known ID of the spatial reference for the returned geometry. If outSR is not specified, the geometry is returned in the spatial reference of the map. |
ReturnAllFields | bool | Sets if all the fields for the features will returned from the query. |
ReturnFields | IEnumerable | The list of fields to be included in the returned resultset. |
ReturnGeometry | bool | If true, the resultset includes the geometry associated with each result. The default is true |
SecondaryCriteria | IEnumerable | Additional textual criteria for the query. |
SpatialRelationship | QuerySpatialRelationships? | The spatial relationship to be applied on the input geometry while performing the query. |
TextCriteriaFieldNames | IEnumerable |
Example
var criteria = new Criteria
{
ComparisonType = ComparisonType.Equals,
Value = ids.First(),
Field = idField
};
var secondaryCriteria = ids.Skip(1).Select(sc => new SecondaryCriteria
{
ComparisonType = ComparisonType.Equals,
Value = sc,
Field = idField,
LogicalOperator = LogicalOperator.Or
}).ToList();
var sqo = new SpatialQueryOptions
{
Criteria = criteria,
InputSpatialReference = MapHandler.MapSpatialReference,
OutputSpatialReference = MapHandler.MapSpatialReference,
Layer = layer,
ReturnAllFields = true,
ReturnGeometry = true,
SecondaryCriteria = secondaryCriteria
};
var client = new QueryServiceClient();
var result= client.Query(sqo,"URL FOR MAPSERVICE");
QueryObjectIds
The QueryObjectIds method returns all of the objectids for a given spatial query. The method takes a
SpatialQueryOptions object as a parameter.
Example
var criteria = new Criteria
{
ComparisonType = ComparisonType.Equals,
Value = ids.First(),
Field = idField
};
var secondaryCriteria = ids.Skip(1).Select(sc => new SecondaryCriteria
{
ComparisonType = ComparisonType.Equals,
Value = sc,
Field = idField,
LogicalOperator = LogicalOperator.Or
}).ToList();
var sqo = new SpatialQueryOptions
{
Criteria = criteria,
InputSpatialReference = MapHandler.MapSpatialReference,
OutputSpatialReference = MapHandler.MapSpatialReference,
Layer = layer,
ReturnAllFields = true,
ReturnGeometry = true,
SecondaryCriteria = secondaryCriteria
};
var client = new QueryServiceClient();
var result= client.QueryObjectIds(sqo,"URL FOR MAPSERVICE");
See Also