private static void _SaveShape(XmlWriter writer, string geometry) { writer.WriteStartElement(SHAPE_NODE_NAME); writer.WriteStartElement(TYPE_NODE_NAME); writer.WriteValue(1); writer.WriteEndElement(); Point[] points; if (CompactGeometryConverter.Convert(geometry, out points)) { writer.WriteStartElement(POLYLINE_NODE_NAME); writer.WriteStartElement(PATH_NODE_NAME); writer.WriteStartElement(COORDS_NODE_NAME); string coords = ""; foreach (Point point in points) { coords += string.Format("{0} {1};", point.X.ToString(DOUBLE_FORMAT, NumberFormatInfo.InvariantInfo), point.Y.ToString(DOUBLE_FORMAT, NumberFormatInfo.InvariantInfo)); } writer.WriteValue(coords); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndElement(); } writer.WriteEndElement(); }
/// <summary> /// Converts the specified feature to the <see cref="Direction"/> value. /// </summary> /// <param name="feature">The reference to the feature to be converted.</param> /// <returns>A new <see cref="Direction"/> value corresponding to the /// <paramref name="feature"/>.</returns> public static DirectionEx ConvertToDirection(GPFeature feature) { Debug.Assert(feature != null); var direction = new DirectionEx { DirectionType = ArcLogistics.DirectionType.ManeuverDirection, Length = feature.Attributes.Get <double>(NAAttribute.DirectionsDriveDistance), Text = feature.Attributes.Get <string>(NAAttribute.DirectionsText), }; var geometry = default(IEnumerable <Point>); Debug.Assert(feature.Geometry != null && feature.Geometry.Value != null); var points = (GPPolyline)feature.Geometry.Value; var allPoints = points.Paths.SelectMany(Identity); var haveMCoordinate = allPoints.All(point => point.Length == 3); if (haveMCoordinate) { geometry = allPoints.Select(point => new Point(point[0], point[1], point[2])); } else { geometry = allPoints.Select(point => new Point(point[0], point[1])); } direction.Geometry = CompactGeometryConverter.Convert(geometry); // Read maneuver type and drive time. var type = NADirectionsManeuverType.esriDMTUnknown; var subItemType = feature.Attributes.Get <NADirectionsSubItemType>( NAAttribute.DirectionsSubItemType); if (subItemType == NADirectionsSubItemType.ManeuverItem) { type = feature.Attributes.Get <NADirectionsManeuverType>( NAAttribute.DirectionsStringType); // Elapsed time is equal to drive time for maneuver direction items which are // not arrive/depart ones. if (type != NADirectionsManeuverType.esriDMTStop && type != NADirectionsManeuverType.esriDMTDepart) { direction.Time = feature.Attributes.Get <double>( NAAttribute.DirectionsElapsedTime); } } else { direction.DirectionType = DirectionType.Other; } direction.ManeuverType = _ConvertManeuverType(type); return(direction); }
/// <summary> /// Builds path. /// </summary> /// <param name="dirs">Directions.</param> /// <returns>Created directions geometry.</returns> private static Polyline _BuildPath(Direction[] dirs) { Debug.Assert(dirs != null); var points = new List <Point>(); foreach (Direction dir in dirs) { Point[] dirPoints = null; if (!CompactGeometryConverter.Convert(dir.Geometry, out dirPoints)) { throw new RouteException(Properties.Messages.Error_CompactGeometryConversion); // exception } points.AddRange(dirPoints); } return(new Polyline(points.ToArray())); }