コード例 #1
0
        public override double[,] getMatrix()
        {
            if (unVlDic == null)
            {
                unVlDic = UniqueClassValues;
            }
            List <string> aVlLst = new List <string>();

            foreach (KeyValuePair <string, List <string> > kvp in unVlDic)
            {
                List <string> vlLst = kvp.Value;
                aVlLst.AddRange(vlLst);
            }
            labels = aVlLst.Distinct().ToList();
            double[] weights = new double[labels.Count];
            mctable = new int[2, 2];
            g1table = new int[labels.Count, labels.Count];
            g2table = new int[labels.Count, labels.Count];
            g3table = new int[labels.Count, labels.Count];
            ICursor cur      = InTable.Search(null, false);
            int     refIndex = cur.FindField(DependentFieldNames[0]);
            int     m1Index  = cur.FindField(IndependentFieldNames[0]);
            int     m2index  = cur.FindField(IndependentFieldNames[1]);
            //Console.WriteLine(wIndex.ToString());
            IRow rw = cur.NextRow();

            while (rw != null)
            {
                string rVl   = rw.get_Value(refIndex).ToString();
                string m1Vl  = rw.get_Value(m1Index).ToString();
                string m2Vl  = rw.get_Value(m2index).ToString();
                string rVll  = rVl.ToLower();
                string m1Vll = m1Vl.ToLower();
                string m2Vll = m2Vl.ToLower();
                int    mClm  = 0;
                int    mRws  = 0;
                if (rVll != m1Vll && rVll != m2Vll)
                {
                    mClm = 1;
                    mRws = 1;
                }
                else if (rVll == m1Vll && rVll != m2Vll)
                {
                    mClm = 0;
                    mRws = 1;
                }
                else if (rVll != m1Vll && rVll == m2Vll)
                {
                    mClm = 1;
                    mRws = 0;
                }
                mctable[mClm, mRws] += 1;
                g1table[labels.IndexOf(rVl), labels.IndexOf(m1Vl)]  += 1;
                g2table[labels.IndexOf(rVl), labels.IndexOf(m2Vl)]  += 1;
                g3table[labels.IndexOf(m1Vl), labels.IndexOf(m2Vl)] += 1;
                rw = cur.NextRow();
            }
            return(null);
        }
コード例 #2
0
        public override double[,] getMatrix()
        {
            if (unVlDic == null)
            {
                unVlDic = UniqueClassValues;
            }
            List <string> aVlLst = new List <string>();

            foreach (KeyValuePair <string, List <string> > kvp in unVlDic)
            {
                List <string> vlLst = kvp.Value;
                aVlLst.AddRange(vlLst);
            }
            labels = aVlLst.Distinct().ToList();
            double[] weights = new double[labels.Count];
            int      clms    = labels.Count();
            int      rws     = clms;

            xtable = new int[clms, rws];
            ICursor cur      = InTable.Search(null, false);
            int     depIndex = cur.FindField(DependentFieldNames[0]);
            int     indIndex = cur.FindField(IndependentFieldNames[0]);
            int     wIndex   = -1;

            if (weightfld != "")
            {
                wIndex = cur.FindField(weightfld);
            }
            //Console.WriteLine(wIndex.ToString());
            IRow rw = cur.NextRow();

            while (rw != null)
            {
                string dVl = rw.get_Value(depIndex).ToString();
                string iVl = rw.get_Value(indIndex).ToString();
                double w   = 1;
                if (wIndex != -1)
                {
                    w = System.Convert.ToDouble(rw.get_Value(wIndex));
                }
                int mClm = labels.IndexOf(iVl);
                int mRws = labels.IndexOf(dVl);
                weights[mClm]       = w;
                xtable[mClm, mRws] += 1;
                rw = cur.NextRow();
            }
            //Console.WriteLine(String.Join(", ", (from d in weights select d.ToString()).ToArray()));
            if (wIndex != -1)
            {
                updateXTable(weights);
            }
            return(null);
        }
コード例 #3
0
        /// <summary>
        /// 获取有属性表的值和数目
        /// </summary>
        /// <param name="rasterLayer"></param>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        public static IUniqueValues GetTableValueAndCount(IRasterLayer rasterLayer, string fieldName)
        {
            ITable pRTable = (ITable)rasterLayer;
            //获得表格游标
            ICursor pCursor    = pRTable.Search(null, false);
            int     fieldIndex = pCursor.FindField(fieldName);
            int     countIndex = pCursor.FindField("Count");
            IRasterCalcUniqueValues calcUniqueValues = new RasterCalcUniqueValuesClass();
            IUniqueValues           uniqueValues     = new UniqueValuesClass();

            //添加表格数据到唯一值中
            calcUniqueValues.AddFromTable(pCursor, fieldIndex, countIndex, uniqueValues);
            return(uniqueValues);
        }
コード例 #4
0
        public string addConstantGroupField()
        {
            string            outNm = "gr";
            IObjectClassInfo2 ocI2  = (IObjectClassInfo2)InTable;

            if (!ocI2.CanBypassEditSession())
            {
                System.Windows.Forms.MessageBox.Show("Input table has a composition relationship. Please export data and try again!");
            }
            else
            {
                outNm = geoUtil.createField(InTable, outNm, esriFieldType.esriFieldTypeString, false);
                IQueryFilter qf = new QueryFilterClass();
                qf.SubFields = outNm;
                ICursor cur     = InTable.Update(qf, false);
                int     flIndex = cur.FindField(outNm);
                IRow    rw      = cur.NextRow();
                while (rw != null)
                {
                    rw.set_Value(flIndex, "1");
                    cur.UpdateRow(rw);
                    rw = cur.NextRow();
                }
            }
            return(outNm);
        }
コード例 #5
0
        private Dictionary <string, int> getUniqueValueCounts(ITable SampleTable)
        {
            Dictionary <string, int> outDic = new Dictionary <string, int>();
            IQueryFilter             qf     = new QueryFilterClass();

            qf.SubFields = StrataField;
            ICursor cur    = SampleTable.Search(qf, false);
            int     sIndex = cur.FindField(StrataField);
            IRow    rw     = cur.NextRow();

            while (rw != null)
            {
                string vlStr = rw.get_Value(sIndex).ToString();
                int    cnt;
                if (outDic.TryGetValue(vlStr, out cnt))
                {
                    cnt           = cnt + 1;
                    outDic[vlStr] = cnt;
                }
                else
                {
                    outDic.Add(vlStr, 1);
                }
                rw = cur.NextRow();
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(cur);
            return(outDic);
        }
コード例 #6
0
        public void CanSortByStringField()
        {
            IFeatureWorkspace featureWs =
                WorkspaceUtils.OpenFileGdbFeatureWorkspace(TestData.GetArealeFileGdbPath());

            ITable table = DatasetUtils.OpenTable(featureWs, "TLM_NUTZUNGSAREAL");

            const string operatorFieldName = "OPERATEUR";
            ICursor      cursor            = TableSortUtils.GetSortedTableCursor(table, operatorFieldName);

            int fieldIndex = cursor.FindField(operatorFieldName);

            Assert.True(fieldIndex >= 0, "Field not found");

            string lastValue = null;
            IRow   row;

            while ((row = cursor.NextRow()) != null)
            {
                object value = row.get_Value(fieldIndex);

                Assert.False(value == DBNull.Value, "Empty field");

                var currentValue = (string)value;
                Console.WriteLine(currentValue);

                if (lastValue != null)
                {
                    Assert.False(currentValue.CompareTo(lastValue) < 0, "Not sorted");
                }

                lastValue = currentValue;
            }
        }
コード例 #7
0
ファイル: Fabric.cs プロジェクト: kgalliher/kg-geodata-sdk
        public static List <string> QueryStandaloneTable(ITable table, string searchField)
        {
            List <string> output = new List <string>();

            try
            {
                ICursor cursor = table.Search(null, false);
                IRow    row    = cursor.NextRow();

                output.Add(string.Format("{0}", table.RowCount(null).ToString()));

                while (row != null)
                {
                    string desc = row.Value[cursor.FindField(searchField)].ToString();
                    if (desc.Length > 0)
                    {
                        output.Add(desc);
                    }
                    else
                    {
                        output.Add("nvdf");
                    }
                    row = cursor.NextRow();
                }
                return(output);
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occured:\n" + ex.Message);
            }

            return(null);
        }
コード例 #8
0
ファイル: GDBData.cs プロジェクト: VB6Hobbyst7/minegis
        public IList <RasterName> get_RasterDataSetNames()
        {
            IList <RasterName> names = new List <RasterName>();

            if (this.m_workSpace != null)
            {
                IEnumDatasetName   enumDatasetName   = m_workSpace.get_DatasetNames(esriDatasetType.esriDTRasterCatalog);
                IDatasetName       datasetName       = enumDatasetName.Next();//DataSet的名字
                IRasterWorkspaceEx rasterWorkspaceEx = m_workSpace as IRasterWorkspaceEx;
                while (datasetName != null)
                {
                    RasterName name = new RasterName();
                    name.RasDCName = datasetName.Name.ToString();
                    IRasterCatalogName rasterCaName  = (IRasterCatalogName)datasetName;
                    IRasterCatalog     rasterCatalog = rasterWorkspaceEx.OpenRasterCatalog(name.RasDCName);
                    ITable             table         = rasterCatalog as ITable;
                    ICursor            cursor        = table.Search(null, false);
                    IRow row = cursor.NextRow();
                    while (row != null)
                    {
                        name.RDSName.Add(row.get_Value(cursor.FindField("NAME")).ToString());

                        row = cursor.NextRow();
                    }
                    names.Add(name);
                    datasetName = enumDatasetName.Next();
                }
            }
            return(names);
        }
コード例 #9
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (this.listBox1.SelectedItems == null)
            {
                MessageBox.Show("请选择图幅名!");
                return;
            }

            string sqlText = "";

            for (int i = 0; i < this.listBox1.SelectedItems.Count; i++)
            {
                sqlText = "select name,DATASTRUCTURE from sheetmetadata where NAME='" + listBox1.SelectedItems[i] + "'";
                m_oraCmd.CommandText = sqlText;
                OracleDataReader dr = m_oraCmd.ExecuteReader();
                if (!dr.HasRows)
                {
                    MessageBox.Show("图幅不存在!");
                    return;
                }
                while (dr.Read())
                {
                    // this.listBox1.Items.Add(dr.GetValue(0).ToString());
                    if (dr.GetValue(1).ToString() == "矢量")
                    {
                        IFeatureLayer feaLyr;
                        feaLyr = m_gdata.AddFeatureClassToMap(dr.GetValue(0).ToString());
                        this.m_mapControl.Map.AddLayer(feaLyr);
                    }
                    if (dr.GetValue(1).ToString() == "影像")
                    {
                        IRasterWorkspaceEx rasterWS      = m_workSpace as IRasterWorkspaceEx;
                        IRasterCatalog     rasterCatalog = rasterWS.OpenRasterCatalog("COASTALGIS." + dr.GetValue(1).ToString());
                        ITable             table         = rasterCatalog as ITable;
                        ICursor            cursor        = table.Search(null, false);
                        IRow           row      = cursor.NextRow();
                        IRasterDataset rasterDS = null;
                        while (row != null)
                        {
                            IRasterCatalogItem rasterCatalogItem = row as IRasterCatalogItem;

                            if (dr.GetValue(0).ToString() == row.get_Value(cursor.FindField("NAME")).ToString())
                            {
                                rasterDS = rasterCatalogItem.RasterDataset;
                                break;
                            }
                            row = cursor.NextRow();
                        }
                        IRasterLayer rasterLayer = new RasterLayerClass();
                        rasterLayer.CreateFromDataset(rasterDS);
                        this.m_mapControl.Map.AddLayer(rasterLayer);
                    }
                }
            }
        }
