private void InsertFeature(IFeatureCursor inCurr, IFeatureBuffer inBuff, IFeature origF, IGeometry inGeo) { mLog.Debug("inside insert feature"); IField tmpField; IFields fieldColl; //object Missing = Type.Missing; fieldColl = origF.Fields; mLog.Debug("this feature has " + fieldColl.FieldCount.ToString() + " fields to work with"); for (int i = 0; i < fieldColl.FieldCount; i++) { tmpField = fieldColl.get_Field(i); mLog.Debug("this field is " + tmpField.Name); mLog.Debug("this field type is " + tmpField.VarType.ToString()); if (tmpField.Type != esriFieldType.esriFieldTypeGeometry && tmpField.Type != esriFieldType.esriFieldTypeOID && tmpField.Editable) { mLog.Debug(inBuff.get_Value(i).ToString()); mLog.Debug("seting the value to " + origF.get_Value(i)); inBuff.set_Value(i, origF.get_Value(i)); } } inBuff.Shape = inGeo; inCurr.InsertFeature(inBuff); inCurr.Flush(); }
private void processMiscellaneousFields(IFeatureBuffer targetFeatureBuffer, string sidc) { if ((symbolCreator == null) || (targetFeatureBuffer == null)) { return; } // Set required field UniqueDesignation if empty int indexUD = targetFeatureBuffer.Fields.FindField(MilitaryFeatureClassHelper.UNIQUE_ID_FIELD_NAME); if (indexUD >= 0) { object oUD = targetFeatureBuffer.get_Value(indexUD); string s = oUD.ToString(); // if its null or hasn't changed, set it if ((lastUniqueDesignation == s) || (oUD == null) || (oUD == DBNull.Value) || (s.Length == 0)) { string newUniqueDesignation = symbolCreator.GetGenericSymbolName(sidc); // Apparently if you set a string field to a size larger than allowed it throws an exception // so don't let this happen IField uidField = targetFeatureBuffer.Fields.get_Field(indexUD); if (uidField != null) { int maxUidLength = uidField.Length; if (newUniqueDesignation.Length > maxUidLength) { newUniqueDesignation = newUniqueDesignation.Substring(0, maxUidLength); } } targetFeatureBuffer.set_Value(indexUD, newUniqueDesignation); lastUniqueDesignation = newUniqueDesignation; } } // Set Echelon field int indexEch = targetFeatureBuffer.Fields.FindField(MilitaryFeatureClassHelper.ECHELON_FIELD); if ((indexEch >= 0) && (symbolCreator.HasValidEchelon(sidc))) { object oEch = targetFeatureBuffer.get_Value(indexEch); if ((oEch == DBNull.Value) || (oEch.ToString().Length == 0)) // if it's empty { int ech = symbolCreator.GetEchelonOrdinal(sidc); oEch = (object)ech; targetFeatureBuffer.set_Value(indexEch, oEch); lastEchelon = ech; } else { // if its not empty, it may be because of the previous value/state of the featurebuffer // so we need to check the case when it hasn't changed int ech = (int)oEch; if (ech == lastEchelon) { ech = symbolCreator.GetEchelonOrdinal(sidc); oEch = (object)ech; targetFeatureBuffer.set_Value(indexEch, oEch); lastEchelon = ech; } } } // Set Country Code field int indexCC = targetFeatureBuffer.Fields.FindField(MilitaryFeatureClassHelper.COUNTRY_FIELD); if (indexCC >= 0) { object oCC = targetFeatureBuffer.get_Value(indexCC); string s = oCC.ToString(); // if its null or hasn't changed, set it if ((lastCountryCode == s) || (oCC == null) || (oCC == DBNull.Value) || (s.Length == 0)) { string countryCode = symbolCreator.GetCountryCode(sidc); targetFeatureBuffer.set_Value(indexCC, countryCode); lastCountryCode = countryCode; } } }
private void processMiscellaneousFields(IFeatureBuffer targetFeatureBuffer, string sidc) { if ((symbolCreator == null) || (targetFeatureBuffer == null)) return; // Set required field UniqueDesignation if empty int indexUD = targetFeatureBuffer.Fields.FindField(MilitaryFeatureClassHelper.UNIQUE_ID_FIELD_NAME); if (indexUD >= 0) { object oUD = targetFeatureBuffer.get_Value(indexUD); string s = oUD.ToString(); // if its null or hasn't changed, set it if ((lastUniqueDesignation == s) || (oUD == null) || (oUD == DBNull.Value) || (s.Length == 0)) { string newUniqueDesignation = symbolCreator.GetGenericSymbolName(sidc); // Apparently if you set a string field to a size larger than allowed it throws an exception // so don't let this happen IField uidField = targetFeatureBuffer.Fields.get_Field(indexUD); if (uidField != null) { int maxUidLength = uidField.Length; if (newUniqueDesignation.Length > maxUidLength) newUniqueDesignation = newUniqueDesignation.Substring(0, maxUidLength); } targetFeatureBuffer.set_Value(indexUD, newUniqueDesignation); lastUniqueDesignation = newUniqueDesignation; } } // Set Echelon field int indexEch = targetFeatureBuffer.Fields.FindField(MilitaryFeatureClassHelper.ECHELON_FIELD); if ((indexEch >= 0) && (symbolCreator.HasValidEchelon(sidc))) { object oEch = targetFeatureBuffer.get_Value(indexEch); if ((oEch == DBNull.Value) || (oEch.ToString().Length == 0)) // if it's empty { int ech = symbolCreator.GetEchelonOrdinal(sidc); oEch = (object)ech; targetFeatureBuffer.set_Value(indexEch, oEch); lastEchelon = ech; } else { // if its not empty, it may be because of the previous value/state of the featurebuffer // so we need to check the case when it hasn't changed int ech = (int)oEch; if (ech == lastEchelon) { ech = symbolCreator.GetEchelonOrdinal(sidc); oEch = (object)ech; targetFeatureBuffer.set_Value(indexEch, oEch); lastEchelon = ech; } } } // Set Country Code field int indexCC = targetFeatureBuffer.Fields.FindField(MilitaryFeatureClassHelper.COUNTRY_FIELD); if (indexCC >= 0) { object oCC = targetFeatureBuffer.get_Value(indexCC); string s = oCC.ToString(); // if its null or hasn't changed, set it if ((lastCountryCode == s) || (oCC == null) || (oCC == DBNull.Value) || (s.Length == 0)) { string countryCode = symbolCreator.GetCountryCode(sidc); targetFeatureBuffer.set_Value(indexCC, countryCode); lastCountryCode = countryCode; } } }