예제 #1
0
        public object get_mapped_value(OSGeo.OGR.Feature feature, int esriFieldsIndex)
        {
            // get the ESRI Field
            ESRI.ArcGIS.Geodatabase.IField pField = m_fields.get_Field(esriFieldsIndex);

            if (esriFieldsIndex == m_oidFieldIndex)
            {
                return(feature.GetFID());
            }

            if (esriFieldsIndex == m_geometryFieldIndex)
            {
                System.Diagnostics.Debug.Assert(false);
                return(null); // this should never be called for geometries
            }

            int ogrIndex = (int)m_fieldMapping[esriFieldsIndex];

            if (!feature.IsFieldSet(ogrIndex))
            {
                return(null);
            }

            switch (feature.GetFieldType(ogrIndex))
            {
            // must be kept in sync with utilities library

            case OSGeo.OGR.FieldType.OFTInteger:
                return(feature.GetFieldAsInteger(ogrIndex));

            case OSGeo.OGR.FieldType.OFTReal:
                return(feature.GetFieldAsDouble(ogrIndex));

            case OSGeo.OGR.FieldType.OFTString:
                return(feature.GetFieldAsString(ogrIndex));

            case OSGeo.OGR.FieldType.OFTBinary:

                // WTF, the C# bindings don't have a blob retrieval until this ticket gets solved
                // http://trac.osgeo.org/gdal/ticket/4457#comment:2

                return(null);

            case OSGeo.OGR.FieldType.OFTDateTime:
            {
                int year, month, day, hour, minute, second, flag;
                feature.GetFieldAsDateTime(ogrIndex, out year, out month, out day, out hour, out minute, out second, out flag);

                DateTime date = new DateTime(year, month, day, hour, minute, second);
                return(date);
            }


            default:
                return(feature.GetFieldAsString(ogrIndex));    //most things coerce as strings
            }
        }
예제 #2
0
        public Field(ESRI.ArcGIS.Geodatabase.IField field, Feature feature)
        {
            Feature     = feature;
            this._field = field;

            _renderContainer = new RendererContainer(this);

            if (field.Type <= ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeDouble)
            {
                _isNumber = true;
            }
            if (field.Type == ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeOID)
            {
                _isOid = true;
            }
        }
예제 #3
0
        /// <summary>
        /// Returns a display name as verified against a coded value domain. If there is not a coded value domain, just returns
        /// the value
        /// </summary>
        /// <param name="field">Field to check against</param>
        /// <param name="value">Value to check</param>
        /// <returns>Display name</returns>
        public static string CheckForCodedName(ESRI.ArcGIS.Geodatabase.IField field, object value)
        {
            // Assume no domain, in which case we will just return the input value
            string result = value.ToString();

            if (null == field)
            {
                throw new ArgumentNullException("field");
            }

            ESRI.ArcGIS.Geodatabase.ICodedValueDomain domain = field.Domain as ESRI.ArcGIS.Geodatabase.ICodedValueDomain;
            if (null != domain)
            {
                result = GetDomainNameForValue(domain, value);
            }

            return(result);
        }
예제 #4
0
        /// <summary>
        /// Returns a nullable int value for a given field on a feature. If the field uses a coded value domain, the name for
        /// the value is returned.
        /// </summary>
        /// <param name="feature">IFeature</param>
        /// <param name="fieldName">Name of the field that holds the value</param>
        /// <returns>int?</returns>
        public static int?GetDomainedIntName(ESRI.ArcGIS.Geodatabase.IFeature feature, string fieldName)
        {
            int?result = null;

            #region Validation

            if (null == feature)
            {
                throw new ArgumentNullException("feature");
            }

            int fieldIdx = feature.Fields.FindField(fieldName);
            if (-1 == fieldIdx)
            {
                string message = string.Format("Field {0} does not exist.", fieldName);
                throw new ArgumentException(message);
            }

            #endregion

            object objValue = feature.get_Value(fieldIdx);
            if (DBNull.Value != objValue)
            {
                ESRI.ArcGIS.Geodatabase.IField field = feature.Fields.get_Field(fieldIdx);
                string valueString = CheckForCodedName(field, objValue);

                int parseResult = -1;
                if (!int.TryParse(valueString, out parseResult))
                {
                    string message = string.Format("{0} value {1} could not be parsed to int.", fieldName, valueString);
                    throw new Exception(message);
                }
                else
                {
                    result = parseResult;
                }
            }

            return(result);
        }
예제 #5
0
        /// <summary>
        /// Creates A GeoJSON feature from an IFeature
        /// </summary>
        /// <param name="feat">The feature.</param>
        /// <returns>A GeoJSON Feature</returns>
        public static GeoJSONFeature CreateFromIFeature(IFeature feat)
        {
            GeoJSONFeature jsonFeature = new GeoJSONFeature();

            jsonFeature.id       = feat.OID.ToString();
            jsonFeature.geometry = GeoJSONGeometry.CreateFromIGeometry(feat.Shape);
            StringBuilder sb = new StringBuilder();

            sb.Append("{");

            for (int i = 0; i < feat.Fields.FieldCount; i++)
            {
                ESRI.ArcGIS.Geodatabase.IField fld = feat.Fields.get_Field(i);
                switch (fld.Name.ToUpper())
                {
                case "SHAPE":
                    break;

                default:
                    string val = "null";
                    if (feat.get_Value(i) != null)
                    {
                        val = feat.get_Value(i).ToString();
                    }
                    if (sb.Length > 1)
                    {
                        sb.Append(",");
                    }
                    sb.Append(string.Format("\"{0}\":\"{1}\"", fld.Name, val));

                    break;
                }
            }

            jsonFeature.properties = sb.ToString();
            sb.Append("}");
            jsonFeature.properties = sb.ToString();
            return(jsonFeature);
        }
