PageRenderTime 59ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/GPX.Firemap.Server/FireMapExtension/FireMapExtension.cs

https://bitbucket.org/shope/dfu
C# | 779 lines | 459 code | 173 blank | 147 comment | 36 complexity | c80f269d109e1ebbec9bcdf3e1f28239 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Collections.Specialized;
  6. using System.Runtime.InteropServices;
  7. using System.EnterpriseServices;
  8. using ESRI.ArcGIS.esriSystem;
  9. using ESRI.ArcGIS.Server;
  10. using ESRI.ArcGIS.Geometry;
  11. using ESRI.ArcGIS.Geodatabase;
  12. using ESRI.ArcGIS.Carto;
  13. using ESRI.ArcGIS.SOESupport;
  14. using System.IO;
  15. namespace GPX.Firemap.Server
  16. {
  17. [ComVisible(true)]
  18. [Guid("b1402a3e-ed21-4ca5-a077-015bc8dcafce")]
  19. [ClassInterface(ClassInterfaceType.None)]
  20. public class FireMapExtension : ServicedComponent, IServerObjectExtension, IObjectConstruct, IRESTRequestHandler
  21. {
  22. private string soe_name;
  23. private IPropertySet configProps;
  24. private IServerObjectHelper serverObjectHelper;
  25. private ServerLogger logger;
  26. private IRESTRequestHandler reqHandler;
  27. private CoordinateConverter coorConv;
  28. //private IGeographicCoordinateSystem baseCoordinateSystem = null;
  29. private const int VICGRID = 3111;
  30. private const int MGA54 = 28354;
  31. private const int MGA55 = 28355;
  32. private const int GCS = 4283;
  33. private const int WMCT = 3857;
  34. private const int WGS84 = 6326;
  35. private const int GDA94 = 6283;
  36. private const int SOE_ERROR_CODE = 99999;
  37. public FireMapExtension()
  38. {
  39. soe_name = this.GetType().Name;
  40. logger = new ServerLogger();
  41. reqHandler = new SoeRestImpl(soe_name, CreateRestSchema()) as IRESTRequestHandler;
  42. }
  43. #region IServerObjectExtension Members
  44. public void Init(IServerObjectHelper pSOH)
  45. {
  46. serverObjectHelper = pSOH;
  47. }
  48. public void Shutdown()
  49. {
  50. }
  51. #endregion
  52. #region IObjectConstruct Members
  53. public void Construct(IPropertySet props)
  54. {
  55. configProps = props;
  56. //intialise the coordinate convertor
  57. coorConv = new CoordinateConverter();
  58. }
  59. #endregion
  60. #region IRESTRequestHandler Members
  61. public string GetSchema()
  62. {
  63. return reqHandler.GetSchema();
  64. }
  65. public byte[] HandleRESTRequest(string Capabilities, string resourceName, string operationName, string operationInput, string outputFormat, string requestProperties, out string responseProperties)
  66. {
  67. return reqHandler.HandleRESTRequest(Capabilities, resourceName, operationName, operationInput, outputFormat, requestProperties, out responseProperties);
  68. }
  69. #endregion
  70. private RestResource CreateRestSchema()
  71. {
  72. //main extension resource
  73. //provides a layer list of all layers in the service on which the extension is attached to.
  74. RestResource rootRes = new RestResource(soe_name, false, RootResHandler);
  75. //provides a single layer view - basically name and layer id
  76. RestResource nearestLayerResource = new RestResource("NearestLayers", true, NearestLayerHandler);
  77. //Operation for converting from MGRS reference to Coordinate
  78. RestOperation convertMGRS = new RestOperation("ConvertMGRS",
  79. new string[] { "reference", "wkid" },
  80. new string[] { "json" },
  81. ConvertMGRSHandler);
  82. //Operation for getting nearest feature from a layer
  83. RestOperation getNearestFeatureOp = new RestOperation("GetNearestFeature",
  84. new string[] { "location", "wkid"},
  85. new string[] { "json" },
  86. GetNearestFeatureHandler);
  87. nearestLayerResource.operations.Add(getNearestFeatureOp);
  88. rootRes.resources.Add(nearestLayerResource);
  89. rootRes.operations.Add(convertMGRS);
  90. return rootRes;
  91. }
  92. #region Resource Handlers
  93. private byte[] RootResHandler(NameValueCollection boundVariables, string outputFormat, string requestProperties, out string responseProperties)
  94. {
  95. responseProperties = null;
  96. NearestLayerInfo[] layerInfos = GetLayerInfos();
  97. JsonObject[] jos = new JsonObject[layerInfos.Length];
  98. for (int i = 0; i < layerInfos.Length; i++)
  99. jos[i] = layerInfos[i].ToJsonObject();
  100. JsonObject result = new JsonObject();
  101. result.AddArray("nearestLayers", jos);
  102. string json = result.ToJson();
  103. return Encoding.UTF8.GetBytes(json);
  104. }
  105. private byte[] NearestLayerHandler(NameValueCollection boundVariables, string outputFormat, string requestProperties, out string responseProperties)
  106. {
  107. responseProperties = null;
  108. //layerID
  109. int layerID = Convert.ToInt32(boundVariables["NearestLayersId"]);
  110. //execute
  111. NearestLayerInfo layerInfo = GetLayerInfo(layerID);
  112. string json = layerInfo.ToJsonObject().ToJson();
  113. return Encoding.UTF8.GetBytes(json);
  114. }
  115. #endregion
  116. #region Operation Handlers
  117. /// <summary>
  118. /// Converts the MGRS handler.
  119. /// </summary>
  120. /// <param name="boundVariables">The bound variables.</param>
  121. /// <param name="operationInput">The operation input.</param>
  122. /// <param name="outputFormat">The output format.</param>
  123. /// <param name="requestProperties">The request properties.</param>
  124. /// <param name="responseProperties">The response properties.</param>
  125. private byte[] ConvertMGRSHandler(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties)
  126. {
  127. try
  128. {
  129. responseProperties = null;
  130. ISpatialReference referenceSystem;
  131. string mgrsReference;
  132. bool found = operationInput.TryGetString("reference", out mgrsReference);
  133. if (!found || string.IsNullOrEmpty(mgrsReference))
  134. {
  135. throw new ArgumentNullException("reference");
  136. }
  137. long? wkid;
  138. found = operationInput.TryGetAsLong("wkid", out wkid);
  139. if (!found)
  140. {
  141. throw new ArgumentNullException("wkid");
  142. }
  143. else
  144. {
  145. //if valid set the spatial reference system based upon the WKID
  146. referenceSystem = GetSpatialReferenceSystem(Convert.ToInt32(wkid));
  147. }
  148. //process the incoming mgrs reference
  149. List<string> references = null;
  150. MGRSHelper.ProcessMGRSReference(mgrsReference, out references, coorConv);
  151. //SH - Added to support DFU-40
  152. //convert the references to points
  153. //List<IPoint> convertedReferences = ConvertMGRSReference(referenceSystem, references);
  154. JsonObject convertedReferences = ConvertMGRSReference(referenceSystem, references);
  155. //SH - Added to support DFU-40
  156. //return Encoding.UTF8.GetBytes(ConvertPointsToJsonResponse(referenceSystem, mgrsReference, convertedReferences).ToJson());
  157. return Encoding.UTF8.GetBytes(convertedReferences.ToJson());
  158. }
  159. catch
  160. {
  161. throw;
  162. }
  163. finally
  164. {
  165. }
  166. }
  167. /// <summary>
  168. /// Gets the nearest feature handler.
  169. /// </summary>
  170. /// <param name="boundVariables">The bound variables.</param>
  171. /// <param name="operationInput">The operation input.</param>
  172. /// <param name="outputFormat">The output format.</param>
  173. /// <param name="requestProperties">The request properties.</param>
  174. /// <param name="responseProperties">The response properties.</param>
  175. /// <returns></returns>
  176. private byte[] GetNearestFeatureHandler(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties)
  177. {
  178. try
  179. {
  180. responseProperties = null;
  181. //layerID
  182. int layerID = Convert.ToInt32(boundVariables["NearestLayersID"]);
  183. //location
  184. JsonObject jsonPoint;
  185. if (!operationInput.TryGetJsonObject("location", out jsonPoint))
  186. throw new ArgumentNullException("location");
  187. //wkid
  188. long? wkid;
  189. if (!operationInput.TryGetAsLong("wkid", out wkid))
  190. throw new ArgumentNullException("wkid");
  191. IPoint location = Conversion.ToGeometry(jsonPoint, esriGeometryType.esriGeometryPoint) as IPoint;
  192. if (location == null)
  193. throw new ArgumentException("GetNearestFeature: invalid location", "location");
  194. return FindNearFeatures(layerID, location, wkid);
  195. }
  196. catch
  197. {
  198. throw;
  199. }
  200. finally
  201. {
  202. }
  203. }
  204. #endregion
  205. /// <summary>
  206. /// Finds the nearest features in a layer to the passed in point.
  207. /// </summary>
  208. /// <param name="layerID">The layer ID.</param>
  209. /// <param name="location">The location.</param>
  210. /// <param name="wkid">The wkid.</param>
  211. private byte[] FindNearFeatures(int layerID, IPoint location, long? wkid)
  212. {
  213. IMapServer3 mapServer;
  214. IMapServerDataAccess dataAccess;
  215. IFeatureClass fc;
  216. try
  217. {
  218. if (layerID < 0)
  219. throw new ArgumentOutOfRangeException("layerID");
  220. mapServer = serverObjectHelper.ServerObject as IMapServer3;
  221. if (mapServer == null)
  222. throw new Exception("Unable to access the map server.");
  223. // Access the source feature class.
  224. string mapName = mapServer.DefaultMapName;
  225. dataAccess = (IMapServerDataAccess)mapServer;
  226. fc = (IFeatureClass)dataAccess.GetDataSource(mapName, layerID);
  227. if (fc == null)
  228. throw new Exception("Unable to access the feature class for layer id:" + layerID);
  229. return CalculateNearestFeature(location, fc, GetSpatialReferenceSystem(Convert.ToInt32(wkid)));
  230. }
  231. catch (Exception ex)
  232. {
  233. logger.LogMessage(ServerLogger.msgType.error, "FindNearFeatures", SOE_ERROR_CODE, "An error occurred finding the nearest feature: " + ex.ToString()
  234. + "Paremeters: "
  235. + layerID.ToString()
  236. + ":"
  237. + location.ToString()
  238. + ":"
  239. + wkid.ToString());
  240. throw ex;
  241. }
  242. finally
  243. {
  244. mapServer = null;
  245. dataAccess = null;
  246. fc = null;
  247. }
  248. }
  249. /// <summary>
  250. /// Calculates the nearest feature from a feature class, based upon a point location and a spatial reference.
  251. /// </summary>
  252. /// <param name="location">The location.</param>
  253. /// <param name="fc">The fc.</param>
  254. /// <param name="sr">The sr.</param>
  255. /// <param name="layerID">The layer ID.</param>
  256. /// <remarks>Uses the input spatial reference to create an in memory index on the input feature class</remarks>
  257. private byte[] CalculateNearestFeature(IPoint location, IFeatureClass fc, ISpatialReference sr)
  258. {
  259. IIndexQuery2 idxQuery = null;
  260. IFeatureIndex2 ftIdx = null;
  261. ITrackCancel trkCancel = null;
  262. IGeoDataset ftDataset = null;
  263. try
  264. {
  265. ftIdx = new FeatureIndexClass();
  266. trkCancel = new TrackCancel();
  267. ftDataset = (IGeoDataset)fc;
  268. idxQuery = (IIndexQuery2)ftIdx;
  269. ftIdx.FeatureClass = fc;
  270. ftIdx.set_OutputSpatialReference(fc.ShapeFieldName, sr);
  271. ftIdx.Index(trkCancel, ftDataset.Extent);
  272. int closestFeature = -1;
  273. double distance = -1;
  274. if (idxQuery != null)
  275. idxQuery.NearestFeature(location, out closestFeature, out distance);
  276. JsonObject response = new JsonObject();
  277. response.AddLong("NearestFeatureId", closestFeature);
  278. response.AddDouble("Distance", Math.Round((distance / 1000), 2)); //convert to kilometers and round.
  279. return Encoding.UTF8.GetBytes(response.ToJson());
  280. }
  281. catch (Exception ex)
  282. {
  283. logger.LogMessage(ServerLogger.msgType.error, "CalculateNearestFeature", SOE_ERROR_CODE, "An error calculating the nearest feature: "
  284. + ex.ToString()
  285. + "Parameters: "
  286. + location.ToString()
  287. + ":"
  288. + sr.FactoryCode
  289. + ":"
  290. + fc.AliasName);
  291. throw ex;
  292. }
  293. finally
  294. {
  295. idxQuery = null;
  296. ftIdx = null;
  297. trkCancel = null;
  298. ftDataset = null;
  299. }
  300. }
  301. /// <summary>
  302. /// Gets the nearest layer info object based upon a map service layer id.
  303. /// </summary>
  304. /// <param name="layerID">The layer ID.</param>
  305. /// <returns></returns>
  306. private NearestLayerInfo GetLayerInfo(int layerID)
  307. {
  308. IMapServer3 mapServer;
  309. IMapLayerInfo layerInfo;
  310. IMapLayerInfos layerInfos;
  311. try
  312. {
  313. if (layerID < 0)
  314. throw new ArgumentOutOfRangeException("layerID");
  315. mapServer = serverObjectHelper.ServerObject as IMapServer3;
  316. if (mapServer == null)
  317. throw new Exception("Unable to access the map server.");
  318. layerInfos = mapServer.GetServerInfo(mapServer.DefaultMapName).MapLayerInfos;
  319. long c = layerInfos.Count;
  320. for (int i = 0; i < c; i++)
  321. {
  322. layerInfo = layerInfos.get_Element(i);
  323. if (layerInfo.ID == layerID)
  324. return new NearestLayerInfo(layerInfo);
  325. }
  326. throw new ArgumentOutOfRangeException("layerID");
  327. }
  328. catch (Exception ex)
  329. {
  330. logger.LogMessage(ServerLogger.msgType.error, "GetLayerInfo", SOE_ERROR_CODE, "An error occurred getting the nearest layer info: " + ex.ToString());
  331. throw ex;
  332. }
  333. finally
  334. {
  335. mapServer = null;
  336. layerInfos = null;
  337. layerInfo = null;
  338. }
  339. }
  340. /// <summary>
  341. /// Gets the nearest layer infos based upon the layer infos in a map service.
  342. /// </summary>
  343. /// <returns></returns>
  344. private NearestLayerInfo[] GetLayerInfos()
  345. {
  346. IMapServer3 mapServer;
  347. IMapServerInfo msInfo;
  348. IMapLayerInfos layerInfos;
  349. try
  350. {
  351. mapServer = serverObjectHelper.ServerObject as IMapServer3;
  352. if (mapServer == null)
  353. throw new Exception("Unable to access the map server.");
  354. msInfo = mapServer.GetServerInfo(mapServer.DefaultMapName);
  355. layerInfos = msInfo.MapLayerInfos;
  356. int c = layerInfos.Count;
  357. NearestLayerInfo[] nearestLayerInfos = new NearestLayerInfo[c];
  358. for (int i = 0; i < c; i++)
  359. {
  360. IMapLayerInfo layerInfo = layerInfos.get_Element(i);
  361. nearestLayerInfos[i] = new NearestLayerInfo(layerInfo);
  362. }
  363. return nearestLayerInfos;
  364. }
  365. catch (Exception ex)
  366. {
  367. logger.LogMessage(ServerLogger.msgType.error, "GetLayerInfos", SOE_ERROR_CODE, "An error occurred getting the nearest layer collection: " + ex.ToString());
  368. throw ex;
  369. }
  370. finally
  371. {
  372. mapServer = null;
  373. msInfo = null;
  374. layerInfos = null;
  375. }
  376. }
  377. /// <summary>
  378. /// Converts a set of IPoints to json response.
  379. /// </summary>
  380. /// <param name="referenceSystem">The reference system.</param>
  381. /// <param name="mgrsReference">The MGRS reference.</param>
  382. /// <param name="coordinates">The coordinates.</param>
  383. /// <remarks>Adds a wkid to the response to denote the wkid of coordinates. Does this because internally the method uses the SOESupport.Conversion method
  384. /// which does not convert the spatial reference on the IPoint.</remarks>
  385. private JsonObject ConvertPointsToJsonResponse(ISpatialReference referenceSystem, string mgrsReference, List<IPoint> coordinates)
  386. {
  387. try
  388. {
  389. //set up the properties of the response
  390. JsonObject result = new JsonObject();
  391. result.AddString("wkid", referenceSystem.FactoryCode.ToString());
  392. List<JsonObject> convertedCoords = new List<JsonObject>();
  393. foreach (var coordinate in coordinates)
  394. {
  395. JsonObject convertedCoord = ESRI.ArcGIS.SOESupport.Conversion.ToJsonObject(coordinate);
  396. convertedCoords.Add(convertedCoord);
  397. }
  398. result.AddArray("ConvertedCoordinates", convertedCoords.ToArray());
  399. return result;
  400. }
  401. catch (Exception ex)
  402. {
  403. logger.LogMessage(ServerLogger.msgType.error, "ConvertPointsToJsonResponse", SOE_ERROR_CODE, "An error converting Point collection to JSON " + ex.ToString());
  404. throw ex;
  405. }
  406. finally
  407. {
  408. }
  409. }
  410. /// <summary>
  411. /// Converts all MGRS References sent in the references collection to a collection of IPoints.
  412. /// Uses the referenceSystem parameter as the target spatial reference system for the IPoints
  413. /// </summary>
  414. /// <param name="referenceSystem">The reference system.</param>
  415. /// <param name="references">The references.</param>
  416. /// <returns></returns>
  417. /// <remarks>
  418. /// Note the conversion of the MGRS reference is based upon and input and out Spheroid Datum of GDA94, therefore the passed in referenceSystem for final projection
  419. /// should be compatible with GDA94
  420. /// </remarks>
  421. private JsonObject ConvertMGRSReference(ISpatialReference referenceSystem, List<string> references)
  422. {
  423. //List<IPoint> convertedCoords;
  424. try
  425. {
  426. //get the datum of the desired output
  427. IDatum datum = GetSpatialReferenceSystemDatum(referenceSystem);
  428. //initialise the base coordinate systems for projection
  429. ESRI.ArcGIS.Geometry.ISpatialReferenceFactory spatRefFact = new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass();
  430. ISpatialReference baseCoordinateSystem = null;
  431. if(datum.FactoryCode==WGS84)
  432. baseCoordinateSystem = spatRefFact.CreateGeographicCoordinateSystem((int)ESRI.ArcGIS.Geometry.esriSRGeoCSType.esriSRGeoCS_WGS1984);
  433. else if (datum.FactoryCode == GDA94)
  434. baseCoordinateSystem = spatRefFact.CreateGeographicCoordinateSystem((int)ESRI.ArcGIS.Geometry.esriSRGeoCSType.esriSRGeoCS_GDA1994);
  435. else
  436. {
  437. throw new ArgumentOutOfRangeException("The datum: " + datum.Name + " for spatial reference: " + referenceSystem.Name + " is not supported. " +
  438. "Conversion is supportred on Datums: WGS84 (WKID: 6326) and GD94 (WKID: 6283)");
  439. }
  440. //SH - Added to support DFU-40
  441. //convertedCoords = new List<IPoint>();
  442. if (references == null)
  443. throw new Exception("References collection cannot be null");
  444. //SH - Added to support DFU-40
  445. //use a dictionary to store the reference and its associated point
  446. Dictionary<string, IPoint> convertedReferences = new Dictionary<string, IPoint>();
  447. foreach (var refr in references)
  448. {
  449. //convert to GDA94
  450. double longitude = 0;
  451. double latitude = 0;
  452. if(datum.FactoryCode==WGS84)
  453. coorConv.ConvertMGRSToDD(refr, SpheroidDatum.SPHEROID_WGS84, SpheroidDatum.SPHEROID_WGS84, out longitude, out latitude);
  454. else if(datum.FactoryCode==GDA94)
  455. coorConv.ConvertMGRSToDD(refr, SpheroidDatum.SPHEROID_WGS84, SpheroidDatum.SPHEROID_GDA94, out longitude, out latitude);
  456. //project to the requested WKID
  457. IPoint pnt = CreatePoint(baseCoordinateSystem, referenceSystem, latitude, longitude);
  458. //SH - Added to support DFU-40
  459. convertedReferences.Add(refr, pnt);
  460. //convertedCoords.Add(pnt);
  461. pnt = null;
  462. }
  463. //SH - Added to support DFU-40
  464. //convert the dictionary to JSON
  465. JsonObject[] convertedReferencesJson = CreateJsonRecords(convertedReferences) as JsonObject[];
  466. //SH - Added to support DFU-40
  467. // Create a JSON object to store the final results
  468. JsonObject finalResults = new JsonObject();
  469. finalResults.AddArray("convertedReferences", convertedReferencesJson.ToArray());
  470. return finalResults;
  471. }
  472. catch (Exception ex)
  473. {
  474. logger.LogMessage(ServerLogger.msgType.error, "ConvertMGRSReference", SOE_ERROR_CODE, "An error converting MGRS reference: " + ex.ToString());
  475. throw ex;
  476. }
  477. finally
  478. {
  479. }
  480. }
  481. /// <summary>
  482. /// Creates the json records.
  483. /// </summary>
  484. /// <param name="convertedReferences">The converted references.</param>
  485. /// <returns></returns>
  486. /// <remarks>Added to support DFU-40 - updated the method to return a complex object containing both the reference and the geometry</remarks>
  487. private JsonObject[] CreateJsonRecords(Dictionary<string, IPoint> convertedReferences)
  488. {
  489. JsonObject[] jsonRecordsArray = new JsonObject[convertedReferences.Count];
  490. int i = 0;
  491. // Loop through dictionary
  492. foreach (KeyValuePair<string, IPoint> kvp in convertedReferences)
  493. {
  494. // Get the current key and value
  495. string currentKey = kvp.Key.ToString();
  496. JsonObject currentValue = ESRI.ArcGIS.SOESupport.Conversion.ToJsonObject(kvp.Value);
  497. // Add the key and value to a JSON object
  498. JsonObject currentKeyValue = new JsonObject();
  499. currentKeyValue.AddString("reference", currentKey);
  500. currentKeyValue.AddString("wkid", kvp.Value.SpatialReference.FactoryCode.ToString());
  501. currentKeyValue.AddJsonObject("point", currentValue);
  502. // Add the record object to an array
  503. jsonRecordsArray.SetValue(currentKeyValue, i);
  504. i++;
  505. }
  506. return jsonRecordsArray;
  507. }
  508. private IDatum GetSpatialReferenceSystemDatum(ISpatialReference referenceSystem)
  509. {
  510. IDatum datum = null;
  511. IProjectedCoordinateSystem projSystem = referenceSystem as IProjectedCoordinateSystem;
  512. IGeographicCoordinateSystem geoSystem = referenceSystem as IGeographicCoordinateSystem;
  513. if (projSystem!=null)
  514. {
  515. datum = projSystem.GeographicCoordinateSystem.Datum;
  516. }
  517. else if (geoSystem!=null)
  518. {
  519. datum = geoSystem.Datum;
  520. }
  521. return datum;
  522. }
  523. /// <summary>
  524. /// Gets the spatial reference system based upon a well known identifier (WKID).
  525. /// </summary>
  526. /// <param name="WKID">The WKID.</param>
  527. private ESRI.ArcGIS.Geometry.ISpatialReference GetSpatialReferenceSystem(int WKID)
  528. {
  529. ESRI.ArcGIS.Geometry.ISpatialReference coordSystem = null;
  530. ESRI.ArcGIS.Geometry.ISpatialReferenceFactory spatRefFact = new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass();
  531. try
  532. {
  533. Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
  534. ISpatialReferenceFactory3 srFactory = (ISpatialReferenceFactory3)Activator.CreateInstance(factoryType);
  535. return srFactory.CreateSpatialReference(WKID);
  536. //List<int> allowableSpatialReferences = new List<int> { VICGRID, MGA54, MGA55, GCS, WMCT };
  537. //if (!allowableSpatialReferences.Contains(WKID))
  538. //{
  539. // throw new ArgumentOutOfRangeException(WKID.ToString(), "The WKID: " + WKID.ToString() + " is not an accepted WKID. Supported spatial references are: " +
  540. // "GDA_1994_VICGRID94 (WKID: 3111), GDA_1994_MGA_Zone_54 (WKID: 28354), GDA_1994_MGA_Zone_55 (WKID: 28355), GCS_GDA_1994 (WKID: 4283) WGS_1984_Web_Mercator_Auxiliary_Sphere (3857)");
  541. //}
  542. //if (WKID == VICGRID)
  543. //{
  544. // coordSystem = spatRefFact.CreateProjectedCoordinateSystem((int)ESRI.ArcGIS.Geometry.esriSRProjCS4Type.esriSRProjCS_GDA1994_VICGRID94);
  545. //}
  546. //else if (WKID == MGA54)
  547. //{
  548. // coordSystem = spatRefFact.CreateProjectedCoordinateSystem((int)ESRI.ArcGIS.Geometry.esriSRProjCSType.esriSRProjCS_GDA1994MGA_54);
  549. //}
  550. //else if (WKID == MGA55)
  551. //{
  552. // coordSystem = spatRefFact.CreateProjectedCoordinateSystem((int)ESRI.ArcGIS.Geometry.esriSRProjCSType.esriSRProjCS_GDA1994MGA_55);
  553. //}
  554. //else if (WKID == GCS)
  555. //{
  556. // coordSystem = spatRefFact.CreateGeographicCoordinateSystem((int)ESRI.ArcGIS.Geometry.esriSRGeoCSType.esriSRGeoCS_GDA1994);
  557. //}
  558. //else if (WKID == WMCT)
  559. //{
  560. // coordSystem = spatRefFact.CreateProjectedCoordinateSystem((int)ESRI.ArcGIS.Geometry.esriSRProjCS3Type.esriSRProjCS_WGS1984WebMercatorMajorAuxSphere);
  561. //}
  562. //else
  563. //{
  564. // throw new ArgumentOutOfRangeException(WKID.ToString(), "The WKID: " + WKID.ToString() + " is not an accepted WKID");
  565. //}
  566. //return coordSystem;
  567. }
  568. catch (Exception ex)
  569. {
  570. logger.LogMessage(ServerLogger.msgType.error, "GetSpatialReferenceSystem", SOE_ERROR_CODE, "An error creating a spatial reference system based on WKID " + WKID.ToString() + "Error: " + ex.ToString());
  571. throw ex;
  572. }
  573. finally
  574. {
  575. spatRefFact = null;
  576. }
  577. }
  578. /// <summary>
  579. /// Creates a point based upon a lat and long, uses the base and target systems to reporoject
  580. /// </summary>
  581. /// <param name="baseSystem">The base system.</param>
  582. /// <param name="targetSystem">The target system.</param>
  583. /// <param name="latitude">The latitude.</param>
  584. /// <param name="longitude">The longitude.</param>
  585. private IPoint CreatePoint(ISpatialReference baseSystem, ISpatialReference targetSystem, double latitude, double longitude)
  586. {
  587. IPoint point = null;
  588. try
  589. {
  590. point = new PointClass();
  591. point.PutCoords(longitude, latitude);
  592. point.SpatialReference = baseSystem;
  593. point.Project(targetSystem);
  594. return point;
  595. }
  596. catch (Exception ex)
  597. {
  598. logger.LogMessage(ServerLogger.msgType.error, "CreatePoint", SOE_ERROR_CODE, "An error occured created point: " + ex.ToString());
  599. throw ex;
  600. }
  601. finally
  602. {
  603. }
  604. }
  605. }
  606. }