LayerTime (arcpy.mapping)

サマリ

The LayerTime object provides access to time management operations for time-enabled layers.

説明

The LayerTime object provides information about how time is stored and configured in a time-enabled layer. The time properties on a layer can be set on the Time tab of the Layer Properties dialog box in ArcMap, ArcScene, or ArcGlobe.

Learn more about setting time properties on a layer

The time properties on a layer are read-only. The UpdateLayerTime function allows you to replace all layer properties available on the Time tab of the Layer Properties dialog box using a layer (.lyr) file or another layer in a map document that contains time information.

Time information, such as the time fields containing the time values associated with the features, start and end time of the data, and the time-step interval, and so on, can be used for not only gaining knowledge about the time properties on the time-enabled layer but also for performing further data management and analysis tasks over time. Example one below shows how you can get the time extent of your time-enabled layer using the startTime and endTime. Example two below shows how you can formulate a time query using the time field and select a set of features based on time and then save those features to a separate feature class. Also, you can use the time information to ensure that the time specified for selecting the features lies within the start and end time of the layer.

Furthermore, you can use several LayerTime properties together to loop through the data in your time-enabled layer based on time. Example three shows how you can step through your data based on time using the timeStepInterval property and generate surfaces from features valid at various time steps. Note that the timeStepInterval property returns a EsriTimeDelta object.

特性

プロパティ説明データ タイプ
daylightSavings
(読み取り専用)

Indicates whether the time values in the time field of the time-enabled layer were collected while observing Daylight Saving Time rules in the input time zone.

Boolean
displayDataCumulatively
(読み取り専用)

Indicates whether or not data in the time-enabled layer is displayed cumulatively in the display.

Boolean
endTime
(読み取り専用)

Gets the end date and time for a time-enabled layer.

DateTime
endTimeField
(読み取り専用)

The name of the field containing the end time values. End time field is used along with the start time field to store start and end time values for features that are valid for a certain duration.

String
isTimeEnabled
(読み取り専用)

Indicates whether or not time is enabled on the layer.

Boolean
startTime
(読み取り専用)

Gets the start date and time for a time-enabled layer.

DateTime
startTimeField
(読み取り専用)

The name of the field containing the time values. This field is used for features that are valid at a particular instant in time.

String
timeFormat
(読み取り専用)

The format in which the time values were stored in the input time field. The time format is important when formulating a time query.

String
timeOffset
(読み取り専用)

The time offset applied to the time values in your data. This value is a EsriTimeDelta object and is used to iterate over a period of time (for example, 2 days, 1 month, and so on).

EsriTimeDelta
timeStepInterval
(読み取り専用)

The time-step interval defines the granularity of the temporal data. The time-step interval can be thought of as how often the time values were recorded in your data. This value is a EsriTimeDelta object and is used to iterate over a period of time (for example, 2 days, 1 month, and so on).

EsriTimeDelta
timeZone
(読み取り専用)

The Time Zone set on the time-enabled layer.

String

コードのサンプル

LayerTime example 1

The following script tests if a layer file supports time and if time properties have been set. It then uses time information (start time and end time) to calculate the time extent of a time-enabled layer.

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 example 2

The following script creates a feature class from input features valid at a certain time, while ensuring that the selection time is within the time extent (start time and end time) of the time-enabled layer.

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 example 3

The following script uses the time information (start time, end time, time-step interval) to step through data in a time-enabled layer to generate raster surfaces from points that are valid at each time step and then stores these rasters in a mosaic dataset.

import arcpy, datetime
# Check out the ArcGIS Spatial Analyst エクステンション 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","#")
4/26/2014