arcobject创建featureclass

private IFeatureClass createFeatureClass(IServerContext sc,IFeatureWorkspace fws, ISpatialReference spatialReference) throws  Exception{
    	
    	IFeatureClass fClass ;
    	IFields fields =(Fields)sc.createObject(Fields.getClsid());
        IFieldsEdit fieldsEdit = (IFieldsEdit)fields;
        fieldsEdit.setFieldCount(3);

        //创建对象id字段
        IField field = (Field)sc.createObject(Field.getClsid());
        IFieldEdit fieldEdit = (IFieldEdit)field;
        fieldEdit.setName("OBJECTID");
        fieldEdit.setAliasName("OBJECTID");
        fieldEdit.setType(esriFieldType.esriFieldTypeOID);
        fieldsEdit.setFieldByRef(0, field);

        //创建几何形状字段
        IField field1 = (Field)sc.createObject(Field.getClsid());
        fieldEdit = (IFieldEdit)field1;
        //为形状字段建立几何定义
        IGeometryDef geometryDef =(GeometryDef)sc.createObject(GeometryDef.getClsid());
        IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
        geometryDefEdit.setGeometryType(esriGeometryType.esriGeometryPoint);
        geometryDefEdit.setGridCount(1);
        geometryDefEdit.setGridSize(0, 0); //gridesize基于初次装载或者插入的features
        geometryDefEdit.setHasM(false);
        geometryDefEdit.setHasZ(false);

        //配置空间参考,从feature dataset中继承
        if (spatialReference != null)  {
            geometryDefEdit.setSpatialReferenceByRef(spatialReference);
        }
        //设置标准字段属性
        fieldEdit.setName("SHAPE");
        fieldEdit.setType(esriFieldType.esriFieldTypeGeometry) ;
        fieldEdit.setGeometryDefByRef(geometryDef);
        fieldEdit.setIsNullable(true);
        fieldEdit.setRequired(true);
        fieldsEdit.setFieldByRef(1, field1);

        IField field2 = (Field)sc.createObject(Field.getClsid());
        fieldEdit = (IFieldEdit)field2;
        fieldEdit.setName("USERID");
        fieldEdit.setAliasName("USERID");
        fieldEdit.setEditable(true);
        //fieldEdit.setIsNullable(false);
        fieldEdit.setType(esriFieldType.esriFieldTypeString);
        fieldsEdit.setFieldByRef(2, field2);

        //通过指定的CLSID和EXTCLSID来创建一个feature class的描述对象
        IFeatureClassDescription fcDesc = (FeatureClassDescription)sc.createObject(FeatureClassDescription.getClsid());
        IObjectClassDescription ocDesc = (IObjectClassDescription)fcDesc;
        fClass = fws.createFeatureClass("FeatureClass_temp", fields, 
        				ocDesc.getInstanceCLSID(), ocDesc.getClassExtensionCLSID(), 
        				esriFeatureType.esriFTSimple, "SHAPE", "");
        return fClass;
    }

你可能感兴趣的:(object)