0

I'm having an issue with some code I'm trying to write. Here's the code and below that is the output.

    # -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# RecalcFiberFootages.py
# Created on: 2019-05-03 10:34:21.00000
#   (generated by ArcGIS/ModelBuilder)
# Description: 
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy
import datetime

print("Modules Imported")

# Local variables:
date = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
GDB_date = "GDB" + date + ".gdb"
DIR = "F:\\zanders_folder\\Tools\\FiberCable_Strand_Footage_Recalc\\"
GDB_JOIN = DIR + GDB_date

FIBERCABLE_Project = "\\FiberCable_Project"
CONDUIT_Project = "\\CONDUIT_Project"
SlackLoop_Summarized = "\\SlackLoop_Summarized"
ROUTE_Project__3_ = "\\ROUTE_Project"
FiberCable = "FiberCable"
Conduit = "Conduit"
Route = "Route"
Strand = "Strand"

gisDB_DBO_FIBERCABLE = "Database Connections\\Connection to gisDB(edits).sde\\gisDB.DBO.TelecomDataset\\gisDB.DBO.FIBERCABLE"
gisDB_DBO_STRAND = "Database Connections\\Connection to gisDB(edits).sde\\gisDB.DBO.TelecomDataset\\gisDB.DBO.STRAND"
gisDB_DBO_SLACKLOOP = "Database Connections\\Connection to gisDB(edits).sde\\gisDB.DBO.TelecomDataset\\gisDB.DBO.SLACKLOOP"
gisDB_DBO_ROUTE = "Database Connections\\Connection to gisDB(edits).sde\\gisDB.DBO.TelecomDataset\\gisDB.DBO.ROUTE"
gisDB_DBO_CONDUIT = "Database Connections\\Connection to gisDB(edits).sde\\gisDB.DBO.TelecomDataset\\gisDB.DBO.CONDUIT"

print("Variables Imported")

# Process: Create File GDB
arcpy.CreateFileGDB_management(DIR,GDB_date, "CURRENT")

print("File GDB created")

# Process: Project (2)
tempEnvironment0 = arcpy.env.workspace
arcpy.env.workspace = "F:\\zanders_folder\\Tools\\FiberCable_Strand_Footage_Recalc\\" + GDB_date + ".gdb"
print(arcpy.env.workspace)
arcpy.Project_management(gisDB_DBO_FIBERCABLE, GDB_JOIN + FIBERCABLE_Project, "PROJCS['NAD_1983_CORS96_StatePlane_California_III_FIPS_0403_Ft_US',GEOGCS['GCS_NAD_1983_CORS96',DATUM['D_NAD_1983_CORS96',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Lambert_Conformal_Conic'],PARAMETER['False_Easting',6561666.666666666],PARAMETER['False_Northing',1640416.666666667],PARAMETER['Central_Meridian',-120.5],PARAMETER['Standard_Parallel_1',37.06666666666667],PARAMETER['Standard_Parallel_2',38.43333333333333],PARAMETER['Latitude_Of_Origin',36.5],UNIT['Foot_US',0.3048006096012192]]", "WGS_1984_(ITRF00)_To_NAD_1983_CORS96", "PROJCS['WGS_1984_Web_Mercator_Auxiliary_Sphere',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Mercator_Auxiliary_Sphere'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',0.0],PARAMETER['Standard_Parallel_1',0.0],PARAMETER['Auxiliary_Sphere_Type',0.0],UNIT['Meter',1.0]]")
arcpy.env.workspace = tempEnvironment0

print("FiberCable Projected")

# Process: Calculate Field (3)
arcpy.CalculateField_management(GDB_JOIN + FIBERCABLE_Project, "CALCULATEDLENGTH", "!Shape_Length!", "PYTHON_9.3", "")

print("FiberCable shape_length applied to CALCULATEDLENGTH field")

# Process: Summary Statistics
arcpy.Statistics_analysis(gisDB_DBO_SLACKLOOP, GDB_JOIN + SlackLoop_Summarized, "LENGTH SUM", "SEGMENTIDFKEY")

print("Footage calculated per cable for total slack")

# Process: Join Field
arcpy.JoinField_management(GDB_JOIN + SlackLoop_Summarized, "SEGMENTIDFKEY", GDB_JOIN + FIBERCABLE_Project, "SEGMENTID", "CABLE_NAME;CABLE_CATEGORY;CALCULATEDLENGTH;Shape_Length;SEGMENTIDFKEY")

