public XLayer ReadFile(string filename) { FileStream fsr = new FileStream(filename, FileMode.Open); BinaryReader br = new BinaryReader(fsr); //读文件头 MyFileHeader mfh = (MyFileHeader)XTools.FromBytes(br, typeof(MyFileHeader)); //读图层名称 string name = XTools.ReadString(br); //读属性字段结构 List <XField> fields = ReadFields(mfh.FieldCount, br); //定义图层 SHAPETYPE ShapeType = (SHAPETYPE)Enum.Parse(typeof(SHAPETYPE), mfh.ShapeType.ToString()); XExtent extent = new XExtent( new XVertex(mfh.MinX, mfh.MinY), new XVertex(mfh.MaxX, mfh.MaxY)); XLayer layer = new XLayer(name, ShapeType, extent, fields); //读空间对象类型 for (int i = 0; i < mfh.FeatureCount; i++) { XSpatial spatial = ReadSpatial(ShapeType, br); XAttribute attribute = ReadAttribute(br, fields); layer.AddFeature(new XFeature(spatial, attribute)); } //关闭文件并返回结果 br.Close(); fsr.Close(); return(layer); }
void WriteFileHeader(XLayer layer, BinaryWriter bw) { MyFileHeader mfh = new MyFileHeader(); mfh.MinX = layer.Extent.GetMinX(); mfh.MinY = layer.Extent.GetMinY(); mfh.MaxX = layer.Extent.GetMaxX(); mfh.MaxY = layer.Extent.GetMaxY(); mfh.FeatureCount = layer.FeatureCount(); mfh.ShapeType = (int)(layer.ShapeType); mfh.FieldCount = layer.Fields.Count; bw.Write(XTools.ToBytes(mfh)); }
static void WriteFileHeader(GISLayer layer, BinaryWriter bw)//bw是与文件相连的文件写入工具 { MyFileHeader mfh = new MyFileHeader(); mfh.MinX = layer.Extent.getMinX(); mfh.MinY = layer.Extent.getMinY(); mfh.MaxX = layer.Extent.getMaxX(); mfh.MaxY = layer.Extent.getMaxY(); mfh.FeatureCount = layer.FeatureCount(); mfh.Shapetype = (int)(layer.ShapeType); mfh.FieldCount = layer.Fields.Count; bw.Write(GISTools.ToBytes(mfh)); }
static void WriteFileHeader(GISLayer layer, BinaryWriter bw) { MyFileHeader mfh = new MyFileHeader(); mfh.MinX = layer.Extent.MinX; mfh.MinY = layer.Extent.MinY; mfh.MaxX = layer.Extent.MaxX; mfh.MaxY = layer.Extent.MaxY; mfh.FeatureCount = layer.Features.Count; mfh.DrawAttributeOrNot = layer.DrawAttributeOrNot ? 1 : 0; mfh.ShapeType = ShapeTypeToInt(layer.ShapeType); mfh.FieldCount = layer.Fields.Count; bw.Write(ToBytes(mfh)); }
public static GISLayer ReadFile(string filename) { FileStream fsr = new FileStream(filename, FileMode.Open); BinaryReader br = new BinaryReader(fsr); MyFileHeader mfh = (MyFileHeader)(GISTools.FromBytes(br, typeof(MyFileHeader))); //读取文件头 SHAPETYPE ShapeType = (SHAPETYPE)Enum.Parse(typeof(SHAPETYPE), mfh.Shapetype.ToString()); //获取空间实体类型shapetype和 GISExtent Extent = new GISExtent(mfh.MinX, mfh.MaxX, mfh.MinY, mfh.MaxY); //地图范围extent string layername = GISTools.ReadString(br); //读取图层名 List <GISField> Fields = ReadFields(br, mfh.FieldCount); //读取字段信息 GISLayer layer = new GISLayer(layername, ShapeType, Extent, Fields); ReadFeatures(layer, br, mfh.FeatureCount); br.Close(); fsr.Close(); return(layer); }
public static GISLayer ReadFile(string filename) { FileStream fsr = new FileStream(filename, FileMode.Open); BinaryReader br = new BinaryReader(fsr); MyFileHeader mfh = (MyFileHeader)(FromBytes(br, typeof(MyFileHeader))); SHAPETYPE ShapeType = IntToShapeType(mfh.ShapeType); GISExtent Extent = new GISExtent(new GISVertex(mfh.MinX, mfh.MinY), new GISVertex(mfh.MaxX, mfh.MaxY)); string layername = ReadString(br); List <GISField> Fields = ReadFields(br, mfh.FieldCount); GISLayer layer = new GISLayer(layername, ShapeType, Extent, Fields); layer.DrawAttributeOrNot = (mfh.DrawAttributeOrNot == 1); layer.Features = ReadFeatures(br, ShapeType, Fields, mfh.FeatureCount); br.Close(); fsr.Close(); return(layer); }