ファイル ジオデータベースへラスター データセットを作成

投稿日:2016/9/1 (木) 更新日:

//設定値
string Name = "";
double PointX = -180.00000101746991;
double PointY = -90.000001068692526;
esriSRGeoCSType SpatialRereference = esriSRGeoCSType.esriSRGeoCS_WGS1984;
int CulumnCount = 43200;
int RowCount = 21600;
double CellSizeX = 0.00833333376795053;
double CellSizeY = 0.00833333376795053;
int NumBand = 1;
rstPixelType PixelType = rstPixelType.PT_SHORT;
 
//ファイル ジオデータベースへのアクセス
IWorkspaceFactory pWorkspaceFactory = new FileGDBWorkspaceFactoryClass();
IRasterWorkspaceEx pRasterWorkspaceEx = (IRasterWorkspaceEx)pWorkspaceFactory.OpenFromFile(@"D:\Workspace\FileGeodatabase.gdb",0);
 
//空間参照の作成
ISpatialReferenceFactory pSpatialReferenceFactory = new SpatialReferenceEnvironmentClass();
ISpatialReference pSpatialReference = pSpatialReferenceFactory.CreateGeographicCoordinateSystem((int)SpatialRereference);
 
//ラスタの原点の作成(原点はラスタの左上となります)
IPoint pPoint = new PointClass();
pPoint.X = PointX;
pPoint.Y = PointY;
pPoint.SpatialReference = pSpatialReference;
 
//セルサイズの作成
IPnt pPnt = new PntClass();
pPnt.X = CellSizeX;
pPnt.Y = CellSizeY;
 
//RasterStorageDefオブジェクトの作成
IRasterStorageDef pRasterStorageDef = new RasterStorageDefClass();
pRasterStorageDef.CellSize = pPnt;
pRasterStorageDef.Origin = pPoint;
pRasterStorageDef.CompressionType = esriRasterCompressionType.esriRasterCompressionJPEG2000;
pRasterStorageDef.PyramidLevel = 2;
pRasterStorageDef.PyramidResampleType = rstResamplingTypes.RSP_BilinearInterpolation;
pRasterStorageDef.TileHeight = 128;
pRasterStorageDef.TileWidth = 128;
pRasterStorageDef.CompressionType = esriRasterCompressionType.esriRasterCompressionUnknown;
 
//RasterDefの作成
IRasterDef pRasterDef = new RasterDefClass();
pRasterDef.SpatialReference = pSpatialReference;
 
//GeometryDefオブジェクトの作成(必須ではありません。デフォルト値を使用する場合は、CreateRasterDataset()の第7引数をNullとします)
IGeometryDefEdit pGeometryDefEdit = new GeometryDefClass();
pGeometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
pGeometryDefEdit.AvgNumPoints_2 = 4;
pGeometryDefEdit.GridCount_2 = 1;
pGeometryDefEdit.set_GridSize(0, 1000);
pGeometryDefEdit.SpatialReference_2 = pSpatialReference;
 
//RasterDatasetの作成
IRasterDataset3 pRasterDataset = (IRasterDataset3)pRasterWorkspaceEx.CreateRasterDataset(Name, NumBand, PixelType, pRasterStorageDef, "", pRasterDef, pGeometryDefEdit);
 
 
//Rasterを取得してセルサイズを変更
IRaster pRaster = pRasterDataset.CreateFullRaster();
IRasterProps pRasterProp = (IRasterProps)pRaster;
int lngCol = CulumnCount;
int lngRow = RowCount;
 
IEnvelope pEnvelope = new EnvelopeClass();
pEnvelope.XMin = pPoint.X;
pEnvelope.XMax = pPoint.X + pPnt.X * lngCol;
pEnvelope.YMin = pPoint.Y - pPnt.Y * lngRow;
pEnvelope.YMax = pPoint.Y;
 
pRasterProp.Width = lngCol;
pRasterProp.Height = lngRow;
pRasterProp.Extent = pEnvelope;
 
//IRasterEdit::Write()を使用した方法(セルサイズが大きすぎるとメモリエラーとなる)
//IPnt pSize = new PntClass();
//pSize.SetCoords(lngCol, lngRow);
 
//IPixelBlock pPixcelBlock = pRaster.CreatePixelBlock(pSize);
 
//IPnt pWritePnt = new PntClass();
//pWritePnt.SetCoords(0,0);
 
//IRasterEdit pRasterEdit = (IRasterEdit)pRaster;
//pRasterEdit.Write(pWritePnt,pPixcelBlock);
 
//変更したセルサイズをRasterDatasetに反映(モザイクを使用)
IRasterDatasetEdit pRasterDatasetEdit = (IRasterDatasetEdit)pRasterDataset;
pRasterDatasetEdit.Mosaic(pRaster, 0);

関連記事

-プログラミング, ArcGIS
-, ,

Copyright© WINGFIELD since1981 , 2018 All Rights Reserved.