コード例 #10
0
        private Dictionary <string, List <string> > getUniqueClassValues()
        {
            Dictionary <string, List <string> > outDic = new Dictionary <string, List <string> >();

            if (ClassFieldNames == null || ClassFieldNames.Length == 0)
            {
                return(outDic);
            }
            string cFldn1 = ClassFieldNames[0];

            if (cFldn1 == "")
            {
                return(outDic);
            }
            IQueryFilter qf = new QueryFilterClass();

            if (generalQf != null)
            {
                qf.WhereClause = generalQf.WhereClause;
            }
            qf.SubFields = String.Join(",", ClassFieldNames);
            HashSet <string>[] hshStrgLst = new HashSet <string> [ClassFieldNames.Length];
            //Console.WriteLine("HashStrgLstLength = " + hshStrgLst.Length);
            int[]   fldIndexArr = new int[ClassFieldNames.Length];
            ICursor cur         = InTable.Search(qf, true);

            for (int i = 0; i < ClassFieldNames.Length; i++)
            {
                fldIndexArr[i] = cur.FindField(ClassFieldNames[i]);
                hshStrgLst[i]  = new HashSet <string>();
            }
            IRow rw = cur.NextRow();

            while (rw != null)
            {
                for (int i = 0; i < fldIndexArr.Length; i++)
                {
                    int    indVl = fldIndexArr[i];
                    string vl    = rw.get_Value(indVl).ToString();
                    //Console.WriteLine(vl);
                    //Console.WriteLine(indVl.ToString());
                    hshStrgLst[i].Add(vl);
                }
                rw = cur.NextRow();
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(cur);

            for (int i = 0; i < ClassFieldNames.Length; i++)
            {
                outDic.Add(ClassFieldNames[i], hshStrgLst[i].ToList());
            }
            return(outDic);
        }
コード例 #11
0
ファイル: RuleMs.cs プロジェクト: secondii/Yutai
        public RuleMs(IPipelineConfig config)
        {
            ITable table = ((IFeatureWorkspace)config.Workspace).OpenTable("YT_PIPE_DEPTH");

            _rules = new List <RuleMsItem>();
            ICursor cursor  = table.Search(null, false);
            int     codeIdx = cursor.FindField("PipeCode");
            int     nameIdx = cursor.FindField("PipeName");
            int     msfsIdx = cursor.FindField("MSFS");
            int     rxdIdx  = cursor.FindField("RXDDepth");
            int     cxdIdx  = cursor.FindField("CXDDepth");
            int     bzIdx   = cursor.FindField("Remark");
            IRow    row     = cursor.NextRow();

            while (row != null)
            {
                RuleMsItem item = new RuleMsItem()
                {
                    Code     = row.get_Value(codeIdx).ToString(),
                    Name     = row.get_Value(nameIdx).ToString(),
                    MSFS     = row.get_Value(msfsIdx).ToString(),
                    RxdDepth = Convert.ToDouble(row.get_Value(rxdIdx).ToString()),
                    CxdDepth = Convert.ToDouble(row.get_Value(cxdIdx).ToString()),
                    Remark   = row.get_Value(bzIdx).ToString()
                };
                _rules.Add(item);
                row = cursor.NextRow();
            }
            Marshal.ReleaseComObject(cursor);
            Marshal.ReleaseComObject(table);
        }
コード例 #12
0
ファイル: StatReportformsUI.cs プロジェクト: secondii/Yutai
        private void BtnOK_Click(object sender, EventArgs e)
        {
            _featureLayer = ((LayerboxItem)this.CmbLayers.SelectedItem).m_pPipeLayer;
            if (CmbCalField.SelectedItem == null || CmbStatField.SelectedItem == null || CmbStatWay.SelectedItem == null)
            {
                return;
            }
            string  statFieldName = this.CmbStatField.SelectedItem.ToString();
            string  calFieldName  = this.CmbCalField.SelectedItem.ToString();
            string  statWay       = this.CmbStatWay.SelectedItem.ToString();
            ITable  table         = (ITable)_featureLayer.FeatureClass;
            ICursor cursor        = table.Search(null, false);
            int     idxStatField  = cursor.FindField(statFieldName);
            int     idxCalField   = cursor.FindField(calFieldName);

            if (idxStatField <= 0 || idxCalField <= 0)
            {
                MessageBox.Show(@"字段不存在!");
                return;
            }
            IRow      row;
            DataTable dataTable = CreateDataTable(statFieldName, calFieldName);

            while ((row = cursor.NextRow()) != null)
            {
                dataTable.Rows.Add(row.Value[idxStatField], row.Value[idxCalField]);
            }

            StatForm form = new StatForm();

            form.Form_CalField  = this.CmbCalField.SelectedItem.ToString();
            form.Form_StatField = this.CmbStatField.SelectedItem.ToString();
            form.Form_StatWay   = statWay;
            form.resultTable    = dataTable;
            form.TopMost        = true;
            form.ShowDialog(this);
        }
コード例 #13
0
ファイル: UCResultsTree.cs プロジェクト: siszoey/geosufan
        public void InitializeResultsTree()
        {
            if (m_Workspace == null)
            {
                return;
            }

            tVResults.ImageList = imageList_Small;
            //edit xisheng 20120612 改变获取参数的方法 start
            ICursor cursor       = SysCommon.Gis.ModGisPub.GetQueryCursor(m_Workspace, "SYSSETTING", "settingname ='制图文件目录'", new string[] { "settingvalue", });
            int     ResultsIndex = cursor.FindField("settingvalue");

            if (ResultsIndex == -1)
            {
                return;
            }
            IRow row = cursor.NextRow();

            //不存在则插入一条记录
            if (row == null)
            {
                return;
            }
            //string strResultsName = row.get_Value(ResultsIndex).ToString();

            System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor);

            string strResultsPath = row.get_Value(ResultsIndex).ToString();
            //string strResultsPath = SysCommon.Gis.ModGisPub.re(m_Workspace, "A00GIS_图形模块运行参数表", "参数ID ='10521'","参数" );

            TreeNode rootNode = new TreeNode();

            rootNode.Text = "制图文件目录";
            //edit xisheng 20120612 改变获取参数的方法 end
            Dictionary <string, string> pDicTag = new Dictionary <string, string>();

            pDicTag.Add("Path", strResultsPath);
            pDicTag.Add("Type", "Root");
            rootNode.Tag              = pDicTag;
            rootNode.ImageKey         = "Root";
            rootNode.SelectedImageKey = "Root";
            tVResults.Nodes.Add(rootNode);
            rootNode.Expand();
            //刷新当前节点
            RefreshResultsTree(rootNode);
        }
コード例 #14
0
        protected override void OnClick()
        {
            string       featPath    = Path.Combine(DataPath, @"Geodatabase\ManhattanKS.gdb\Parcels");
            string       featName    = Path.GetFileName(featPath);
            const string searchField = "PID";

            Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
            IWorkspaceFactory workspaceFactory = Activator.CreateInstance(factoryType) as IWorkspaceFactory;
            IFeatureWorkspace featureWorkspace = workspaceFactory.OpenFromFile(Path.GetDirectoryName(featPath), 0) as IFeatureWorkspace;

            IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(featName);

            string       sql         = string.Format("{0} NOT IN ('', ' ', NULL)", searchField);
            IQueryFilter queryFilter = new QueryFilterClass {
                SubFields = searchField, IQueryFilter2_WhereClause = sql
            };
            ICursor cursor     = (ICursor)featureClass.Search(queryFilter, true);
            int     fieldIndex = cursor.FindField(searchField);

            List <string> uniqueList = new List <string>();

            IRow row;

            while ((row = cursor.NextRow()) != null)
            {
                uniqueList.Add(row.Value[fieldIndex].ToString());
            }

            uniqueList.Sort();
            string[] uniqueValues = uniqueList.Distinct().ToArray();
            string   txtPath      = Path.Combine(DataPath, @"UniqueValues.txt");

            using (StreamWriter writer = new StreamWriter(txtPath))
            {
                for (int i = 0; i < uniqueValues.Length; i++)
                {
                    writer.WriteLine("{0}. {1}", i + 1, uniqueValues[i]);
                }
            }

            Process.Start(txtPath);
            Marshal.FinalReleaseComObject(cursor);
        }
コード例 #15
0
        public static void DataStatistic(IFeatureClass featureCls)
        {
            IDataset          pDataset     = (IDataset)featureCls;
            IFeatureWorkspace featuretWrok = (IFeatureWorkspace)pDataset.Workspace;
            IQueryDef2        queryDef     = featuretWrok.CreateQueryDef() as IQueryDef2;

            queryDef.Tables        = pDataset.Name;
            queryDef.SubFields     = "zldwdm,sum(TBMJ) as mj";
            queryDef.PostfixClause = "group by zldwdm ";
            ICursor cursor = queryDef.Evaluate();
            //todo:
            var  zlFieldIndex = cursor.FindField("zldwdm");
            IRow row          = cursor.NextRow();

            while (row != null)
            {
                var dm = row.get_Value(zlFieldIndex);
                row = cursor.NextRow();
            }
        }
コード例 #16
0
        private static void LoopAndWrite(ICursor cursor, string uuidFieldName)
        {
            int fieldIndex = cursor.FindField(uuidFieldName);

            Assert.True(fieldIndex >= 0, "Field not found");

            IRow row;

            while ((row = cursor.NextRow()) != null)
            {
                object value = row.get_Value(fieldIndex);

                Assert.False(value == DBNull.Value, "Empty UUID field");

                var         currentGuid  = new Guid((string)value);
                IComparable currentValue = currentGuid;                 // value as IComparable; // currentGuid;

                Console.WriteLine(currentValue);
            }
        }
コード例 #17
0
        public void CanSortOnFgdbGuids()
        {
            IFeatureWorkspace featureWs =
                WorkspaceUtils.OpenFileGdbFeatureWorkspace(TestData.GetArealeFileGdbPath());
            //IFeatureWorkspace featureWs = OpenTestWorkspace();

            ITable table = DatasetUtils.OpenTable(featureWs, "TLM_NUTZUNGSAREAL");
            //ITable table = DatasetUtils.OpenTable(featureWs, "TOPGIS_TLM.TLM_NUTZUNGSAREAL");

            const string uuidFieldName = "UUID";

            ICursor cursor = TableSortUtils.GetGuidFieldSortedCursor(table, uuidFieldName);

            int fieldIndex = cursor.FindField(uuidFieldName);

            Assert.True(fieldIndex >= 0, "Field not found");

            Guid lastGuid = Guid.Empty;
            IRow row;

            while ((row = cursor.NextRow()) != null)
            {
                object value = row.get_Value(fieldIndex);

                Assert.False(value == DBNull.Value, "Empty UUID field");

                var currentGuid = new Guid((string)value);
                Console.WriteLine(currentGuid);

                if (lastGuid != Guid.Empty)
                {
                    Assert.False(currentGuid.CompareTo(lastGuid) < 0, "Not sorted");
                }

                lastGuid = currentGuid;
            }
        }
