Update records with ArcPy update cursor? Geodatabase format












2














I try to update thousands of rows when all records get the same value.
My code has a loop that runs thousands of times.
Is it possible for the program to make the change to all the columns in one command and save run time ?



For example, php+mySQL can do this:



mysql_query("UPDATE all_records SET Xcenter = $val1, Ycenter = $val2 WHERE ID > 100");


This is my code:



    for row in rows:
row.setValue("Xcenter", val1)
row.setValue("Ycenter", val2)
rows.updateRow(row)









share|improve this question









New contributor




Oz1988 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Please Edit the question to specify the data storage format of the target (file geodatabase, RDBMS, shapefile,...) and provide a sample of your existing code.
    – Vince
    2 days ago






  • 1




    Please add more code, since that fragment is missing cursor creation. Note that there are no versions of ArcGIS which aren't retired for which non-DataAccess cursors are appropriate. setRow is not supported on DataAcess cursor rows, and DataAcess cursors are much faster than the old, deprecated cursors. You also have indent issues.
    – Vince
    2 days ago












  • exactly. I mean thousands of records. I updated. Thanks
    – Oz1988
    2 days ago










  • What's wrong with a for loop? In essence, it's exactly what's going one behind the scenes of any other method, except, with a da cursor, it should be more efficient than using an unnecessary intermediary like CalculateField.
    – Tom
    2 days ago
















2














I try to update thousands of rows when all records get the same value.
My code has a loop that runs thousands of times.
Is it possible for the program to make the change to all the columns in one command and save run time ?



For example, php+mySQL can do this:



mysql_query("UPDATE all_records SET Xcenter = $val1, Ycenter = $val2 WHERE ID > 100");


This is my code:



    for row in rows:
row.setValue("Xcenter", val1)
row.setValue("Ycenter", val2)
rows.updateRow(row)









share|improve this question









New contributor




Oz1988 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Please Edit the question to specify the data storage format of the target (file geodatabase, RDBMS, shapefile,...) and provide a sample of your existing code.
    – Vince
    2 days ago






  • 1




    Please add more code, since that fragment is missing cursor creation. Note that there are no versions of ArcGIS which aren't retired for which non-DataAccess cursors are appropriate. setRow is not supported on DataAcess cursor rows, and DataAcess cursors are much faster than the old, deprecated cursors. You also have indent issues.
    – Vince
    2 days ago












  • exactly. I mean thousands of records. I updated. Thanks
    – Oz1988
    2 days ago










  • What's wrong with a for loop? In essence, it's exactly what's going one behind the scenes of any other method, except, with a da cursor, it should be more efficient than using an unnecessary intermediary like CalculateField.
    – Tom
    2 days ago














2












2








2







I try to update thousands of rows when all records get the same value.
My code has a loop that runs thousands of times.
Is it possible for the program to make the change to all the columns in one command and save run time ?



For example, php+mySQL can do this:



mysql_query("UPDATE all_records SET Xcenter = $val1, Ycenter = $val2 WHERE ID > 100");


This is my code:



    for row in rows:
row.setValue("Xcenter", val1)
row.setValue("Ycenter", val2)
rows.updateRow(row)









share|improve this question









New contributor




Oz1988 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I try to update thousands of rows when all records get the same value.
My code has a loop that runs thousands of times.
Is it possible for the program to make the change to all the columns in one command and save run time ?



For example, php+mySQL can do this:



mysql_query("UPDATE all_records SET Xcenter = $val1, Ycenter = $val2 WHERE ID > 100");


This is my code:



    for row in rows:
row.setValue("Xcenter", val1)
row.setValue("Ycenter", val2)
rows.updateRow(row)






arcpy arcmap






share|improve this question









New contributor




Oz1988 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Oz1988 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago









BERA

14.9k52042




14.9k52042






New contributor




Oz1988 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









Oz1988Oz1988

133




133




New contributor




