This example specializes in the process of using GP development based on Arcengine and the problems encountered. More GP ways to use: GP experience
Functional Requirements : Now the first data of the outside industry (for short, the draft. mdb) and the second data (for short, check. mdb) have duplicates. The second was based on the first, That is, if you draw the. mdb in the LCA layer has 365 elements, check when found errors, deleted 11 errors, and added 43, a total of 408, check. mdb is compared to the draw. mdb actually has 354 duplicates, and now you want to repeat the deletion, the MDB includes point, line, polygon three types of feature classes.
Software Implementation : The use of tools in ArcGIS can be implemented, using the spatial location of the query, find duplicates, and then delete it; because there are more feature layers in each MDB, you can use batch processing, which can be done quickly with Excel when you fill out parameters in batches. However, the MDB is more, the path is different, the layer is more, the operation is not more time-consuming.
Program Implementation :
1. First determine what tool to implement (first in ArcGIS): Use spatial location query to select Duplicate features, open editor, delete!
2. Design the interface, I write a function, all have to tidy up the interface, because I do not want it ugly to go out to see people. The use of DotNetBar here saves a considerable amount of time.
3. Because the database is directly operational, the first step is to traverse the feature layer in the data, the general practice is to take advantage of the GP listfeatureclasses method.
Gp. Setenvironmentvalue ("Workspace", Moredbpath.trim ()); Igpenumlist pgpenumlist = GP. Listfeatureclasses ("," "," "); string strfc = Pgpenumlist.next (); while (STRFC! =" ") { System.Windows.Forms.Application.DoEvents (); Console.WriteLine (STRFC); STRFC = Pgpenumlist.next ();}
Choose to traverse the database no problem!
4. Use Select by location
Selectlayerbylocation slbl = new Selectlayerbylocation (); Slbl.in_layer = moredb + "\ \" + Strfc; Slbl.select_features = Referdb + "\ \" + Strfc; Slbl.overlap_type = "Are_identical_to"; Gpclass.execute (SLBL); The custom Gpclass class is used here and can be used directly with the Gpexecute
Error 000368, go to the official website to help a check, unexpectedly no 368, this is why? But from the neighboring error message, which argument should be invalid!
Then go to the official website to see the search by spatial location help document. It says: The input must be a feature layer, and it cannot be a feature class. Feature layer? Feature class? I used to think of them as a meaning, so I looked for help, long knowledge.
As a result, Python's sample code uses Makefeaturelayer to create a feature layer.
Create a feature layer makefeaturelayer MFL = new Makefeaturelayer (); Mfl.in_features = moredb + "\ \" + Strfc; Mfl.out_layer = Strfc + @ "_lyr"; Gpclass.execute (MFL);//Select by location selectlayerbylocation slbl = new Selectlayerbylocation (); Slbl.in_layer = Strfc + @ "_lyr"; Slbl.select_features = Referdb + "\ \" + Strfc; Slbl.overlap_type = "Are_identical_to"; Gpclass.execute (SLBL);
The GP was successful, although it did not see the effect. Because Makefeaturelayer is a temporary layer, the program ends without it and needs to be directed out:
Copy feature Export
Copyfeatures CF = new Copyfeatures (); Cf.in_features = Strfc + @ "_lyr"; Cf.out_feature_class = resultdb + "\ \" + Strfc; Gpclass.execute (CF);
The question now is whether the selection type is are_identical_to, and if the features in the input layer are the same as a selected feature (in terms of geometry), those features are selected. The resulting MDB is the part that repeats that part, and the desired result is the one that is not duplicated. You can do this in ArcGIS by toggling the selection. So I thought, you can select it all first and then remove the duplicate. Code:
Create a feature layer makefeaturelayer MFL = new Makefeaturelayer (); Mfl.in_features = moredb + "\ \" + Strfc; Mfl.out_layer = Strfc + @ "_lyr"; Gpclass.execute (MFL);//Select all Selectlayerbyattribute Slba = new Selectlayerbyattribute (); Slba.in_layer_or_view = Strfc + @ "_lyr"; Gpclass.execute (Slba);//Select by location (remove) selectlayerbylocation SLBL = new Selectlayerbylocation (); Slbl.in_layer = Strfc + @ "_lyr"; Slbl.select_features = Referdb + "\ \" + Strfc; Slbl.overlap_type = "Are_identical_to"; Slbl.selection_type = "Remove_from_selection"; Gpclass.execute (SLBL);//Copy features Copyfeatures CF = new Copyfeatures (); Cf.in_features = Strfc + @ "_lyr"; Cf.out_feature_class = resultdb + "\ \" + Strfc; Gpclass.execute (CF);
Finally came true.
5. In order to increase the user experience, rewrite in a class and create a new thread to handle:
String referdb = ""; string moredb = ""; string resultdb = ""; Progressbarx progress = Null;public Norepeatclass (string _referdb, String _moredb, String _resultdb, Progressbarx _progre SS) { Referdb = _referdb; Moredb = _moredb; Resultdb = _resultdb; progress = _progress; Thread mythreadone = new Thread (new ThreadStart (Mainfun)); Mythreadone.name = "Norepeat"; Mythreadone.isbackground = true; Mythreadone.start ();} private void Mainfun () {//Main program code}
6. To let the user know the progress of the process, a progress bar is added and the content is updated with the name of the current processing layer. But here, you can't set the control property of the main thread directly in one of the threads, so we find a function:
#region Setting Control parameters///<summary>///Setting Control Parameters///</summary>///<param name= "Ocontrol" > Controls </param>/// <param name= "propname" > Parameter name </param>///<param name= "propvalue" > Parameter value </param>delegate void Setcontrolvaluecallback (Control Ocontrol, String propname, Object propvalue);p ublic static void Setcontrolpropertyvalue (Control Ocontrol, String propname, Object PropValue) {if (ocontrol.invokerequired) { Setcontrolvaluecallback d = new Setcontrolvaluecallback (setcontrolpropertyvalue); Ocontrol.invoke (d, new object[] {ocontrol, propname, propvalue}); } else {Type t = ocontrol.gettype (); system.reflection.propertyinfo[] props = t.getproperties (); foreach (System.Reflection.PropertyInfo p in props) {if (p.name.toupper () = = Propname.toupper ()) {P.setvalue (Ocontrol, propvalue, NULL); }}} #endregion
The current results are as follows:
7. In order to improve the operation efficiency, add the path drag and drop function, the following is the drag and drop class:
Using system;using system.collections.generic;using system.linq;using system.text;using System.Windows.Forms;using System.io;namespace gptools{class Dragclass {private control control; private string fileType = ""; Public Dragclass (Control _control,string _filetype) {//If the control is empty if (_control = = null) {return; } control = _control; FileType = _filetype; Sets whether control can be dragged and dropped. AllowDrop = true; Defines the drag-and-drop event control. DragEnter + = new DragEventHandler (control_dragenter); Ontrol. DragDrop + = new DragEventHandler (Control_dragdrop); The private void Control_dragenter (object sender, DragEventArgs e) {if (E.data.getdatapresent (Data Formats.filedrop)) {e.effect = dragdropeffects.copy; }} private void Control_dragdrop (object sender, DragEventArgs e){string[] files = (string[]) e.data.getdata (DataFormats.FileDrop); foreach (string file in files) {//Determine file type if (path.getextension (file) = = FileType ) {Console.WriteLine (file); Control. Text = file; } } } }}
The drag-and-drop class is instantiated after the main program is initialized, and the DragEnter event and the DragDrop event are triggered once drag-and-drop:
Dragclass dg = new Dragclass (This.txbreferdb, ". mdb");D ragclass dg2 = new Dragclass (This.txbmoredb, ". mdb");
8. Because we only traverse the check. mdb layer, in case the draw. mdb does not have a corresponding layer how, so, we have to check, if not then skip.
Create feature layer//......//Check data Object dt = ""; if (GPClass.GP.Exists (Referdb + "\" + STRFC, ref dt)) { //3. Select All //4. Select (remove) by location} Copy Features//...
9. For more accurate statistical operation time, the timing function is added. As follows:
Reference: http://bbs.esrichina-bj.cn/esri/viewthread.php?tid=50540