Beispiel #1
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            m_pEngine.Evaluate("ip <- installed.packages()").AsCharacter();
            string[]         installedPackages = m_pEngine.Evaluate("ip[,1]").AsCharacter().ToArray(); //To Check Installed Packages in R
            clsRPackageNames pPckNames         = new clsRPackageNames();

            m_pForm.blnsInstalledPcks = pPckNames.CheckedRequiredPackages(installedPackages);

            UpdateAvailiability(m_pForm.blnsInstalledPcks);
        }
Beispiel #2
0
        private void UpdateAvailiability(bool[] blnsInstalledPcks)
        {
            lvReqPacks.BeginUpdate();
            lvReqPacks.Items.Clear();

            clsRPackageNames pPckNames = new clsRPackageNames();
            int intCnt = blnsInstalledPcks.Length;

            for (int i = 0; i < intCnt; i++)
            {
                ListViewItem lvi = new ListViewItem(pPckNames.RequiredPackageNames[i]);
                lvi.SubItems.Add(blnsInstalledPcks[i].ToString());

                lvReqPacks.Items.Add(lvi);
            }
            lvReqPacks.EndUpdate();
        }
Beispiel #3
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            //Get Start up path to set a sample data path and path of temporary folder
            strPath = System.Windows.Forms.Application.StartupPath;
            axMapControl1.ActiveView.FocusMap.Name = "Layers";
            //get the MapControl
            m_mapControl = (IMapControl3)axMapControl1.Object;

            //disable the Save menu (since there is no document yet)
            menuSaveDoc.Enabled = false;

            lstRenderedLayers = new List <clsRenderedLayers>();
            m_pSnippet        = new clsSnippet();
            try
            {
                //Load sample mxd
                //string filePath = strPath + @"\Sample.mxd";
                //string filePath = strPath + @"\SampleData\Sample_plano.mxd";//For Plano
                //string filePath = strPath + @"\SampleData\Classification\Iowa_cnties.mxd";//For Iowa

                //if (axMapControl1.CheckMxFile(filePath))
                //    axMapControl1.LoadMxFile(filePath, Type.Missing, Type.Missing);
                //else
                //    MessageBox.Show("Wrong direction");

                ////Get Envelope of mxd
                //IActiveView pActiveView1 = axMapControl1.ActiveView.FocusMap as IActiveView;
                ////ILayer pLayer1 = pActiveView1.FocusMap.get_Layer(2);
                //ILayer pLayer1 = pActiveView1.FocusMap.get_Layer(0);

                ////adjust extent to fit a screen resolution
                //IFeatureLayer pFLayer1 = pLayer1 as IFeatureLayer;
                //IEnvelope envelope1 = new EnvelopeClass();
                //envelope1.PutCoords(pFLayer1.AreaOfInterest.Envelope.XMin - (pFLayer1.AreaOfInterest.Envelope.XMin * 0.0005), pFLayer1.AreaOfInterest.Envelope.YMin - (pFLayer1.AreaOfInterest.Envelope.YMin * 0.0005), pFLayer1.AreaOfInterest.Envelope.XMax * 1.0005, pFLayer1.AreaOfInterest.Envelope.YMax * 1.0005);
                //axMapControl1.ActiveView.Extent = envelope1;
                //axMapControl1.ActiveView.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error 101: " + ex.Message);
            }

            try
            {
                //R environment setting

                #region Previous Methods
                //var envPath = Environment.GetEnvironmentVariable("PATH");
                //var rBinPath = strPath + @"\R-3.1.2\bin\i386"; // R is copited into startup path
                //Environment.SetEnvironmentVariable("PATH", envPath + System.IO.Path.PathSeparator + rBinPath);
                ////Environment.SetEnvironmentVariable("PATH", rBinPath); //Not working
                //Environment.SetEnvironmentVariable("R_HOME", strPath + @"\R-3.1.2");

                ////Loading REngine
                //pEngine = REngine.CreateInstance(strREngineName);
                //pEngine.Initialize();

                ////string[] strRHOME = pEngine.Evaluate("R.home(component = 'home')").AsCharacter().ToArray(); //For Deburgging
                //LibHome = pEngine.Evaluate(".libPaths()").AsCharacter().ToArray();

                //string strLibPath = strPath.Replace(@"\", @"/") + "/R-3.1.2/library";
                ////pEngine.Evaluate(".libPaths(" + strLibPath + ")");
                ////pEngine.Evaluate(".libPaths(c(" + strLibPath + ", .Library.site, .Library))");//Same results with the above
                ////pEngine.Evaluate(".libPaths(c(" + strLibPath + "))");//Same results with the above
                //pEngine.Evaluate(".Library.site <- file.path('"+strLibPath+"')"); //Same results with the above
                //pEngine.Evaluate("Sys.setenv(R_LIBS_USER='******')");
                ////string[] tempstring1 = pEngine.Evaluate("Sys.getenv('R_LIBS_USER')").AsCharacter().ToArray();
                ////string[] tempstring = pEngine.Evaluate(".Library.site").AsCharacter().ToArray();
                //pEngine.Evaluate(".libPaths(c('" + strLibPath + "', .Library.site, .Library))");

                //LibHome = pEngine.Evaluate(".libPaths()").AsCharacter().ToArray();
                //pEngine.Evaluate("ip <- installed.packages()").AsCharacter();
                //string[] installedPackages = pEngine.Evaluate("ip[,1]").AsCharacter().ToArray(); //To Check Installed Packages in R
                //clsRPackageNames pPckNames = new clsRPackageNames();
                //blnsInstalledPcks = pPckNames.CheckedRequiredPackages(installedPackages);

                #endregion

                //Current version of R is 3.4.4 (03/19/18 HK)
                var envPath  = Environment.GetEnvironmentVariable("PATH");
                var rBinPath = strPath + @"\R-3.4.4\bin\i386"; // R is copited into startup path
                Environment.SetEnvironmentVariable("PATH", envPath + System.IO.Path.PathSeparator + rBinPath);
                Environment.SetEnvironmentVariable("R_HOME", strPath + @"\R-3.4.4");

                //Loading REngine
                pEngine = REngine.CreateInstance(strREngineName);
                pEngine.Initialize();

                //Set Library home and remove local home!
                LibHome = pEngine.Evaluate(".libPaths()").AsCharacter().ToArray();
                string strLibPath = strPath.Replace(@"\", @"/") + "/R-3.4.4/library"; //path for R packages
                pEngine.Evaluate(".Library.site <- file.path('" + strLibPath + "')");
                pEngine.Evaluate("Sys.setenv(R_LIBS_USER='******')");
                pEngine.Evaluate(".libPaths(c('" + strLibPath + "', .Library.site, .Library))");

                //Checked installed packages and R
                LibHome = pEngine.Evaluate(".libPaths()").AsCharacter().ToArray();
                pEngine.Evaluate("ip <- installed.packages()").AsCharacter();
                string[]         installedPackages = pEngine.Evaluate("ip[,1]").AsCharacter().ToArray(); //To Check Installed Packages in R
                clsRPackageNames pPckNames         = new clsRPackageNames();
                blnsInstalledPcks = pPckNames.CheckedRequiredPackages(installedPackages);



                ////Installing Additional Package
                //Currently required pacakges:: MASS, geoR, car, spdep, maptools, deldir, rgeos, e1071
                //package required for Testing: fpc
                //pEngine.Evaluate("install.packages('fpc')");
                //pEngine.Evaluate("install.packages('e1071')");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error 102:" + ex.Message);
            }

            try
            {
                //Toolbar Control, insert new tools here!!
                m_ToolbarControl = (IToolbarControl2)axToolbarControl1.Object;

                int intItemCounts = m_ToolbarControl.Count;
                m_ToolbarControl.AddItem(new toolDenPlot(), -1, intItemCounts, true, 0, esriCommandStyles.esriCommandStyleIconOnly);        //Probability density plot tool
                //m_ToolbarControl.AddItem(new toolUncernFeature(), -1, intItemCounts+1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); // Remove now 07/31/15
                m_ToolbarControl.AddItem(new ToolCumsum(), -1, intItemCounts + 1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);    // Empirical cumulative density function
                m_ToolbarControl.AddItem(new toolHistogram(), -1, intItemCounts + 2, false, 0, esriCommandStyles.esriCommandStyleIconOnly); // Histogram tool
                m_ToolbarControl.AddItem(new LinkingTool(), -1, intItemCounts + 3, true, 0, esriCommandStyles.esriCommandStyleIconOnly);    // Histogram tool
                m_ToolbarControl.AddItem(new AddFeatureClass(), -1, 1, false, 0, esriCommandStyles.esriCommandStyleIconOnly);               // Histogram tool
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error 103: " + ex.Message);
            }

            try
            {
                //Loading Context menu at TOC
                m_tocControl = axTOCControl1.Object as ITOCControl2;
                m_tocControl.SetBuddyControl(m_mapControl);
                m_menuLayer = new ToolbarMenuClass();
                m_menuLayer.AddItem(new RemoveLayer(), -1, 0, false, esriCommandStyles.esriCommandStyleTextOnly);
                m_menuLayer.AddItem(new OpenAttriTable(), -1, 1, false, esriCommandStyles.esriCommandStyleTextOnly);
                m_menuLayer.AddItem(new ZoomToLayer(), -1, 2, false, esriCommandStyles.esriCommandStyleTextOnly);
                m_menuLayer.AddItem(new ZoomToSelectedFeatures(), -1, 3, false, esriCommandStyles.esriCommandStyleTextOnly);
                m_menuLayer.AddItem(new SaveLayerFile(), -1, 4, false, esriCommandStyles.esriCommandStyleTextOnly);
                m_menuLayer.AddItem(new LayerSymbology(), -1, 5, false, esriCommandStyles.esriCommandStyleTextOnly);
                m_menuLayer.AddItem(new LayerProperty(), -1, 6, false, esriCommandStyles.esriCommandStyleTextOnly);
                //m_menuLayer.AddItem(new Symbology(), -1, 3, false, esriCommandStyles.esriCommandStyleTextOnly);
                //m_menuLayer.AddItem(new SimpleSymbology(), -1, 3, false, esriCommandStyles.esriCommandStyleTextOnly);
                m_menuLayer.SetHook(m_mapControl);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error 104:" + ex.Message);
            }
        }