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
system call string length limit
Derivation tree not rendering
He got a vote 80% that of Emmanuel Macron’s
University's motivation for having tenure-track positions
Can I visit the Trinity College (Cambridge) library and see some of their rare books
Can the DM override racial traits?
How did the audience guess the pentatonic scale in Bobby McFerrin's presentation?
Do working physicists consider Newtonian mechanics to be "falsified"?
Sort list of array linked objects by keys and values
Chern class of a vector bundle and the associated projective space bundle
Does the AirPods case need to be around while listening via an iOS Device?
RT6224D-based step down circuit yields 0V - why?
Is there a writing software that you can sort scenes like slides in PowerPoint?
Windows 10: How to Lock (not sleep) laptop on lid close?
How to prevent selfdestruct from another contract
Why can't wing-mounted spoilers be used to steepen approaches?
Can smartphones with the same camera sensor have different image quality?
Keeping a retro style to sci-fi spaceships?
Single author papers against my advisor's will?
Does Parliament need to approve the new Brexit delay to 31 October 2019?
Would an alien lifeform be able to achieve space travel if lacking in vision?
Is every episode of "Where are my Pants?" identical?
Separating matrix elements by lines
Are spiders unable to hurt humans, especially very small spiders?
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