Arcobjec, C # t create a blank shapefile

Source: Internet
Author: User
/// <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, string strshapename)
{
// 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; // numeric length
pfieldedit. scale_2 = 3; // number of decimal places
pfieldsedit. addfield (pfield);

// Create a shapefile
PWS. createfeatureclass (strshapename, pfields, null, null, esrifeaturetype. esriftsimple, strshapefieldname, ""); // null in C # replaces nothing in VB
}

====================================

The above function is written based on the VB example in help. It is hard to understand at first, mainly because it is not familiar with interfaces, not only ifield and ifields, but also ifield and ifieldedit. Similar to other geometrydef. After review, I finally figured out their differences.

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.

Ifields is a set of ifields with the addfield () method;

There are also several types to be clarified. Here we also take a look:
Esrifieldtype field types include esrifieldtypegeometry in addition to common types such as int, string, and double;
Esrigeometrytype has 10 geometric types, such as pointing, line, and surface. Not quite clear;
Esrifeaturetype element types, including simple element classes, complex elements, annotations, dimension elements, covering, and raster.

Today (3.19) I found an error to correct it. Length_2 = 10 was previously written. An error was found during editing. length is only for the string field. The length of the numeric field should be set to the precision value. If it is double, you can also use scale to set the number of decimal places 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.

====================================

 

From: http://hi.baidu.com/murphy1314/blog/item/926b1e4eda251e0db3de05a5.html

Related Article

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.