ArcGIS engine efficiency exploration--adding and deleting features, reading and updating attributes

Source: Internet
Author: User
Tags bulk insert rowcount

ArcGIS Engine efficiency exploration--adding and deleting features, reading and updating attributes

From: http://blog.csdn.net/freewaywalker/article/details/23703863

Category: Arcnotes2014-04-14 20:56 1781 people read comments (0) favorite reports

1. Adding a feature

In ArcGIS engine, there are two main methods for adding features:

    • Using Ifeatureclass.createfeature followed by Ifeature.store
    • Using Ifeatureclass.createfeaturebuffer with an INSERT cursor

Bulk INSERT feature, if you use the Feature.store () method to insert features into the layer individually, it is much slower than using both the INSERT cursor and the feature buffer method.

Because the latter triggers fewer events and more complex behaviors (for example, no behavior caused by topological relationships).

2. Deletion of features

Delete feature, delete on the Ifeature.delete method can, here no longer repeat, only write a method of bulk deletion, for itable is for the database operation, so fast.

The best approach to take when deleting features depends on the factors, how many features is being deleted and whether T He data source is a local geodatabase or an ArcSDE geodatabase.

In the simplest case, a single feature, and already been retrieved can deleted by Callingifeature.delete. If bulk Features is being deleted and the geodatabase is a ArcSDE geodatabase, the most efficient approach requires the Use of a search cursor and the Ifeature.delete method.

On the other hand, if the geodatabase are a local geodatabase (a file or personal geodatabase), the most efficient method F Or bulk deletion is Theitable.deletesearchedrows method.

Example:

[CSharp]View Plaincopy
  1. <summary>
  2. Delete all feature in a Featurelayer
  3. </summary>
  4. <param name= "PLayer" > Operating coating </param>
  5. <remarks> the method can be given to a queryfilter to delete the eligible features</remarks>
  6. Private void Deleteallfeatures (Ifeaturelayer pLayer, <code></code>iqueryfilter queryfilter)
  7. {
  8. ITable ptable = Player.featureclass as ITable;
  9. Ptable.deletesearchedrows (QueryFilter);
  10. }

3. Reading of properties

There are several ways to get the value of the property sheet:

Method One:

[CSharp]View Plaincopy
    1. ITable ptable = Player.featureclass as ITable;
    2. Clsfldvalue = Ptable.getrow (i). Get_value (Clsfldindex);

Method Two:

[CSharp]View Plaincopy
    1. Ifeaturecursor fcursor = PLayer.FeatureClass.Search (new Queryfilterclass (), false);
    2. IFeature feature = Fcursor.nextfeature ();
    3. if (feature = = null) return null;
    4. Clsfldvalue = Feature.get_value (Clsfldindex);
    5. Feature = Fcursor.nextfeature ();

Using Environment.tickcount for code Execution Time test, the results found that the method reads the entire table time is 4984ms, and the method two read the same attribute to the time of only the MS, the execution efficiency of law two is Fayi 156 times times!!!

The complete test code is as follows:

[CSharp]View Plaincopy
  1. Ifeaturelayer PLayer = Utilities.getlayerbyname ((string) Cmbreglayers.selecteditem, M_mapcontrol) as   Ifeaturelayer;
  2. Ifeaturecursor fcursor = PLayer.FeatureClass.Search (new Queryfilterclass (), false);
  3. IFeature feature = Fcursor.nextfeature ();
  4. int t = environment.tickcount;
  5. object clsfldvalue=null;
  6. For (int i = 0; i < PLayer.FeatureClass.FeatureCount (null); i++)
  7. {
  8. Clsfldvalue = Feature.get_value (3);
  9. Feature = Fcursor.nextfeature ();
  10. }
  11. t = environment.tickcount-t;
  12. MessageBox.Show (T.tostring ());
  13. ITable ptable = Player.featureclass as ITable;
  14. t = Environment.tickcount;
  15. For (int i = 0; i < Ptable.rowcount (null); i++)
  16. Clsfldvalue = Ptable.getrow (i). Get_value (3);
  17. t = environment.tickcount-t;
  18. MessageBox.Show (T.tostring ());

4. Updates to Properties

First, when a batch of data is updated to a certain same attribute, the use of itable.updatesearchedrows is highly efficient.

Examples are as follows:

[CSharp]View Plaincopy
  1. Find the position of the field that would be updated.
  2. int typefieldindex = Featureclass.findfield ("TYPE");
  3. Create a query filter defining which fields would be updated
  4. (the subfields) and how to constrain which rows is updated
  5. (the WHERE clause).
  6. Iqueryfilter queryfilter = new Queryfilterclass
  7. {
  8. subfields = "TYPE", Whereclause = "Lane_count = 4"
  9. };
  10. Create a comreleaser for buffer management.
  11. using (ComReleaser ComReleaser = new ComReleaser ())
  12. {
  13. //Create a feature buffer containing the values to be updated.
  14. Ifeaturebuffer Featurebuffer = Featureclass.createfeaturebuffer ();
  15. Featurebuffer.set_value (Typefieldindex, "Highway");
  16. Comreleaser.managelifetime (Featurebuffer);
  17. //Cast the class to ITable and perform the updates.
  18. ITable table = (ITable) featureclass;
  19. Irowbuffer Rowbuffer = (irowbuffer) featurebuffer;
  20. Table. Updatesearchedrows (QueryFilter, Rowbuffer);
  21. }

Second, update record by article

There are three methods available in this way, as follows:

(1)

[CSharp]View Plaincopy
    1. for (int i = 0; i < Ptable.rowcount (null); i++)
    2. {
    3. PRow = Ptable.getrow (i);
    4. Prow.set_value (2, i + 6);
    5. Prow.store ();
    6. }

(2)

[CSharp]View Plaincopy
    1. Ifeaturecursor fcursor = PLayer.FeatureClass.Search (new Queryfilterclass (), false);
    2. IFeature feature = Fcursor.nextfeature ();
    3. for (int i = 0; i < featurenum; i++)
    4. {
    5. Feature.set_value (2, I);
    6. Feature. Store ();
    7. Feature = Fcursor.nextfeature ();
    8. }

(3)

[CSharp]View Plaincopy
    1. ICursor pcursor =ptable.update (null, false);
    2. PRow = Pcursor.nextrow ();
    3. for (int i = 0; i < Ptable.rowcount (null); i++)
    4. {
    5. Prow.set_value (2, i + 6);
    6. Pcursor.updaterow (PRow);
    7. PRow = Pcursor.nextrow ();
    8. }

The test data are 320 records, three methods of operation time are: Law (1) is 40297ms; Law (2) 34922ms is; Law (3) is 219ms.

Can be seen using Ifeature and IRow store method update speed is very slow, with icursor Updaterow method speed, respectively is the former two efficiency 184 times times, 159 times times!!

Reference:

Creating features http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//00010000049v000000

Updating Features http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000002rs000000

Several ways to insert and delete feature in Featureclass (vb.net) http://www.cnblogs.com/wall/archive/2008/12/05/1348646.html

A study of Arcengine efficiency--reading http://blog.csdn.net/lk103852503/article/details/6566652 of attributes

Arcengine Efficiency Exploration II--update of attributes http://blog.csdn.net/lk103852503/article/details/6570748

ArcGIS engine efficiency exploration--adding and deleting features, reading and updating attributes

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.