日期:2014-05-17  浏览次数:20908 次

C# + ArcGIS10.0创建shapefile,为什么汉字不能写入到.dbf属性文件里(请看代码)
本帖最后由 zhenggary 于 2012-11-29 09:42:41 编辑 各位大虾,请帮帮我,这个问题困扰我好多天了。
问题:在程序中,生成shapefile,但是在生成的.dbf属性文件里,汉字(pInsertFeatureBuffer.Value[3] = "中国";)没有被写入。怎样才能把汉字写入到.dbf文件里。
环境:VS2010 + ESRI AirGIS10.0

代码如下:
using System;
using ESRI.ArcGIS;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;

namespace CSV2ShapeFile
{
    class Program
    {
        static void Main(string[] args)
        {
// License验证
            if (CheckOutLicenses(esriLicenseProductCode.esriLicenseProductCodeArcInfo) != ESRI.ArcGIS.esriSystem.esriLicenseStatus.esriLicenseCheckedOut)
            {
                // don't get the license
                Console.WriteLine("Don't get the license,failed!");
            }

            const string strFolder = @"D:\ZG\Mapwork\";   //目标文件夹
            const string strName = "myshapefile";  //文件名
            const string strShapeFieldName = "Shape";

            //Open the folder to contain the shapefile as a workspace
            IFeatureWorkspace pFWS;
            IWorkspaceFactory2 pWorkspaceFactory = new ShapefileWorkspaceFactory() as IWorkspaceFactory2;
            pFWS = pWorkspaceFactory.OpenFromFile(strFolder, 0) as IFeatureWorkspace;

            //Set up a simple fields collection
            IFields pFields = new FieldsClass();  //字段
            IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;

            //Make the shape field
            //it will need a geometry definition, with a spatial reference
            IField pField = new FieldClass();
            IFieldEdit pFieldEdit = pField as IFieldEdit;
            pFieldEdit.Name_2 = strShapeFieldName;
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;