YouTube | Facebook | X(Twitter) | RSS

タイル インターネット レイヤを指定範囲で TIFF 画像に変換

2016/9/1 (木)

Private Declare Sub Sleep Lib & "kernel32" (ByVal dwMilliseconds As Long)

Public Sub run()

    Dim i As Long
    Dim j As Long

    Dim pMxDocument As IMxDocument
    Set pMxDocument = ThisDocument

    Dim pEnvelope As IEnvelope
    Set pEnvelope = pMxDocument.ActiveView.Extent

    Dim pClone As IClone
    Set pClone = pEnvelope

    Dim pNewEnvelope As IEnvelope

    Dim Overlap As Double
    Overlap = 400 'オーバーラップ

    Dim pTransform2D As ITransform2D

    For i = 0 To 10
        For j = 0 To 20

            Set pNewEnvelope = pClone.Clone
            Set pTransform2D = pNewEnvelope

            Call pTransform2D.Move(pEnvelope.Width * j - Overlap * j, -pEnvelope.Height * i + Overlap * i)

            pMxDocument.ActiveView.Extent = pTransform2D
            pMxDocument.ActiveView.Refresh
            DoEvents
            'Call Sleep(30)

            'Call ExportTIFF

        Next j

    Next i

    MsgBox "終了"

End Sub

Public Sub ExportTIFF()

    Dim dt_path As String
    dt_path = "C:\Temp\Data\"

    Dim ExportFileName As String
    Dim i As Long
   ExportFileName = Dir(dt_path & "output" & i & ".tif")
    Do While ExportFileName <> ""
        i = i + 1
        ExportFileName = Dir(dt_path & "output" & i & ".tif")
    Loop

    ExportFileName = dt_path & "output" & i & ".tif"

    Dim ExportResolution As Integer
    ExportResolution = 300

    Dim DPI As Integer
    DPI = 96

    Dim pMxDocument As IMxDocument
    Set pMxDocument = ThisDocument

    Dim pActiveView As IActiveView
    Set pActiveView = pMxDocument.ActiveView

    Dim pOutputRasterSettings As IOutputRasterSettings
    Set pOutputRasterSettings = pActiveView.ScreenDisplay.DisplayTransformation
    pOutputRasterSettings.ResampleRatio = 1 'ラスタのピクセル比率を1に変更

    Dim pExport As IExport
    Set pExport = New ExportTIFF
    pExport.ExportFileName = ExportFileName     '保存場所
    pExport.Resolution = ExportResolution       '解像度

    Dim pExportTIFF As IExportTIFF
    Set pExportTIFF = pExport
    pExportTIFF.GeoTiff = True
    pExportTIFF.CompressionType = esriTIFFCompressionLZW

    Dim pWorldFileSettings As IWorldFileSettings
    Set pWorldFileSettings = pExport
    pWorldFileSettings.OutputWorldFile = True 
    pWorldFileSettings.MapExtent = pActiveView.Extent

    '出力地図範囲
    Dim pVisibleBounds As IEnvelope
    Set pVisibleBounds = pActiveView.Extent

    '出力ラスタ ピクセル サイズ
    Dim pRECT As tagRECT
    pRECT = pActiveView.ExportFrame
    pRECT.Left = 0
    pRECT.Top = 0
    pRECT.Right = pRECT.Right * pExport.Resolution / DPI
    pRECT.bottom = pRECT.bottom * pExport.Resolution / DPI

    Dim pPixelBounds As IEnvelope
    Set pPixelBounds = New Envelope
    pPixelBounds.PutCoords pRECT.Left, pRECT.Top, pRECT.Right, pRECT.bottom

    pExport.PixelBounds = pPixelBounds

    Dim hDc As OLE_HANDLE
    hDc = pExport.StartExporting

    pActiveView.Output hDc, pExport.Resolution, pRECT, pVisibleBounds, Nothing      '第2引数をあげると出力画像の線が細くなる

    pExport.FinishExporting
    pExport.Cleanup

    DoEvents

End Sub

関連記事

  • この記事を書いた人

羽田 康祐

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

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

WINGFIELD since1981をもっと見る

今すぐ購読し、続きを読んで、すべてのアーカイブにアクセスしましょう。

続きを読む