Ejemplo n.º 1
0
 private void createOutRaster()
 {
     OutRasterName = rsUtil.getSafeOutputName(wks, OutRasterName);
     outraster     = rsUtil.returnRaster(rsUtil.createNewRaster(inRs, wks, OutRasterName, rasterUtil.rasterType.IMAGINE));
     rsProps2      = (IRasterProps)OutRaster;
     System.Array noDataValues2 = (System.Array)rsProps2.NoDataValue;
     noDataVl2 = System.Convert.ToInt32(noDataValues2.GetValue(0));
     if (noDataVl2 >= 0)
     {
         counter = Int32.MinValue + 2;
     }
     else
     {
         counter = Int32.MinValue + 2;
     }
     #region create VAT Table
     IFields     flds  = new FieldsClass();
     IField      fld   = new FieldClass();
     IFieldsEdit fldsE = (IFieldsEdit)flds;
     IFieldEdit  fldE  = (IFieldEdit)fld;
     fldE.Name_2      = "Value";
     fldE.Type_2      = esriFieldType.esriFieldTypeInteger;
     fldE.Precision_2 = 50;
     fldsE.AddField(fld);
     IField     fld2  = new FieldClass();
     IFieldEdit fld2E = (IFieldEdit)fld2;
     fld2E.Name_2     = "Count";
     fld2E.Type_2     = esriFieldType.esriFieldTypeInteger;
     fldE.Precision_2 = 50;
     fldsE.AddField(fld2);
     IField     fld3  = new FieldClass();
     IFieldEdit fld3E = (IFieldEdit)fld3;
     fld3E.Name_2      = "Perimeter";
     fld3E.Type_2      = esriFieldType.esriFieldTypeInteger;
     fld3E.Precision_2 = 50;
     fldsE.AddField(fld3);
     vatTable   = geoUtil.createTable(vWks, OutRasterName + "_vat", flds);
     valueIndex = vatTable.FindField("Value");
     countIndex = vatTable.FindField("Count");
     permIndex  = vatTable.FindField("Perimeter");
     #endregion
 }
Ejemplo n.º 2
0
        private void fillFields()
        {
            if (rd != null)
            {
                rd.addMessage("Output table name = " + wks.PathName + "\\" + tblName);
            }
            //bool weCreate = true;
            //if (!geoUtil.ftrExists(wks, tblName))
            //{
            IFields     nflds  = new FieldsClass();
            IFieldsEdit nfldsE = (IFieldsEdit)nflds;
            IField      nfld   = new FieldClass();
            IFieldEdit  nfldE  = (IFieldEdit)nfld;

            nfldE.Name_2 = "Band";
            nfldE.Type_2 = esriFieldType.esriFieldTypeDouble;
            nfldsE.AddField(nfldE);
            IField     nfld2  = new FieldClass();
            IFieldEdit nfld2E = (IFieldEdit)nfld2;

            nfld2E.Name_2 = "Zone";
            nfld2E.Type_2 = esriFieldType.esriFieldTypeDouble;
            nfldsE.AddField(nfld2E);
            IField     nfld3  = new FieldClass();
            IFieldEdit nfld3E = (IFieldEdit)nfld3;

            nfld3E.Name_2 = "Count";
            nfld3E.Type_2 = esriFieldType.esriFieldTypeDouble;
            nfldsE.AddField(nfld3E);
            oTbl = geoUtil.createTable(wks, tblName, nflds);
            int[] fldIndex = new int[ZoneTypes.Length];
            for (int zIndex = 0; zIndex < ZoneTypes.Length; zIndex++)
            {
                string fldNm = ZoneTypes[zIndex].ToString();
                fldNm            = geoUtil.createField(oTbl, fldNm, esriFieldType.esriFieldTypeDouble);
                fldIndex[zIndex] = oTbl.FindField(fldNm);
            }
            IWorkspaceEdit wksE = (IWorkspaceEdit)wks;

            if (wksE.IsBeingEdited())
            {
                wksE.StopEditing(true);
            }
            try
            {
                int        bdIndex  = oTbl.FindField("Band");
                int        vlIndex  = oTbl.FindField("Zone");
                int        cntIndex = oTbl.FindField("Count");
                int        bndCnt   = 1;
                ICursor    cur      = oTbl.Insert(true);
                IRowBuffer rw       = oTbl.CreateRowBuffer();
                foreach (Dictionary <double, object[]> zoneValueDicOut in zoneValueDicArr)
                {
                    foreach (KeyValuePair <double, object[]> kVp in zoneValueDicOut)
                    {
                        double   key = kVp.Key;
                        object[] vl  = kVp.Value;
                        Dictionary <rasterUtil.zoneType, double> vDic = getValueDic(vl);

                        //IRow rw = null;
                        //if (!weCreate)
                        //{
                        //    string qry = "Band = " + bndCnt.ToString() + " and Zone = " + key;
                        //    IQueryFilter qf = new QueryFilterClass();
                        //    qf.WhereClause = qry;
                        //    ISelectionSet tblSelectionSet = oTbl.Select(qf, esriSelectionType.esriSelectionTypeIDSet, esriSelectionOption.esriSelectionOptionOnlyOne, wks);
                        //    if (tblSelectionSet.Count > 0)
                        //    {
                        //        int id = tblSelectionSet.IDs.Next();
                        //        rw = oTbl.GetRow(id);
                        //    }
                        //    else
                        //    {
                        //        rw = oTbl.CreateRow();
                        //    }

                        //}
                        //else
                        //{
                        //rw = oTbl.CreateRow();
                        //}
                        //Console.WriteLine(key.ToString());
                        rw.set_Value(bdIndex, bndCnt);
                        rw.set_Value(vlIndex, key);
                        rw.set_Value(cntIndex, vl[0]);
                        for (int zIndex = 0; zIndex < ZoneTypes.Length; zIndex++)// (rasterUtil.zoneType zT in ZoneTypes)
                        {
                            rasterUtil.zoneType zT = ZoneTypes[zIndex];
                            double zVl             = vDic[zT];
                            //Console.WriteLine("\t"+fldNm+ ": " + zVl.ToString());
                            rw.set_Value(fldIndex[zIndex], zVl);
                        }
                        //rw.Store();
                        cur.InsertRow(rw);
                    }
                    bndCnt += 1;
                }
                //trs.CommitTransaction();
                cur.Flush();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(cur);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(rw);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                //trs.AbortTransaction();
            }
            finally
            {
            }
        }