예제 #6
0
        /// <summary>
        /// Splices all available strands from one cable to the other, at a given splice closure
        /// </summary>
        /// <param name="cableA">Cable A</param>
        /// <param name="cableB">Cable B</param>
        /// <param name="splice">Splice Closure</param>
        /// <param name="strands">Strands to splice together</param>
        /// <param name="isExistingOperation">Flag to control whether we need to wrap this in an edit operation</param>
        /// <returns>Success</returns>
        public bool CreateSplices(FiberCableWrapper cableA, SpliceableCableWrapper cableB, SpliceClosureWrapper splice, Dictionary <int, FiberSplice> strands, bool isExistingOperation)
        {
            bool success         = false;
            bool isOperationOpen = false;

            #region Validation
            if (null == cableA)
            {
                throw new ArgumentNullException("cableA");
            }

            if (null == cableB)
            {
                throw new ArgumentNullException("cableB");
            }

            if (ESRI.ArcGIS.Editor.esriEditState.esriStateNotEditing == _editor.EditState)
            {
                throw new InvalidOperationException("You must be editing to perform this operation");
            }
            #endregion

            if (!isExistingOperation)
            {
                _editor.StartOperation();
                isOperationOpen = true;
            }


            if (null == splice)
            {
                splice = GenerateSpliceClosure(cableA, cableB);
            }
            else if (0 == splice.IPID.Length)
            {
                // Populate an IPID; we will need it
                ESRI.ArcGIS.Geodatabase.IFeature spliceFt = splice.Feature;
                Guid g = Guid.NewGuid();

                spliceFt.set_Value(spliceFt.Fields.FindField(ConfigUtil.IpidFieldName), g.ToString("B").ToUpper());
                spliceFt.Store();
            }

            try
            {
                ESRI.ArcGIS.Geodatabase.ITable fiberSpliceTable = _wkspHelper.FindTable(ConfigUtil.FiberSpliceTableName);
//                ESRI.ArcGIS.Geodatabase.ITable fiberSpliceTable = GdbUtils.GetTable(cableA.Feature.Class, ConfigUtil.FiberSpliceTableName);
                int aCableIdx     = fiberSpliceTable.FindField(ConfigUtil.ACableIdFieldName);
                int bCableIdx     = fiberSpliceTable.FindField(ConfigUtil.BCableIdFieldName);
                int aFiberNumIdx  = fiberSpliceTable.FindField(ConfigUtil.AFiberNumberFieldName);
                int bFiberNumIdx  = fiberSpliceTable.FindField(ConfigUtil.BFiberNumberFieldName);
                int spliceIpidIdx = fiberSpliceTable.FindField(ConfigUtil.SpliceClosureIpidFieldName);
                int isAFromIdx    = fiberSpliceTable.FindField(ConfigUtil.IsAFromEndFieldName);
                int isBFromIdx    = fiberSpliceTable.FindField(ConfigUtil.IsBFromEndFieldName);
                int lossIdx       = fiberSpliceTable.FindField(ConfigUtil.LossFieldName);
                int typeIdx       = fiberSpliceTable.FindField(ConfigUtil.TypeFieldName);
                ESRI.ArcGIS.Geodatabase.IField typeField = fiberSpliceTable.Fields.get_Field(typeIdx);

                string aCableId   = cableA.IPID;
                string bCableId   = cableB.IPID;
                string isAFromEnd = cableB.IsOtherFromEnd ? "T" : "F";
                string isBFromEnd = cableB.IsThisFromEnd ? "T" : "F";
                string spliceIpid = splice.IPID;

                using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser())
                {
                    // TODO cant use insert cursor since edit events wont fire.
                    // We need evetns to fire for dynamic values to get populated.
                    // ESRI.ArcGIS.Geodatabase.ICursor insertCursor = fiberSpliceTable.Insert(true);
                    // releaser.ManageLifetime(insertCursor);

                    foreach (KeyValuePair <int, FiberSplice> pair in strands)
                    {
                        IRow row = fiberSpliceTable.CreateRow();

                        releaser.ManageLifetime(row);

                        FiberSplice fiberSplice = pair.Value;

                        row.set_Value(aCableIdx, aCableId);
                        row.set_Value(bCableIdx, bCableId);
                        row.set_Value(aFiberNumIdx, pair.Key);
                        row.set_Value(bFiberNumIdx, fiberSplice.BRange.Low);
                        row.set_Value(spliceIpidIdx, spliceIpid);
                        row.set_Value(isAFromIdx, isAFromEnd);
                        row.set_Value(isBFromIdx, isBFromEnd);

                        if (null == fiberSplice.Loss)
                        {
                            row.set_Value(lossIdx, DBNull.Value);
                        }
                        else
                        {
                            row.set_Value(lossIdx, fiberSplice.Loss);
                        }

                        object typeValue = DBNull.Value;
                        if (null != fiberSplice.Type)
                        {
                            try
                            {
                                typeValue = GdbUtils.CheckForCodedValue(typeField, fiberSplice.Type);
                            }
                            catch
                            {
                                // TODO: Log a warning about why we can't set the default split splice type?
                            }
                        }

                        row.set_Value(typeIdx, typeValue);
                        row.Store();
                    }
                }

                if (isOperationOpen)
                {
                    _editor.StopOperation("Edit Splices");
                }

                success = true;
            }
            catch
            {
                if (isOperationOpen)
                {
                    _editor.AbortOperation();
                }

                success = false;
            }

            return(success);
        }