/GPX.FireMap.Workflow/GPX.FireMap.Workflow/AGSServerSupport.cs
C# | 153 lines | 117 code | 30 blank | 6 comment | 4 complexity | f8c5c149a84a8b7cffc4491e408a0cae MD5 | raw file
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- using System.Net;
- using Newtonsoft.Json.Linq;
- using ESRI.ArcGIS.Client.Geometry;
- using Geocortex.Logging;
-
- namespace GPX.Firemap.Workflow.Activities.Server
- {
- static class AGSServerSupport
- {
-
-
- /// <summary>
- /// Calls the Arc GIS server.
- /// </summary>
- /// <param name="URI">The URI.</param>
- /// <param name="response">The response.</param>
- static public void CallArcGISServer(string URI, out JObject response)
- {
- Stream data = null;
- StreamReader reader = null;
-
- try
- {
- //log the request string
- Logger.SystemInfo("Sending request to AGS: " + URI);
-
- WebClient client = new WebClient();
- data = client.OpenRead(URI);
- reader = new StreamReader(data);
-
- string s = reader.ReadToEnd();
-
- response = JObject.Parse(s);
-
- }
- catch (Exception ex)
- {
- Logger.SystemError("An error occured when calling ArcGIS Server" + ex.ToString());
- throw;
- }
- finally
- {
- if (data != null)
- data.Close();
-
- if (reader != null)
- reader.Close();
- }
-
- }
-
-
- public static string CreateMGRSConvertRequest(string serviceUrl, string mgrsReference, string wkid)
- {
- StringBuilder sb = new StringBuilder();
- sb.Append(serviceUrl);
- sb.Append("?reference=");
- sb.Append(mgrsReference);
- sb.Append("&wkid=");
- sb.Append(wkid);
- sb.Append("&f=pjson");
-
- return sb.ToString();
-
-
- }
-
- public static string CreateNearestFeatureIdRequest(MapPoint location, string layerId, string nearestFeatureUrl)
- {
-
- string finalUrl = string.Format(nearestFeatureUrl + "{0}/GetNearestFeature", layerId);
-
- StringBuilder sb = new StringBuilder();
- sb.Append(finalUrl);
- sb.Append("?location=");
- sb.Append(ConvertMapPointToJsom(location));
- sb.Append("&wkid=");
- sb.Append(location.SpatialReference.WKID.ToString());
- sb.Append("&f=pjson");
-
- return sb.ToString();
-
- }
-
- public static string CreateProjectGeometryRequest(MapPoint location, string inWkid, string outWkid, string geometryServiceUrl)
- {
- StringBuilder sb = new StringBuilder();
- sb.Append(geometryServiceUrl);
- sb.Append("/project");
- sb.Append("?inSR=" + inWkid.ToString());
- sb.Append("&outSR=" + outWkid.ToString());
- sb.Append("&geometries=");
- sb.Append("{");
- sb.Append("\"geometryType\" : \"esriGeometryPoint\",");
- sb.Append("\"geometries\" : ");
- sb.Append("[");
- sb.Append(ConvertMapPointToJsom(location));
- sb.Append("]");
- sb.Append("}");
- sb.Append("&f=json");
-
- return sb.ToString();
- }
-
- public static string CreateQueryRequest(MapPoint location, string rootUrl, IntersectFeatureDefinition ifd, string lyrId)
- {
-
- StringBuilder sb = new StringBuilder();
- sb.Append(rootUrl);
- sb.Append(lyrId);
- sb.Append("/query");
- sb.Append("?text=&geometry=");
- sb.Append(ConvertMapPointToJsom(location));
- sb.Append("&geometryType=esriGeometryPoint");
- sb.Append("&inSR=");
- sb.Append("&spatialRel=esriSpatialRelIntersects");
- sb.Append("&relationParam=");
- sb.Append("&objectIds=");
- sb.Append("&where=");
- sb.Append("&time=");
- sb.Append("&returnCountOnly=false");
- sb.Append("&returnIdsOnly=false");
- sb.Append("&returnGeometry=false");
- sb.Append("&maxAllowableOffset=");
- sb.Append("&outSR=");
- sb.Append("&outFields=");
- sb.Append(ifd.Fields);
- sb.Append("&f=json");
- return sb.ToString();
- }
-
- private static string ConvertMapPointToJsom(MapPoint pnt)
- {
-
- StringBuilder sb = new StringBuilder();
- sb.Append("{");
- sb.Append("x:" + pnt.X);
- sb.Append(",");
- sb.Append("y:" + pnt.Y);
- sb.Append("}");
-
- return sb.ToString();
- }
-
-
-
- }
- }