/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Method fills Serialization information about GPGeometry. /// </summary> /// <param name="info">Serialization Info.</param> /// <param name="context">Streaming Context.</param> /// <exception cref="SerializationException">In case of geometry type is not /// supported.</exception> public void GetObjectData(SerializationInfo info, StreamingContext context) { if (_value is GPPoint) { GPPoint pt = (GPPoint)_value; info.AddValue(GPAttribute.POINT_X, pt.X); info.AddValue(GPAttribute.POINT_Y, pt.Y); } else if (_value is GPPolygon) { GPPolygon polygon = _value as GPPolygon; info.AddValue(GPAttribute.POLYGON_RINGS, polygon.Rings); } else if (_value is GPPolyline) { GPPolyline polyline = _value as GPPolyline; info.AddValue(GPAttribute.POLYLINE_PATHS, polyline.Paths); } else { // Unsupported geometry type. throw new SerializationException( Properties.Messages.Error_UnsupportedGPGeometryObject); } }
/// <summary> /// Converts <see cref="GPPoint"/> object into <see cref="Point"/> one. /// </summary> /// <param name="point">The reference to the <see cref="GPPoint"/> object /// to be converted.</param> /// <returns>A new <see cref="Point"/> instance converted from the <see cref="GPPoint"/> /// one.</returns> public static Point GPPointToPoint(GPPoint point) { Debug.Assert(point != null); var result = new Point(point.X, point.Y); return(result); }
/// <summary> /// Method converts Point object to GPPoint object. /// </summary> /// <param name="polygon">Point object to convert.</param> /// <returns>GPPoint object.</returns> public static GPPoint PointToGPPoint(Point pt) { GPPoint gppt = new GPPoint(); gppt.X = pt.X; gppt.Y = pt.Y; gppt.SpatialReference = new GPSpatialReference(WKID); return(gppt); }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Method creates GPPoint from Serialization Info. /// </summary> /// <param name="info">Serialization Info.</param> /// <returns>GPPoint.</returns> private GPPoint _CreatePoint(SerializationInfo info) { Debug.Assert(info != null); GPPoint pt = new GPPoint(); pt.X = info.GetDouble(GPAttribute.POINT_X); pt.Y = info.GetDouble(GPAttribute.POINT_Y); return(pt); }
/// <summary> /// Ensures that all driving directions have corresponding geometry. /// </summary> /// <param name="drivingDirections">Collection of driving directions to fix geometries /// for.</param> /// <param name="routeId">Route's id.</param> /// <param name="location">Location which will be used /// in case if direction has no geometry.</param> private static void _FixGeometries(IEnumerable<GPFeature> drivingDirections, Guid routeId, GPPoint location) { // Check that we have directions. if (!drivingDirections.Any()) throw _CreateNoDirectionsError(routeId); // Try to get item with geometry. var firstItemWithGeometry = drivingDirections.FirstOrDefault( gpFeature => gpFeature.Geometry != null && gpFeature.Geometry.Value != null); // Check that we get item with not null geometry. // NOTE: in some cases compact geometry is not set, for example when // route contains one order which point is the same as start and end // locations points. // WORKAROUND: in such cases apply first stop point as each geometry direction. if (firstItemWithGeometry == null || firstItemWithGeometry.Geometry == null || firstItemWithGeometry.Geometry.Value == null) { // Set first direction item geometry, all other will be set in next cycle. var item = drivingDirections.First(); _FillGeometry(item, new double[] { location.X, location.Y }); } var directionsList = new List<GPFeature>(drivingDirections); for (int i = 0; i < directionsList.Count; i++) { var item = directionsList[i]; // If current item has no geometry. if (item.Geometry == null || item.Geometry.Value == null) { // If it is first geometry - use next geometry first point to // create line with zero length as current item geometry. if (i == 0) { var geometry = (GPPolyline)firstItemWithGeometry.Geometry.Value; _FillGeometry(item, geometry.Paths.Last().First()); } // In all other case - use previous geometry last point to // create line with zero length as current item geometry. else { var geometry = (GPPolyline)directionsList[i - 1].Geometry.Value; _FillGeometry(item, geometry.Paths.Last().Last()); } } } }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Method creates GPPoint from Serialization Info. /// </summary> /// <param name="info">Serialization Info.</param> /// <returns>GPPoint.</returns> private GPPoint _CreatePoint(SerializationInfo info) { Debug.Assert(info != null); GPPoint pt = new GPPoint(); pt.X = info.GetDouble(GPAttribute.POINT_X); pt.Y = info.GetDouble(GPAttribute.POINT_Y); return pt; }