Пример #1
0
        public void start()
        {
            try
            {
                geoDatabaseUtility         geoUtil = new geoDatabaseUtility();
                System.Diagnostics.Process pr      = new System.Diagnostics.Process();
                geoUtil.check_dir(rmrsDir);
                string hFl = rmrsDir + "\\" + HelpFileName;
                pr.StartInfo.FileName = hFl;

                if (System.IO.File.Exists(hFl))
                {
                    pr.Start();
                }
                else
                {
                    update up = new update();
                    try
                    {
                        System.Windows.Forms.MessageBox.Show("Can't find help files. Trying to download from the internet.");
                        string cuSet = up.UpdateCheck;
                        if (cuSet.ToLower() != "yes")
                        {
                            up.UpdateCheck = "yes";
                        }
                        Properties.Settings.Default.HelpVersion = "unknown";
                        Properties.Settings.Default.Save();
                        if (up.updateHelp())
                        {
                            pr.Start();
                        }
                        else
                        {
                            System.Windows.Forms.MessageBox.Show("Can't find help files on the internet. Try again later.");
                        }
                        up.UpdateCheck = cuSet;
                    }
                    catch
                    {
                        System.Windows.Forms.MessageBox.Show("Error in updating help. Try again later.");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            finally
            {
            }
        }
Пример #2
0
 public frmHelper(IMap map, rasterUtil rasterUtility = null)
 {
     TheMap         = map;
     GeoUtility     = new geoDatabaseUtility();
     FeatureUtility = new featureUtil();
     if (rasterUtility == null)
     {
         RasterUtility = new rasterUtil();
     }
     else
     {
         RasterUtility = rasterUtility;
     }
     fillDictionary();
 }
Пример #3
0
        private void btnDownload_Click(object sender, EventArgs e)
        {
            if (!checkInputs())
            {
                MessageBox.Show("You must have a value for all inputs");
                return;
            }
            mapserviceutility  msUtil  = new mapserviceutility();
            geoDatabaseUtility geoUtil = new geoDatabaseUtility();
            IImageServerLayer  svLyr   = getServerLayer();

            ESRI.ArcGIS.Geometry.IEnvelope ext = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            if (cmbExtent.Text.ToLower() == "display")
            {
                ext = av.Extent;
            }
            else
            {
                IFeatureLayer ftrLyr = getFeatureLayer();
                ext = ((ESRI.ArcGIS.Geodatabase.IGeoDataset)ftrLyr).Extent;
            }
            if (svLyr == null)
            {
                MessageBox.Show("You must select a Image server layer");
                return;
            }
            this.Visible = false;
            ESRI.ArcGIS.Geodatabase.IWorkspace wks = geoUtil.OpenWorkSpace(txtGeoDb.Text);
            ESRI.ArcGIS.Geodatabase.IRaster    rs  = null;
            string msg = msUtil.fillDbRaster(svLyr, wks, ext, svLyr.ServiceInfo.SpatialReference, out rs);
            IMap   mp  = (IMap)av;

            if (rs != null)
            {
                IRasterLayer rsLyr = new RasterLayerClass();
                rsLyr.CreateFromRaster(rs);
                rsLyr.Name    = svLyr.ServiceInfo.Name;
                rsLyr.Visible = false;
                mp.AddLayer((ILayer)rsLyr);
            }
            this.Close();
            //MessageBox.Show(msg);
        }
 private void btnDownload_Click(object sender, EventArgs e)
 {
     if (!checkInputs())
     {
         MessageBox.Show("You must have a value for all inputs");
         return;
     }
     mapserviceutility msUtil = new mapserviceutility();
     geoDatabaseUtility geoUtil = new geoDatabaseUtility();
     IImageServerLayer svLyr = getServerLayer();
     ESRI.ArcGIS.Geometry.IEnvelope ext = new ESRI.ArcGIS.Geometry.EnvelopeClass();
     if(cmbExtent.Text.ToLower()=="display")
     {
         ext = av.Extent;
     }
     else
     {
         IFeatureLayer ftrLyr = getFeatureLayer();
         ext = ((ESRI.ArcGIS.Geodatabase.IGeoDataset)ftrLyr).Extent;
     }
     if(svLyr==null)
     {
         MessageBox.Show("You must select a Image server layer");
         return;
     }
     this.Visible = false;
     ESRI.ArcGIS.Geodatabase.IWorkspace wks = geoUtil.OpenWorkSpace(txtGeoDb.Text);
     ESRI.ArcGIS.Geodatabase.IRaster rs = null;
     string msg = msUtil.fillDbRaster(svLyr,wks,ext,svLyr.ServiceInfo.SpatialReference,out rs);
     IMap mp = (IMap)av;
     if (rs != null)
     {
         IRasterLayer rsLyr = new RasterLayerClass();
         rsLyr.CreateFromRaster(rs);
         rsLyr.Name = svLyr.ServiceInfo.Name;
         rsLyr.Visible = false;
         mp.AddLayer((ILayer)rsLyr);
     }
     this.Close();
     //MessageBox.Show(msg);
 }
Пример #5
0
        /// <summary>
        /// adds a layer to the active view
        /// </summary>
        /// <param name="path">full path name</param>
        /// <returns>Ilayer</returns>
        public ILayer addLayer(string path)
        {
            IMap map = (IMap)acView;
            geoDatabaseUtility geoUtil = new geoDatabaseUtility();
            esriDatasetType    dType   = geoUtil.getDataType(path);
            ILayer             lyr     = null;

            switch (dType)
            {
            case esriDatasetType.esriDTFeatureClass:
                IFeatureLayer ftrLayer = new FeatureLayerClass();
                ftrLayer.FeatureClass = geoUtil.getFeatureClass(path);
                lyr      = (ILayer)ftrLayer;
                lyr.Name = ftrLayer.FeatureClass.AliasName;
                map.AddLayer(lyr);
                break;

            case esriDatasetType.esriDTRasterBand:
            case esriDatasetType.esriDTRasterCatalog:
            case esriDatasetType.esriDTRasterDataset:
                IRasterLayer rasterLayer = new RasterLayerClass();
                rasterLayer.CreateFromDataset(geoUtil.getRasterDataset(path));
                rasterLayer.Name = rasterLayer.Name;
                map.AddLayer((ILayer)rasterLayer);
                break;

            case esriDatasetType.esriDTTable:
                ITable           tbl             = geoUtil.getTable(path);
                ITableCollection tableCollection = (ITableCollection)map;
                tableCollection.AddTable(tbl);
                break;

            default:
                break;
            }
            acView.Refresh();
            return(lyr);
        }
Пример #6
0
        private List <string> getNames(esriDatasetType dType)
        {
            geoDatabaseUtility geoUtil = new geoDatabaseUtility();
            List <string>      lyrLst  = new List <string>();

            switch (dType)
            {
            case esriDatasetType.esriDTFeatureClass:
                lyrLst = geoUtil.getAllFeatureNames(prjDatabase);
                break;

            case esriDatasetType.esriDTRasterDataset:
                lyrLst = geoUtil.getAllRasterNames(prjDatabase);
                break;

            case esriDatasetType.esriDTTable:
                lyrLst = geoUtil.getAllTableNames(prjDatabase);
                break;

            default:
                break;
            }
            return(lyrLst);
        }
Пример #7
0
        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)
            {
                for (int i = 0; i < unqCnt; i++)
                {
                    IRow rwZs = curZs.NextRow();
                    for (int j = 0; j < zsFldNames.Count; j++)
                    {
                        string zsN           = zsFldNames[j];
                        int    zsNIndex      = zsFldNamesIndex[j];
                        double zsVl          = System.Convert.ToDouble(rwZs.get_Value(zsNIndex));
                        string newZName      = prf + zsN + "_" + (i + 1).ToString();
                        int    newZNameIndex = newFldNamesIndex[newFldNames.IndexOf(newZName)];
                        rwZ.set_Value(newZNameIndex, zsVl);
                    }
                }
                rwZ.Store();
                //curZ.UpdateRow(rwZ);
                rwZ = curZ.NextRow();
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(curZ);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(curZs);
        }
        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)
            {
                for (int i = 0; i < unqCnt; i++)
                {
                    IRow rwZs = curZs.NextRow();
                    for (int j = 0; j < zsFldNames.Count; j++)
                    {
                        string zsN = zsFldNames[j];
                        int zsNIndex = zsFldNamesIndex[j];
                        double zsVl = System.Convert.ToDouble(rwZs.get_Value(zsNIndex));
                        string newZName = prf+zsN + "_" + (i + 1).ToString();
                        int newZNameIndex = newFldNamesIndex[newFldNames.IndexOf(newZName)];
                        rwZ.set_Value(newZNameIndex, zsVl);
                    }
                }
                rwZ.Store();
                //curZ.UpdateRow(rwZ);
                rwZ = curZ.NextRow();
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(curZ);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(curZs);
        }
Пример #9
0
        static void Main(string[] args)
        {
            //ESRI License Initializer generated code.
            m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeAdvanced }, new esriLicenseExtensionCode[] { esriLicenseExtensionCode.esriLicenseExtensionCode3DAnalyst });//{esriLicenseExtensionCode.esriLicenseExtensionCode3DAnalyst});
            System.DateTime dt = System.DateTime.Now;

            System.DateTime dt2;
            TimeSpan        ts;

            rasterUtil         rsUtil  = new rasterUtil();
            geoDatabaseUtility geoUtil = new geoDatabaseUtility();
            string             pred    = @"C:\Users\jshogland\Documents\John\projects\FtStewart\models\TreeEstimates\HdwPresentPred.bch";
            string             mdl     = @"C:\Users\jshogland\Documents\John\projects\FtStewart\models\TreeEstimates\HdwPresent.mdl";

            double[] minArr, maxArr;
            Console.WriteLine("Getting Min Max");
            batchCalculations.getMinMaxArr(mdl, out minArr, out maxArr);
            Console.WriteLine("First Min Max: " + minArr[0].ToString() + ";" + maxArr[0].ToString());
            IFunctionRasterDataset fdset = rsUtil.extactModelDomainFunction(pred, minArr, maxArr);

            Console.WriteLine(fdset.RasterInfo.PixelType.ToString());
            IRaster rs      = rsUtil.createRaster(fdset);
            IPnt    pntSize = new PntClass();

            pntSize.SetCoords(100, 100);
            IPixelBlock pb = rs.CreatePixelBlock(pntSize);

            rs.Read(pntSize, pb);
            int cnt = 0;

            for (int r = 0; r < pb.Height; r++)
            {
                for (int c = 0; c < pb.Width; c++)
                {
                    object vl = pb.GetVal(0, c, r);
                    if (vl != null)
                    {
                        if (System.Convert.ToInt32(vl) == 0)
                        {
                            cnt++;
                        }
                    }
                }
            }
            Console.WriteLine("Total zeros = " + cnt.ToString());
            //string dir = @"C:\Users\jshogland\Documents\John\projects\UMGradSchool\Classes\Mining Big Data\Assignments\NatureServe\train\ALB";
            //string[] fls = System.IO.Directory.GetFiles(dir, "*.jpg");
            //foreach (string flPath in fls)
            //{
            //    string nm = System.IO.Path.GetFileNameWithoutExtension(flPath);
            //    Console.WriteLine(nm);
            //    Bitmap bm = new Bitmap(flPath);
            //    Accord.Imaging.Moments.CentralMoments cm = new Accord.Imaging.Moments.CentralMoments(bm, 3);
            //    //Console.WriteLine(cm.Mu00.ToString());
            //    Console.WriteLine("\t"+cm.Mu01.ToString());
            //    Console.WriteLine("\t" + cm.Mu02.ToString());
            //    Console.WriteLine("\t" + cm.Mu03.ToString());
            //    Console.WriteLine("\t" + cm.Mu10.ToString());
            //    Console.WriteLine("\t" + cm.Mu20.ToString());
            //    Console.WriteLine("\t" + cm.Mu30.ToString());
            //}

            //string plots = @"C:\Users\jshogland\Documents\John\projects\UMGradSchool\Project\papers\Co-registration\Data\coReg.gdb\SampleLocations";
            //string ls= @"C:\Users\jshogland\Documents\John\projects\UMGradSchool\Project\papers\Co-registration\Data\FloridaLandsat.tif";
            //string naip= @"C:\Users\jshogland\Documents\John\projects\UMGradSchool\Project\papers\Co-registration\Data\GeorgiaNaipAgAl.tif";
            //rasterUtil rsUtil = new rasterUtil();



            //HashSet<string> uStr = new HashSet<string>();
            //int[] filesLines = getClasses(prjDir,ref uStr);
            //Console.WriteLine("Files = " + filesLines[0].ToString());
            //Console.WriteLine("Lines = " + filesLines[1].ToString());
            //Console.WriteLine(uStr.Count().ToString());



            //geoDatabaseUtility geoUtil = new geoDatabaseUtility();
            //rasterUtil rsUtil = new rasterUtil();
            //featureUtil ftrUtil = new featureUtil(rsUtil);
            ////string origPath = @"C:\Users\jshogland\Documents\John\projects\SpatialAdjust\Shift.gdb\OriginalSample";
            ////string nwPath = @"C:\Users\jshogland\Documents\John\projects\SpatialAdjust\Shift.gdb\RandomtShiftSample";
            ////CreateNewPoints(origPath, nwPath, rsUtil, ftrUtil, geoUtil, true);
            //string fiaTestPath = @"C:\Users\jshogland\Documents\John\projects\SpatialAdjust\Shift.gdb\RandomtShiftSample";
            //string fiaOutPath = @"C:\Users\jshogland\Documents\John\projects\SpatialAdjust\Shift.gdb\adjustSample";
            //string rsPath = @"C:\Users\jshogland\Documents\John\projects\SpatialAdjust\models\predictorsOneVariable.bch";
            //IFunctionRasterDataset fDset = rsUtil.createIdentityRaster(rsPath);
            //IFeatureClass ftrCls = geoUtil.getFeatureClass(fiaTestPath);
            //int error = 15;
            //adjustCoregistrationErrors aE = new adjustCoregistrationErrors(rsUtil);
            //aE.FunctionRasterDataset = fDset;
            //aE.DependentField = "Pred15";
            //aE.GeometricErrorCells = error;
            //aE.OutFtrClassPath = fiaOutPath;
            //aE.PlotFeatureClass = ftrCls;
            //aE.adjustErrors();
            dt2 = System.DateTime.Now;
            ts  = dt2.Subtract(dt);
            Console.WriteLine("Total Seconds = " + ts.TotalSeconds.ToString());

            m_AOLicenseInitializer.ShutdownApplication();
        }
