public bool CopyRaster(IRasterWorkspace2 pRW, string pFileName, IRasterWorkspaceEx pWorkSpace, string pDestName) { try { IRasterDataset pRds = pRW.OpenRasterDataset(pFileName); IRasterProps pRasterProps = (IRasterProps)pRds.CreateDefaultRaster(); IRasterStorageDef pRasterStorageDef = new RasterStorageDefClass(); IRasterDef pRasterDef = new RasterDefClass(); pRasterDef.SpatialReference = pRasterProps.SpatialReference; IGeometryDef pGeoDef = new GeometryDefClass(); IGeometryDefEdit pGeoDefEdit = pGeoDef as IGeometryDefEdit; pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon; pGeoDefEdit.AvgNumPoints_2 = 4; pGeoDefEdit.GridCount_2 = 1; pGeoDefEdit.set_GridSize(0, 1000); pGeoDefEdit.SpatialReference_2 = pRasterProps.SpatialReference; IRasterDataset pRasterDataset = pWorkSpace.SaveAsRasterDataset(pDestName, pRds.CreateDefaultRaster(), pRasterStorageDef, "", pRasterDef, pGeoDef); return(true); } catch (System.Exception ex) { return(false); } }
public bool CopyRaster(IRasterWorkspace2 pRW, string pFileName, IRasterWorkspaceEx pWorkSpace, string pDestName) { try { IRasterDataset pRds = pRW.OpenRasterDataset(pFileName); IRasterProps pRasterProps = (IRasterProps)pRds.CreateDefaultRaster(); IRasterStorageDef pRasterStorageDef = new RasterStorageDefClass(); IRasterDef pRasterDef = new RasterDefClass(); pRasterDef.SpatialReference = pRasterProps.SpatialReference; IGeometryDef pGeoDef = new GeometryDefClass(); IGeometryDefEdit pGeoDefEdit = pGeoDef as IGeometryDefEdit; pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon; pGeoDefEdit.AvgNumPoints_2 = 4; pGeoDefEdit.GridCount_2 = 1; pGeoDefEdit.set_GridSize(0, 1000); pGeoDefEdit.SpatialReference_2 = pRasterProps.SpatialReference; IRasterDataset pRasterDataset = pWorkSpace.SaveAsRasterDataset(pDestName, pRds.CreateDefaultRaster(), pRasterStorageDef, "", pRasterDef, pGeoDef); return true; } catch (System.Exception ex) { return false; } }
private void btnOK_Click(object sender, EventArgs e) { try { if (this.CanDo()) { RasterUtil rasterUtil = new RasterUtil(); if (!(this.m_pOutName is IRasterCatalogName)) { IRasterWorkspaceEx rasterWorkspaceEx = this.m_pOutName.Open() as IRasterWorkspaceEx; for (int i = 0; i < this.m_pInNames.Count; i++) { IRasterDataset2 rasterDataset2 = (this.m_pInNames[i] as IName).Open() as IRasterDataset2; string fileNameWithoutExtension = Path.GetFileNameWithoutExtension((rasterDataset2 as IDataset).Name); if ((fileNameWithoutExtension[0] < '0' ? false : fileNameWithoutExtension[0] <= '9')) { fileNameWithoutExtension = string.Concat("A", fileNameWithoutExtension); } if (rasterWorkspaceEx is IWorkspace2) { int num = 1; string str = fileNameWithoutExtension; try { while ( (rasterWorkspaceEx as IWorkspace2).NameExists[ esriDatasetType.esriDTFeatureClass, str]) { str = string.Concat(fileNameWithoutExtension, "_", num.ToString()); num++; } } catch { } fileNameWithoutExtension = str; } ((IGeometryDefEdit)(new GeometryDef())).SpatialReference_2 = (rasterDataset2 as IGeoDataset).SpatialReference; rasterWorkspaceEx.SaveAsRasterDataset(fileNameWithoutExtension, rasterDataset2.CreateFullRaster(), null, "", null, null); } } else { IFeatureClass featureClass = this.m_pOutName.Open() as IFeatureClass; rasterUtil.ToRasterCatalog(this.m_pInNames, featureClass); } } } catch (Exception exception1) { Exception exception = exception1; CErrorLog.writeErrorLog(this, exception, ""); MessageBox.Show(exception.Message); } this.progressBar1.Visible = false; }