print("Summary Statistics joined to FiberCable_Project")

# Process: Add Field
arcpy.AddField_management(GDB_JOIN + SlackLoop_Summarized, "MEASUREDLENGTH", "DOUBLE", "38", "8", "", "", "NULLABLE", "NON_REQUIRED", "")

print("Field added to slack_loop_summarized called MEASURED LENGTH")

# Process: Calculate Field
arcpy.CalculateField_management(GDB_JOIN + SlackLoop_Summarized, "MEASUREDLENGTH", "[CALCULATEDLENGTH] + [SUM_LENGTH]", "VB", "")

print("Calculated MEASUREDLENGTH = CALCULATEDLENGTH + SUM_LENGTH")

# Process: Join Field (2)
arcpy.JoinField_management(GDB_JOIN + FIBERCABLE_Project, "SEGMENTID", GDB_JOIN + SlackLoop_Summarized, "SEGMENTIDFKEY", "")

print("Joining slack loop summarized table to fiber cable")

# Process: Calculate Field (4)
arcpy.CalculateField_management(GDB_JOIN + FIBERCABLE_Project, "MEASUREDLENGTH", "[MEASUREDLENGTH_1]", "VB", "")

print("Calculate joined slackloop summarized field to MEASUREDLENGTH")

# Process: Add Join
arcpy.AddJoin_management(FiberCable, "THREEGISID", GDB_JOIN + FIBERCABLE_Project, "THREEGISID", "KEEP_COMMON")

print("Joining FiberCable to the projected FiberCable")

# Process: Calculate Field (7)
arcpy.CalculateField_management(GDB_JOIN + FIBERCABLE_Project, "gisDB.DBO.FIBERCABLE.MEASUREDLENGTH", "[FIBERCABLE_Project.MEASUREDLENGTH]", "VB", "")

print("Calculate projected FiberCable MEASUREDLENGTH to database FiberCable MEASUREDLENGTH")

# Process: Calculate Field (8)
arcpy.CalculateField_management(GDB_JOIN + FIBERCABLE_Project, "gisDB.DBO.FIBERCABLE.CALCULATEDLENGTH", "[FIBERCABLE_Project.CALCULATEDLENGTH]", "VB", "")

print("Calculate projected FiberCable CALCULATEDLENGTH to database FiberCable CALCULATEDLENGTH")

# Process: Remove Join
arcpy.RemoveJoin_management(GDB_JOIN + FIBERCABLE_Project, "FIBERCABLE_Project")

print("Remove projected FiberCable join to db FiberCable")

# Process: Project (4)
tempEnvironment0 = arcpy.env.workspace
arcpy.env.workspace = "F:\\zanders_folder\\Tools\\FiberCable_Strand_Footage_Recalc\\" + GDB_date + ".gdb"
arcpy.Project_management(gisDB_DBO_CONDUIT, GDB_JOIN + CONDUIT_Project, "PROJCS['NAD_1983_CORS96_StatePlane_California_III_FIPS_0403_Ft_US',GEOGCS['GCS_NAD_1983_CORS96',DATUM['D_NAD_1983_CORS96',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Lambert_Conformal_Conic'],PARAMETER['False_Easting',6561666.666666666],PARAMETER['False_Northing',1640416.666666667],PARAMETER['Central_Meridian',-120.5],PARAMETER['Standard_Parallel_1',37.06666666666667],PARAMETER['Standard_Parallel_2',38.43333333333333],PARAMETER['Latitude_Of_Origin',36.5],UNIT['Foot_US',0.3048006096012192]]", "WGS_1984_(ITRF00)_To_NAD_1983_CORS96", "PROJCS['WGS_1984_Web_Mercator_Auxiliary_Sphere',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Mercator_Auxiliary_Sphere'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',0.0],PARAMETER['Standard_Parallel_1',0.0],PARAMETER['Auxiliary_Sphere_Type',0.0],UNIT['Meter',1.0]]")
arcpy.env.workspace = tempEnvironment0

print("Project Conduit")

# Process: Calculate Field (6)
arcpy.CalculateField_management(GDB_JOIN + CONDUIT_Project, "CALCULATEDLENGTH", "[Shape_length]", "VB", "")

