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
- <summary>
- Delete all feature in a Featurelayer
- </summary>
- <param name= "PLayer" > Operating coating </param>
- <remarks> the method can be given to a queryfilter to delete the eligible features</remarks>
- Private void Deleteallfeatures (Ifeaturelayer pLayer, <code></code>iqueryfilter queryfilter)
- {
- ITable ptable = Player.featureclass as ITable;
- Ptable.deletesearchedrows (QueryFilter);
- }
3. Reading of properties
There are several ways to get the value of the property sheet:
Method One:
[CSharp]View Plaincopy
- ITable ptable = Player.featureclass as ITable;
- Clsfldvalue = Ptable.getrow (i). Get_value (Clsfldindex);
Method Two:
[CSharp]View Plaincopy
- Ifeaturecursor fcursor = PLayer.FeatureClass.Search (new Queryfilterclass (), false);
- IFeature feature = Fcursor.nextfeature ();
- if (feature = = null) return null;
- Clsfldvalue = Feature.get_value (Clsfldindex);
- 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
- Ifeaturelayer PLayer = Utilities.getlayerbyname ((string) Cmbreglayers.selecteditem, M_mapcontrol) as Ifeaturelayer;
- Ifeaturecursor fcursor = PLayer.FeatureClass.Search (new Queryfilterclass (), false);
- IFeature feature = Fcursor.nextfeature ();
- int t = environment.tickcount;
- object clsfldvalue=null;
- For (int i = 0; i < PLayer.FeatureClass.FeatureCount (null); i++)
- {
- Clsfldvalue = Feature.get_value (3);
- Feature = Fcursor.nextfeature ();
- }
- t = environment.tickcount-t;
- MessageBox.Show (T.tostring ());
- ITable ptable = Player.featureclass as ITable;
- t = Environment.tickcount;
- For (int i = 0; i < Ptable.rowcount (null); i++)
- Clsfldvalue = Ptable.getrow (i). Get_value (3);
- t = environment.tickcount-t;
- 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
- Find the position of the field that would be updated.
- int typefieldindex = Featureclass.findfield ("TYPE");
- Create a query filter defining which fields would be updated
- (the subfields) and how to constrain which rows is updated
- (the WHERE clause).
- Iqueryfilter queryfilter = new Queryfilterclass
- {
- subfields = "TYPE", Whereclause = "Lane_count = 4"
- };
- Create a comreleaser for buffer management.
- using (ComReleaser ComReleaser = new ComReleaser ())
- {
- //Create a feature buffer containing the values to be updated.
- Ifeaturebuffer Featurebuffer = Featureclass.createfeaturebuffer ();
- Featurebuffer.set_value (Typefieldindex, "Highway");
- Comreleaser.managelifetime (Featurebuffer);
- //Cast the class to ITable and perform the updates.
- ITable table = (ITable) featureclass;
- Irowbuffer Rowbuffer = (irowbuffer) featurebuffer;
- Table. Updatesearchedrows (QueryFilter, Rowbuffer);
- }
Second, update record by article
There are three methods available in this way, as follows:
(1)
[CSharp]View Plaincopy
- for (int i = 0; i < Ptable.rowcount (null); i++)
- {
- PRow = Ptable.getrow (i);
- Prow.set_value (2, i + 6);
- Prow.store ();
- }
(2)
[CSharp]View Plaincopy
- Ifeaturecursor fcursor = PLayer.FeatureClass.Search (new Queryfilterclass (), false);
- IFeature feature = Fcursor.nextfeature ();
- for (int i = 0; i < featurenum; i++)
- {
- Feature.set_value (2, I);
- Feature. Store ();
- Feature = Fcursor.nextfeature ();
- }
(3)
[CSharp]View Plaincopy
- ICursor pcursor =ptable.update (null, false);
- PRow = Pcursor.nextrow ();
- for (int i = 0; i < Ptable.rowcount (null); i++)
- {
- Prow.set_value (2, i + 6);
- Pcursor.updaterow (PRow);
- PRow = Pcursor.nextrow ();
- }
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