Python code ERROR 000670

2174
14
Jump to solution
05-12-2014 04:17 AM
CezaryGorczynski
New Contributor
Hi,
I'm learning to write scripts and I have now some problem.

import arcpy

arcpy.env.workspace = "c:/wtyczka/"
arcpy.env.overwriteOutput = True
outWorkspace = "c:/wtyczka/"

#dane
Wybor_gminy = "'Wyszków'"
Warstwa_zabudowy = arcpy.GetParameterAsText(0)
Bufor_od_zabudowy = arcpy.GetParameterAsText(1)
Warstwa_sieci_drog = arcpy.GetParameterAsText(2)
Bufor_od_sieci_drog = arcpy.GetParameterAsText(3)
Warstwa_sieci_kolejowej = arcpy.GetParameterAsText(4)
Bufor_od_sieci_kolejowej = arcpy.GetParameterAsText(5)
Warstwa_inna = arcpy.GetParameterAsText(6)
Bufor_od_inna = arcpy.GetParameterAsText(7)
Warstwa_inna_1 = arcpy.GetParameterAsText(8)
Bufor_od_inna_1 = arcpy.GetParameterAsText(9)
gminy = "c:/wtyczka/gminy_92.shp"
gmina = "c:/wtyczka/gmina.shp"
selekcja = '"GMINA"'+ " = " + "'Wyszków'"
lista = []

# Local variables:
zabudowa_clip = Warstwa_zabudowy
zabudowa_clip_bufor = zabudowa_clip
drogi_clip = Warstwa_sieci_drog
drogi_clip_bufor = drogi_clip
kolej_clip = Warstwa_sieci_kolejowej
kolej_clip_bufor = kolej_clip
inna_clip = Warstwa_inna
inna_clip_bufor = inna_clip
inna1_clip = Warstwa_inna_1
inna1_clip_bufor = inna_clip

#selekcja
arcpy.Select_analysis(gminy, gmina, '"GMINA" = \'Wyszków\'')

# Process: Clip zabudowa
if arcpy.Exists(Warstwa_zabudowy):
arcpy.Clip_analysis(Warstwa_zabudowy, gmina, zabudowa_clip, "0") - line 41
else:
print "false"

When I'm trying run this stript in ArcMap is an ERROR 000670: output Output Feature Class is same as input Input Features
Failed to execute (Clip).
I don't know why because input and out put Features has other names.

Please help! 🙂
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JoshuaChisholm
Occasional Contributor III
Hello Cezary,

Both Warstwa_zabudowy and zabudowa_clip point to the same feature class.

Input feature class (Warstwa_zabudowy) and output feature class (zabudowa_clip) must be different.

View solution in original post

0 Kudos
14 Replies
JoshuaChisholm
Occasional Contributor III
Hello Cezary,

Both Warstwa_zabudowy and zabudowa_clip point to the same feature class.

Input feature class (Warstwa_zabudowy) and output feature class (zabudowa_clip) must be different.
0 Kudos
CezaryGorczynski
New Contributor
ok, but i don't want to create next shp.
what can i do?

I'm trying to create tools which will have optional input data (5xshp)
and if any of this data will be exists do clip by layer form arcpy.Select_analysis, later diferent bufor for each layer.
In the end I want to Merge all this layer after buffor

This is what I wrote to now:
import arcpy

arcpy.env.workspace = "c:/wtyczka/"
arcpy.env.overwriteOutput = True
outWorkspace = "c:/wtyczka/"

#dane
Wybor_gminy = "'Wyszków'"
Warstwa_zabudowy = arcpy.GetParameterAsText(0)
Bufor_od_zabudowy = arcpy.GetParameterAsText(1)
Warstwa_sieci_drog = arcpy.GetParameterAsText(2)
Bufor_od_sieci_drog = arcpy.GetParameterAsText(3)
Warstwa_sieci_kolejowej = arcpy.GetParameterAsText(4)
Bufor_od_sieci_kolejowej = arcpy.GetParameterAsText(5)
Warstwa_inna = arcpy.GetParameterAsText(6)
Bufor_od_inna = arcpy.GetParameterAsText(7)
Warstwa_inna_1 = arcpy.GetParameterAsText(8)
Bufor_od_inna_1 = arcpy.GetParameterAsText(9)
gminy = "c:/wtyczka/gminy_92.shp"
gmina = "c:/wtyczka/gmina.shp"
selekcja = " \"GMINA\" = 'Wyszków' "
lista = []

