Select to view content in your preferred language

Error 000210 and 000354 when running Union analysis in a Python script.

3076
12
01-17-2020 08:31 AM
by Anonymous User
Not applicable

Hello everyone! I've come across an issue that has completely stumped our entire organization. I'm currently working through the issue with ESRI support (who also seems stumped) as well but wanted to see if the broader community had any experience with this issue as well.

We have a python script that compares two cities and extracts the differences and doctors them up a bit for project standards. Naturally, the first stage of the script is calls for a union. On the first set of cities that I wanted to compare, I got the following error: 


PS Microsoft.PowerShell.Core\FileSystem::\\havc.local\misc\GIS\Regional\Boundary and Annexation Survey (BAS)\2020 BAS> python BASupdate.py
If the city is two words, do not add a space.

Enter city:
Aiken


Input Folder: \\havc.local\misc\GIS\Regional\Boundary and Annexation Survey (BAS)\2020 BAS\Aiken
MXD Path: \\havc.local\misc\GIS\Regional\Boundary and Annexation Survey (BAS)\2020 BAS\Aiken\AikenBAS.mxd
env.workspace: \\havc.local\misc\GIS\Regional\Boundary and Annexation Survey (BAS)\2020 BAS\Aiken\Aiken_2020.gdb
Creating the change polygons...
Traceback (most recent call last):
File "BASupdate.py", line 56, in <module>
arcpy.Union_analysis([censusData, havcData], unionFC)
File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\analysis.py", line 628, in Union
raise e
arcgisscripting.ExecuteError: ERROR 000210: Cannot create output \\havc.local\misc\GIS\Regional\Boundary and Annexation Survey (BAS)\2020 BAS\Aiken\Aiken_2020.gdb\union.shp.shp
ERROR 000354: The name contains invalid characters
Failed to execute (Union).

PS Microsoft.PowerShell.Core\FileSystem::\\havc.local\misc\GIS\Regional\Boundary and Annexation Survey (BAS)\2020 BAS>

As you can see, it looks like it is trying to export a shapefile into a geodatabase, but that is not what the code is telling it to do at all. Here is the entire code snippet up until that point: 

import os
import sys
import arcpy
from arcpy import env
import shutil
import subprocess


# Folder location will need to be changed every year
# There are two instances of the year in the script. Use the search function to find them.
basFolder = '\\\\havc.local\\misc\\GIS\\Regional\\Boundary and Annexation Survey (BAS)\\2020 BAS\\'


print "If the city is two words, do not add a space.\n"


# user to input the city name for the script
userInput = raw_input('Enter city:\n')
inputFolder = os.path.join(basFolder, userInput)
basReturnDirectory = os.path.join(basFolder, userInput + '\\BASReturn')


# check if folder exists
if os.path.exists(inputFolder):

print "\n"
# print out the input folder as specified by the user
print "Input Folder: " + inputFolder

# create BASReturn folder for final deliverables
if not os.path.exists(basReturnDirectory):
os.makedirs(basReturnDirectory)

# set the environment to list the mxds
arcpy.env.workspace = inputFolder

for file in arcpy.ListFiles("*.mxd"):

mxd_path = os.path.join(inputFolder, file)
print "MXD Path: " + mxd_path

# reset the environment to the database
env.workspace = inputFolder + '\\' + userInput + '_2020.gdb'
print "env.workspace: " + env.workspace
# map variables
mxd = arcpy.mapping.MapDocument(mxd_path)
df = arcpy.mapping.ListDataFrames(mxd, "*")[0]
havcData = arcpy.mapping.ListLayers(mxd, "HavcData", df)
censusData = arcpy.mapping.ListLayers(mxd, "CensusData", df)
unionFC = "union"
union_m2s = "union_multisingle"

# create the change polygons
print "Creating the change polygons..."

arcpy.Union_analysis([censusData, havcData], unionFC)

It seems to not be recognizing the env.workspace as being a geodatabase for some reason. 

As if that wasn't strange enough, I decided to try the tool on a different city and it worked flawlessly. That city's polygon's came out of the same feature classes that the one that failed did as well. Does anyone have any suggestions on what may be causing this? If I can provide any more information, please let me know! Thanks so much!

0 Kudos
12 Replies
by Anonymous User
Not applicable

Hmmmm. Well, I attempted to use this format and it returned the same error (trying to export union.shp.shp). Here is how I formatted it: 

userInput = raw_input('Enter city:\n')

basFolder = '\\\\mgrc.local\\misc\\GIS\\Regional\\Boundary and Annexation Survey (BAS)\\2020 BAS\\'

inputFolder = r"{}\{}".format(basFolder, userInput)

env.workspace = r"{}\{}_2020.gdb".format(inputFolder,userInput)

So far the only thing that has worked is changing the name during the user input portion of the script.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

I suggest you don't build OS paths yourself but utilize the built-in Python functionality for this purpose: os.path.join — Common pathname manipulations — Python 3.8.1 documentation 

0 Kudos
by Anonymous User
Not applicable

I actually attempted this already. Unless I did something wrong (which is highly probable!) it did not work. I can't remember what the error returned was, but I think that the gist was that os.path.join  won't take a list. There were 3 parts to the file name that I needed to create. 

0 Kudos