Program crashing because '#' is being added to argument somewhere

144 views Asked by At

I'm getting the error

Traceback (most recent call last):
    arcpy.Intersect_analysis([new_dir+'\\'+table1+'.shp', new_dir+'\\'+table2+'.shp'], out_path, "ALL", 1.5)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\analysis.py", line 289, in Intersect
    raise e
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Features: Dataset \\storage1\gis\temp\alpha.shp #;\\storage1\gistemp\beta.shp # does not exist or is not supported
Failed to execute (Intersect).

I can't figure out where the # is coming from. Here is the relevant code

host = sys.argv[1]
db = sys.argv[2]
schema1 = sys.argv[3]
schema2 = sys.argv[4]
username = sys.argv[5]
password = sys.argv[6]
table1 = sys.argv[7]
table2 = sys.argv[8]

out_path = r'\\storage1\gis\temp\intersected.shp'
new_dir = r'\\storage1\gis\temp\'


pgsql2shp = 'pgsql2shp -f %s\\table1e -h %s -p 5432 -P %s -u %s %s %s.%s' % (new_dir, host, password, username, db, schema1, table1)
subprocess.Popen(pgsql2shp, shell=True).wait()
pgsql2shp = 'pgsql2shp -f %s\\table2 -h %s -p 5432 -P %s -u %s %s %s.%s' % (new_dir, host, password, username, db, schema2, table2)
subprocess.Popen(pgsql2shp, shell=True).wait()
print('argument:'+ new_dir+'\\'+table1+'.shp'+' , '+ new_dir+'\\'+table2+'.shp')
arcpy.Intersect_analysis([new_dir+'\\'+table1+'.shp', new_dir+'\\'+table2+'.shp'], out_path, "ALL", 1.5)

arcpy.AddField_management(out_path, "intersect_area", "DOUBLE")

I know the code is rediculously messy but I intend to get it running first. Feel free to comment for more information.

1

There are 1 answers

2
Tom On BEST ANSWER

No pound sign is being added anywhere. That's simply an ESRI message flag.

It's telling you that there is no shapefile \storage1\gis\temp\alpha.shp. Note that it's not telling you that beta.shp is missing (though it may be as well).

The path is incorrect. You have an extra 'e' after table1 in the line:

pgsql2shp = 'pgsql2shp -f %s\\table1e -h %s -p 5432 -P %s -u %s %s %s.%s' % (new_dir, host, password, username, db, schema1, table1)

Then again, you're placing the text 'table1' in there anyway instead of the name of the table. Is that its name?

I'm guessing that you want to parameterize it as well:

pgsql2shp = 'pgsql2shp -f %s\\%s -h %s -p 5432 -P %s -u %s %s %s.%s' % (new_dir, table1, host, password, username, db, schema1, table1)

Peripherally, you can clean up the whole thing by assigning your shapefile names to variables:

host = sys.argv[1]
db = sys.argv[2]
schema1 = sys.argv[3]
schema2 = sys.argv[4]
username = sys.argv[5]
password = sys.argv[6]
table1 = sys.argv[7]
table2 = sys.argv[8]

out_path = r'\\storage1\gis\temp\intersected.shp'
new_dir = r'\\storage1\gis\temp'

shp1 = os.path.join(new_dir, '{}.shp'.format(table1))
shp2 = os.path.join(new_dir, '{}.shp'.format(table2))

pgsql2shp = 'pgsql2shp -f %s -h %s -p 5432 -P %s -u %s %s %s.%s' % (shp1, host, password, username, db, schema1, table1)
subprocess.Popen(pgsql2shp, shell=True).wait()
pgsql2shp = 'pgsql2shp -f %s -h %s -p 5432 -P %s -u %s %s %s.%s' % (shp2, host, password, username, db, schema2, table2)
subprocess.Popen(pgsql2shp, shell=True).wait()

print('arguments:', shp1, shp2)
arcpy.Intersect_analysis([shp1, shp2], out_path, "ALL", 1.5)

arcpy.AddField_management(out_path, "intersect_area", "DOUBLE")