# Local variables:
zabudowa_clip = Warstwa_zabudowy
zabudowa_clip_bufor = zabudowa_clip
drogi_clip = Warstwa_sieci_drog
drogi_clip_bufor = drogi_clip
kolej_clip = Warstwa_sieci_kolejowej
kolej_clip_bufor = kolej_clip
inna_clip = Warstwa_inna
inna_clip_bufor = inna_clip
inna1_clip = Warstwa_inna_1
inna1_clip_bufor = inna_clip

#selekcja
arcpy.Select_analysis(gminy, gmina, selekcja)

# Process: Clip zabudowa
if arcpy.Exists(Warstwa_zabudowy):
arcpy.Clip_analysis(Warstwa_zabudowy, gmina, zabudowa_clip, "")
else:
print "false"

# Process: Buffer zabudowa
if arcpy.Exists(zabudowa_clip):
arcpy.Buffer_analysis(zabudowa_clip, zabudowa_clip_bufor, Bufor_od_zabudowy, "FULL", "ROUND", "ALL", "")
lista.append("zabudowa_clip_bufor")
else:
print "false"

# Process: Clip drogi
if arcpy.Exists(Warstwa_sieci_drog):
arcpy.Clip_analysis(Warstwa_sieci_drog, gmina, drogi_clip, "")
else:
print "false"

# Process: Buffer drogi
if arcpy.Exists(drogi_clip):
arcpy.Buffer_analysis(drogi_clip, drogi_clip_bufor, Bufor_od_drog, "FULL", "ROUND", "ALL", "")
lista.append("drogi_clip_bufor")
else:
print "false"

# Process: Clip kolej
if arcpy.Exists(Warstwa_sieci_kolejowej):
arcpy.Clip_analysis(Warstwa_sieci_kolejowej, gmina, kolej_clip, "")
else:
print "false"

# Process: Buffer kolej
if arcpy.Exists(kolej_clip):
arcpy.Buffer_analysis(kolej_clip, kolej_clip_bufor, Bufor_od_sieci_kolejowej, "FULL", "ROUND", "ALL", "")
lista.append("kolej_clip_bufor")
else:
print "false"

# Process: Clip inna
if arcpy.Exists(Warstwa_inna):
arcpy.Clip_analysis(Warstwa_inna, gmina, inna_clip, "")
else:
print "false"

# Process: Buffer inna
if arcpy.Exists(inna_clip):
arcpy.Buffer_analysis(inna_clip, inna_clip_bufor, Bufor_od_inna, "FULL", "ROUND", "ALL", "")
lista.append("inna1_clip_bufor")
else:
print "false"

# Process: Clip inna 1
if arcpy.Exists(Warstwa_inna_1):
arcpy.Clip_analysis(Warstwa_inna_1, gmina, inna1_clip, "")
else:
print "false"

# Process: Buffer inna 1
if arcpy.Exists(inna1_clip):
arcpy.Buffer_analysis(inna1_clip, inna1_clip_bufor, Bufor_od_inna_1, "FULL", "ROUND", "ALL", "")
lista.append("inna1_clip_bufor")
else:
    print "false"

print lista

I don't how to merg each element in list "lista"
0 Kudos
JoshuaChisholm
Occasional Contributor III
Firstly, take the quotes out of the lista.append lines. For example, change lista.append("zabudowa_clip_bufor") to lista.append(zabudowa_clip_bufor)

If you want to merge all the feature classes in lista, use the merge tool. Like this:
arcpy.Merge_management(lista,r"C:\Path\To\MergedOutput.shp")


If you want to remove some of the shapefiles that you used throughout the script, then use the Delete Features tool, like this:
arcpy.DeleteFeatures_management(zabudowa_clip)
arcpy.DeleteFeatures_management(zabudowa_clip_bufor)

Good luck!
0 Kudos
CezaryGorczynski
New Contributor
Hello,
thanks for help. It works 🙂

But now I have problem with SQL Expression, besause I want choose a region to analyze and select appropriate polygons.
[ATTACH=CONFIG]33770[/ATTACH]
The best will be if user will write only the name of region (which is in Field in gminy_92.shp) or choose from list in SQL Expression.
I want to everyone be able to use this tool.

Sorry for my English.

