Closed MikeMillerGIS closed 7 years ago
def makeFeatureView(workspace,sourceFC,viewName,whereClause,xmlFields):
# make a feature view using the where clause
if arcpy.Exists(sourceFC):
if arcpy.Exists(viewName):
arcpy.Delete_management(viewName) # delete view if it exists
desc = arcpy.Describe(sourceFC)
fields = arcpy.ListFields(sourceFC)
fStr = getViewString(fields,xmlFields)
try:
if str(whereClause).strip() == '':
whereClause = '1=1'
addMessage('sourceFC:{}\n\nviewName:{}\n\nwhereClause: {}\n\nworkspace:{}\n\nfStr:{}\n\n'.format(sourceFC,viewName,whereClause,workspace,fStr))
arcpy.MakeFeatureLayer_management(sourceFC, viewName , whereClause, workspace, fStr)
except:
showTraceback()
addMessage("Error occured, where clause: " + whereClause)
#addMessage("Feature Layer " + viewName + " created for " + str(whereClause))
else:
addError(sourceFC + " does not exist, exiting")
if not arcpy.Exists(viewName):
exit(-1)
return(viewName)
I added a check for a blank where clause and defaulted that to a 1=1 to ensure it works. I think a blank string is not support, so we could use 1=1 or None
hmm, nope that the where clause. I think I see the issue. I am processing two or more sources in to a single target. The result is the same view name viewName:WATERDEVICE_ViewAppend
going to add a random name to this and see if it resolves it.
I see there is a delete, but that is just checking the name, so if the env.workspace does not make the workspace, it will not exist, joining the workspace and name should resolve this.
ok, think I tracked it down to specifying the workspace in the Make Feature Layer. Setting this to None does nothing negative.
I also added a random name generation to the views.
resolved
Error below. I think the issue is the where clause. Fix in following comment
Used .lyrx filePath as source Python Error messages: Traceback Info: File "C:\Users\mich3661\AppData\Local\ESRI\ArcGISPro\AssemblyCache{28142961-b645-420f-ba2a-72bcf8212558}\GPTools\arcpy\dla.py", line 230, in makeFeatureView arcpy.MakeFeatureLayer_management(sourceFC, viewName , whereClause, workspace, fStr) File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py", line 5726, in MakeFeatureLayer raise e File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py", line 5723, in MakeFeatureLayer retval = convertArcObjectToPythonObject(gp.MakeFeatureLayer_management(gp_fixargs((in_features, out_layer, where_clause, workspace, field_info), True))) File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing_base.py", line 506, in
return lambda args: val(*gp_fixargs(args, True))
Error occured, where clause: