Пример #1
0
        /// <summary>
        /// 获取文件大小
        /// </summary>
        /// <param name="task"></param>
        /// <returns></returns>
        private int CalculateSize(TransferTask task)
        {
            if (task.Category == TaskCategory.Files)
            {
                System.IO.FileInfo fileInfo = new System.IO.FileInfo(task.SourceFileName);
                return((int)(fileInfo.Length / 1024));
            }
            else if (task.Category == TaskCategory.Features)
            {
                DirectoryInfo dir      = new DirectoryInfo(System.IO.Path.GetDirectoryName(task.SourceFileName));
                string        nickName = System.IO.Path.GetFileNameWithoutExtension(task.SourceFileName);
                FileInfo[]    fs       = dir.GetFiles(string.Format("*{0}*", nickName));
                int           length   = 0;
                foreach (FileInfo f in fs)
                {
                    length += (int)f.Length;
                }

                if (task.DestFileName.ToLower().Contains(".gdb"))
                {
                    if (task.SourceFileName.ToLower().Contains(".gdb"))
                    {
                    }
                    else
                    {
                        return(length / 1024 + 1150);
                    }
                }
                else
                {
                    if (task.SourceFileName.ToLower().Contains(".gdb"))
                    {
                    }
                    else
                    {
                        return(length / 1024);
                    }
                }
            }
            else if (task.Category == TaskCategory.Raster)
            {
                if (task.DestFileName.ToLower().Contains(".gdb"))
                {
                    if (task.SourceFileName.ToLower().Contains(".gdb"))
                    {
                        IWorkspaceFactory inputWsF       = null;
                        IWorkspace        inputWs        = null;
                        IRasterWorkspace  inputRstWs     = null;
                        IRasterDataset2   inputRstDs     = null;
                        IRaster           inputRaster    = null;
                        string            inputDirectory = string.Empty;
                        string            inputRstName   = string.Empty;

                        string input = task.SourceFileName.Trim();
                        if (input.ToLower().Contains(".gdb"))
                        {
                            inputWsF       = new FileGDBWorkspaceFactoryClass();
                            inputDirectory = input.Substring(0, input.IndexOf(".gdb") + 4);
                        }
                        else
                        {
                            inputWsF       = new RasterWorkspaceFactoryClass();
                            inputDirectory = System.IO.Path.GetDirectoryName(input);
                        }
                        inputRstName = System.IO.Path.GetFileName(input);
                        inputWs      = inputWsF.OpenFromFile(inputDirectory, 0);
                        inputRstWs   = inputWs as IRasterWorkspace;
                        inputRstDs   = inputRstWs.OpenRasterDataset(inputRstName) as IRasterDataset2;
                        inputRaster  = inputRstDs.CreateDefaultRaster();

                        IRawBlocks  inputRawBlocks = (IRawBlocks)inputRstDs;
                        IRasterInfo inputRstInfo   = inputRawBlocks.RasterInfo;

                        IRasterProps in_rasterProps           = (IRasterProps)inputRaster;
                        int          Height                   = in_rasterProps.Height;
                        int          Width                    = in_rasterProps.Width;
                        rstPixelType in_rstPT                 = in_rasterProps.PixelType;
                        int          BandsCount               = inputRstInfo.BandCount;
                        Dictionary <rstPixelType, int> DictPT = new Dictionary <rstPixelType, int>();
                        DictPT.Clear();
                        DictPT.Add(rstPixelType.PT_DOUBLE, 64);
                        DictPT.Add(rstPixelType.PT_FLOAT, 32);
                        DictPT.Add(rstPixelType.PT_LONG, 32);
                        DictPT.Add(rstPixelType.PT_SHORT, 32);
                        DictPT.Add(rstPixelType.PT_UCHAR, 8);
                        DictPT.Add(rstPixelType.PT_ULONG, 32);
                        DictPT.Add(rstPixelType.PT_USHORT, 32);
                        DictPT.Add(rstPixelType.PT_CHAR, 8);

                        int Depth = 32;
                        DictPT.TryGetValue(in_rasterProps.PixelType, out Depth);

                        return((int)(1.0 * Height * Width * BandsCount * Depth / 8.0 / 1024));
                    }
                    else
                    {
                        System.IO.FileInfo fileInfo = new System.IO.FileInfo(task.SourceFileName);
                        return((int)(fileInfo.Length / 1024 + 1150));
                    }
                }
                else
                {
                    if (task.SourceFileName.ToLower().Contains(".gdb"))
                    {
                    }
                    else
                    {
                        System.IO.FileInfo fileInfo = new System.IO.FileInfo(task.SourceFileName);
                        return((int)(fileInfo.Length / 1024));
                    }
                }
            }
            return(task.Size);
        }
Пример #2
0
        private void ExportToTif()
        {
            string strFloder = txtOutData.Text;

            for (int i = 0; i < m_pMapControl.Map.LayerCount; i++)
            {
                if (m_pMapControl.Map.get_Layer(i) is IRasterLayer)
                {
                    //导入数据
                    IRasterLayer pRLayer     = m_pMapControl.Map.get_Layer(i) as IRasterLayer;
                    IRaster2     pRaster     = pRLayer.Raster as IRaster2;
                    IRawBlocks   pRawBlocks  = pRaster as IRawBlocks;
                    IRasterInfo  pRInfo      = pRawBlocks.RasterInfo;
                    IPnt         pPnt        = pRInfo.CellSize;
                    double       dcellSize   = pPnt.X;
                    double       dcellsizeY  = pPnt.Y;
                    string       sCellSize   = Convert.ToInt32(dcellSize * 10).ToString();
                    string       strFileName = "R" + sCellSize + "_" + pRLayer.Name;
                    string       strFullName = txtOutData.Text + "\\" + strFileName;
                    //设置空间参考
                    ISpatialReference pSpatialRef;
                    if (rdoLayer.Checked)//与原图相同
                    {
                        IGeoDataset pGeo = (IGeoDataset)pRLayer;
                        pSpatialRef = pGeo.SpatialReference;
                    }
                    else//与工作空间相同
                    {
                        pSpatialRef = m_pMapControl.Map.SpatialReference;
                    }

                    try
                    {
                        //IRasterLayerExport pRLayerExport = new RasterLayerExportClass();
                        //pRLayerExport.RasterLayer = pRLayer;
                        //pRLayerExport.SpatialReference = pSpatialRef;
                        //pRLayerExport.SetSize(pRLayer.ColumnCount, pRLayer.RowCount);
                        IWorkspaceFactory pWSF = new RasterWorkspaceFactoryClass();
                        IWorkspace        pWS  = pWSF.OpenFromFile(txtOutData.Text, 0);
                        //IRasterDataset pRDset = pRLayerExport.Export(pWS, strFileName, "TIFF");
                        //System.Runtime.InteropServices.Marshal.ReleaseComObject(pRDset);

                        IRasterProps pRasterProps = pRaster as IRasterProps;
                        //pRasterProps.PixelType = pRInfo.PixelType;
                        //投影发生变化,栅格的分辨率会发生变化
                        pRasterProps.SpatialReference = pSpatialRef;
                        IRawBlocks  pRBlocks = pRasterProps as IRawBlocks;
                        IRasterInfo pRaInfo  = pRBlocks.RasterInfo;
                        //计算出重投影之后对应的栅格的行数和列数,行列数改变之后,它对应的栅格的分辨率也会变化为原始栅格的分辨率
                        //如果没有下面的计算行列的步骤,重投影之后的分辨率和原始影响的分辨率不同,行列数相同
                        pRasterProps.Width  = Convert.ToInt32(pRasterProps.MeanCellSize().X *pRLayer.ColumnCount / dcellSize);
                        pRasterProps.Height = Convert.ToInt32(pRasterProps.MeanCellSize().Y *pRLayer.RowCount / dcellsizeY);
                        IEnvelope pEnvelope = new EnvelopeClass();
                        pEnvelope.XMin      = pRasterProps.Extent.UpperLeft.X;
                        pEnvelope.YMax      = pRasterProps.Extent.UpperLeft.Y;
                        pEnvelope.XMax      = pRasterProps.Extent.UpperLeft.X + pRasterProps.Width * dcellSize;
                        pEnvelope.YMin      = pRasterProps.Extent.UpperLeft.Y - pRasterProps.Height * dcellsizeY;
                        pRasterProps.Extent = pEnvelope;

                        ISaveAs2          pSaveAs = pRasterProps as ISaveAs2;
                        IRasterStorageDef pRSDef  = new RasterStorageDefClass();
                        //将存储栅格的分辨率设置为与原始图像相同,其实经过上面行列计算之后已经是相同的
                        IPnt pPntdec = new PntClass();
                        pPntdec.X       = dcellSize;
                        pPntdec.Y       = dcellsizeY;
                        pRSDef.CellSize = pPntdec;

                        IRasterDataset pDataset = pSaveAs.SaveAsRasterDataset(strFileName, pWS, "TIFF", pRSDef);
                        pDataset.PrecalculateStats(0);
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(pDataset);
                    }
                    catch (Exception exc)
                    {
                        //MessageBox.Show(exc.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
            this.Close();
        }