ArcGIS for python arcpy (3)

Source: Internet
Author: User

The previous article describes how to add a data record.

This article describes how to edit and query


In arcpy 10.1, a new data access module arcpy. Da is added.

In the help section, the performance will be much faster than that of the original cursor.

However, I found a problem with arcpy. Da. updatecursor in my use. As of this article, I have not received a reply from ESRI staff.

The methods in the DA module are also different from the original method parameters.

For example, the comparison between arcpy. Da. searchcursor and arcpy. searchcursor is as follows:


First introduce the environment and set the database

Then query through the new DA Module

Here we can find that the "OID @" in the fields parameter is a token of the objectid field.

The entire fields is a string-type array.

In addition, the row can use the index when the value is set.

However, when the where condition is used, the actual field name is required.


Note: Remember to delete the variable after each use. If the where value is string, add "".


The following is a query using the original module.

We can find that the first original module cannot use the with syntax.

The optional parameter fields of the second original module is a string without a special token.

The third row does not have an index. You must use the getvalue method.


The following describes how to query using the original module:

Basically, there is little difference


It should be noted that I have not entered the edit. startedit method here, so no matter whether SDE is registered or not, it will be modified on the default version.

The update method is the same as the query method.

However, the arcpy. Da. updatecursor method cannot be updated no matter whether the editing mode is enabled or not.

Fortunately, you can use the original updatecursor

The new DA module has the following error:


At last, da. updatecursor can try the following code:

From arcpy import *

Ws = r 'database Connections \ connection to'
Edit = da. Editor (WS)

Edit. startediting (false, true)
Edit. startoperation ()

With da. updatecursor ("SDE. mutlpolygons", 'test') as cur:
For row in cur:
Row [0] = '1'
Cur. updaterow (ROW)

Edit. stopoperation ()
Edit. stopediting (true)


If version control is enabled, startoperation and stopoperation are required.

If the version is not enabled, you cannot try it out.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.