Example #1
0
 public GetValueFromRasterCommand(RasterArgs rasterArgs, IRasterWorkspaceEx rasterWorkspaceEx)
 {
     Args            = rasterArgs;
     RasterWorkspace = rasterWorkspaceEx;
 }
Example #2
0
        /// <summary>
        ///     Handles the incoming rest requests
        /// </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>
        /// <exception cref="System.ArgumentNullException"></exception>
        public static byte[] Handler(NameValueCollection boundVariables, JsonObject operationInput,
                                     string outputFormat, string requestProperties,
                                     out string responseProperties)
        {
            responseProperties = null;
            var errors = new ErrorModel(400);

            string layerName;
            double?utmx, utmy;

            var found = operationInput.TryGetString("layerName", out layerName);

            if (!found || string.IsNullOrEmpty(layerName))
            {
                throw new ArgumentNullException("layerName");
            }

            found = operationInput.TryGetAsDouble("utmx", out utmx);
            if (!found || !utmx.HasValue)
            {
                throw new ArgumentNullException("utmx");
            }

            found = operationInput.TryGetAsDouble("utmy", out utmy);
            if (!found || !utmy.HasValue)
            {
                throw new ArgumentNullException("utmy");
            }

            var connector = SdeConnectorFactory.Create(layerName);

            if (connector == null)
            {
                return(Json(new
                {
                    Message = "Database does not exist for {0}".With(layerName)
                }));
            }

            var workspace = connector.Connect();

            var featureWorkSpace = workspace as IFeatureWorkspace;

            if (featureWorkSpace == null)
            {
                errors.Message = "Error connecting to SDE.";

                return(Json(errors));
            }

            var rasterArgs = new RasterArgs(layerName, utmx, utmy);

            var response =
                CommandExecutor.ExecuteCommand(new GetValueFromRasterCommand(rasterArgs,
                                                                             featureWorkSpace as IRasterWorkspaceEx));

            if (response == null)
            {
                errors.Message = "No features found in {2} at the location {0}, {1}.".With(
                    rasterArgs.X, rasterArgs.Y, rasterArgs.LayerName);

                return(Json(errors));
            }

            return(Json(response));
        }