/// <summary> /// Reads <see cref="GPPolyline"/> object from the specified serialization info. /// </summary> /// <param name="info">The reference to the serialization info object to read /// polyline from.</param> /// <returns>A new deserialized <see cref="GPPolyline"/> object,</returns> private static GPPolyline _ReadPolyline(SerializationInfo info) { Debug.Assert(info != null); var paths = (object[])info.GetValue(GPAttribute.POLYLINE_PATHS, typeof(object[])); var data = new double[paths.Length][][]; for (var i = 0; i < paths.Length; ++i) { // Read a single path. var path = (object[])paths[i]; var dataPath = data[i] = new double[path.Length][]; for (var j = 0; j < path.Length; ++j) { // Read a single point from the path. var point = (object[])path[j]; var dataPoint = dataPath[j] = new double[point.Length]; // Copy point data. for (var k = 0; k < point.Length; ++k) { dataPoint[k] = Convert.ToDouble(point[k]); } } } var result = new GPPolyline { Paths = data, }; return(result); }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /// <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> /// Method converts Polyline object to GPPolyline object. /// </summary> /// <param name="polyline">Polyline object to convert.</param> /// <returns>GPPolyline object.</returns> public static GPPolyline PolylineToGPPolyline(Polyline polyline) { double[][][] paths = new double[polyline.Groups.Length][][]; for (int nGroup = 0; nGroup < polyline.Groups.Length; nGroup++) { paths[nGroup] = new double[polyline.Groups[nGroup]][]; Point[] points = polyline.GetGroupPoints(nGroup); for (int nPoint = 0; nPoint < points.Length; nPoint++) { paths[nGroup][nPoint] = new double[3]; paths[nGroup][nPoint][0] = points[nPoint].X; paths[nGroup][nPoint][1] = points[nPoint].Y; paths[nGroup][nPoint][2] = points[nPoint].M; } } GPPolyline gppolyline = new GPPolyline(); gppolyline.Paths = paths; gppolyline.SpatialReference = new GPSpatialReference(WKID); return(gppolyline); }
/// <summary> /// Converts the specified <see cref="GPPolyline"/> object to the <see cref="Polyline"/> one. /// </summary> /// <param name="polygon">The reference to the <see cref="GPPolyline"/> object to be /// converted.</param> /// <returns>A new <see cref="Polyline"/> object equivalent to the specified /// polyline.</returns> public static Polyline GPPolylineToPolyline(GPPolyline polyline) { return(_MakePolyCurve(polyline.Paths, (groups, points) => new Polyline(groups, points))); }
/// <summary> /// Reads <see cref="GPPolyline"/> object from the specified serialization info. /// </summary> /// <param name="info">The reference to the serialization info object to read /// polyline from.</param> /// <returns>A new deserialized <see cref="GPPolyline"/> object,</returns> private static GPPolyline _ReadPolyline(SerializationInfo info) { Debug.Assert(info != null); var paths = (object[])info.GetValue(GPAttribute.POLYLINE_PATHS, typeof(object[])); var data = new double[paths.Length][][]; for (var i = 0; i < paths.Length; ++i) { // Read a single path. var path = (object[])paths[i]; var dataPath = data[i] = new double[path.Length][]; for (var j = 0; j < path.Length; ++j) { // Read a single point from the path. var point = (object[])path[j]; var dataPoint = dataPath[j] = new double[point.Length]; // Copy point data. for (var k = 0; k < point.Length; ++k) { dataPoint[k] = Convert.ToDouble(point[k]); } } } var result = new GPPolyline { Paths = data, }; return result; }