예제 #1
0
        // ArcGIS Snippet Title:
        // Create Table
        //
        // Long Description:
        // Creates a dataset in a workspace.
        //
        // Add the following references to the project:
        // ESRI.ArcGIS.Geodatabase
        // ESRI.ArcGIS.Geometry
        // ESRI.ArcGIS.System
        //
        // Intended ArcGIS Products for this snippet:
        // ArcGIS Desktop (ArcEditor, ArcInfo, ArcView)
        // ArcGIS Engine
        // ArcGIS Server
        //
        // Applicable ArcGIS Product Versions:
        // 9.2
        // 9.3
        // 9.3.1
        // 10.0
        //
        // Required ArcGIS Extensions:
        // (NONE)
        //
        // Notes:
        // This snippet is intended to be inserted at the base level of a Class.
        // It is not intended to be nested within an existing Uitvoeren.
        //

        ///<summary>Creates a table with some default fields.</summary>
        ///
        ///<param name="workspace">An IWorkspace2 interface</param>
        ///<param name="tableName">A System.String of the table name in the workspace. Example: "owners"</param>
        ///<param name="fields">An IFields interface or Nothing</param>
        ///
        ///<returns>An ITable interface or Nothing</returns>
        ///
        ///<remarks>
        ///Notes:
        ///(1) If an IFields interface is supplied for the 'fields' collection it will be used to create the
        ///    table. If a Nothing value is supplied for the 'fields' collection, a table will be created using
        ///    default values in the method.
        ///(2) If a table with the supplied 'tableName' exists in the workspace an ITable will be returned.
        ///    if table does not exit a new one will be created.
        ///</remarks>
        public ESRI.ArcGIS.Geodatabase.ITable CreateOrOpenTableLog(ESRI.ArcGIS.Geodatabase.IWorkspace2 workspace, System.String tableName, ESRI.ArcGIS.Geodatabase.IFields fields)
        {
            // create the behavior clasid for the featureclass
            ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass();

            if (workspace == null)
            {
                return(null);                                                                                                  // valid feature workspace not passed in as an argument to the method
            }
            ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explicit Cast
            ESRI.ArcGIS.Geodatabase.ITable            table;

            if (workspace.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTTable, tableName))
            {
                // table with that name already exists return that table
                table = featureWorkspace.OpenTable(tableName);
                return(table);
            }

            uid.Value = "esriGeoDatabase.Object";

            ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.ObjectClassDescriptionClass();

            // if a fields collection is not passed in then supply our own
            if (fields == null)
            {
                // create the fields using the required fields method
                fields = objectClassDescription.RequiredFields;
                ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast

                fieldsEdit.AddField(this.CreateFieldInt("ID"));
                fieldsEdit.AddField(this.CreateFieldInt("index"));
                fieldsEdit.AddField(this.CreateFieldDouble("X_From", 8, 2));
                fieldsEdit.AddField(this.CreateFieldDouble("Y_From", 8, 2));
                fieldsEdit.AddField(this.CreateFieldDouble("M_From", 8, 2));
                fieldsEdit.AddField(this.CreateFieldDouble("X_To", 8, 2));
                fieldsEdit.AddField(this.CreateFieldDouble("Y_To", 8, 2));
                fieldsEdit.AddField(this.CreateFieldDouble("M_To", 8, 2));


                // add field to field collection
                fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit; // Explicit Cast
            }

            // Use IFieldChecker to create a validated fields collection.
            ESRI.ArcGIS.Geodatabase.IFieldChecker   fieldChecker    = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass();
            ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError  = null;
            ESRI.ArcGIS.Geodatabase.IFields         validatedFields = null;
            fieldChecker.ValidateWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)workspace;
            fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

            // The enumFieldError enumerator can be inspected at this point to determine
            // which fields were modified during validation.


            // create and return the table
            table = featureWorkspace.CreateTable(tableName, validatedFields, uid, null, "");

            return(table);
        }
