コード例 #1
0
		/// <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(Geometry geometry, System.IO.BinaryWriter file, GeometryFactory geometryFactory)
		{
			if (geometry.IsValid()==false)
			{
				Trace.WriteLine("Invalid polygon being written.");
			}
			GeometryCollection multi;
			if(geometry is GeometryCollection)
			{
				multi = (GeometryCollection) geometry;
			}
			else 
			{
				GeometryFactory gf = new GeometryFactory(geometry.PrecisionModel, geometry.GetSRID());
				//multi = new MultiPolygon(new Polygon[]{(Polygon) geometry}, geometry.PrecisionModel, geometry.GetSRID());
				multi = gf.CreateMultiPolygon( new Polygon[]{(Polygon) geometry} );
			}
			//file.setLittleEndianMode(true);
			file.Write(int.Parse(Enum.Format(typeof(ShapeType),this.ShapeType,"d")));
        
			Envelope box = multi.GetEnvelopeInternal();
			Envelope bounds = ShapeHandler.GetEnvelopeExternal(geometryFactory.PrecisionModel,  box);
			file.Write(bounds.MinX);
			file.Write(bounds.MinY);
			file.Write(bounds.MaxX);
			file.Write(bounds.MaxY);
        
			int numParts = GetNumParts(multi);
			int numPoints = multi.GetNumPoints();
			file.Write(numParts);
			file.Write(numPoints);
        
			
			// write the offsets to the points
			int offset=0;
			for (int part = 0; part < multi.Count; part++)
			{
				// offset to the shell points
				Polygon polygon = (Polygon)multi[part];
				file.Write(offset);
				offset = offset + polygon.Shell.GetNumPoints();
				// offstes to the holes
				foreach (LinearRing ring in polygon.Holes)
				{
					file.Write(offset);
					offset = offset + ring.GetNumPoints();
				}	
			}


			// write the points 
			for (int part = 0; part < multi.Count; part++)
			{
				Polygon poly = (Polygon)multi[part];
				Coordinates points = poly.Shell.GetCoordinates();
				if (_cga.IsCCW(points)==true)
				{
					//points = points.ReverseCoordinateOrder();
				}
				WriteCoords(points, file, geometryFactory);
				foreach(LinearRing ring in poly.Holes)
				{
					Coordinates points2 = ring.GetCoordinates();
					if (_cga.IsCCW(points2)==false)
					{
						//points2 = points2.ReverseCoordinateOrder();
					}
					WriteCoords(points2, file, geometryFactory);
				}
			}
		}