# -*- 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.
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)
# -*- 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 arcpy.env.workspace = "Database Connections\\sars.sde\\" # Script arguments Selecting_Features = arcpy.GetParameterAsText(0) value = arcpy.GetParameterAsText(1) # Local variables: Input_Points = "sars.dbo.CITYTEST" #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)
# -*- 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 #arcpy.env.workspace = "Database Connections\\sars.sde\\" arcpy.env.workspace = "d:/ArcGISData/SARS/Python_10April2013/SARS.gdb" # Script arguments Selecting_Features = arcpy.GetParameterAsText(0) value = arcpy.GetParameterAsText(1) # Local variables: #Input_Points = "sars.dbo.CITYTEST" 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)
# Import arcpy module import os, sys, arcpy, traceback, arcgisscripting arcpy.env.workspace = "Database Connections\\sars.sde\\" #arcpy.env.workspace = "d:/ArcGISData/SARS/Python_10April2013/SARS.gdb" # Script arguments Selecting_Features = arcpy.GetParameterAsText(0) value = arcpy.GetParameterAsText(1) stewardship = arcpy.GetParameterAsText(2) # Local variables: #Input_Points = "sars.dbo.CITYTEST" 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 # Process: Calculate Field #arcpy.CalculateField_management(Input_Points_Layer, "City, '"' + value + '"', "PYTHON_9.3") 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)
>>> GetPolyFC = 'my user-defined value' >>> workspace = r'\\myServer\myGDB.sde' >>> theFullPath = workspace + r'\%s' %GetPolyFC >>> print '"' + theFullPath + '"' "\\myServer\myGDB.sde\my user-defined value" 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 #arcpy.env.workspace = "Database Connections\\sars.sde\\" arcpy.env.workspace = "Database Connections\\Connection to tfsgis-iisd01IWILSON.sde" # Script arguments Selecting_Features = arcpy.GetParameterAsText(0) value = arcpy.GetParameterAsText(1) stewardship = arcpy.GetParameterAsText(2) # Local variables: #Input_Points = "sars.dbo.CITYTEST" Input_Points = stewardship #Final_Output = value Input_Points_Layer = "SamplePoints_Layer" # Process: Make Feature Layer arcpy.MakeFeatureLayer_management("Database Connections\\Connection to tfsgis-iisd01IWILSON.sde\\%s" %Input_Points , Input_Points_Layer) # Process: Select Layer By Location arcpy.SelectLayerByLocation_management(Input_Points_Layer, "INTERSECT", Selecting_Features, "", "NEW_SELECTION") # Process: Calculate Field # Process: Calculate Field #arcpy.CalculateField_management(Input_Points_Layer, "City, '"' + value + '"', "PYTHON_9.3") 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)