print("Calculate projected conduit field shape_length to CALCULATEDLENGTH")

# Process: Add Join (2)
arcpy.AddJoin_management(Conduit, "THREEGISID", GDB_JOIN + CONDUIT_Project, "THREEGISID", "KEEP_COMMON")

print("Join db Conduit to projected conduit")

# Process: Calculate Field (10)
arcpy.CalculateField_management(GDB_JOIN + CONDUIT_Project, "gisDB.DBO.CONDUIT.CALCULATEDLENGTH", "[CONDUIT_Project.CALCULATEDLENGTH]", "VB", "")

print("Calculate projected Conduit CALCULATEDLENGTH to db Conduit CALCULATEDLENGTH")

# Process: Remove Join (2)
arcpy.RemoveJoin_management(GDB_JOIN + CONDUIT_Project, "")

print("Remove projected conduit to db conduit join")

# Process: Project (3)
tempEnvironment0 = arcpy.env.workspace
arcpy.env.workspace = "F:\\zanders_folder\\Tools\\FiberCable_Strand_Footage_Recalc\\" + GDB_date + ".gdb"
arcpy.Project_management(gisDB_DBO_ROUTE, GDB_JOIN + ROUTE_Project, "PROJCS['NAD_1983_CORS96_StatePlane_California_III_FIPS_0403_Ft_US',GEOGCS['GCS_NAD_1983_CORS96',DATUM['D_NAD_1983_CORS96',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Lambert_Conformal_Conic'],PARAMETER['False_Easting',6561666.666666666],PARAMETER['False_Northing',1640416.666666667],PARAMETER['Central_Meridian',-120.5],PARAMETER['Standard_Parallel_1',37.06666666666667],PARAMETER['Standard_Parallel_2',38.43333333333333],PARAMETER['Latitude_Of_Origin',36.5],UNIT['Foot_US',0.3048006096012192]]", "WGS_1984_(ITRF00)_To_NAD_1983_CORS96", "PROJCS['WGS_1984_Web_Mercator_Auxiliary_Sphere',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Mercator_Auxiliary_Sphere'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',0.0],PARAMETER['Standard_Parallel_1',0.0],PARAMETER['Auxiliary_Sphere_Type',0.0],UNIT['Meter',1.0]]")
arcpy.env.workspace = tempEnvironment0

print("Project Route")

# Process: Calculate Field (5)
arcpy.CalculateField_management(GDB_JOIN + ROUTE_Project, "CALCULATEDLENGTH", "[Shape_length]", "VB", "")

print("Calculate shapelength to Route CALCULATEDLENGTH")

# Process: Add Join (3)
arcpy.AddJoin_management(Route, "THREEGISID", GDB_JOIN + ROUTE_Project, "THREEGISID", "KEEP_COMMON")

print("Join Route project to db Route")

# Process: Calculate Field (9)
arcpy.CalculateField_management(GDB_JOIN + ROUTE_Project, "gisDB.DBO.ROUTE.CALCULATEDLENGTH", "[ROUTE_Project.CALCULATEDLENGTH]", "VB", "")

print("Calculate projected Route CALCULATEDLENGTH to db Route CALCULATEDLENGTH")

# Process: Remove Join (3)
arcpy.RemoveJoin_management(GDB_JOIN + ROUTE_Project, "ROUTE_Project")

print("Remove Route join")

# Process: Project
tempEnvironment0 = arcpy.env.workspace
arcpy.env.workspace = "F:\\zanders_folder\\Tools\\FiberCable_Strand_Footage_Recalc\\" + GDB_date + ".gdb"
arcpy.Project_management(gisDB_DBO_STRAND, GDB_JOIN + STRAND_Project, "PROJCS['NAD_1983_CORS96_StatePlane_California_III_FIPS_0403_Ft_US',GEOGCS['GCS_NAD_1983_CORS96',DATUM['D_NAD_1983_CORS96',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Lambert_Conformal_Conic'],PARAMETER['False_Easting',6561666.666666666],PARAMETER['False_Northing',1640416.666666667],PARAMETER['Central_Meridian',-120.5],PARAMETER['Standard_Parallel_1',37.06666666666667],PARAMETER['Standard_Parallel_2',38.43333333333333],PARAMETER['Latitude_Of_Origin',36.5],UNIT['Foot_US',0.3048006096012192]]", "WGS_1984_(ITRF00)_To_NAD_1983_CORS96", "PROJCS['WGS_1984_Web_Mercator_Auxiliary_Sphere',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Mercator_Auxiliary_Sphere'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',0.0],PARAMETER['Standard_Parallel_1',0.0],PARAMETER['Auxiliary_Sphere_Type',0.0],UNIT['Meter',1.0]]")
arcpy.env.workspace = tempEnvironment0

