Exemplo n.º 1
0
        private IFeatureClass CreateFeatureClass(IFeatureWorkspace ipWorkspace, ISpatialReference ipSr)
        {
            //Ìí¼Óº¯ÊýCreateFeatureClass()
            IFieldsEdit ipFields = new FieldsClass();

            ipFields.FieldCount_2 = 3;
            IFieldEdit ipField = new FieldClass();

            ipField.Name_2      = "ObjectID";
            ipField.AliasName_2 = "FID";
            ipField.Type_2      = esriFieldType.esriFieldTypeOID;
            ipFields.set_Field(0, ipField);
            //Add others miscellaneous text field
            IFieldEdit ipField2 = new FieldClass();

            ipField2.Name_2      = "SmallInteger";
            ipField2.AliasName_2 = "short";
            ipField2.Type_2      = esriFieldType.esriFieldTypeSmallInteger;
            ipFields.set_Field(1, ipField2);
            //Make the shape field
            //it will need a geometry definition, with a spatial reference
            IGeometryDefEdit ipGeoDef = new GeometryDefClass();

            ipGeoDef.SpatialReference_2 = ipSr;
            ipGeoDef.GeometryType_2     =
                esriGeometryType.esriGeometryPoint;
            IFieldEdit ipField3 = new FieldClass();

            ipField3.Name_2        = "Shape";
            ipField3.AliasName_2   = "shape";
            ipField3.Type_2        = esriFieldType.esriFieldTypeGeometry;
            ipField3.GeometryDef_2 = ipGeoDef;
            ipFields.set_Field(2, ipField3);
            ipSr.SetDomain(-60000000, 60000000, -60000000, 60000000);

            IFeatureDataset ipFeatDs =
                ipWorkspace.OpenFeatureDataset("tast1");

            IFeatureClass ipFeatCls = ipFeatDs.CreateFeatureClass
                                          ("pit16er", ipFields, null, null, esriFeatureType.
                                          esriFTSimple, "Shape", "");

            return(ipFeatCls);
        }
Exemplo n.º 2
0
        public static IFieldsEdit GetBareMetalFields(esriGeometryType type, int epsg, List <MyFieldDef> extraFields, string oidFieldName = "OID", string shapeFieldName = "Shape")
        {
            int         len   = null == extraFields ? 0 : extraFields.Count;
            int         count = 0;
            IFieldsEdit flds  = new FieldsClass();

            flds.FieldCount_2 = 2 + len;

            IFieldEdit fld = new FieldClass();

            fld.Name_2 = oidFieldName;
            fld.Type_2 = esriFieldType.esriFieldTypeOID;
            flds.set_Field(count++, fld);

            fld               = new FieldClass();
            fld.Name_2        = shapeFieldName;
            fld.Type_2        = esriFieldType.esriFieldTypeGeometry;
            fld.GeometryDef_2 = CreateGeometryDef(type, epsg);
            flds.set_Field(count++, fld);

            if (null != extraFields)
            {
                foreach (var fd in extraFields)
                {
                    //let the exception throw if the following conditions are not met
                    //Otherwise, user may take granted and cause confusion if the missing fields fail the following operations
                    //if (null != fd && null != fd.Name && null != fd.Type)
                    {
                        fld        = new FieldClass();
                        fld.Name_2 = fd.Name;
                        fld.Type_2 = fd.Type;
                        flds.set_Field(count++, fld);
                    }
                }
            }
            return(flds);
        }