Select by attribute with field equal to element of vector in ArcPy? The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Formatting SQL expressions for ArcPy with ArcSDE for PostgreSQL feature class?ExecuteError: Failed to execute. Parameters are not valid. ERROR 000732: Layer Name or Table View: Dataset L does not existReferencing Selection in SQL query (where clause) with ArcPy?Invalid Expression ERROR 000358: Select by AttributeUsing variable in Arcpy select analysisIterate through features of a feature class and buffer them?Error 000358 with SelectLayerByAttribute_managmentCreate and populate field with name of feature (Select by Location) ArcPyWhy is SelectLayerByAttribute_management claiming “Column Does Not Exist”?arcpy SelectLayerByAttribute_management runs in the Python window in ArcGIS Pro, but fails to run from Spyder or PyCharm
Why can't wing-mounted spoilers be used to steepen approaches?
How to pronounce 1ターン?
Why can't devices on different VLANs, but on the same subnet, communicate?
Create an outline of font
Python - Fishing Simulator
how can a perfect fourth interval be considered either consonant or dissonant?
Can the DM override racial traits?
Empty set is subset of every set? If yes, why that...
Is above average number of years spent on PhD considered a red flag in future academia or industry positions?
Sort list of array linked objects by keys and values
Working through the single responsibility principle (SRP) in Python when calls are expensive
Is this wall load bearing? Blueprints and photos attached
The variadic template constructor of my class cannot modify my class members, why is that so?
Semisimplicity of the category of coherent sheaves?
The following signatures were invalid: EXPKEYSIG 1397BC53640DB551
Typeface like Times New Roman but with "tied" percent sign
"... to apply for a visa" or "... and applied for a visa"?
How can I protect witches in combat who wear limited clothing?
ELI5: Why do they say that Israel would have been the fourth country to land a spacecraft on the Moon and why do they call it low cost?
Can withdrawing asylum be illegal?
Can a 1st-level character have an ability score above 18?
Difference between "generating set" and free product?
Keeping a retro style to sci-fi spaceships?
Finding degree of a finite field extension
Select by attribute with field equal to element of vector in ArcPy?
The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Formatting SQL expressions for ArcPy with ArcSDE for PostgreSQL feature class?ExecuteError: Failed to execute. Parameters are not valid. ERROR 000732: Layer Name or Table View: Dataset L does not existReferencing Selection in SQL query (where clause) with ArcPy?Invalid Expression ERROR 000358: Select by AttributeUsing variable in Arcpy select analysisIterate through features of a feature class and buffer them?Error 000358 with SelectLayerByAttribute_managmentCreate and populate field with name of feature (Select by Location) ArcPyWhy is SelectLayerByAttribute_management claiming “Column Does Not Exist”?arcpy SelectLayerByAttribute_management runs in the Python window in ArcGIS Pro, but fails to run from Spyder or PyCharm
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am trying to select by an attribute with a condition that field equals to an element of a vector. I use a for loop but could not get the right expression for this condition. Here are my codes.
random37 = [30449, 46617, 17309]
pointlayer = "network_nodeSelected"
for random in random37:
randomname = "n" + str(random)
arcpy.MakeFeatureLayer_management(pointlayer,pointlayer)
arcpy.SelectLayerByAttribute_management(pointlayer,'NEW_SELECTION','"ARC_" = random')
arcpy.CopyFeatures_management(pointlayer, randomname)
print randomname
The error message is presented as follows.
Traceback (most recent call last):
File "", line 6, in
arcpy.SelectLayerByAttribute_management(pointlayer,'NEW_SELECTION','"ARC_" = point')
File "C:Program Files (x86)ArcGISDesktop10.6ArcPyarcpymanagement.py", line 7742, in SelectLayerByAttribute
raise e
ExecuteError: ERROR 000358: Invalid expression
Failed to execute (SelectLayerByAttribute).
As you can see, my problem is the expression '"ARC_" = random'. But I do not know how to get the right expression.
arcpy arcgis-10.0 select-by-attribute error-000358
add a comment |
I am trying to select by an attribute with a condition that field equals to an element of a vector. I use a for loop but could not get the right expression for this condition. Here are my codes.
random37 = [30449, 46617, 17309]
pointlayer = "network_nodeSelected"
for random in random37:
randomname = "n" + str(random)
arcpy.MakeFeatureLayer_management(pointlayer,pointlayer)
arcpy.SelectLayerByAttribute_management(pointlayer,'NEW_SELECTION','"ARC_" = random')
arcpy.CopyFeatures_management(pointlayer, randomname)
print randomname
The error message is presented as follows.
Traceback (most recent call last):
File "", line 6, in
arcpy.SelectLayerByAttribute_management(pointlayer,'NEW_SELECTION','"ARC_" = point')
File "C:Program Files (x86)ArcGISDesktop10.6ArcPyarcpymanagement.py", line 7742, in SelectLayerByAttribute
raise e
ExecuteError: ERROR 000358: Invalid expression
Failed to execute (SelectLayerByAttribute).
As you can see, my problem is the expression '"ARC_" = random'. But I do not know how to get the right expression.
arcpy arcgis-10.0 select-by-attribute error-000358
What happens when you run the code that you have presented? I suspect the error message will lead you to an answer in an existing Q&A here. Also, your three functions can be replaced by Select_analysis() for simpler code.
– PolyGeo♦
Apr 7 at 19:52
@PolyGeo, thanks for helping. I have added the error message. The error is the invalid expression and failed to execute SelectLayerByAttribute. Could you help me find the right expression? Really appreciate!
– Zhenyu
Apr 7 at 20:43
Click the tag button for ERROR 000358 to see how others have researched/solved this.
– PolyGeo♦
Apr 7 at 21:07
@PolyGeo thanks for your suggestions. I find a similar question and post my solution.
– Zhenyu
Apr 7 at 21:28
Which question did you find? This Q&A should almost certainly be a duplicate of that one.
– PolyGeo♦
Apr 7 at 21:56
add a comment |
I am trying to select by an attribute with a condition that field equals to an element of a vector. I use a for loop but could not get the right expression for this condition. Here are my codes.
random37 = [30449, 46617, 17309]
pointlayer = "network_nodeSelected"
for random in random37:
randomname = "n" + str(random)
arcpy.MakeFeatureLayer_management(pointlayer,pointlayer)
arcpy.SelectLayerByAttribute_management(pointlayer,'NEW_SELECTION','"ARC_" = random')
arcpy.CopyFeatures_management(pointlayer, randomname)
print randomname
The error message is presented as follows.
Traceback (most recent call last):
File "", line 6, in
arcpy.SelectLayerByAttribute_management(pointlayer,'NEW_SELECTION','"ARC_" = point')
File "C:Program Files (x86)ArcGISDesktop10.6ArcPyarcpymanagement.py", line 7742, in SelectLayerByAttribute
raise e
ExecuteError: ERROR 000358: Invalid expression
Failed to execute (SelectLayerByAttribute).
As you can see, my problem is the expression '"ARC_" = random'. But I do not know how to get the right expression.
arcpy arcgis-10.0 select-by-attribute error-000358
I am trying to select by an attribute with a condition that field equals to an element of a vector. I use a for loop but could not get the right expression for this condition. Here are my codes.
random37 = [30449, 46617, 17309]
pointlayer = "network_nodeSelected"
for random in random37:
randomname = "n" + str(random)
arcpy.MakeFeatureLayer_management(pointlayer,pointlayer)
arcpy.SelectLayerByAttribute_management(pointlayer,'NEW_SELECTION','"ARC_" = random')
arcpy.CopyFeatures_management(pointlayer, randomname)
print randomname
The error message is presented as follows.
Traceback (most recent call last):
File "", line 6, in
arcpy.SelectLayerByAttribute_management(pointlayer,'NEW_SELECTION','"ARC_" = point')
File "C:Program Files (x86)ArcGISDesktop10.6ArcPyarcpymanagement.py", line 7742, in SelectLayerByAttribute
raise e
ExecuteError: ERROR 000358: Invalid expression
Failed to execute (SelectLayerByAttribute).
As you can see, my problem is the expression '"ARC_" = random'. But I do not know how to get the right expression.
arcpy arcgis-10.0 select-by-attribute error-000358
arcpy arcgis-10.0 select-by-attribute error-000358
edited Apr 7 at 21:05
PolyGeo♦
53.9k1782246
53.9k1782246
asked Apr 7 at 18:45
ZhenyuZhenyu
234
234
What happens when you run the code that you have presented? I suspect the error message will lead you to an answer in an existing Q&A here. Also, your three functions can be replaced by Select_analysis() for simpler code.
– PolyGeo♦
Apr 7 at 19:52
@PolyGeo, thanks for helping. I have added the error message. The error is the invalid expression and failed to execute SelectLayerByAttribute. Could you help me find the right expression? Really appreciate!
– Zhenyu
Apr 7 at 20:43
Click the tag button for ERROR 000358 to see how others have researched/solved this.
– PolyGeo♦
Apr 7 at 21:07
@PolyGeo thanks for your suggestions. I find a similar question and post my solution.
– Zhenyu
Apr 7 at 21:28
Which question did you find? This Q&A should almost certainly be a duplicate of that one.
– PolyGeo♦
Apr 7 at 21:56
add a comment |
What happens when you run the code that you have presented? I suspect the error message will lead you to an answer in an existing Q&A here. Also, your three functions can be replaced by Select_analysis() for simpler code.
– PolyGeo♦
Apr 7 at 19:52
@PolyGeo, thanks for helping. I have added the error message. The error is the invalid expression and failed to execute SelectLayerByAttribute. Could you help me find the right expression? Really appreciate!
– Zhenyu
Apr 7 at 20:43
Click the tag button for ERROR 000358 to see how others have researched/solved this.
– PolyGeo♦
Apr 7 at 21:07
@PolyGeo thanks for your suggestions. I find a similar question and post my solution.
– Zhenyu
Apr 7 at 21:28
Which question did you find? This Q&A should almost certainly be a duplicate of that one.
– PolyGeo♦
Apr 7 at 21:56
What happens when you run the code that you have presented? I suspect the error message will lead you to an answer in an existing Q&A here. Also, your three functions can be replaced by Select_analysis() for simpler code.
– PolyGeo♦
Apr 7 at 19:52
What happens when you run the code that you have presented? I suspect the error message will lead you to an answer in an existing Q&A here. Also, your three functions can be replaced by Select_analysis() for simpler code.
– PolyGeo♦
Apr 7 at 19:52
@PolyGeo, thanks for helping. I have added the error message. The error is the invalid expression and failed to execute SelectLayerByAttribute. Could you help me find the right expression? Really appreciate!
– Zhenyu
Apr 7 at 20:43
@PolyGeo, thanks for helping. I have added the error message. The error is the invalid expression and failed to execute SelectLayerByAttribute. Could you help me find the right expression? Really appreciate!
– Zhenyu
Apr 7 at 20:43
Click the tag button for ERROR 000358 to see how others have researched/solved this.
– PolyGeo♦
Apr 7 at 21:07
Click the tag button for ERROR 000358 to see how others have researched/solved this.
– PolyGeo♦
Apr 7 at 21:07
@PolyGeo thanks for your suggestions. I find a similar question and post my solution.
– Zhenyu
Apr 7 at 21:28
@PolyGeo thanks for your suggestions. I find a similar question and post my solution.
– Zhenyu
Apr 7 at 21:28
Which question did you find? This Q&A should almost certainly be a duplicate of that one.
– PolyGeo♦
Apr 7 at 21:56
Which question did you find? This Q&A should almost certainly be a duplicate of that one.
– PolyGeo♦
Apr 7 at 21:56
add a comment |
1 Answer
1
active
oldest
votes
The problem is the sql expression. Here is the solution.
random37 = [30449,46617,17309]
pointlayer = "network_nodeSelected"
layer1 = "wqi_ConProshp"
for point in random37:
pointname = "n" + str(point)
fieldname = 'ARC_'
whereClause = """0 = 1""".format(arcpy.AddFieldDelimiters(pointlayer, fieldname),point)
arcpy.MakeFeatureLayer_management(pointlayer,pointlayer)
arcpy.SelectLayerByAttribute_management(pointlayer,'NEW_SELECTION',whereClause)
arcpy.CopyFeatures_management(pointlayer, pointname)
#select the location and then export it
print pointname
To be honest, I still can not understand how it works but it indeed solves my problem.
In your original post, the where clause literally had the word "random" in the string as opposed to the value of the variable calledrandom
. In this example, the stringformat()
method is inserting the actual value into the string
– mikewatt
Apr 9 at 22:50
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "79"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f318047%2fselect-by-attribute-with-field-equal-to-element-of-vector-in-arcpy%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The problem is the sql expression. Here is the solution.
random37 = [30449,46617,17309]
pointlayer = "network_nodeSelected"
layer1 = "wqi_ConProshp"
for point in random37:
pointname = "n" + str(point)
fieldname = 'ARC_'
whereClause = """0 = 1""".format(arcpy.AddFieldDelimiters(pointlayer, fieldname),point)
arcpy.MakeFeatureLayer_management(pointlayer,pointlayer)
arcpy.SelectLayerByAttribute_management(pointlayer,'NEW_SELECTION',whereClause)
arcpy.CopyFeatures_management(pointlayer, pointname)
#select the location and then export it
print pointname
To be honest, I still can not understand how it works but it indeed solves my problem.
In your original post, the where clause literally had the word "random" in the string as opposed to the value of the variable calledrandom
. In this example, the stringformat()
method is inserting the actual value into the string
– mikewatt
Apr 9 at 22:50
add a comment |
The problem is the sql expression. Here is the solution.
random37 = [30449,46617,17309]
pointlayer = "network_nodeSelected"
layer1 = "wqi_ConProshp"
for point in random37:
pointname = "n" + str(point)
fieldname = 'ARC_'
whereClause = """0 = 1""".format(arcpy.AddFieldDelimiters(pointlayer, fieldname),point)
arcpy.MakeFeatureLayer_management(pointlayer,pointlayer)
arcpy.SelectLayerByAttribute_management(pointlayer,'NEW_SELECTION',whereClause)
arcpy.CopyFeatures_management(pointlayer, pointname)
#select the location and then export it
print pointname
To be honest, I still can not understand how it works but it indeed solves my problem.
In your original post, the where clause literally had the word "random" in the string as opposed to the value of the variable calledrandom
. In this example, the stringformat()
method is inserting the actual value into the string
– mikewatt
Apr 9 at 22:50
add a comment |
The problem is the sql expression. Here is the solution.
random37 = [30449,46617,17309]
pointlayer = "network_nodeSelected"
layer1 = "wqi_ConProshp"
for point in random37:
pointname = "n" + str(point)
fieldname = 'ARC_'
whereClause = """0 = 1""".format(arcpy.AddFieldDelimiters(pointlayer, fieldname),point)
arcpy.MakeFeatureLayer_management(pointlayer,pointlayer)
arcpy.SelectLayerByAttribute_management(pointlayer,'NEW_SELECTION',whereClause)
arcpy.CopyFeatures_management(pointlayer, pointname)
#select the location and then export it
print pointname
To be honest, I still can not understand how it works but it indeed solves my problem.
The problem is the sql expression. Here is the solution.
random37 = [30449,46617,17309]
pointlayer = "network_nodeSelected"
layer1 = "wqi_ConProshp"
for point in random37:
pointname = "n" + str(point)
fieldname = 'ARC_'
whereClause = """0 = 1""".format(arcpy.AddFieldDelimiters(pointlayer, fieldname),point)
arcpy.MakeFeatureLayer_management(pointlayer,pointlayer)
arcpy.SelectLayerByAttribute_management(pointlayer,'NEW_SELECTION',whereClause)
arcpy.CopyFeatures_management(pointlayer, pointname)
#select the location and then export it
print pointname
To be honest, I still can not understand how it works but it indeed solves my problem.
edited Apr 9 at 21:53
PolyGeo♦
53.9k1782246
53.9k1782246
answered Apr 7 at 21:27
ZhenyuZhenyu
234
234
In your original post, the where clause literally had the word "random" in the string as opposed to the value of the variable calledrandom
. In this example, the stringformat()
method is inserting the actual value into the string
– mikewatt
Apr 9 at 22:50
add a comment |
In your original post, the where clause literally had the word "random" in the string as opposed to the value of the variable calledrandom
. In this example, the stringformat()
method is inserting the actual value into the string
– mikewatt
Apr 9 at 22:50
In your original post, the where clause literally had the word "random" in the string as opposed to the value of the variable called
random
. In this example, the string format()
method is inserting the actual value into the string– mikewatt
Apr 9 at 22:50
In your original post, the where clause literally had the word "random" in the string as opposed to the value of the variable called
random
. In this example, the string format()
method is inserting the actual value into the string– mikewatt
Apr 9 at 22:50
add a comment |
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f318047%2fselect-by-attribute-with-field-equal-to-element-of-vector-in-arcpy%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What happens when you run the code that you have presented? I suspect the error message will lead you to an answer in an existing Q&A here. Also, your three functions can be replaced by Select_analysis() for simpler code.
– PolyGeo♦
Apr 7 at 19:52
@PolyGeo, thanks for helping. I have added the error message. The error is the invalid expression and failed to execute SelectLayerByAttribute. Could you help me find the right expression? Really appreciate!
– Zhenyu
Apr 7 at 20:43
Click the tag button for ERROR 000358 to see how others have researched/solved this.
– PolyGeo♦
Apr 7 at 21:07
@PolyGeo thanks for your suggestions. I find a similar question and post my solution.
– Zhenyu
Apr 7 at 21:28
Which question did you find? This Q&A should almost certainly be a duplicate of that one.
– PolyGeo♦
Apr 7 at 21:56