Ejemplo n.º 3
0
        private void createTable()
        {
            string      tblName = "catTbl.dbf";
            IWorkspace  wks     = geoUtil.OpenWorkSpace(rsUtil.TempMosaicDir);
            IFields     flds    = new FieldsClass();
            IFieldsEdit fldsE   = (IFieldsEdit)flds;
            IField      fld     = new FieldClass();
            IFieldEdit  fldE    = (IFieldEdit)fld;

            fldE.Name_2 = "catIndex";
            fldE.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
            fldsE.AddField(fldE);

            IField     fld2  = new FieldClass();
            IFieldEdit fldE2 = (IFieldEdit)fld2;

            fldE2.Name_2 = "XMIN";
            fldE2.Type_2 = esriFieldType.esriFieldTypeDouble;
            fldsE.AddField(fldE2);

            IField     fld3  = new FieldClass();
            IFieldEdit fldE3 = (IFieldEdit)fld3;

            fldE3.Name_2 = "XMAX";
            fldE3.Type_2 = esriFieldType.esriFieldTypeDouble;
            fldsE.AddField(fldE3);

            IField     fld4  = new FieldClass();
            IFieldEdit fldE4 = (IFieldEdit)fld4;

            fldE4.Name_2 = "YMIN";
            fldE4.Type_2 = esriFieldType.esriFieldTypeDouble;
            fldsE.AddField(fldE4);

            IField     fld5  = new FieldClass();
            IFieldEdit fldE5 = (IFieldEdit)fld5;

            fldE5.Name_2 = "YMAX";
            fldE5.Type_2 = esriFieldType.esriFieldTypeDouble;
            fldsE.AddField(fldE5);

            tbl = geoUtil.createTable(wks, tblName, flds);
            int catInd  = tbl.FindField("catIndex");
            int xMinInd = tbl.FindField("XMIN");
            int xMaxInd = tbl.FindField("XMAX");
            int yMinInd = tbl.FindField("YMIN");
            int yMaxInd = tbl.FindField("YMAX");
            int cnt     = 0;

            foreach (IRaster rs in inrs)
            {
                IRow rw = tbl.CreateRow();
                rw.set_Value(catInd, cnt);
                IEnvelope ext = ((IRasterProps)rs).Extent;
                rw.set_Value(xMinInd, ext.XMin);
                rw.set_Value(xMaxInd, ext.XMax);
                rw.set_Value(yMinInd, ext.YMin);
                rw.set_Value(yMaxInd, ext.YMax);
                rw.Store();
                cnt++;
            }
        }