日期:2014-05-18 浏览次数:20923 次
//写shp文件 FileStream ShpFileStream = new FileStream(outFilePath + PointFile.m_FileName + ".shp", FileMode.Create, FileAccess.Write); BinaryWriter BShpW = new BinaryWriter(ShpFileStream, Encoding.Default); ////////////////////////////////////////////////////////////////////////// //开始写.shp头文件 //////// fileCode 部分 位序 big int fileCode = 170328064; //fileCode部分的总是为9994 且其位序为big故需要转换位序 BShpW.Write(fileCode); /////// Unused 部分 位序 big,但其总是为0,故不用再进行换位 int[] Unused = new Int32[5]; for (int i = 0; i < 5; BShpW.Write(Unused[i]), i++) ; /////// fileLength 部分 位序 big ChangeOnBig是将高低位调转的函数 byte[] fileLength = ChangeOnBig(((44 *PointFile.Points.Count) + 100) / 2); BShpW.Write(fileLength); ////// versionNumber 部分 位序 little int versionNumber = 1000; BShpW.Write(versionNumber); ////// shapeType 部分 位序 little int shapeType = EssentialType; BShpW.Write(shapeType); //如果是点Z则是11 BShpW.Write(Xmin); BShpW.Write(Ymin); BShpW.Write(Xmax); BShpW.Write(Ymax); //写入Zmin BShpW.Write(PointFile.Hmin); //写入Zmax BShpW.Write(PointFile.Hmax); double Mmin = 0.0; BShpW.Write(Mmin); double Mmax = 0.0; BShpW.Write(Mmax); ///关于一个点的头文件已记录完毕,下面是点的shp实体文件: byte[] BRecordNumber = new byte[4]; int ID = 0; for (int i = 0; i < PointCounts; i++, ID++) { ////// 写入 RecordNumber 部分 位序 big BRecordNumber = ChangeOnBig(Convert.ToInt32(ID + 1)); BShpW.Write(BRecordNumber); ////// 写入 Content 部分 位序 big byte[] BContentLength = new byte[4]; BContentLength = ChangeOnBig(18); BShpW.Write(BContentLength); //写入要素类型 BShpW.Write(11); PerPoint thisPoint = PointFile.Points[i]; tx = thisPoint.m_Coor.x; //X坐标 ty = thisPoint.m_Coor.y; //Y坐标 BShpW.Write(tx); BShpW.Write(ty); double Zcord = Convert.ToDouble(thisPoint.m_Coor.H); BShpW.Write(Zcord); //Measure的值在此处对于每个点都是固定的 byte[] Measure = new byte[8] { 255, 255, 255, 255, 255, 255, 239, 255 }; BShpW.Write(Measure); } BShpW.Close(); DBFFileWrite(outFilePath, EssentialType); //写dbf文件