コード例 #18
0
        public bool ChangeDatesOnTableMulti(ICursor pCursor, List<bool> HistorySettings, List<string> sDate, bool Unversioned, 
      Dictionary<int, string> ParcelToHistory_DICT,IStepProgressor m_pStepProgressor, ITrackCancel m_pTrackCancel)
        {
            bool bSystemEndDate_Clear = HistorySettings[0];
              bool bLegalStDate_Clear = HistorySettings[1];
              bool bLegalEndDate_Clear = HistorySettings[2];
              bool bSystemEndDate_Set = HistorySettings[3];
              bool bLegalStDate_Set = HistorySettings[4];
              bool bLegalEndDate_Set = HistorySettings[5];

              object dbNull = DBNull.Value;

              int FldIdxSystemEnd = pCursor.FindField("systemenddate");
              int iHistorical = pCursor.FindField("historical");
              int FldIdxLegalSt =pCursor.FindField("legalstartdate");
              int FldIdxLegalEnd = pCursor.FindField("legalenddate");
              bool bHasSysEndDateFld = (FldIdxSystemEnd > -1);
              bool bHasHistoricFld = (iHistorical > -1);
              bool bCont = true;
              bool m_bShowProgressor = (m_pStepProgressor!=null);

              IRow pRow = pCursor.NextRow();
              while (pRow != null)
              {
            //Check if the cancel button was pressed. If so, stop process
            if (m_bShowProgressor)
            {
              bCont = m_pTrackCancel.Continue();
              if (!bCont)
            break;
            }

            string sHistoryInfo = "";
            string[] sUpdateDictionaryDates = null;
            bool bTryGetTrue = false;
            if (ParcelToHistory_DICT.TryGetValue(pRow.OID, out sHistoryInfo))
            {
              //update the strings in the dictionary
              sUpdateDictionaryDates = sHistoryInfo.Split(',');
              bTryGetTrue = true;
            }

            if (bSystemEndDate_Set && bTryGetTrue)
            {
              pRow.set_Value(FldIdxSystemEnd, sDate[0]);
              if (bHasHistoricFld)                          // if writing date to SystemEndDate field
            pRow.set_Value(iHistorical, 1);             //then set the Historical flag to true = 1
              //update the dictionary
              //find the location of the System End Date
              string x= ParcelToHistory_DICT[pRow.OID];
              int i1 = x.IndexOf(",", 0);
              int i2 = x.IndexOf(",", i1+1);
              string s1= x.Remove(i1 + 1, i2 - i1);
              string s2=s1.Insert(i1 + 1, sDate[0] + ",");
              ParcelToHistory_DICT[pRow.OID] = s2;
            }

            if (bSystemEndDate_Clear && bTryGetTrue)
            {
              pRow.set_Value(FldIdxSystemEnd, dbNull);
              if (bHasHistoricFld)                          // if writing date to SystemEndDate field
            pRow.set_Value(iHistorical, 0);             //then set the Historical flag to true = 1

              //update the dictionary
              //find the location of the System End Date
              string x = ParcelToHistory_DICT[pRow.OID];
              int i1 = x.IndexOf(",", 0);
              int i2 = x.IndexOf(",", i1 + 1);
              string s1 = x.Remove(i1 + 1, i2 - i1);
              string s2 = s1.Insert(i1 + 1, ",");
              ParcelToHistory_DICT[pRow.OID] = s2;
            }

            if (bLegalStDate_Set && bTryGetTrue)
            {
              pRow.set_Value(FldIdxLegalSt, sDate[1]);
              //update the dictionary
              //find the location of the System End Date
              string x = ParcelToHistory_DICT[pRow.OID];
              int i1 = x.IndexOf(",", 0);
              int i2 = x.IndexOf(",", i1 + 1);
              int i3 = x.IndexOf(",", i2 + 1);
              string s1 = x.Remove(i2 + 1, i3 - i2);
              string s2 = s1.Insert(i2 + 1,sDate[1]  + ",");
              ParcelToHistory_DICT[pRow.OID] = s2;
            }

            if (bLegalStDate_Clear && bTryGetTrue)
            {
              pRow.set_Value(FldIdxLegalSt, dbNull);
              //update the dictionary
              //find the location of the System End Date
              string x = ParcelToHistory_DICT[pRow.OID];
              int i1 = x.IndexOf(",", 0);
              int i2 = x.IndexOf(",", i1 + 1);
              int i3 = x.IndexOf(",", i2 + 1);
              string s1 = x.Remove(i2 + 1, i3 - i2);
              string s2 = s1.Insert(i2 + 1, ",");
              ParcelToHistory_DICT[pRow.OID] = s2;
            }

            if (bLegalEndDate_Set && bTryGetTrue)
            {
              pRow.set_Value(FldIdxLegalEnd, sDate[2]);
              //update the dictionary
              //find the location of the System End Date
              string x = ParcelToHistory_DICT[pRow.OID];
              int i1 = x.IndexOf(",", 0);
              int i2 = x.IndexOf(",", i1 + 1);
              int i3 = x.IndexOf(",", i2 + 1);
              int i4 = x.IndexOf(",", i3 + 1);

              string s1 = x.Remove(i3 + 1, i4 - i3);
              string s2 = s1.Insert(i3 + 1, sDate[2] + ",");
              ParcelToHistory_DICT[pRow.OID] = s2;
            }

            if (bLegalEndDate_Clear && bTryGetTrue)
            {
              pRow.set_Value(FldIdxLegalEnd, dbNull);
              //update the dictionary
              //find the location of the System End Date
              string x = ParcelToHistory_DICT[pRow.OID];
              int i1 = x.IndexOf(",", 0);
              int i2 = x.IndexOf(",", i1 + 1);
              int i3 = x.IndexOf(",", i2 + 1);
              int i4 = x.IndexOf(",", i3 + 1);

              string s1 = x.Remove(i3 + 1, i4 - i3);
              string s2 = s1.Insert(i3 + 1, ",");
              ParcelToHistory_DICT[pRow.OID] = s2;
            }

            if (Unversioned)
              pCursor.UpdateRow(pRow);
            else
              pRow.Store();

            Marshal.ReleaseComObject(pRow);
            pRow = pCursor.NextRow();
            if (m_bShowProgressor)
            {
              if (m_pStepProgressor.Position < m_pStepProgressor.MaxRange)
            m_pStepProgressor.Step();
            }
              }
              Marshal.ReleaseComObject(pCursor);
              if (!bCont)
            return false;
              return true;
        }
