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

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

LayerTime

  • 描述
  • 讨论
  • 属性
  • 代码示例

描述

LayerTime 对象可用于访问启用了时间属性的图层管理操作。

讨论

LayerTime 对象提供用于在时间图层中存储并配置时间的信息。可在 ArcMap、ArcScene 或 ArcGlobe 的图层属性 对话框的时间选项卡中设置时间属性。

了解有关设置图层时间属性的详细信息

图层上的时间属性为只读。可通过 UpdateLayerTime 函数使用图层 (.lyr) 文件或其他包含时间信息的地图文档中的图层替换图层属性 对话框中时间选项卡内的所有可用属性。

时间信息(诸如与要素相关联的时间值字段、数据的开始和结束时间字段,以及表示步长间隔等的时间字段),不仅可用于获取已启用时间的图层的时间属性信息,而且还能用于执行动态的数据管理和分析任务。下面的示例一说明了如何通过 startTime 和 endTime 获取时间图层的时间范围。下方示例二说明了如何使用时间字段格式化时间查询,选择一组基于时间的要素,并将这些要素保存在独立的要素类中。也可以使用时间信息确保所选要素的时间处于图层的开始时间与结束时间之间。

此外,也可以同时使用多个 LayerTime 属性在时间图层中进行数据循环。示例三说明了如何使用 timeStepInterval 属性浏览基于时间的数据,并根据不同时间步长的有效要素生成栅格表面。注意:timeStepInterval 属性返回 EsriTimeDelta 对象。

属性

属性说明数据类型
daylightSavings
(只读)

表示启用时间的图层中时间字段内的时间值在收集时是否遵循了输入时区的夏令时规则。

Boolean
displayDataCumulatively
(只读)

指示启用时间的图层中的数据是否以累积方式显示。

Boolean
endTime
(只读)

获取启用时间的图层的结束日期和时间。

DateTime
endTimeField
(只读)

含有结束时间值的字段的名称。结束时间字段随开始时间字段一同用于存储在某一特定期间有效的要素的开始和结束时间值。

String
isTimeEnabled
(只读)

指示在图层上是否启用时间。

Boolean
startTime
(只读)

获取启用时间的图层的开始日期和时间。

DateTime
startTimeField
(只读)

含有时间值的字段的名称。此字段用于在某一特定时刻有效的要素。

String
timeFormat
(只读)

输入时间字段中的时间值所使用的存储格式。格式化时间查询时,时间格式很重要。

String
timeOffset
(只读)

时间偏移应用于数据中的时间值。此值是 EsriTimeDelta 对象并用来迭代某时间段(例如,2 天、1 个月等)。

EsriTimeDelta
timeStepInterval
(只读)

时间步长间隔定义时态数据的间隔长度。可将时间步长间隔视为在数据中记录时间值的频率。此值是 EsriTimeDelta 对象并用来迭代某时间段(例如,2 天、1 个月等)。

EsriTimeDelta
timeZone
(只读)

在启用时间的图层上设置的时区。

String

代码示例

LayerTime 示例 1

以下脚本首先测试图层文件是否支持时间以及是否已设置时间属性。然后使用时间信息(开始时间和结束时间)计算已启用时间属性的图层的时间范围。

import arcpy, datetime
lyr = arcpy.mapping.Layer(r'C:\Project\Data\Time\TemperatureWithTime.lyr')
if lyr.supports("TIME"):
    lyrTime = lyr.time
    if lyr.time.isTimeEnabled:
        startTime = lyrTime.startTime
        endTime = lyrTime.endTime
        timeDelta = endTime - startTime
        print "Start Time: " + str(startTime)
        print "End Time: " + str(endTime)
        print "Time Extent: " + str(timeDelta)
    else:
        print "No time properties have been set on the layer"
else:
    print "Time is not supported on this layer"
LayerTime 示例 2

以下脚本将根据特定有效时间段的输入要素创建一个要素类,同时确保所选时间在时间图层的时间范围(开始时间和结束时间)之内。

import arcpy, datetime

output_GDB = r"C:\Project\Output\Output.gdb"
    
lyr = arcpy.mapping.Layer(r"C:\Project\Data\Time\TimeLayer.lyr")
lyrTime = lyr.time

# Set the time for which you want to select features in the time-enabled layer
timeSelection = datetime.datetime(2009, 9, 10, 12, 0)

# Get the start and end time of the time enabled layer
startTime = lyrTime.startTime
endTime = lyrTime.endTime

# Get the time field containing the time values associated with data in the time-enabled layer 
timeField = str(lyrTime.startTimeField)

# Check to see if the time for which you want to select features lies within the start and end time of the time enabled layer
if (timeSelection < startTime or timeSelection > endTime):
    print "The time specified for selecting features is not within the time extent of the layer"
else:
    # Formulate the time query
    timeQuery = "\"" + timeField + "\"" + "= date '" + str(timeSelection) + "'"
    # Process: Feature Class to Feature Class
    arcpy.FeatureClassToFeatureClass_conversion(lyr, output_GDB, "timeSubset", timeQuery, "", "")
LayerTime 示例 3

以下脚本使用时间信息(开始时间、结束时间和时间步长间隔)浏览时间图层中的数据,以便根据各时间步长的有效点要素生成栅格表面,栅格并保存在镶嵌数据集中。

import arcpy, datetime
# Check out the ArcGIS Spatial Analyst extension for using the IDW interpolation tool
arcpy.CheckOutExtension("spatial")

# Get the layer time properties
lyr = arcpy.mapping.Layer(r"C:\Project\Data\Time\TimeLayer.lyr")
lyrTime = lyr.time

# Calculate the number of iterations based on the time extent and timestep interval
startTime = lyrTime.startTime
endTime = lyrTime.endTime
timeExtent = endTime - startTime
timeStepInterval = lyrTime.timeStepInterval

iterations = timeExtent.days / timeStepInterval.interval

# Get the time field containing the time values associated
# with the data in the time-enabled layer
startTimeField = str(lyrTime.startTimeField)

# Specify the output mosaic dataset to which the interpolated rasters will be added 
outputMosaicDataset = r"C:\Project\Output\Output.gdb\outputMosaicDataset"

i = 0
while i <= iterations:
    # Formulate the time query and increment the time by the timeStepInterval
    currentTime = str(startTime + (i*timeStepInterval))
    timeQuery = "\"" + startTimeField + "\"" + " = date '" + currentTime + "'"

    # Create an in-memory feature layer containing points that are valid at each timestep
    tempFeatureLyr = "tempTimeLayer" + str(i)
    arcpy.MakeFeatureLayer_management(lyr, tempFeatureLyr, timeQuery)

    # Create an interpolated raster surface using the points valid at each timestep
    outRaster = r"C:\Project\Output\Output.gdb\raster" + str(i)
    print outRaster
    arcpy.gp.Idw_sa(tempFeatureLyr, "Temperature", outRaster)

    # Add the newly created raster surface to a Mosaic Dataset
    arcpy.AddRastersToMosaicDataset_management(outputMosaicDataset, "Raster Dataset", outRaster)

    i = i + 1
    
# Calculate the statistics on the output Mosaic Dataset for
# classifying your data after new rasters are added   
arcpy.CalculateStatistics_management(outputMosaicDataset,"1","1","#")

ArcGIS Desktop

  • 主页
  • 文档
  • 支持

ArcGIS

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

关于 Esri

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