コード例 #1
0
 public static void RelateTableLayer(ILayer pSrcLayer, string pSrcFieldName, ITable pToTable, string pToFieldName)
 {
     try
     {
         IAttributeTable table = pSrcLayer as IAttributeTable;
         if (table != null)
         {
             ITable attributeTable = table.AttributeTable;
             if (pToTable is IStandaloneTable)
             {
                 pToTable = (pToTable as IStandaloneTable).Table;
             }
             IMemoryRelationshipClassFactory factory = new MemoryRelationshipClassFactoryClass();
             IRelationshipClass relationshipClass    = factory.Open("TabletoLayer", (IObjectClass)pToTable,
                                                                    pToFieldName, (IObjectClass)attributeTable, pSrcFieldName, "forward", "backward",
                                                                    esriRelCardinality.esriRelCardinalityOneToMany);
             ((IRelationshipClassCollectionEdit)pSrcLayer).AddRelationshipClass(relationshipClass);
         }
     }
     catch (COMException exception)
     {
         MessageBox.Show(exception.Message, "COM Error: " + exception.ErrorCode.ToString(), MessageBoxButtons.OK,
                         MessageBoxIcon.Exclamation);
     }
     catch (Exception exception2)
     {
         MessageBox.Show(exception2.Message, ".NET Error: ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }
コード例 #2
0
ファイル: BaseRelationshipAU.cs プロジェクト: wey12138/Wave
        /// <summary>
        ///     Gets whether the specified AU is enabled.
        /// </summary>
        /// <param name="pRelClass">The relationship class.</param>
        /// <param name="eEvent">The edit event.</param>
        /// <returns><c>true</c> if this AutoUpdater is enabled; otherwise <c>false</c></returns>
        public bool get_Enabled(IRelationshipClass pRelClass, mmEditEvent eEvent)
        {
            try
            {
                if (pRelClass == null)
                {
                    return(false);
                }

                return(this.InternalEnabled(pRelClass, pRelClass.OriginClass, pRelClass.DestinationClass, eEvent));
            }
            catch (Exception e)
            {
                if (MinerRuntimeEnvironment.IsUserInterfaceSupported)
                {
                    Log.Error("Error Enabling Relationship AU " + Name, e);
                }
                else
                {
                    Log.Error(e);
                }
            }

            return(false);
        }
コード例 #3
0
 public static void RelateTableLayer(ILayer ilayer_0, string string_0, ITable itable_0, string string_1)
 {
     try
     {
         IAttributeTable table = ilayer_0 as IAttributeTable;
         if (table != null)
         {
             ITable attributeTable = table.AttributeTable;
             if (itable_0 is IStandaloneTable)
             {
                 itable_0 = (itable_0 as IStandaloneTable).Table;
             }
             IMemoryRelationshipClassFactory factory = new MemoryRelationshipClassFactoryClass();
             IRelationshipClass relationshipClass    = factory.Open("TabletoLayer", (IObjectClass)itable_0,
                                                                    string_1, (IObjectClass)attributeTable, string_0, "forward", "backward",
                                                                    esriRelCardinality.esriRelCardinalityOneToMany);
             ((IRelationshipClassCollectionEdit)ilayer_0).AddRelationshipClass(relationshipClass);
         }
     }
     catch (COMException exception)
     {
         MessageBox.Show(exception.Message, "COM Error: " + exception.ErrorCode.ToString(), MessageBoxButtons.OK,
                         MessageBoxIcon.Exclamation);
     }
     catch (Exception exception2)
     {
         MessageBox.Show(exception2.Message, ".NET Error: ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RelationshipClassJoinDefinition"/> class.
        /// </summary>
        /// <param name="relClass">The relationship class.</param>
        /// <param name="joinType">The join type.</param>
        /// <param name="baseFeatureClass">The primary feature class containing the shape field
        /// in for joins between two feature classes. In the case of an outer join it must not be
        /// on the outer side, i.e. no null values must exist in the base feature class side.</param>
        internal RelationshipClassJoinDefinition(
            [NotNull] IRelationshipClass relClass,
            JoinType joinType,
            [CanBeNull] IFeatureClass baseFeatureClass = null)
            : base(joinType)
        {
            Assert.ArgumentNotNull(relClass, nameof(relClass));

            _relClass = relClass;

            if (baseFeatureClass == null)
            {
                _tableNames = GetTableNames(relClass, out _baseFeatureClass,
                                            out _featureClassCount);
            }
            else
            {
                _baseFeatureClass = baseFeatureClass;

                Assert.True(IsInvolvedFeatureClass(baseFeatureClass, relClass),
                            "The base feature class must participate in the relationship class");

                _tableNames = GetTableNames(relClass, baseFeatureClass, joinType,
                                            out _featureClassCount);
            }
        }
コード例 #5
0
ファイル: clsSupportTable.cs プロジェクト: ESOmenium/AIS
        /// <summary>
        /// Creates relationship classes between the Broadcast feature class and the Voyage and Vessel tables.
        /// </summary>
        /// <param name="pWorkspace">FileGeodatabase workspace.</param>
        public void CreateRelationshipClass(IWorkspace pWorkspace)
        {
            try
            {
                if (!(IsArcInfoLicense()))
                {
                    return;
                }

                IFeatureWorkspace pFWS = (IFeatureWorkspace)pWorkspace;

                // Creating a relationship class without an intermediate table.
                IObjectClass pOriginClass = (IObjectClass)pFWS.OpenFeatureClass("Broadcast");
                IObjectClass pVesselClass = (IObjectClass)pFWS.OpenTable("Vessel");
                IObjectClass pVoyageClass = (IObjectClass)pFWS.OpenTable("Voyage");

                IRelationshipClass pVesselRClass = pFWS.CreateRelationshipClass("BroadcastHasVessel", pOriginClass, pVesselClass, "Vessel",
                                                                                "Broadcast", esriRelCardinality.esriRelCardinalityOneToOne, esriRelNotification.esriRelNotificationBoth, false,
                                                                                false, null, "MMSI", "", "MMSI", "");

                IRelationshipClass pVoyageRClass = pFWS.CreateRelationshipClass("BroadcastHasVoyage", pOriginClass, pVoyageClass, "Voyage",
                                                                                "Broadcast", esriRelCardinality.esriRelCardinalityOneToOne, esriRelNotification.esriRelNotificationBoth, false,
                                                                                false, null, "VoyageID", "", "VoyageID", "");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
コード例 #6
0
        // TODO: Is this a static Utils class? Or does each IAttributes implementation have
        // its specific AttributeHarvester? Or will there be a DatasetHarvester/ModelHarvester
        // that can create instances of this class (for the right IAttributes implementation)
        // in order to more loosely couple them with the domain classes?

        //private readonly IAttributes _attributeContainer;

        //public AttributeHarvester(IAttributes attributeContainer)
        //{
        //	_attributeContainer = attributeContainer;
        //}

        #region AttributedAssociation Attribute harvesting

        public static void HarvestAttributes([NotNull] AttributedAssociation attributedAssociation)
        {
            // TODO: support for configurator?

            attributedAssociation.ClearAttributeMaps();

            using (_msg.IncrementIndentation(
                       "Harvesting attributes for attributed association {0}", attributedAssociation.Name))
            {
                const bool         allowAlways       = true;
                IRelationshipClass relationshipClass =
                    ModelElementUtils.TryOpenFromMasterDatabase(attributedAssociation, allowAlways);
                Assert.NotNull(relationshipClass,
                               "Relationship class not found in model master database: {0}",
                               attributedAssociation.Name);
                var table = (ITable)relationshipClass;

                IList <IField> fields = DatasetUtils.GetFields(table);

                for (var fieldIndex = 0; fieldIndex < fields.Count; fieldIndex++)
                {
                    IField field = fields[fieldIndex];

                    AddOrUpdateAttribute(attributedAssociation, field, fieldIndex);
                }

                DeleteAttributesNotInList(attributedAssociation, fields);

                attributedAssociation.ClearAttributeMaps();
            }
        }
コード例 #7
0
        private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            //在地块图层获得关系类
            IFeatureClass          pFeatClass             = pParcelFeatLayer.FeatureClass;
            IObjectClass           pObjectClass           = pFeatClass as IObjectClass;
            IEnumRelationshipClass pEnumRelationshipClass = pObjectClass.get_RelationshipClasses(esriRelRole.esriRelRoleOrigin);

            pEnumRelationshipClass.Reset();
            IRelationshipClass pRelationshipClass = pEnumRelationshipClass.Next();
            IRow         pOwnerRow;
            IFeature     pParcelFeature;
            AxMapControl axMap = pMainFrm.getMapControl();

            for (int i = 0; i <= pFeatArray.Count - 1; i++)
            {
                pParcelFeature = pFeatArray.get_Element(i) as IFeature;
                ISet pRelatedSet = pRelationshipClass.GetObjectsRelatedToObject(pParcelFeature);
                pRelatedSet.Reset();
                pOwnerRow = pRelatedSet.Next() as IRow;

                if (pOwnerRow != null)
                {
                    if (pOwnerRow.get_Value(pOwnerRow.Fields.FindField("TMK")).ToString() == e.Item.Text)
                    {
                        Utility.FlashFeature(pParcelFeature, axMap.ActiveView.FocusMap);
                        break;
                    }
                }
            }
        }
コード例 #8
0
        private static IFeatureWorkspace CreateTestWorkspace(
            [NotNull] string fgdbName,
            [NotNull] string fcName, [NotNull] string tableName, [NotNull] string relClassName,
            [NotNull] out IFeatureClass fc,
            [NotNull] out ITable table,
            [NotNull] out IRelationshipClass rc)
        {
            IFeatureWorkspace ws = TestWorkspaceUtils.CreateTestFgdbWorkspace(fgdbName);

            ISpatialReference sref = SpatialReferenceUtils.CreateSpatialReference(
                (int)esriSRProjCS2Type.esriSRProjCS_CH1903Plus_LV95, true);

            fc = DatasetUtils.CreateSimpleFeatureClass(
                ws, fcName, null,
                FieldUtils.CreateOIDField(),
                FieldUtils.CreateIntegerField("FKEY"),
                FieldUtils.CreateShapeField(
                    "SHAPE", esriGeometryType.esriGeometryPoint,
                    sref, 1000));

            table = DatasetUtils.CreateTable(ws, tableName,
                                             FieldUtils.CreateOIDField(),
                                             FieldUtils.CreateTextField("TEXT", 100));

            rc = TestWorkspaceUtils.CreateSimple1NRelationship(
                ws, relClassName,
                table, (ITable)fc,
                table.OIDFieldName, "FKEY");

            return(ws);
        }
コード例 #9
0
ファイル: AddRelationshipAU.cs プロジェクト: wey12138/Wave
        /// <summary>
        ///     Executes the geoprocessing function using the given array of parameter values.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <param name="trackCancel">The track cancel.</param>
        /// <param name="environmentManager">Provides access to all the current environments and settings of the current client.</param>
        /// <param name="messages">The messages that are reported to the user.</param>
        /// <param name="utilities">
        ///     The utilities object that provides access to the properties and methods of a geoprocessing
        ///     objects.
        /// </param>
        protected override void Execute(Dictionary <string, IGPValue> parameters, ITrackCancel trackCancel, IGPEnvironmentManager environmentManager, IGPMessages messages, IGPUtilities2 utilities)
        {
            IGPValue           value    = parameters["in_table"];
            IRelationshipClass relClass = utilities.OpenRelationshipClass(value);

            if (relClass != null)
            {
                IMMConfigTopLevel configTopLevel = ConfigTopLevel.Instance;
                configTopLevel.Workspace = utilities.GetWorkspace(value);

                IGPMultiValue onCreate = (IGPMultiValue)parameters["in_create"];
                IGPMultiValue onDelete = (IGPMultiValue)parameters["in_delete"];

                var uids = new Dictionary <mmEditEvent, IEnumerable <IUID> >();
                uids.Add(mmEditEvent.mmEventRelationshipCreated, onCreate.AsEnumerable().Cast <IGPAutoValue>().Select(o => o.UID));
                uids.Add(mmEditEvent.mmEventRelationshipDeleted, onDelete.AsEnumerable().Cast <IGPAutoValue>().Select(o => o.UID));

                // Update the list to have these UIDs.
                ID8List list = (ID8List)configTopLevel.GetRelationshipClass(relClass);
                base.Add(uids, list, messages);

                // Commit the changes to the database.
                configTopLevel.SaveRelationshipClasstoDB(relClass);

                // Success.
                parameters["out_results"].SetAsText("true");
            }
            else
            {
                // Failure.
                parameters["out_results"].SetAsText("false");
            }
        }
コード例 #10
0
ファイル: LayerInfo.cs プロジェクト: MadhavKrishna/MXDReader
        private void processRelates(IFeatureLayer flyr)
        {
            string res          = "";
            string destName     = "";
            string destServer   = "";
            string destInstance = "";
            string destUser     = "";
            IRelationshipClassCollection relClassColl = (IRelationshipClassCollection)flyr;
            IEnumRelationshipClass       enumRelClass = relClassColl.RelationshipClasses;

            enumRelClass.Reset();
            IRelationshipClass relClass = enumRelClass.Next();

            while (relClass != null)
            {
                IDataset dset      = (IDataset)relClass;
                ITable   destTable = (ITable)relClass.DestinationClass;
                IDataset dsetDest  = (IDataset)destTable;
                destName     = dsetDest.Name;
                destServer   = dsetDest.Workspace.ConnectionProperties.GetProperty("server").ToString();
                destInstance = dsetDest.Workspace.ConnectionProperties.GetProperty("instance").ToString();
                destUser     = dsetDest.Workspace.ConnectionProperties.GetProperty("user").ToString();
                res          = res + "(" + destName + "/" + destServer + "/" + destInstance + "/" + destUser + "/" + relClass.OriginPrimaryKey + "/" + relClass.OriginForeignKey + "/" + dset.BrowseName + ")";
                relClass     = enumRelClass.Next();
            }

            relateinfo = res;
        }
コード例 #11
0
ファイル: Table.cs プロジェクト: wenwen195/GisClassDemo
        /// <summary>
        /// Join Urban-rural Devide Table
        /// </summary>
        /// <param name="layer"></param>
        /// <param name="year"></param>
        /// <author>Shen Yongyuan</author>
        /// <date>20091111</date>
        public static void JoinDevideTable(ILayer layer, int year, string city)
        {
            //Add Fields
            IFieldsEdit allFields = new FieldsClass();
            IFieldEdit  field1    = new FieldClass();

            field1.Name_2 = "ID";
            field1.Type_2 = esriFieldType.esriFieldTypeString;
            allFields.AddField(field1);
            IFieldEdit field2 = new FieldClass();

            field2.Name_2 = Town.Constant.Constant.TmpFieldName;
            field2.Type_2 = esriFieldType.esriFieldTypeString;
            allFields.AddField(field2);

            //Create Table
            IWorkspaceFactory workspaceFactory = new InMemoryWorkspaceFactoryClass();
            IWorkspaceName    workspaceName    = workspaceFactory.Create("", "Temporary WorkSpace In Memory", null, 0);
            IFeatureWorkspace workspace        = ((IName)workspaceName).Open() as IFeatureWorkspace;
            ITable            table            = workspace.CreateTable(Town.Constant.Constant.TmpTableDevide, allFields, null, null, "");

            //Import Data
            IWorkspaceEdit workspaceEdit = workspace as IWorkspaceEdit;

            workspaceEdit.StartEditing(false);
            workspaceEdit.StartEditOperation();
            ICursor cursor    = table.Insert(true);
            int     fldField1 = cursor.Fields.FindField("ID");
            int     fldField2 = cursor.Fields.FindField(Town.Constant.Constant.TmpFieldName);


            //Query and Import
            Dictionary <int, string> devideResult = DataLib.DA_Devide.GetDevideResult(year, city);

            foreach (KeyValuePair <int, string> d in devideResult)
            {
                IRowBuffer buffer = table.CreateRowBuffer();
                buffer.set_Value(fldField1, d.Key.ToString());
                buffer.set_Value(fldField2, d.Value);
                cursor.InsertRow(buffer);
            }

            cursor.Flush();
            workspaceEdit.StartEditOperation();
            workspaceEdit.StopEditing(true);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor);

            //Join
            IMemoryRelationshipClassFactory pMemRelFact = new MemoryRelationshipClassFactory();
            IFeatureLayer      feaLayer    = layer as IFeatureLayer;
            ITable             originTable = feaLayer.FeatureClass as ITable;
            IRelationshipClass pRelClass   = pMemRelFact.Open("Join", originTable as IObjectClass, "ID",
                                                              table as IObjectClass, "ID", "forward", "backward",
                                                              esriRelCardinality.esriRelCardinalityOneToOne);
            IDisplayRelationshipClass pDispRC = feaLayer as IDisplayRelationshipClass;

            pDispRC.DisplayRelationshipClass(null, esriJoinType.esriLeftOuterJoin);
            pDispRC.DisplayRelationshipClass(pRelClass, esriJoinType.esriLeftOuterJoin);
        }
コード例 #12
0
 public ITable OpenRelationshipQuery(IRelationshipClass pRelClass,
                                     bool joinForward,
                                     IQueryFilter pSrcQueryFilter,
                                     ISelectionSet pSrcSelectionSet,
                                     string TargetColumns, bool DoNotPushJoinToDB)
 {
     throw new NotImplementedException();
 }
コード例 #13
0
ファイル: QaUniqueTest.cs プロジェクト: sungaoyong/ProSuite
        private static void CanDetect1ToNUnique([NotNull] IFeatureWorkspace workspace)
        {
            const string uniqueFieldName = "Unique";

            ITable tableOrig;
            {
                IFieldsEdit fields = new FieldsClass();
                fields.AddField(FieldUtils.CreateOIDField());
                fields.AddField(FieldUtils.CreateField(
                                    uniqueFieldName, esriFieldType.esriFieldTypeInteger));
                ITable table = TestWorkspaceUtils.CreateSimpleTable(
                    workspace, "Relate1NUnique1", fields);
                for (var i = 0; i < 10; i++)
                {
                    IRow row = table.CreateRow();
                    row.set_Value(1, i);
                    row.Store();
                }

                tableOrig = table;
            }
            ITable tableRel;
            {
                IFieldsEdit fields = new FieldsClass();
                fields.AddField(FieldUtils.CreateOIDField());
                fields.AddField(FieldUtils.CreateField(
                                    "Ref", esriFieldType.esriFieldTypeInteger));
                ITable table = TestWorkspaceUtils.CreateSimpleTable(
                    workspace, "Relate1NUnique2", fields);
                for (var i = 0; i < 10; i++)
                {
                    IRow row = table.CreateRow();
                    row.set_Value(1, i);
                    row.Store();
                }

                tableRel = table;
            }
            IRelationshipClass rel =
                TestWorkspaceUtils.CreateSimple1NRelationship(workspace,
                                                              "rel1NUnique", tableOrig,
                                                              tableRel, uniqueFieldName, "Ref");

            ITable relTab = TableJoinUtils.CreateQueryTable(rel, JoinType.InnerJoin);

            foreach (bool forceInMemoryTableSort in new[] { true, false })
            {
                var test = new QaUnique(relTab, "Relate1NUnique1." + uniqueFieldName)
                {
                    ForceInMemoryTableSorting = forceInMemoryTableSort
                };

                var runner = new QaTestRunner(test);
                runner.Execute();
                AssertUtils.NoError(runner);
            }
        }
コード例 #14
0
        /// <summary>
        ///     Checks the validity of the <paramref name="relClass" /> is valid to have an intermediate table.
        /// </summary>
        /// <param name="relClass">The relationship class.</param>
        /// <returns>
        ///     Returns a <see cref="bool" /> representing if the relationship class is valid.
        /// </returns>
        private bool CheckValidity(IRelationshipClass relClass)
        {
            if (relClass.Cardinality != esriRelCardinality.esriRelCardinalityManyToMany || !relClass.IsAttributed)
            {
                return(false);
            }

            return(true);
        }
コード例 #15
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="IntermediateRelationship" /> class.
        /// </summary>
        /// <param name="relClass">The relationship class.</param>
        /// <exception cref="System.ArgumentException">
        ///     The relationship must either have attributes or many to many
        ///     cardinality.;relClass
        /// </exception>
        public IntermediateRelationship(IRelationshipClass relClass)
        {
            if (!CheckValidity(relClass))
            {
                throw new ArgumentException(@"The relationship must either have attributes or many to many cardinality.", "relClass");
            }

            this.RelationshipClass = relClass;
        }
コード例 #16
0
        private static IUniqueValueRenderer GenerateUniqueValueRenderer(IFeatureLayer featureLayer)
        {
            IFeatureWorkspace featureWorkspace = ((IDataset)featureLayer.FeatureClass).Workspace as IFeatureWorkspace;
            ITable            table            = featureWorkspace.OpenTable(TableName);

            string             relClassName = string.Format("{0}_{1}", ((IDataset)featureLayer.FeatureClass).Name, ((IDataset)table).Name);
            IRelationshipClass relClass     = featureWorkspace.OpenRelationshipClass(relClassName);

            IDisplayRelationshipClass displayRelClass = featureLayer as IDisplayRelationshipClass;

            if (displayRelClass == null)
            {
                return(null);
            }
            displayRelClass.DisplayRelationshipClass(relClass, esriJoinType.esriLeftOuterJoin);

            IUniqueValueRenderer uvRenderer = new UniqueValueRendererClass {
                FieldCount = 1
            };

            uvRenderer.Field[0] = string.Format("{0}.{1}", ((IDataset)table).Name, JoinField);

            IFeatureCursor      cursor         = ((IGeoFeatureLayer)featureLayer).SearchDisplayFeatures(null, true);
            DataStatisticsClass dataStatistics = new DataStatisticsClass
            {
                Field  = uvRenderer.Field[0],
                Cursor = cursor as ICursor
            };

            IEnumerator pEnumerator = dataStatistics.UniqueValues;

            pEnumerator.Reset();

            Random random = new Random();

            while (pEnumerator.MoveNext())
            {
                string value = Convert.ToString(pEnumerator.Current);

                RgbColorClass fillColor = new RgbColorClass
                {
                    Red   = random.Next(0, 255),
                    Green = random.Next(0, 255),
                    Blue  = random.Next(0, 255)
                };

                SimpleFillSymbolClass fillSymbol = new SimpleFillSymbolClass {
                    Color = fillColor
                };

                uvRenderer.AddValue(value, "ZONE", fillSymbol);
            }

            Marshal.ReleaseComObject(cursor);
            return(uvRenderer);
        }
コード例 #17
0
ファイル: IntermediateRow.cs プロジェクト: wey12138/Wave
        /// <summary>
        ///     Initializes a new instance of the <see cref="IntermediateRow" /> struct.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <param name="relClass">The relationship class.</param>
        public IntermediateRow(IRow row, IRelationshipClass relClass)
        {
            this.Row   = row;
            this.Items = new Dictionary <string, object>();

            ITable table = (ITable)relClass;

            this.OriginForeignKey      = TypeCast.Cast(row.get_Value(table.FindField(relClass.OriginForeignKey)), string.Empty);
            this.DestinationForeignKey = TypeCast.Cast(row.get_Value(table.FindField(relClass.DestinationForeignKey)), string.Empty);
        }
コード例 #18
0
ファイル: AnnotationUtils.cs プロジェクト: arcpad/epsgis
        /// <summary>
        /// 获取与标注对应的关联设备
        /// </summary>
        /// <param name="pAnnoFeature"></param>
        /// <returns></returns>
        public static IFeature GetLinkedFeature(IAnnotationFeature2 pAnnoFeature)
        {
            // 方法一
            IFeature               pFeature      = (IFeature)pAnnoFeature;
            IFeatureClass          pfClass       = (IFeatureClass)pFeature.Class;
            IEnumRelationshipClass pEnumRelation =
                pfClass.get_RelationshipClasses(esriRelRole.esriRelRoleAny);
            IRelationshipClass pRelationship = pEnumRelation.Next();

            if (pRelationship == null)
            {
                return(null);
            }

            ISet pSet = pRelationship.GetObjectsRelatedToObject(pFeature);

            if (pSet == null)
            {
                return(null);
            }

            object o = pSet.Next();

            if (o == null || !(o is IFeature))
            {
                return(null);
            }

            pFeature = (IFeature)o;
            return(pFeature);

            // 方法二

            /*
             * IFeature pFeature = (IFeature)pAnnoFeature;
             * IFeatureClass pfClass = (IFeatureClass)pFeature.Class;
             * IEnumRelationshipClass enumRelCls =
             *          pfClass.get_RelationshipClasses(esriRelRole.esriRelRoleAny);
             * IRelationshipClass pRelationship = enumRelCls.Next();
             * if (pRelationship == null)
             *  return null;
             *
             * // 注记的FeatureClass
             * IFeatureClass pDestionClass = (IFeatureClass)pRelationship.OriginClass;
             * if (pDestionClass == null)
             *  return null;
             *
             * string foreignKey = pRelationship.DestinationPrimaryKey;
             * if (string.IsNullOrEmpty(foreignKey))
             *  return null;
             *
             * pFeature = pDestionClass.GetFeature(pAnnoFeature.LinkedFeatureID);
             * return pFeature;
             */
        }
コード例 #19
0
        private static void TestNMRelation(IFeatureWorkspace ws)
        {
            IFieldsEdit fields1 = new FieldsClass();

            fields1.AddField(FieldUtils.CreateOIDField());
            fields1.AddField(FieldUtils.CreateIntegerField("Pk"));

            ITable tbl1 = DatasetUtils.CreateTable(ws, "TestNMRelation1", null, fields1);

            IFieldsEdit fields2 = new FieldsClass();

            fields2.AddField(FieldUtils.CreateOIDField());
            fields2.AddField(FieldUtils.CreateIntegerField("Fk"));

            ITable tbl2 = DatasetUtils.CreateTable(ws, "TestNMRelation2", null, fields2);

            IRelationshipClass rel = CreateSimpleMNRelationship(ws, "TestNMRelationRel", tbl1,
                                                                tbl2, "Pk", "Fk");

            ((IWorkspaceEdit)ws).StartEditing(false);
            IRow r11 = CreateRow(tbl1, 8);
            IRow r12 = CreateRow(tbl1, 12);
            IRow r13 = CreateRow(tbl1, 7);

            IRow r21 = CreateRow(tbl2, 9);
            IRow r22 = CreateRow(tbl2, 5);
            IRow r23 = CreateRow(tbl2, 4);

            Assert.NotNull(r12);             // not used otherwise

            rel.CreateRelationship((IObject)r11, (IObject)r21);
            rel.CreateRelationship((IObject)r11, (IObject)r23);
            rel.CreateRelationship((IObject)r13, (IObject)r22);

            r22.set_Value(1, 6);
            r22.Store();

            ((IWorkspaceEdit)ws).StopEditing(true);

            var test = new QaUnreferencedRows(tbl1,
                                              new[] { tbl2 },
                                              new[] { "pk,pk,TestNMRelationRel,fk,fk" });

            using (var r = new QaTestRunner(test))
            {
                r.Execute();
                Assert.AreEqual(2, r.Errors.Count);
            }

            var container = new QaContainerTestRunner(10000, test);

            container.Execute();
            Assert.AreEqual(2, container.Errors.Count);
        }
コード例 #20
0
        /// <summary>
        ///     Returns the many to many relationship (or intermediate table) that resides in between the origin and destination
        ///     classes.
        /// </summary>
        /// <param name="source">The relationship class that participates in a many to many relationship.</param>
        /// <returns>
        ///     Returns a <see cref="IIntermediateRelationship" /> representing the intermediate table (or many to many
        ///     relationship) that resides between
        ///     the many to many relationship.
        /// </returns>
        public static IIntermediateRelationship GetIntermediateRelationship(this IRelationshipClass source)
        {
            if (source == null)
            {
                return(null);
            }

            IIntermediateRelationship o = new IntermediateRelationship(source);

            return(o);
        }
コード例 #21
0
        private static ObjectAttribute GetOriginFK([NotNull] IRelationshipClass relClass,
                                                   [NotNull] IObjectDataset objectDataset)
        {
            ObjectAttribute originFK = objectDataset.GetAttribute(relClass.OriginForeignKey);

            Assert.NotNull(originFK, "origin foreign key not found on dataset {0}: {1}",
                           objectDataset.Name,
                           relClass.OriginForeignKey);

            return(originFK);
        }
コード例 #22
0
        /// <summary>
        ///     Implementation of enabled method for derived classes.
        /// </summary>
        /// <param name="relClass">The relelationship class.</param>
        /// <param name="originClass">The origin class.</param>
        /// <param name="destClass">The destination class.</param>
        /// <param name="editEvent">The edit event.</param>
        /// <returns>
        ///     <c>true</c> if this AutoUpdater is enabled; otherwise <c>false</c>
        /// </returns>
        /// <remarks>
        ///     This method will be called from IMMRelationshipAUStrategyEx::get_Enabled
        ///     and is wrapped within the exception handling for that method.
        /// </remarks>
        protected override bool InternalEnabled(IRelationshipClass relClass, IObjectClass originClass, IObjectClass destClass, mmEditEvent editEvent)
        {
            foreach (IMMRelationshipAUStrategy item in this.Items)
            {
                if (!item.get_Enabled(relClass, editEvent))
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #23
0
        /// <summary>
        ///     Creates a new relationship between the two specified objects.
        /// </summary>
        /// <param name="source">The relationship class that participates in a many to many relationship.</param>
        /// <param name="originObject">The origin object.</param>
        /// <param name="destinationObject">The destination object.</param>
        /// <param name="mode">The mode.</param>
        /// <returns>
        ///     Returns a <see cref="IRelationship" /> representing the relationship between the two objects.
        /// </returns>
        public static IRelationship CreateRelationship(this IRelationshipClass source, IObject originObject, IObject destinationObject, mmAutoUpdaterMode mode)
        {
            if (source == null)
            {
                return(null);
            }

            using (new AutoUpdaterModeReverter(mode))
            {
                return(source.CreateRelationship(originObject, destinationObject));
            }
        }
コード例 #24
0
        public static Association CreateAssociation(
            [NotNull] IRelationshipClass relClass,
            [NotNull] IObjectDataset destinationDataset,
            [NotNull] IObjectDataset originDataset,
            [NotNull] Model model)
        {
            bool unqualifyDatasetName = !model.HarvestQualifiedElementNames;

            string relClassName = DatasetUtils.GetName(relClass);

            AssociationCardinality cardinality = GetCardinality(relClass);
            ObjectAttribute        originPK    = GetOriginPK(relClass, originDataset);

            string associationName = !unqualifyDatasetName
                                                         ? relClassName
                                                         : ModelElementNameUtils.GetUnqualifiedName(relClassName);

            if (!relClass.IsAttributed &&
                relClass.Cardinality != esriRelCardinality.esriRelCardinalityManyToMany)
            {
                ObjectAttribute originFK = GetOriginFK(relClass,
                                                       destinationDataset);

                return(new ForeignKeyAssociation(associationName,
                                                 cardinality,
                                                 originFK,
                                                 originPK)
                {
                    Model = model
                });
            }

            ObjectAttribute destinationPK = GetDestinationPK(
                relClass, destinationDataset);

            var           relTable          = (ITable)relClass;
            esriFieldType destinationFKType = DatasetUtils.GetField(
                relTable,
                relClass.DestinationForeignKey).Type;
            esriFieldType originFKType = DatasetUtils.GetField(
                relTable, relClass.OriginForeignKey).Type;

            return(new AttributedAssociation(
                       associationName,
                       cardinality,
                       relClass.DestinationForeignKey, (FieldType)destinationFKType,
                       destinationPK,
                       relClass.OriginForeignKey, (FieldType)originFKType,
                       originPK)
            {
                Model = model
            });
        }
コード例 #25
0
 /// <summary>
 /// This function use the "OpenRelationshipClass" function to open a relationship class in the passed in workspace. Then the relationship class uses the
 /// "GetObjectsRelated" to return an ISet of the objects that are related to the specified input object.
 /// </summary>
 /// <param name="relatedTable">the relateionship table</param>
 /// <param name="obj">the object to find relationships for</param>
 /// <param name="fws">the feature workspace to work in</param>
 /// <returns>ISet of all relationships for passed in object</returns>
 public static ISet PerformRelatedObjectQuery(string relatedTable, IObject obj, IFeatureWorkspace fws)
 {
     try
     {
         IRelationshipClass pRelClass = fws.OpenRelationshipClass(relatedTable);
         return(pRelClass.GetObjectsRelatedToObject(obj));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
コード例 #26
0
ファイル: TableHelper.cs プロジェクト: eaglegis/FGTableSearch
        public void Refresh()
        {
            TableList.Clear();
            RelationLookup.Clear();
            IMap        aMap       = ArcMap.Document.FocusMap as IMap;
            IMapLayers2 layers     = ArcMap.Document.FocusMap as IMapLayers2;
            IEnumLayer  someLayers = layers.Layers;
            ILayer      aLayer     = null;

            while ((aLayer = someLayers.Next()) != null)
            {
                IFeatureLayer2 someFeatlayer = aLayer as IFeatureLayer2;
                if (someFeatlayer != null)
                {
                    IFeatureClass featClass = someFeatlayer.FeatureClass as IFeatureClass;
                    if (featClass != null)
                    {
                        IEnumRelationshipClass someRelationships = featClass.RelationshipClasses[esriRelRole.esriRelRoleAny] as IEnumRelationshipClass;
                        if (someRelationships != null)
                        {
                            IRelationshipClass aRelationship = someRelationships.Next();
                            while (aRelationship != null)
                            {
                                Debug.WriteLine(aRelationship.OriginClass.AliasName + " <--> " + aRelationship.DestinationClass.AliasName);
                                IDataset aDataset       = aRelationship.OriginClass as IDataset;
                                IDataset anotherDataset = aRelationship.DestinationClass as IDataset;
                                AddDataset(new IDataset[] { aDataset, anotherDataset });
                                IDataset aDS = featClass as IDataset;
                                if (aDS != null)
                                {
                                    Debug.WriteLine(aDS.Name + "," + aDataset.Name + "," + anotherDataset.Name);
                                    string name = aDS.Name.Equals(aDataset.Name, StringComparison.InvariantCultureIgnoreCase) ? anotherDataset.Name : aDataset.Name;
                                    if (RelationLookup.ContainsKey(name))
                                    {
                                        RelationLookup[name].Add(aRelationship);
                                    }
                                    else
                                    {
                                        RelationLookup.Add(name, new List <IRelationshipClass>()
                                        {
                                            aRelationship
                                        });
                                    }
                                }
                                aRelationship = someRelationships.Next();
                            }
                        }
                    }
                }
            }
            TableList.Sort((a, b) => a.TableName.CompareTo(b.TableName));
        }
コード例 #27
0
ファイル: AnnotationUtils.cs プロジェクト: arcpad/epsgis
        /// <summary>
        /// 获取与要素设置的releationshipclss对应的标注要素

        /// </summary>
        /// <param name="pFeature">地图要素</param>
        /// <returns>标注要素</returns>
        public static IAnnotationFeature2 GetLinkedFeature(IFeature pFeature)
        {
            // 方法一
            IFeatureClass          pfClass       = (IFeatureClass)pFeature.Class;
            IEnumRelationshipClass pEnumRelation =
                pfClass.get_RelationshipClasses(esriRelRole.esriRelRoleAny);
            IRelationshipClass pRelationship = pEnumRelation.Next();

            if (pRelationship == null)
            {
                return(null);
            }

            ISet pSet = pRelationship.GetObjectsRelatedToObject(pFeature);

            if (pSet == null)
            {
                return(null);
            }

            object o = pSet.Next();

            if (o == null || !(o is IAnnotationFeature2))
            {
                return(null);
            }

            IAnnotationFeature2 pAnnoFeature = (IAnnotationFeature2)o;

            return(pAnnoFeature);

            /*
             * 方法二
             *
             * // 注记的FeatureClass
             * IFeatureClass pDestionClass = (IFeatureClass)pRelationship.DestinationClass;
             * if (pDestionClass == null)
             *  return null;
             *
             * string foreignKey = pRelationship.OriginForeignKey;
             * if (string.IsNullOrEmpty(foreignKey))
             *  return null;
             *
             * string where = foreignKey + "='" + pFeature.OID + "'";
             * IAnnotationFeature2 pAnnoFeature =
             *  (IAnnotationFeature2)GeometryHelper.SearchFeature(pDestionClass, where);
             *
             * return pAnnoFeature;
             */
        }
コード例 #28
0
        /// <summary>
        ///     Creates an <see cref="IEnumerable{T}" /> from an <see cref="IEnumRelationshipClass" />
        /// </summary>
        /// <param name="source">An <see cref="IEnumRelationshipClass" /> to create an <see cref="IEnumerable{T}" /> from.</param>
        /// <returns>An <see cref="IEnumerable{T}" /> that contains the relationship classes from the input source.</returns>
        public static IEnumerable <IRelationshipClass> AsEnumerable(this IEnumRelationshipClass source)
        {
            if (source != null)
            {
                source.Reset();
                IRelationshipClass relationshipClass = source.Next();
                while (relationshipClass != null)
                {
                    yield return(relationshipClass);

                    relationshipClass = source.Next();
                }
            }
        }
コード例 #29
0
        private static ObjectAttribute GetDestinationPK(
            [NotNull] IRelationshipClass relClass,
            [NotNull] IObjectDataset objectDataset)
        {
            ObjectAttribute destinationPK =
                objectDataset.GetAttribute(relClass.DestinationPrimaryKey);

            Assert.NotNull(destinationPK,
                           "destination primary key not found on dataset {0}: {1}",
                           objectDataset.Name,
                           relClass.DestinationPrimaryKey);

            return(destinationPK);
        }
コード例 #30
0
 private void method_2(IDisplayRelationshipClass idisplayRelationshipClass_0, IRelQueryTable irelQueryTable_0)
 {
     try
     {
         IRelationshipClass relationshipClass = irelQueryTable_0.RelationshipClass;
         if (relationshipClass != null)
         {
             idisplayRelationshipClass_0.DisplayRelationshipClass(relationshipClass,
                                                                  idisplayRelationshipClass_0.JoinType);
         }
     }
     catch
     {
     }
 }
コード例 #31
0
 void IRelationshipClassCollectionEdit.RemoveRelationshipClass(IRelationshipClass RelationshipClass)
 {
     ((IRelationshipClassCollectionEdit)featureLayer).RemoveRelationshipClass(RelationshipClass);
 }
コード例 #32
0
ファイル: Transaction.cs プロジェクト: EAWCS1/SUITT
        private void populate(IFeature src, IFeature dest, IRelationshipClass rc, string[] fnames)
        {
            // the rc is 1-1
            ISet st = rc.GetObjectsRelatedToObject(src);
            if(st.Count!=1)
            {
                Logger.Write("Join not found for "+((IDataset)rc).Name);
                return;
            }
            IRow row = (IRow)st.Next();

            // extract the fields
            for(int i=0;i<fnames.Length;i++)
            {
                int index = dest.Fields.FindField(fnames[i]);
                int index2 = row.Fields.FindField(fnames[i]);
                if(index > -1 && index2 > -1)
                {
                    dest.set_Value(index,row.get_Value(index2));
                }
            }
        }
コード例 #33
0
 void IDisplayRelationshipClass.DisplayRelationshipClass(IRelationshipClass relClass, esriJoinType JoinType)
 {
     ((IDisplayRelationshipClass)featureLayer).DisplayRelationshipClass(relClass, JoinType);
 }
コード例 #34
0
 public ITable OpenRelationshipQuery(IRelationshipClass pRelClass, bool joinForward, IQueryFilter pSrcQueryFilter, ISelectionSet pSrcSelectionSet, string TargetColumns, bool DoNotPushJoinToDB)
 {
     // I don't think this needs to be implemented for now.
     throw new NotImplementedException();
 }
コード例 #35
0
ファイル: GJoin.cs プロジェクト: truonghinh/TnX
        void IJoin.Perform()
        {
            _relClassEdit = (IRelationshipClassCollectionEdit)_featureLayer;
            _relClassEdit.RemoveAllRelationshipClasses();

            _geoFeatureLayer = (IGeoFeatureLayer)_featureLayer;

            _dspRel = (IDisplayRelationshipClass)_geoFeatureLayer;

            _memRelFact = new MemoryRelationshipClassFactoryClass();

            IObjectClass tblObj = (IObjectClass)_table;
            _relClass = _memRelFact.Open("test", _geoFeatureLayer.FeatureClass, _joinFieldOnLayer, tblObj, _joinFieldOnTable,
                "Forwards", "Backwards", _cardinality);
            _dspRel.DisplayRelationshipClass(_relClass, _type);
        }