コード例 #19
0
        public override double[,] getMatrix()
        {
            if (unVlDic == null)
            {
                unVlDic = UniqueClassValues;
            }
            int indCnt = IndependentFieldNames.Length;
            int depCnt = DependentFieldNames.Length;

            int rws = InTable.RowCount(null);

            n = rws;
            ICursor cur        = InTable.Search(null, true);
            string  depFldName = DependentFieldNames[0];
            int     depIndex   = cur.FindField(depFldName);
            int     clms       = indCnt;

            int[] allFieldIndexArray = new int[clms];
            allFieldNames = new string[clms + 1];
            for (int i = 0; i < indCnt; i++)
            {
                string lu = IndependentFieldNames[i];
                allFieldNames[i]      = lu;
                allFieldIndexArray[i] = cur.FindField(lu);
                List <string> outSet = null;
                if (unVlDic.TryGetValue(lu, out outSet))
                {
                    int t = (outSet.Count() - 1);
                    clms = clms + t;
                }
            }


            allFieldNames[indCnt] = depFldName;
            nvars          = clms;
            independentVls = new double[rws][];
            dependentVls   = new int[rws];
            List <string> depKey = unVlDic[depFldName];
            int           rwCnt  = 0;
            IRow          rw     = cur.NextRow();

            while (rw != null)
            {
                double[] rwVls        = new double[clms];
                int      indMatrixClm = 0;
                for (int i = 0; i < allFieldIndexArray.Length; i++)
                {
                    string lu         = allFieldNames[i];
                    int    fldClmCntT = 1;
                    int    indexFld   = allFieldIndexArray[i];
                    object vl         = rw.get_Value(indexFld);
                    updateMinMaxSum(vl, i);
                    double dblVl = 0;
                    try
                    {
                        string        strVl = vl.ToString();
                        List <string> unVl  = null;
                        if (unVlDic.TryGetValue(lu, out unVl))
                        {
                            int fldClmCntP = unVl.IndexOf(strVl);
                            fldClmCntT    = unVl.Count() - fldClmCntP;
                            indMatrixClm += fldClmCntP;
                            dblVl         = 1;
                        }
                        else
                        {
                            dblVl = System.Convert.ToDouble(strVl);
                        }
                    }
                    catch
                    {
                        dblVl = 0;
                    }
                    rwVls[indMatrixClm] = dblVl;
                    indMatrixClm       += fldClmCntT;
                }
                independentVls[rwCnt] = rwVls;
                string depStr = rw.get_Value(depIndex).ToString();
                dependentVls[rwCnt] = depKey.IndexOf(depStr);
                rw     = cur.NextRow();
                rwCnt += 1;
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(cur);
            return(null);
        }
コード例 #20
0
        /// <summary>
        /// Adds Probabilities confidence intervals to the map given the plr model
        /// </summary>

        public void addConfidenceIntervals()
        {
            IEnumerable <string> hdArr = null;
            Dictionary <string, IEnumerable <string> > vlDic = new Dictionary <string, IEnumerable <string> >();

            using (System.IO.StreamReader sr = new System.IO.StreamReader(SasOutputFile))
            {
                string ln = sr.ReadLine();
                hdArr = ln.Split(new char[] { ',' }).Skip(2);
                foreach (string s in hdArr)
                {
                    if (InTable.FindField(s) == -1)
                    {
                        geoUtil.createField(InTable, s, esriFieldType.esriFieldTypeSingle);
                    }
                }
                while ((ln = sr.ReadLine()) != null)
                {
                    string[]             vlArr   = ln.Split(new char[] { ',' });
                    string               mpCls   = vlArr[0];
                    IEnumerable <string> enumVls = vlArr.Skip(2);
                    vlDic[mpCls] = enumVls;
                }
                sr.Close();
            }
            IDataset       dSet    = (IDataset)InTable;
            IWorkspace     wks     = dSet.Workspace;
            IWorkspaceEdit wksE    = (IWorkspaceEdit)wks;
            bool           weStart = true;

            if (wksE.IsBeingEdited())
            {
                weStart = false;
            }
            else
            {
                wksE.StartEditing(false);
            }
            wksE.StartEditOperation();
            ICursor uCur     = InTable.Update(null, false);
            int     valIndex = uCur.FindField(MapField);
            IRow    uRow     = uCur.NextRow();

            while (uRow != null)
            {
                string mpVl = uRow.get_Value(valIndex).ToString();
                IEnumerable <string> vls;
                if (vlDic.TryGetValue(mpVl, out vls))
                {
                    for (int i = 0; i < hdArr.Count(); i++)
                    {
                        string fldNm    = hdArr.ElementAt(i);
                        float  fldVl    = System.Convert.ToSingle(vls.ElementAt(i));
                        int    fldIndex = uCur.FindField(fldNm);
                        uRow.set_Value(fldIndex, fldVl);
                    }
                    uCur.UpdateRow(uRow);
                }
                uRow = uCur.NextRow();
            }
            wksE.StopEditOperation();
            if (weStart)
            {
                wksE.StopEditing(true);
            }
        }
コード例 #21
0
ファイル: PipelineConfig.cs プロジェクト: secondii/Yutai
        public List <IPipelineLayer> ReadLayersFromDatabase()
        {
            List <IPipelineLayer> layers = new List <IPipelineLayer>();
            ITable     pCodeTable        = _workspace.OpenTable("YT_PIPE_CODE");
            ITableSort tableSort         = new TableSortClass();

            tableSort.Table  = pCodeTable;
            tableSort.Fields = "Priority";
            tableSort.Sort(null);

            ICursor pCursor  = tableSort.Rows;
            IRow    pRow     = pCursor.NextRow();
            int     codeIdx  = pCursor.FindField("PipeCode");
            int     classIdx = pCursor.FindField("ClassCode");
            int     nameIdx  = pCursor.FindField("PipeName");
            int     autoIdx  = pCursor.FindField("AutoNames");
            int     priIdx   = pCursor.FindField("Priority");

            while (pRow != null)
            {
                IPipelineLayer oneLayer = new PipelineLayer()
                {
                    Code      = pRow.Value[codeIdx].ToString(),
                    Name      = pRow.Value[nameIdx].ToString(),
                    AutoNames = pRow.Value[autoIdx].ToString(),
                    Layers    = new List <IBasicLayerInfo>(),
                    ClassCode = pRow.Value[classIdx].ToString()
                };
                layers.Add(oneLayer);
                pRow = pCursor.NextRow();
            }
            Marshal.ReleaseComObject(pCursor);
            Marshal.ReleaseComObject(tableSort);
            Marshal.ReleaseComObject(pCodeTable);

            List <IYTDomain> domains = new List <IYTDomain>();

            pCodeTable = _workspace.OpenTable("YT_PIPE_DOMAIN");
            pCursor    = pCodeTable.Search(null, false);
            pRow       = pCursor.NextRow();
            nameIdx    = pCursor.FindField("DomainName");
            autoIdx    = pCursor.FindField("DomainValues");

            while (pRow != null)
            {
                string    domainName   = pRow.Value[nameIdx].ToString();
                string    domainValues = pRow.Value[autoIdx].ToString();
                IYTDomain onedomain    = new YTDomain(domainName, domainValues);
                domains.Add(onedomain);
                pRow = pCursor.NextRow();
            }
            Marshal.ReleaseComObject(pCursor);
            Marshal.ReleaseComObject(pCodeTable);

            List <IPipelineTemplate> templates = new List <IPipelineTemplate>();

            //! 先读取模板
            pCodeTable       = _workspace.OpenTable("YT_PIPE_FIELD");
            tableSort        = new TableSortClass();
            tableSort.Table  = pCodeTable;
            tableSort.Fields = "TemplateName";

            tableSort.Sort(null);
            pCursor = tableSort.Rows;
            string oldTemplate = "";

            int[] fieldIndexes = new int[10];
            pRow            = pCursor.NextRow();
            fieldIndexes[0] = pRow.Fields.FindField("TemplateName");
            fieldIndexes[1] = pRow.Fields.FindField("TypeName");
            fieldIndexes[2] = pRow.Fields.FindField("FieldName");
            fieldIndexes[3] = pRow.Fields.FindField("FieldAliasName");
            fieldIndexes[4] = pRow.Fields.FindField("FieldType");
            fieldIndexes[5] = pRow.Fields.FindField("FieldLength");
            fieldIndexes[6] = pRow.Fields.FindField("FieldPrecision");
            fieldIndexes[7] = pRow.Fields.FindField("AllowNull");
            fieldIndexes[8] = pRow.Fields.FindField("AutoValues");
            fieldIndexes[9] = pRow.Fields.FindField("IsKey");
            //  fieldIndexes[10] = pRow.Fields.FindField("Domains");


            IPipelineTemplate oneTemplate = null;

            while (pRow != null)
            {
                string templateName = pRow.Value[fieldIndexes[0]].ToString();
                if (!templateName.Equals(oldTemplate))
                {
                    if (oneTemplate != null)
                    {
                        templates.Add(oneTemplate);
                    }
                    oneTemplate = new PipelineTemplate()
                    {
                        Name = templateName, Fields = new List <IYTField>()
                    };
                    oldTemplate = templateName;
                }
                IYTField field = new YTField()
                {
                    TypeName  = pRow.Value[fieldIndexes[1]].ToString(),
                    Name      = pRow.Value[fieldIndexes[2]].ToString(),
                    AliasName = pRow.Value[fieldIndexes[3]].ToString(),
                    Length    = Convert.ToInt32(pRow.Value[fieldIndexes[5]].ToString()),
                    Precision = Convert.ToInt32(pRow.Value[fieldIndexes[6]].ToString()),
                    AllowNull = Convert.ToInt32(pRow.Value[fieldIndexes[7]].ToString()) == -1 ? true : false,
                    AutoNames = pRow.Value[fieldIndexes[8]].ToString(),
                    FieldType = FieldHelper.ConvertFromString(pRow.Value[fieldIndexes[4]].ToString())
                };
                oneTemplate.Fields.Add(field);
                pRow = pCursor.NextRow();
            }
            if (oneTemplate != null)
            {
                templates.Add(oneTemplate);
            }
            Marshal.ReleaseComObject(pCursor);
            Marshal.ReleaseComObject(tableSort);
            Marshal.ReleaseComObject(pCodeTable);

            List <IBasicLayerInfo> basicInfos = new List <IBasicLayerInfo>();

            pCodeTable       = _workspace.OpenTable("YT_PIPE_LAYER");
            tableSort        = new TableSortClass();
            tableSort.Table  = pCodeTable;
            tableSort.Fields = "Priority,LayerName";
            tableSort.Sort(null);
            pCursor      = tableSort.Rows;
            pRow         = pCursor.NextRow();
            fieldIndexes = new int[8];

            fieldIndexes[0] = pRow.Fields.FindField("PipeCode");
            fieldIndexes[1] = pRow.Fields.FindField("BasicName");
            fieldIndexes[2] = pRow.Fields.FindField("LayerName");
            fieldIndexes[3] = pRow.Fields.FindField("AutoNames");
            fieldIndexes[4] = pRow.Fields.FindField("Priority");
            fieldIndexes[5] = pRow.Fields.FindField("DataType");
            fieldIndexes[6] = pRow.Fields.FindField("Template");
            fieldIndexes[7] = pRow.Fields.FindField("Domains");
            while (pRow != null)
            {
                string         pipeCode = pRow.Value[fieldIndexes[0]].ToString();
                IPipelineLayer oneLayer = layers.Find(c => c.Code == pipeCode);
                if (oneLayer == null)
                {
                    pRow = pCursor.NextRow();
                    continue;
                }
                enumPipelineDataType dataType =
                    Yutai.Pipeline.Config.Helpers.EnumHelper.ConvertDataTypeFromString(
                        pRow.Value[fieldIndexes[5]].ToString().Trim());
                IBasicLayerInfo basicLayer = new BasicLayerInfo()
                {
                    Name         = pRow.Value[fieldIndexes[1]].ToString(),
                    AliasName    = pRow.Value[fieldIndexes[2]].ToString(),
                    AutoNames    = pRow.Value[fieldIndexes[3]].ToString(),
                    DataType     = dataType,
                    TemplateName = pRow.Value[fieldIndexes[6]].ToString(),
                    Fields       = new List <IYTField>()
                };
                if (pRow.Value[fieldIndexes[6]] != null)
                {
                    IPipelineTemplate template = templates.Find(c => c.Name == basicLayer.TemplateName);
                    if (template != null)
                    {
                        foreach (IYTField field in template.Fields)
                        {
                            basicLayer.Fields.Add(new YTField(field));
                        }
                    }
                }

                string domainStr = pRow.Value[fieldIndexes[7]] == DBNull.Value
                    ? string.Empty
                    : pRow.Value[fieldIndexes[7]].ToString();
                if (!string.IsNullOrEmpty(domainStr))
                {
                    //获得Domainzhi值
                    string[] domainPairs = domainStr.Split('/');
                    for (int j = 0; j < domainPairs.Length; j++)
                    {
                        string[]  domainPair = domainPairs[j].Split(':');
                        string    fieldName  = domainPair[0];
                        string    domainName = domainPair[1];
                        IYTDomain findDomain = domains.FirstOrDefault(c => c.DomainName == domainName);
                        if (findDomain != null)
                        {
                            IYTField pField = basicLayer.Fields.FirstOrDefault(c => c.TypeName == fieldName);
                            if (pField != null)
                            {
                                pField.Domain = new YTDomain(findDomain.DomainName, findDomain.DomainValues);
                            }
                        }
                    }
                }

                oneLayer.Layers.Add(basicLayer);
                pRow = pCursor.NextRow();
            }
            Marshal.ReleaseComObject(pCursor);
            Marshal.ReleaseComObject(tableSort);
            Marshal.ReleaseComObject(pCodeTable);
            return(layers);
        }
コード例 #22
0
        static void ImportCSV(string csvPath, string stylePath)
        {
            //the expected field names for this util
            string filePath          = "filePath";
            string pointSize         = "pointSize";
            string styleItemName     = "styleItemName";
            string styleItemCategory = "styleItemCategory";
            string styleItemTags     = "styleItemTags";

            IStyleGallery styleGallery = GetStyleGallery(stylePath);

            IStyleGalleryStorage styleGalleryStorage = styleGallery as IStyleGalleryStorage;

            styleGalleryStorage.TargetFile = stylePath;

            ITable             table = OpenCSVAsTable(csvPath);
            IRow               row = null;
            int                filePathIdx, styleItemNameIdx, pointSizeIdx, styleItemCategoryIdx, styleItemTagsIdx;
            IStyleGalleryItem3 styleGalleryItem = null;

            using (ComReleaser comReleaser = new ComReleaser())
            {
                // Create the cursor.
                ICursor cursor = table.Search(null, false);
                comReleaser.ManageLifetime(cursor);
                filePathIdx          = cursor.FindField(filePath);
                styleItemNameIdx     = cursor.FindField(styleItemName);
                pointSizeIdx         = cursor.FindField(pointSize);
                styleItemCategoryIdx = cursor.FindField(styleItemCategory);
                styleItemTagsIdx     = cursor.FindField(styleItemTags);

                int rowCount = 0;
                while ((row = cursor.NextRow()) != null)
                {
                    rowCount++;

                    try
                    {
                        String itemFilePath = (string)row.get_Value(filePathIdx);
                        IPictureMarkerSymbol pictureMarkerSymbol = MakeMarkerSymbol(itemFilePath, Convert.ToDouble(row.get_Value(pointSizeIdx)));

                        if (pictureMarkerSymbol == null)
                        {
                            Console.WriteLine("Image not found: Row: " + rowCount + ", Image: " + itemFilePath);
                            continue;
                        }

                        styleGalleryItem          = new StyleGalleryItemClass();
                        styleGalleryItem.Item     = pictureMarkerSymbol;
                        styleGalleryItem.Name     = row.get_Value(styleItemNameIdx) as string;
                        styleGalleryItem.Category = row.get_Value(styleItemCategoryIdx) as string;
                        object obj = row.get_Value(styleItemTagsIdx);

                        // set a default tag, just in case tags field is empty
                        string tags = styleGalleryItem.Category + ";" + styleGalleryItem.Name;

                        // Make sure tags are set & a valid string type before converting to string
                        if (!((obj == null) || (obj is DBNull)))
                        {
                            tags = obj as string;
                        }

                        const int MAX_TAG_LENGTH = 255;

                        int tagsLength = tags.Length;
                        if (tagsLength > MAX_TAG_LENGTH)
                        {
                            // WORKAROUND if length > 255 (a hard limit), trim from the front (last most important)
                            tags = tags.Substring(tagsLength - MAX_TAG_LENGTH, MAX_TAG_LENGTH);
                        }

                        // Note: Tag vector symbols for later (see: containsVectorTag)
                        // + switch to disable if desired
                        const bool TAG_EMFS_WITH_VECTOR_TAG = true;
                        if (TAG_EMFS_WITH_VECTOR_TAG &&
                            (itemFilePath.Substring(itemFilePath.Length - 4) == ".emf") &&
                            (!tags.ToUpper().Contains("VECTOR")))
                        {
                            tags = tags + ";vector";
                        }

                        styleGalleryItem.Tags = tags;

                        //we want tags for search. If they weren't specified, use the default tags
                        if (styleGalleryItem.Tags == "")
                        {
                            styleGalleryItem.Tags = styleGalleryItem.DefaultTags;
                        }

                        Console.WriteLine("Importing symbol " + rowCount + " : " + styleGalleryItem.Name);
                        styleGallery.AddItem((IStyleGalleryItem)styleGalleryItem);
                    }
                    catch (Exception ex)
                    {
                        // Catch-all exception for row processing, just so 1 bad row doesn't abort the whole process
                        Console.WriteLine("Skipping bad row: " + rowCount + ", Exception : " + ex.Message);
                        continue;
                    }
                }
            }
        }
コード例 #23
0
        private void buildModelftr()
        {
            sumX.Clear();
            sumX2.Clear();
            cateDic.Clear();
            lbl.Clear();
            int v1 = VariableFieldNames.Length;

            double[] s  = new double[(v1 * v1 - v1) / 2];
            double[] s2 = new double[s.Length];
            n = 0;
            IQueryFilter qf = new QueryFilterClass();

            qf.SubFields = StrataField + "," + String.Join(",", VariableFieldNames);
            ICursor cur = InTable.Search(qf, false);

            int[] varIndex = new int[VariableFieldNames.Length];
            for (int i = 0; i < VariableFieldNames.Length; i++)
            {
                string var = VariableFieldNames[i];
                varIndex[i] = cur.FindField(var);
            }
            int  stIndex = cur.FindField(StrataField);
            IRow rw      = cur.NextRow();

            while (rw != null)
            {
                object strata = rw.get_Value(stIndex);
                if (strata == null)
                {
                    continue;
                }
                else
                {
                    string strataStr = strata.ToString();
                    int    strataIndex;
                    int    cnt;
                    if (cateDic.TryGetValue(strataStr, out cnt))
                    {
                        cnt         = cnt + 1;
                        strataIndex = lbl.IndexOf(strataStr);
                        s           = sumX[strataIndex];
                        s2          = sumX2[strataIndex];
                    }
                    else
                    {
                        cnt = 1;
                        cateDic.Add(strataStr, 0);
                        lbl.Add(strataStr);
                        strataIndex = lbl.Count - 1;
                        s           = new double[s.Length];
                        s2          = new double[s.Length];
                        sumX.Add(s);
                        sumX2.Add(s2);
                    }
                    bool     checkVl = true;
                    double[] vlArr   = new double[VariableFieldNames.Length];
                    for (int p = 0; p < VariableFieldNames.Length; p++)
                    {
                        int    fldIndex = varIndex[p];
                        object vl       = rw.get_Value(fldIndex);
                        if (vl == null)
                        {
                            checkVl = false;
                            break;
                        }
                        else
                        {
                            vlArr[p] = System.Convert.ToDouble(vl);
                        }
                    }
                    if (checkVl)
                    {
                        int vlCnter = 1;
                        int sCnter  = 0;
                        for (int i = 0; i < vlArr.Length - 1; i++)
                        {
                            for (int k = vlCnter; k < vlArr.Length; k++)
                            {
                                double m  = vlArr[i] - vlArr[k];
                                double m2 = m * m;
                                s[sCnter]  = s[sCnter] + m;
                                s2[sCnter] = s2[sCnter] + m2;
                                sCnter    += 1;
                            }
                            vlCnter += 1;
                        }
                        cateDic[strataStr] = cnt;
                        n += 1;
                    }
                }
                rw = cur.NextRow();
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(cur);
        }
コード例 #24
0
        /// <summary>
        /// Excecute is called by Data Reviewer engine and passed the appropriate parameters.
        /// </summary>
        /// <param name="ipSelectionToValidate">ISelectionSet of features/rows to validate</param>
        /// <param name="arguments">comma delimited string of arguments</param>
        /// <returns>
        /// Collection of validation results.
        /// </returns>
        public IPLTSErrorCollection Execute(ISelectionSet ipSelectionToValidate, string arguments)
        {
            if (null == ipSelectionToValidate)
            {
                throw new ArgumentNullException("ISelectionSet parameter is null");
            }

            if (String.IsNullOrEmpty(arguments))
            {
                throw new ArgumentNullException("string parameter is null or empty");
            }

            //Get cursor of selected features/rows
            ICursor ipCursor = null;

            ipSelectionToValidate.Search(null, true, out ipCursor);

            IDataset      ipSourceDataset      = ipSelectionToValidate.Target as IDataset;
            IFeatureClass ipSourceFeatureClass = null;

            //Setup reference to feature class to be used when creating results
            if (ipSourceDataset.Type == esriDatasetType.esriDTFeatureClass)
            {
                ipSourceFeatureClass = ipSourceDataset as IFeatureClass;
            }

            //Get the index of the field we are checking
            int iIndexOfField = -1;

            iIndexOfField = ipCursor.FindField(arguments); //arguments is the name of the field we are checking

            if (-1 == iIndexOfField)
            {
                throw new Exception(String.Format("Field {0} was not found in Dataset {1}", arguments, ipSourceDataset.Name));
            }

            //Collection of results passed back to Data Reviewer
            IPLTSErrorCollection ipRevResultCollection = new PLTSErrorCollectionClass();

            //Loop through rows and check if field is numeric
            IRow ipRow = ipCursor.NextRow();

            while (null != ipRow)
            {
                object oValue     = ipRow.get_Value(iIndexOfField);
                bool   bIsNumeric = false;
                if (null != oValue)
                {
                    double dOutValue;
                    bIsNumeric = double.TryParse(oValue.ToString().Trim(),
                                                 System.Globalization.NumberStyles.Any,
                                                 System.Globalization.CultureInfo.CurrentCulture,
                                                 out dOutValue);
                }

                if (!bIsNumeric)
                {
                    //Create Reviewer result and add to collection
                    IPLTSError2 ipRevResult = new PLTSErrorClass() as IPLTSError2;
                    ipRevResult.ErrorKind          = pltsValErrorKind.pltsValErrorKindStandard;
                    ipRevResult.OID                = ipRow.OID;
                    ipRevResult.QualifiedTableName = ipSourceDataset.Name;
                    ipRevResult.ShortDescription   = "Field does not contain a number";
                    ipRevResult.LongDescription    = oValue.ToString() + " in " + arguments + " is not a number.";

                    if (null != ipSourceFeatureClass)
                    {
                        IFeature ipFeature = ipSourceFeatureClass.GetFeature(ipRow.OID);
                        if (null != ipFeature)
                        {
                            ipRevResult.ErrorGeometry = ipFeature.ShapeCopy;
                        }
                    }

                    ipRevResultCollection.AddError(ipRevResult);
                }

                ipRow = ipCursor.NextRow();
            }//end while

            //Release cursor
            Marshal.ReleaseComObject(ipCursor);
            ipCursor = null;

            //Return the collection of results
            return(ipRevResultCollection);
        }
コード例 #25
0
        private void formatData()
        {
            string depFldName = DependentFieldNames[0];

            if (unVlDic == null)
            {
                unVlDic = UniqueClassValues;
            }
            int indCnt = IndependentFieldNames.Length;
            int depCnt = DependentFieldNames.Length;
            int rws    = InTable.RowCount(null);

            n = rws;
            ICursor cur  = InTable.Search(null, false);
            int     clms = indCnt;

            int[] allFieldIndexArray = new int[clms];
            allFieldNames = new string[clms];
            for (int i = 0; i < indCnt; i++)
            {
                string lu = IndependentFieldNames[i];
                allFieldNames[i]      = lu;
                allFieldIndexArray[i] = cur.FindField(lu);
                List <string> outSet = null;
                if (unVlDic.TryGetValue(lu, out outSet))
                {
                    int t = (outSet.Count() - 1);
                    clms = clms + t;
                }
            }
            categories = unVlDic[depFldName].ToArray();
            ncat       = categories.Length;
            int depIndex = cur.FindField(depFldName);

            nvars       = clms;
            independent = new double[rws][];
            dependent   = new double[rws];
            int  rwCnt = 0;
            IRow rw    = cur.NextRow();

            while (rw != null)
            {
                int      indMatrixClm = 0;
                double[] rwVls        = new double[clms];
                for (int i = 0; i < allFieldIndexArray.Length; i++)
                {
                    string lu         = allFieldNames[i];
                    int    fldClmCntT = 1;
                    int    indexFld   = allFieldIndexArray[i];
                    object vl         = rw.get_Value(indexFld);
                    updateMinMaxSum(vl, i);
                    double dblVl = 0;
                    try
                    {
                        string        strVl = vl.ToString();
                        List <string> unVl  = null;
                        if (unVlDic.TryGetValue(lu, out unVl))
                        {
                            int fldClmCntP = unVl.IndexOf(strVl);
                            fldClmCntT    = unVl.Count() - fldClmCntP;
                            indMatrixClm += fldClmCntP;
                            dblVl         = 1;
                        }
                        else
                        {
                            dblVl = System.Convert.ToDouble(strVl);
                        }
                    }
                    catch
                    {
                        dblVl = 0;
                    }
                    rwVls[indMatrixClm] = dblVl;
                    indMatrixClm       += fldClmCntT;
                }
                independent[rwCnt] = rwVls;
                string dVl   = rw.get_Value(depIndex).ToString();
                int    index = unVlDic[depFldName].IndexOf(dVl);
                dependent[rwCnt] = index;
                rw     = cur.NextRow();
                rwCnt += 1;
            }
        }
コード例 #26
0
        private void buildSamples(string s)
        {
            Random rn = new Random();
            double mS = maxSample * 1.05; // to make sure we get max sample give random nature of Random function

            //double minS = maxSample / Variables.Length; // to make sure we get min samples given random nature of Random function
            sample1 = new double[Variables.Length][];
            sample2 = new double[Variables.Length][];
            int[]  strataCnt = cntDic[s];
            int    s1        = strataCnt[0] * Variables.Length;
            int    s2        = strataCnt[1] * Variables.Length;
            double r1        = 1;
            double r2        = 1;
            double sr1       = 1;
            double sr2       = 1;

            if (s1 > mS)
            {
                r1  = mS / s1;
                sr1 = maxSample / s1;
            }
            if (s2 > mS)
            {
                r2  = mS / s2;
                sr2 = maxSample / s2;
            }
            int ss1 = System.Convert.ToInt32((sr1 * strataCnt[0])); // / Variables.Length);
            int ss2 = System.Convert.ToInt32((sr2 * strataCnt[1])); // / Variables.Length);

            //Console.WriteLine("ss1,ss2 = " + ss1.ToString() + "," + ss2.ToString());

            for (int i = 0; i < Variables.Length; i++)
            {
                double[] vlArr1 = new double[ss1];
                double[] vlArr2 = new double[ss2];
                sample1[i] = vlArr1;
                sample2[i] = vlArr2;
            }
            IQueryFilter qf = new QueryFilterClass();

            if (StrataField == "")
            {
                qf.SubFields = String.Join(",", Variables);
            }
            else
            {
                qf.SubFields = StrataField + "," + String.Join(",", Variables);
                string d = "";
                if (Sample1.Fields.get_Field(Sample1.FindField(StrataField)).Type == esriFieldType.esriFieldTypeString)
                {
                    d = "'";
                }
                qf.WhereClause = StrataField + " = " + d + s + d;
            }
            ICursor cur = Sample1.Search(qf, false);

            int[]    fldIndexArr = new int[Variables.Length];
            double[] minArr      = new double[Variables.Length];
            double[] maxArr      = new double[Variables.Length];
            minArr[0] = Double.MaxValue - 100;
            maxArr[0] = Double.MinValue + 100;
            for (int i = 0; i < fldIndexArr.Length; i++)
            {
                fldIndexArr[i] = cur.FindField(Variables[i]);
            }
            IRow rw   = cur.NextRow();
            int  tCnt = 0;

            double[] vArr  = new double[Variables.Length];
            double[] vArr2 = new double[Variables.Length];
            clusCountDic.Add(s, new int[numberOfBins]);
            int[] clusVArr = clusCountDic[s];
            //Console.WriteLine("Start iteration 1");
            while (rw != null && tCnt < ss1)
            {
                double nRn = rn.NextDouble();
                if (nRn <= r1)
                {
                    bool checkVls = true;
                    for (int i = 0; i < fldIndexArr.Length; i++)
                    {
                        object vlObj = rw.get_Value(fldIndexArr[i]);
                        if (vlObj == null)
                        {
                            checkVls = false;
                            break;
                        }
                        vArr[i] = System.Convert.ToDouble(vlObj);
                    }
                    if (checkVls)
                    {
                        int clusCl = cluster.computNew(vArr);
                        clusVArr[clusCl] = clusVArr[clusCl] + 1;
                        if (Oridinate)
                        {
                            vArr2 = pca.computNew(vArr);
                        }
                        else
                        {
                            vArr2 = vArr;
                        }
                        for (int i = 0; i < fldIndexArr.Length; i++)
                        {
                            double vl = vArr2[i];
                            sample1[i][tCnt] = vl;
                            if (vl < minArr[i])
                            {
                                minArr[i] = vl;
                            }
                            if (vl > maxArr[i])
                            {
                                maxArr[i] = vl;
                            }
                        }
                        tCnt += 1;
                    }
                }
                rw = cur.NextRow();
            }
            double[][] minMax = new double[2][];
            minMax[0] = minArr;
            minMax[1] = maxArr;
            //Console.WriteLine(String.Join(",", (from double d in minArr select d.ToString()).ToArray()));
            //Console.WriteLine(String.Join(",", (from double d in maxArr select d.ToString()).ToArray()));
            minMaxDic1.Add(s, minMax);
            qf = new QueryFilterClass();
            if (StrataField == "")
            {
                qf.SubFields = String.Join(",", Variables);
            }
            else
            {
                qf.SubFields = StrataField + "," + String.Join(",", Variables);
                string d = "";
                if (Sample1.Fields.get_Field(Sample1.FindField(StrataField)).Type == esriFieldType.esriFieldTypeString)
                {
                    d = "'";
                }
                qf.WhereClause = StrataField + " = " + d + s + d;
            }
            cur       = Sample2.Search(qf, false);
            minArr    = new double[Variables.Length];
            maxArr    = new double[Variables.Length];
            minArr[0] = Double.MaxValue;
            maxArr[0] = Double.MinValue;
            for (int i = 0; i < fldIndexArr.Length; i++)
            {
                fldIndexArr[i] = cur.FindField(Variables[i]);
            }
            rw   = cur.NextRow();
            tCnt = 0;
            clusSampleCountDic.Add(s, new int[numberOfBins]);
            clusVArr = clusSampleCountDic[s];
            //Console.WriteLine("Start iteration2");
            while (rw != null && tCnt < ss2)
            {
                double nRn = rn.NextDouble();
                if (nRn <= r2)
                {
                    bool checkVls = true;
                    for (int i = 0; i < fldIndexArr.Length; i++)
                    {
                        object vlObj = rw.get_Value(fldIndexArr[i]);
                        if (vlObj == null)
                        {
                            checkVls = false;
                            break;
                        }
                        vArr[i] = System.Convert.ToDouble(vlObj);
                    }
                    if (checkVls)
                    {
                        int clusCl = cluster.computNew(vArr);
                        clusVArr[clusCl] = clusVArr[clusCl] + 1;
                        if (Oridinate)
                        {
                            vArr2 = pca.computNew(vArr);
                        }
                        else
                        {
                            vArr2 = vArr;
                        }
                        for (int i = 0; i < fldIndexArr.Length; i++)
                        {
                            double vl = vArr2[i];
                            sample2[i][tCnt] = vl;
                            if (vl < minArr[i])
                            {
                                minArr[i] = vl;
                            }
                            if (vl > maxArr[i])
                            {
                                maxArr[i] = vl;
                            }
                        }
                        tCnt += 1;
                    }
                }
                rw = cur.NextRow();
            }
            minMax    = new double[2][];
            minMax[0] = minArr;
            minMax[1] = maxArr;
            //Console.WriteLine(String.Join(",", (from double d in minArr select d.ToString()).ToArray()));
            //Console.WriteLine(String.Join(",", (from double d in maxArr select d.ToString()).ToArray()));
            minMaxDic2.Add(s, minMax);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(cur);
            //Console.WriteLine("Finished iterations");
        }
コード例 #27
0
        protected override void OnClick()
        {
            IMouseCursor pMouseCursor = new MouseCursorClass();

            pMouseCursor.SetCursor(2);

            //first get the selected parcel features
            UID pUID = new UIDClass();

            pUID.Value = "{114D685F-99B7-4B63-B09F-6D1A41A4DDC1}";
            ICadastralExtensionManager2 pCadExtMan = (ICadastralExtensionManager2)ArcMap.Application.FindExtensionByCLSID(pUID);
            ICadastralEditor            pCadEd     = (ICadastralEditor)ArcMap.Application.FindExtensionByCLSID(pUID);

            Marshal.ReleaseComObject(pUID);

            IEditor pEd = (IEditor)ArcMap.Application.FindExtensionByName("esri object editor");

            IFeatureLayer CFPointLayer = null; IFeatureLayer CFLineLayer = null;
            IFeatureLayer CFControlLayer   = null;
            IFeatureLayer CFLinePointLayer = null;

            IActiveView      pActiveView       = ArcMap.Document.ActiveView;
            IMap             pMap              = pActiveView.FocusMap;
            ICadastralFabric pCadFabric        = null;
            IProgressDialog2 pProgressorDialog = null;

            clsFabricUtils UTILS = new clsFabricUtils();

            //if we're in an edit session then grab the target fabric
            if (pEd.EditState == esriEditState.esriStateEditing)
            {
                pCadFabric = pCadEd.CadastralFabric;
            }

            if (pCadFabric == null)
            {//find the first fabric in the map
                if (!UTILS.GetFabricFromMap(pMap, out pCadFabric))
                {
                    MessageBox.Show
                        ("No Parcel Fabric found in the map.\r\nPlease add a single fabric to the map, and try again.");
                    return;
                }
            }

            IArray CFParcelLayers = new ArrayClass();

            if (!(UTILS.GetFabricSubLayersFromFabric(pMap, pCadFabric, out CFPointLayer, out CFLineLayer,
                                                     out CFParcelLayers, out CFControlLayer, out CFLinePointLayer)))
            {
                return; //no fabric sublayers available for the targeted fabric
            }
            bool       bIsFileBasedGDB = false; bool bIsUnVersioned = false; bool bUseNonVersioned = false;
            IWorkspace pWS = null;

            try
            {
                //Get the selection of parcels
                IFeatureLayer pFL = (IFeatureLayer)CFParcelLayers.get_Element(0);
                IDataset      pDS = (IDataset)pFL.FeatureClass;
                pWS = pDS.Workspace;

                if (!UTILS.SetupEditEnvironment(pWS, pCadFabric, pEd, out bIsFileBasedGDB,
                                                out bIsUnVersioned, out bUseNonVersioned))
                {
                    return;
                }

                if (bUseNonVersioned)
                {
                    ICadastralFabricLayer pCFLayer = new CadastralFabricLayerClass();
                    pCFLayer.CadastralFabric    = pCadFabric;
                    pCadEd.CadastralFabricLayer = pCFLayer;//NOTE: Need to set this back to NULL when done.
                }

                Hashtable   FabLyrToFieldMap   = new Hashtable();
                DateChanger pDateChangerDialog = new DateChanger();
                pDateChangerDialog.cboBoxFabricClasses.Items.Clear();
                string[] FieldStrArr = new string[CFParcelLayers.Count];
                for (int i = 0; i < CFParcelLayers.Count; i++)
                {
                    FieldStrArr[i] = "";
                    IFeatureLayer lyr = (IFeatureLayer)CFParcelLayers.get_Element(i);
                    //   ICadastralFabricLayer cflyr = CFParcelLayers.get_Element(i);

                    pDateChangerDialog.cboBoxFabricClasses.Items.Add(lyr.Name);
                    IFields pFlds = lyr.FeatureClass.Fields;
                    for (int j = 0; j < lyr.FeatureClass.Fields.FieldCount; j++)
                    {
                        IField pFld = lyr.FeatureClass.Fields.get_Field(j);
                        if (pFld.Type == esriFieldType.esriFieldTypeDate)
                        {
                            if (FieldStrArr[i].Trim() == "")
                            {
                                FieldStrArr[i] = pFld.Name;
                            }
                            else
                            {
                                FieldStrArr[i] += "," + pFld.Name;
                            }
                        }
                    }
                    FabLyrToFieldMap.Add(i, FieldStrArr[i]);
                }
                pDateChangerDialog.FieldMap = FabLyrToFieldMap;
                pDateChangerDialog.cboBoxFabricClasses.SelectedIndex = 0;



                // ********  Display the dialog  *********
                DialogResult pDialogResult = pDateChangerDialog.ShowDialog();
                if (pDialogResult != DialogResult.OK)
                {
                    return;
                }
                //************************

                //*** get the choices from the dialog
                IFeatureLayer flyr     = (IFeatureLayer)CFParcelLayers.get_Element(pDateChangerDialog.cboBoxFabricClasses.SelectedIndex);
                int           iDateFld = flyr.FeatureClass.Fields.FindField(pDateChangerDialog.cboBoxFields.Text);

                if (pDateChangerDialog.radioButton2.Checked)
                {
                    IField pFld = flyr.FeatureClass.Fields.get_Field(iDateFld);
                    if (!pFld.IsNullable)
                    {
                        MessageBox.Show("The field you selected does not allow NULL values, and must have a date." + Environment.NewLine +
                                        "Please try again using the date option, or using a different date field.", "Field does not Allow Null", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }

                ICadastralFabricSubLayer pSubLyr = (ICadastralFabricSubLayer)flyr;
                bool bLines   = false;
                bool bParcels = false;
                if (pSubLyr.CadastralTableType == esriCadastralFabricTable.esriCFTLines)
                {
                    bLines = true;
                }
                if (pSubLyr.CadastralTableType == esriCadastralFabricTable.esriCFTParcels)
                {
                    bParcels = true;
                }

                //find out if there is a selection for the chosen layer
                bool ChosenLayerHasSelection = false;

                IFeatureSelection   pFeatSel       = null;
                ISelectionSet2      pSelSet        = null;
                ICadastralSelection pCadaSel       = null;
                IEnumGSParcels      pEnumGSParcels = null;

                int iFeatureCnt = 0;
                pFeatSel = (IFeatureSelection)flyr;
                if (pFeatSel != null)
                {
                    pSelSet = (ISelectionSet2)pFeatSel.SelectionSet;
                    ChosenLayerHasSelection = (pSelSet.Count > 0);
                    iFeatureCnt             = pSelSet.Count;
                }
                //****

                if (iFeatureCnt == 0)
                {
                    if (MessageBox.Show("There are no features selected in the " + flyr.Name + " layer." + Environment.NewLine + "Click OK to Change dates for ALL features in the layer.", "No Selection",
                                        MessageBoxButtons.OKCancel) != DialogResult.OK)
                    {
                        return;
                    }
                }
                else
                {
                    pCadaSel = (ICadastralSelection)pCadEd;
                    //** TODO: this enum should be based on the selected points, lines, or line-points
                    pEnumGSParcels = pCadaSel.SelectedParcels;// need to get the parcels before trying to get the parcel count: BUG workaround
                    //***
                }

                if (iFeatureCnt == 0)
                {
                    m_pCursor = (ICursor)flyr.FeatureClass.Search(null, false);
                    ITable pTable = (ITable)flyr.FeatureClass;
                    iFeatureCnt = pTable.RowCount(null);
                }

                m_bShowProgressor = (iFeatureCnt > 10);
                if (m_bShowProgressor)
                {
                    m_pProgressorDialogFact     = new ProgressDialogFactoryClass();
                    m_pTrackCancel              = new CancelTrackerClass();
                    m_pStepProgressor           = m_pProgressorDialogFact.Create(m_pTrackCancel, ArcMap.Application.hWnd);
                    pProgressorDialog           = (IProgressDialog2)m_pStepProgressor;
                    m_pStepProgressor.MinRange  = 1;
                    m_pStepProgressor.MaxRange  = iFeatureCnt;
                    m_pStepProgressor.StepValue = 1;
                    pProgressorDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressSpiral;
                }
                m_pQF = new QueryFilterClass();
                string sPref; string sSuff;

                ISQLSyntax pSQLSyntax = (ISQLSyntax)pWS;
                sPref = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix);
                sSuff = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierSuffix);

                //====== need to do this for all the parcel sublayers in the map that are part of the target fabric
                if (m_bShowProgressor)
                {
                    pProgressorDialog.ShowDialog();
                    m_pStepProgressor.Message = "Collecting data...";
                }

                bool bCont = true;
                m_pFIDSetParcels = new FIDSetClass();

                if (ChosenLayerHasSelection && bParcels && !bIsUnVersioned)
                {
                    //if there is a selection add the OIDs of all the selected parcels into a new feature IDSet
                    pEnumGSParcels.Reset();
                    IGSParcel pGSParcel = pEnumGSParcels.Next();

                    while (pGSParcel != null)
                    {
                        //Check if the cancel button was pressed. If so, stop process
                        if (m_bShowProgressor)
                        {
                            bCont = m_pTrackCancel.Continue();
                            if (!bCont)
                            {
                                break;
                            }
                        }
                        m_pFIDSetParcels.Add(pGSParcel.DatabaseId);
                        Marshal.ReleaseComObject(pGSParcel); //garbage collection
                        pGSParcel = pEnumGSParcels.Next();
                        //}
                        if (m_bShowProgressor)
                        {
                            if (m_pStepProgressor.Position < m_pStepProgressor.MaxRange)
                            {
                                m_pStepProgressor.Step();
                            }
                        }
                    }
                }

                if ((!ChosenLayerHasSelection && bParcels && !bIsUnVersioned) ||
                    (!ChosenLayerHasSelection && bLines && !bIsUnVersioned))
                {
                    IRow pRow = m_pCursor.NextRow();
                    while (pRow != null)
                    {
                        m_pFIDSetParcels.Add(pRow.OID);
                        Marshal.ReleaseComObject(pRow);
                        pRow = m_pCursor.NextRow();
                    }
                    Marshal.ReleaseComObject(m_pCursor);
                }

                if (bLines && ChosenLayerHasSelection && !bIsUnVersioned)
                {
                    pSelSet.Search(null, false, out m_pCursor);
                    IRow pRow = m_pCursor.NextRow();
                    int  iFld = m_pCursor.FindField("PARCELID");
                    while (pRow != null)
                    {
                        m_pFIDSetParcels.Add((int)pRow.get_Value(iFld));
                        Marshal.ReleaseComObject(pRow);
                        pRow = m_pCursor.NextRow();
                    }
                    Marshal.ReleaseComObject(m_pCursor);
                }

                //=========================================================
                if (!bCont)
                {
                    //Since I'm using update cursor need to clear the cadastral selection
                    pCadaSel.SelectedParcels = null;
                    //clear selection, to make sure the parcel explorer is updated and refreshed properly
                    return;
                }

                string sTime = "";
                if (!bIsUnVersioned)
                {
                    //see if parcel locks can be obtained on the selected parcels. First create a job.
                    DateTime localNow = DateTime.Now;
                    sTime = Convert.ToString(localNow);
                    ICadastralJob pJob = new CadastralJobClass();
                    pJob.Name        = sTime;
                    pJob.Owner       = System.Windows.Forms.SystemInformation.UserName;
                    pJob.Description = "Change Date on selected parcels";
                    try
                    {
                        Int32 jobId = pCadFabric.CreateJob(pJob);
                    }
                    catch (COMException ex)
                    {
                        if (ex.ErrorCode == (int)fdoError.FDO_E_CADASTRAL_FABRIC_JOB_ALREADY_EXISTS)
                        {
                            MessageBox.Show("Job named: '" + pJob.Name + "', already exists");
                        }
                        else
                        {
                            MessageBox.Show(ex.Message);
                        }
                        m_pStepProgressor = null;
                        if (!(pProgressorDialog == null))
                        {
                            pProgressorDialog.HideDialog();
                        }
                        pProgressorDialog = null;
                        if (bUseNonVersioned)
                        {
                            pCadEd.CadastralFabricLayer = null;
                        }
                        return;
                    }
                }

                //if we're in an enterprise then test for edit locks
                ICadastralFabricLocks pFabLocks = (ICadastralFabricLocks)pCadFabric;
                if (!bIsUnVersioned)
                {
                    pFabLocks.LockingJob = sTime;
                    ILongArray pLocksInConflict    = null;
                    ILongArray pSoftLcksInConflict = null;

                    ILongArray pParcelsToLock = new LongArrayClass();

                    UTILS.FIDsetToLongArray(m_pFIDSetParcels, ref pParcelsToLock, m_pStepProgressor);
                    if (m_pStepProgressor != null && !bIsFileBasedGDB)
                    {
                        m_pStepProgressor.Message = "Testing for edit locks on parcels...";
                    }

                    try
                    {
                        pFabLocks.AcquireLocks(pParcelsToLock, true, ref pLocksInConflict, ref pSoftLcksInConflict);
                    }
                    catch (COMException pCOMEx)
                    {
                        if (pCOMEx.ErrorCode == (int)fdoError.FDO_E_CADASTRAL_FABRIC_JOB_LOCK_ALREADY_EXISTS)
                        {
                            MessageBox.Show("Edit Locks could not be acquired on all selected parcels.");
                            // since the operation is being aborted, release any locks that were acquired
                            pFabLocks.UndoLastAcquiredLocks();
                            //clear selection, to make sure the parcel explorer is updated and refreshed properly
                            RefreshMap(pActiveView, CFParcelLayers, CFPointLayer, CFLineLayer, CFControlLayer, CFLinePointLayer);
                        }
                        else
                        {
                            MessageBox.Show(Convert.ToString(pCOMEx.ErrorCode));
                        }

                        if (bUseNonVersioned)
                        {
                            pCadEd.CadastralFabricLayer = null;
                        }
                        return;
                    }
                }

                //Now... start the edit. Start an edit operation.
                if (pEd.EditState == esriEditState.esriStateEditing)
                {
                    pEd.StartOperation();
                }

                if (bUseNonVersioned)
                {
                    if (!UTILS.StartEditing(pWS, bUseNonVersioned))
                    {
                        if (bUseNonVersioned)
                        {
                            pCadEd.CadastralFabricLayer = null;
                        }
                        return;
                    }
                }

                //Change all the date records
                if (m_pStepProgressor != null)
                {
                    m_pStepProgressor.Message = "Changing dates...";
                }

                bool bSuccess = true;

                ITable      Table2Edit = (ITable)flyr.FeatureClass;
                ITableWrite pTableWr   = (ITableWrite)Table2Edit;

                if (ChosenLayerHasSelection)
                {
                    //TODO: Selection based update does not work on unversioned tables
                    //need to change this code to create an update cursor from the selection,
                    //including code for tokens > 995
                    pSelSet.Update(null, false, out m_pCursor);
                }
                else
                {
                    if (bUseNonVersioned)
                    {
                        m_pCursor = pTableWr.UpdateRows(null, false);
                    }
                    else
                    {
                        m_pCursor = Table2Edit.Update(null, false);
                    }
                }
                ICadastralFabricSchemaEdit2 pSchemaEd = (ICadastralFabricSchemaEdit2)pCadFabric;
                if (bLines)
                {
                    pSchemaEd.ReleaseReadOnlyFields(Table2Edit,
                                                    esriCadastralFabricTable.esriCFTLines); //release safety-catch
                }
                else if (bParcels)
                {
                    pSchemaEd.ReleaseReadOnlyFields(Table2Edit,
                                                    esriCadastralFabricTable.esriCFTParcels); //release safety-catch
                }
                else
                {
                    pSchemaEd.ReleaseReadOnlyFields(Table2Edit,
                                                    esriCadastralFabricTable.esriCFTPoints);     //release safety-catch
                    pSchemaEd.ReleaseReadOnlyFields(Table2Edit,
                                                    esriCadastralFabricTable.esriCFTControl);    //release safety-catch
                    pSchemaEd.ReleaseReadOnlyFields(Table2Edit,
                                                    esriCadastralFabricTable.esriCFTLinePoints); //release safety-catch
                }

                if (pDateChangerDialog.radioButton2.Checked)
                {
                    bSuccess = UTILS.ChangeDatesOnTable(m_pCursor, pDateChangerDialog.cboBoxFields.Text, "",
                                                        bUseNonVersioned, m_pStepProgressor, m_pTrackCancel);
                }
                else
                {
                    bSuccess = UTILS.ChangeDatesOnTable(m_pCursor, pDateChangerDialog.cboBoxFields.Text,
                                                        pDateChangerDialog.dateTimePicker1.Text, bUseNonVersioned, m_pStepProgressor, m_pTrackCancel);
                }

                if (!bSuccess)
                {
                    if (!bIsUnVersioned)
                    {
                        pFabLocks.UndoLastAcquiredLocks();
                    }
                    if (bUseNonVersioned)
                    {
                        UTILS.AbortEditing(pWS);
                    }
                    else
                    {
                        pEd.AbortOperation();
                    }
                    //clear selection, to make sure the parcel explorer is updated and refreshed properly

                    return;
                }

                if (pEd.EditState == esriEditState.esriStateEditing)
                {
                    pEd.StopOperation("Change Date");
                }

                if (bUseNonVersioned)
                {
                    UTILS.StopEditing(pWS);
                }

                if (bParcels)
                {
                    pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTParcels);
                }
                else if (bLines)
                {
                    pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTLines);
                }
                else
                {
                    pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTPoints);     //release safety-catch
                    pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTControl);    //release safety-catch
                    pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTLinePoints); //release safety-catch
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:" + ex.Message);
                if (bUseNonVersioned)
                {
                    UTILS.AbortEditing(pWS);
                }
                else
                {
                    pEd.AbortOperation();
                }
            }
            finally
            {
                RefreshMap(pActiveView, CFParcelLayers, CFPointLayer, CFLineLayer, CFControlLayer, CFLinePointLayer);

                if (bUseNonVersioned)
                {
                    pCadEd.CadastralFabricLayer = null;
                    CFParcelLayers   = null;
                    CFPointLayer     = null;
                    CFLineLayer      = null;
                    CFControlLayer   = null;
                    CFLinePointLayer = null;
                }

                m_pStepProgressor = null;
                if (!(pProgressorDialog == null))
                {
                    pProgressorDialog.HideDialog();
                }
                pProgressorDialog = null;
            }
        }