Oz1988 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Oz1988 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Oz1988 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Please Edit the question to specify the data storage format of the target (file geodatabase, RDBMS, shapefile,...) and provide a sample of your existing code.
    – Vince
    2 days ago






  • 1




    Please add more code, since that fragment is missing cursor creation. Note that there are no versions of ArcGIS which aren't retired for which non-DataAccess cursors are appropriate. setRow is not supported on DataAcess cursor rows, and DataAcess cursors are much faster than the old, deprecated cursors. You also have indent issues.
    – Vince
    2 days ago












  • exactly. I mean thousands of records. I updated. Thanks
    – Oz1988
    2 days ago










  • What's wrong with a for loop? In essence, it's exactly what's going one behind the scenes of any other method, except, with a da cursor, it should be more efficient than using an unnecessary intermediary like CalculateField.
    – Tom
    2 days ago


















  • Please Edit the question to specify the data storage format of the target (file geodatabase, RDBMS, shapefile,...) and provide a sample of your existing code.
    – Vince
    2 days ago






  • 1




    Please add more code, since that fragment is missing cursor creation. Note that there are no versions of ArcGIS which aren't retired for which non-DataAccess cursors are appropriate. setRow is not supported on DataAcess cursor rows, and DataAcess cursors are much faster than the old, deprecated cursors. You also have indent issues.
    – Vince
    2 days ago












  • exactly. I mean thousands of records. I updated. Thanks
    – Oz1988
    2 days ago










  • What's wrong with a for loop? In essence, it's exactly what's going one behind the scenes of any other method, except, with a da cursor, it should be more efficient than using an unnecessary intermediary like CalculateField.
    – Tom
    2 days ago
















Please Edit the question to specify the data storage format of the target (file geodatabase, RDBMS, shapefile,...) and provide a sample of your existing code.
– Vince
2 days ago




Please Edit the question to specify the data storage format of the target (file geodatabase, RDBMS, shapefile,...) and provide a sample of your existing code.
– Vince
2 days ago




1




1




Please add more code, since that fragment is missing cursor creation. Note that there are no versions of ArcGIS which aren't retired for which non-DataAccess cursors are appropriate. setRow is not supported on DataAcess cursor rows, and DataAcess cursors are much faster than the old, deprecated cursors. You also have indent issues.
– Vince
2 days ago






Please add more code, since that fragment is missing cursor creation. Note that there are no versions of ArcGIS which aren't retired for which non-DataAccess cursors are appropriate. setRow is not supported on DataAcess cursor rows, and DataAcess cursors are much faster than the old, deprecated cursors. You also have indent issues.
– Vince
2 days ago














exactly. I mean thousands of records. I updated. Thanks
– Oz1988
2 days ago




exactly. I mean thousands of records. I updated. Thanks
– Oz1988
2 days ago












What's wrong with a for loop? In essence, it's exactly what's going one behind the scenes of any other method, except, with a da cursor, it should be more efficient than using an unnecessary intermediary like CalculateField.
– Tom
2 days ago




What's wrong with a for loop? In essence, it's exactly what's going one behind the scenes of any other method, except, with a da cursor, it should be more efficient than using an unnecessary intermediary like CalculateField.
– Tom
2 days ago










2 Answers
2






active

oldest

votes


















2














I have a weird feeling that you are looking for arcpy.CalculateField_management It is simple and quick calculate field help






share|improve this answer





















  • Great idea.. TNX :)
    – Oz1988
    17 hours ago



















3














Try the da.UpdateCursor:



import arcpy
feature_class = r'C:data.gdbfeatures1'

val1 = 123
val2 = 456

sql = """{0} > 100""".format(arcpy.AddFieldDelimiters(feature_class, 'ID'))

fields_to_update = ['Xcenter','Ycenter']
with arcpy.da.UpdateCursor(feature_class, fields_to_update, sql) as cursor:
for row in cursor:
row = val1, val2
cursor.updateRow(row)





