# -*- coding: utf-8 -*- # --------------------------------------------------------------------------- # calcfeatures_script.py # Created on: 2013-09-30 15:22:46.00000 # (generated by ArcGIS/ModelBuilder) # Usage: calcfeatures_script <Selecting_Features> <value> # Description: # test # --------------------------------------------------------------------------- # Import arcpy module import os, sys, arcpy, traceback, arcgisscripting # Script arguments Selecting_Features = arcpy.GetParameterAsText(0) value = arcpy.GetParameterAsText(1) Stewardship = arcpy.GetParameterAsText(2) arcpy.AddMessage("TEST") arcpy.AddMessage(value) # Local variables: Input_Points = Stewardship #Final_Output = value Input_Points_Layer = "SamplePoints_Layer" # Process: Make Feature Layer arcpy.MakeFeatureLayer_management(Input_Points, Input_Points_Layer) # Process: Select Layer By Location arcpy.SelectLayerByLocation_management(Input_Points_Layer, "INTERSECT", Selecting_Features, "", "NEW_SELECTION") # Process: Calculate Field with arcpy.da.UpdateCursor(Input_Points_Layer, ("City")) as rows: # row comes back as a tuple in the order specified here, so Office is row[0], Forester is row[1] for row in rows: row[0] = value rows.updateRow(row)
Solved! Go to Solution.
OR MAYBE THIS, IF YOU LIKE IT BETTER: (either way, pathnames are assembled out of text passed in) >>> import os >>> os.path.join(workspace, GetPolyFC) '\\\\myServer\\myGDB.sde\\my user-defined value' >>>
import os, sys, arcpy, traceback, arcgisscripting
# DELETED WORKSPACE AND REFERENCE TO SDE FILES
# Script arguments
Selecting_Features = arcpy.GetParameterAsText(0)
value = arcpy.GetParameterAsText(1)
stewardship = arcpy.GetParameterAsText(2)
# DELETED MAKE FEATURE LAYER....
#Drag the layer from SDE you want into ArcMap. Its this layer:
#Connection to tfsgis-iisd01IWILSON.sde\sars.dbo.CITYTEST
#Name that layer in the TOC "CITYTEST"
#You'll have a variable in the script which references that layer, here:
myLayerToModify = "CITYTEST"
#When you run this script, in ArcMap, it will look for a layer called CITYTEST when you use the myLayerToModify variable. A name matching occurs.
#This variable "myLayerToModify" will be used in the script. You don't need MakeFeatureLayer.
# Process: Select Layer By Location
arcpy.SelectLayerByLocation_management(myLayerToModify, "INTERSECT", Selecting_Features, "", "NEW_SELECTION")
# Process: Calculate Field
#arcpy.CalculateField_management(myLayerToModify, "City, '"' + value + '"', "PYTHON_9.3")
with arcpy.da.UpdateCursor(myLayerToModify, ("City")) as rows:
# row comes back as a tuple in the order specified here, so Office is row[0], Forester is row[1]
for row in rows:
row[0] = value
rows.updateRow(row)
import os, sys, arcpy, traceback, arcgisscripting
arcpy.env.workspace = "Database Connections\\sars.sde\\"
Input_Points = "Stewardship"
Input_Polygons = "Polygon_Layer"
# Process: Make Feature Layer
arcpy.MakeFeatureLayer_management(Input_Polygons, Input_Polygon_Layer)
with arcpy.da.UpdateCursor(Input_Polygon_Layer, ("DateStart", "FFY")) as rows:
for row in rows:
Datestarstr1 = row[0]
Datestarstr2 = str(Datestarstr1)
yearonly = Datestarstr2[0:4]
row[1] = yearonly
rows.updateRow(row)
import os, sys, arcpy, traceback, arcgisscripting
Input_Polygons = "Stewardship"
with arcpy.da.UpdateCursor(Input_Polygons, ("DateStart", "FFY")) as rows:
for row in rows:
Datestarstr1 = row[0]
Datestarstr2 = str(Datestarstr1)
yearonly = Datestarstr2[0:4]
row[1] = yearonly
rows.updateRow(row)
Input_Polygons = "Stewardship" with arcpy.da.UpdateCursor(Input_Polygons, ("DateStart", "PlanID", "FFY")) as rows: for row in rows: if not (row[1] or "").strip(): #covers blank, one blank space, or Null Datestarstr1 = row[0] Datestarstr2 = str(Datestarstr1) yearonly = Datestarstr2[0:4] row[2] = yearonly rows.updateRow(row)