/// <summary> /// Performs a query on the specified layer. /// </summary> /// <param name="layerId">The id of the layer to query.</param> /// <param name="query">A where clause for the query filter. Any legal SQL where clause operating on the fields in the layer is allowed.</param> /// <param name="outSR">The spatial reference of the returned geometry.</param> /// <param name="relationship">The spatial relationship to be applied on the input geometry while performing the query.</param> /// <param name="geometry">The geometry to apply as the spatial filter.</param> /// <param name="returnGeometry">If true, the resultset includes the geometry associated with each result.</param> /// <param name="objectIds">The object IDs of this layer / table to be queried.</param> /// <param name="outFields">The list of fields to be included in the returned resultset.</param> /// <param name="returnIdsOnly">If true, the response only includes an array of object IDs. Otherwise the response is a feature set.</param> /// <param name="returnCountOnly">If true, the response only includes the count (number of features / records) that would be returned by a query. Otherwise the response is a feature set.</param> /// <returns></returns> public FeatureSetQuery Query( int layerId, string query, WKID outSR, esriSpatialRelationship relationship, Geometry geometry = null, bool returnGeometry = true, int[] objectIds = null, string outFields = "", bool returnIdsOnly = false, bool returnCountOnly = false) { LayerTableInfo layer = this.LayerInfos.Single(x => x.ID == layerId); if (layer == null) { Throw.ArgumentOutOfRange("layerId"); } IDictionary <string, object> inputs = new Dictionary <string, object>() { { "returnGeometry", returnGeometry.ToString() }, { "returnIdsOnly", returnIdsOnly }, { "returnCountOnly", returnCountOnly }, { "outFields", outFields }, { "where", query }, { "objectIds", objectIds }, }; if (outSR != WKID.NotSpecified) { inputs.Add("outSR", outSR); } if (geometry != null) { try { ValidateGeometry(geometry); } catch (ArgumentNullException ex) { Throw.InvalidOperation("", x => new InvalidOperationException("Geometry object is invalid.", ex)); } inputs.Add("geometry", geometry); inputs.Add("geometryType", geometry.GeometryType); inputs.Add("spatialRel", relationship); inputs.Add("inSR", geometry.SpatialReference.WKID); } Uri endpoint = GetUrl(string.Format("{0}/query", layer.ID), inputs); return(Geocrest.Model.RestHelper.HydrateObject <FeatureSetQuery>(endpoint.ToString())); }
/// <summary> /// Executes a query on the specified layer and returns a featureset result. /// </summary> /// <param name="layerId">The ID of the layer to query.</param> /// <param name="where">The where clause used to query. Any legal SQL where clause operating on the fields in the layer is allowed.</param> /// <param name="geometry">The geometry to apply as the spatial filter.</param> /// <param name="spatialRel">The spatial relationship to be applied on the input geometry while performing the query.</param> /// <param name="outSR">The spatial reference of the returned geometry.</param> /// <param name="outFields">The list of fields to be included in the returned result set.</param> /// <param name="objectIds">The object IDs of this layer/table to be queried.</param> /// <param name="orderByFields">The fields by which to order the results.</param> /// <param name="returnGeometry">If set to <c>true</c> the result includes the geometry associated with each feature returned.</param> /// <param name="returnDistinctValues">If set to <c>true</c> it returns distinct values based on the fields specified in outFields.</param> /// <returns></returns> public FeatureSet Query(int layerId, string where, Geometry geometry = null, esriSpatialRelationship spatialRel = esriSpatialRelationship.esriSpatialRelIntersects, SpatialReference outSR = null, string outFields = "*", int[] objectIds = null, string orderByFields = "", bool returnGeometry = true, bool returnDistinctValues = false) { LayerTableBase layer = this.LayerInfos.Single(x => x.ID == layerId); if (layer == null) { Throw.ArgumentOutOfRange("layerId"); } IDictionary <string, object> inputs = new Dictionary <string, object>() { { "where", where }, { "objectIds", objectIds != null?string.Join(",", objectIds) : null }, { "returnGeometry", returnGeometry }, { "outFields", outFields }, { "orderByFields", orderByFields }, { "returnDistinctValues", returnDistinctValues } }; if (outSR != null && outSR.WKID != WKID.NotSpecified) { inputs.Add("outSR", outSR); } if (geometry != null) { try { ValidateGeometry(geometry); } catch (ArgumentNullException ex) { Throw.InvalidOperation("", x => new InvalidOperationException("Geometry object is invalid.", ex)); } inputs.Add("geometry", geometry); inputs.Add("geometryType", geometry.GeometryType); inputs.Add("spatialRel", spatialRel); inputs.Add("inSR", geometry.SpatialReference); } Uri endpoint = GetUrl("query", inputs, layer); return(Geocrest.Model.RestHelper.HydrateObject <FeatureSet>(endpoint.ToString())); }
/// <summary> /// Executes a query on the specified layer and returns the count of features that match. /// </summary> /// <param name="layerId">The ID of the layer to query.</param> /// <param name="where">The where clause used to query. Any legal SQL where clause operating on the fields in the layer is allowed.</param> /// <param name="geometry">The geometry to apply as the spatial filter.</param> /// <param name="spatialRel">The spatial relationship to be applied on the input geometry while performing the query.</param> /// <param name="outSR">The spatial reference of the returned geometry.</param> /// <returns> /// The count of features that match the query. /// </returns> public int QueryForCount( int layerId, string where, Geometry geometry = null, esriSpatialRelationship spatialRel = esriSpatialRelationship.esriSpatialRelIntersects, SpatialReference outSR = null) { LayerTableBase layer = this.LayerInfos.Single(x => x.ID == layerId); if (layer == null) { Throw.ArgumentOutOfRange("layerId"); } IDictionary <string, object> inputs = new Dictionary <string, object>() { { "where", where }, { "returnGeometry", false }, { "returnCountOnly", true } }; if (outSR != null && outSR.WKID != WKID.NotSpecified) { inputs.Add("outSR", outSR); } if (geometry != null) { try { ValidateGeometry(geometry); } catch (ArgumentNullException ex) { Throw.InvalidOperation("", x => new InvalidOperationException("Geometry object is invalid.", ex)); } inputs.Add("geometry", geometry); inputs.Add("geometryType", geometry.GeometryType); inputs.Add("spatialRel", spatialRel); inputs.Add("inSR", geometry.SpatialReference); } Uri endpoint = GetUrl("query", inputs, layer); var response = Geocrest.Model.RestHelper.HydrateObject <FeatureSetQuery>(endpoint.ToString()); return(response.Count); }