public async Task <PolygonGeometry> ProjectPolygon(string token, string inSR, string outSR, PolygonGeometry geometry) { var queryUrl = $"{getRestServiceEndpoint()}/project"; var payLoadModel = new ArcGISProjectPolygonGeometryParam(new PolygonGeometry[] { geometry }); var encodedContent = new ArcGISEncodedContent { { "f", responseFormat }, { "token", token }, { "inSR", inSR }, { "outSR", outSR }, { "geometries", JsonConvert.SerializeObject(payLoadModel).TrimJsonRequest() } }; var resp = await ArcGISHttpClient.PostAsync(queryUrl, encodedContent.ToStringUrlEncodedContent()); var respStr = await resp.Content.ReadAsStringAsync(); if (resp.StatusCode != HttpStatusCode.OK) { throw new ArcGISInvalidResponseException($"Unsuccessfull. \n" + $"Response Code: {resp.StatusCode}\n" + $"Response: {respStr}" + $"Query String: {queryUrl}"); } var model = JsonConvert.DeserializeObject <ArcGISProjectPolygonResponse>(respStr); return(model.geometries.FirstOrDefault()); }
public async Task <ArcGISAuthToken> GetToken() { try { string reqUrl = getAuthRequestUrl(); HttpResponseMessage resp = await ArcGISHttpClient.PostAsync(reqUrl, null); string str = await resp.Content.ReadAsStringAsync(); if (resp.StatusCode != System.Net.HttpStatusCode.OK) { throw new ArcGISAuthException($"Unsuccessfull " + $"Username: {username}, StatusCode: {resp.StatusCode}, " + $"Response Returned: {str}"); } var model = JsonConvert.DeserializeObject <ArcGISAuthToken>(str); return(model); } catch (System.Exception ex) { throw new ArcGISAuthException($"{ex.Message}", ex); } }
public async Task <ArcGISAreaLengthResponse> CalculateAreasAndLengths(string token, string sr, EsriGeometryCalcType calculationType, EsriAreaUnit areaUnit, PolygonGeometry geometry, string lengthUnit = "") { string queryUrl = $"{getRestServiceEndpoint()}/areasAndLengths"; var areaUnitParam = new ArcGISCalculateAreasAndLengthAreaParam(areaUnit); PolygonGeometry[] polygonPayload = { geometry }; var encodedContent = new ArcGISEncodedContent { { "f", responseFormat }, { "token", token }, { "sr", sr }, { "lengthUnit", lengthUnit }, { "calculationType", calculationType.ToString() }, { "areaUnit", JsonConvert.SerializeObject(areaUnitParam).TrimJsonRequest() }, { "polygons", JsonConvert.SerializeObject(polygonPayload).TrimJsonRequest() } }; var resp = await ArcGISHttpClient.PostAsync(queryUrl, encodedContent.ToStringUrlEncodedContent()); var respStr = await resp.Content.ReadAsStringAsync(); if (resp.StatusCode != HttpStatusCode.OK) { throw new ArcGISInvalidResponseException($"Unsuccessfull. \n" + $"Response Code: {resp.StatusCode}\n" + $"Response: {respStr}" + $"Query String: {queryUrl}"); } var model = JsonConvert.DeserializeObject <ArcGISCalculateAreasAndLengthsResponse>(respStr); if (model.areas.Count > 1 || model.lengths.Count > 1) { throw new ArcGISUnexpectedResponseException("Returned response count greater than 1 or equal to 0"); } return(new ArcGISAreaLengthResponse(model.areas.FirstOrDefault(), model.lengths.FirstOrDefault())); }
public async Task <ArcGISFeaturesLayerQueryResponse> QueryFeatureLayer(string token, int layerId, string[] outFields, string whereClause = "1=1") { var queryUrl = $"{this.getRestServiceEndpoint()}/{layerId}/query" + $"?token={token}" + $"&f={responseFormat}" + $"&outFields={string.Join(",", outFields)}" + $"&where={whereClause}"; var resp = await ArcGISHttpClient.PostAsync(queryUrl, null); var respStr = await resp.Content.ReadAsStringAsync(); if (resp.StatusCode != System.Net.HttpStatusCode.OK) { throw new ArcGISInvalidResponseException($"Unsuccessfull. \n" + $"Response Code: {resp.StatusCode}\n" + $"Response: {respStr}" + $"Query String: {queryUrl}"); } var model = JsonConvert.DeserializeObject <ArcGISFeaturesLayerQueryResponse>(respStr); return(model); }