YouTube | Facebook | X(Twitter) | RSS

ファイルストリームへの保存・読込方法

2016/9/1 (木)

'ファイルストリームに保存する方法
Public Sub SaveObjectAsFile(PersistStream As IPersistStream, PathName As String)
    Dim pFileStream As IStream
    Set pFileStream = New FileStream
     
    Dim pFile As IFile
    Set pFile = pFileStream
     
    pFile.Open PathName, esriReadWrite
    PersistStream.Save pFileStream, 0
 
End Sub
 
Function Save(pGeometry As IGeometry, sFile As String)
    Set pGeometry = pFeature.Shape
    Dim pPolycurve As IPolycurve
    Set pPolycurve = pGeometry
    Dim pPersistStream As IPersistStream
    Set pPersistStream = pPolycurve
     
    Dim pFileStream As IStream
    Set pFileStream = New FileStream
    Dim pFile As IFile
    Set pFile = pFileStream
    pFile.Open sFile, esriReadWrite
    pPersistStream.Save pFileStream, 0
End Function
 
'ファイルストリームを読み込む方法
Function Load(sFile As String) As IGeometry
    Dim pFileStream As IStream
    Set pFileStream = New FileStream
    Dim pFile As IFile
    Set pFile = pFileStream
    pFile.Open sFile, esriReadOnly
     
    Dim pPolyline As IPolyline
    Set pPolyline = New Polyline
    Dim pPersistStream As IPersistStream
    Set pPersistStream = pPolyline
    pPersistStream.Load pFileStream
    Set Load = pPolyline
End Function
 
Public Sub LoadObjectFromFile(ByRef PersistStream As IPersistStream, PathName As String)
    'PersistStreamはファイルに保存したオブジェクトの型であらかじめインスタンスを作成しておく
 
    Dim pFileStream As IStream
    Set pFileStream = New FileStream
     
    Dim pFile As IFile
    Set pFile = pFileStream
    pFile.Open PathName, esriReadOnly
     
    PersistStream.Load pFileStream
     
End Sub
 
'-----------------------------------
'Streamの保存
Public Sub saveobj(v As IGeoTransformation)
    Dim pMemoryBlobStream As IMemoryBlobStream
    Set pMemoryBlobStream = New MemoryBlobStream
    Dim pObjectStream As IObjectStream
    Set pObjectStream = New ObjectStream
    Set pObjectStream.Stream = pMemoryBlobStream
     
    Dim pPersistStream As IPersistStream
    Set pPersistStream = v
     
    pPersistStream.Save pObjectStream, False
    pMemoryBlobStream.SaveToFile "D:\Workspace\Tokyo_To_JGD_2000_NTv2.GeoTransformation"
 
End Sub
 
'Streamの読み込み
Dim pObjectStream2 As IObjectStream
Set pObjectStream2 = New ObjectStream
 
Dim pMemoryBlobStream2 As IMemoryBlobStream
Set pMemoryBlobStream2 = New MemoryBlobStream
pMemoryBlobStream2.LoadFromFile "D:\Workspace\Tokyo_To_JGD_2000_NTv2.GeoTransformation"
 
Dim pMygeo As IGeoTransformation
Set pMygeo = New NTv2Transformation
 
Dim pPersistStream2 As IPersistStream
Set pPersistStream2 = pMygeo
 
Set pObjectStream2.Stream = pMemoryBlobStream2
pPersistStream2.Load pObjectStream2
  • この記事を書いた人

羽田 康祐

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

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