예제 #2
0
        // Create 3 feature classes to hold the point, polyline, and polygon transactions
        private Dictionary <esriGeometryType, IFeatureClass> CreateFCS(string path)
        {
            // Connect to the output file GDB
            IWorkspaceFactory wsFact = new FileGDBWorkspaceFactory();
            IWorkspace        ws     = wsFact.OpenFromFile(path, this.Handle.ToInt32());
            IFeatureWorkspace featws = ws as IFeatureWorkspace;

            // Get the coded value domain for the transaction type, creating if necessary
            IDomain domain = GetOrCreateDomain(ws);

            Dictionary <esriGeometryType, IFeatureClass> dictionary = new Dictionary <esriGeometryType, IFeatureClass>();

            foreach (var geomType in new esriGeometryType[] { esriGeometryType.esriGeometryPoint, esriGeometryType.esriGeometryPolyline, esriGeometryType.esriGeometryPolygon })
            {
                // Create the feature classes
                string fcName   = Enum.GetName(typeof(esriGeometryType), geomType) + "_TransactionsExportedAt" + DateTime.Now.ToString("yyyyMMdd_HHmm");
                UID    tableUID = new UIDClass();
                tableUID.Value = "esriGeoDatabase.Feature";

                // Get the fields for this geometry type
                IFields fields = GetFields(geomType, domain);

                // Validate the fields
                ESRI.ArcGIS.Geodatabase.IFieldChecker   fieldChecker    = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass();
                ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError  = null;
                ESRI.ArcGIS.Geodatabase.IFields         validatedFields = null;
                fieldChecker.ValidateWorkspace = ws;
                fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

                IFieldError err;
                while (enumFieldError != null && (err = enumFieldError.Next()) != null)
                {
                    // If the field validation failed, display an error (since fields are mostly hardcoded, this shouldn't really happen)
                    MessageBox.Show(Enum.GetName(typeof(esriFieldNameErrorType), err.FieldError), "Field Error");
                }

                dictionary.Add(geomType, featws.CreateFeatureClass(fcName, validatedFields, tableUID, null, esriFeatureType.esriFTSimple, "SHAPE", "DEFAULT"));
            }

            return(dictionary);
        }
