/// <summary> /// Locates point route location with the specified route identifier. /// </summary> /// <param name="routeId">The route identifier.</param> /// <param name="point">The point.</param> /// <param name="error">The error that occured during location.</param> /// <returns> /// Returns a <see cref="IGeometry" /> representing the location. /// </returns> public IGeometry Locate(object routeId, IPoint point, out esriLocatingError error) { IRouteLocation routeLocation = new RouteMeasurePointLocationClass(); routeLocation.RouteID = routeId; IRouteMeasurePointLocation location = (IRouteMeasurePointLocation)routeLocation; location.Measure = point.M; IGeometry result; this.Locator.Locate(routeLocation, out result, out error); return(result.IsEmpty ? null : result); }
/// <summary> /// Handler operation Point Location /// </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[] PointLocationOperHandler(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties) { responseProperties = "{\"Content-Type\" : \"application/json\"}"; int routeLayerID = Convert.ToInt32(boundVariables["RouteLayersID"], CultureInfo.InvariantCulture); esriUnits routeMeasureUnit = DSUtility.GetMeasureUnit(operationInput, MeasureUnit.routeMeasureUnit); esriUnits routeLocationMeasureUnit = DSUtility.GetMeasureUnit(operationInput, MeasureUnit.routeLocationMeasureUnit); double?measure; bool found = operationInput.TryGetAsDouble("measure", out measure); if (!found || !measure.HasValue) { throw new DynamicSegmentationException("measure not valid"); } double?lateralOffset; found = operationInput.TryGetAsDouble("lateralOffset", out lateralOffset); if (!found || !lateralOffset.HasValue) { lateralOffset = 0; } IFeatureClass featureClass = this.GetRouteFeatureClass(routeLayerID); 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; found = operationInput.TryGetObject("routeID", out routeID); if (!found) { throw new DynamicSegmentationException("routeID not valid"); } IField field = fields.get_Field(indexField); this.CheckRouteID(routeID, field); IRouteLocator2 routeLocator = DSUtility.GetRouteLocator(featureClass, routeIDFieldNameValue, routeMeasureUnit); IRouteLocation routeLocation = new RouteMeasurePointLocationClass(); routeLocation.RouteID = routeID; routeLocation.MeasureUnit = routeLocationMeasureUnit; routeLocation.LateralOffset = lateralOffset.Value; IRouteMeasurePointLocation routeMeasurePointLocation = (IRouteMeasurePointLocation)routeLocation; routeMeasurePointLocation.Measure = measure.Value; IGeometry geometry; esriLocatingError locatingError; routeLocator.Locate(routeLocation, out geometry, out locatingError); int errorId = (int)locatingError; JsonObject result = null; if (errorId != 0) { string errorDescription = string.Format(CultureInfo.InvariantCulture, "{0} ({1})", Enum.GetName(typeof(esriLocatingError), locatingError), errorId); IObjectJson jsonObjectError = new ObjectError(errorDescription); result = jsonObjectError.ToJsonObject(); } if ((geometry != null) && (!geometry.IsEmpty)) { if (result == null) { result = new JsonObject(); } result.AddJsonObject("geometries", Conversion.ToJsonObject(geometry)); } return(result.JsonByte()); }