Esempio n. 1
0
        /// <summary>
        /// Handler operation Identify Route
        /// </summary>
        /// <param name="boundVariables">list of variables bound</param>
        /// <param name="operationInput">input of operation</param>
        /// <param name="outputFormat">format of output</param>
        /// <param name="requestProperties">list of request properties</param>
        /// <param name="responseProperties">list of response properties </param>
        /// <returns>response in byte</returns>
        private byte[] IdentifyRouteOperHandler(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties)
        {
            responseProperties = "{\"Content-Type\" : \"application/json\"}";
            string methodName   = MethodBase.GetCurrentMethod().Name;
            int    routeLayerID = Convert.ToInt32(boundVariables["RouteLayersID"], CultureInfo.InvariantCulture);

            esriUnits routeMeasureUnit = DSUtility.GetMeasureUnit(operationInput, MeasureUnit.routeMeasureUnit);

            IFeatureClass  featureClass          = this.GetRouteFeatureClass(routeLayerID);
            string         routeIDFieldNameValue = DSUtility.GetRouteIDFieldName(operationInput, featureClass.OIDFieldName);
            IRouteLocator2 routeLocator          = DSUtility.GetRouteLocator(featureClass, routeIDFieldNameValue, routeMeasureUnit);

            double?tolerance;
            bool   found = operationInput.TryGetAsDouble("tolerance", out tolerance);

            if (!found || !tolerance.HasValue)
            {
                tolerance = 0.0;
            }

            JsonObject jsonLocation;

            if (!operationInput.TryGetJsonObject("location", out jsonLocation))
            {
                throw new ArgumentException("Invalid location", methodName);
            }

            IPoint location = Conversion.ToGeometry(jsonLocation, esriGeometryType.esriGeometryPoint) as IPoint;

            if (location == null)
            {
                throw new ArgumentException("Invalid location", methodName);
            }

            IEnvelope envelope = location.Envelope;

            envelope.Expand(tolerance.Value, tolerance.Value, false);

            IRouteMeasurePointLocation routeMeasurePointLocation = new RouteMeasurePointLocationClass();
            IRouteLocation             routeLocation;
            IFeature   feature;
            JsonObject result = new JsonObject();

            List <JsonObject>        measures   = new List <JsonObject>();
            IEnumRouteIdentifyResult enumResult = routeLocator.Identify(envelope, string.Empty);

            for (int i = 1; i <= enumResult.Count; i++)
            {
                enumResult.Next(out routeLocation, out feature);
                routeMeasurePointLocation = (IRouteMeasurePointLocation)routeLocation;
                JsonObject measure = new JsonObject();
                measure.AddString("routeID", routeLocation.RouteID.ToString());
                measure.AddDouble("measure", routeMeasurePointLocation.Measure);
                measures.Add(measure);
            }

            result.AddArray("location", measures.ToArray());

            return(result.JsonByte());
        }
