Пример #1
0
 /// <summary>
 /// 写入shp
 /// </summary>
 /// <param name="wktList"></param>
 public void WriteShp(List <string> wktList)
 {
     if (mFileCreat)
     {
         mShpRecord.GetWKTInfo(wktList);
         mShxRecord = new ShxRecord(mShpRecord.Header);
         mHeader.Write(mShpFileWriter);
         mShxRecord.RecordDic = mShpRecord.Write(mShpFileWriter);
     }
 }
Пример #2
0
        /// <summary>
        /// 写入record记录
        /// 先判断是否获取wkt信息以及写入header
        /// 写入的同时 计算shx的记录内容
        /// </summary>
        /// <param name="writer"></param>
        /// <returns>返回shx的文件内容</returns>
        public Dictionary <ulong, ShxData> Write(BinaryWriter writer)
        {
            Dictionary <ulong, ShxData> shxDic = new Dictionary <ulong, ShxData>();

            if (isGetWKTInfo)
            {
                if (writer.BaseStream.Position == 0)
                {
                    mHeader.Write(writer);
                }
                int offset = 50;//跳过头文件
                switch (mHeader.GeoType)
                {
                case ShapeType.Point:
                    for (int i = 0; i < mRecordDic.Count; i++)
                    {
                        EVPoint point = mRecordDic[(ulong)(i + 1)].GeoShape as EVPoint;
                        ShxData shx   = new ShxData();
                        shx.ContentLength = point.DataLength;
                        shx.Offset        = offset;
                        offset           += shx.ContentLength + 4;
                        shxDic.Add(point.RecordNum, shx);
                        //写入shp
                        byte[] lbtRecorderNum = BitConverter.GetBytes(point.RecordNum);
                        byte[] bbtRecorderNum = ByteTransUtil.little2big(lbtRecorderNum);
                        writer.Write(bbtRecorderNum);

                        byte[] lbtDataLength = BitConverter.GetBytes(point.DataLength);
                        byte[] bbtDataLength = ByteTransUtil.little2big(lbtDataLength);
                        writer.Write(bbtDataLength);
                        writer.Write((int)ShapeType.Point);
                        writer.Write(point.X);
                        writer.Write(point.Y);
                    }

                    break;

                case ShapeType.PolyLine:
                    for (int i = 0; i < mRecordDic.Count; i++)
                    {
                        EVPolyLine line = mRecordDic[(ulong)(i + 1)].GeoShape as EVPolyLine;
                        ShxData    shx  = new ShxData();
                        shx.ContentLength = line.DataLength;
                        shx.Offset        = offset;
                        offset           += shx.ContentLength + 4;
                        shxDic.Add(line.RecordNum, shx);
                        //写入shp
                        byte[] lbtRecorderNum = BitConverter.GetBytes(line.RecordNum);
                        byte[] bbtRecorderNum = ByteTransUtil.little2big(lbtRecorderNum);
                        writer.Write(bbtRecorderNum);

                        byte[] lbtDataLength = BitConverter.GetBytes(line.DataLength);
                        byte[] bbtDataLength = ByteTransUtil.little2big(lbtDataLength);
                        writer.Write(bbtDataLength);

                        writer.Write((int)line.GeoType);
                        writer.Write(line.Xmin);
                        writer.Write(line.Ymin);
                        writer.Write(line.Xmax);
                        writer.Write(line.Ymax);

                        writer.Write(line.NumParts);
                        writer.Write(line.NumPoints);

                        for (int j = 0; j < line.NumParts; j++)
                        {
                            writer.Write((int)line.Parts[j]);
                        }

                        for (int j = 0; j < line.NumPoints; j++)
                        {
                            EVPoint point = line.Points[j] as EVPoint;
                            writer.Write(point.X);
                            writer.Write(point.Y);
                        }
                    }

                    break;

                case ShapeType.Polygon:
                    for (int i = 0; i < mRecordDic.Count; i++)
                    {
                        EVPolygon gon = mRecordDic[(ulong)(i + 1)].GeoShape as EVPolygon;
                        ShxData   shx = new ShxData();
                        shx.ContentLength = gon.DataLength;
                        shx.Offset        = offset;
                        offset           += shx.ContentLength + 4;
                        shxDic.Add(gon.RecordNum, shx);
                        //写入shp
                        byte[] lbtRecorderNum = BitConverter.GetBytes(gon.RecordNum);
                        byte[] bbtRecorderNum = ByteTransUtil.little2big(lbtRecorderNum);
                        writer.Write(bbtRecorderNum);

                        byte[] lbtDataLength = BitConverter.GetBytes(gon.DataLength);
                        byte[] bbtDataLength = ByteTransUtil.little2big(lbtDataLength);
                        writer.Write(bbtDataLength);

                        writer.Write((int)gon.GeoType);
                        writer.Write(gon.Xmin);
                        writer.Write(gon.Ymin);
                        writer.Write(gon.Xmax);
                        writer.Write(gon.Ymax);

                        writer.Write(gon.NumParts);
                        writer.Write(gon.NumPoints);

                        for (int j = 0; j < gon.NumParts; j++)
                        {
                            writer.Write((int)gon.Parts[j]);
                        }

                        for (int j = 0; j < gon.NumPoints; j++)
                        {
                            EVPoint point = gon.Points[j] as EVPoint;
                            writer.Write(point.X);
                            writer.Write(point.Y);
                        }
                    }

                    break;
                }
            }
            return(shxDic);
        }