/// <summary> /// Writes a Geometry to the given binary wirter. /// </summary> /// <param name="geometry">The geometry to write.</param> /// <param name="file">The file stream to write to.</param> /// <param name="geometryFactory">The geometry factory to use.</param> public override void Write(IBasicGeometry geometry, System.IO.BinaryWriter file, IGeometryFactory geometryFactory) { if(!(geometry is MultiPoint)) throw new ArgumentException("Geometry Type error: MultiPoint expected, but the type retrieved is " + geometry.GetType().Name); //if (!geometry.IsValid) // Trace.WriteLine("Invalid multipoint being written."); MultiPoint mpoint = geometry as MultiPoint; file.Write(int.Parse(Enum.Format(typeof(ShapeGeometryTypes), this.ShapeType, "d"))); IEnvelope box = geometry.Envelope; IEnvelope bounds = ShapeHandler.GetEnvelopeExternal(new PrecisionModel(geometryFactory.PrecisionModel), box); file.Write(bounds.Minimum.X); file.Write(bounds.Minimum.Y); file.Write(bounds.Maximum.X); file.Write(bounds.Maximum.Y); int numPoints = mpoint.NumPoints; file.Write(numPoints); // write the points for (int i = 0; i < numPoints; i++) { Point point = (Point)mpoint.Geometries[i]; file.Write(point.X); file.Write(point.Y); } }
/// <summary> /// 线 /// </summary> /// <param name="geometry"></param> /// <returns></returns> public static IEnumerable <byte> GetPolyLineBytes(IBasicGeometry geometry) { if (geometry.GetType().Name == "MultiPolyLine") { //var polyLine = ((MultiPolyLine)geometry).PolyLines[0]; return(GetMultiPolyLineBytes(geometry)); } else { var bytes = new List <byte>(); var line = (PolyLine)geometry; MultiGeometryPreHandle(bytes, line.Envelope, 1, line.PointsNum ); //Index to the First Point in Part bytes.AddRange(BitConverter.GetBytes(0)); foreach (var point in line.Points) { bytes.AddRange(BitConverter.GetBytes(point.X)); bytes.AddRange(BitConverter.GetBytes(point.Y)); } return(bytes); } }
/// <summary> /// 多线 /// </summary> /// <param name="geometry"></param> /// <returns></returns> public static IEnumerable <byte> GetMultiPolyLineBytes(IBasicGeometry geometry) { var bytes = new List <byte>(); MultiGeometryPreHandle(bytes, geometry.Envelope, geometry.PartsNum, geometry.PointsNum ); var firstPtIndexOfEveryPart = new List <int>(); var curPtIndexOfAllPoints = 0; var allPointsBytes = new List <byte>(); IEnumerable <PolyLine> polyLines = new List <PolyLine>(); if (geometry.GetType().Name == "MultiPolyLine") { var multiPolyLine = (MultiPolyLine)geometry; polyLines = multiPolyLine.PolyLines; } else if (geometry.GetType().Name == "Polygon") { var multiPolyLine = (Polygon)geometry; polyLines = multiPolyLine.PolyLines; } foreach (var polyLine in polyLines) { firstPtIndexOfEveryPart.Add(curPtIndexOfAllPoints); curPtIndexOfAllPoints += polyLine.PointsNum; allPointsBytes.AddRange(GeOneLineBytes(polyLine)); } foreach (var i in firstPtIndexOfEveryPart) { bytes.AddRange(BitConverter.GetBytes(i)); } bytes.AddRange(allPointsBytes); return(bytes); }