コード例 #28
0
ファイル: LayerCatalogAdapter.cs プロジェクト: zj8487/HyDM
        private void Load3DLayers2()
        {
            IWorkspace wsSource = GISOpr.getInstance().WorkSpace;
            // 为了在Skyline下预览数据, 必须取得数据库的连接信息
            DBCore       db                  = new DBCore(true);
            IList        paramList           = db.GetAll(typeof(Tbsysparams), "Paramid");
            IPropertySet workspaceProperySet = new PropertySetClass();

            foreach (Tbsysparams param in paramList)
            {
                if (param.Paramenname.ToUpper() == "SDESERVER")
                {
                    workspaceProperySet.SetProperty("Server", param.Paramvalue);
                }
                if (param.Paramenname.ToUpper() == "SDEINSTANCE")
                {
                    workspaceProperySet.SetProperty("Instance", param.Paramvalue);
                }
                if (param.Paramenname.ToUpper() == "SDEVERSION")
                {
                    workspaceProperySet.SetProperty("Version", param.Paramvalue);
                }
                if (param.Paramenname.ToUpper() == "SDEUSER")
                {
                    workspaceProperySet.SetProperty("User", param.Paramvalue);
                }
                if (param.Paramenname.ToUpper() == "SDEPASSWORD")
                {
                    workspaceProperySet.SetProperty("Password", param.Paramvalue);
                }
            }
            IWorkspaceCatalogItem itemWorkspace = new WorkspaceCatalogItem(workspaceProperySet, Hy.Catalog.Utility.enumWorkspaceType.SDE, null, "当前空间数据库");

            if ((wsSource as IWorkspace2).get_NameExists(esriDatasetType.esriDTTable, "ThreeDimenLayersCache"))
            {
                IFeatureWorkspace fwsSource = (wsSource as IFeatureWorkspace);
                ITable            t3DLayers = fwsSource.OpenTable("ThreeDimenLayersCache");
                ICursor           cursor    = t3DLayers.Search(null, true);
                IRow rowLayer   = cursor.NextRow();
                int  fNameIndex = cursor.FindField("LayerName");
                int  fTypeIndex = cursor.FindField("LayerType");
                int  f3DType    = (int)enumCatalogType.FeatureClass3D;
                while (rowLayer != null)
                {
                    if (f3DType == Convert.ToInt32(rowLayer.get_Value(fTypeIndex)))
                    {
                        IFeatureClass fClass3D = fwsSource.OpenFeatureClass(rowLayer.get_Value(fNameIndex) as string);

                        //
                        ICatalogItem curItem = new FeatureClassCatalogItem((fClass3D as IDataset).FullName as IDatasetName, null);
                        curItem.WorkspaceItem = itemWorkspace;
                        TreeNode node3D = this.m_Node3D.Nodes.Add(curItem.Name);
                        node3D.ImageIndex         = 19;
                        node3D.SelectedImageIndex = 19;

                        node3D.Tag = curItem;
                    }
                    rowLayer = cursor.NextRow();
                }
            }
            else
            {
                // ParentName和Desription(以及LayerType)都保留,到支持栅格数据时可能用得到
                string strSQL = @"Create Table ThreeDimenLayersCache(
                                    LayerName varchar2(256) not null,
                                    ParentName varchar2(256) ,
                                    Description varchar(4000),
                                    LayerType INTEGER default "
                                + ((int)enumCatalogType.FeatureClass3D).ToString()
                                + ")";

                wsSource.ExecuteSQL(strSQL);

                IEnumDatasetName enDatasetName = wsSource.get_DatasetNames(esriDatasetType.esriDTFeatureClass);
                IDatasetName     dsName3D      = enDatasetName.Next();
                while (dsName3D != null)
                {
                    if ((dsName3D as IFeatureClass).ShapeType == esriGeometryType.esriGeometryMultiPatch)
                    {
                        // 存入数据库缓存并加载到树上
                        strSQL = string.Format("Insert into ThreeDimenLayersCache(LayerName) values('{0}')", dsName3D.Name);
                        wsSource.ExecuteSQL(strSQL);

                        //
                        ICatalogItem curItem = new FeatureClassCatalogItem(dsName3D, null);
                        curItem.WorkspaceItem = itemWorkspace;
                        TreeNode node3D = this.m_Node3D.Nodes.Add(curItem.Name);
                        node3D.ImageIndex         = 19;
                        node3D.SelectedImageIndex = 19;

                        node3D.Tag = curItem;
                    }

                    dsName3D = enDatasetName.Next();
                }

                // FeatureDataset底下的3维FeatureClass
                enDatasetName = wsSource.get_DatasetNames(esriDatasetType.esriDTFeatureDataset);
                IDatasetName dsNameContainer = enDatasetName.Next();
                while (dsNameContainer != null)
                {
                    IEnumDatasetName enDsName3D = dsNameContainer.SubsetNames;
                    dsName3D = enDsName3D.Next();
                    while (dsName3D != null)
                    {
                        if (dsName3D is IFeatureClass && (dsName3D as IFeatureClass).ShapeType == esriGeometryType.esriGeometryMultiPatch)
                        {
                            // 存入数据库缓存并加载到树上
                            strSQL = string.Format("Insert into ThreeDimenLayersCache(LayerName) values('{0}')", dsName3D.Name);
                            wsSource.ExecuteSQL(strSQL);

                            //
                            ICatalogItem curItem = new FeatureClassCatalogItem(dsName3D, null);
                            curItem.WorkspaceItem = itemWorkspace;
                            TreeNode node3D = this.m_Node3D.Nodes.Add(curItem.Name);
                            node3D.ImageIndex         = 19;
                            node3D.SelectedImageIndex = 19;

                            node3D.Tag = curItem;
                        }

                        dsName3D = enDsName3D.Next();
                    }

                    dsNameContainer = enDatasetName.Next();
                }
            }

            m_Node3D.Expand();
        }
