当前位置: 首页>>代码示例>>C#>>正文


C# ITable.RowCount方法代码示例

本文整理汇总了C#中ITable.RowCount方法的典型用法代码示例。如果您正苦于以下问题:C# ITable.RowCount方法的具体用法?C# ITable.RowCount怎么用?C# ITable.RowCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ITable的用法示例。


在下文中一共展示了ITable.RowCount方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: writeDataInExcle

        private void writeDataInExcle(HSSFSheet hssfSheet, ITable table)
        {
            int rownum = table.RowCount(null);
            int colnum = table.Fields.FieldCount;

            //int myindex1 = table.FindField("FID");
            int myindex2 = table.FindField("FinalScore");

            //IField field1 = null;
            IField field2 = null;
            //field1 = table.Fields.get_Field(myindex1);
            field2 = table.Fields.get_Field(myindex2);
            // write header
            NPOI.SS.UserModel.IRow row = hssfSheet.CreateRow(0);
            //row.CreateCell(0).SetCellValue(field1.Name.ToString());
            row.CreateCell(0).SetCellValue(field2.Name.ToString());

            // write data
            ICursor cursor = table.Search(null, true);
            IRow trow = cursor.NextRow();
            int i = 1;
            while (trow != null)
            {
                row = hssfSheet.CreateRow(i);
                //row.CreateCell(0).SetCellValue(Convert.ToDouble(trow.get_Value(myindex1)));
                row.CreateCell(0).SetCellValue(Convert.ToDouble(trow.get_Value(myindex2)));
                trow = cursor.NextRow();
                i++;
            }
        }
开发者ID:weigiser,项目名称:LandPriceOnline,代码行数:30,代码来源:FeatureDataManager.cs

