/// <summary> /// 从wkt获取shp文件信息,包括头文件和记录 /// </summary> /// <param name="wktList"></param> public void GetWKTInfo(List <string> wktList) { if (mRecordDic != null) { mRecordDic.Clear(); } else { mRecordDic = new Dictionary <ulong, ShpData>(); } if (wktList != null && wktList.Count > 0) { for (int i = 0; i < wktList.Count; i++) { ShpData data = new ShpData(); data.WKTStr = wktList[i]; data.CoordTransGeo2Pro(); //从数据库读出是地理坐标系 需要转换为投影坐标系 data.GeoShape.RecordNum = (ulong)(i + 1); mRecordDic.Add((ulong)(i + 1), data); } } //根据RecordDic求header TransHeader(); isGetWKTInfo = true; }
/// <summary> /// 读取record数据 /// 当读取时文件流位置在第一个记录处 /// </summary> /// <param name="reader"></param> public void Read(BinaryReader reader) { //如果header为空先读取header if (mHeader == null) { mHeader.Read(reader); } if (mRecordDic != null) { mRecordDic.Clear(); } else { mRecordDic = new Dictionary <ulong, ShpData>(); } //目前只考虑点线面三种类型 switch (mHeader.GeoType) { case ShapeType.Point: while (reader.PeekChar() != -1) { EVPoint point = new EVPoint(); uint RecordNum = reader.ReadUInt32(); int DataLength = reader.ReadInt32(); ulong uRecordNum = ByteTransUtil.big2little((int)RecordNum); //读取第i个记录 //每一条的记录长度没有考虑RecordNum、DataLength 所以比实际长度少4字 int uDataLength = (int)ByteTransUtil.big2little(DataLength); //以字为单位,一字等于2字节,等于16位 长度不包括uRecordNum和uDataLength int geoType = reader.ReadInt32(); //每一个对象的类型 没有用! point.RecordNum = uRecordNum; point.DataLength = uDataLength; //固定10字 没有考虑RecordNum、DataLength 比实际长度少4字 point.GeoType = ShapeType.Point; point.X = reader.ReadDouble(); point.Y = reader.ReadDouble(); // ShpData item = new ShpData(); item.GeoShape = point; mRecordDic.Add(uRecordNum, item); } break; case ShapeType.PolyLine: while (reader.PeekChar() != -1) { EVPolyLine polyline = new EVPolyLine(); polyline.Parts = new ArrayList(); polyline.Points = new ArrayList(); uint RecordNum = reader.ReadUInt32(); //读取第i个记录 从1开始算 ulong uRecordNum = ByteTransUtil.big2little((int)RecordNum); int DataLength = reader.ReadInt32(); //以字为单位,一字等于2字节,等于16位 //每一条的记录长度没有考虑RecordNum、DataLength 所以比实际长度少4字 int uDataLength = (int)ByteTransUtil.big2little(DataLength); int geoType = reader.ReadInt32();//每一个对象的类型 没有用 polyline.RecordNum = uRecordNum; polyline.DataLength = uDataLength; //没有考虑RecordNum、DataLength 比实际长度少4字 polyline.GeoType = ShapeType.PolyLine; polyline.Xmin = reader.ReadDouble(); polyline.Ymin = reader.ReadDouble(); polyline.Xmax = reader.ReadDouble(); polyline.Ymax = reader.ReadDouble(); polyline.NumParts = reader.ReadInt32(); polyline.NumPoints = reader.ReadInt32(); for (int i = 0; i < polyline.NumParts; i++) { int parts = new int(); parts = reader.ReadInt32(); polyline.Parts.Add(parts); } for (int j = 0; j < polyline.NumPoints; j++) { EVPoint pointtemp = new EVPoint(); pointtemp.X = reader.ReadDouble(); pointtemp.Y = reader.ReadDouble(); polyline.Points.Add(pointtemp); } ShpData item = new ShpData(); item.GeoShape = polyline; mRecordDic.Add(uRecordNum, item); } break; case ShapeType.Polygon: while (reader.PeekChar() != -1) { EVPolygon polygon = new EVPolygon(); polygon.Parts = new ArrayList(); polygon.Points = new ArrayList(); uint RecordNum = reader.ReadUInt32(); int DataLength = reader.ReadInt32(); ulong uRecordNum = ByteTransUtil.big2little((int)RecordNum); //读取第i个记录 //每一条的记录长度没有考虑RecordNum、DataLength 所以比实际长度少4字 //以字为单位,一字等于2字节,等于16位 int uDataLength = (int)ByteTransUtil.big2little(DataLength); int geoType = reader.ReadInt32(); polygon.RecordNum = uRecordNum; polygon.DataLength = uDataLength; polygon.GeoType = ShapeType.Polygon; polygon.Xmin = reader.ReadDouble(); polygon.Ymin = reader.ReadDouble(); polygon.Xmax = reader.ReadDouble(); polygon.Ymax = reader.ReadDouble(); polygon.NumParts = reader.ReadInt32(); polygon.NumPoints = reader.ReadInt32(); for (int j = 0; j < polygon.NumParts; j++) { int parts = new int(); parts = reader.ReadInt32(); polygon.Parts.Add(parts); } for (int j = 0; j < polygon.NumPoints; j++) { EVPoint pointtemp = new EVPoint(); pointtemp.X = reader.ReadDouble(); pointtemp.Y = reader.ReadDouble(); polygon.Points.Add(pointtemp); } ShpData item = new ShpData(); item.GeoShape = polygon; mRecordDic.Add(uRecordNum, item); } break; } }