print("Project Strand")

# Process: Calculate Field (2)
arcpy.CalculateField_management(GDB_JOIN + STRAND_Project, "CALCULATEDLENGTH", "!Shape_Length!", "PYTHON_9.3", "")

print("Calculate Strand shape_length to CALCULATEDLENGTH")

# Process: Add Join (4)
arcpy.AddJoin_management(Strand, "THREEGISID", GDB_JOIN + STRAND_Project, "THREEGISID", "KEEP_COMMON")

print("Join projected Strand to db Strand")

# Process: Calculate Field (11)
arcpy.CalculateField_management(GDB_JOIN + STRAND_Project, "gisDB.DBO.STRAND.CALCULATEDLENGTH", "[STRAND_Project.CALCULATEDLENGTH]", "VB", "")

print("Calculate projected Strand CALCULATEDLENGTH to db Strand CALCULATEDLENGTH")

# Process: Remove Join (4)
arcpy.RemoveJoin_management(GDB_JOIN + STRAND_Project, "STRAND_Project")

print("Remove Strand join")

print("PROCESS COMPLETED!!")

OUTPUT:

Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>> 
Modules Imported
Variables Imported
File GDB created
F:\zanders_folder\Tools\FiberCable_Strand_Footage_Recalc\GDB2019-06-11-13-05-54.gdb.gdb
FiberCable Projected
FiberCable shape_length applied to CALCULATEDLENGTH field
Footage calculated per cable for total slack
Summary Statistics joined to FiberCable_Project
Field added to slack_loop_summarized called MEASURED LENGTH
Calculated MEASUREDLENGTH = CALCULATEDLENGTH + SUM_LENGTH
Joining slack loop summarized table to fiber cable
Calculate joined slackloop summarized field to MEASUREDLENGTH

Traceback (most recent call last):
  File "F:\zanders_folder\Tools\FiberCable_Strand_Footage_Recalc\RecalcFiberFootages.py", line 88, in <module>
    arcpy.AddJoin_management(gisDB_DBO_FIBERCABLE, "THREEGISID", GDB_JOIN + FIBERCABLE_Project, "THREEGISID", "KEEP_COMMON")
  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\management.py", line 5632, in AddJoin
    raise e
ExecuteError: Failed to execute. Parameters are not valid.
The value cannot be a feature class
ERROR 000840: The value is not a Raster Layer.
ERROR 000840: The value is not a Raster Catalog Layer.
ERROR 000840: The value is not a Mosaic Layer.
Failed to execute (AddJoin).

>>> 

Sorry in advance as I'm not 100% comfortable using Python. I am trying to fix some footages to some lines in our gdb using a model exported out of model builder to Python. The code starts by creating a unique gdb to todays date/time and starts re-projecting and joining data. I'm able to get all the way down to the first add join and it fails there with the above error. I was able to get this working in ModelBuilder however trying to apply the updated source, it's failing.

closed as off-topic by PolyGeo Jun 11 at 22:52

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

4

The error is in this line.

# Process: Add Join
arcpy.AddJoin_management(FiberCable, "THREEGISID", GDB_JOIN + FIBERCABLE_Project, "THREEGISID", "KEEP_COMMON")

FiberCable, which is a variable with string "FiberCable", appears to be a feature class in your workspace.

AddJoin requires a feature layer.

FiberCableLyr = arcpy.MakeFeatureLayer_management (FiberCable, "FiberCableLayer") [0]
arcpy.AddJoin_management(FiberCableLyr, "THREEGISID", GDB_JOIN + FIBERCABLE_Project, "THREEGISID", "KEEP_COMMON")
  • This worked! Just wanted to add that I had to set the env.workspace for it to work. Once that was set the tool ran smoothly! – Alex P Jul 2 at 16:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.