Convert the Featclass attribute table efficiently into a DataTable

Source: Internet
Author: User

Converting Ifeatureclass\ itable into a DataTable is highly efficient.

Method Oneitable traversing rows

1. Use the Ifeatureclass property query in a slower way, which can increase the speed by dozens of times times.

2. Avoid HRESULT 0x80040952 errors

        /// <summary>        ///Convert the Featclass attribute table efficiently into a DataTable
Gisrsman.cnblogs.com/// </summary> /// <param name= "Featcls" >the input feature class</param> /// <param name= "Pqueryfilter" >query, none null</param> /// <returns></returns> Public StaticDataTable featclass2datatable (Ifeatureclass featcls, Iqueryfilter pqueryfilter) {DataTable Pattdt =NULL; stringPfieldname; stringPfieldvalue; DataRow Pdatarow; if(Featcls! =NULL) { //Initializes a table structure based on the Ifeatureclass field structurePATTDT =inittablebyfeacls (FEATCLS); ITable pfeattable = Featcls as ITable; intPfieldcout =PFeatTable.Fields.FieldCount; ICursor Pcursor= Pfeattable.search (Pqueryfilter,false); IRow PRow = Pcursor.nextrow (); while(PRow! =NULL) {Pdatarow=Pattdt.newrow (); for(intj =0; J < Pfieldcout; J + +) {Pfieldvalue=Prow.get_value (j). ToString (); Pfieldname=PFeatTable.Fields.get_Field (j). Name; Pdatarow[pfieldname]=Pfieldvalue; } pAttDT.Rows.Add (Pdatarow); PRow=Pcursor.nextrow (); } } returnPattdt; }

Note: Do not use Ptable.getrow (i). Get_value (j) This way, prone to HRESULT 0x80040952 error

Method TwoIfeatureclass Traversal Properties

Traversal feature method query, low efficiency

Traversing feature methods
        /// <summary>        ///convert featclass attribute table to DataTable/// </summary>        /// <param name= "Featcls" ></param>        /// <param name= "Pqueryfilter" >query, none null</param>        /// <returns></returns>         Public StaticDataTable featclass2datatable (Ifeatureclass featcls, Iqueryfilter pqueryfilter) {DataTable Pattdt =NULL; IFeature pfeature=NULL; Ifeaturecursor Pfeatcur=NULL; stringPfieldname; stringPfieldvalue;            DataRow Pdatarow; if(Featcls! =NULL) {Pattdt=inittablebyfeacls (FEATCLS); Pfeatcur= Featcls.search (Pqueryfilter,false); if(Pfeatcur! =NULL) Pfeature =pfeatcur.nextfeature ();  while(Pfeature! =NULL) {Pdatarow=Pattdt.newrow (); Ifields Pfields=Pfeature.fields; intPnum =Pfields.fieldcount;  for(inti =0; i < Pnum; i++) {Pfieldname=Pfields.get_field (i).                        Name; Pfieldvalue=Pfeature.get_value (i).                        ToString (); Pdatarow[pfieldname]=Pfieldvalue;                    } pAttDT.Rows.Add (Pdatarow); Pfeature=pfeatcur.nextfeature (); }            }            returnPattdt; }

Method Three: Directly with the SDE user connection, query the corresponding table

Each feature class is essentially a table in the database, and you can query the table of the corresponding feature class directly with the SQL statement.

For example, a railway feature class is stored in Oracle.

HRESULT 0x80040952 Error
Objectid are not necessarily sequential, so reading data is not used for loops, while.
1. When traversing Featureclass: Cursor.nextfeature ()
The main reason is to use the For loop to traverse the feature set, but the For loop is traversed by Objectid as ID, and the Objectid of many feature sets are not sequentially continuous from 0-n, such as 0 1 2 5 6 7 8 ...
or use Cursor.nextfeature () so that you don't have the above problem

2. When traversing itable lines: Pcursor.nextrow ();


Reference:
ArcGIS engine efficiency exploration--adding and deleting features, reading and updating attributes
A study of Arcengine efficiency--reading of attributes
Arcengine Efficiency Exploration II--update of attributes

Convert the Featclass attribute table efficiently into a DataTable

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.