Пример #10
0
        private static void CreateNewPoints(string inPath, string outPath, rasterUtil rsUtil, featureUtil ftrUtil, geoDatabaseUtility geoUtil, bool prnd = true, int cShift = 5)
        {
            IFeatureClass  ftrCls    = geoUtil.getFeatureClass(inPath);
            IFeatureClass  newFtrCls = ftrUtil.exportFeatures(ftrCls, outPath, null);
            IFeatureCursor uCur      = newFtrCls.Update(null, true);
            IFeature       ftr       = uCur.NextFeature();

            if (prnd)
            {
                System.Random rnd = new Random();
                while (ftr != null)
                {
                    IPoint opnt = (IPoint)ftr.ShapeCopy;
                    IPoint pnt  = new PointClass();
                    double rndx = rnd.NextDouble() * 10;
                    double rndy = rnd.NextDouble() * 10;
                    pnt.PutCoords(opnt.X + rndx, opnt.Y + rndy);
                    ftr.Shape = pnt;
                    uCur.UpdateFeature(ftr);
                    ftr = uCur.NextFeature();
                }
            }
            else
            {
                while (ftr != null)
                {
                    IPoint opnt = (IPoint)ftr.ShapeCopy;
                    IPoint pnt  = new PointClass();
                    pnt.PutCoords(opnt.X + cShift, opnt.Y + cShift);
                    ftr.Shape = pnt;
                    uCur.UpdateFeature(ftr);
                    ftr = uCur.NextFeature();
                }
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(uCur);
        }
 private List<string> getNames(esriDatasetType dType)
 {
     geoDatabaseUtility geoUtil = new geoDatabaseUtility();
     List<string> lyrLst = new List<string>();
     switch (dType)
     {
         case esriDatasetType.esriDTFeatureClass:
             lyrLst = geoUtil.getAllFeatureNames(prjDatabase);
             break;
         case esriDatasetType.esriDTRasterDataset:
             lyrLst = geoUtil.getAllRasterNames(prjDatabase);
             break;
         case esriDatasetType.esriDTTable:
             lyrLst = geoUtil.getAllTableNames(prjDatabase);
             break;
         default:
             break;
     }
     return lyrLst;
 }
Пример #12
0
        private static void calcStandMeans(IFeatureClass strataFtr, IFeatureClass standsFtr, int[] meanStrataFldIndex, int[] varStrataFldIndex, int[] countFldStrataIndex, IField[] fldsToSummarize, geoDatabaseUtility geoUtil)
        {
            int cnt = 0;

            int[] ptFldIndex   = new int[fldsToSummarize.Length];
            int[] meanFldIndex = new int[fldsToSummarize.Length];
            int[] varFldIndex  = new int[fldsToSummarize.Length];
            int[] cntFldIndex  = new int[fldsToSummarize.Length];
            foreach (IField fld in fldsToSummarize)
            {
                string sName = geoUtil.createField(standsFtr, "v_" + fld.Name, esriFieldType.esriFieldTypeDouble, false);
                varFldIndex[cnt] = standsFtr.FindField(sName);
                string mName = geoUtil.createField(standsFtr, "m_" + fld.Name, esriFieldType.esriFieldTypeDouble, false);
                meanFldIndex[cnt] = standsFtr.FindField(mName);
                string cName = geoUtil.createField(standsFtr, "n_" + fld.Name, esriFieldType.esriFieldTypeDouble, false);
                cntFldIndex[cnt] = standsFtr.FindField(cName);
                cnt++;
            }
            IFeatureCursor uCur = standsFtr.Update(null, true);
            IFeature       uFtr = uCur.NextFeature();

            while (uFtr != null)
            {
                ESRI.ArcGIS.Geometry.IGeometry geo = uFtr.Shape;
                ISpatialFilter spFlt = new SpatialFilter();
                spFlt.Geometry   = geo;
                spFlt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                double         totalArea = 0;
                IFeatureCursor sCur      = strataFtr.Search(spFlt, true);
                IFeature       sFtr      = sCur.NextFeature();
                double[][]     vlArr     = new double[meanFldIndex.Length][];
                for (int i = 0; i < meanFldIndex.Length; i++)
                {
                    vlArr[i] = new double[3];
                }
                while (sFtr != null)
                {
                    ESRI.ArcGIS.Geometry.IGeometry             sgeo  = sFtr.Shape;
                    ESRI.ArcGIS.Geometry.ITopologicalOperator4 topo  = (ESRI.ArcGIS.Geometry.ITopologicalOperator4)sgeo;
                    ESRI.ArcGIS.Geometry.IGeometry             sgeo2 = topo.Intersect(geo, ESRI.ArcGIS.Geometry.esriGeometryDimension.esriGeometry2Dimension);
                    double subArea = (((ESRI.ArcGIS.Geometry.IArea)sgeo2).Area);
                    totalArea += subArea;
                    for (int i = 0; i < meanFldIndex.Length; i++)
                    {
                        vlArr[i][0] += System.Convert.ToDouble(sFtr.get_Value(meanStrataFldIndex[i])) * subArea;
                        vlArr[i][1] += System.Convert.ToDouble(sFtr.get_Value(varStrataFldIndex[i])) * subArea;
                        vlArr[i][2] += System.Convert.ToDouble(sFtr.get_Value(countFldStrataIndex[i]));
                    }
                    sFtr = sCur.NextFeature();
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(sCur);
                if (totalArea != 0)
                {
                    for (int i = 0; i < meanFldIndex.Length; i++)
                    {
                        uFtr.set_Value(meanFldIndex[i], vlArr[i][0] / totalArea);
                        uFtr.set_Value(varFldIndex[i], vlArr[i][1] / totalArea);
                        uFtr.set_Value(cntFldIndex[i], vlArr[i][2]);
                    }
                    uCur.UpdateFeature(uFtr);
                }
                uFtr = uCur.NextFeature();
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(uCur);
        }
Пример #13
0
        public static void summarizeBiomassPolygon(IFeatureClass pointFtr, IField[] fldsToSummarize, IFeatureClass strataFtr, IFeatureClass standsFtr = null, geoDatabaseUtility geoUtil = null)
        {
            if (geoUtil == null)
            {
                geoUtil = new geoDatabaseUtility();
            }
            int cnt = 0;

            int[] ptFldIndex   = new int[fldsToSummarize.Length];
            int[] meanFldIndex = new int[fldsToSummarize.Length];
            int[] varFldIndex  = new int[fldsToSummarize.Length];
            int[] cntFldIndex  = new int[fldsToSummarize.Length];
            foreach (IField fld in fldsToSummarize)
            {
                ptFldIndex[cnt] = pointFtr.FindField(fld.Name);
                string sName = geoUtil.createField(strataFtr, "v_" + fld.Name, esriFieldType.esriFieldTypeDouble, false);
                varFldIndex[cnt] = strataFtr.FindField(sName);
                string mName = geoUtil.createField(strataFtr, "m_" + fld.Name, esriFieldType.esriFieldTypeDouble, false);
                meanFldIndex[cnt] = strataFtr.FindField(mName);
                string cntName = geoUtil.createField(strataFtr, "n_" + fld.Name, esriFieldType.esriFieldTypeInteger, false);
                cntFldIndex[cnt] = strataFtr.FindField(cntName);
                cnt++;
            }
            IFeatureCursor uCur = strataFtr.Update(null, true);
            IFeature       uFtr = uCur.NextFeature();

            while (uFtr != null)
            {
                ISpatialFilter sFilt = new SpatialFilter();
                sFilt.Geometry   = uFtr.Shape;
                sFilt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                double[][] fldVlsArr = new double[fldsToSummarize.Length][];
                for (int i = 0; i < fldsToSummarize.Length; i++)
                {
                    fldVlsArr[i] = new double[3];
                }
                IFeatureCursor psCur = pointFtr.Search(sFilt, true);
                IFeature       psFtr = psCur.NextFeature();

                while (psFtr != null)
                {
                    for (int i = 0; i < ptFldIndex.Length; i++)
                    {
                        int    indexVl = ptFldIndex[i];
                        object objVl   = psFtr.get_Value(indexVl);
                        if (objVl != null)
                        {
                            double vl  = System.Convert.ToDouble(objVl);
                            double vl2 = vl * vl;
                            fldVlsArr[i][0] += vl;
                            fldVlsArr[i][1] += vl2;
                            fldVlsArr[i][2] += 1;
                        }
                    }
                    psFtr = psCur.NextFeature();
                }

                System.Runtime.InteropServices.Marshal.ReleaseComObject(psCur);
                for (int i = 0; i < ptFldIndex.Length; i++)
                {
                    double s        = fldVlsArr[i][0];
                    double s2       = fldVlsArr[i][1];
                    double n        = fldVlsArr[i][2];
                    double mean     = s / n;                                 //mean
                    double var      = (s2 - (Math.Pow(s, 2) / n)) / (n - 1); //variance
                    int    mIndex   = meanFldIndex[i];
                    int    vIndex   = varFldIndex[i];
                    int    cntIndex = cntFldIndex[i];
                    uFtr.set_Value(mIndex, mean);
                    uFtr.set_Value(vIndex, var);
                    uFtr.set_Value(cntIndex, n);
                }
                uCur.UpdateFeature(uFtr);
                uFtr = uCur.NextFeature();
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(uCur);
            if (standsFtr != null)
            {
                calcStandMeans(strataFtr, standsFtr, meanFldIndex, varFldIndex, cntFldIndex, fldsToSummarize, geoUtil);
            }
        }
Пример #14
0
        private static Dictionary <string, double[][]> getDictionaryValues(ESRI.ArcGIS.Geodatabase.IFeatureClass pointFtr, ESRI.ArcGIS.Geodatabase.IField[] fldsToSummarize, IFunctionRasterDataset strataRaster, geoDatabaseUtility geoUtil, rasterUtil rsUtil)
        {
            IRaster2 rs2 = (IRaster2)rsUtil.createRaster(strataRaster);

            int[] ptfldIndex = new int[fldsToSummarize.Length];
            for (int i = 0; i < ptfldIndex.Length; i++)
            {
                ptfldIndex[i] = pointFtr.FindField(fldsToSummarize[i].Name);
            }
            Dictionary <string, double[][]> outDic = new Dictionary <string, double[][]>();
            IFeatureCursor sCur = pointFtr.Search(null, true);
            IFeature       sFtr = sCur.NextFeature();

            while (sFtr != null)
            {
                IGeometry geo = sFtr.Shape;
                IPoint    pnt = (IPoint)geo;
                int       clm, rw;
                rs2.MapToPixel(pnt.X, pnt.Y, out clm, out rw);
                object strataVlObj = rs2.GetPixelValue(0, clm, rw);
                if (strataVlObj != null)
                {
                    string     strataVl = strataVlObj.ToString();
                    double[][] vlArr;
                    if (outDic.TryGetValue(strataVl, out vlArr))
                    {
                        for (int i = 0; i < ptfldIndex.Length; i++)
                        {
                            object vlObj = sFtr.get_Value(ptfldIndex[i]);
                            if (vlObj != null)
                            {
                                double vl = System.Convert.ToDouble(vlObj);
                                vlArr[i][0] += vl;
                                vlArr[i][1] += (vl * vl);
                                vlArr[i][2] += 1;
                            }
                        }
                    }
                    else
                    {
                        vlArr = new double[fldsToSummarize.Length][];
                        for (int i = 0; i < ptfldIndex.Length; i++)
                        {
                            double[] vlSumArr = new double[3];
                            object   vlObj    = sFtr.get_Value(ptfldIndex[i]);
                            if (vlObj != null && !System.Convert.IsDBNull(vlObj))
                            {
                                double vl = System.Convert.ToDouble(vlObj);
                                vlSumArr[0] = vl;
                                vlSumArr[1] = (vl * vl);
                                vlSumArr[2] = 1;
                            }
                            vlArr[i] = vlSumArr;
                        }
                        outDic[strataVl] = vlArr;
                    }
                }
                sFtr = sCur.NextFeature();
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(sCur);
            return(outDic);
        }
Пример #15
0
        public static void summarizeBiomassPolygon(IFeatureClass pointFtr, IField[] fldsToSummarize, IFunctionRasterDataset strataRaster, IFeatureClass standsFtr, geoDatabaseUtility geoUtil = null, rasterUtil rsUtil = null)
        {
            if (geoUtil == null)
            {
                geoUtil = new geoDatabaseUtility();
            }
            if (rsUtil == null)
            {
                rsUtil = new rasterUtil();
            }
            int cnt = 0;
            //need to work on calculating N
            Dictionary <string, double[][]> vlDic = getDictionaryValues(pointFtr, fldsToSummarize, strataRaster, geoUtil, rsUtil); //Strata: SummaryFields [{sum,sum2,cnt},...]

            int[] meanFldIndex = new int[fldsToSummarize.Length];
            int[] varFldIndex  = new int[fldsToSummarize.Length];
            int[] cntFldIndex  = new int[fldsToSummarize.Length];
            //string cntName = geoUtil.createField(standsFtr, "n", esriFieldType.esriFieldTypeInteger, false);
            //int cntIndex = standsFtr.FindField(cntName);
            foreach (IField fld in fldsToSummarize)
            {
                string sName = geoUtil.createField(standsFtr, "v_" + fld.Name, esriFieldType.esriFieldTypeDouble, false);
                varFldIndex[cnt] = standsFtr.FindField(sName);
                string mName = geoUtil.createField(standsFtr, "m_" + fld.Name, esriFieldType.esriFieldTypeDouble, false);
                meanFldIndex[cnt] = standsFtr.FindField(mName);
                string cntName = geoUtil.createField(standsFtr, "n_" + fld.Name, esriFieldType.esriFieldTypeDouble, false);
                cntFldIndex[cnt] = standsFtr.FindField(cntName);
                cnt++;
            }
            IFeatureCursor uCur = standsFtr.Update(null, true);
            IFeature       uFtr = uCur.NextFeature();

            while (uFtr != null)
            {
                ESRI.ArcGIS.Geometry.IGeometry geo = uFtr.Shape;
                IFunctionRasterDataset         cRs = rsUtil.clipRasterFunction(strataRaster, geo, esriRasterClippingType.esriRasterClippingOutside);
                //Console.WriteLine("Clipping raster");
                Dictionary <string, double> rsStrataPropDic = getStrataProportion(cRs, rsUtil); //Strata: proportion of area
                //int tn = 0;
                //double[] tn = new double[meanFldIndex.Length];
                double[][] updateValuesArr = new double[meanFldIndex.Length][];
                for (int i = 0; i < meanFldIndex.Length; i++)
                {
                    updateValuesArr[i] = new double[3];
                }
                foreach (KeyValuePair <string, double> kvp in rsStrataPropDic)
                {
                    string stratum    = kvp.Key;
                    double proportion = kvp.Value;
                    //Console.WriteLine(stratum + " = " + proportion.ToString());
                    double[][] vlDicArr;
                    if (vlDic.TryGetValue(stratum, out vlDicArr))
                    {
                        //double n = vlDicArr[0][2];
                        //tn += System.Convert.ToInt32(n);
                        for (int i = 0; i < meanFldIndex.Length; i++)
                        {
                            double[] dArr = vlDicArr[i];
                            double   n    = dArr[2];
                            //tn[i] += n;
                            double s  = dArr[0];
                            double s2 = dArr[1];
                            updateValuesArr[i][0] += (s / n) * proportion;                             //mean
                            updateValuesArr[i][1] += (s2 - Math.Pow(s, 2) / n) / (n - 1) * proportion; //variance
                            updateValuesArr[i][2] += n;
                        }
                    }
                }
                //uFtr.set_Value(cntIndex, tn);
                for (int i = 0; i < meanFldIndex.Length; i++)
                {
                    uFtr.set_Value(meanFldIndex[i], updateValuesArr[i][0]);
                    uFtr.set_Value(varFldIndex[i], updateValuesArr[i][1]);
                    uFtr.set_Value(cntFldIndex[i], updateValuesArr[i][2]);
                }
                uCur.UpdateFeature(uFtr);
                uFtr = uCur.NextFeature();
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(uCur);
        }