Пример #1
0
        /// <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);
        }
Пример #2
0
        /// <summary>
        ///     Joins the specified foreign class with the source class to create an in memory relationship.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="foreignClass">The foreign class.</param>
        /// <param name="primaryKeyField">The primary key field.</param>
        /// <param name="foreignKeyField">The foreign key field.</param>
        /// <param name="cardinality">The cardinality.</param>
        /// <param name="name">The name.</param>
        /// <returns>
        ///     Returns a <see cref="IRelationshipClass" /> representing the relationship between the two classes.
        /// </returns>
        public static IRelationshipClass Join(this IObjectClass source, IObjectClass foreignClass, string primaryKeyField, string foreignKeyField, esriRelCardinality cardinality, string name)
        {
            var joinName = name ?? string.Format("{0}_{1}", ((IDataset)source).Name, ((IDataset)foreignClass).Name);

            var factory = new MemoryRelationshipClassFactory();

            return(factory.Open(joinName, source, primaryKeyField, foreignClass, foreignKeyField, "Forward", "Backward", cardinality));
        }
        private void Command1_Click(object sender, EventArgs e)
        {
            try
            {
                if (cmbType.Text.Trim().Length == 0) return;
                if (cmbClasse.Text.Trim().Length == 0) return;
                if (SF10_extMain.m_LayerName == null) return;

                cmbType.Enabled = false;
                cmbClasse.Enabled = false;
                dtDe.Enabled = false;
                timeDe.Enabled = false;
                Command2.Enabled = false;
                dtA.Enabled = false;
                timeA.Enabled = false;
                cmbUsager.Enabled = false;
                Command1.Enabled = false;

                DateTime dDateDebut;
                DateTime dDateFin;

                DateTime.TryParse(dtDe.Value.Year + "/" + dtDe.Value.Month + "/" + dtDe.Value.Day +
                    " " + timeDe.Value.Hour + ":" + timeDe.Value.Minute + ":" + timeDe.Value.Second, out dDateDebut);

                DateTime.TryParse(dtA.Value.Year + "/" + dtA.Value.Month + "/" + dtA.Value.Day +
                    " " + timeA.Value.Hour + ":" + timeA.Value.Minute + ":" + timeA.Value.Second, out dDateFin);

                TimeSpan ts = dDateFin - dDateDebut;
                double dEcoule = ts.TotalSeconds;

                IDisplayTable pDispTable;
                IFeatureClass pFCLayer;
                ITable pTLayer;

                pDispTable = (IDisplayTable)SF10_extMain.m_LayerName;
                pFCLayer = (IFeatureClass)pDispTable.DisplayTable;
                pTLayer = (ITable)pFCLayer;

                ITable pTTable;
                pTTable = SF10_clsBase.ouvrirDbf(SF10_extMain.m_Parametres.pathValidation + @"\terrain.dbf");

                string strJnField1 = "TER_CO";
                string strJnField2 = "CO_TER";

                switch (SF10_extMain.m_Parametres.typeSaisie)
                {
                    case "MRNF_NAIPF_2013":
                        strJnField2 = "CO_TER";
                        break;
                }

                // Create virtual relate
                IMemoryRelationshipClassFactory pMemRelFact;
                IRelationshipClass pRelClass;
                pMemRelFact = new MemoryRelationshipClassFactory();
                pRelClass = pMemRelFact.Open("TabletoLayer",
                    (IObjectClass)pTTable, strJnField1,
                    (IObjectClass)pTLayer, strJnField2,
                    "forward", "backward",
                    esriRelCardinality.esriRelCardinalityOneToMany);

                // use Relate to perform a join
                IDisplayRelationshipClass pDispRC;
                pDispRC = (IDisplayRelationshipClass)SF10_extMain.m_LayerName;
                pDispRC.DisplayRelationshipClass(pRelClass, esriJoinType.esriLeftOuterJoin);

                // GO CALCULS!!

                double sTotPolys;
                double sTotArea;

                string sCurDateDe;
                string sCurDateA;

                sCurDateDe = string.Format("{0:0000}{1:00}{2:00}{3:00}{4:00}{5:00}", dtDe.Value.Year, dtDe.Value.Month, dtDe.Value.Day, timeDe.Value.Hour, timeDe.Value.Minute, timeDe.Value.Second);
                sCurDateA = string.Format("{0:0000}{1:00}{2:00}{3:00}{4:00}{5:00}", dtA.Value.Year, dtA.Value.Month, dtA.Value.Day, timeA.Value.Hour, timeA.Value.Minute, timeA.Value.Second);

                string sClasseSelect;
                sClasseSelect = "";
                switch (cmbClasse.Text)
                {
                    case "Forestier":
                        sClasseSelect = "FP";
                        break;
                    case "Improductif":
                        sClasseSelect = "FIFP";
                        break;
                    case "Non-forestier":
                        sClasseSelect = "NF";
                        break;
                }

                string sChampType = "";
                string sChampUsager = "";
                string sChampDate = "";

                switch (cmbType.Text)
                {
                    case "Édités":
                        sChampType = "fait";
                        sChampUsager = "usager_geo";
                        sChampDate = "curdategeo";
                        break;
                    case "Interprétés":
                        sChampType = "saisie_ok";
                        sChampUsager = "usager";
                        sChampDate = "curdate";
                        break;
                }

                string sSQL;
                switch (cmbClasse.Text)
                {
                    case "Total":
                        sSQL = sChampDate + " >= '" + sCurDateDe + "' and " +
                            sChampDate + " <= '" + sCurDateA + "' and " +
                            sChampUsager + " = '" + cmbUsager.Text.Trim().ToUpper() + "'";
                        break;
                    default:
                        sSQL = sChampDate + " >= '" + sCurDateDe + "' and " +
                            sChampDate + " <= '" + sCurDateA + "' and " +
                            sChampUsager + " = '" + cmbUsager.Text.Trim().ToUpper() +
                            (cmbType.Text == "Interprétés" ? "' and \"terrain.cte_co\" = '" + sClasseSelect + "'" : "'");
                        break;
                }

                sTotPolys = SF10_clsBase.returnNbPolys(SF10_extMain.m_LayerName, true, sSQL);
                sTotArea = SF10_clsBase.returnCalcArea(SF10_extMain.m_LayerName, true, sSQL);

                double lPolys;
                double sArea;

                lPolys = sTotPolys;
                sArea = sTotArea;

                double sSup;
                double sSupMoyHa;

                lblNbPolys.Text = "0";
                lblSupTot.Text = "0";
                lblSupMoy.Text = "0";
                lblInterval.Text = "0";
                lblPolysHeure.Text = "0";
                lblKm2Heure.Text = "0";

                if (lPolys > 0 && sArea > 0)
                {
                    sSup = sArea / 1000000;
                    sSupMoyHa = sArea / lPolys / 10000;

                    lblNbPolys.Text = lPolys.ToString();
                    lblSupTot.Text = string.Format("{0:#0.0000}", sSup);
                    lblSupMoy.Text = string.Format("{0:#0.00}", sSupMoyHa);
                }
                else
                {
                    sSup = 0;
                    sSupMoyHa = 0;
                }

                if (lPolys > 0 && sArea > 0)
                {
                    lblInterval.Text = string.Format("{0}", ts); ;
                    lblPolysHeure.Text = string.Format("{0:#0.00}", lPolys / (dEcoule / 3600));
                    lblKm2Heure.Text = string.Format("{0:#0.00}", ((sSup * 3600) / dEcoule));
                }

                //' **************************************
                //' RESTANT
                lblNbPolysReste.Text = "0";
                lblSupTotReste.Text = "0";

                sSQL = sChampType + " = 0";

                sTotPolys = SF10_clsBase.returnNbPolys(SF10_extMain.m_LayerName, true, sSQL);
                sTotArea = SF10_clsBase.returnCalcArea(SF10_extMain.m_LayerName, true, sSQL);

                lPolys = sTotPolys;
                sArea = sTotArea;

                if (lPolys > 0 && sArea > 0)
                {
                    sSup = sArea / 1000000;
                    sSupMoyHa = sArea / lPolys / 10000;

                    lblNbPolysReste.Text = lPolys.ToString();
                    lblSupTotReste.Text = string.Format("{0:#0.0000}", sSup);
                }

                // FLUSH

                pDispRC.DisplayRelationshipClass(null, esriJoinType.esriLeftInnerJoin);

                pDispTable = null;
                pFCLayer = null;
                pTLayer = null;
                pTTable = null;
                pMemRelFact = null;
                pRelClass = null;
                pDispRC = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "SF10");
            }
            finally
            {
                cmbType.Enabled = true;
                cmbClasse.Enabled = true;
                dtDe.Enabled = true;
                timeDe.Enabled = true;
                Command2.Enabled = true;
                dtA.Enabled = true;
                timeA.Enabled = true;
                cmbUsager.Enabled = true;
                Command1.Enabled = true;
            }
        }
