How to Use name objects, including workspacenames and datasetnames
1. Name object
A name object is a representative object. By using the name object, you can access some basic attributes of the object it represents, instead of calling the entire object into the memory. If you need to use the object itself represented by the name object, you can get it by name.
The name object can be applied to tables, featureclasses, and workspaces.
Name:
1. workspacename
2. datasetname
1> relationshipclassname
2> featuredatasetname
3> rasterdatasetname
4> tinname
5> tablename
△-- Featureclassname
The most important thing to use a name object is to get the representative object through name. to access any object in the name subclass, use the open method of the INAME interface.
Example: search for a dataset and open it
Public void opencities ()
{
Iworkspacefactory pwsfactory;
Iworkspace PWS;
Ienumdatasetname penumdsnames;
Idatasetname pdsname;
Ifeatureclass pcities;
Pwsfactory = new shapefileworkspacefactoryclass ();
PWS = pwsfactory. openfromfile ("C: \ data \ Africa", 0 );
Penumdsnames = PWS. datasetnames (esridatasettype. esridtfeatureclass); // feature class
Pdsname = penumdsnames. Next ();
While (pdsname! = NULL)
{
If (pdsname. Name = "africties ties ")
{
INAME pname = pdsname as INAME;
Pcities = pname. open () as ifeatureclass;
Return;
}
Pdsname = penumdsnames. Next ();
}
Ii. Use datasetnames
A common usage of the name object is to specify a name when creating a data set on a disk. For example, you can use the datasetname object in the input and output parameters during data conversion without using the DataSet object. All subclasses of datasetname are coclasses that can be created with the New Keyword. Once created, you can set the name attribute to represent the dataset.
Example: Create a new table positianfroys. DBF under c: \ data.
Iworkspacefactory pshapewsfactory;
Iworkspacename pworkname;
Idatasetname ptablename;
Pshapewsfactory = new shapefileworkspacefactoryclass ();
Pworkname = pshapewsfactory. Create ("C: \", "data", null, 0 );
Ptablename = new tablenameclass ();
Ptablename. workspacename = pworkname;
Ptable. Name = "positianfroys. DBF ";
Iii. Data conversion, output, and loading
Featuredataconverter is a coclass that can convert element classes, element sets, or tables into other datasets. It can not only convert a single element class or table, you can also convert the entire dataset (such as ArcInfo coverage ). The featuredataconverter object enables data conversion between Geodatabase, shapefile, and coverages to support most data types (except tagging ). When introducing data to Geodatabase, you can specify the differences between data. For ArcSDE Geodatabase, you can also specify storage parameters by configuring certain keywords of ArcSDE.
Exportoperation is a coclass used to output element classes or tables. It provides similar functions and feature data converters, but the form is simpler. When you right-click a layer in the ArcMap directory table, this data output function is called.
Objectloader is used to append a table (or element class) to a table (or element class ). Iobjectloader only contains one method-loadobjects.
Iv. Verification fields and records
The fieldchecker object can be used to verify a field set, which is useful for data conversion between different formats, because the field names of different formats of datasets may not be common. When fieldchecker encounters an invalid field name, it can correct the error according to certain standards (such as adding the bottom line UID) to generate a valid field set. When converting data to Geodatabase format, fieldchecker generates a standard name (shape and objectid) for the geometry and OID fields ).
When using objectloader or featuredataconverter to load or convert elements, invalid objects are returned in the form of enumeration (ienuminvalidobject). By viewing this enumeration, it is easy to know which objects cannot be loaded or converted.
5. Use feature data converter
The ifeaturedataconverter interface has three methods for data conversion:
1. convertfeatureclass
2. convertfeaturedataset
3. converttable
Public ienuminvalidobject convertfeatureclass (
IfeatureclassnameInputdatasetname,
IqueryfilterInputqueryfilter,
IfeaturedatasetnameOutputfdatasetname,
IfeatureclassnameOutputfclassname,
IgeometrydefOutputgeometrydef,
IfieldsOutputfields,
StringConfigkey,
IntFlushinterval,
IntParenthwnd
);
Inputdatasetname-- Ifeatureclassname is a name object used to specify the element class for conversion;
Inputqueryfilter-- Iqueryfilter: The queryfilter object used to filter the elements to be converted;
Outputfdatasetname-- New data output by the ifeaturedatasetname element class integrates the name object of the existing dataset;
Outputfclassname-- Ifeatureclassname name object of the new output element class;
Outputgeometrydef-- Geometrydef object used to specify the space reference information of the output element class. If it is null, use the output element to integrate the space reference information of the input element class.
Outputfields-- Ifields is used to specify the field set of the output element class. If you simply output the element class in the same format, you can use the field set of the input element class. If the format is changed, fieldchecker is recommended to ensure that the output format is valid;
Configkey-- String is a string used to specify the ArcSDE configuration keyword;
Flushinterval-- It is used to specify the Integer Range when the elements are converted to the new element category when they are output to Geodatabase;
Parenthwnd --Specifies the window handle of the application;
Example: // ifeaturedataconverter convertfeatureclass example (from. NET Help)
// E.g., nameofsourcefeatureclass = "ctgfeatureshp. SHP"
// Nameoftargetfeatureclass = "ctgfeature"
Public void ifeaturedataconverter_convertfeatureclass_example (iworkspace sourceworkspace, iworkspace targetworkspace, string nameofsourcefeatureclass, string nameoftargetfeatureclass)
{
// Create source workspace name
Idataset sourceworkspacedataset = (idataset) sourceworkspace;
Iworkspacename sourceworkspacename = (iworkspacename) sourceworkspacedataset. fullname;
// Create source dataset name
Ifeatureclassname sourcefeatureclassname = new featureclassnameclass ();
Idatasetname sourcedatasetname = (idatasetname) sourcefeatureclassname;
Sourcedatasetname. workspacename = sourceworkspacename;
Sourcedatasetname. Name = nameofsourcefeatureclass;
// Create target workspace name
Idataset targetworkspacedataset = (idataset) targetworkspace;
Iworkspacename targetworkspacename = (iworkspacename) targetworkspacedataset. fullname;
// Create target dataset name
Ifeatureclassname targetfeatureclassname = new featureclassnameclass ();
Idatasetname targetdatasetname = (idatasetname) targetfeatureclassname;
Targetdatasetname. workspacename = targetworkspacename;
Targetdatasetname. Name = nameoftargetfeatureclass;
// Open input featureclass to get field definitions.
ESRI. ArcGIS. esrisystem. INAME sourcename = (ESRI. ArcGIS. esrisystem. INAME) sourcefeatureclassname;
Ifeatureclass sourcefeatureclass = (ifeatureclass) sourcename. open ();
// Validate the field names because you are converting between different workspace types.
Ifieldchecker fieldchecker = new fieldcheckerclass ();
Ifields targetfeatureclassfields;
Ifields sourcefeatureclassfields = sourcefeatureclass. fields;
Ienumfielderror enumfielderror;
// Most importantly set the input and validate workspaces!
Fieldchecker. inputworkspace = sourceworkspace;
Fieldchecker. validateworkspace = targetworkspace;
Fieldchecker. Validate (sourcefeatureclassfields, out enumfielderror, out targetfeatureclassfields );
// Loop through the output fields to find the geomerty Field
Ifield geometryfield;
For (INT I = 0; I <targetfeatureclassfields. fieldcount; I ++)
{
If (targetfeatureclassfields. get_field (I). type = esrifieldtype. esrifieldtypegeometry)
{
Geometryfield = targetfeatureclassfields. get_field (I );
// Get the geometry field's geometry defenition
Igeometrydef geometrydef = geometryfield. geometrydef;
// Give the geometry definition a spatial index grid count and grid size
Igeometrydefedit targetfcgeodefedit = (igeometrydefedit) geometrydef;
Targetfcgeodefedit. gridcount_2 = 1;
Targetfcgeodefedit. set_gridsize (0, 0); // allow ArcGIS to determine a valid grid size for the data loaded
Targetfcgeodefedit. spatialreference_2 = geometryfield. geometrydef. spatialreference;
// We want to convert all of the features
Iqueryfilter queryfilter = new queryfilterclass ();
Queryfilter. whereclause = "";
// Load the feature class
Ifeaturedataconverter fctofc = new featuredataconverterclass ();
Ienuminvalidobject enumerrors = fctofc. convertfeatureclass (sourcefeatureclassname, queryfilter, null, targetfeatureclassname, geometrydef, targetfeatureclassfields, "", 1000, 0 );
Break;
}
}
}