コード例 #29
0
        private IEnumerable <OSMTurnInfo> EnumerateOsmTurnRestrictions(IFeatureWorkspace fws)
        {
            OSMUtility osmUtility    = new OSMUtility();
            ITable     tableRelation = fws.OpenTable(_osmDataset.Name + "_osm_relation");

            try
            {
                TaskManager.StartProgress(tableRelation.RowCount(null));

                using (ComReleaser cr = new ComReleaser())
                {
                    ICursor cursor = tableRelation.Search(null, false);
                    cr.ManageLifetime(cursor);

                    int idxTags    = cursor.FindField("osmTags");
                    int idxMembers = cursor.FindField("osmMembers");

                    IRow row = null;
                    while ((row = cursor.NextRow()) != null)
                    {
                        tag[] tags            = osmUtility.retrieveOSMTags(row, idxTags, _osmDataset.Workspace);
                        var   tagsRestriction = tags.Where(t => t.k.Equals("restriction", StringComparison.CurrentCultureIgnoreCase));

                        foreach (tag tagRestrict in tagsRestriction)
                        {
                            OSMTurnInfo turn = new OSMTurnInfo();

                            turn.TurnType = tagRestrict.v;

                            foreach (member m in osmUtility.retrieveMembers(row, idxMembers))
                            {
                                if (m.role.Equals("from", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    turn.From = m;
                                }
                                else if (m.role.Equals("to", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    turn.To = m;
                                }
                                else if (m.role.Equals("via", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    turn.Via = m;
                                }
                            }

                            if (turn.HasValidMembers())
                            {
                                turn.FromFeature = FindEdgeFeature(turn.From.@ref);
                                turn.ToFeature   = FindEdgeFeature(turn.To.@ref);
                                turn.ViaFeature  = FindJunctionFeature(turn.Via.@ref);

                                if (turn.HasValidFeatures())
                                {
                                    yield return(turn);
                                }
                            }
                        }

                        TaskManager.StepProgress();
                    }
                }
            }
            finally
            {
                TaskManager.EndProgress();
            }
        }
コード例 #30
0
        public override double[,] getMatrix()
        {
            if (unVlDic == null)
            {
                unVlDic = UniqueClassValues;
            }
            int indCnt = IndependentFieldNames.Length;
            int depCnt = DependentFieldNames.Length;
            int rws    = InTable.RowCount(null);

            n = rws;
            ICursor cur  = InTable.Search(null, false);
            int     clms = IndependentFieldNames.Length + DependentFieldNames.Length;

            int[] allFieldIndexArray = new int[clms];
            allFieldNames = new string[clms];
            for (int i = 0; i < indCnt; i++)
            {
                string lu = IndependentFieldNames[i];
                allFieldNames[i]      = lu;
                allFieldIndexArray[i] = cur.FindField(lu);
                List <string> outSet = null;
                if (unVlDic.TryGetValue(lu, out outSet))
                {
                    int t = (outSet.Count() - 1);
                    clms = clms + t;
                }
            }
            for (int i = 0; i < depCnt; i++)
            {
                string lu = DependentFieldNames[i];
                categories = unVlDic[lu].ToArray();
                nclasses  += unVlDic[lu].Count;
                allFieldNames[i + indCnt]      = lu;
                allFieldIndexArray[i + indCnt] = cur.FindField(lu);
            }
            nvars     = clms - 1;
            outMatrix = new double[rws, clms];
            int  rwCnt = 0;
            IRow rw    = cur.NextRow();

            while (rw != null)
            {
                int indMatrixClm = 0;
                for (int i = 0; i < allFieldIndexArray.Length; i++)
                {
                    string lu         = allFieldNames[i];
                    int    fldClmCntT = 1;
                    int    indexFld   = allFieldIndexArray[i];
                    object vl         = rw.get_Value(indexFld);
                    updateMinMaxSum(vl, i);
                    double dblVl = 0;
                    try
                    {
                        string        strVl = vl.ToString();
                        List <string> unVl  = null;
                        if (unVlDic.TryGetValue(lu, out unVl))
                        {
                            int fldClmCntP = unVl.IndexOf(strVl);
                            if (i == allFieldIndexArray.Length - 1)
                            {
                                dblVl = fldClmCntP;
                            }
                            else
                            {
                                fldClmCntT    = unVl.Count() - fldClmCntP;
                                indMatrixClm += fldClmCntP;
                                dblVl         = 1;
                            }
                        }
                        else
                        {
                            dblVl = System.Convert.ToDouble(strVl);
                        }
                    }
                    catch
                    {
                        dblVl = 0;
                    }
                    outMatrix[rwCnt, indMatrixClm] = dblVl;
                    indMatrixClm += fldClmCntT;
                }
                rw     = cur.NextRow();
                rwCnt += 1;
            }
            return(outMatrix);
        }
コード例 #31
0
        public bool ChangeDatesOnTable(ICursor pCursor, string FieldName, string sDate, bool Unversioned, 
      IStepProgressor m_pStepProgressor, ITrackCancel m_pTrackCancel)
        {
            bool bWriteNull = (sDate.Trim() == "");
              object dbNull = DBNull.Value;
              int FldIdx = pCursor.FindField(FieldName);
              int iSysEndDate = pCursor.FindField("systemenddate");
              int iHistorical = pCursor.FindField("historical");

              bool bIsSysEndDate = (FieldName.ToLower() == "systemenddate");
              bool bIsHistorical = (FieldName.ToLower() == "historical");
              bool bHasSysEndDateFld = (iSysEndDate > -1);
              bool bHasHistoricFld = (iHistorical > -1);

              bool bCont = true;
              bool m_bShowProgressor = (m_pStepProgressor != null);

              if (bWriteNull)
              {
            IField pfld = pCursor.Fields.get_Field(FldIdx);
            if (!pfld.IsNullable)
              return false;
              }

              DateTime localNow = DateTime.Now;

              IRow pRow = pCursor.NextRow();
              while (pRow != null)
              {
            //Check if the cancel button was pressed. If so, stop process
            if (m_bShowProgressor)
            {
              bCont = m_pTrackCancel.Continue();
              if (!bCont)
            break;
            }

            if (bWriteNull)
            {
              if (bIsHistorical) //if writing null to Historical field, use 0 instead
            pRow.set_Value(FldIdx, 0);
              else
            pRow.set_Value(FldIdx, dbNull);

              if (bIsHistorical && bHasSysEndDateFld)   // if writing null to Historical field
            pRow.set_Value(iSysEndDate, dbNull);   // then also Null system end date
              if (bIsSysEndDate && bHasHistoricFld)     // if writing null to SystemEndDate field
            pRow.set_Value(iHistorical, 0);            //then set the Historical flag to false = 0
            }
            else
            {
              pRow.set_Value(FldIdx, sDate);
              if (bIsSysEndDate && bHasHistoricFld)     // if writing date to SystemEndDate field
            pRow.set_Value(iHistorical, 1);            //then set the Historical flag to true = 1
            }

            if (Unversioned)
              pCursor.UpdateRow(pRow);
            else
              pRow.Store();

            Marshal.ReleaseComObject(pRow);
            pRow = pCursor.NextRow();
            if (m_bShowProgressor)
            {
              if (m_pStepProgressor.Position < m_pStepProgressor.MaxRange)
            m_pStepProgressor.Step();
            }
              }
              Marshal.ReleaseComObject(pCursor);
              if (!bCont)
            return false;
              return true;
        }