AE creates a blank shapefile

Source: Internet
Author: User

http://www.97sky.com/bbs/viewthread.php?tid=2282

 

 

 

Code

 /// <Summary>
/// Create an empty shapefile with the specified name in the specified path
/// </Summary>
/// <Param name = "strshapefolder"> specify the path </param>
/// <Param name = "strshapename"> file name </param>

Public void createshapefile (string strshapefolder)
{
// Open the Workspace
Const string strshapefieldname = "shape ";
Iworkspacefactory pwsf = new shapefileworkspacefactoryclass ();
Ifeatureworkspace PWS = (ifeatureworkspace) pwsf. openfromfile (strshapefolder, 0 );

// Set the field set
Ifields pfields = new fieldsclass ();
Ifieldsedit pfieldsedit = (ifieldsedit) pfields;

// Set Fields
Ifield pfield = new fieldclass ();
Ifieldedit pfieldedit = (ifieldedit) pfield;

// Create a field of the geometric type
Pfieldedit. name_2 = strshapefieldname;
Pfieldedit. type_2 = esrifieldtype. esrifieldtypegeometry;

// Create a geometric definition for fields of the esrifieldtypegeometry type, including the type and space references.
Igeometrydef pgeodef = new geometrydefclass (); // The geometry definition for the field if isgeometry is true.
Igeometrydefedit pgeodefedit = (igeometrydefedit) pgeodef;
Pgeodefedit. geometrytype_2 = esrigeometrytype. esrigeometrypoint;
Pgeodefedit. spatialreference_2 = new unknowncoordinatesystemclass ();

Pfieldedit. geometrydef_2 = pgeodef;
Pfieldsedit. addfield (pfield );

// Add other fields
Pfield = new fieldclass ();
Pfieldedit = (ifieldedit) pfield;
Pfieldedit. name_2 = "waterlevel ";
Pfieldedit. type_2 = esrifieldtype. esrifieldtypedouble;
Pfieldedit. precision_2 = 7; // numerical accuracy
Pfieldedit. scale_2 = 3; // number of decimal places
Pfieldsedit. addfield (pfield );

// Create a shapefile
PWS. createfeatureclass (strshapename, pfields, null, null, esrifeaturetype. esriftsimple, strshapefieldname ,"");
}

 

More detailed information

MS-help: // ESRI. ednv9.3/esrigeodatabase/html/ifeatureworkspace.createfeatureclass_example.htm

 

 

 

 

1. Differences between ifield and ifieldedit:
Ifieldedit inherits ifield, because most ifield attributes are read-only. Therefore, ifieldedit has multiple write-only Attributes Based on ifield. This is why name_2 and length_2 may occur. The same is true for ifields and ifieldsedit.

In the code, this will not cause errors,


2. Differences between ifield and ifields
Ifields is a set of ifield. You can use the addfield () method or the set_field () method to add a field. The set_field can use the index to add a field at the specified position;
3.
esriFieldTypeField type,Besides common types such as int, string, and double, esrifieldtypegeometry is also included.

(Geometric type, that is, point, line, and surface)

 

Element types, including simple element classes, complex elements, notes, multidimensional elements, covering, raster, etc.
Length is only applicable to the string field. The length of the numeric field should be set to the value of precision_2. If it is double, you can also use scale_2 to set the number of decimal points to be retained.
Add a description of several parameters of createfeatureclass (). I just checked it online:
CLSID and extclsid have interesting meanings. As we know, each object in Geodatabase has a unique identifier uid. The system authenticates this 64-bit random value to distinguish different objects. Likewise, the extension part of the element class and element class also has such an identifier, but in general we cannot see this uid value. How to generate these two values is also very simple. Use:
CLSID = pocdesc. instanceclsid;
Extclsid = pocdesc. classextensionclsid;
The clsid property of a table determines the type of row object returned by the table; original
Shapefieldname refers to the shape field name of an element class, generally "shape ". ---- It seems that it cannot be changed. After the changes are completed, the shape is displayed.
You do not need to set configkeyword. You can set it to an empty string.
View plaincopy to clipboardprint?

 

 

Iworkspacefactory

             IFields pFields = new FieldsClass();   
IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;

 

 

Because New fieldsclass () can be converted to ifieldsedit

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.