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

























  • 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
    Jan 7 at 14:27






  • 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
    Jan 7 at 14:38













  • exactly. I mean thousands of records. I updated. Thanks

    – Oz1988
    Jan 7 at 14:51











  • 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
    Jan 7 at 15:53
















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

























  • 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
    Jan 7 at 14:27






  • 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
    Jan 7 at 14:38













  • exactly. I mean thousands of records. I updated. Thanks

    – Oz1988
    Jan 7 at 14:51











  • 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
    Jan 7 at 15:53














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
















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















share|improve this question













share|improve this question




share|improve this question








edited Jan 7 at 14:57









BERA

15.3k52042




15.3k52042










asked Jan 7 at 14:22









Oz1988Oz1988

133




133













  • 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
    Jan 7 at 14:27






  • 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
    Jan 7 at 14:38













  • exactly. I mean thousands of records. I updated. Thanks

    – Oz1988
    Jan 7 at 14:51











  • 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
    Jan 7 at 15:53



















  • 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
    Jan 7 at 14:27






  • 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
    Jan 7 at 14:38













  • exactly. I mean thousands of records. I updated. Thanks

    – Oz1988
    Jan 7 at 14:51











  • 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
    Jan 7 at 15:53

















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
Jan 7 at 14:27





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
Jan 7 at 14:27




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
Jan 7 at 14:38







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
Jan 7 at 14:38















exactly. I mean thousands of records. I updated. Thanks

– Oz1988
Jan 7 at 14:51





exactly. I mean thousands of records. I updated. Thanks

– Oz1988
Jan 7 at 14:51













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
Jan 7 at 15:53





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
Jan 7 at 15:53










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
    Jan 9 at 12:36



















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
    Jan 7 at 14:47








  • 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
    Jan 7 at 14:52








  • 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
    Jan 7 at 14:56













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


}
});














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
    Jan 9 at 12:36
















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
    Jan 9 at 12:36














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 Jan 7 at 14:57









ChrisLChrisL

369312




369312













  • Great idea.. TNX :)

    – Oz1988
    Jan 9 at 12:36



















  • Great idea.. TNX :)

    – Oz1988
    Jan 9 at 12:36

















Great idea.. TNX :)

– Oz1988
Jan 9 at 12:36





Great idea.. TNX :)

– Oz1988
Jan 9 at 12:36













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
    Jan 7 at 14:47








  • 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
    Jan 7 at 14:52








  • 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
    Jan 7 at 14:56


















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
    Jan 7 at 14:47








  • 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
    Jan 7 at 14:52








  • 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
    Jan 7 at 14:56
















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 Jan 7 at 14:53

























answered Jan 7 at 14:40









BERABERA

15.3k52042




15.3k52042













  • 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
    Jan 7 at 14:47








  • 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
    Jan 7 at 14:52








  • 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
    Jan 7 at 14:56





















  • 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
    Jan 7 at 14:47








  • 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
    Jan 7 at 14:52








  • 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
    Jan 7 at 14:56



















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
Jan 7 at 14:47







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
Jan 7 at 14:47






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
Jan 7 at 14:52







@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
Jan 7 at 14:52






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
Jan 7 at 14:56







@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
Jan 7 at 14:56




















draft saved

draft discarded




















































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.




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

Aardman Animations

Are they similar matrix

“minimization” problem in Euclidean space related to orthonormal basis