How to convert simple data to a Geodatabase

Source: Internet
Author: User
ArticleDirectory
    • Connecting to a Geodatabase
How to convert simple data to a Geodatabase

Summary

The article shows how to use the ifeaturedataconverter interface to load simple feature data into a Geodatabase. the first example sets up the basic framework to convert a shapefile into a file Geodatabase feature class. converting into a personal Geodatabase or enterprise Geodatabase only requires changing the workspacefactory. code fragments explaining how to use a spatial index grid size other than the default and how to modify the output spatial reference (Project) are supported ded.

Development Licensing Deployment Licensing
ArcView ArcView
Arceditor Arceditor
ArcInfo ArcInfo
Engine developer Kit Engine Runtime

Additional requirements

  • The ifeaturedataconverter interface only loads simple feature data (points, lines, polygons ).
  • If working in ArcSDE, an arceditor or greater license will be needed for ArcGIS Desktop and the Geodatabase update extension will be required for ArcGIS Engine.

Converting simple data to a GeodatabaseThe ifeaturedataconverter interface is designed to work with the arccatalog igxdialog minibrowser and accepts iworkspacenames as input. as this example is not using a arccatalog igxdiple minibrowser, two iworkspace objects are required-one for the source data and one for the target.

Connecting to a Geodatabase

The inworkspace is a shapefile and the outworkspace, a file Geodatabase. simple features can be loaded from and to shapefiles, personal geodatabases, file geodatabases, and ArcSDE. arcInfo coverages can be converted to any of the other listed workspaces, but cannot be used as targets. for more information, see how to connect to a Geodatabase.

    • You need to create the necessary iworkspacename objects as shown in the following code:

[C #]

 
// Create inworkspace name.Idataset inworkspacedataset = (idataset) inworkspacefactory; iworkspacename inworkspacename = (iworkspacename) inworkspacedataset. fullname;// Create outworkspace name.Idataset outworkspacedataset = (idataset) outworkspacefactory; iworkspacename outworkspacename = (iworkspacename) outworkspacedataset. fullname;

    • Using inworkspacename, create indatasetname and assign the name of the input feature class, which in this case, is a shapefile (ctgfeatureshp. SHP). See the following code:

[C #]

// Set in dataset and feature class names.Ifeatureclassname infeatureclassname =NewFeatureclassnameclass (); idatasetname indatasetname = (idatasetname) infeatureclassname; indatasetname. workspacename = inworkspacename; indatasetname. Name = "ctgfeatureshp. SHP ";

    • Using outworkspacename,Outdatasetname using idatasetname interface and assign the name ofOutput feature class, which in this case, is a file Geodatabase (ctgfeature_fdcon). The name of the Target Feature class must not already exist in the outworkspace. See the following code:

[C #]

// Set out dataset and feature class names.Ifeatureclassname outfeatureclassname =NewFeatureclassnameclass (); idatasetname outdatasetname = (idatasetname) outfeatureclassname; outdatasetname. workspacename = outworkspacename; outdatasetname. Name = "ctgfeature_fdcon ";

    • Open the input feature class using the INAME. Open method to get field definitions for validation. See the following code:

[C #]

 
// Open input featureclass to get field definitions.INAME inname = (INAME) infeatureclassname; ifeatureclass infeatureclass = (ifeatureclass) inname. open ();

    • Set up for field name validation. See the following code:
Setting both the ifieldchecker, inputworkspace, and ifieldchecker. validateworkspace parameters is required for correct field validation.

[C #]

 
// Validate the field names.Ifieldchecker fieldchecker =NewFieldcheckerclass (); ifields partition = infeatureclass. fields; ienumfielderror enumfielderror; fieldchecker. inputworkspace = inworkspacefactory; fieldchecker. validateworkspace = outworkspacefactory;

    • Validate the fields. If an error is found, enumfielderror can be traversed and an error returned. Refer to ifieldchecker. Validate and enumfielderror for details. See the following code:

[C #]

// Validate the fields.Fieldchecker. Validate (infeatureclassfields,OutEnumfielderror,OutOutfeatureclassfields );

    • Get the geometry definition from the shapefile of the outfeatureclass. See the following code:

[C #]

 
// Set up the geometry definition.Ifield geometryfield; geometryfield = outfeatureclassfields. get_field (outfeatureclassfields. findfield (infeatureclass. shapefieldname ));// Get the geometry field's geometry definition.Igeometrydef geometrydef = geometryfield. geometrydef;

This section is optional You can set the spatial index grid size if needed. this is done through the igeometrydefedit. gridcount and igeometrydefedit. gridsize_2 parameters. it is recommended that you do not set these values and use the defaults. the default values reflect the loaded data and are usually correct. see the following code:

[C #]

 
// Give the geometry definition a spatial index grid count and grid size.Export outfcgeodefedit = (optional) geometrydef; outfcgeodefedit. gridcount_2 = 1; outfcgeodefedit. set_gridsize (); outfcgeodefedit. Gauge = geometryfield. geometrydef. spatialreference;

    • Set up the iqueryfilter to convert all of the features by leaving a blank whereclause. A where clause can be used to subset the input feature class. See the following code:

[C #]

 
Iqueryfilter QF =NewQueryfilterclass (); QF. whereclause = "";

    • Load the feature class. Though rarely needed, rejected features can be reported using enumerrors. See the following code:

[C #]

Ifeaturedataconverter fctofc =NewFeaturedataconverterclass (); ienuminvalidobject enumerrors = fctofc. convertfeatureclass (infeatureclassname, QF,Null, Outfeatureclassname, geometrydef, outfeatureclassfields, "", 1000, 0 );

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.