예제 #3
0
        /// <summary>
        /// CreateFeatureClass
        /// </summary>
        /// <param name="FeatureWorkspace"></param>
        /// <param name="LayerName"></param>
        /// <param name="featureType"></param>
        /// <param name="GeometryType"></param>
        /// <returns></returns>
        public IFeatureClass CreateFeatureClass(IFeatureWorkspace FeatureWorkspace, string LayerName, esriFeatureType featureType, esriGeometryType GeometryType)
        {
            //----------------
            ESRI.ArcGIS.Geodatabase.FeatureClassDescriptionClass objectClassDescription = new ESRI.ArcGIS.Geodatabase.FeatureClassDescriptionClass();

            // create the fields using the required fields method
            ESRI.ArcGIS.Geodatabase.IFields     fields     = objectClassDescription.RequiredFields;
            ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast
            IField fd              = null;
            bool   IsOIDField      = false;
            bool   IsGeometryField = false;

            for (int i = 0; i < fields.FieldCount; i++)
            {
                fd = fields.get_Field(i);
                if (fd.Type == esriFieldType.esriFieldTypeOID)
                {
                    (fd as IFieldEdit).Name_2 = this.OIDFieldName;
                    IsOIDField = true;
                }
                if (fd.Type == esriFieldType.esriFieldTypeGeometry)
                {
                    (fd as IFieldEdit).Name_2 = this.GeometryFieldName;
                    (fd.GeometryDef as IGeometryDefEdit).GeometryType_2 = GeometryType;
                    IsGeometryField = true;
                }
            }
            //----------------

            if (IsOIDField == false)
            {
                //创建OBJECTID字段
                IField     field3 = new FieldClass();
                IFieldEdit edit2  = field3 as IFieldEdit;
                edit2.Name_2      = this.OIDFieldName;
                edit2.AliasName_2 = this.OIDFieldName;
                edit2.Type_2      = esriFieldType.esriFieldTypeOID;
                fieldsEdit.AddField(field3);
            }
            string ShapeFiledName = this.GeometryFieldName;

            if (IsGeometryField == false)
            {
                //创建几何字段
                IGeometryDef     def   = new GeometryDefClass();
                IGeometryDefEdit edit4 = def as IGeometryDefEdit;
                edit4.GeometryType_2 = this.GeometryType;
                edit4.GridCount_2    = 1;
                edit4.set_GridSize(0, 1000);
                edit4.AvgNumPoints_2     = 2;
                edit4.HasM_2             = false;
                edit4.HasZ_2             = false;
                edit4.SpatialReference_2 = this.ShapeSpatialReference;
                //
                IField     field4 = new FieldClass();
                IFieldEdit edit3  = field4 as IFieldEdit;
                edit3.Name_2        = this.GeometryFieldName;
                edit3.AliasName_2   = this.GeometryFieldName;
                edit3.Type_2        = esriFieldType.esriFieldTypeGeometry;
                edit3.GeometryDef_2 = def;
                fieldsEdit.AddField(field4);
                //
                ShapeFiledName = field4.Name;
            }

            UID uid  = null;
            UID uid2 = null;

            switch (featureType)
            {
            case esriFeatureType.esriFTSimple:       //FeatureClass
                uid  = objectClassDescription.InstanceCLSID;
                uid2 = objectClassDescription.ClassExtensionCLSID;
                break;

            default:
                break;
            }
            //创建要素对象
            IFeatureClass fc = FeatureWorkspace.CreateFeatureClass(LayerName, fields, uid, uid2, featureType, ShapeFiledName, null);

            //
            return(fc);
        }
