Example #1
0
 private void btnSubset_Click(object sender, EventArgs e)
 {
     try
     {
         frmSubsetPoly pfrmSubsetPoly = new frmSubsetPoly();
         pfrmSubsetPoly.ShowDialog();
         m_blnSubset = pfrmSubsetPoly.m_blnSubset;
         if (m_blnSubset)
         {
             m_pClippedPolygon   = pfrmSubsetPoly.m_pMaplayer;;
             chkCumulate.Visible = true;
             chkCumulate.Text    = "Clipped by '" + m_pClippedPolygon.DataSet.Name + "'";
             chkCumulate.Checked = true;
             chkCumulate.Enabled = true;
         }
         else
         {
             chkCumulate.Visible = false;
         }
     }
     catch (Exception ex)
     {
         frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog();
         return;
     }
 }
Example #2
0
        //Creating Spatial Weight Matrix
        public int CreateSpatialWeightMatrix(REngine pEngine, IMapLayer pMapLayer, string strSWMtype, frmProgress pfrmProgress)
        {
            try
            {
                //Return 0, means fails to create spatial weight matrix, 1 means success.

                SpatialWeightMatrixType pSWMType = new SpatialWeightMatrixType();

                if (pMapLayer is MapPolygonLayer)
                {
                    if (strSWMtype == pSWMType.strPolyDefs[0])
                    {
                        pEngine.Evaluate("sample.nb <- poly2nb(sample.shp, queen=T)");
                    }
                    else if (strSWMtype == pSWMType.strPolyDefs[1])
                    {
                        pEngine.Evaluate("sample.nb <- poly2nb(sample.shp, queen=F)");
                    }
                    else
                    {
                        pEngine.Evaluate("sample.nb <- poly2nb(sample.shp, queen=T)");
                    }
                    //For dealing empty neighbors
                    try
                    {
                        pEngine.Evaluate("sample.listw <- nb2listw(sample.nb, style='W');sample.listb <- nb2listw(sample.nb, style='B')");
                    }
                    catch
                    {
                        DialogResult dialogResult = MessageBox.Show("Empty neighbor sets are founded. Do you want to continue?", "Empty neighbor", MessageBoxButtons.YesNo);


                        if (dialogResult == DialogResult.Yes)
                        {
                            pEngine.Evaluate("sample.listw <- nb2listw(sample.nb, style='W', zero.policy=TRUE);sample.listb <- nb2listw(sample.nb, style='B', zero.policy=TRUE)");
                        }
                        else if (dialogResult == DialogResult.No)
                        {
                            pfrmProgress.Close();
                            return(0);
                        }
                    }
                }
                else if (pMapLayer is MapPointLayer)
                {
                    FormCollection pFormCollection = System.Windows.Forms.Application.OpenForms;
                    bool           blnOpen         = false;
                    int            intIdx          = 0;

                    for (int j = 0; j < pFormCollection.Count; j++)
                    {
                        if (pFormCollection[j].Name == "frmSubsetPoly")//Brushing to Histogram
                        {
                            intIdx = j;

                            blnOpen = true;
                        }
                    }

                    if (blnOpen) //Delaunay with clipping
                    {
                        frmSubsetPoly pfrmSubsetPoly1 = pFormCollection[intIdx] as frmSubsetPoly;
                        if (pfrmSubsetPoly1.m_blnSubset)
                        {
                            string strPolypathR = FilePathinRfromLayer(pfrmSubsetPoly1.m_pMaplayer);

                            pEngine.Evaluate("sample.sub.shp <- readShapePoly('" + strPolypathR + "')");

                            pEngine.Evaluate("sample.nb <- del.subset(sample.shp, sample.sub.shp)");
                            bool blnError = pEngine.Evaluate("nrow(sample.shp) == length(sample.nb)").AsLogical().First();

                            if (blnError == false)
                            {
                                MessageBox.Show("The number of features in points and the rows of neighbors is not matched.", "Error");
                                return(0);
                            }
                            else
                            {
                                try
                                {
                                    pEngine.Evaluate("sample.listw <- nb2listw(sample.nb, style='W'); sample.listb <- nb2listw(sample.nb, style='B')");
                                }
                                catch
                                {
                                    DialogResult dialogResult = MessageBox.Show("Empty neighbor sets are founded. Do you want to continue?", "Empty neighbor", MessageBoxButtons.YesNo);


                                    if (dialogResult == DialogResult.Yes)
                                    {
                                        pEngine.Evaluate("sample.listw <- nb2listw(sample.nb, style='W', zero.policy=TRUE);sample.listb <- nb2listw(sample.nb, style='B', zero.policy=TRUE)");
                                    }
                                    else if (dialogResult == DialogResult.No)
                                    {
                                        pfrmProgress.Close();
                                        return(0);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        pEngine.Evaluate("sample.nb <- tri2nb(coordinates(sample.shp))");
                        //For dealing empty neighbors

                        try
                        {
                            pEngine.Evaluate("sample.listw <- nb2listw(sample.nb, style='W'); sample.listb <- nb2listw(sample.nb, style='B')");
                        }
                        catch
                        {
                            DialogResult dialogResult = MessageBox.Show("Empty neighbor sets are founded. Do you want to continue?", "Empty neighbor", MessageBoxButtons.YesNo);


                            if (dialogResult == DialogResult.Yes)
                            {
                                pEngine.Evaluate("sample.listw <- nb2listw(sample.nb, style='W', zero.policy=TRUE);sample.listb <- nb2listw(sample.nb, style='B', zero.policy=TRUE)");
                            }
                            else if (dialogResult == DialogResult.No)
                            {
                                pfrmProgress.Close();
                                return(0);
                            }
                        }
                    }
                }
                else
                {
                    int intResult = SWMusingGAL(pEngine, pMapLayer, strSWMtype);
                    if (intResult == -1)
                    {
                        pfrmProgress.Close();
                        return(0);
                    }
                }
                return(1);
            }
            catch (Exception ex)
            {
                frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog();
                return(0);
            }
        }