Пример #4
0
        /// <summary>
        /// Join Complex Index Table
        /// </summary>
        /// <param name="layer"></param>
        /// <param name="year"></param>
        /// <author>Shen Yongyuan</author>
        /// <date>20091111</date>
        public static void JoinComplexTable(ILayer layer, int year, string city, bool normal)
        {
            //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 = "Ecology";
            field2.Type_2 = esriFieldType.esriFieldTypeDouble;
            allFields.AddField(field2);
            IFieldEdit field3 = new FieldClass();

            field3.Name_2 = "Social";
            field3.Type_2 = esriFieldType.esriFieldTypeDouble;
            allFields.AddField(field3);
            IFieldEdit field4 = new FieldClass();

            field4.Name_2 = "Economic";
            field4.Type_2 = esriFieldType.esriFieldTypeDouble;
            allFields.AddField(field4);

            //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.TmpTableIndex, 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("Ecology");
            int     fldField3 = cursor.Fields.FindField("Social");
            int     fldField4 = cursor.Fields.FindField("Economic");

            IQueryable <DataLib.I_INDEX> indexCollect = DataLib.DA_Index.QueryIndex(year, city);
            List <int> OIDList = new List <int>();

            foreach (DataLib.I_INDEX i in indexCollect)
            {
                if (OIDList.Contains(i.I_ZONE.OID) == false)
                {
                    double EcologyValue  = indexCollect.Where(c => c.Name.Equals("生态子系统综合指标") && c.Zone == i.Zone).Single().Value;
                    double SocialValue   = indexCollect.Where(c => c.Name.Equals("社会子系统综合指标") && c.Zone == i.Zone).Single().Value;
                    double EconomicValue = indexCollect.Where(c => c.Name.Equals("经济子系统综合指标") && c.Zone == i.Zone).Single().Value;

                    //if (normal == true)
                    //{
                    //    EcologyValue += Math.Abs(DataLib.DA_Index.QueryIndex("生态子系统综合指标", city).Min(c => c.Value)) + 1;
                    //    SocialValue += Math.Abs(DataLib.DA_Index.QueryIndex("社会子系统综合指标", city).Min(c => c.Value)) + 1;
                    //    EconomicValue += Math.Abs(DataLib.DA_Index.QueryIndex("经济子系统综合指标", city).Min(c => c.Value)) + 1;
                    //}

                    EcologyValue  = Math.Abs(EcologyValue);
                    SocialValue   = Math.Abs(SocialValue);
                    EconomicValue = Math.Abs(EconomicValue);
                    IRowBuffer buffer = table.CreateRowBuffer();
                    buffer.set_Value(fldField1, i.I_ZONE.OID);
                    buffer.set_Value(fldField2, EcologyValue);
                    buffer.set_Value(fldField3, SocialValue);
                    buffer.set_Value(fldField4, EconomicValue);
                    cursor.InsertRow(buffer);

                    OIDList.Add(i.I_ZONE.OID);
                }
            }

            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);
        }
Пример #5
0
        /// <summary>
        /// Join Index
        /// </summary>
        /// <param name="layer"></param>
        /// <param name="year"></param>
        /// <author>Shen Yongyuan</author>
        /// <date>20091111</date>
        public static void JoinIndexTable(ILayer layer, string indexName, int year, string city, bool normal)
        {
            //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.esriFieldTypeDouble;
            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.TmpTableIndex, 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);

            IQueryable <DataLib.I_INDEX> indexCollect = DataLib.DA_Index.QueryIndex(indexName, city).Where(c => c.FromDate.Year == year);

            foreach (DataLib.I_INDEX index in indexCollect)
            {
                IRowBuffer buffer = table.CreateRowBuffer();
                buffer.set_Value(fldField1, index.I_ZONE.OID);
                if (normal == false)
                {
                    buffer.set_Value(fldField2, index.Value);
                }
                else if (normal == true && DataLib.DA_Index.QueryIndex(indexName, city).Min(c => c.Value) > 0)
                {
                    buffer.set_Value(fldField2, index.Value);
                }
                else
                {
                    buffer.set_Value(fldField2, index.Value + Math.Abs(DataLib.DA_Index.QueryIndex(indexName, city).Min(c => c.Value)) + 1);
                }
                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);
        }