//************* //从文件中读取字段信息 static List <GISField> ReadFields(BinaryReader br, int FieldCount) { List <GISField> fields = new List <GISField>(); for (int fieldindex = 0; fieldindex < FieldCount; fieldindex++) { Type fieldtype = GISTools.IntToType(br.ReadInt32()); string fieldname = GISTools.ReadString(br); fields.Add(new GISField(fieldtype, fieldname)); } return(fields); }
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); }
//读取一个gisfeature的所有属性值,放在gisfile中 此函数需要事先知道字段结构,根据字段类型选取适当的读取函数 static GISAttribute ReadAttributes(List <GISField> fs, BinaryReader br) { GISAttribute attribute = new GISAttribute(); for (int i = 0; i < fs.Count; i++) { Type type = fs[i].datatype; if (type.ToString() == "System.Boolean") { attribute.AddValue(br.ReadBoolean()); } else if (type.ToString() == "System.Boolean") { attribute.AddValue(br.ReadBoolean()); } else if (type.ToString() == "System.Byte") { attribute.AddValue(br.ReadByte()); } else if (type.ToString() == "System.Char") { attribute.AddValue(br.ReadChar()); } else if (type.ToString() == "System.Decimal") { attribute.AddValue(br.ReadDecimal()); } else if (type.ToString() == "System.Double") { attribute.AddValue(br.ReadDouble()); } else if (type.ToString() == "System.Single") { attribute.AddValue(br.ReadSingle()); } else if (type.ToString() == "System.Int32") { attribute.AddValue(br.ReadInt32()); } else if (type.ToString() == "System.Int64") { attribute.AddValue(br.ReadInt64()); } else if (type.ToString() == "System.UInt16") { attribute.AddValue(br.ReadUInt16()); } else if (type.ToString() == "System.UInt32") { attribute.AddValue(br.ReadUInt32()); } else if (type.ToString() == "System.UInt64") { attribute.AddValue(br.ReadUInt64()); } else if (type.ToString() == "System.Boolean") { attribute.AddValue(br.ReadBoolean()); } else if (type.ToString() == "System.String") { attribute.AddValue(GISTools.ReadString(br)); } } return(attribute); }