share|improve this answer























  • First of all thank you Also in your program there is a loop that runs thousands of times (as many records) I'm looking for something to do it at once. The values I put are identical to all records so I do not want to run thousands of times in a loop
    – Oz1988
    2 days ago








  • 1




    @Oz1988: The data access cursors (da.UpdateCursor etc.) are very fast so thousands of rows should not be a problem, it should finish in a few seconds. This is what they are designed to do. I know no other way.
    – BERA
    2 days ago








  • 2




    @Oz1988 If you had a large number of rows (tens to hundreds of millions), it would actually be much faster to set multiple values per row than to use the Field Calculator one column at a time. Your stated goal and intended methodology are incongruous.
    – Vince
    2 days ago













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
});


}
});






Oz1988 is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f307790%2fupdate-records-with-arcpy-update-cursor-geodatabase-format%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














I have a weird feeling that you are looking for arcpy.CalculateField_management It is simple and quick calculate field help






share|improve this answer





















  • Great idea.. TNX :)
    – Oz1988
    17 hours ago
















2














I have a weird feeling that you are looking for arcpy.CalculateField_management It is simple and quick calculate field help






share|improve this answer





















  • Great idea.. TNX :)
    – Oz1988
    17 hours ago














2












2








2






I have a weird feeling that you are looking for arcpy.CalculateField_management It is simple and quick calculate field help






share|improve this answer












I have a weird feeling that you are looking for arcpy.CalculateField_management It is simple and quick calculate field help







share|improve this answer












share|improve this answer



share|improve this answer










answered 2 days ago









ChrisLChrisL

369312




369312












  • Great idea.. TNX :)
    – Oz1988
    17 hours ago


















  • Great idea.. TNX :)
    – Oz1988
    17 hours ago
















Great idea.. TNX :)
– Oz1988
17 hours ago




Great idea.. TNX :)
– Oz1988
17 hours ago













3














Try the da.UpdateCursor:



import arcpy
feature_class = r'C:data.gdbfeatures1'

val1 = 123
val2 = 456

sql = """{0} > 100""".format(arcpy.AddFieldDelimiters(feature_class, 'ID'))

fields_to_update = ['Xcenter','Ycenter']
with arcpy.da.UpdateCursor(feature_class, fields_to_update, sql) as cursor:
for row in cursor:
row = val1, val2
cursor.updateRow(row)





share|improve this answer























  • First of all thank you Also in your program there is a loop that runs thousands of times (as many records) I'm looking for something to do it at once. The values I put are identical to all records so I do not want to run thousands of times in a loop
    – Oz1988
    2 days ago








  • 1




    @Oz1988: The data access cursors (da.UpdateCursor etc.) are very fast so thousands of rows should not be a problem, it should finish in a few seconds. This is what they are designed to do. I know no other way.
    – BERA
    2 days ago








  • 2




    @Oz1988 If you had a large number of rows (tens to hundreds of millions), it would actually be much faster to set multiple values per row than to use the Field Calculator one column at a time. Your stated goal and intended methodology are incongruous.
    – Vince
    2 days ago


















3














Try the da.UpdateCursor:



import arcpy
feature_class = r'C:data.gdbfeatures1'

val1 = 123
val2 = 456

sql = """{0} > 100""".format(arcpy.AddFieldDelimiters(feature_class, 'ID'))

fields_to_update = ['Xcenter','Ycenter']
with arcpy.da.UpdateCursor(feature_class, fields_to_update, sql) as cursor:
for row in cursor:
row = val1, val2
cursor.updateRow(row)





share|improve this answer























  • First of all thank you Also in your program there is a loop that runs thousands of times (as many records) I'm looking for something to do it at once. The values I put are identical to all records so I do not want to run thousands of times in a loop
    – Oz1988
    2 days ago








  • 1




    @Oz1988: The data access cursors (da.UpdateCursor etc.) are very fast so thousands of rows should not be a problem, it should finish in a few seconds. This is what they are designed to do. I know no other way.
    – BERA
    2 days ago








  • 2




    @Oz1988 If you had a large number of rows (tens to hundreds of millions), it would actually be much faster to set multiple values per row than to use the Field Calculator one column at a time. Your stated goal and intended methodology are incongruous.
    – Vince
    2 days ago
















3












3








3






Try the da.UpdateCursor:



import arcpy
feature_class = r'C:data.gdbfeatures1'

val1 = 123
val2 = 456

