/GPX.Firemap.Server/FireMapExtension/FireMapExtension.cs
C# | 779 lines | 459 code | 173 blank | 147 comment | 36 complexity | c80f269d109e1ebbec9bcdf3e1f28239 MD5 | raw file
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Collections.Specialized;
- using System.Runtime.InteropServices;
- using System.EnterpriseServices;
- using ESRI.ArcGIS.esriSystem;
- using ESRI.ArcGIS.Server;
- using ESRI.ArcGIS.Geometry;
- using ESRI.ArcGIS.Geodatabase;
- using ESRI.ArcGIS.Carto;
- using ESRI.ArcGIS.SOESupport;
- using System.IO;
-
-
- namespace GPX.Firemap.Server
- {
- [ComVisible(true)]
- [Guid("b1402a3e-ed21-4ca5-a077-015bc8dcafce")]
- [ClassInterface(ClassInterfaceType.None)]
- public class FireMapExtension : ServicedComponent, IServerObjectExtension, IObjectConstruct, IRESTRequestHandler
- {
- private string soe_name;
-
- private IPropertySet configProps;
- private IServerObjectHelper serverObjectHelper;
- private ServerLogger logger;
- private IRESTRequestHandler reqHandler;
- private CoordinateConverter coorConv;
- //private IGeographicCoordinateSystem baseCoordinateSystem = null;
-
- private const int VICGRID = 3111;
- private const int MGA54 = 28354;
- private const int MGA55 = 28355;
- private const int GCS = 4283;
- private const int WMCT = 3857;
- private const int WGS84 = 6326;
- private const int GDA94 = 6283;
-
- private const int SOE_ERROR_CODE = 99999;
-
-
- public FireMapExtension()
- {
- soe_name = this.GetType().Name;
- logger = new ServerLogger();
- reqHandler = new SoeRestImpl(soe_name, CreateRestSchema()) as IRESTRequestHandler;
- }
-
- #region IServerObjectExtension Members
-
- public void Init(IServerObjectHelper pSOH)
- {
- serverObjectHelper = pSOH;
- }
-
- public void Shutdown()
- {
- }
-
- #endregion
-
- #region IObjectConstruct Members
-
- public void Construct(IPropertySet props)
- {
- configProps = props;
-
- //intialise the coordinate convertor
- coorConv = new CoordinateConverter();
-
- }
-
- #endregion
-
- #region IRESTRequestHandler Members
-
- public string GetSchema()
- {
- return reqHandler.GetSchema();
- }
-
- public byte[] HandleRESTRequest(string Capabilities, string resourceName, string operationName, string operationInput, string outputFormat, string requestProperties, out string responseProperties)
- {
- return reqHandler.HandleRESTRequest(Capabilities, resourceName, operationName, operationInput, outputFormat, requestProperties, out responseProperties);
- }
-
- #endregion
-
- private RestResource CreateRestSchema()
- {
- //main extension resource
- //provides a layer list of all layers in the service on which the extension is attached to.
- RestResource rootRes = new RestResource(soe_name, false, RootResHandler);
-
- //provides a single layer view - basically name and layer id
- RestResource nearestLayerResource = new RestResource("NearestLayers", true, NearestLayerHandler);
-
-
-
- //Operation for converting from MGRS reference to Coordinate
- RestOperation convertMGRS = new RestOperation("ConvertMGRS",
- new string[] { "reference", "wkid" },
- new string[] { "json" },
- ConvertMGRSHandler);
-
- //Operation for getting nearest feature from a layer
- RestOperation getNearestFeatureOp = new RestOperation("GetNearestFeature",
- new string[] { "location", "wkid"},
- new string[] { "json" },
- GetNearestFeatureHandler);
-
- nearestLayerResource.operations.Add(getNearestFeatureOp);
-
- rootRes.resources.Add(nearestLayerResource);
-
- rootRes.operations.Add(convertMGRS);
-
- return rootRes;
- }
-
-
- #region Resource Handlers
-
- private byte[] RootResHandler(NameValueCollection boundVariables, string outputFormat, string requestProperties, out string responseProperties)
- {
- responseProperties = null;
-
- NearestLayerInfo[] layerInfos = GetLayerInfos();
-
- JsonObject[] jos = new JsonObject[layerInfos.Length];
-
- for (int i = 0; i < layerInfos.Length; i++)
- jos[i] = layerInfos[i].ToJsonObject();
-
- JsonObject result = new JsonObject();
- result.AddArray("nearestLayers", jos);
-
- string json = result.ToJson();
-
- return Encoding.UTF8.GetBytes(json);
- }
-
- private byte[] NearestLayerHandler(NameValueCollection boundVariables, string outputFormat, string requestProperties, out string responseProperties)
- {
- responseProperties = null;
-
- //layerID
- int layerID = Convert.ToInt32(boundVariables["NearestLayersId"]);
-
- //execute
- NearestLayerInfo layerInfo = GetLayerInfo(layerID);
-
- string json = layerInfo.ToJsonObject().ToJson();
-
- return Encoding.UTF8.GetBytes(json);
- }
-
- #endregion
-
- #region Operation Handlers
-
- /// <summary>
- /// Converts the MGRS handler.
- /// </summary>
- /// <param name="boundVariables">The bound variables.</param>
- /// <param name="operationInput">The operation input.</param>
- /// <param name="outputFormat">The output format.</param>
- /// <param name="requestProperties">The request properties.</param>
- /// <param name="responseProperties">The response properties.</param>
- private byte[] ConvertMGRSHandler(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties)
- {
-
- try
- {
- responseProperties = null;
- ISpatialReference referenceSystem;
-
-
- string mgrsReference;
- bool found = operationInput.TryGetString("reference", out mgrsReference);
- if (!found || string.IsNullOrEmpty(mgrsReference))
- {
- throw new ArgumentNullException("reference");
- }
-
- long? wkid;
- found = operationInput.TryGetAsLong("wkid", out wkid);
- if (!found)
- {
- throw new ArgumentNullException("wkid");
- }
- else
- {
- //if valid set the spatial reference system based upon the WKID
- referenceSystem = GetSpatialReferenceSystem(Convert.ToInt32(wkid));
- }
-
-
- //process the incoming mgrs reference
- List<string> references = null;
- MGRSHelper.ProcessMGRSReference(mgrsReference, out references, coorConv);
-
- //SH - Added to support DFU-40
- //convert the references to points
- //List<IPoint> convertedReferences = ConvertMGRSReference(referenceSystem, references);
- JsonObject convertedReferences = ConvertMGRSReference(referenceSystem, references);
-
-
- //SH - Added to support DFU-40
- //return Encoding.UTF8.GetBytes(ConvertPointsToJsonResponse(referenceSystem, mgrsReference, convertedReferences).ToJson());
- return Encoding.UTF8.GetBytes(convertedReferences.ToJson());
- }
- catch
- {
- throw;
- }
- finally
- {
-
- }
-
-
- }
-
-
- /// <summary>
- /// Gets the nearest feature handler.
- /// </summary>
- /// <param name="boundVariables">The bound variables.</param>
- /// <param name="operationInput">The operation input.</param>
- /// <param name="outputFormat">The output format.</param>
- /// <param name="requestProperties">The request properties.</param>
- /// <param name="responseProperties">The response properties.</param>
- /// <returns></returns>
- private byte[] GetNearestFeatureHandler(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties)
- {
- try
- {
- responseProperties = null;
-
- //layerID
- int layerID = Convert.ToInt32(boundVariables["NearestLayersID"]);
-
- //location
- JsonObject jsonPoint;
- if (!operationInput.TryGetJsonObject("location", out jsonPoint))
- throw new ArgumentNullException("location");
-
- //wkid
- long? wkid;
- if (!operationInput.TryGetAsLong("wkid", out wkid))
- throw new ArgumentNullException("wkid");
-
- IPoint location = Conversion.ToGeometry(jsonPoint, esriGeometryType.esriGeometryPoint) as IPoint;
- if (location == null)
- throw new ArgumentException("GetNearestFeature: invalid location", "location");
-
-
- return FindNearFeatures(layerID, location, wkid);
- }
- catch
- {
- throw;
- }
- finally
- {
-
- }
-
-
- }
-
- #endregion
-
- /// <summary>
- /// Finds the nearest features in a layer to the passed in point.
- /// </summary>
- /// <param name="layerID">The layer ID.</param>
- /// <param name="location">The location.</param>
- /// <param name="wkid">The wkid.</param>
- private byte[] FindNearFeatures(int layerID, IPoint location, long? wkid)
- {
- IMapServer3 mapServer;
- IMapServerDataAccess dataAccess;
- IFeatureClass fc;
-
- try
- {
- if (layerID < 0)
- throw new ArgumentOutOfRangeException("layerID");
-
-
- mapServer = serverObjectHelper.ServerObject as IMapServer3;
- if (mapServer == null)
- throw new Exception("Unable to access the map server.");
-
- // Access the source feature class.
- string mapName = mapServer.DefaultMapName;
- dataAccess = (IMapServerDataAccess)mapServer;
- fc = (IFeatureClass)dataAccess.GetDataSource(mapName, layerID);
-
- if (fc == null)
- throw new Exception("Unable to access the feature class for layer id:" + layerID);
-
-
- return CalculateNearestFeature(location, fc, GetSpatialReferenceSystem(Convert.ToInt32(wkid)));
- }
- catch (Exception ex)
- {
- logger.LogMessage(ServerLogger.msgType.error, "FindNearFeatures", SOE_ERROR_CODE, "An error occurred finding the nearest feature: " + ex.ToString()
- + "Paremeters: "
- + layerID.ToString()
- + ":"
- + location.ToString()
- + ":"
- + wkid.ToString());
- throw ex;
-
- }
- finally
- {
- mapServer = null;
- dataAccess = null;
- fc = null;
- }
-
- }
-
- /// <summary>
- /// Calculates the nearest feature from a feature class, based upon a point location and a spatial reference.
- /// </summary>
- /// <param name="location">The location.</param>
- /// <param name="fc">The fc.</param>
- /// <param name="sr">The sr.</param>
- /// <param name="layerID">The layer ID.</param>
- /// <remarks>Uses the input spatial reference to create an in memory index on the input feature class</remarks>
- private byte[] CalculateNearestFeature(IPoint location, IFeatureClass fc, ISpatialReference sr)
- {
- IIndexQuery2 idxQuery = null;
- IFeatureIndex2 ftIdx = null;
- ITrackCancel trkCancel = null;
- IGeoDataset ftDataset = null;
-
- try
- {
-
- ftIdx = new FeatureIndexClass();
- trkCancel = new TrackCancel();
- ftDataset = (IGeoDataset)fc;
-
- idxQuery = (IIndexQuery2)ftIdx;
- ftIdx.FeatureClass = fc;
-
- ftIdx.set_OutputSpatialReference(fc.ShapeFieldName, sr);
-
- ftIdx.Index(trkCancel, ftDataset.Extent);
-
- int closestFeature = -1;
- double distance = -1;
-
- if (idxQuery != null)
- idxQuery.NearestFeature(location, out closestFeature, out distance);
-
-
- JsonObject response = new JsonObject();
- response.AddLong("NearestFeatureId", closestFeature);
- response.AddDouble("Distance", Math.Round((distance / 1000), 2)); //convert to kilometers and round.
-
- return Encoding.UTF8.GetBytes(response.ToJson());
- }
- catch (Exception ex)
- {
- logger.LogMessage(ServerLogger.msgType.error, "CalculateNearestFeature", SOE_ERROR_CODE, "An error calculating the nearest feature: "
- + ex.ToString()
- + "Parameters: "
- + location.ToString()
- + ":"
- + sr.FactoryCode
- + ":"
- + fc.AliasName);
-
- throw ex;
- }
- finally
- {
- idxQuery = null;
- ftIdx = null;
- trkCancel = null;
- ftDataset = null;
-
- }
-
- }
-
- /// <summary>
- /// Gets the nearest layer info object based upon a map service layer id.
- /// </summary>
- /// <param name="layerID">The layer ID.</param>
- /// <returns></returns>
- private NearestLayerInfo GetLayerInfo(int layerID)
- {
- IMapServer3 mapServer;
- IMapLayerInfo layerInfo;
- IMapLayerInfos layerInfos;
-
- try
- {
- if (layerID < 0)
- throw new ArgumentOutOfRangeException("layerID");
-
- mapServer = serverObjectHelper.ServerObject as IMapServer3;
- if (mapServer == null)
- throw new Exception("Unable to access the map server.");
-
-
- layerInfos = mapServer.GetServerInfo(mapServer.DefaultMapName).MapLayerInfos;
- long c = layerInfos.Count;
-
- for (int i = 0; i < c; i++)
- {
- layerInfo = layerInfos.get_Element(i);
- if (layerInfo.ID == layerID)
- return new NearestLayerInfo(layerInfo);
- }
-
- throw new ArgumentOutOfRangeException("layerID");
- }
- catch (Exception ex)
- {
- logger.LogMessage(ServerLogger.msgType.error, "GetLayerInfo", SOE_ERROR_CODE, "An error occurred getting the nearest layer info: " + ex.ToString());
- throw ex;
- }
- finally
- {
- mapServer = null;
- layerInfos = null;
- layerInfo = null;
-
- }
- }
-
- /// <summary>
- /// Gets the nearest layer infos based upon the layer infos in a map service.
- /// </summary>
- /// <returns></returns>
- private NearestLayerInfo[] GetLayerInfos()
- {
- IMapServer3 mapServer;
- IMapServerInfo msInfo;
- IMapLayerInfos layerInfos;
-
- try
- {
- mapServer = serverObjectHelper.ServerObject as IMapServer3;
- if (mapServer == null)
- throw new Exception("Unable to access the map server.");
-
- msInfo = mapServer.GetServerInfo(mapServer.DefaultMapName);
- layerInfos = msInfo.MapLayerInfos;
- int c = layerInfos.Count;
-
- NearestLayerInfo[] nearestLayerInfos = new NearestLayerInfo[c];
-
- for (int i = 0; i < c; i++)
- {
- IMapLayerInfo layerInfo = layerInfos.get_Element(i);
- nearestLayerInfos[i] = new NearestLayerInfo(layerInfo);
- }
-
- return nearestLayerInfos;
- }
- catch (Exception ex)
- {
- logger.LogMessage(ServerLogger.msgType.error, "GetLayerInfos", SOE_ERROR_CODE, "An error occurred getting the nearest layer collection: " + ex.ToString());
- throw ex;
- }
- finally
- {
- mapServer = null;
- msInfo = null;
- layerInfos = null;
- }
- }
-
- /// <summary>
- /// Converts a set of IPoints to json response.
- /// </summary>
- /// <param name="referenceSystem">The reference system.</param>
- /// <param name="mgrsReference">The MGRS reference.</param>
- /// <param name="coordinates">The coordinates.</param>
- /// <remarks>Adds a wkid to the response to denote the wkid of coordinates. Does this because internally the method uses the SOESupport.Conversion method
- /// which does not convert the spatial reference on the IPoint.</remarks>
- private JsonObject ConvertPointsToJsonResponse(ISpatialReference referenceSystem, string mgrsReference, List<IPoint> coordinates)
- {
- try
- {
- //set up the properties of the response
- JsonObject result = new JsonObject();
- result.AddString("wkid", referenceSystem.FactoryCode.ToString());
- List<JsonObject> convertedCoords = new List<JsonObject>();
-
- foreach (var coordinate in coordinates)
- {
-
- JsonObject convertedCoord = ESRI.ArcGIS.SOESupport.Conversion.ToJsonObject(coordinate);
- convertedCoords.Add(convertedCoord);
-
- }
-
- result.AddArray("ConvertedCoordinates", convertedCoords.ToArray());
- return result;
- }
- catch (Exception ex)
- {
- logger.LogMessage(ServerLogger.msgType.error, "ConvertPointsToJsonResponse", SOE_ERROR_CODE, "An error converting Point collection to JSON " + ex.ToString());
- throw ex;
- }
- finally
- {
-
- }
- }
-
- /// <summary>
- /// Converts all MGRS References sent in the references collection to a collection of IPoints.
- /// Uses the referenceSystem parameter as the target spatial reference system for the IPoints
- /// </summary>
- /// <param name="referenceSystem">The reference system.</param>
- /// <param name="references">The references.</param>
- /// <returns></returns>
- /// <remarks>
- /// 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
- /// should be compatible with GDA94
- /// </remarks>
- private JsonObject ConvertMGRSReference(ISpatialReference referenceSystem, List<string> references)
- {
- //List<IPoint> convertedCoords;
-
- try
- {
-
- //get the datum of the desired output
- IDatum datum = GetSpatialReferenceSystemDatum(referenceSystem);
-
- //initialise the base coordinate systems for projection
- ESRI.ArcGIS.Geometry.ISpatialReferenceFactory spatRefFact = new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass();
- ISpatialReference baseCoordinateSystem = null;
-
- if(datum.FactoryCode==WGS84)
- baseCoordinateSystem = spatRefFact.CreateGeographicCoordinateSystem((int)ESRI.ArcGIS.Geometry.esriSRGeoCSType.esriSRGeoCS_WGS1984);
- else if (datum.FactoryCode == GDA94)
- baseCoordinateSystem = spatRefFact.CreateGeographicCoordinateSystem((int)ESRI.ArcGIS.Geometry.esriSRGeoCSType.esriSRGeoCS_GDA1994);
- else
- {
- throw new ArgumentOutOfRangeException("The datum: " + datum.Name + " for spatial reference: " + referenceSystem.Name + " is not supported. " +
- "Conversion is supportred on Datums: WGS84 (WKID: 6326) and GD94 (WKID: 6283)");
- }
-
- //SH - Added to support DFU-40
- //convertedCoords = new List<IPoint>();
-
- if (references == null)
- throw new Exception("References collection cannot be null");
-
- //SH - Added to support DFU-40
- //use a dictionary to store the reference and its associated point
- Dictionary<string, IPoint> convertedReferences = new Dictionary<string, IPoint>();
-
-
- foreach (var refr in references)
- {
-
- //convert to GDA94
- double longitude = 0;
- double latitude = 0;
-
- if(datum.FactoryCode==WGS84)
- coorConv.ConvertMGRSToDD(refr, SpheroidDatum.SPHEROID_WGS84, SpheroidDatum.SPHEROID_WGS84, out longitude, out latitude);
- else if(datum.FactoryCode==GDA94)
- coorConv.ConvertMGRSToDD(refr, SpheroidDatum.SPHEROID_WGS84, SpheroidDatum.SPHEROID_GDA94, out longitude, out latitude);
-
-
- //project to the requested WKID
- IPoint pnt = CreatePoint(baseCoordinateSystem, referenceSystem, latitude, longitude);
-
- //SH - Added to support DFU-40
- convertedReferences.Add(refr, pnt);
- //convertedCoords.Add(pnt);
-
- pnt = null;
-
- }
-
- //SH - Added to support DFU-40
- //convert the dictionary to JSON
- JsonObject[] convertedReferencesJson = CreateJsonRecords(convertedReferences) as JsonObject[];
-
- //SH - Added to support DFU-40
- // Create a JSON object to store the final results
- JsonObject finalResults = new JsonObject();
- finalResults.AddArray("convertedReferences", convertedReferencesJson.ToArray());
-
- return finalResults;
- }
- catch (Exception ex)
- {
- logger.LogMessage(ServerLogger.msgType.error, "ConvertMGRSReference", SOE_ERROR_CODE, "An error converting MGRS reference: " + ex.ToString());
- throw ex;
- }
- finally
- {
-
- }
- }
-
- /// <summary>
- /// Creates the json records.
- /// </summary>
- /// <param name="convertedReferences">The converted references.</param>
- /// <returns></returns>
- /// <remarks>Added to support DFU-40 - updated the method to return a complex object containing both the reference and the geometry</remarks>
- private JsonObject[] CreateJsonRecords(Dictionary<string, IPoint> convertedReferences)
- {
- JsonObject[] jsonRecordsArray = new JsonObject[convertedReferences.Count];
-
- int i = 0;
-
- // Loop through dictionary
- foreach (KeyValuePair<string, IPoint> kvp in convertedReferences)
- {
- // Get the current key and value
- string currentKey = kvp.Key.ToString();
- JsonObject currentValue = ESRI.ArcGIS.SOESupport.Conversion.ToJsonObject(kvp.Value);
-
- // Add the key and value to a JSON object
- JsonObject currentKeyValue = new JsonObject();
- currentKeyValue.AddString("reference", currentKey);
- currentKeyValue.AddString("wkid", kvp.Value.SpatialReference.FactoryCode.ToString());
- currentKeyValue.AddJsonObject("point", currentValue);
-
- // Add the record object to an array
- jsonRecordsArray.SetValue(currentKeyValue, i);
- i++;
- }
-
- return jsonRecordsArray;
- }
-
-
- private IDatum GetSpatialReferenceSystemDatum(ISpatialReference referenceSystem)
- {
- IDatum datum = null;
-
- IProjectedCoordinateSystem projSystem = referenceSystem as IProjectedCoordinateSystem;
- IGeographicCoordinateSystem geoSystem = referenceSystem as IGeographicCoordinateSystem;
-
- if (projSystem!=null)
- {
- datum = projSystem.GeographicCoordinateSystem.Datum;
- }
- else if (geoSystem!=null)
- {
- datum = geoSystem.Datum;
- }
-
- return datum;
- }
-
- /// <summary>
- /// Gets the spatial reference system based upon a well known identifier (WKID).
- /// </summary>
- /// <param name="WKID">The WKID.</param>
- private ESRI.ArcGIS.Geometry.ISpatialReference GetSpatialReferenceSystem(int WKID)
- {
-
- ESRI.ArcGIS.Geometry.ISpatialReference coordSystem = null;
- ESRI.ArcGIS.Geometry.ISpatialReferenceFactory spatRefFact = new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass();
-
- try
- {
-
-
- Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
- ISpatialReferenceFactory3 srFactory = (ISpatialReferenceFactory3)Activator.CreateInstance(factoryType);
-
- return srFactory.CreateSpatialReference(WKID);
-
- //List<int> allowableSpatialReferences = new List<int> { VICGRID, MGA54, MGA55, GCS, WMCT };
-
- //if (!allowableSpatialReferences.Contains(WKID))
- //{
- // throw new ArgumentOutOfRangeException(WKID.ToString(), "The WKID: " + WKID.ToString() + " is not an accepted WKID. Supported spatial references are: " +
- // "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)");
- //}
-
- //if (WKID == VICGRID)
- //{
- // coordSystem = spatRefFact.CreateProjectedCoordinateSystem((int)ESRI.ArcGIS.Geometry.esriSRProjCS4Type.esriSRProjCS_GDA1994_VICGRID94);
- //}
- //else if (WKID == MGA54)
- //{
- // coordSystem = spatRefFact.CreateProjectedCoordinateSystem((int)ESRI.ArcGIS.Geometry.esriSRProjCSType.esriSRProjCS_GDA1994MGA_54);
- //}
- //else if (WKID == MGA55)
- //{
- // coordSystem = spatRefFact.CreateProjectedCoordinateSystem((int)ESRI.ArcGIS.Geometry.esriSRProjCSType.esriSRProjCS_GDA1994MGA_55);
-
- //}
- //else if (WKID == GCS)
- //{
- // coordSystem = spatRefFact.CreateGeographicCoordinateSystem((int)ESRI.ArcGIS.Geometry.esriSRGeoCSType.esriSRGeoCS_GDA1994);
-
- //}
- //else if (WKID == WMCT)
- //{
- // coordSystem = spatRefFact.CreateProjectedCoordinateSystem((int)ESRI.ArcGIS.Geometry.esriSRProjCS3Type.esriSRProjCS_WGS1984WebMercatorMajorAuxSphere);
- //}
-
- //else
- //{
- // throw new ArgumentOutOfRangeException(WKID.ToString(), "The WKID: " + WKID.ToString() + " is not an accepted WKID");
- //}
-
- //return coordSystem;
- }
- catch (Exception ex)
- {
- logger.LogMessage(ServerLogger.msgType.error, "GetSpatialReferenceSystem", SOE_ERROR_CODE, "An error creating a spatial reference system based on WKID " + WKID.ToString() + "Error: " + ex.ToString());
- throw ex;
-
- }
- finally
- {
- spatRefFact = null;
- }
-
-
- }
-
- /// <summary>
- /// Creates a point based upon a lat and long, uses the base and target systems to reporoject
- /// </summary>
- /// <param name="baseSystem">The base system.</param>
- /// <param name="targetSystem">The target system.</param>
- /// <param name="latitude">The latitude.</param>
- /// <param name="longitude">The longitude.</param>
- private IPoint CreatePoint(ISpatialReference baseSystem, ISpatialReference targetSystem, double latitude, double longitude)
- {
-
- IPoint point = null;
-
- try
- {
-
- point = new PointClass();
- point.PutCoords(longitude, latitude);
- point.SpatialReference = baseSystem;
- point.Project(targetSystem);
-
-
- return point;
- }
- catch (Exception ex)
- {
-
- logger.LogMessage(ServerLogger.msgType.error, "CreatePoint", SOE_ERROR_CODE, "An error occured created point: " + ex.ToString());
- throw ex;
- }
- finally
- {
-
- }
-
- }
-
- }
- }