Map service QueryFeatureIDs2 method
Queries and returns the IDs of the features that meet the query filter selection criteria for the specified layer description.
QueryFeatureIDs2(string MapName, LayerDescription LayerDescription, QueryFilter)
Parameter |
Description |
---|---|
MapName |
The name of the map (data frame) that contains the layer associated with the LayerDescription parameter. |
LayerDescription |
The description of the layer to query. |
QueryFilter |
An attribute or spatial query that defines the selection criteria for the layer associated with the LayerDescription parameter. |
Return Value
An FIDSet that contains an array of integers. Each integer represents a unique identifier for each feature (FID) in the layer queried. The map service assigns FIDs to each feature in every feature layer it contains. A SOAP exception will be thrown if the SQL expression in the query filter is invalid.
Remarks
Definitions applied to the LayerDescription input parameter using its DefinitionExpression property will filter the returned feature count.
Examples
C#
MapService_MapServer mapservice = new MapService_MapServer();
mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";
string mapname = mapservice.GetDefaultMapName();
MapServerInfo mapinfo = mapservice.GetServerInfo(mapname);
MapDescription mapdesc = mapinfo.DefaultMapDescription;
MapLayerInfo[] maplayerinfos = mapinfo.MapLayerInfos;
string geometryfieldname = string.Empty;
foreach (MapLayerInfo layerinfo in maplayerinfos)
{
if (layerinfo.Name == "countries")
{
layerid = layerinfo.LayerID;
Field[] fields = layerinfo.Fields.FieldArray;
foreach (Field field in fields)
{
if (field.Type == esriFieldType.esriFieldTypeGeometry)
{
geometryfieldname = field.Name;
break;
}
}
}
}
LayerDescription[] layerdescriptions = mapdesc.LayerDescriptions;
LayerDescription activelayerdesc = null;
foreach (LayerDescription layerdesc in layerdescriptions)
{
if (layerdesc.LayerID == layerid)
{
activelayerdesc = layerdesc;
break;
}
}
activelayerdesc.DefinitionExpression = "POP_CNTRY > 50000000";
PointN pnt1 = new PointN();
pnt1.X = -120;
pnt1.Y = 35;
PointN pnt2 = new PointN();
pnt2.X = -60;
pnt2.Y = 20;
PointN pnt3 = new PointN();
pnt3.X = 80;
pnt3.Y = 35;
PointN[] pnts = new PointN[3];
pnts[0] = pnt1;
pnts[1] = pnt2;
pnts[2] = pnt3;
Ring[] rings = new Ring[1];
Ring ring = new Ring();
ring.PointArray = pnts;
rings[0] = ring;
PolygonN polygon = new PolygonN();
polygon.RingArray = rings;
SpatialFilter spatialfilter = new SpatialFilter();
spatialfilter.FilterGeometry = polygon;
spatialfilter.GeometryFieldName = geometryfieldname;
spatialfilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
FIDSet fidset = null;
try
{
fidset = mapservice.QueryFeatureIDs2(mapname, activelayerdesc, spatialfilter);
}
catch (Exception ex)
{
// Improper format of where clause will cause exception
}
activelayerdesc.SelectionFeatures = fidset.FIDArray;
VB.NET
Dim mapservice As MapService_MapServer = New MapService_MapServer()
mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer"
Dim mapname As String = mapservice.GetDefaultMapName()
Dim mapinfo As MapServerInfo = mapservice.GetServerInfo(mapname)
Dim mapdesc As MapDescription = mapinfo.DefaultMapDescription
Dim maplayerinfos() As MapLayerInfo = mapinfo.MapLayerInfos
Dim layerid As Integer = 0
Dim geomeTryfieldname As String = String.Empty
Dim layerinfo As MapLayerInfo
For Each layerinfo In maplayerinfos
If layerinfo.Name = "countries" Then
layerid = layerinfo.LayerID
Dim fields() As Field = layerinfo.Fields.FieldArray
Dim field As Field
For Each field In fields
If field.Type = esriFieldType.esriFieldTypeGeometry Then
geomeTryfieldname = field.Name
Exit For
End If
Next
End If
Next
Dim layerdescriptions() As LayerDescription = mapdesc.LayerDescriptions
Dim activelayerdesc As LayerDescription = Nothing
Dim layerdesc As LayerDescription
For Each layerdesc In layerdescriptions
If layerdesc.LayerID = layerid Then
activelayerdesc = layerdesc
Exit For
End If
Next
activelayerdesc.DefinitionExpression = "POP_CNTRY > 50000000"
Dim pnt1 As PointN = New PointN()
pnt1.X = -120
pnt1.Y = 35
Dim pnt2 As PointN = New PointN()
pnt2.X = -60
pnt2.Y = 20
Dim pnt3 As PointN = New PointN()
pnt3.X = 80
pnt3.Y = 35
Dim pnts(2) As PointN
pnts(0) = pnt1
pnts(1) = pnt2
pnts(2) = pnt3
Dim rings(0) As Ring
Dim ring As Ring = New Ring()
ring.PointArray = pnts
rings(0) = ring
Dim polygon As PolygonN = New PolygonN()
polygon.RingArray = rings
Dim spatialfilter As SpatialFilter = New SpatialFilter()
spatialfilter.FilterGeometry = polygon
spatialfilter.GeometryFieldName = geomeTryfieldname
spatialfilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains
Dim fidset As FIDSet = Nothing
Try
fidset = mapservice.QueryFeatureIDs2(mapname, activelayerdesc, spatialfilter)
Catch ex As Exception
' Improper format of where clause will cause exception
End Try
activelayerdesc.SelectionFeatures = fidset.FIDArray