Example #1
0
        private void addFields(string prefix = "")
        {
            HashSet <string> un;

            if (prefix == "")
            {
                un = unSp;
            }
            else
            {
                un = sUnSp;
            }
            foreach (string s in un)
            {
                //Console.WriteLine(s.ToString());
                foreach (biomassTypes t in fldArr)
                {
                    string fldNm = prefix + t.ToString() + "_" + s;
                    //Console.WriteLine(fldNm);
                    if (SampleFeatureClass.FindField(fldNm) > -1)
                    {
                    }
                    else
                    {
                        geoDbUtil.createField(SampleFeatureClass, fldNm, esriFieldType.esriFieldTypeDouble);
                    }
                }
            }
        }
Example #2
0
        private void createAndFillPlotsTable()
        {
            //DataTable dTblPlots = dSet.Tables.Add("Table", "tblPlots");
            //dTblPlots.Columns.Add("PLT_CN",System.Type.GetType("System.String"));
            IQueryFilter qf = new QueryFilterClass();

            qf.SubFields = PlotCnField;
            if (SubPlotField != "" && SubPlotField != null)
            {
                qf.SubFields = PlotCnField + "," + SubPlotField;
            }
            IFeatureCursor fCur     = SampleFeatureClass.Search(qf, true);
            int            cnIndex  = fCur.FindField(PlotCnField);
            int            subIndex = fCur.FindField(SubPlotField);
            IFeature       ftr      = fCur.NextFeature();

            while (ftr != null)
            {
                string plCn   = ftr.get_Value(cnIndex).ToString();
                string subPlt = "0";
                if (subIndex > -1)
                {
                    object subPltObj = ftr.get_Value(subIndex);
                    if (subPltObj != null)
                    {
                        subPlt = subPltObj.ToString();
                    }
                }
                string pltID = plCn + "_" + subPlt;
                //Console.WriteLine(pltID);
                unPlots.Add(pltID);
                ftr = fCur.NextFeature();
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(fCur);
        }
Example #3
0
 private void addRegenFields()
 {
     foreach (string s in rUnSp)
     {
         string fldNm = "RTPA_" + s;
         if (SampleFeatureClass.FindField(fldNm) > -1)
         {
         }
         else
         {
             geoDbUtil.createField(SampleFeatureClass, fldNm, esriFieldType.esriFieldTypeDouble);
         }
     }
 }
Example #4
0
        public void summarizeBiomass()
        {
            try
            {
                if (SubPlotField == null)
                {
                    SubPlotField = "";
                }
                //Console.WriteLine("Creating FIlling Plots Table");
                createAndFillPlotsTable();
                //Console.WriteLine("Creating And Filling Tree Ref Table");
                createAndFillTreesRef();
                //Console.WriteLine("Adding fields");
                //need to add in groups and update unSp
                addFields();
                if (regen)
                {
                    createAndFillRegenRef();
                    //System.Windows.Forms.MessageBox.Show(String.Join(", ", rgDic.Keys.ToArray()));
                    addRegenFields();
                }
                if (less5)
                {
                    addFields("s");
                }
                IQueryFilter   qryFlt   = new QueryFilterClass();
                string         nFldNm   = "";
                string         fldNm    = "";
                IFeatureCursor ftrCur   = SampleFeatureClass.Update(null, true);
                IFeature       ftr      = ftrCur.NextFeature();
                int            cnIndex  = ftrCur.FindField(PlotCnField);
                int            subIndex = ftrCur.FindField(SubPlotField);
                double         divs     = (43560 / (Math.PI * Math.Pow(24, 2)));
                double         rdivs    = (43560 / (Math.PI * Math.Pow(6.8, 2)));
                if (SubPlotField == "" || SubPlotField == null)
                {
                    divs  = divs / 4;
                    rdivs = rdivs / 4;
                }
                List <string> allEstFld = Enum.GetNames(typeof(biomassTypes)).ToList();
                while (ftr != null)
                {
                    string pCn = ftr.get_Value(cnIndex).ToString();
                    int    sPl = 0;
                    if (subIndex > -1)
                    {
                        sPl = System.Convert.ToInt32(ftr.get_Value(subIndex));
                    }
                    if (regen)
                    {
                        foreach (string rt in rUnSp)
                        {
                            string ky = pCn + "_" + sPl + "_" + rt;
                            int    rgCnt;
                            double cnt = 0;
                            if (rgDic.TryGetValue(ky, out rgCnt))
                            {
                                cnt = rdivs * rgCnt;
                            }
                            else
                            {
                                cnt = 0;
                            }
                            int rgIndex = ftr.Fields.FindField("RTPA_" + rt);
                            ftr.set_Value(rgIndex, cnt);
                        }
                    }
                    if (less5)
                    {
                        foreach (string t in sUnSp)                  //(biomassTypes s in fldArr)
                        {
                            string   ky = pCn + "_" + sPl + "_" + t; //CN_SubPlot_species
                            object[] vls;
                            if (sVlDic.TryGetValue(ky, out vls))
                            {
                            }
                            else
                            {
                                vls     = new object[12];
                                vls[0]  = pCn;
                                vls[1]  = sPl;
                                vls[2]  = t;
                                vls[3]  = 0; //MDBH
                                vls[4]  = 0; //AGB
                                vls[5]  = 0; //StemAGB
                                vls[6]  = 0; //ButtAGB
                                vls[7]  = 0; //FoliageAGB
                                vls[8]  = 0; //TopAGB
                                vls[9]  = 0; //BAA
                                vls[10] = 0; //TPA
                                vls[11] = 0; //MHT
                            }
                            foreach (biomassTypes s in fldArr)
                            {
                                string btStr      = s.ToString();
                                int    arrayIndex = allEstFld.IndexOf(btStr);
                                double sdivs2     = rdivs;
                                if (arrayIndex <= 1)
                                {
                                    arrayIndex = 9 + arrayIndex;
                                }
                                else
                                {
                                    if (arrayIndex <= 6)
                                    {
                                        arrayIndex = 2 + arrayIndex;
                                        sdivs2     = rdivs / 2000;//tons
                                    }
                                    else if (arrayIndex == 7)
                                    {
                                        arrayIndex = 3;
                                        double d = System.Convert.ToDouble(vls[10]);
                                        if (d < 1)
                                        {
                                            sdivs2 = 1;
                                        }
                                        else
                                        {
                                            sdivs2 = 1 / d;
                                        }
                                    }
                                    else
                                    {
                                        arrayIndex = 11;
                                        double d = System.Convert.ToDouble(vls[10]);
                                        if (d < 1)
                                        {
                                            sdivs2 = 1;
                                        }
                                        else
                                        {
                                            sdivs2 = 1 / d;
                                        }
                                    }
                                }

                                string spCd = vls[2].ToString();
                                fldNm = "s" + s + "_" + spCd;
                                //Console.WriteLine(fldNm);
                                int fldIndex = ftrCur.FindField(fldNm);
                                if (fldIndex == -1)
                                {
                                    fldIndex = ftrCur.FindField(nFldNm.Substring(0, 10));
                                }
                                object vl = (System.Convert.ToDouble(vls[arrayIndex])) * sdivs2;
                                ftr.set_Value(fldIndex, vl);
                            }
                        }
                    }

                    foreach (string t in unSp)                   //(biomassTypes s in fldArr)
                    {
                        string   ky = pCn + "_" + sPl + "_" + t; //CN_SubPlot_species
                        object[] vls;
                        if (vlDic.TryGetValue(ky, out vls))
                        {
                        }
                        else
                        {
                            vls     = new object[12];
                            vls[0]  = pCn;
                            vls[1]  = sPl;
                            vls[2]  = t;
                            vls[3]  = 0; //MDBH
                            vls[4]  = 0; //AGB
                            vls[5]  = 0; //StemAGB
                            vls[6]  = 0; //ButtAGB
                            vls[7]  = 0; //FoliageAGB
                            vls[8]  = 0; //TopAGB
                            vls[9]  = 0; //BAA
                            vls[10] = 0; //TPA
                            vls[11] = 0; //MHT
                        }
                        foreach (biomassTypes s in fldArr)
                        {
                            string btStr      = s.ToString();
                            int    arrayIndex = allEstFld.IndexOf(btStr);
                            double divs2      = divs;
                            if (arrayIndex <= 1)
                            {
                                arrayIndex = 9 + arrayIndex;
                            }
                            else
                            {
                                if (arrayIndex <= 6)
                                {
                                    arrayIndex = 2 + arrayIndex;
                                    divs2      = divs / 2000;//tons
                                }
                                else if (arrayIndex == 7)
                                {
                                    arrayIndex = 3;
                                    double d = System.Convert.ToDouble(vls[10]);
                                    if (d < 1)
                                    {
                                        divs2 = 1;
                                    }
                                    else
                                    {
                                        divs2 = 1 / d;
                                    }
                                }
                                else
                                {
                                    arrayIndex = 11;
                                    double d = System.Convert.ToDouble(vls[10]);
                                    if (d < 1)
                                    {
                                        divs2 = 1;
                                    }
                                    else
                                    {
                                        divs2 = 1 / d;
                                    }
                                }
                            }

                            string spCd = vls[2].ToString();
                            fldNm = s + "_" + spCd;
                            //Console.WriteLine(fldNm);
                            int fldIndex = ftrCur.FindField(fldNm);
                            if (fldIndex == -1)
                            {
                                fldIndex = ftrCur.FindField(nFldNm.Substring(0, 10));
                            }
                            object vl = (System.Convert.ToDouble(vls[arrayIndex])) * divs2;
                            ftr.set_Value(fldIndex, vl);
                        }
                    }
                    ftrCur.UpdateFeature(ftr);
                    ftr = ftrCur.NextFeature();
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(ftrCur);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                //System.Environment.OSVersion.
                if (av == "0.0" || ev == "0.0")
                {
                    System.Windows.Forms.MessageBox.Show("You do not have OleDB 12.0 installed. Please download and install Office 2007 data provider from:\nhttp://www.microsoft.com/en-us/download/confirmation.aspx?id=23734", "No data provider found", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                }
                else
                {
                    Console.WriteLine(e.ToString());
                }
            }
        }