示例2: transformData

        public static void transformData(ITable zoneTable, string linkFieldName, ITable zonalSummaryTable, string prefix="")
        {
            string prf = "";
            if (prefix != ""&&prefix!=null) prf = prefix + "_";
            IObjectClassInfo2 oi2 = (IObjectClassInfo2)zoneTable;
            if (!oi2.CanBypassEditSession())
            {
                System.Windows.Forms.MessageBox.Show("Table has a composite relationship. Please export data to a simple object and try again.");
                return;
            }
            geoDatabaseUtility geoUtil = new geoDatabaseUtility();
            IFields zsFlds = zonalSummaryTable.Fields;
            IFields zFlds = zoneTable.Fields;
            foreach (string s in new string[] { "Band", "Zone", "Count" })
            {
                if (zsFlds.FindField(s) == -1)
                {
                    System.Windows.Forms.MessageBox.Show("Not a valid Zonal Summary table!!!", "Format", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                    return;
                }
            }
            if (zFlds.FindField(linkFieldName) == -1)
            {
                System.Windows.Forms.MessageBox.Show("Not a valid Zone table!!!", "Format", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }
            IDataStatistics dStat = new DataStatisticsClass();
            dStat.Cursor = zonalSummaryTable.Search(null, false);
            dStat.Field = "Band";
            int unqCnt = 0;
            System.Collections.IEnumerator en = dStat.UniqueValues;
            en.MoveNext();
            do
            {
                //Console.WriteLine(en.Current.ToString());
                unqCnt++;
            } while (en.MoveNext());
            int exRwCnt = zoneTable.RowCount(null) * unqCnt;
            int sumRwCnt = zonalSummaryTable.RowCount(null);
            //Console.WriteLine("zonal*bands = " + exRwCnt.ToString() + "zoneSumCnt = " + sumRwCnt.ToString());
            if (exRwCnt != sumRwCnt)
            {

                System.Windows.Forms.MessageBox.Show("Zone and Zonal Summary tables row counts do not match! You must update your zonal statistics before running this tool!", "Format", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;

            }
            List<string> newFldNames = new List<string>();
            List<string> zsFldNames = new List<string>();
            for (int i = 0; i < zsFlds.FieldCount; i++)
            {
                IField fld = zsFlds.get_Field(i);
                if (fld.Type == esriFieldType.esriFieldTypeDouble)
                {
                    string nm = fld.Name;
                    if (nm.ToLower() != "zone" && nm.ToLower() != "band")
                    {
                        zsFldNames.Add(nm);
                        for (int j = 0; j < unqCnt; j++)
                        {
                            string nnm = prf+nm + "_" + (j + 1).ToString();
                            newFldNames.Add(geoUtil.createField(zoneTable, nnm, esriFieldType.esriFieldTypeDouble,false));
                        }
                    }

                }
            }
            int[] zsFldNamesIndex = new int[zsFldNames.Count];
            for (int i = 0; i < zsFldNames.Count; i++)
            {
                string vl = zsFldNames[i];
                zsFldNamesIndex[i] = zonalSummaryTable.FindField(vl);
            }
            int[] newFldNamesIndex = new int[newFldNames.Count];
            for (int i = 0; i < newFldNames.Count; i++)
            {
                string vl = newFldNames[i];
                newFldNamesIndex[i] = zoneTable.FindField(vl);
            }
            //IQueryFilter qfz = new QueryFilterClass();
            //IQueryFilterDefinition qfzD = (IQueryFilterDefinition)qfz;
            //qfzD.PostfixClause = "ORDER BY " + linkFieldName;
            //IQueryFilter qfzs = new QueryFilterClass();
            //IQueryFilterDefinition qfzsD = (IQueryFilterDefinition)qfzs;
            //qfzsD.PostfixClause = "ORDER BY Zone, Band";
            //ICursor curZ = zoneTable.Update(qfz, false);
            //ICursor curZs = zonalSummaryTable.Search(qfzs, false);
            ITableSort tblSortZ = new TableSortClass();
            tblSortZ.Table = zoneTable;
            tblSortZ.Fields = linkFieldName;
            ITableSort tblSortZs = new TableSortClass();
            tblSortZs.Table = zonalSummaryTable;
            tblSortZs.Fields = "Zone, Band";
            tblSortZs.Sort(null);
            tblSortZ.Sort(null);
            ICursor curZ = tblSortZ.Rows;
            ICursor curZs = tblSortZs.Rows;
            IRow rwZ = curZ.NextRow();
            while (rwZ != null)
            {
//.........这里部分代码省略.........
开发者ID:GeospatialDaryl,项目名称:USFS_RMRS_FunctionalModeling_RasterModeling,代码行数:101,代码来源:zonalHelper.cs

示例3: UpdatePointXYFromGeometry

        private bool UpdatePointXYFromGeometry(ITable PointTable, IQueryFilter QueryFilter, bool Unversioned, double UpdateIfMoreThanTolerance, out int ChangedPointCount)
        {
            IProgressDialogFactory pProgressorDialogFact = new ProgressDialogFactoryClass();
              ITrackCancel pTrackCancel = new CancelTrackerClass();
              IStepProgressor pStepProgressor = pProgressorDialogFact.Create(pTrackCancel, ArcMap.Application.hWnd);
              IProgressDialog2 pProgressorDialog = (IProgressDialog2)pStepProgressor;
              try
              {
            pStepProgressor.MinRange = 0;
            pStepProgressor.MaxRange = PointTable.RowCount(null);
            pStepProgressor.StepValue = 1;
            pProgressorDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressSpiral;
            bool bCont = true;

            IRow pPointFeat = null;
            ICursor pPtCurs = null;
            ChangedPointCount = 0;
            if (Unversioned)
            {
              ITableWrite pTableWr = (ITableWrite)PointTable;//used for unversioned table
              pPtCurs = pTableWr.UpdateRows(QueryFilter, false);
            }
            else
              pPtCurs = PointTable.Update(QueryFilter, false);

            pPointFeat = pPtCurs.NextRow();

            int iPointIdx_X = pPtCurs.Fields.FindField("X");
            int iPointIdx_Y = pPtCurs.Fields.FindField("Y");

            pProgressorDialog.ShowDialog();
            pStepProgressor.Message = "Updating point data...";

            while (pPointFeat != null)
            {//loop through all of the fabric points, and if any of the point id values are in the deleted set,
              //then remove the control name from the point's NAME field

              bCont = pTrackCancel.Continue();
              if (!bCont)
            break;

              IFeature pFeat = (IFeature)pPointFeat;
              IPoint pPtSource = (IPoint)pFeat.ShapeCopy;

              if (pPtSource == null)
              {
            Marshal.ReleaseComObject(pPointFeat); //garbage collection
            pPointFeat = pPtCurs.NextRow();
            continue;
              }

              if (pPtSource.IsEmpty)
              {
            Marshal.ReleaseComObject(pPointFeat); //garbage collection
            pPointFeat = pPtCurs.NextRow();
            continue;
              }
              IPoint pPtTarget = new ESRI.ArcGIS.Geometry.PointClass();
              pPtTarget.X = Convert.ToDouble(pPointFeat.get_Value(iPointIdx_X));
              pPtTarget.Y = Convert.ToDouble(pPointFeat.get_Value(iPointIdx_Y));

              ILine pLine = new ESRI.ArcGIS.Geometry.LineClass();
              pLine.PutCoords(pPtSource, pPtTarget);

              if (pLine.Length > UpdateIfMoreThanTolerance)
              {
            pPointFeat.set_Value(iPointIdx_X, pPtSource.X);
            pPointFeat.set_Value(iPointIdx_Y, pPtSource.Y);

            //if (Unversioned)
              pPtCurs.UpdateRow(pPointFeat);
            //else
            //  pPointFeat.Store();
            ChangedPointCount++;
            string sCnt = ChangedPointCount.ToString() + " of " + pStepProgressor.MaxRange.ToString();
            pStepProgressor.Message = "Updating point data..." + sCnt;
              }

              Marshal.ReleaseComObject(pPointFeat); //garbage collection
              pPointFeat = pPtCurs.NextRow();

              if (pStepProgressor.Position < pStepProgressor.MaxRange)
            pStepProgressor.Step();

            }
            Marshal.ReleaseComObject(pPtCurs); //garbage collection
            return bCont;

              }
              catch (COMException ex)
              {
            MessageBox.Show("Problem updating point XY from shape: " + Convert.ToString(ex.ErrorCode));
            ChangedPointCount = 0;
            return false;
              }
              finally
              {
            pStepProgressor = null;
            if (!(pProgressorDialog == null))
              pProgressorDialog.HideDialog();
//.........这里部分代码省略.........
开发者ID:Esri,项目名称:parcel-fabric-desktop-addins,代码行数:101,代码来源:CoordinateInverse.cs

示例4: MatchTable

        /// <summary>
        /// Geocodes a table of addresses
        /// </summary>
        /// <param name="addressTable">Input address table</param>
        /// <param name="addressFieldNames">Fields defined in the table</param>
        /// <param name="whereClause">Query filter where clause</param>
        /// <param name="outputFeatureClass">Output feature class for matched addresses</param>
        /// <param name="outputFieldNames">Output field names</param>
        /// <param name="fieldsToCopy"></param>
        /// <param name="cancelTracker"></param>
        public virtual void MatchTable(ITable addressTable, String addressFieldNames, String whereClause,
          IFeatureClass outputFeatureClass, String outputFieldNames, IPropertySet fieldsToCopy, ITrackCancel cancelTracker)
        {
            _log.Debug("IAddressGeocoding MatchTable");

              // Obtain the read and insert cursors
              IQueryFilter queryFilter = new QueryFilterClass();
              queryFilter.WhereClause = whereClause;
              ICursor readCursor = null;
              IFeatureCursor insertCursor = null;
              IFeatureCursor updateCursor = null;

              // m_needToUpdate will be True when a Rematch is being preformed
              if (m_needToUpdate)
              {
              // Create update cursor to update matched records
              updateCursor = outputFeatureClass.Update(queryFilter, false);
              if (isSameObject(addressTable, outputFeatureClass))
                  readCursor = updateCursor as ICursor;
              else
                  readCursor = addressTable.Search(queryFilter, true);
              }
              else
              {
              // Create insert cursor to add new records
              readCursor = addressTable.Search(queryFilter, true);
              insertCursor = outputFeatureClass.Insert(true);
              }

              int count = addressTable.RowCount(queryFilter);

              // Progress dialog setup
              IStepProgressor progressor = null;
              if (cancelTracker != null)
              progressor = cancelTracker.Progressor as IStepProgressor;
              IProgressStatistics progStats = cancelTracker as IProgressStatistics;
              if (progressor != null)
              {
              progressor.StepValue = 1;
              progressor.MaxRange = addressTable.RowCount(null);
              }

              // Separate the input field names
              string[] multilineFields = addressFieldNames.Split(',');

              // Read the first row and get the address field
              IRow row = readCursor.NextRow();

              Dictionary<int, string> addressFieldIndexes = new Dictionary<int, string>();

              // Get the index of each valid field
              for (int i = 0; i < multilineFields.Length; i++)
              {
              if (multilineFields[i].Trim().Length > 0)
                  addressFieldIndexes.Add(row.Fields.FindField(multilineFields[i].Trim()), multilineFields[i].Trim());
              }

              string address;
              IPropertySet addressProperties = new PropertySetClass();
              IPropertySet resultSet;
              IFeatureBuffer featureBuffer;
              object copyTo, copyFrom, key, value;

              // Get the name and value of all the properties in the property set
              fieldsToCopy.GetAllProperties(out copyTo, out copyFrom);
              string[] copyToArray = copyTo as string[];
              object[] copyFromArray = copyFrom as object[];
              string matchStatus = "U";

              // Populate the output feature class
              while (row != null)
              {
              featureBuffer = outputFeatureClass.CreateFeatureBuffer();
              foreach (KeyValuePair<int,string> entry in addressFieldIndexes)
              {
                  if (entry.Key != -1)
                      address = row.get_Value(entry.Key) as string;
                  else
                      address = row.get_Value(0) as string;

                  addressProperties.SetProperty(entry.Value, address);
              }

              resultSet = MatchAddress(addressProperties);

              // Get all of the fields and values of the result
              resultSet.GetAllProperties(out key, out value);
              string[] names = key as string[];
              object[] items = value as object[];

//.........这里部分代码省略.........
开发者ID:EsriUK,项目名称:dynamic-locator-sdk,代码行数:101,代码来源:LocatorWrapper.cs

示例5: CopyTable

 public static void CopyTable(ITable pSrcTable, ITable pDestTable)
 {
     Exception exception;
     try
     {
         if ((pSrcTable != null) && (pDestTable != null))
         {
             List<int> pSrcField = null;
             List<int> pDestField = null;
             CreateFieldMap(pSrcTable, pDestTable, out pSrcField, out pDestField);
             ICursor o = pSrcTable.Search(null, true);
             int num = pSrcTable.RowCount(null);
             if (num > 0)
             {
                 int num2 = (num / 10) + 1;
                 IWorkspaceEdit edit = (pDestTable as IDataset).Workspace as IWorkspaceEdit;
                 edit.StartEditing(false);
                 edit.StartEditOperation();
                 IRow pSrcFea = o.NextRow();
                 int num3 = 1;
                 while (pSrcFea != null)
                 {
                     try
                     {
                         if ((num2 >= 0x3e8) && ((num3++ % num2) == 0))
                         {
                             edit.StopEditOperation();
                             edit.StopEditing(true);
                             edit.StartEditing(false);
                             edit.StartEditOperation();
                         }
                         IRow pDestFea = pDestTable.CreateRow();
                         CopyRow(pSrcFea, pDestFea, pSrcField, pDestField);
                         if ((pSrcFea is IFeature) && (pDestFea is IFeature))
                         {
                             (pDestFea as IFeature).Shape = (pSrcFea as IFeature).ShapeCopy;
                         }
                         pDestFea.Store();
                     }
                     catch (Exception exception1)
                     {
                         exception = exception1;
                     }
                     pSrcFea = o.NextRow();
                     edit.StopEditOperation();
                     edit.StopEditing(true);
                 }
                 Marshal.ReleaseComObject(o);
             }
         }
     }
     catch (Exception exception2)
     {
         exception = exception2;
     }
 }
开发者ID:ismethr,项目名称:gas-geological-map,代码行数:56,代码来源:FeatureHelper.cs

示例6: selectStrataFeaturesToSample

        public void selectStrataFeaturesToSample(ITable inputTable, string strataModelPath, string strataFieldName = "Cluster", double proportionOfMean = 0.1, double alpha = 0.05, bool weightsEqual = false)
        {
            IObjectClassInfo2 objInfo2 = (IObjectClassInfo2)inputTable;
            if (!objInfo2.CanBypassEditSession())
            {
                System.Windows.Forms.MessageBox.Show("Input Table participates in a composite relationship. Please export this table as a new table and try again!");
                return;
            }
            esriUtil.Statistics.dataPrepStrata dpC = new Statistics.dataPrepStrata();
            dpC.buildModel(strataModelPath);
            List<string> labels = dpC.Labels;
            HashSet<string> unqVls = geoUtil.getUniqueValues(inputTable, strataFieldName);
            System.Random rd = new Random();
            int[] samplesPerCluster = esriUtil.Statistics.dataPrepSampleSize.sampleSizeMaxCluster(strataModelPath, proportionOfMean, alpha);
            double[] propPerCluster = esriUtil.Statistics.dataPrepSampleSize.clusterProportions(strataModelPath);
            double[] weightsPerCluster = new double[propPerCluster.Length];
            double sSamp = System.Convert.ToDouble(samplesPerCluster.Sum());
            for (int i = 0; i < weightsPerCluster.Length; i++)
            {
                weightsPerCluster[i] = propPerCluster[i] / (samplesPerCluster[i] / sSamp);
            }
            if (weightsEqual)
            {
                double minProp = weightsPerCluster.Min();
                for (int i = 0; i < samplesPerCluster.Length; i++)
                {
                    samplesPerCluster[i] = System.Convert.ToInt32(samplesPerCluster[i] * (weightsPerCluster[i] / minProp));
                    weightsPerCluster[i] = 1;
                }
            }
            int[] tsPerCluster = new int[propPerCluster.Length];
            double[] randomRatioPerClust = new double[propPerCluster.Length];
            if (samplesPerCluster.Length != unqVls.Count)
            {
                System.Windows.Forms.MessageBox.Show("Unique Values in cluster field do not match the number of cluster models!");
                return;
            }
            string sampleFldName = geoUtil.createField(inputTable, "sample", esriFieldType.esriFieldTypeSmallInteger, false);
            string weightFldName = geoUtil.createField(inputTable, "weight", esriFieldType.esriFieldTypeDouble, false);
            IQueryFilter qf0 = new QueryFilterClass();
            qf0.SubFields = strataFieldName;
            string h = "";
            IField fld = inputTable.Fields.get_Field(inputTable.FindField(strataFieldName));
            if (fld.Type == esriFieldType.esriFieldTypeString) h = "'";
            for (int i = 0; i < samplesPerCluster.Length; i++)
            {

                qf0.WhereClause = strataFieldName + " = " + h + labels[i] + h;
                int tCnt = inputTable.RowCount(qf0);
                tsPerCluster[i] = tCnt;
                randomRatioPerClust[i] = System.Convert.ToDouble(samplesPerCluster[i]) / tCnt;
            }
            IQueryFilter qf = new QueryFilterClass();
            qf.SubFields = strataFieldName + "," + sampleFldName + "," + weightFldName;
            IWorkspace wks = ((IDataset)inputTable).Workspace;
            IWorkspaceEdit wksE = (IWorkspaceEdit)wks;
            if (wksE.IsBeingEdited())
            {
                wksE.StopEditing(true);
            }
            try
            {
                ICursor cur = inputTable.Update(qf, false);
                int sIndex = cur.FindField(sampleFldName);
                int cIndex = cur.FindField(strataFieldName);
                int wIndex = cur.FindField(weightFldName);
                IRow rw = cur.NextRow();
                while (rw != null)
                {
                    string clustStr = rw.get_Value(cIndex).ToString();
                    int clust = labels.IndexOf(clustStr);
                    double w = weightsPerCluster[clust];
                    double rNum = rd.NextDouble();
                    int ss = 0;
                    double r = randomRatioPerClust[clust];
                    if (rNum < r)
                    {
                        ss = 1;
                    }
                    rw.set_Value(sIndex, ss);
                    rw.set_Value(wIndex, w);
                    cur.UpdateRow(rw);
                    rw = cur.NextRow();
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(cur);
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.ToString());
            }
        }
开发者ID:GeospatialDaryl,项目名称:USFS_RMRS_FunctionalModeling_RasterModeling,代码行数:91,代码来源:featureUtil.cs

示例7: selectRandomFeaturesToSample

 public void selectRandomFeaturesToSample(ITable inputTable, int totalSamples)
 {
     IObjectClassInfo2 objInfo2 = (IObjectClassInfo2)inputTable;
     if (!objInfo2.CanBypassEditSession())
     {
         System.Windows.Forms.MessageBox.Show("Input Table participates in a composite relationship. Please export this table as a new table and try again!");
         return;
     }
     System.Random rd = new Random();
     double tRec = inputTable.RowCount(null);
     double gR = totalSamples / System.Convert.ToDouble(tRec);
     string sampleFldName = geoUtil.createField(inputTable, "sample", esriFieldType.esriFieldTypeSmallInteger, false);
     string weightFldName = geoUtil.createField(inputTable, "weight", esriFieldType.esriFieldTypeDouble, false);
     IWorkspace wks = ((IDataset)inputTable).Workspace;
     IWorkspaceEdit wksE = (IWorkspaceEdit)wks;
     if (wksE.IsBeingEdited())
     {
         wksE.StopEditing(true);
     }
     try
     {
         ICursor cur = inputTable.Update(null, false);
         int sIndex = cur.FindField(sampleFldName);
         int wIndex = cur.FindField(weightFldName);
         IRow rw = cur.NextRow();
         while (rw != null)
         {
             double rNum = rd.NextDouble();
             int ss = 0;
             if (rNum <= gR)
             {
                 ss = 1;
             }
             rw.set_Value(sIndex, ss);
             rw.set_Value(wIndex, 1);
             cur.UpdateRow(rw);
             rw = cur.NextRow();
         }
         System.Runtime.InteropServices.Marshal.ReleaseComObject(cur);
     }
     catch (Exception e)
     {
         System.Windows.Forms.MessageBox.Show(e.ToString());
     }
 }
开发者ID:GeospatialDaryl,项目名称:USFS_RMRS_FunctionalModeling_RasterModeling,代码行数:45,代码来源:featureUtil.cs

示例8: selectPcaFeaturesToSample

 public void selectPcaFeaturesToSample(ITable inputTable, string pcaModelPath, double proportionOfMean, double alpha)
 {
     IObjectClassInfo2 objInfo2 = (IObjectClassInfo2)inputTable;
     if (!objInfo2.CanBypassEditSession())
     {
         System.Windows.Forms.MessageBox.Show("Input Table participates in a composite relationship. Please export this table as a new table and try again!");
         return;
     }
     Statistics.dataPrepPrincipleComponents pca = new Statistics.dataPrepPrincipleComponents();
     pca.buildModel(pcaModelPath);
     System.Random rd = new Random();
     double tSamples = System.Convert.ToDouble(esriUtil.Statistics.dataPrepSampleSize.sampleSizeMaxMean(pca.MeanVector, pca.StdVector, proportionOfMean, alpha));
     int tRecords = inputTable.RowCount(null);
     double gR = tSamples / tRecords;
     string sampleFldName = geoUtil.createField(inputTable, "sample", esriFieldType.esriFieldTypeSmallInteger, false);
     IQueryFilter qf0 = new QueryFilterClass();
     IQueryFilter qf = new QueryFilterClass();
     qf.SubFields = sampleFldName;
     IWorkspace wks = ((IDataset)inputTable).Workspace;
     IWorkspaceEdit wksE = (IWorkspaceEdit)wks;
     if (wksE.IsBeingEdited())
     {
         wksE.StopEditing(true);
     }
     try
     {
         ICursor cur = inputTable.Update(qf, false);
         int sIndex = cur.FindField(sampleFldName);
         IRow rw = cur.NextRow();
         while (rw != null)
         {
             double rNum = rd.NextDouble();
             int ss = 0;
             double r = gR;
             if (rNum < r)
             {
                 ss = 1;
             }
             rw.set_Value(sIndex, ss);
             cur.UpdateRow(rw);
             rw = cur.NextRow();
         }
         System.Runtime.InteropServices.Marshal.ReleaseComObject(cur);
     }
     catch (Exception e)
     {
         System.Windows.Forms.MessageBox.Show(e.ToString());
     }
 }
开发者ID:GeospatialDaryl,项目名称:USFS_RMRS_FunctionalModeling_RasterModeling,代码行数:49,代码来源:featureUtil.cs

示例9: selectEqualFeaturesToSample

        public void selectEqualFeaturesToSample(ITable inputTable, string mapField, int SamplesPerClass, bool weightsEqual=false )
        {
            IObjectClassInfo2 objInfo2 = (IObjectClassInfo2)inputTable;
            if (!objInfo2.CanBypassEditSession())
            {
                System.Windows.Forms.MessageBox.Show("Input Table participates in a composite relationship. Please export this table as a new table and try again!");
                return;
            }
            HashSet<string> unqVls = geoUtil.getUniqueValues(inputTable, mapField);
            System.Random rd = new Random();
            int samplesPerClass = SamplesPerClass;
            double tSamples = System.Convert.ToDouble(samplesPerClass * unqVls.Count);
            double gR = samplesPerClass / tSamples;
            double[] weightsPerClass = new double[unqVls.Count];
            int[] tsPerClass = new int[unqVls.Count];
            double[] ratioPerClass = new double[unqVls.Count];
            string sampleFldName = geoUtil.createField(inputTable, "sample", esriFieldType.esriFieldTypeSmallInteger, false);
            string weightFldName = geoUtil.createField(inputTable, "weight", esriFieldType.esriFieldTypeDouble, false);
            IQueryFilter qf0 = new QueryFilterClass();
            qf0.SubFields = mapField;
            string h = "";
            IField fld = inputTable.Fields.get_Field(inputTable.FindField(mapField));
            if (fld.Type == esriFieldType.esriFieldTypeString) h = "'";
            for (int i = 0; i < unqVls.Count; i++)
            {

                qf0.WhereClause = mapField + " = " + h + unqVls.ElementAt(i) + h;
                int tCnt = inputTable.RowCount(qf0);
                tsPerClass[i] = tCnt;
                ratioPerClass[i] = System.Convert.ToDouble(samplesPerClass) / tCnt;
            }
            double tsSamp = System.Convert.ToDouble(tsPerClass.Sum());
            for (int i = 0; i < weightsPerClass.Length; i++)
            {
                weightsPerClass[i] = (tsPerClass[i]/tsSamp) / (gR);
            }
            if (weightsEqual)
            {
                double minW = weightsPerClass.Min();
                for (int i = 0; i < weightsPerClass.Length; i++)
                {
                    double aSamp = samplesPerClass*(weightsPerClass[i]/minW);
                    ratioPerClass[i] = aSamp / tsPerClass[i];
                    weightsPerClass[i] = 1;
                }

            }
            IQueryFilter qf = new QueryFilterClass();
            qf.SubFields = mapField + "," + sampleFldName + "," + weightFldName;
            IWorkspace wks = ((IDataset)inputTable).Workspace;
            IWorkspaceEdit wksE = (IWorkspaceEdit)wks;
            if (wksE.IsBeingEdited())
            {
                wksE.StopEditing(true);
            }
            try
            {
                ICursor cur = inputTable.Update(qf, false);
                int sIndex = cur.FindField(sampleFldName);
                int cIndex = cur.FindField(mapField);
                int wIndex = cur.FindField(weightFldName);
                IRow rw = cur.NextRow();
                List<string> unqLst = unqVls.ToList();
                while (rw != null)
                {
                    string classStr = rw.get_Value(cIndex).ToString();
                    int cls = unqLst.IndexOf(classStr);
                    double w = weightsPerClass[cls];
                    double rNum = rd.NextDouble();
                    int ss = 0;
                    double r = ratioPerClass[cls];
                    if (rNum < r)
                    {
                        ss = 1;
                    }
                    rw.set_Value(sIndex, ss);
                    rw.set_Value(wIndex, w);
                    cur.UpdateRow(rw);
                    rw = cur.NextRow();
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(cur);
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.ToString());
            }
        }
开发者ID:GeospatialDaryl,项目名称:USFS_RMRS_FunctionalModeling_RasterModeling,代码行数:87,代码来源:featureUtil.cs


注:本文中的ITable.RowCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。