Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

layer enable time arcpy

import arcpy, os

# Setup output location and overwrite status
arcpy.env.overwriteOutput = True
path = r"C:ProjectsTimeShips"
output_GDB = os.path.join(path, "Ships.gdb")

# Get time information from a layer in a layer file    
lyrFile = arcpy.mp.LayerFile(os.path.join(path, "ShipPositions.lyrx"))
lyr = lyrFile.listLayers()[0]
lyrTime = lyr.time

# Set the time for which you want to select features in the time-enabled layer
fromTimeSelection = datetime.datetime(1776, 1, 1)
toTimeSelection = datetime.datetime(1777, 1, 1)

# Get the start and end time of the time enabled layer and its time field
startTime = lyrTime.startTime
endTime = lyrTime.endTime
timeField = 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 (fromTimeSelection < startTime or toTimeSelection > endTime):
    print("The time specified for selecting features is not within the time extent of the layer")
else:
    # Formulate the time query
    timeQuery = f"{timeField} >= timestamp '{fromTimeSelection}' And 
                  {timeField} < timestamp '{toTimeSelection}'"
    # Process: Feature Class to Feature Class
    arcpy.FeatureClassToFeatureClass_conversion(lyr, output_GDB, "Ships_1776", timeQuery, "", "")

# Add the new layer to a map and enable time
p = arcpy.mp.ArcGISProject(os.path.join(path, "ships.aprx"))
lyt = p.listLayouts('Ships')[0]
mf = lyt.listElements('MAPFRAME_ELEMENT', 'NoTimeMF')[0]
m = mf.map
m.addDataFromPath(os.path.join(output_GDB, "Ships_1776"))
l = m.listLayers("Ships_1776")[0]
l.enableTime()
mt = mf.time
mt.isTimeEnabled = True

# Save a copy of the project
p.saveACopy(os.path.join(path, "ships2.aprx"))
Comment

PREVIOUS NEXT
Code Example
Python :: Python write value in next row of existing .text file 
Python :: regex_2/_regex.c:50:10: fatal error: Python.h: No such file or directory 
Python :: df.fillna(-999,inplace=True) 
Python :: start virtual environment python linux 
Python :: django admin create project 
Python :: python spliting string into list 
Python :: how to input n space separated integers in python 
Python :: SyntaxError: positional argument follows keyword argument 
Python :: remove decimal python 
Python :: odoo order by xml rpc 
Python :: python datetime move forward one day 
Python :: pip install opencv 
Python :: python fibonacci function 
Python :: django pagination class based views 
Python :: Filter Pandas rows by specific string elements 
Python :: time in regression expression python 
Python :: windows how to store filepath as variabley python 
Python :: how to click a div element in selenium python 
Python :: add option in python script 
Python :: replace characters in string python 
Python :: python if condition 
Python :: create a window using tkinter 
Python :: Group based sort pandas 
Python :: absolute url 
Python :: pandas write csv 
Python :: enumerate in range python 
Python :: python get third friday of the month 
Python :: python matrix 
Python :: matplotlib savefig cutting off graph 
Python :: why a Python Arithmetic Operators used 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =