YouTube | Facebook | X(Twitter) | RSS

ラスターのジオリファレンス

2016/9/1 (木)

{
    //時計回りでタイポイントを取得
     IPointCollection pTiePointCollection;
     pTiePointCollection = new MultipointClass();
     
     IPoint[] pPoint = new IPoint[4];
     pPoint(0) = new PointClass();
     pPoint(1) = new PointClass();
     pPoint(2) = new PointClass();
     pPoint(3) = new PointClass();
     pPoint(0).PutCoords(131.328125, 33.9583333333333);
     pPoint(1).PutCoords(131.34375, 33.9583333333333);
     pPoint(2).PutCoords(131.34375, 33.9479166666667);
     pPoint(3).PutCoords(131.328125, 33.9479166666667);
     
     int i;
     for (i = 0; i <= 3; i++) {
         pTiePointCollection.AddPoint(pPoint(i));
     }
     
     
    //ラスタのエクステント座標を取得
     IWorkspaceFactory pRasterWorkspaceFactory;
     pRasterWorkspaceFactory = new RasterWorkspaceFactory();
     
     IRasterWorkspace pRasterWorkspace;
     pRasterWorkspace = pRasterWorkspaceFactory.OpenFromFile("E:\\Projects\\Data", 0); //ラスタフォルダ
     
     IRasterDataset2 pRasterDataset;
     pRasterDataset = pRasterWorkspace.OpenRasterDataset("50317235.png"); //該当ラスタファイル
     
    //ラスタデータセットからラスタの取得
     IRaster pRaster;
     pRaster = pRasterDataset.CreateFullRaster;
     
     IRasterProps pRasterProps;
     pRasterProps = pRaster;
     
     IPointCollection pRasterPointCollection;
     pRasterPointCollection = new Multipoint();
     
     pRasterPointCollection.AddPoint(pRasterProps.Extent.UpperLeft());
     pRasterPointCollection.AddPoint(pRasterProps.Extent.UpperRight());
     pRasterPointCollection.AddPoint(pRasterProps.Extent.LowerRight());
     pRasterPointCollection.AddPoint(pRasterProps.Extent.LowerLeft());
     
     
    //ジオリファレンス
     IRasterGeometryProc pRasterGeometryProc;
     pRasterGeometryProc = new RasterGeometryProc();
     
     pRasterGeometryProc.Warp(pRasterPointCollection, pTiePointCollection, esriGeoTransPolyOrder1, pRaster);
     
     pRasterGeometryProc.Register(pRaster);
     
     
    //ラスタをレイヤに追加
     IRasterLayer pRasterLayer;
     pRasterLayer = new RasterLayer();
     pRasterLayer.Name = pRasterDataset.CompleteName;
     
     pRasterLayer.CreateFromRaster(pRaster);
     
     IMxDocument pMxDocument;
     pMxDocument = ThisDocument;
     
     IMap pMap;
     pMap = pMxDocument.FocusMap;
     
     pMap.AddLayer(pRasterLayer);
     
     pMxDocument.ActiveView.Refresh();
     pMxDocument.UpdateContents();
 
}
Sub GeoReference_fromLayer()
    '時計回りでタイポイントを取得
    Dim pTiePointCollection As IPointCollection
    Set pTiePointCollection = New MultipointClass()
     
    Dim pPoint(3) As IPoint
    Set pPoint(0) = New PointClass()
    Set pPoint(1) = New PointClass()
    Set pPoint(2) = New PointClass()
    Set pPoint(3) = New PointClass()
    pPoint(0).PutCoords 131.328125, 33.9583333333333
    pPoint(1).PutCoords 131.34375, 33.9583333333333
    pPoint(2).PutCoords 131.34375, 33.9479166666667
    pPoint(3).PutCoords 131.328125, 33.9479166666667
         
    Dim i As Integer
    For i = 0 To 3
        pTiePointCollection.AddPoint pPoint(i)
    Next i
     
     
    'ラスタのエクステント座標を取得
    Dim pRasterWorkspaceFactory As IWorkspaceFactory
    Set pRasterWorkspaceFactory = New RasterWorkspaceFactory
     
    Dim pRasterWorkspace As IRasterWorkspace
    Set pRasterWorkspace = pRasterWorkspaceFactory.OpenFromFile("E:\Projects\Data", 0)
     
    Dim pRasterDataset As IRasterDataset2
    Set pRasterDataset = pRasterWorkspace.OpenRasterDataset("50317235.png")
     
    'ラスタデータセットからラスタの取得
    Dim pRaster As IRaster
'    Set pRaster = pRasterDataset.CreateDefaultRaster
    Set pRaster = pRasterDataset.CreateFullRaster       '変更箇所
 
    Dim pRasterProps As IRasterProps
    Set pRasterProps = pRaster
     
    Dim pRasterPointCollection As IPointCollection
    Set pRasterPointCollection = New MultipointClass()
     
    With pRasterProps.Extent
        pRasterPointCollection.AddPoint .UpperLeft
        pRasterPointCollection.AddPoint .UpperRight
        pRasterPointCollection.AddPoint .LowerRight
        pRasterPointCollection.AddPoint .LowerLeft
    End With
     
     
    'ジオリファレンス
    Dim pRasterGeometryProc As IRasterGeometryProc
    Set pRasterGeometryProc = New RasterGeometryProc
     
    pRasterGeometryProc.Warp pRasterPointCollection, _
        pTiePointCollection, esriGeoTransPolyOrder1, pRaster
     
    pRasterGeometryProc.Register pRaster
     
    'ラスタをレイヤに追加
    Dim pRasterLayer As IRasterLayer
    Set pRasterLayer = New RasterLayer
    pRasterLayer.Name = pRasterDataset.CompleteName
     
    pRasterLayer.CreateFromRaster pRaster
     
    Dim pMxDocument As IMxDocument
    Set pMxDocument = ThisDocument
     
    Dim pMap As IMap
    Set pMap = pMxDocument.FocusMap
     
    pMap.AddLayer pRasterLayer
     
    pMxDocument.ActiveView.Refresh
    pMxDocument.UpdateContents
     
End Sub
  • この記事を書いた人

羽田 康祐

伊達と酔狂のGISエンジニア。GIS上級技術者、Esri認定インストラクター、CompTIA CTT+ Classroom Trainer、潜水士、PADIダイブマスター、四アマ。WordPress は 2.1 からのユーザーで歴だけは長い。 代表著書『"地図リテラシー入門―地図の正しい読み方・描き方がわかる』 GIS を使った自己紹介はこちら。ESRIジャパン(株)所属、元青山学院大学非常勤講師を兼務。日本地図学会第31期常任委員。発言は個人の見解です。

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