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); }
public XFeature(XSpatial _Spatial, XAttribute _Attribute) { Spatial = _Spatial; Attribute = _Attribute; }