ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • 帮助
  • Sign Out
ArcGIS Desktop

ArcGIS Online

专为贵组织打造的制图平台

ArcGIS Desktop

全面的专业性 GIS

ArcGIS Enterprise

面向企业的 GIS

ArcGIS Developers

用于构建位置感知应用程序的工具

ArcGIS Solutions

适用于行业的免费模板地图和应用程序

ArcGIS Marketplace

获取适用于组织的应用程序和数据

  • 文档
  • 支持
Esri
  • 登录
user
  • 我的个人资料
  • 登出

ArcMap

  • 主页
  • 入门
  • 地图
  • 分析
  • 管理数据
  • 工具
  • 扩展模块

DataFrameTime

  • 描述
  • 讨论
  • 属性
  • 方法概述
  • 方法
  • 代码示例

描述

DataFrameTime 对象可用于访问数据框中启用了时间属性的图层管理操作。

讨论

DataFrameTime 对象提供了两种基本情景下的若干功能:

  • 第一种情况适用于发布时已启用了时间图层的地图文档,其设置已通过时间滑块选项对话框建立,并随地图文档一同保存。此种情况下,可使用现有属性进行自动输出。下面的示例 1 和示例 2 即为第一种情况。
  • 第二种情况适用于发布时不含启用时间图层的地图文档,但后续通过脚本添加了该时间图层,因而需要设置时间滑块选项,以便自动得到所需输出。下方的示例 3 即为第二种情况。

timeStepInterval 使用 EsriTimeDelta 类。EsriTimeDelta 类是核心 python datetime.timedelta 的备选选项,针对无法由核心 python timedelta 对象处理的时间间隔使用内部 Esri 时间单位(如月、周等)timeStepInterval 可用于在日期与时间内进行循环。如果希望在一个循环中使用不同的时间间隔,则需创建新的 python timedelta 对象或 EsriTimeDelta 对象(请参阅示例 3)。注意:如果已修改并保存 timeWindowUnits,将会影响 timeStepInterval。

旧版本:

在 10.1 之前的版本,DataFrameTime 类中的 timeStepInterval 属性返回一个 datetime.timedelta 类型的 Python 对象。

要在导出数据框时向图像中嵌入时间戳,请使用时间文本。

ArcGIS 中包含大量关于时态的帮助文档。下面列出了与 DataFrameTime 对象中的方法和属性最为相关的部分内容:

  • 关于修改时间滑块属性
  • 根据数据源使用时间信息
  • 使用时间滑块窗口

属性

属性说明数据类型
currentTime
(可读写)

包含启用时间的图层的数据框的当前日期和时间。可以在 ArcMap 中的时间滑块选项对话框中找到相同属性。

DateTime
endTime
(可读写)

包含启用时间的图层的数据框的结束日期和时间。可以在 ArcMap 中的时间滑块选项对话框中找到相同属性。

DateTime
startTime
(可读写)

包含启用时间的图层的数据框的开始日期和时间。可以在 ArcMap 中的时间滑块选项对话框中找到相同属性。

DateTime
timeStepInterval
(只读)

返回已通过 ArcMap 中的时间滑块选项对话框设置的时间步长间隔。此值是 EsriTimeDelta 对象并用来迭代某时间段(例如,2 天、1 个月等)。

EsriTimeDelta
timeWindow
(可读写)

用于控制之前出现的启用时间的数据的单位数量以及包含当前时间的时间窗口。例如,如果 timeWindow 设置为 1,并且 timeWindowUnits 设置为周,则时间窗口将为 2 周。

Double
timeWindowUnits
(可读写)

与 TimeStepInterval 和 TimeWindow 属性配合使用的单位。有效单位为:

  • MILLISECONDS
  • SECONDS
  • MINUTES
  • HOURS
  • DAYS
  • WEEKS
  • MONTHS
  • YEARS
  • DECADES
  • CENTURIES
String

方法概述

方法说明
resetTimeExtent ()