예제 #4
0
        public IFeatureClass createFeatureClassInMemory(string strName, IFields FeatureFields, IWorkspace pWS, esriFeatureType featType)
        {
            ESRI.ArcGIS.esriSystem.UID CLSID = null;
            //ESRI.ArcGIS.esriSystem.UID CLSEXT = null;
            IFeatureWorkspace pFWS = null;

            ESRI.ArcGIS.Geodatabase.IFieldChecker   fieldChecker    = null;
            ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError  = null;
            ESRI.ArcGIS.Geodatabase.IFields         validatedFields = null;
            try
            {
                //CLSEXT = null;

                pFWS = (IFeatureWorkspace)pWS;


                if (CLSID == null)
                {
                    CLSID       = new ESRI.ArcGIS.esriSystem.UIDClass();
                    CLSID.Value = "esriGeoDatabase.Feature";
                }


                fieldChecker    = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass();
                enumFieldError  = null;
                validatedFields = null;
                fieldChecker.ValidateWorkspace = pWS;
                fieldChecker.Validate(FeatureFields, out enumFieldError, out validatedFields);
                bool          FCCreated = false;
                IFeatureClass newFeat   = null;
                int           loopCnt   = 0;
                while (FCCreated == false)
                {
                    try
                    {
                        if (loopCnt == 0)
                        {
                            loopCnt = loopCnt + 1;
                            newFeat = pFWS.CreateFeatureClass(strName, validatedFields, null, null, featType, "SHAPE", "");
                        }
                        else
                        {
                            loopCnt = loopCnt + 1;
                            newFeat = pFWS.CreateFeatureClass(strName + (loopCnt - 1).ToString(), validatedFields, null, null, featType, "SHAPE", "");
                        }
                        FCCreated = true;
                    }
                    catch
                    {
                        FCCreated = false;
                    }
                    if (loopCnt == 100)
                    {
                        FCCreated = true;
                    }
                }
                return(newFeat);
            }
            catch
            {
                return(null);
            }
            finally
            {
                CLSID = null;

                pFWS = null;

                fieldChecker    = null;
                enumFieldError  = null;
                validatedFields = null;
            }
        }
        /// <summary>
        /// Sets the input and output ports based on the given configuration. If IPID and/or CABLEID are null, it also
        /// takes care of them
        /// </summary>
        /// <param name="feature">The device feature to configure</param>
        /// <param name="inputPorts">Number of input ports</param>
        /// <param name="outputPorts">Number of output ports</param>
        /// <param name="isExistingOperation">Flag to control whether this method is being called from within an existing
        /// edit operation -- the default behavior is "false" in which case it adds an operation of its own</param>
        /// <returns>True if the configuration is complete</returns>
        public bool ConfigureDevice(ESRI.ArcGIS.Geodatabase.IFeature feature, int inputPorts, int outputPorts, bool isExistingOperation)
        {
            bool   isComplete         = false;
            bool   isOurOperationOpen = false;
            string deviceIpid         = string.Empty;

            #region Validation

            string missingFieldFormat = "Field {0} is missing.";

            // The following will be set during Validation
            ESRI.ArcGIS.Geodatabase.IObjectClass ftClass = null;
            ESRI.ArcGIS.Geodatabase.IFields      fields  = null;

            ftClass = feature.Class;
            fields  = ftClass.Fields;

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

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

            if (0 > inputPorts)
            {
                throw new ArgumentOutOfRangeException("inputPorts");
            }

            if (0 > outputPorts)
            {
                throw new ArgumentOutOfRangeException("outputPorts");
            }

            int ipidIdx = fields.FindField(ConfigUtil.IpidFieldName);
            if (-1 == ipidIdx)
            {
                throw new InvalidOperationException(string.Format(missingFieldFormat, ConfigUtil.IpidFieldName));
            }

            int inPortsIdx = fields.FindField(ConfigUtil.InputPortsFieldName);
            if (-1 == inPortsIdx)
            {
                throw new InvalidOperationException(string.Format(missingFieldFormat, ConfigUtil.InputPortsFieldName));
            }

            int outPortsIdx = fields.FindField(ConfigUtil.OutputPortsFieldName);
            if (-1 == outPortsIdx)
            {
                throw new InvalidOperationException(string.Format(missingFieldFormat, ConfigUtil.OutputPortsFieldName));
            }

            #endregion

            // Are we RE-configuring?
            //            int? oldInputPorts = GdbUtils.GetDomainedIntName(feature, ConfigUtil.InputPortsFieldName);
            //            int? oldOutputPorts = GdbUtils.GetDomainedIntName(feature, ConfigUtil.OutputPortsFieldName);

            //            int inputPortDifference = oldInputPorts.HasValue ? Math.Abs(inputPorts - oldInputPorts.Value) : inputPorts;
            //            int outputPortDifference = oldOutputPorts.HasValue ? Math.Abs(outputPorts - oldOutputPorts.Value) : outputPorts;

            ESRI.ArcGIS.esriSystem.ITrackCancel    trackCancel    = new ESRI.ArcGIS.Display.CancelTrackerClass();
            ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog = _hookHelper.CreateProgressDialog(trackCancel, "Configuring device...", 1, inputPorts + outputPorts, 1, "Starting edit operation...", "Device Configuration");
            //            ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog = CreateProgressDialog(trackCancel, "Configuring device...", 1, inputPortDifference + outputPortDifference + 2, 1, "Starting edit operation...", "Device Configuration");
            ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = (ESRI.ArcGIS.esriSystem.IStepProgressor)progressDialog;

            progressDialog.ShowDialog();
            stepProgressor.Step();

            if (!isExistingOperation)
            {
                try
                {
                    _editor.StartOperation();
                    isOurOperationOpen = true;
                }
                catch (Exception ex)
                {
                    throw new Exception("Failed to start edit operation.", ex);
                }
            }

            try
            {
                feature.set_Value(inPortsIdx, inputPorts);
                feature.set_Value(outPortsIdx, outputPorts);

                if (DBNull.Value == feature.get_Value(ipidIdx))
                {
                    Guid g = Guid.NewGuid();
                    deviceIpid = g.ToString("B").ToUpper();
                    feature.set_Value(ipidIdx, deviceIpid);
                }
                else
                {
                    deviceIpid = feature.get_Value(ipidIdx).ToString();
                }

                //                if (!oldOutputPorts.HasValue && !oldInputPorts.HasValue)
                //                {
                isComplete = GeneratePorts(feature, 1, inputPorts, 1, outputPorts, progressDialog, trackCancel);
                //                }
                //                else
                //                {
                //                    bool additionsComplete = false;
                //                    bool deletionsComplete = false;
                //
                //                    additionsComplete = GeneratePorts(feature, oldInputPorts.Value + 1, oldInputPorts.Value + inputPortDifference, oldOutputPorts.Value + 1, oldOutputPorts.Value + outputPortDifference, progressDialog, trackCancel);
                //                    deletionsComplete = DeletePorts(feature, inputPorts, outputPorts, progressDialog, trackCancel);
                //
                //                    isComplete = additionsComplete && deletionsComplete;
                //                }

                if (isComplete)
                {
                    stepProgressor.Message = "Finishing configuration...";
                    stepProgressor.Step();

                    if (isOurOperationOpen)
                    {
                        feature.Store();
                        _editor.StopOperation("Configure Device");
                    }
                }
                else
                {
                    stepProgressor.Message = "Cancelling configuration...";
                    stepProgressor.Step();

                    if (isOurOperationOpen)
                    {
                        _editor.AbortOperation();
                    }
                }
            }
            catch
            {
                if (isOurOperationOpen)
                {
                    _editor.AbortOperation();
                }
            }

            if (null != progressDialog)
            {
                progressDialog.HideDialog();
            }

            return(isComplete);
        }
        ///// <summary>
        ///// The active view has refreshed. Redraw our results, if we have any
        ///// </summary>
        ///// <param name="Display">Display to draw on</param>
        ///// <param name="phase"></param>
        //private void _arcMapWrapper_ActiveViewAfterDraw(ESRI.ArcGIS.Display.IDisplay Display, ESRI.ArcGIS.Carto.esriViewDrawPhase phase)
        //{
        //    if (phase == ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection)
        //    {
        //        // Draw after the selection
        //        if (null != _currentResults)
        //        {
        //            ESRI.ArcGIS.Display.ILineSymbol lineSymbol = new ESRI.ArcGIS.Display.SimpleLineSymbol();
        //            ESRI.ArcGIS.Display.IRgbColor color = new ESRI.ArcGIS.Display.RgbColorClass();
        //            color.Red = 255;
        //            color.Green = 0;
        //            color.Blue = 0;

        //            lineSymbol.Color = color;
        //            lineSymbol.Width = 4;

        //            ESRI.ArcGIS.Display.ISimpleMarkerSymbol markerSymbol = new ESRI.ArcGIS.Display.SimpleMarkerSymbolClass();
        //            markerSymbol.Color = color;
        //            markerSymbol.Style = ESRI.ArcGIS.Display.esriSimpleMarkerStyle.esriSMSCircle;
        //            markerSymbol.Size = 6;

        //            for (int i = 0; i < _currentResults.Count; i++)
        //            {
        //                ESRI.ArcGIS.Geometry.IGeometry geometry = _currentResults[i];
        //                if (geometry is ESRI.ArcGIS.Geometry.IPolyline)
        //                {
        //                    Display.SetSymbol((ESRI.ArcGIS.Display.ISymbol)lineSymbol);
        //                    Display.DrawPolyline((ESRI.ArcGIS.Geometry.IPolyline)geometry);
        //                }
        //                else if (geometry is ESRI.ArcGIS.Geometry.IPoint)
        //                {
        //                    Display.SetSymbol((ESRI.ArcGIS.Display.ISymbol)markerSymbol);
        //                    Display.DrawPoint((ESRI.ArcGIS.Geometry.IPoint)geometry);
        //                }
        //            }
        //        }
        //    }
        //}

        private List <ESRI.ArcGIS.Geodatabase.IRow> TracePath(ESRI.ArcGIS.Geodatabase.IFeature cableFeature, int fiberNumber, bool isStartingAtFromEnd)
        {
            List <ESRI.ArcGIS.Geodatabase.IRow> result = new List <ESRI.ArcGIS.Geodatabase.IRow>();

            string ipid = cableFeature.get_Value(cableFeature.Fields.FindField(ConfigUtil.IpidFieldName)).ToString();

            ESRI.ArcGIS.Geodatabase.IFeatureClass cableFtClass = (ESRI.ArcGIS.Geodatabase.IFeatureClass)cableFeature.Class;

            ESRI.ArcGIS.Geodatabase.IFeatureClass spliceFtClass    = _wkspHelper.FindFeatureClass(ConfigUtil.SpliceClosureFtClassName);
            ESRI.ArcGIS.Geodatabase.ITable        fiberSpliceTable = _wkspHelper.FindTable(ConfigUtil.FiberSpliceTableName);

            ESRI.ArcGIS.Geodatabase.IFields spliceFields = fiberSpliceTable.Fields;

            string fiberClassName = ConfigUtil.FiberTableName;

            ESRI.ArcGIS.Geodatabase.IRelationshipClass fiberRelationship = GdbUtils.GetRelationshipClass(cableFtClass, ConfigUtil.FiberCableToFiberRelClassName);
            if (null != fiberRelationship && null != fiberRelationship.DestinationClass)
            {
                fiberClassName = GdbUtils.ParseTableName(fiberRelationship.DestinationClass as ESRI.ArcGIS.Geodatabase.IDataset);
            }

            ESRI.ArcGIS.Geodatabase.ITable fiberTable = _wkspHelper.FindTable(fiberClassName);

            _aCableIdx            = spliceFields.FindField(ConfigUtil.ACableIdFieldName);
            _bCableIdx            = spliceFields.FindField(ConfigUtil.BCableIdFieldName);
            _aFiberNumIdx         = spliceFields.FindField(ConfigUtil.AFiberNumberFieldName);
            _bFiberNumIdx         = spliceFields.FindField(ConfigUtil.BFiberNumberFieldName);
            _isAFromIdx           = spliceFields.FindField(ConfigUtil.IsAFromEndFieldName);
            _isBFromIdx           = spliceFields.FindField(ConfigUtil.IsBFromEndFieldName);
            _spliceClosureIpidIdx = spliceFields.FindField(ConfigUtil.SpliceClosureIpidFieldName);

            ESRI.ArcGIS.Geodatabase.IQueryFilter spliceFilter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass();
            spliceFilter.WhereClause = string.Format("({0}='{1}' AND {2}={3})"
                                                     + " OR ({4}='{1}' AND {5}={3})",
                                                     ConfigUtil.ACableIdFieldName,
                                                     ipid,
                                                     ConfigUtil.AFiberNumberFieldName,
                                                     fiberNumber,
                                                     ConfigUtil.BCableIdFieldName,
                                                     ConfigUtil.BFiberNumberFieldName);

            int connections = fiberSpliceTable.RowCount(spliceFilter);

            if (2 < connections)
            {
                // TODO: warning?
                System.Windows.Forms.MessageBox.Show("Less than 2 connections were detected: " + fiberNumber, "Telecom Trace", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
            }

            string spliceClosureIpid = string.Empty;
            string nextCableId       = string.Empty;
            int    nextFiberNumber   = -1;
            bool   isNextFromEnd     = false;

            // {{0}} causes the string.format to
            string cableWhereFormat  = string.Format("{0}='{{0}}'", ConfigUtil.IpidFieldName);
            string spliceWhereFormat = string.Format("{0}='{{0}}'", ConfigUtil.IpidFieldName);
            string fiberWhereFormat  = string.Format("{0}='{{0}}' AND {1}={{1}}", fiberRelationship.OriginForeignKey, ConfigUtil.Fiber_NumberFieldName);

            using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser())
            {
                ESRI.ArcGIS.Geodatabase.IQueryFilter filter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass();
                releaser.ManageLifetime(filter);

                // Ripple down the start cable's to end
                ESRI.ArcGIS.Geodatabase.IRow spliceRow = GetNextSplice(fiberSpliceTable, ipid, fiberNumber, isStartingAtFromEnd, out nextCableId, out nextFiberNumber, out spliceClosureIpid, out isNextFromEnd);
                while (null != spliceRow)
                {
                    ESRI.ArcGIS.Geodatabase.IFeature spliceClosure = null;

                    if (spliceClosureIpid.Equals(""))
                    {
                        System.Windows.Forms.MessageBox.Show("Found Splice with no SpliceClosure (ID/#) " + nextCableId + "/" + nextFiberNumber, "Telecom Trace", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                    }
                    else
                    {
                        filter.WhereClause = string.Format(spliceWhereFormat, spliceClosureIpid);
                        ESRI.ArcGIS.Geodatabase.IFeatureCursor spliceCursor = spliceFtClass.Search(filter, false);
                        releaser.ManageLifetime(spliceCursor);
                        spliceClosure = spliceCursor.NextFeature();
                        if (spliceClosure == null)
                        {
                            System.Windows.Forms.MessageBox.Show("Invalid SpliceClosure referenced: (IPID)" + spliceClosureIpid, "Telecom Trace", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                        }
                    }

                    filter.WhereClause = string.Format(cableWhereFormat, nextCableId);
                    ESRI.ArcGIS.Geodatabase.IFeatureCursor cableCursor = cableFtClass.Search(filter, false);
                    releaser.ManageLifetime(cableCursor);
                    ESRI.ArcGIS.Geodatabase.IFeature cable = cableCursor.NextFeature();
                    if (cable == null)
                    {
                        System.Windows.Forms.MessageBox.Show("Invalid cable ID referenced: (ID)" + nextCableId, "Telecom Trace", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                    }

                    filter.WhereClause = string.Format(fiberWhereFormat, nextCableId, nextFiberNumber);
                    ESRI.ArcGIS.Geodatabase.ICursor fiberCursor = fiberTable.Search(filter, false);
                    releaser.ManageLifetime(fiberCursor);
                    ESRI.ArcGIS.Geodatabase.IRow fiber = fiberCursor.NextRow();
                    if (fiber == null)
                    {
                        System.Windows.Forms.MessageBox.Show("Invalid Fiber Cable or # referenced: (ID/#) " + nextCableId + "/" + nextFiberNumber, "Telecom Trace", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                    }

                    if (isStartingAtFromEnd)
                    {
                        if (spliceRow != null)
                        {
                            result.Add(spliceRow);
                        }
                        if (spliceClosure != null)
                        {
                            result.Add(spliceClosure);
                        }
                        if (fiber != null)
                        {
                            result.Add(fiber);
                        }
                        if (cable != null)
                        {
                            result.Add(cable);
                        }
                    }
                    else
                    {
                        if (spliceClosure != null)
                        {
                            result.Add(spliceClosure);
                        }
                        if (spliceRow != null)
                        {
                            result.Add(spliceRow);
                        }
                        if (cable != null)
                        {
                            result.Add(cable);
                        }
                        if (fiber != null)
                        {
                            result.Add(fiber);
                        }
                    }

                    spliceRow = GetNextSplice(fiberSpliceTable, nextCableId, nextFiberNumber, !isNextFromEnd, out nextCableId, out nextFiberNumber, out spliceClosureIpid, out isNextFromEnd);
                }

                // See if there is a port for this one
                ESRI.ArcGIS.Geodatabase.IRow     portRow  = null;
                ESRI.ArcGIS.Geodatabase.IFeature deviceFt = null;
                if (GetConnectedPort(cableFtClass, nextCableId, nextFiberNumber, isNextFromEnd, out portRow, out deviceFt))
                {
                    if (isStartingAtFromEnd)
                    {
                        result.Add(portRow);
                        result.Add(deviceFt);
                    }
                    else
                    {
                        result.Add(deviceFt);
                        result.Add(portRow);
                    }
                }

                return(result);
            }
        }
예제 #7
0
        public static IFeatureClass CreateFeatureClassInPGDB(IWorkspace2 workspace, IFeatureDataset featureDataset, string featureClassName, IFields fields, UID CLSID, UID CLSEXT, string strConfigKeyword, esriGeometryType esriGeometryType)
        {
            if (featureClassName == "")
            {
                return(null);                        // name was not passed in
            }
            ESRI.ArcGIS.Geodatabase.IFeatureClass     featureClass;
            ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explicit Cast
            if (workspace.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureClass, featureClassName))        //feature class with that name already exists
            {
                featureClass = featureWorkspace.OpenFeatureClass(featureClassName);
                return(featureClass);
            }


            // assign the class id value if not assigned

            if (CLSID == null)
            {
                CLSID       = new ESRI.ArcGIS.esriSystem.UIDClass();
                CLSID.Value = "esriGeoDatabase.Feature";
            }

            ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.FeatureClassDescriptionClass();


            // if a fields collection is not passed in then supply our own

            if (fields == null)
            {
                // create the fields using the required fields method

                fields = objectClassDescription.RequiredFields;

                ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast
                ESRI.ArcGIS.Geodatabase.IField      field      = new ESRI.ArcGIS.Geodatabase.FieldClass();

                // create a user defined text field
                ESRI.ArcGIS.Geodatabase.IFieldEdit fieldEdit = (ESRI.ArcGIS.Geodatabase.IFieldEdit)field; // Explicit Cast

                // setup field properties
                fieldEdit.Name_2         = "SampleField";
                fieldEdit.Type_2         = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString;
                fieldEdit.IsNullable_2   = true;
                fieldEdit.AliasName_2    = "Sample Field Column";
                fieldEdit.DefaultValue_2 = "test";
                fieldEdit.Editable_2     = true;
                fieldEdit.Length_2       = 100;

                // add field to field collection
                fieldsEdit.AddField(field);
                fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit; // Explicit Cast
            }

            System.String strShapeField = "";

            // locate the shape field
            for (int j = 0; j < fields.FieldCount; j++)
            {
                if (fields.get_Field(j).Type == esriFieldType.esriFieldTypeGeometry)
                {
                    strShapeField = fields.get_Field(j).Name;
                    ((IGeometryDefEdit)fields.get_Field(j).GeometryDef).GeometryType_2 = esriGeometryType;
                }
            }

            // Use IFieldChecker to create a validated fields collection.
            ESRI.ArcGIS.Geodatabase.IFieldChecker   fieldChecker    = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass();
            ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError  = null;
            ESRI.ArcGIS.Geodatabase.IFields         validatedFields = null;
            fieldChecker.ValidateWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)workspace;
            fieldChecker.Validate(fields, out enumFieldError, out validatedFields);
            // The enumFieldError enumerator can be inspected at this point to determine
            // which fields were modified during validation.

            // finally create and return the feature class

            if (featureDataset == null)// if no feature dataset passed in, create at the workspace level
            {
                featureClass = featureWorkspace.CreateFeatureClass(featureClassName, validatedFields, CLSID, CLSEXT, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, strShapeField, strConfigKeyword);
            }
            else
            {
                featureClass = featureDataset.CreateFeatureClass(featureClassName, validatedFields, CLSID, CLSEXT, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, strShapeField, strConfigKeyword);
            }
            return(featureClass);
        }