I wrote this:
Wybor_gminy = arcpy.GetParameterAsText(0)
Warstwa_zabudowy = arcpy.GetParameterAsText(1)
Bufor_od_zabudowy = arcpy.GetParameterAsText(2)
Warstwa_sieci_drog = arcpy.GetParameterAsText(3)
Bufor_od_sieci_drog = arcpy.GetParameterAsText(4)
Warstwa_sieci_kolejowej = arcpy.GetParameterAsText(5)
Bufor_od_sieci_kolejowej = arcpy.GetParameterAsText(6)
Warstwa_inna = arcpy.GetParameterAsText(7)
Bufor_od_inna = arcpy.GetParameterAsText(8)
Warstwa_inna_1 = arcpy.GetParameterAsText(9)
Bufor_od_inna_1 = arcpy.GetParameterAsText(10)
gminy = "c:/wtyczka/gminy_92.shp"
selekcja = "\"GMINA\""+ "=" + "'" + Wybor_gminy + "'"
gmina = "c:/wtyczka/gmina.shp"
lista = []

# Local variables:
zabudowa_clip = "c:/wtyczka/zabudowa_clip.shp"
zabudowa_clip_bufor = "c:/wtyczka/zabudowa_clip_bufor.shp"
drogi_clip = "c:/wtyczka/drogi_clip.shp"
drogi_clip_bufor = "c:/wtyczka/drogi_clip_bufor.shp"
kolej_clip = "c:/wtyczka/kolej_clip.shp"
kolej_clip_bufor = "c:/wtyczka/gminy_92.shp"
inna_clip = "c:/wtyczka/inna_clip.shp"
inna_clip_bufor = "c:/wtyczka/inna_clip_bufor.shp"
inna1_clip = "c:/wtyczka/inna1_clip.shp"
inna1_clip_bufor = "c:/wtyczka/inna1_clip_bufor.shp"

#selekcja
arcpy.Select_analysis(gminy, gmina, selekcja)


In ArcGis I typed for Wybor gminy Wyszków and when I run script I have "ERROR 000358: Invalid expression "GMINA"='Wyszków'"

How can I corect this error?
0 Kudos
JoshuaChisholm
Occasional Contributor III
"GMINA"='Wyszków' looks like a valid expression to me. I'd make sure that there is a field called GMINA in gminy (gminy_92.shp).

If you want the user to type in part of the SQL statement instead of building an SQL, then just set it up as a "String" (text) input parameter, and put that input into the SQL statement.
[INDENT]*Note: If you use this method, the user must enter the exact same string that exists in the attribute table. For example, if the user enters 'Wyszków ' or 'Wyszkow' your tool will not work properly. As far as I know, there is no easy way to set up a drop-down for all possible field values. It would involve making a custom form using the Tkinter module. I would highly recommend avoiding this if possible. [/INDENT]


If you want the user to build an SQL Statement (like the screenshot you attached), you should change the line selekcja = "\"GMINA\""+ "=" + "'" + Wybor_gminy + "'" to selekcja = Wybor_gminy. That might be why you're getting an error.
0 Kudos
CezaryGorczynski
New Contributor
Both methods are not working 😕

I'm sending you the whole script and the screens:
These are the settings for method with part of the SQL statement (file aaaaaaa.py)
[ATTACH=CONFIG]33798[/ATTACH]

These are the settings for build an SQL Statement (file bbbbbb.py)
[ATTACH=CONFIG]33799[/ATTACH]

In shp is field GMINA.
0 Kudos
JoshuaChisholm
Occasional Contributor III
Method "aaaaaaaaaa.py�??":

[INDENT]It looks like it should be working. What error are you getting? What line is the error occurring?[/INDENT]


Method "bbbbbbbbb.py�??":

[INDENT]Normally you can make the SQL Statement easier on the user by setting a source for the SQL (as done here). Unfortunately, this will not work for you because gminy is not an input from the user.

Also, selekcja = '"' + kolumna + '"'+ " = " + "'" + Wybor_gminy + "'" should be changed to selekcja = Wybor_gminy.[/INDENT]


I think method "aaaaaaaaaa.py�??" would be better in your case.
0 Kudos
CezaryGorczynski
New Contributor
hua17;388646 wrote:
Method "aaaaaaaaaa.py�??":


[INDENT]It looks like it should be working. What error are you getting? What line is the error occurring?[/INDENT]

This is the screen of error
[ATTACH=CONFIG]33832[/ATTACH]
0 Kudos
JoshuaChisholm
Occasional Contributor III
That seems really strange. It looks like a good SQL Expression to me.

Can you please try running that exact expression to the attribute table for c:/wtyczka/gminy_92.shp. Let me know if you get an error and if the expression actually selects records in the table.

If you are using a Geodatabase ('.gdb') you would need to use square brackets[] instead or double quotes"". Like this:
selekcja = '[GMINA] = ' + "'" + Wybor_gminy + "'"

This shouldn't be the issue since you are using a shapefile, but you could try it just in case.
0 Kudos