将时间范围重新设置为数据框中所有已启用时间的图层的时间窗范围。

方法

resetTimeExtent ()

此函数的作用与在 ArcMap 中单击时间滑块选项 对话框上的最小时间和最大时间按钮的作用相同。

代码示例

DataFrameTime 示例 1

以下脚本使用现有地图文档中发布的时间设置(开始时间、结束时间和时间间隔),以导出一系列的图像。各输出图像均通过时间戳内的解析日期信息给定唯一名称。

import arcpy
import os

mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Traffic Analysis")[0]
df.time.currentTime = df.time.startTime

while df.time.currentTime <= df.time.endTime:
    # An example str(newTime) would be: "2008-12-29 02:19:59"
    # The following line splits the string at the space and takes the first 
    # item in the resulting string.  
    fileName = str(df.time.currentTime).split(" ")[0] + ".png"
    arcpy.mapping.ExportToPNG(mxd, os.path.join(r"C:\Project\Output", fileName), df)
    df.time.currentTime = df.time.currentTime + df.time.timeStepInterval
del mxd
DataFrameTime 示例 2

以下脚本与上述示例 1 相同,但是使用了修改的开始时间、结束时间和间隔,这与地图文档内已启用时间的数据框中所发布的现有设置不同。Python 日期时间模块用于创建时间和时间增量。也可以选用 EsriTimeDelta 类创建时间增量。

import arcpy
import datetime
import os

mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Traffic Analysis")[0]
df.time.currentTime = datetime.datetime(2008, 10, 1)
endTime = datetime.datetime(2008, 10, 31)
interval = datetime.timedelta(days=7)

while df.time.currentTime <= endTime:
    # An example str(newTime) would be: "2008-01-29 02:19:59"
    # The following line splits the string at the space and takes the first 
    # item in the resulting string.  
    fileName = str(df.time.currentTime).split(" ")[0] + ".png"
    arcpy.mapping.ExportToPNG(mxd, os.path.join(r"C:\Project\Output", fileName), df)
    df.time.currentTime = df.time.currentTime + interval
del mxd
DataFrameTime 示例 3

以下脚本表示向不具有时态功能的新数据框添加新的时间图层的情形,因此,并未在地图文档中设置时间滑块属性。此脚本将已启用时间的图层添加到使用 AddLayer 函数的数据框,然后设置与上述脚本类似的相应时间设置。在本示例中,时间间隔使用 EsriTimeDelta 类进行设置。另外,Python 日期时间模块可用于创建时间增量。

import arcpy
import datetime
import os

mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "New Data Frame")[0]
timeLayer = arcpy.mapping.Layer(r"C:\Project\Data\Accidents.lyr")
arcpy.mapping.AddLayer(df, timeLayer, "AUTO_ARRANGE")
df.time.resetTimeExtent()
df.time.timeWindowUnits = "DAYS"
df.time.timeWindow = 7
df.time.currentTime = datetime.datetime(2008, 10, 1)
endTime = datetime.datetime(2008, 10, 31)
interval = arcpy.time.EsriTimeDelta(1, 'weeks')

while df.time.currentTime <= endTime:
    # An example str(newTime) would be: "2008-01-29 02:19:59"
    # The following line splits the string at the space and takes the first
    # item in the resulting string.
    fileName = str(df.time.currentTime).split(" ")[0] + ".png"
    arcpy.mapping.ExportToPNG(mxd, os.path.join(r"C:\Project\Output", fileName))
    df.time.currentTime = df.time.currentTime + interval
del mxd, timeLayer

ArcGIS Desktop

  • 主页
  • 文档
  • 支持

ArcGIS

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS
  • ArcGIS Developer
  • ArcGIS Solutions
  • ArcGIS Marketplace

关于 Esri

  • 关于我们
  • 招贤纳士
  • Esri 博客
  • 用户大会
  • 开发者峰会
Esri
分享您的想法。
Copyright © 2021 Esri. | 隐私政策 | 法律声明