PageRenderTime 81ms CodeModel.GetById 31ms RepoModel.GetById 2ms app.codeStats 0ms

/GPX.FireMap.Workflow/GPX.FireMap.Workflow/AGSServerSupport.cs

https://bitbucket.org/shope/dfu
C# | 153 lines | 117 code | 30 blank | 6 comment | 4 complexity | f8c5c149a84a8b7cffc4491e408a0cae MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. using System.Net;
  7. using Newtonsoft.Json.Linq;
  8. using ESRI.ArcGIS.Client.Geometry;
  9. using Geocortex.Logging;
  10. namespace GPX.Firemap.Workflow.Activities.Server
  11. {
  12. static class AGSServerSupport
  13. {
  14. /// <summary>
  15. /// Calls the Arc GIS server.
  16. /// </summary>
  17. /// <param name="URI">The URI.</param>
  18. /// <param name="response">The response.</param>
  19. static public void CallArcGISServer(string URI, out JObject response)
  20. {
  21. Stream data = null;
  22. StreamReader reader = null;
  23. try
  24. {
  25. //log the request string
  26. Logger.SystemInfo("Sending request to AGS: " + URI);
  27. WebClient client = new WebClient();
  28. data = client.OpenRead(URI);
  29. reader = new StreamReader(data);
  30. string s = reader.ReadToEnd();
  31. response = JObject.Parse(s);
  32. }
  33. catch (Exception ex)
  34. {
  35. Logger.SystemError("An error occured when calling ArcGIS Server" + ex.ToString());
  36. throw;
  37. }
  38. finally
  39. {
  40. if (data != null)
  41. data.Close();
  42. if (reader != null)
  43. reader.Close();
  44. }
  45. }
  46. public static string CreateMGRSConvertRequest(string serviceUrl, string mgrsReference, string wkid)
  47. {
  48. StringBuilder sb = new StringBuilder();
  49. sb.Append(serviceUrl);
  50. sb.Append("?reference=");
  51. sb.Append(mgrsReference);
  52. sb.Append("&wkid=");
  53. sb.Append(wkid);
  54. sb.Append("&f=pjson");
  55. return sb.ToString();
  56. }
  57. public static string CreateNearestFeatureIdRequest(MapPoint location, string layerId, string nearestFeatureUrl)
  58. {
  59. string finalUrl = string.Format(nearestFeatureUrl + "{0}/GetNearestFeature", layerId);
  60. StringBuilder sb = new StringBuilder();
  61. sb.Append(finalUrl);
  62. sb.Append("?location=");
  63. sb.Append(ConvertMapPointToJsom(location));
  64. sb.Append("&wkid=");
  65. sb.Append(location.SpatialReference.WKID.ToString());
  66. sb.Append("&f=pjson");
  67. return sb.ToString();
  68. }
  69. public static string CreateProjectGeometryRequest(MapPoint location, string inWkid, string outWkid, string geometryServiceUrl)
  70. {
  71. StringBuilder sb = new StringBuilder();
  72. sb.Append(geometryServiceUrl);
  73. sb.Append("/project");
  74. sb.Append("?inSR=" + inWkid.ToString());
  75. sb.Append("&outSR=" + outWkid.ToString());
  76. sb.Append("&geometries=");
  77. sb.Append("{");
  78. sb.Append("\"geometryType\" : \"esriGeometryPoint\",");
  79. sb.Append("\"geometries\" : ");
  80. sb.Append("[");
  81. sb.Append(ConvertMapPointToJsom(location));
  82. sb.Append("]");
  83. sb.Append("}");
  84. sb.Append("&f=json");
  85. return sb.ToString();
  86. }
  87. public static string CreateQueryRequest(MapPoint location, string rootUrl, IntersectFeatureDefinition ifd, string lyrId)
  88. {
  89. StringBuilder sb = new StringBuilder();
  90. sb.Append(rootUrl);
  91. sb.Append(lyrId);
  92. sb.Append("/query");
  93. sb.Append("?text=&geometry=");
  94. sb.Append(ConvertMapPointToJsom(location));
  95. sb.Append("&geometryType=esriGeometryPoint");
  96. sb.Append("&inSR=");
  97. sb.Append("&spatialRel=esriSpatialRelIntersects");
  98. sb.Append("&relationParam=");
  99. sb.Append("&objectIds=");
  100. sb.Append("&where=");
  101. sb.Append("&time=");
  102. sb.Append("&returnCountOnly=false");
  103. sb.Append("&returnIdsOnly=false");
  104. sb.Append("&returnGeometry=false");
  105. sb.Append("&maxAllowableOffset=");
  106. sb.Append("&outSR=");
  107. sb.Append("&outFields=");
  108. sb.Append(ifd.Fields);
  109. sb.Append("&f=json");
  110. return sb.ToString();
  111. }
  112. private static string ConvertMapPointToJsom(MapPoint pnt)
  113. {
  114. StringBuilder sb = new StringBuilder();
  115. sb.Append("{");
  116. sb.Append("x:" + pnt.X);
  117. sb.Append(",");
  118. sb.Append("y:" + pnt.Y);
  119. sb.Append("}");
  120. return sb.ToString();
  121. }
  122. }
  123. }