public void MainMethodCode() { // Opening a Non-Versioned SQL Server instance. DatabaseConnectionProperties connectionProperties = new DatabaseConnectionProperties(EnterpriseDatabaseType.SQLServer) { AuthenticationMode = AuthenticationMode.DBMS, // Where testMachine is the machine where the instance is running and testInstance is the name of the SqlServer instance. Instance = @"testMachine\testInstance", // Provided that a database called LocalGovernment has been created on the testInstance and geodatabase has been enabled on the database. Database = "LocalGovernment", // Provided that a login called gdb has been created and corresponding schema has been created with the required permissions. User = "******", Password = "******", Version = "dbo.DEFAULT" }; using (Geodatabase geodatabase = new Geodatabase(connectionProperties)) using (FeatureClass enterpriseFeatureClass = geodatabase.OpenDataset <FeatureClass>("LocalGovernment.GDB.FacilitySite")) { FeatureClassDefinition facilitySiteDefinition = enterpriseFeatureClass.GetDefinition(); int facilityCodeIndex = facilitySiteDefinition.FindField("FCODE"); int subtypeFieldIndex = facilitySiteDefinition.FindField(facilitySiteDefinition.GetSubtypeField()); // Agriculture, Food and Livestock subtype. Subtype agricultureSubtype = facilitySiteDefinition.GetSubtypes().First(subtype => subtype.GetCode() == 701); // Industry Subtype. Subtype industrySubtype = facilitySiteDefinition.GetSubtypes().First(subtype => subtype.GetName().Equals("Industry")); Field faclilityCodeField = facilitySiteDefinition.GetFields()[facilityCodeIndex]; // This will be true since FCODE is a Text field. if (faclilityCodeField.FieldType.Equals(FieldType.String)) { // This will be null since at the field level there is no default value. string fieldLevelDefaultValue = faclilityCodeField.GetDefaultValue() as String; // This will be "Agriculture or Livestock Structure". string defaultValueForAgricultureSubtype = faclilityCodeField.GetDefaultValue(agricultureSubtype) as String; // This will be "Industrial Facility". string defaultValueForIndustrySubtype = faclilityCodeField.GetDefaultValue(industrySubtype) as String; } Field subtypeField = facilitySiteDefinition.GetFields()[subtypeFieldIndex]; // This will be true since SUBTYPEFIELD is a Long Integer field. if (subtypeField.FieldType.Equals(FieldType.Integer)) { // This will be 701 since at the field level the default value is set. int fieldLevelDefaultValue = Convert.ToInt32(subtypeField.GetDefaultValue()); // This will give you 701 since it is Agriculture, Food and Livestock subtype subtype. int defaultValueForAgricultureSubtype = Convert.ToInt32(subtypeField.GetDefaultValue(agricultureSubtype)); // This will give you 710 since it is Industry subtype. int defaultValueForIndustrySubtype = Convert.ToInt32(subtypeField.GetDefaultValue(industrySubtype)); } } }
public void MainMethodCode() { // Opening a Non-Versioned SQL Server instance. DatabaseConnectionProperties connectionProperties = new DatabaseConnectionProperties(EnterpriseDatabaseType.SQLServer) { AuthenticationMode = AuthenticationMode.DBMS, // Where testMachine is the machine where the instance is running and testInstance is the name of the SqlServer instance. Instance = @"testMachine\testInstance", // Provided that a database called LocalGovernment has been created on the testInstance and geodatabase has been enabled on the database. Database = "LocalGovernment", // Provided that a login called gdb has been created and corresponding schema has been created with the required permissions. User = "******", Password = "******", Version = "dbo.DEFAULT" }; using (Geodatabase geodatabase = new Geodatabase(connectionProperties)) using (FeatureClass enterpriseFeatureClass = geodatabase.OpenDataset <FeatureClass>("LocalGovernment.GDB.FacilitySite")) { FeatureClassDefinition facilitySiteDefinition = enterpriseFeatureClass.GetDefinition(); int facilityCodeIndex = facilitySiteDefinition.FindField("FCODE"); int ownerTypeIndex = facilitySiteDefinition.FindField("OWNTYPE"); int subtypeFieldIndex = facilitySiteDefinition.FindField(facilitySiteDefinition.GetSubtypeField()); // Agriculture, Food and Livestock subtype. Subtype agricultureSubtype = facilitySiteDefinition.GetSubtypes().First(subtype => subtype.GetCode() == 701); // Industry Subtype. Subtype industrySubtype = facilitySiteDefinition.GetSubtypes().First(subtype => subtype.GetName().Equals("Industry")); Field faclilityCodeField = facilitySiteDefinition.GetFields()[facilityCodeIndex]; // This will be null since there is not domain assigned at the field level. Domain facilityCodeFieldLevelDomain = faclilityCodeField.GetDomain(); Domain facilityCodeAgricultureSubtypeDomain = faclilityCodeField.GetDomain(agricultureSubtype); // This will be "Agriculture Food and Livestock FCode". string facilityCodeAgricultureSubtypeDomainName = facilityCodeAgricultureSubtypeDomain.GetName(); Domain facilityCodeIndustrySubtypeDomain = faclilityCodeField.GetDomain(industrySubtype); // This will be "Industry FCode" string facilityCodeIndustrySubtypeDomainName = facilityCodeIndustrySubtypeDomain.GetName(); Field ownerTypeField = facilitySiteDefinition.GetFields()[ownerTypeIndex]; Domain ownerTypeFieldLevelDomain = ownerTypeField.GetDomain(); // This will be "OwnerType". string ownerTypeFieldLevelDomainName = ownerTypeFieldLevelDomain.GetName(); Domain ownerTypeAgricultureSubtypeDomain = ownerTypeField.GetDomain(agricultureSubtype); // This will be "OwnerType" because the same domain has been set at the subtype level. string ownerTypeAgricultureSubtypeDomainName = ownerTypeAgricultureSubtypeDomain.GetName(); Domain ownerTypeIndustrySubtypeDomain = ownerTypeField.GetDomain(industrySubtype); // This will be "OwnerType" because the same domain has been set at the subtype level. string ownerTypeIndustrySubtypeDomainName = ownerTypeIndustrySubtypeDomain.GetName(); Field subtypeField = facilitySiteDefinition.GetFields()[subtypeFieldIndex]; // This will be null. Domain subtypeField_FieldLevelDomain = subtypeField.GetDomain(); // This will be null. Domain subtypeField_AgricultureSubtypeDomain = subtypeField.GetDomain(agricultureSubtype); // This will be null. Domain subtypeField_IndustrySubtypeDomain = subtypeField.GetDomain(industrySubtype); } }
public void MainMethodCode() { // Opening a Non-Versioned SQL Server instance. DatabaseConnectionProperties connectionProperties = new DatabaseConnectionProperties(EnterpriseDatabaseType.SQLServer) { AuthenticationMode = AuthenticationMode.DBMS, // Where testMachine is the machine where the instance is running and testInstance is the name of the SqlServer instance. Instance = @"testMachine\testInstance", // Provided that a database called LocalGovernment has been created on the testInstance and geodatabase has been enabled on the database. Database = "LocalGovernment", // Provided that a login called gdb has been created and corresponding schema has been created with the required permissions. User = "******", Password = "******", Version = "dbo.DEFAULT" }; using (Geodatabase geodatabase = new Geodatabase(connectionProperties)) using (FeatureClass featureClass = geodatabase.OpenDataset <FeatureClass>("LocalGovernment.GDB.FacilitySite")) { FeatureClassDefinition featureClassDefinition = featureClass.GetDefinition(); int facilityCodeIndex = featureClassDefinition.FindField("FCODE"); Field field = featureClassDefinition.GetFields()[facilityCodeIndex]; Domain domain = field.GetDomain(featureClassDefinition.GetSubtypes().FirstOrDefault( subtype => subtype.GetName().ToLowerInvariant().Contains("agriculture"))); CodedValueDomain codedValueDomain = (CodedValueDomain)domain; // Will be "Agriculture Food and Livestock FCode"'. string name = codedValueDomain.GetName(); // Will be FieldType.String'. FieldType fieldType = codedValueDomain.GetFieldType(); // Will be "The type of agriculture, food and livestock facility"'. string description = codedValueDomain.GetDescription(); // Will be 13 since there are 13 code value pairs in this domain'. int numberOfcodedValues = codedValueDomain.GetCount(); // This will be a the code value pairs sorted (in this case) by the codes' increasing integer value. SortedList <object, string> codedValuePairs = codedValueDomain.GetCodedValuePairs(); FeatureClassDefinition siteAddressPointDefinition = geodatabase.GetDefinition <FeatureClassDefinition>("LocalGovernment.GDB.SiteAddressPoint"); int unitTypeIndex = siteAddressPointDefinition.FindField("UNITTYPE"); Field unitTypeField = siteAddressPointDefinition.GetFields()[unitTypeIndex]; Domain addressUnitTypeDomain = unitTypeField.GetDomain(); CodedValueDomain valueDomain = (CodedValueDomain)addressUnitTypeDomain; // Will be Apartment. string aptCodeDescription = valueDomain.GetName("APT"); // Will be Basement. string bsmtCodeDescription = valueDomain.GetName("BSMT"); // Will be DEPT. Make sure you know the domain's FieldType is String before cast. string departmentCode = valueDomain.GetCodedValue("Department") as string; // Will be FL. string floorCode = valueDomain.GetCodedValue("Floor") as string; } }