YouTube | Facebook | X(Twitter) | RSS

TimeQueryFilter の使用方法

2016/9/1 (木)

Public Sub TimeQuery()
    Dim pMxDocument As IMxDocument
    Set pMxDocument = ThisDocument
     
    '[タイム スライダ] ウィンドウ
    Dim pMapTimeDisplay As IMapTimeDisplay
    Set pMapTimeDisplay = pMxDocument.FocusMap
     
    Dim pTimeReference As ITimeReference
    Set pTimeReference = pMapTimeDisplay.TimeReference  '[時間表示] → [タイム ゾーン]
         
    Dim pFeatureLayer As IFeatureLayer
    Set pFeatureLayer = pMxDocument.FocusMap.Layer(0)
     
    'Use time setting
    Dim pTimeData As ITimeData
    Set pTimeData = pFeatureLayer
    pTimeData.UseTime = True
         
    'Timeの作成
    Dim pStartTime As ITime
    Set pStartTime = New Time
    pStartTime.SetFromTimeString esriTimeStringFormat.esriTSFYearThruSecondWithSlash, "2000/09/01 12:00:00"  'Japanese date time style is "YYYY/MM/DD HH:MM:SS"
     
    Dim pEndTime As ITime
    Set pEndTime = New Time
    pEndTime.SetFromTimeString esriTimeStringFormat.esriTSFYearThruSecondWithSlash, "2000/09/30 12:00:00"
     
    'TimeExtentの作成
    Dim pTimeExtent As ITimeExtent
    Set pTimeExtent = New TimeExtent
    Set pTimeExtent.TimeReference = pTimeReference
    pTimeExtent.StartTime = pStartTime
    pTimeExtent.EndTime = pEndTime
'    pTimeExtent.SetExtent pStartTime, pEndTime
     
    'TimeQueryFilterの作成
    Dim pTimeQueryFilter As ITimeQueryFilter
    Set pTimeQueryFilter = New TimeQueryFilter
    Set pTimeQueryFilter.OutputTimeReference = pTimeReference
    pTimeQueryFilter.TimeRelation = esriTimeRelation.esriTimeRelationOverlaps
    Set pTimeQueryFilter.TimeValue = pTimeExtent
     
    'FeatureClassに対してはTimeQueryFilterが利用できないのでSQLで記載する
'    Dim pQueryFilter As IQueryFilter
'    Set pQueryFilter = New QueryFilter
'    pQueryFilter.WhereClause = "Date_Time > date '2000/09/01 12:00:00' AND Date_Time < date '2000/09/30 12:00:00'"
     
    'Search
    Dim pFeatureCursor As IFeatureCursor
    Set pFeatureCursor = pFeatureLayer.Search(pTimeQueryFilter, False)
     
    Dim pFeature As IFeature
    Set pFeature = pFeatureCursor.NextFeature
     
    Do Until pFeature Is Nothing
        'Output
        Debug.Print pFeature.OID, pFeature.Value(10)
     
        Set pFeature = pFeatureCursor.NextFeature
    Loop
 
End Sub
  • この記事を書いた人

羽田 康祐

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

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