Esempio n. 2
0
        /// <summary>
        /// Handler operation Identify Route Ex
        /// </summary>
        /// <param name="boundVariables">list of variables bound</param>
        /// <param name="operationInput">input of operation</param>
        /// <param name="outputFormat">format of output</param>
        /// <param name="requestProperties">list of request properties</param>
        /// <param name="responseProperties">list of response properties </param>
        /// <returns>response in byte</returns>
        private byte[] IdentifyRouteExOperHandler(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties)
        {
            responseProperties = "{\"Content-Type\" : \"application/json\"}";
            string methodName   = MethodBase.GetCurrentMethod().Name;
            int    routeLayerID = Convert.ToInt32(boundVariables["RouteLayersID"], CultureInfo.InvariantCulture);

            esriUnits            routeMeasureUnit = DSUtility.GetMeasureUnit(operationInput, MeasureUnit.routeMeasureUnit);
            esriSegmentExtension segmentExtension = DSUtility.GetSegmentExtension(operationInput);
            IFeatureClass        featureClass     = this.GetRouteFeatureClass(routeLayerID);

            JsonObject jsonLocation;

            if (!operationInput.TryGetJsonObject("location", out jsonLocation))
            {
                throw new ArgumentException("Invalid location", methodName);
            }

            IPoint location = Conversion.ToGeometry(jsonLocation, esriGeometryType.esriGeometryPoint) as IPoint;

            if (location == null)
            {
                throw new ArgumentException("Invalid location", methodName);
            }

            string  routeIDFieldNameValue = DSUtility.GetRouteIDFieldName(operationInput);
            IFields fields     = featureClass.Fields;
            int     indexField = fields.FindField(routeIDFieldNameValue);

            if (indexField == -1)
            {
                throw new DynamicSegmentationException(string.Format(CultureInfo.InvariantCulture, "routeIDFieldName {0} not found!", routeIDFieldNameValue));
            }

            object routeID;
            bool   found = operationInput.TryGetObject("routeID", out routeID);

            if (!found)
            {
                throw new DynamicSegmentationException("routeID not valid");
            }

            double?tolerance;

            found = operationInput.TryGetAsDouble("tolerance", out tolerance);
            if (!found || !tolerance.HasValue)
            {
                tolerance = 0.0;
            }

            IField field = fields.get_Field(indexField);

            this.CheckRouteID(routeID, field);

            IRouteLocator2 routeLocator = DSUtility.GetRouteLocator(featureClass, routeIDFieldNameValue, routeMeasureUnit);

            IQueryFilter queryFilter = new QueryFilterClass();

            queryFilter.SubFields = routeLocator.RouteIDFieldName;
            queryFilter.AddField(routeLocator.RouteFeatureClass.ShapeFieldName);
            string where            = string.Format("{0} = {1}{2}{1}", routeLocator.RouteIDFieldNameDelimited, routeLocator.RouteIDIsString ? "'" : string.Empty, routeID);
            queryFilter.WhereClause = where;

            IPoint         locationNearest = null;
            IFeatureCursor featureCursor   = null;

            try
            {
                featureCursor = routeLocator.RouteFeatureClass.Search(queryFilter, true);
                IFeature featureRoute = featureCursor.NextFeature();
                if (featureRoute == null)
                {
                    throw new DynamicSegmentationException(string.Format(CultureInfo.InvariantCulture, "Feature with value {0} not found!", routeID));
                }

                IProximityOperator proximityOperator = featureRoute.ShapeCopy as IProximityOperator;
                locationNearest = proximityOperator.ReturnNearestPoint(location, segmentExtension);
            }
            catch
            {
                throw;
            }
            finally
            {
                if (featureCursor != null)
                {
                    Marshal.ReleaseComObject(featureCursor);
                }
            }

            IEnvelope envelope = locationNearest.Envelope;

            envelope.Expand(tolerance.Value, tolerance.Value, false);

            IRouteMeasurePointLocation routeMeasurePointLocation = new RouteMeasurePointLocationClass();
            IRouteLocation             routeLocation;
            IFeature   feature;
            JsonObject result = new JsonObject();

            List <JsonObject>        measures   = new List <JsonObject>();
            IEnumRouteIdentifyResult enumResult = routeLocator.Identify(envelope, where);

            for (int i = 1; i <= enumResult.Count; i++)
            {
                enumResult.Next(out routeLocation, out feature);
                routeMeasurePointLocation = (IRouteMeasurePointLocation)routeLocation;
                JsonObject measure = new JsonObject();
                measure.AddString("routeID", routeLocation.RouteID.ToString());
                measure.AddDouble("measure", routeMeasurePointLocation.Measure);
                measure.AddJsonObject("location", Conversion.ToJsonObject(locationNearest, true));
                measures.Add(measure);
            }

            result.AddArray("location", measures.ToArray());

            return(result.JsonByte());
        }