Arcengine data deletion methods and Performance Comparison [reprinted]

Source: Internet
Author: User

Arcengine data deletion methods and Performance Comparison [reprinted]

Reprinted copyright: // By yl landgis@126.com 2008.7.8
From: http://blog.csdn.net/yanleigis/archive/2008/07/09/2627649.aspx

1. After ifeaturecursor cursor query, traverse and delete

2. Update the cursor to delete ifeaturecursor. deletefeature ()

3. Delete itable. deletesearchedrows

4. idataset. workspace. executesql

I. Code of several deletion Methods

1. Delete from query results

Private void delete1 (ifeatureclass pfeatureclass)
{
Iqueryfilter pqueryfilter = new queryfilterclass ();
Pqueryfilter. whereclause = "objectid <=" + deletenum;
Ifeaturecursor pfeaturecursor = pfeatureclass. Search (pqueryfilter, false); ifeature pfeature = pfeaturecursor. nextfeature ();
While (pfeature! = NULL)
{
Pfeature. Delete ();
Pfeature = pfeaturecursor. nextfeature ();
}
System. runtime. interopservices. Marshal. releasecomobject (pqueryfilter );
}

2. Delete update cursor
Private void delete2 (ifeatureclass pfeatureclass)
{
Iqueryfilter pqueryfilter = new queryfilterclass ();
Pqueryfilter. whereclause = "objectid <=" + deletenum;
Ifeaturecursor pfeaturecursor = pfeatureclass. Update (pqueryfilter, false );
Ifeature pfeature = pfeaturecursor. nextfeature ();
While (pfeature! = NULL)
{
Pfeaturecursor. deletefeature ();
Pfeature = pfeaturecursor. nextfeature ();
}
System. runtime. interopservices. Marshal. releasecomobject (pqueryfilter );
}

3. Use deletesearchedrows to delete
Private void delete4 (ifeatureclass pfeatureclass)
{
Iqueryfilter pqueryfilter = new queryfilterclass ();
Pqueryfilter. whereclause = "objectid <=" + deletenum;
Itable ptable = pfeatureclass as itable;
Ptable. deletesearchedrows (pqueryfilter );
System. runtime. interopservices. Marshal. releasecomobject (pqueryfilter );
}

4. Delete executesql
Private void delete4 (ifeatureclass pfeatureclass)
{
Idataset pdataset = pfeatureclass as idataset;
Pdataset. workspace. executesql ("delete from" + pfeatureclass. aliasname + "where objectid <=" + deletenum );
}

Ii. test performance and Comparison
1. Delete 2000 records under the same data Conditions

2. Test code

Ifeaturelayer pfeaturelayer = axmapcontrol1.map. get_layer (0) as ifeaturelayer;
Ifeatureclass pfeatureclass = pfeaturelayer. featureclass;
System. Diagnostics. Stopwatch mywatch = new system. Diagnostics. Stopwatch ();
Mywatch. Start ();
Delete1 (pfeatureclass)
// Delete2 (pfeatureclass );
// Delete3 (pfeatureclass );
// Delete4 (pfeatureclass );
// Delete5 (pfeatureclass );
Mywatch. Stop ();
MessageBox. Show ("deletion time:" + mywatch. elapsedmilliseconds. tostring () + "millisecond ");
3. Test Status
Test Method
First time (unit: MS)
First time (unit: MS)
1
5214 Ms
5735 Ms

2
299 Ms
290 Ms

3
59 Ms
28 Ms

4
26 Ms
26 Ms

Iii. Conclusion

1. Use executesql to delete the database as quickly as possible.

2. deletesearchedrows and executesql are batch deletion tasks with better performance.

3. the query results are deleted at the slowest speed. If you use this method, create your program and modify it immediately because you are wasting time.

4. Use deletesearchedrows or executesql to delete records with a small data volume smaller than 500000 records. Otherwise, use the update cursor (method 2) and add a progress bar. The interface is friendly.

Reprinted copyright: // By yl landgis@126.com 2008.7.8
From: http://blog.csdn.net/yanleigis/archive/2008/07/09/2627649.aspx

 

 

 

 

 

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: info-contact@alibabacloud.com 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.