sql = """{0} > 100""".format(arcpy.AddFieldDelimiters(feature_class, 'ID'))

fields_to_update = ['Xcenter','Ycenter']
with arcpy.da.UpdateCursor(feature_class, fields_to_update, sql) as cursor:
for row in cursor:
row = val1, val2
cursor.updateRow(row)





share|improve this answer














Try the da.UpdateCursor:



import arcpy
feature_class = r'C:data.gdbfeatures1'

val1 = 123
val2 = 456

sql = """{0} > 100""".format(arcpy.AddFieldDelimiters(feature_class, 'ID'))

fields_to_update = ['Xcenter','Ycenter']
with arcpy.da.UpdateCursor(feature_class, fields_to_update, sql) as cursor:
for row in cursor:
row = val1, val2
cursor.updateRow(row)






share|improve this answer














share|improve this answer



share|improve this answer








edited 2 days ago

























answered 2 days ago









BERABERA

14.9k52042




14.9k52042












  • First of all thank you Also in your program there is a loop that runs thousands of times (as many records) I'm looking for something to do it at once. The values I put are identical to all records so I do not want to run thousands of times in a loop
    – Oz1988
    2 days ago








  • 1




    @Oz1988: The data access cursors (da.UpdateCursor etc.) are very fast so thousands of rows should not be a problem, it should finish in a few seconds. This is what they are designed to do. I know no other way.
    – BERA
    2 days ago








  • 2




    @Oz1988 If you had a large number of rows (tens to hundreds of millions), it would actually be much faster to set multiple values per row than to use the Field Calculator one column at a time. Your stated goal and intended methodology are incongruous.
    – Vince
    2 days ago




















  • First of all thank you Also in your program there is a loop that runs thousands of times (as many records) I'm looking for something to do it at once. The values I put are identical to all records so I do not want to run thousands of times in a loop
    – Oz1988
    2 days ago








  • 1




    @Oz1988: The data access cursors (da.UpdateCursor etc.) are very fast so thousands of rows should not be a problem, it should finish in a few seconds. This is what they are designed to do. I know no other way.
    – BERA
    2 days ago








  • 2




    @Oz1988 If you had a large number of rows (tens to hundreds of millions), it would actually be much faster to set multiple values per row than to use the Field Calculator one column at a time. Your stated goal and intended methodology are incongruous.
    – Vince
    2 days ago


















First of all thank you Also in your program there is a loop that runs thousands of times (as many records) I'm looking for something to do it at once. The values I put are identical to all records so I do not want to run thousands of times in a loop
– Oz1988
2 days ago






First of all thank you Also in your program there is a loop that runs thousands of times (as many records) I'm looking for something to do it at once. The values I put are identical to all records so I do not want to run thousands of times in a loop
– Oz1988
2 days ago






1




1




@Oz1988: The data access cursors (da.UpdateCursor etc.) are very fast so thousands of rows should not be a problem, it should finish in a few seconds. This is what they are designed to do. I know no other way.
– BERA
2 days ago






@Oz1988: The data access cursors (da.UpdateCursor etc.) are very fast so thousands of rows should not be a problem, it should finish in a few seconds. This is what they are designed to do. I know no other way.
– BERA
2 days ago






2




2




@Oz1988 If you had a large number of rows (tens to hundreds of millions), it would actually be much faster to set multiple values per row than to use the Field Calculator one column at a time. Your stated goal and intended methodology are incongruous.
– Vince
2 days ago






@Oz1988 If you had a large number of rows (tens to hundreds of millions), it would actually be much faster to set multiple values per row than to use the Field Calculator one column at a time. Your stated goal and intended methodology are incongruous.
– Vince
2 days ago












Oz1988 is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















Oz1988 is a new contributor. Be nice, and check out our Code of Conduct.













Oz1988 is a new contributor. Be nice, and check out our Code of Conduct.












Oz1988 is a new contributor. Be nice, and check out our Code of Conduct.
















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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f307790%2fupdate-records-with-arcpy-update-cursor-geodatabase-format%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Сан-Квентин

8-я гвардейская общевойсковая армия

Алькесар