Exemplo n.º 1
0
        private void btnApply_Click(object sender, EventArgs e)
        {
            clsSnippet     pSnippet        = new clsSnippet();
            FormCollection pFormCollection = System.Windows.Forms.Application.OpenForms;
            frmSymbology   pfrmSymbology   = null;

            for (int j = 0; j < pFormCollection.Count; j++)
            {
                if (pFormCollection[j].Name == "frmSymbology")//Brushing to Histogram
                {
                    pfrmSymbology = pFormCollection[j] as frmSymbology;
                }
            }

            ISimpleFillSymbol pBackFillSymbol = null;

            if (pfrmSymbology != null)
            {
                pBackFillSymbol = new SimpleFillSymbolClass();
                IRgbColor pBackRGB = new RgbColorClass();
                pBackRGB = pSnippet.getRGB(picSymColor.BackColor.R, picSymColor.BackColor.G, picSymColor.BackColor.B);
                pBackFillSymbol.Color = (IColor)pBackRGB;
                ICartographicLineSymbol pBackOut = new CartographicLineSymbolClass();
                IRgbColor pBackOutRGB            = new RgbColorClass();
                pBackOutRGB                = pSnippet.getRGB(picOutColor.BackColor.R, picOutColor.BackColor.G, picOutColor.BackColor.B);
                pBackOut.Color             = (IColor)pBackOutRGB;
                pBackOut.Width             = Convert.ToDouble(nudOutWidth.Value);
                pBackFillSymbol.Outline    = pBackOut;
                pfrmSymbology.m_BackSymbol = pBackFillSymbol;
            }
            this.Close();
        }
Exemplo n.º 2
0
        void IFeatureRenderer.Draw(ESRI.ArcGIS.Geodatabase.IFeatureCursor Cursor, ESRI.ArcGIS.esriSystem.esriDrawPhase DrawPhase, IDisplay Display, ESRI.ArcGIS.esriSystem.ITrackCancel TrackCancel)
        {
            // do not draw features if no display
            if (Display == null)
            {
                return;
            }
            else
            {
                clsSnippet pSnippet = new clsSnippet();
                IFeature   pFeat    = null;

                intBrksCount = pCSMembers.ClassBrks.Length - 1;
                ISimpleFillSymbol pSFillSym = new SimpleFillSymbolClass();

                ICartographicLineSymbol pOutLines = new CartographicLineSymbol();
                pOutLines.Width = dblLineWidth;
                pOutLines.Color = (IColor)pLineRgb;

                pFeat = Cursor.NextFeature();
                IRgbColor pRGBColor = null;
                int       i         = 0;
                double    dblValue  = 0;

                //Start Loop
                while (pFeat != null)
                {
                    dblValue = Convert.ToDouble(pFeat.get_Value(intEstIdx));
                    IFeatureDraw pFeatDraw = (IFeatureDraw)pFeat;
                    pSFillSym         = new SimpleFillSymbolClass();
                    pSFillSym.Outline = pOutLines;
                    pRGBColor         = null;

                    for (int j = 0; j < intBrksCount; j++)
                    {
                        if (j == 0)
                        {
                            if (dblValue >= pCSMembers.ClassBrks[0] && dblValue <= pCSMembers.ClassBrks[1])
                            {
                                pRGBColor = pSnippet.getRGB(pCSMembers.Colors[0, 0], pCSMembers.Colors[0, 1], pCSMembers.Colors[0, 2]);
                            }
                        }
                        else
                        {
                            if (dblValue > pCSMembers.ClassBrks[j] && dblValue <= pCSMembers.ClassBrks[j + 1])
                            {
                                pRGBColor = pSnippet.getRGB(pCSMembers.Colors[j, 0], pCSMembers.Colors[j, 1], pCSMembers.Colors[j, 2]);
                            }
                        }
                    }
                    pSFillSym.Color = (IColor)pRGBColor;
                    Display.SetSymbol((ISymbol)pSFillSym);
                    pFeatDraw.Draw(esriDrawPhase.esriDPGeography, Display, (ISymbol)pSFillSym, true,
                                   null, esriDrawStyle.esriDSNormal);
                    i++;
                    pFeat = Cursor.NextFeature();
                }
            }
        }
Exemplo n.º 3
0
        private int[,] RedToBlueColorRamps()
        {
            IEnumColors pEnumColors = null;

            int[,] arrSepLineColor = new int[10, 3];
            IAlgorithmicColorRamp pColorRamp1 = new AlgorithmicColorRampClass();
            IAlgorithmicColorRamp pColorRamp2 = new AlgorithmicColorRampClass();

            pColorRamp1.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
            pColorRamp2.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;

            IRgbColor pColor1 = new RgbColor();
            IRgbColor pColor2 = new RgbColor();
            IRgbColor pColor3 = new RgbColor();



            pColor1 = pSnippet.getRGB(165, 0, 38);
            pColor2 = pSnippet.getRGB(255, 255, 191);
            pColor3 = pSnippet.getRGB(49, 54, 149);

            pColorRamp1.FromColor = pColor1;
            pColorRamp1.ToColor   = pColor2;
            pColorRamp2.FromColor = pColor2;
            pColorRamp2.ToColor   = pColor3;

            Boolean blnOK = true;

            IMultiPartColorRamp pMultiColorRamp = new MultiPartColorRampClass();

            pMultiColorRamp.Ramp[0] = pColorRamp1;
            pMultiColorRamp.Ramp[1] = pColorRamp2;
            pMultiColorRamp.Size    = 10;
            pMultiColorRamp.CreateRamp(out blnOK);


            pEnumColors = pMultiColorRamp.Colors;
            pEnumColors.Reset();
            for (int k = 0; k < 10; k++)
            {
                IColor    pColor    = pEnumColors.Next();
                IRgbColor pRGBColor = new RgbColorClass();
                pRGBColor.RGB = pColor.RGB;

                arrSepLineColor[k, 0] = pRGBColor.Red;
                arrSepLineColor[k, 1] = pRGBColor.Green;
                arrSepLineColor[k, 2] = pRGBColor.Blue;
            }

            return(arrSepLineColor);
        }
Exemplo n.º 4
0
        private void DrawLineOnActiveView(List <int> lstIndices, double[][] arrValue, IActiveView pActiveView)
        {
            try
            {
                int intLstCnt = lstIndices.Count;

                IGraphicsContainer pGraphicContainer = pActiveView.GraphicsContainer;
                pGraphicContainer.DeleteAllElements();

                IRgbColor pRgbColor = m_pSnippet.getRGB(0, 255, 255);
                //IRgbColor pRgbColor = new RgbColorClass();
                //pRgbColor.Red = 0;
                //pRgbColor.Green = 255;
                //pRgbColor.Blue = 255;
                //pRgbColor.Transparency = 255;


                ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass();
                pSimpleLineSymbol.Width = 2;
                pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
                pSimpleLineSymbol.Color = pRgbColor;



                for (int i = 0; i < intLstCnt; i++)
                {
                    int      intIdx      = lstIndices[i];
                    double[] arrSelValue = arrValue[intIdx];
                    //drawing a polyline
                    IPoint FromP = new PointClass();
                    FromP.X = arrSelValue[0]; FromP.Y = arrSelValue[1];

                    IPoint ToP = new PointClass();
                    ToP.X = arrSelValue[2]; ToP.Y = arrSelValue[3];

                    IPolyline        polyline  = new PolylineClass();
                    IPointCollection pointColl = polyline as IPointCollection;
                    pointColl.AddPoint(FromP);
                    pointColl.AddPoint(ToP);

                    IElement     pElement     = new LineElementClass();
                    ILineElement pLineElement = (ILineElement)pElement;
                    pLineElement.Symbol = pSimpleLineSymbol;
                    pElement.Geometry   = polyline;

                    pGraphicContainer.AddElement(pElement, 0);
                }

                pActiveView.Refresh();
            }
            catch (Exception ex)
            {
                frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog();
                return;
            }
        }
Exemplo n.º 5
0
        private void DrawLineOnActiveView(int intFromLinkID, List <int> arrToLinks, double[,] arrXYCoord, IActiveView pActiveView)
        {
            try
            {
                IGraphicsContainer pGraphicContainer = pActiveView.GraphicsContainer;
                //pGraphicContainer.DeleteAllElements();

                IRgbColor pRgbColor = m_pSnippet.getRGB(0, 255, 255);

                ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass();
                pSimpleLineSymbol.Width = 2;
                pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
                pSimpleLineSymbol.Color = pRgbColor;
                int intFromIdx = intFromLinkID;
                ESRI.ArcGIS.Geometry.IPoint FromP = new PointClass();
                FromP.X = arrXYCoord[intFromIdx, 0]; FromP.Y = arrXYCoord[intFromIdx, 1];

                int intArrLengthCnt = arrToLinks.Count;
                for (int i = 0; i < intArrLengthCnt; i++)
                {
                    int intToIdx = arrToLinks[i] - 1;

                    ESRI.ArcGIS.Geometry.IPoint ToP = new PointClass();
                    ToP.X = arrXYCoord[intToIdx, 0]; ToP.Y = arrXYCoord[intToIdx, 1];

                    IPolyline        polyline  = new PolylineClass();
                    IPointCollection pointColl = polyline as IPointCollection;
                    pointColl.AddPoint(FromP);
                    pointColl.AddPoint(ToP);

                    IElement     pElement     = new LineElementClass();
                    ILineElement pLineElement = (ILineElement)pElement;
                    pLineElement.Symbol = pSimpleLineSymbol;
                    pElement.Geometry   = polyline;

                    pGraphicContainer.AddElement(pElement, 0);
                }

                pActiveView.Refresh();
            }
            catch (Exception ex)
            {
                frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog();
                return;
            }
        }
Exemplo n.º 6
0
        //The function is under reviewing.
        private void DrawLineOnActiveView(double dblFromLink, double[] arrToLinks, double[,] arrXYCoord, IActiveView pActiveView)
        {
            IGraphicsContainer pGraphicContainer = pActiveView.GraphicsContainer;

            pGraphicContainer.DeleteAllElements();

            IRgbColor pRgbColor = m_pSnippet.getRGB(0, 255, 255);

            ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass();

            pSimpleLineSymbol.Width = 2;
            pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
            pSimpleLineSymbol.Color = pRgbColor;
            int    intFromIdx = Convert.ToInt32(dblFromLink) - 1;
            IPoint FromP      = new PointClass();

            FromP.X = arrXYCoord[intFromIdx, 0]; FromP.Y = arrXYCoord[intFromIdx, 1];

            int intArrLengthCnt = arrToLinks.Length;

            for (int i = 0; i < intArrLengthCnt; i++)
            {
                int intToIdx = Convert.ToInt32(arrToLinks[i]) - 1;

                IPoint ToP = new PointClass();
                ToP.X = arrXYCoord[intToIdx, 0]; ToP.Y = arrXYCoord[intToIdx, 1];

                IPolyline        polyline  = new PolylineClass();
                IPointCollection pointColl = polyline as IPointCollection;
                pointColl.AddPoint(FromP);
                pointColl.AddPoint(ToP);

                IElement     pElement     = new LineElementClass();
                ILineElement pLineElement = (ILineElement)pElement;
                pLineElement.Symbol = pSimpleLineSymbol;
                pElement.Geometry   = polyline;

                pGraphicContainer.AddElement(pElement, 0);
            }

            pActiveView.Refresh();
        }
Exemplo n.º 7
0
        private void DrawPointsOnActiveView(int colindex, int rowindex, IRasterProps pRasterProps, IActiveView ActiveView)
        {
            IGraphicsContainer pGraphicContainer = ActiveView.GraphicsContainer;

            IRgbColor pRgbColor = m_pSnippet.getRGB(0, 255, 255);

            //ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass();
            //pSimpleLineSymbol.Width = 2;
            //pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
            //pSimpleLineSymbol.Color = pRgbColor;

            ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass();

            pSimpleMarkerSymbol.Size  = 8;
            pSimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;
            pSimpleMarkerSymbol.Color = pRgbColor;

            double dblX = 0, dblY = 0;
            double dblCellSize = Convert.ToDouble(pRasterProps.MeanCellSize().X);

            dblX = pRasterProps.Extent.XMin + (dblCellSize / 2) + dblCellSize * colindex;
            dblY = pRasterProps.Extent.YMax - (dblCellSize / 2) - dblCellSize * rowindex;

            IPoint pPoint = new PointClass();

            pPoint.X = dblX;
            pPoint.Y = dblY;

            IElement pElement = new MarkerElementClass();

            IMarkerElement pMarkerElement = (IMarkerElement)pElement;

            pMarkerElement.Symbol = pSimpleMarkerSymbol;
            pElement.Geometry     = pPoint;

            pGraphicContainer.AddElement(pElement, 0);

            ActiveView.Refresh();
        }
Exemplo n.º 8
0
        //Draw Symbols by features
        public void Draw(IFeatureCursor pFCursor, esriDrawPhase DrawPhase, IDisplay Display, ITrackCancel trackCancel)
        {
            pFCursor = m_pFeatureClass.Search(m_pQueryFilter, true);
            clsSnippet pSnippet = new clsSnippet();

            IFeature pFeature = pFCursor.NextFeature();

            double dblValue    = 0;
            double dblUncern   = 0;
            double dblInterval = 0;

            IStackedChartSymbol barChartSymbol;
            IChartSymbol        chartSymbol;

            while (pFeature != null)
            {
                IFeatureDraw pFeatDraw = (IFeatureDraw)pFeature;

                dblValue  = Convert.ToDouble(pFeature.get_Value(intValueFldIdx));
                dblUncern = Convert.ToDouble(pFeature.get_Value(intUncerFldIdx));

                dblInterval = dblError * dblUncern;


                barChartSymbol = new StackedChartSymbolClass();

                barChartSymbol.Width = 10;

                if (bln3Dfeature)
                {
                    I3DChartSymbol p3DChartSymbol = barChartSymbol as I3DChartSymbol;
                    p3DChartSymbol.Display3D = true;
                    p3DChartSymbol.Thickness = 3;
                }

                //IMarkerSymbol markerSymbol = barChartSymbol as IMarkerSymbol;
                //markerSymbol.Size = 50;
                chartSymbol          = barChartSymbol as IChartSymbol;
                chartSymbol.MaxValue = dblMaxValue;


                ISymbolArray symbolArray = barChartSymbol as ISymbolArray;
                //Upper Error Symbol
                IFillSymbol fillSymbol = new SimpleFillSymbolClass();
                fillSymbol.Color         = pSnippet.getRGB(0, 0, 255);
                fillSymbol.Outline.Color = pSnippet.getRGB(0, 0, 0);
                symbolArray.AddSymbol(fillSymbol as ISymbol);
                chartSymbol.set_Value(0, dblInterval);

                //Lower Error
                fillSymbol               = new SimpleFillSymbolClass();
                fillSymbol.Color         = pSnippet.getRGB(255, 0, 0);
                fillSymbol.Outline.Color = pSnippet.getRGB(0, 0, 0);
                symbolArray.AddSymbol(fillSymbol as ISymbol);
                chartSymbol.set_Value(1, dblInterval);

                //Value -Error to represent mean value
                fillSymbol               = new SimpleFillSymbolClass();
                fillSymbol.Color         = pSnippet.getRGB(255, 255, 255);
                fillSymbol.Outline.Color = pSnippet.getRGB(0, 0, 0);
                symbolArray.AddSymbol(fillSymbol as ISymbol);
                chartSymbol.set_Value(2, dblValue - dblInterval);
                Display = m_pDisplay;
                Display.SetSymbol((ISymbol)chartSymbol);
                DrawPhase = esriDrawPhase.esriDPGeography;
                pFeatDraw.Draw(DrawPhase, Display, (ISymbol)chartSymbol, true,
                               null, esriDrawStyle.esriDSNormal);
                pFeature = pFCursor.NextFeature();
            }
        }
Exemplo n.º 9
0
        private void btnApply_Click(object sender, EventArgs e)
        {
            try
            {
                string strLayerName = cboSourceLayer.Text;
                if (cboSourceLayer.Text == "" || cboValueField.Text == "" || cboUField.Text == "")
                {
                    MessageBox.Show("Assign proper layer and field");
                    return;
                }

                int    intLIndex = pSnippet.GetIndexNumberFromLayerName(pActiveView, strLayerName);
                ILayer pLayer    = mForm.axMapControl1.get_Layer(intLIndex);

                IFeatureLayer pFLayer = pLayer as IFeatureLayer;
                IFeatureClass pFClass = pFLayer.FeatureClass;

                //Create Rendering of Mean Value at Target Layer
                int    intGCBreakeCount = Convert.ToInt32(nudGCNClasses.Value);
                string strGCRenderField = cboValueField.Text;

                IGeoFeatureLayer pGeofeatureLayer;
                if (chkNewLayer.Checked == true)
                {
                    IFeatureLayer pflOutput = new FeatureLayerClass();
                    pflOutput.FeatureClass = pFClass;
                    pflOutput.Name         = txtNewLayer.Text;
                    pflOutput.Visible      = true;

                    pGeofeatureLayer = (IGeoFeatureLayer)pflOutput;
                }
                else
                {
                    pGeofeatureLayer = (IGeoFeatureLayer)pFLayer;
                }

                ITable       pTable = (ITable)pFClass;
                IClassifyGEN pClassifyGEN;
                switch (cboGCClassify.Text)
                {
                case "Equal Interval":
                    pClassifyGEN = new EqualIntervalClass();
                    break;

                case "Geometrical Interval":
                    pClassifyGEN = new GeometricalInterval();
                    break;

                case "Natural Breaks":
                    pClassifyGEN = new NaturalBreaksClass();
                    break;

                case "Quantile":
                    pClassifyGEN = new QuantileClass();
                    break;

                case "StandardDeviation":
                    pClassifyGEN = new StandardDeviationClass();
                    break;

                default:
                    pClassifyGEN = new NaturalBreaksClass();
                    break;
                }

                //Need to be changed 1/29/15
                ITableHistogram pTableHistogram = new BasicTableHistogramClass();
                pTableHistogram.Field = strGCRenderField;
                pTableHistogram.Table = pTable;
                IBasicHistogram pHistogram = (IBasicHistogram)pTableHistogram;

                object xVals, frqs;
                pHistogram.GetHistogram(out xVals, out frqs);
                pClassifyGEN.Classify(xVals, frqs, intGCBreakeCount);

                ClassBreaksRenderer pRender = new ClassBreaksRenderer();
                double[]            cb      = (double[])pClassifyGEN.ClassBreaks;
                pRender.Field        = strGCRenderField;
                pRender.BreakCount   = intGCBreakeCount;
                pRender.MinimumBreak = cb[0];

                //' create our color ramp
                IAlgorithmicColorRamp pColorRamp = new AlgorithmicColorRampClass();
                pColorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
                IRgbColor pColor1 = new RgbColor();
                IRgbColor pColor2 = new RgbColor();

                //Can Change the color in here!
                pColor1.Red   = picSymolfrom.BackColor.R;
                pColor1.Green = picSymolfrom.BackColor.G;
                pColor1.Blue  = picSymolfrom.BackColor.B;

                Boolean blnOK = true;
                pColor2.Red          = picSymbolTo.BackColor.R;
                pColor2.Green        = picSymbolTo.BackColor.G;
                pColor2.Blue         = picSymbolTo.BackColor.B;
                pColorRamp.FromColor = pColor1;
                pColorRamp.ToColor   = pColor2;
                pColorRamp.Size      = intGCBreakeCount;
                pColorRamp.CreateRamp(out blnOK);

                IEnumColors pEnumColors = pColorRamp.Colors;
                pEnumColors.Reset();

                IRgbColor pColorOutline = new RgbColor();
                //Can Change the color in here!
                pColorOutline.Red   = picGCLineColor.BackColor.R;
                pColorOutline.Green = picGCLineColor.BackColor.G;
                pColorOutline.Blue  = picGCLineColor.BackColor.B;
                double dblGCOutlineSize = Convert.ToDouble(nudGCLinewidth.Value);

                ICartographicLineSymbol pOutLines = new CartographicLineSymbol();
                pOutLines.Width = dblGCOutlineSize;
                pOutLines.Color = (IColor)pColorOutline;

                //' use this interface to set dialog properties
                IClassBreaksUIProperties pUIProperties = (IClassBreaksUIProperties)pRender;
                pUIProperties.ColorRamp = "Custom";

                ISimpleFillSymbol pSimpleFillSym;
                //' be careful, indices are different for the diff lists
                for (int j = 0; j < intGCBreakeCount; j++)
                {
                    pRender.Break[j]          = cb[j + 1];
                    pRender.Label[j]          = Math.Round(cb[j], 2).ToString() + " - " + Math.Round(cb[j + 1], 2).ToString();
                    pUIProperties.LowBreak[j] = cb[j];
                    pSimpleFillSym            = new SimpleFillSymbolClass();
                    pSimpleFillSym.Color      = pEnumColors.Next();
                    pSimpleFillSym.Outline    = pOutLines;
                    pRender.Symbol[j]         = (ISymbol)pSimpleFillSym;
                }
                pGeofeatureLayer.Renderer = (IFeatureRenderer)pRender;
                if (chkNewLayer.Checked == true)
                {
                    mForm.axMapControl1.ActiveView.FocusMap.AddLayer(pGeofeatureLayer);
                }



                ////* Uncertainty Part *////
                //Declare variables in if parts

                if (tcUncern.SelectedIndex == 0) //Graduated Color
                {
                    int    intUncernBreakCount = Convert.ToInt32(nudCoNClasses.Value);
                    string strUncerFieldName   = cboUField.Text;

                    IFeatureLayer pflUncern = new FeatureLayerClass();
                    pflUncern.FeatureClass = pFClass;
                    pflUncern.Name         = cboSourceLayer.Text + " Uncertainty";
                    pflUncern.Visible      = true;

                    IGeoFeatureLayer pGFLUncern = (IGeoFeatureLayer)pflUncern;
                    switch (cboTeClassify.Text)
                    {
                    case "Equal Interval":
                        pClassifyGEN = new EqualIntervalClass();
                        break;

                    case "Geometrical Interval":
                        pClassifyGEN = new GeometricalInterval();
                        break;

                    case "Natural Breaks":
                        pClassifyGEN = new NaturalBreaksClass();
                        break;

                    case "Quantile":
                        pClassifyGEN = new QuantileClass();
                        break;

                    case "StandardDeviation":
                        pClassifyGEN = new StandardDeviationClass();
                        break;

                    default:
                        pClassifyGEN = new NaturalBreaksClass();
                        break;
                    }
                    //Need to be changed 1/29/15
                    pTableHistogram       = new BasicTableHistogramClass();
                    pTableHistogram.Field = strUncerFieldName;
                    pTableHistogram.Table = pTable;
                    pHistogram            = (IBasicHistogram)pTableHistogram;

                    pHistogram.GetHistogram(out xVals, out frqs);
                    pClassifyGEN.Classify(xVals, frqs, intUncernBreakCount);

                    pRender              = new ClassBreaksRenderer();
                    cb                   = (double[])pClassifyGEN.ClassBreaks;
                    pRender.Field        = strUncerFieldName;
                    pRender.BreakCount   = intUncernBreakCount;
                    pRender.MinimumBreak = cb[0];

                    IClassBreaksUIProperties pUIColProperties = (IClassBreaksUIProperties)pRender;
                    pUIColProperties.ColorRamp = "Custom";

                    pColorRamp           = new AlgorithmicColorRampClass();
                    pColorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
                    pColor1 = new RgbColor();
                    pColor2 = new RgbColor();

                    //Can Change the color in here!
                    pColor1 = pSnippet.getRGB(picCoColorFrom.BackColor.R, picCoColorFrom.BackColor.G, picCoColorFrom.BackColor.B);
                    pColor2 = pSnippet.getRGB(picCoColorTo.BackColor.R, picCoColorTo.BackColor.G, picCoColorTo.BackColor.B);
                    if (pColor1 == null || pColor2 == null)
                    {
                        return;
                    }

                    blnOK = true;
                    pColorRamp.FromColor = pColor1;
                    pColorRamp.ToColor   = pColor2;
                    pColorRamp.Size      = intUncernBreakCount;
                    pColorRamp.CreateRamp(out blnOK);

                    pEnumColors = pColorRamp.Colors;
                    pEnumColors.Reset();

                    pColorOutline = pSnippet.getRGB(picCoLineColor.BackColor.R, picCoLineColor.BackColor.G, picCoLineColor.BackColor.B);
                    if (pColorOutline == null)
                    {
                        return;
                    }

                    double dblCoOutlineSize = Convert.ToDouble(nudCoLinewidth.Value);

                    pOutLines       = new CartographicLineSymbol();
                    pOutLines.Width = dblCoOutlineSize;
                    pOutLines.Color = (IColor)pColorOutline;

                    //' use this interface to set dialog properties
                    pUIColProperties           = (IClassBreaksUIProperties)pRender;
                    pUIColProperties.ColorRamp = "Custom";

                    ISimpleMarkerSymbol pSimpleMarkerSym;
                    double dblCoSymSize = Convert.ToDouble(nudCoSymbolSize.Value);
                    //' be careful, indices are different for the diff lists
                    for (int j = 0; j < intUncernBreakCount; j++)
                    {
                        pRender.Break[j]              = cb[j + 1];
                        pRender.Label[j]              = Math.Round(cb[j], 2).ToString() + " - " + Math.Round(cb[j + 1], 2).ToString();
                        pUIColProperties.LowBreak[j]  = cb[j];
                        pSimpleMarkerSym              = new SimpleMarkerSymbolClass();
                        pSimpleMarkerSym.Size         = dblCoSymSize;
                        pSimpleMarkerSym.Color        = pEnumColors.Next();
                        pSimpleMarkerSym.Outline      = true;
                        pSimpleMarkerSym.OutlineColor = pColorOutline;
                        pSimpleMarkerSym.OutlineSize  = dblCoOutlineSize;
                        pRender.Symbol[j]             = (ISymbol)pSimpleMarkerSym;
                    }

                    pGFLUncern.Renderer = (IFeatureRenderer)pRender;
                    mForm.axMapControl1.ActiveView.FocusMap.AddLayer(pGFLUncern);
                }
                else if (tcUncern.SelectedIndex == 1) //Texture
                {
                    //Create Rendering of Uncertainty at Target Layer
                    int    intUncernBreakCount = Convert.ToInt32(nudTeNClasses.Value);
                    string strUncerFieldName   = cboUField.Text;

                    IFeatureLayer pflUncern = new FeatureLayerClass();
                    pflUncern.FeatureClass = pFClass;
                    pflUncern.Name         = cboSourceLayer.Text + " Uncertainty";
                    pflUncern.Visible      = true;

                    IGeoFeatureLayer pGFLUncern = (IGeoFeatureLayer)pflUncern;
                    switch (cboTeClassify.Text)
                    {
                    case "Equal Interval":
                        pClassifyGEN = new EqualIntervalClass();
                        break;

                    case "Geometrical Interval":
                        pClassifyGEN = new GeometricalInterval();
                        break;

                    case "Natural Breaks":
                        pClassifyGEN = new NaturalBreaksClass();
                        break;

                    case "Quantile":
                        pClassifyGEN = new QuantileClass();
                        break;

                    case "StandardDeviation":
                        pClassifyGEN = new StandardDeviationClass();
                        break;

                    default:
                        pClassifyGEN = new NaturalBreaksClass();
                        break;
                    }
                    //Need to be changed 1/29/15
                    pTableHistogram       = new BasicTableHistogramClass();
                    pTableHistogram.Field = strUncerFieldName;
                    pTableHistogram.Table = pTable;
                    pHistogram            = (IBasicHistogram)pTableHistogram;

                    pHistogram.GetHistogram(out xVals, out frqs);
                    pClassifyGEN.Classify(xVals, frqs, intUncernBreakCount);

                    pRender              = new ClassBreaksRenderer();
                    cb                   = (double[])pClassifyGEN.ClassBreaks;
                    pRender.Field        = strUncerFieldName;
                    pRender.BreakCount   = intUncernBreakCount;
                    pRender.MinimumBreak = cb[0];

                    IClassBreaksUIProperties pUITexProperties = (IClassBreaksUIProperties)pRender;
                    pUITexProperties.ColorRamp = "Custom";

                    ILineFillSymbol pLineFillSym    = new LineFillSymbolClass();
                    double          dblFromSep      = Convert.ToDouble(nudSeperationFrom.Value);
                    double          dblToSep        = Convert.ToDouble(nudSeperationTo.Value);
                    double          dblInstantSep   = (dblFromSep - dblToSep) / Convert.ToDouble(intUncernBreakCount - 1);
                    double          dblFromAngle    = Convert.ToDouble(nudAngleFrom.Value);
                    double          dblToAngle      = Convert.ToDouble(nudAngleFrom.Value); // Remove the angle part (04/16)
                    double          dblInstantAngle = (dblToAngle - dblFromAngle) / Convert.ToDouble(intUncernBreakCount - 1);
                    double          dblLinewidth    = Convert.ToDouble(nudTeLinewidth.Value);
                    IRgbColor       pLineColor      = new RgbColor();
                    pLineColor.Red   = picTeLineColor.BackColor.R;
                    pLineColor.Green = picTeLineColor.BackColor.G;
                    pLineColor.Blue  = picTeLineColor.BackColor.B;

                    //' be careful, indices are different for the diff lists
                    for (int j = 0; j < intUncernBreakCount; j++)
                    {
                        pRender.Break[j]             = cb[j + 1];
                        pRender.Label[j]             = Math.Round(cb[j], 5).ToString() + " - " + Math.Round(cb[j + 1], 5).ToString();
                        pUITexProperties.LowBreak[j] = cb[j];
                        pLineFillSym                  = new LineFillSymbolClass();
                        pLineFillSym.Angle            = dblFromAngle + (dblInstantAngle * Convert.ToDouble(j));
                        pLineFillSym.Color            = pLineColor;
                        pLineFillSym.Separation       = dblFromSep - (dblInstantSep * Convert.ToDouble(j));
                        pLineFillSym.LineSymbol.Width = dblLinewidth;
                        pRender.Symbol[j]             = (ISymbol)pLineFillSym;
                    }
                    pGFLUncern.Renderer = (IFeatureRenderer)pRender;
                    mForm.axMapControl1.ActiveView.FocusMap.AddLayer(pGFLUncern);
                }
                else if (tcUncern.SelectedIndex == 2) //For Proportional Symbols
                {
                    string strUncerFieldName = cboUField.Text;
                    double dblMinPtSize      = Convert.ToDouble(nudProSymbolSize.Value);
                    double dblLineWidth      = Convert.ToDouble(nudProLinewidth.Value);

                    IFeatureLayer pflUncern = new FeatureLayerClass();
                    pflUncern.FeatureClass = pFClass;
                    pflUncern.Name         = cboSourceLayer.Text + " Uncertainty";
                    pflUncern.Visible      = true;

                    //Find Fields
                    int intUncernIdx = pTable.FindField(strUncerFieldName);

                    //Find Min value
                    //Set to initial value for min
                    IField          pUncernField = pTable.Fields.get_Field(intUncernIdx);
                    ICursor         pCursor      = pTable.Search(null, false);
                    IDataStatistics pDataStat    = new DataStatisticsClass();
                    pDataStat.Field  = pUncernField.Name;
                    pDataStat.Cursor = pCursor;
                    IStatisticsResults pStatResults = pDataStat.Statistics;
                    double             dblMinValue  = pStatResults.Minimum;
                    double             dblMaxValue  = pStatResults.Maximum;
                    pCursor.Flush();


                    IRgbColor pSymbolRgb = pSnippet.getRGB(picProSymbolColor.BackColor.R, picProSymbolColor.BackColor.G, picProSymbolColor.BackColor.B);
                    if (pSymbolRgb == null)
                    {
                        return;
                    }

                    IRgbColor pLineRgb = pSnippet.getRGB(picProiLineColor.BackColor.R, picProiLineColor.BackColor.G, picProiLineColor.BackColor.B);
                    if (pLineRgb == null)
                    {
                        return;
                    }

                    ISimpleMarkerSymbol pSMarkerSym = new SimpleMarkerSymbolClass();
                    pSMarkerSym.Style        = esriSimpleMarkerStyle.esriSMSCircle;
                    pSMarkerSym.Size         = dblMinPtSize;
                    pSMarkerSym.OutlineSize  = dblLineWidth;
                    pSMarkerSym.Outline      = true;
                    pSMarkerSym.OutlineColor = (IColor)pLineRgb;
                    pSMarkerSym.Color        = (IColor)pSymbolRgb;

                    IGeoFeatureLayer            pGFLUncern    = (IGeoFeatureLayer)pflUncern;
                    IProportionalSymbolRenderer pUncernRender = new ProportionalSymbolRendererClass();
                    pUncernRender.LegendSymbolCount = 2; //Need to be changed 0219
                    pUncernRender.Field             = strUncerFieldName;
                    pUncernRender.MaxDataValue      = dblMaxValue;
                    pUncernRender.MinDataValue      = dblMinValue;
                    pUncernRender.MinSymbol         = (ISymbol)pSMarkerSym;
                    pUncernRender.ValueUnit         = esriUnits.esriUnknownUnits;
                    pUncernRender.BackgroundSymbol  = null;
                    pUncernRender.CreateLegendSymbols();

                    pGFLUncern.Renderer = (IFeatureRenderer)pUncernRender;
                    mForm.axMapControl1.ActiveView.FocusMap.AddLayer(pGFLUncern);
                }
                else if (tcUncern.SelectedIndex == 3) // Bar
                {
                    string strUncerFieldName = cboUField.Text;
                    double dblMaxLength      = Convert.ToDouble(nudMaxBarHeight.Value);
                    double dblBarWidth       = Convert.ToDouble(nudBarWidth.Value);

                    IFeatureLayer pflUncern = new FeatureLayerClass();
                    pflUncern.FeatureClass = pFClass;
                    pflUncern.Name         = cboSourceLayer.Text + " Uncertainty";
                    pflUncern.Visible      = true;

                    int             intUncernIdx = pTable.FindField(strUncerFieldName);
                    IField          pUncernField = pTable.Fields.get_Field(intUncernIdx);
                    ICursor         pCursor      = pTable.Search(null, false);
                    IDataStatistics pDataStat    = new DataStatisticsClass();
                    pDataStat.Field  = pUncernField.Name;
                    pDataStat.Cursor = pCursor;
                    IStatisticsResults pStatResults = pDataStat.Statistics;
                    double             dblMaxValue  = pStatResults.Maximum;
                    pCursor.Flush();


                    IChartRenderer  chartRenderer  = new ChartRendererClass();
                    IRendererFields rendererFields = chartRenderer as IRendererFields;
                    rendererFields.AddField(strUncerFieldName);

                    IBarChartSymbol barChartSymbol = new BarChartSymbolClass();
                    barChartSymbol.Width = dblBarWidth;
                    IMarkerSymbol markerSymbol = barChartSymbol as IMarkerSymbol;
                    markerSymbol.Size = dblMaxLength;
                    IChartSymbol chartSymbol = barChartSymbol as IChartSymbol;
                    chartSymbol.MaxValue = dblMaxValue;
                    ISymbolArray symbolArray = barChartSymbol as ISymbolArray;
                    IFillSymbol  fillSymbol  = new SimpleFillSymbolClass();
                    fillSymbol.Color = pSnippet.getRGB(picBarSymCol.BackColor.R, picBarSymCol.BackColor.G, picBarSymCol.BackColor.B);
                    if (fillSymbol.Color == null)
                    {
                        return;
                    }
                    symbolArray.AddSymbol(fillSymbol as ISymbol);

                    if (chk3D.Checked)
                    {
                        I3DChartSymbol p3DChartSymbol = barChartSymbol as I3DChartSymbol;
                        p3DChartSymbol.Display3D = true;
                        p3DChartSymbol.Thickness = 3;
                    }
                    chartRenderer.ChartSymbol = barChartSymbol as IChartSymbol;
                    SimpleFillSymbol pBaseFillSym = new SimpleFillSymbolClass();
                    //pBaseFillSym.Color = pSnippet.getRGB(picBarSymCol.BackColor.R, picBarSymCol.BackColor.G, picBarSymCol.BackColor.B);
                    //chartRenderer.BaseSymbol = pBaseFillSym as ISymbol;
                    chartRenderer.UseOverposter = false;
                    chartRenderer.CreateLegend();
                    IGeoFeatureLayer pGFLUncern = (IGeoFeatureLayer)pflUncern;
                    pGFLUncern.Renderer = (IFeatureRenderer)chartRenderer;
                    mForm.axMapControl1.ActiveView.FocusMap.AddLayer(pGFLUncern);
                }
                #region illumination
                //This function is not applied in this version. 032317 HK
                //}
                //    else if (tcUncern.SelectedIndex == 4) //illumination
                //    {
                //        frmProgress pfrmProgress = new frmProgress();
                //        pfrmProgress.lblStatus.Text = "Processing:";
                //        pfrmProgress.pgbProgress.Style = ProgressBarStyle.Marquee;
                //        pfrmProgress.Show();

                //        string strUncerFieldName = cboUField.Text;

                //        IGeoDataset geoDataset_output = createRasterfromPolygon(pFClass, strUncerFieldName, pFLayer, 100);

                //        double altitude = Convert.ToDouble(nudAltitude.Value);
                //        double azimuth = Convert.ToDouble(nudAzimuth.Value);
                //        object zFactor = Convert.ToDouble(nudZFactor.Value);


                //        ISurfaceOp2 pSurfOP = new RasterSurfaceOpClass();
                //        IRaster pOutputDS = (IRaster)pSurfOP.HillShade(geoDataset_output, azimuth, altitude, true, ref zFactor);

                //        ((IDataset)geoDataset_output).Delete();
                //        // Create a raster for viewing
                //        ESRI.ArcGIS.Carto.IRasterLayer rasterLayer = new ESRI.ArcGIS.Carto.RasterLayerClass();
                //        rasterLayer.CreateFromRaster(pOutputDS);

                //        //Calculate hillshade value at slope 0 to set as background value
                //        double dblRadian = (Math.PI / 180) * (90 - altitude);
                //        double dblBackValue = Math.Truncate(255 * Math.Cos(dblRadian));

                //        IRasterStretch pRasterStretch = new RasterStretchColorRampRendererClass();
                //        IColor pColor = new RgbColorClass();
                //        pColor.NullColor = true;
                //        pColor.Transparency = 0;
                //        pRasterStretch.Background = true;
                //        pRasterStretch.BackgroundColor = pColor;
                //        pRasterStretch.set_BackgroundValues(ref dblBackValue);

                //        rasterLayer.Name = "Uncertainty of " + strGCRenderField;
                //        rasterLayer.Renderer = pRasterStretch as IRasterRenderer;
                //        rasterLayer.Renderer.Update();

                //        //Apply Transparency
                //        ILayerEffects pLayerEffect = (ILayerEffects)rasterLayer;
                //        pLayerEffect.Transparency = Convert.ToInt16(nudTransparent.Value);

                //        pfrmProgress.Close();
                //        // Add the raster to the map
                //        pActiveView.FocusMap.AddLayer(rasterLayer);

                //    }

                //    mForm.axMapControl1.ActiveView.Refresh();
                //    mForm.axTOCControl1.Update();
                #endregion
            }
            catch (Exception ex)
            {
                frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog();
                return;
            }
        }
Exemplo n.º 10
0
        private IEnumColors MultiPartColorRamp(string strColorRamp, int intGCBreakeCount)
        {
            IAlgorithmicColorRamp pColorRamp1 = new AlgorithmicColorRampClass();

            pColorRamp1.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
            IAlgorithmicColorRamp pColorRamp2 = new AlgorithmicColorRampClass();

            pColorRamp2.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;

            IRgbColor pColor1 = new RgbColor();
            IRgbColor pColor2 = new RgbColor();
            IRgbColor pColor3 = new RgbColor();

            switch (strColorRamp)
            {
            case "Blue to Red":
                pColor1 = pSnippet.getRGB(49, 54, 149);
                pColor2 = pSnippet.getRGB(255, 255, 191);
                pColor3 = pSnippet.getRGB(165, 0, 38);
                break;

            case "Green to Purple":
                pColor1 = pSnippet.getRGB(0, 68, 27);
                pColor2 = pSnippet.getRGB(247, 247, 247);
                pColor3 = pSnippet.getRGB(64, 0, 75);
                break;

            case "Green to Red":
                pColor1 = pSnippet.getRGB(0, 104, 55);
                pColor2 = pSnippet.getRGB(255, 255, 191);
                pColor3 = pSnippet.getRGB(165, 0, 38);
                break;

            case "Purple to Brown":
                pColor1 = pSnippet.getRGB(45, 0, 75);
                pColor2 = pSnippet.getRGB(247, 247, 247);
                pColor3 = pSnippet.getRGB(127, 59, 8);
                break;

            default:
                pColor1 = pSnippet.getRGB(49, 54, 149);
                pColor2 = pSnippet.getRGB(255, 255, 191);
                pColor3 = pSnippet.getRGB(165, 0, 38);
                break;
            }


            pColorRamp1.FromColor = pColor1;
            pColorRamp1.ToColor   = pColor2;
            pColorRamp2.FromColor = pColor2;
            pColorRamp2.ToColor   = pColor3;

            Boolean blnOK = true;

            IMultiPartColorRamp pMultiColorRamp = new MultiPartColorRampClass();

            pMultiColorRamp.Ramp[0] = pColorRamp1;
            pMultiColorRamp.Ramp[1] = pColorRamp2;
            pMultiColorRamp.Size    = intGCBreakeCount;
            pMultiColorRamp.CreateRamp(out blnOK);


            IEnumColors pEnumColors = pMultiColorRamp.Colors;

            return(pEnumColors);
        }
Exemplo n.º 11
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            if (cboFldnm1.Text == "" || cboFldnm2.Text == "")
            {
                MessageBox.Show("Please select target field");
                return;
            }

            frmProgress pfrmProgress = new frmProgress();

            pfrmProgress.lblStatus.Text    = "Processing:";
            pfrmProgress.pgbProgress.Style = ProgressBarStyle.Marquee;
            pfrmProgress.Show();

            REngine pEngine = m_pForm.pEngine;
            // Creates the input and output matrices from the shapefile//
            string strLayerName = cboTargetLayer.Text;

            int    intLIndex = m_pSnippet.GetIndexNumberFromLayerName(m_pActiveView, strLayerName);
            ILayer pLayer    = m_pForm.axMapControl1.get_Layer(intLIndex);

            IFeatureLayer pFLayer  = pLayer as IFeatureLayer;
            IFeatureClass pFClass  = pFLayer.FeatureClass;
            int           nFeature = pFClass.FeatureCount(null);

            IFeatureCursor pFCursor = pFLayer.Search(null, true);
            IFeature       pFeature = pFCursor.NextFeature();

            //Get index for independent and dependent variables
            //Get variable index
            string strVarNM1  = (string)cboFldnm1.SelectedItem;
            string strVarNM2  = (string)cboFldnm2.SelectedItem;
            int    intVarIdx1 = pFClass.FindField(strVarNM1);
            int    intVarIdx2 = pFClass.FindField(strVarNM2);

            //Store Variable at Array
            double[] arrVar1 = new double[nFeature];
            double[] arrVar2 = new double[nFeature];

            int i = 0;

            while (pFeature != null)
            {
                arrVar1[i] = Convert.ToDouble(pFeature.get_Value(intVarIdx1));
                arrVar2[i] = Convert.ToDouble(pFeature.get_Value(intVarIdx2));
                i++;
                pFeature = pFCursor.NextFeature();
            }

            pFCursor.Flush();

            //Plot command for R
            StringBuilder plotCommmand = new StringBuilder();

            string strStartPath = m_pForm.strPath;
            string pathr        = strStartPath.Replace(@"\", @"/");

            pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_LARRY.R')");
            pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_neighbor.R')");
            pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_SASbi.R')");

            //Get the file path and name to create spatial weight matrix
            string strNameR = m_pSnippet.FilePathinRfromLayer(pFLayer);

            if (strNameR == null)
            {
                return;
            }

            //Create spatial weight matrix in R
            pEngine.Evaluate("library(spdep); library(maptools)");
            pEngine.Evaluate("sample.shp <- readShapePoly('" + strNameR + "')");
            pEngine.Evaluate("sample.nb <- poly2nb(sample.shp)");

            NumericVector vecVar1 = pEngine.CreateNumericVector(arrVar1);

            pEngine.SetSymbol("sample.v1", vecVar1);
            NumericVector vecVar2 = pEngine.CreateNumericVector(arrVar2);

            pEngine.SetSymbol("sample.v2", vecVar2);

            string strSigLv   = nudSigLv.Value.ToString();
            string strLSig    = cboLocalL.Text;
            string strRsig    = cboLocalPearson.Text;
            string strRowStd  = cboRowStandardization.Text;
            string strNonZero = null;

            if (chkDiagZero.Checked)
            {
                strNonZero = "FALSE";
            }
            else
            {
                strNonZero = "TRUE";
            }

            pEngine.Evaluate("sample.result <- LARRY.bivariate.spatial.cluster(sample.v1, sample.v2, 1:length(sample.nb), sample.nb, global.sig = " +
                             strSigLv + ", method = '" + strLSig + "', type.row.stand = '" + strRowStd + "', alternative = 'two', diag.zero = " + strNonZero + ")");

            string[] strGlobal = pEngine.Evaluate("as.character(sample.result[[1]]$sig.global)").AsCharacter().ToArray();
            string[] strFDR    = pEngine.Evaluate("as.character(sample.result[[1]]$sig.FDR)").AsCharacter().ToArray();
            string[] strSpBonf = pEngine.Evaluate("as.character(sample.result[[1]]$sig.spBonf)").AsCharacter().ToArray();
            string[] strBonf   = pEngine.Evaluate("as.character(sample.result[[1]]$sig.genBonf)").AsCharacter().ToArray();
            string[] strQuad   = pEngine.Evaluate("as.character(sample.result[[1]]$final.quad)").AsCharacter().ToArray();

            string[] strSigLevels = pEngine.Evaluate("as.character(round(sample.result[[2]],6))").AsCharacter().ToArray();
            //Save Output on SHP
            //Add Target fields to store results in the shapefile
            for (int j = 0; j < 5; j++)
            {
                string strfldName = lvFields.Items[j].SubItems[1].Text;
                if (pFClass.FindField(strfldName) == -1)
                {
                    IField     newField  = new FieldClass();
                    IFieldEdit fieldEdit = (IFieldEdit)newField;
                    fieldEdit.Name_2 = strfldName;
                    fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                    pFClass.AddField(newField);

                    //MessageBox.Show("Same field name exists.", "Same field name", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    //pfrmProgress.Close();
                    //return;
                }
            }

            //Update Field
            pFCursor = pFClass.Update(null, false);
            pFeature = pFCursor.NextFeature();

            string strFinalQuadFldName  = lvFields.Items[4].SubItems[1].Text;
            int    intGlobalFldIdx      = pFClass.FindField(lvFields.Items[0].SubItems[1].Text);
            int    intFDRFldIdx         = pFClass.FindField(lvFields.Items[1].SubItems[1].Text);
            int    intSpatialBonfFldIdx = pFClass.FindField(lvFields.Items[2].SubItems[1].Text);
            int    intGenBonfFldIdx     = pFClass.FindField(lvFields.Items[3].SubItems[1].Text);
            int    intFinalQuadFldIdx   = pFClass.FindField(strFinalQuadFldName);

            int featureIdx = 0;

            while (pFeature != null)
            {
                pFeature.set_Value(intGlobalFldIdx, strGlobal[featureIdx]);
                pFeature.set_Value(intFDRFldIdx, strFDR[featureIdx]);
                pFeature.set_Value(intSpatialBonfFldIdx, strSpBonf[featureIdx]);
                pFeature.set_Value(intGenBonfFldIdx, strBonf[featureIdx]);
                pFeature.set_Value(intFinalQuadFldIdx, strQuad[featureIdx]);

                pFCursor.UpdateFeature(pFeature);

                pFeature = pFCursor.NextFeature();
                featureIdx++;
            }
            pFCursor.Flush();

            if (chkMap.Checked)
            {
                double[,] adblMinMaxForLabel = new double[2, 4];
                ITable pTable = (ITable)pFClass;

                IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass();
                pUniqueValueRenderer.FieldCount = 1;
                pUniqueValueRenderer.set_Field(0, strFinalQuadFldName);
                ISimpleFillSymbol pSymbol;
                IQueryFilter      pQFilter = new QueryFilterClass();
                int    intTotalCount       = 0;
                string strHeading          = null;
                int    intSigIdx           = 0;

                for (int j = 0; j < 16; j++)
                {
                    pSymbol       = new SimpleFillSymbolClass();
                    pSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
                    pSymbol.Color = m_pSnippet.getRGB(m_pClusterSymbols[j].R, m_pClusterSymbols[j].G, m_pClusterSymbols[j].B);


                    if (j % 4 == 0)
                    {
                        intTotalCount = 0;
                        for (int k = 0; k < 4; k++)
                        {
                            pQFilter.WhereClause = strFinalQuadFldName + " = '" + m_pClusterSymbols[j + k].Value + "'";
                            int intCnt = pTable.RowCount(pQFilter);
                            intTotalCount += intCnt;
                        }

                        intSigIdx = 3;

                        strHeading = m_pClusterSymbols[j].Heading + " (" + intTotalCount.ToString() + ")";
                        pUniqueValueRenderer.AddValue(m_pClusterSymbols[j].Value, strHeading, (ISymbol)pSymbol);
                        pUniqueValueRenderer.set_Label(m_pClusterSymbols[j].Value, m_pClusterSymbols[j].Label + "(" + strSigLevels[intSigIdx] + ")");
                    }
                    else
                    {
                        intSigIdx--;
                        pUniqueValueRenderer.AddValue(m_pClusterSymbols[j].Value, strHeading, (ISymbol)pSymbol);
                        pUniqueValueRenderer.set_Label(m_pClusterSymbols[j].Value, m_pClusterSymbols[j].Label + "(" + strSigLevels[intSigIdx] + ")");
                    }
                }

                string strNotSig = "not sig.";
                pSymbol       = new SimpleFillSymbolClass();
                pSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
                pSymbol.Color = m_pSnippet.getRGB(255, 255, 255);

                pQFilter.WhereClause = strFinalQuadFldName + " = '" + strNotSig + "'";
                intTotalCount        = pTable.RowCount(pQFilter);

                pUniqueValueRenderer.AddValue(strNotSig, null, (ISymbol)pSymbol);
                pUniqueValueRenderer.set_Label(strNotSig, "Not significant (" + intTotalCount.ToString() + ")");

                pUniqueValueRenderer.UseDefaultSymbol = false;

                IFeatureLayer pNewFLayer = new FeatureLayerClass();
                pNewFLayer.FeatureClass = pFClass;
                pNewFLayer.Name         = "Bivariate Spatial Clusters";
                IGeoFeatureLayer pGFLayer = (IGeoFeatureLayer)pNewFLayer;
                pGFLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer;
                m_pActiveView.FocusMap.AddLayer(pGFLayer);
                m_pActiveView.Refresh();
                m_pForm.axTOCControl1.Update();
                pfrmProgress.Close();
            }
            else
            {
                MessageBox.Show("Complete. The results are stored in the shape file");
            }
        }
Exemplo n.º 12
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            if (cboFldnm1.Text == "" || cboFldnm2.Text == "")
            {
                MessageBox.Show("Please select target field");
                return;
            }

            frmProgress pfrmProgress = new frmProgress();

            pfrmProgress.lblStatus.Text    = "Processing:";
            pfrmProgress.pgbProgress.Style = ProgressBarStyle.Marquee;
            pfrmProgress.Show();

            REngine pEngine = m_pForm.pEngine;

            int nFeature = m_pFClass.FeatureCount(null);

            IFeatureCursor pFCursor = m_pFClass.Search(null, true);
            IFeature       pFeature = pFCursor.NextFeature();

            //Get index for independent and dependent variables
            //Get variable index
            string strVarNM1  = (string)cboFldnm1.SelectedItem;
            string strVarNM2  = (string)cboFldnm2.SelectedItem;
            int    intVarIdx1 = m_pFClass.FindField(strVarNM1);
            int    intVarIdx2 = m_pFClass.FindField(strVarNM2);
            int    intFIDIdx  = m_pFClass.FindField(m_pFClass.OIDFieldName);

            //Store Variable at Array
            double[] arrVar1 = new double[nFeature];
            double[] arrVar2 = new double[nFeature];

            int[] arrFID = new int[nFeature];

            int i = 0;

            while (pFeature != null)
            {
                arrVar1[i] = Convert.ToDouble(pFeature.get_Value(intVarIdx1));
                arrVar2[i] = Convert.ToDouble(pFeature.get_Value(intVarIdx2));
                arrFID[i]  = Convert.ToInt32(pFeature.get_Value(intFIDIdx));
                i++;
                pFeature = pFCursor.NextFeature();
            }

            pFCursor.Flush();

            //Plot command for R
            StringBuilder plotCommmand = new StringBuilder();

            string strStartPath = m_pForm.strPath;
            string pathr        = strStartPath.Replace(@"\", @"/");

            pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_LARRY.R')");
            pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_neighbor.R')");
            pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_SASbi.R')");

            //Get the file path and name to create spatial weight matrix
            string strNameR = m_pSnippet.FilePathinRfromLayer(m_pFLayer);

            if (strNameR == null)
            {
                return;
            }

            //Create spatial weight matrix in R
            pEngine.Evaluate("library(spdep); library(maptools)");
            pEngine.Evaluate("sample.shp <- readShapePoly('" + strNameR + "')");
            //pEngine.Evaluate("sample.nb <- poly2nb(sample.shp, queen=FALSE)");
            pEngine.Evaluate("sample.nb <- poly2nb(sample.shp)");

            NumericVector vecVar1 = pEngine.CreateNumericVector(arrVar1);

            pEngine.SetSymbol("sample.v1", vecVar1);
            NumericVector vecVar2 = pEngine.CreateNumericVector(arrVar2);

            pEngine.SetSymbol("sample.v2", vecVar2);

            string strNonZero = null;

            if (chkDiagZero.Checked)
            {
                strNonZero = "FALSE";
            }
            else
            {
                strNonZero = "TRUE";
            }

            string[] strSPQuadrants = null;

            double[]      adblVar1 = null;
            double[]      adblVar2 = null;
            NumericVector vecCoeff = null;

            if (cboMeasure.Text == "Lee's L")
            {
                pEngine.Evaluate("sample.result <- LARRY.bivariate.quadrant.lee(sample.v1, sample.v2, 1:length(sample.nb), sample.nb, style = 'W', diag.zero = " + strNonZero + ")");
                strSPQuadrants = pEngine.Evaluate("as.character(sample.result$quad)").AsCharacter().ToArray();
                if (chkScatterplot.Checked)
                {
                    adblVar1 = pEngine.Evaluate("as.numeric(sample.result$v.z.x)").AsNumeric().ToArray();
                    adblVar2 = pEngine.Evaluate("as.numeric(sample.result$v.z.y)").AsNumeric().ToArray();
                    vecCoeff = pEngine.Evaluate("lm(sample.result$v.z.y~sample.result$v.z.x)$coefficients").AsNumeric();
                }
            }
            else if (cboMeasure.Text == "Local Pearson")
            {
                pEngine.Evaluate("sample.result <- LARRY.bivariate.quadrant.pearson(sample.v1, sample.v2, 1:length(sample.nb))");
                strSPQuadrants = pEngine.Evaluate("as.character(sample.result$quad)").AsCharacter().ToArray();
                if (chkScatterplot.Checked)
                {
                    adblVar1 = pEngine.Evaluate("as.numeric(sample.result$z.x)").AsNumeric().ToArray();
                    adblVar2 = pEngine.Evaluate("as.numeric(sample.result$z.y)").AsNumeric().ToArray();
                    vecCoeff = pEngine.Evaluate("lm(sample.result$z.y~sample.result$z.x)$coefficients").AsNumeric();
                }
            }

            //Save Output on SHP
            //Add Target fields to store results in the shapefile // Keep loop
            for (int j = 0; j < 1; j++)
            {
                string strfldName = lvFields.Items[j].SubItems[1].Text;
                if (m_pFClass.FindField(strfldName) == -1)
                {
                    IField     newField  = new FieldClass();
                    IFieldEdit fieldEdit = (IFieldEdit)newField;
                    fieldEdit.Name_2 = strfldName;
                    fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                    m_pFClass.AddField(newField);
                }
            }

            //Update Field
            pFCursor = m_pFClass.Update(null, false);
            pFeature = pFCursor.NextFeature();

            string strSpQuadFldName = lvFields.Items[0].SubItems[1].Text;
            int    intSpQuadFldIdx  = m_pFClass.FindField(strSpQuadFldName);

            int featureIdx = 0;

            while (pFeature != null)
            {
                pFeature.set_Value(intSpQuadFldIdx, strSPQuadrants[featureIdx]);

                pFCursor.UpdateFeature(pFeature);

                pFeature = pFCursor.NextFeature();
                featureIdx++;
            }
            pFCursor.Flush();

            if (chkMap.Checked)
            {
                ITable pTable = (ITable)m_pFClass;

                IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass();
                pUniqueValueRenderer.FieldCount = 1;
                pUniqueValueRenderer.set_Field(0, strSpQuadFldName);

                if (cboMaptype.Text == "choropleth map")
                {
                    ISimpleFillSymbol pSymbol;
                    IQueryFilter      pQFilter = new QueryFilterClass();
                    int    intTotalCount       = 0;
                    string strLabel            = null;

                    for (int j = 0; j < 4; j++)
                    {
                        pSymbol       = new SimpleFillSymbolClass();
                        pSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
                        pSymbol.Color = m_pSnippet.getRGB(m_pQuadrantSymbols[j].R, m_pQuadrantSymbols[j].G, m_pQuadrantSymbols[j].B);

                        pQFilter.WhereClause = strSpQuadFldName + " = '" + m_pQuadrantSymbols[j].Value + "'";

                        intTotalCount = pTable.RowCount(pQFilter);

                        strLabel = m_pQuadrantSymbols[j].Label + " (" + intTotalCount.ToString() + ")";
                        pUniqueValueRenderer.AddValue(m_pQuadrantSymbols[j].Value, null, (ISymbol)pSymbol);
                        pUniqueValueRenderer.set_Label(m_pQuadrantSymbols[j].Value, strLabel);
                    }
                    pUniqueValueRenderer.UseDefaultSymbol = false;
                }
                else if (cboMaptype.Text == "point map")
                {
                    ICharacterMarkerSymbol pSymbol;
                    stdole.IFontDisp       stdFontCls = ((stdole.IFontDisp)(new stdole.StdFont()));
                    stdFontCls.Name = "ESRI NIMA VMAP1&2 PT";
                    stdFontCls.Size = 10;

                    IQueryFilter pQFilter      = new QueryFilterClass();
                    int          intTotalCount = 0;
                    string       strLabel      = null;

                    for (int j = 0; j < 4; j++)
                    {
                        pSymbol = new CharacterMarkerSymbolClass();
                        pSymbol.CharacterIndex = 248;
                        //pSymbol.Color = m_pSnippet.getRGB(m_pQuadrantSymbols[j].R, m_pQuadrantSymbols[j].G, m_pQuadrantSymbols[j].B);
                        pSymbol.Size = 10;
                        pSymbol.Font = stdFontCls;

                        pSymbol.Angle = m_pQuadrantSymbols[j].Angle;

                        //Create a Fill Symbol for the Mask
                        ISimpleFillSymbol smpFill = new SimpleFillSymbol();
                        smpFill.Color = m_pSnippet.getRGB(0, 0, 0);
                        smpFill.Style = esriSimpleFillStyle.esriSFSSolid;
                        //Create a MultiLayerMarkerSymbol
                        IMultiLayerMarkerSymbol multiLyrMrk = new MultiLayerMarkerSymbol();
                        //Add the simple marker to the MultiLayer
                        multiLyrMrk.AddLayer(pSymbol);
                        //Create a Mask for the MultiLayerMarkerSymbol
                        IMask mrkMask = (IMask)multiLyrMrk;
                        mrkMask.MaskSymbol = smpFill;
                        mrkMask.MaskStyle  = esriMaskStyle.esriMSHalo;
                        mrkMask.MaskSize   = 0.5;

                        pQFilter.WhereClause = strSpQuadFldName + " = '" + m_pQuadrantSymbols[j].Value + "'";

                        intTotalCount = pTable.RowCount(pQFilter);

                        strLabel = m_pQuadrantSymbols[j].Label + " (" + intTotalCount.ToString() + ")";
                        pUniqueValueRenderer.AddValue(m_pQuadrantSymbols[j].Value, null, (ISymbol)multiLyrMrk);
                        pUniqueValueRenderer.set_Label(m_pQuadrantSymbols[j].Value, strLabel);
                    }
                    pUniqueValueRenderer.UseDefaultSymbol = false;
                }
                IFeatureLayer pNewFLayer = new FeatureLayerClass();
                pNewFLayer.FeatureClass = m_pFClass;
                pNewFLayer.Name         = "Bivariate Spatial Quadrants";
                IGeoFeatureLayer pGFLayer = (IGeoFeatureLayer)pNewFLayer;
                pGFLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer;
                m_pActiveView.FocusMap.AddLayer(pGFLayer);
                m_pActiveView.Refresh();
                m_pForm.axTOCControl1.Update();
            }

            if (chkScatterplot.Checked)
            {
                frmMScatterResults pfrmMScatterResult = new frmMScatterResults();
                pfrmMScatterResult.pChart.ChartAreas[0].AxisX.IsStartedFromZero = false;
                pfrmMScatterResult.pChart.ChartAreas[0].AxisX.IsMarginVisible   = true;

                pfrmMScatterResult.pChart.ChartAreas[0].AxisY.IsStartedFromZero = false;

                pfrmMScatterResult.Text = cboMeasure.Text + " Scatter Plot of " + m_pFLayer.Name;
                pfrmMScatterResult.pChart.Series.Clear();
                System.Drawing.Color pMarkerColor = System.Drawing.Color.Blue;
                var seriesPts = new System.Windows.Forms.DataVisualization.Charting.Series
                {
                    Name              = "Points",
                    Color             = pMarkerColor,
                    BorderColor       = pMarkerColor,
                    IsVisibleInLegend = false,
                    IsXValueIndexed   = false,
                    ChartType         = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point,
                    MarkerStyle       = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle
                };

                pfrmMScatterResult.pChart.Series.Add(seriesPts);

                for (int j = 0; j < adblVar1.Length; j++)
                {
                    seriesPts.Points.AddXY(adblVar1[j], adblVar2[j]);
                }

                var VLine = new System.Windows.Forms.DataVisualization.Charting.Series
                {
                    Name            = "VLine",
                    Color           = System.Drawing.Color.Black,
                    BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash,
                    //BorderColor = System.Drawing.Color.Black,
                    IsVisibleInLegend = false,
                    IsXValueIndexed   = false,
                    ChartType         = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line
                };
                pfrmMScatterResult.pChart.Series.Add(VLine);

                VLine.Points.AddXY(adblVar1.Average(), adblVar2.Min());
                VLine.Points.AddXY(adblVar1.Average(), adblVar2.Max());

                var HLine = new System.Windows.Forms.DataVisualization.Charting.Series
                {
                    Name            = "HLine",
                    Color           = System.Drawing.Color.Black,
                    BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash,
                    //BorderColor = System.Drawing.Color.Black,
                    IsVisibleInLegend = false,
                    IsXValueIndexed   = false,
                    ChartType         = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line
                };
                pfrmMScatterResult.pChart.Series.Add(HLine);

                HLine.Points.AddXY(adblVar1.Min(), adblVar2.Average());
                HLine.Points.AddXY(adblVar1.Max(), adblVar2.Average());

                var seriesLine = new System.Windows.Forms.DataVisualization.Charting.Series
                {
                    Name  = "RegLine",
                    Color = System.Drawing.Color.Red,
                    //BorderColor = System.Drawing.Color.Black,
                    IsVisibleInLegend = false,
                    IsXValueIndexed   = false,
                    ChartType         = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line
                };

                pfrmMScatterResult.pChart.Series.Add(seriesLine);

                seriesLine.Points.AddXY(adblVar1.Min(), adblVar1.Min() * vecCoeff[1] + vecCoeff[0]);
                seriesLine.Points.AddXY(adblVar1.Max(), adblVar1.Max() * vecCoeff[1] + vecCoeff[0]);

                if (cboMeasure.Text == "Local Pearson")
                {
                    pfrmMScatterResult.pChart.ChartAreas[0].AxisX.Title = "z-transformed " + cboFldnm1.Text;
                    pfrmMScatterResult.pChart.ChartAreas[0].AxisY.Title = "z-transformed " + cboFldnm2.Text;
                    pfrmMScatterResult.lblRegression.Text = string.Empty;
                }
                else
                {
                    pfrmMScatterResult.pChart.ChartAreas[0].AxisX.Title = "z-transformed SMA of " + cboFldnm1.Text;
                    pfrmMScatterResult.pChart.ChartAreas[0].AxisY.Title = "z-transformed SMA of " + cboFldnm2.Text;
                    pfrmMScatterResult.lblRegression.Text = string.Empty;
                }

                pfrmMScatterResult.m_pForm       = m_pForm;
                pfrmMScatterResult.m_pFLayer     = m_pFLayer;
                pfrmMScatterResult.m_pActiveView = m_pActiveView;
                pfrmMScatterResult.arrVar        = adblVar1;
                pfrmMScatterResult.arrFID        = arrFID;
                pfrmMScatterResult.strFIDNM      = m_pFClass.OIDFieldName;
                //pfrmMScatterResult.arrWeightVar = arrWeightVar;
                pfrmMScatterResult.pMakerColor = pMarkerColor;
                pfrmMScatterResult.strVarNM    = cboFldnm1.Text;

                pfrmMScatterResult.pChart.ChartAreas[0].AxisX.IsLabelAutoFit = false;
                pfrmMScatterResult.pChart.ChartAreas[0].AxisX.CustomLabels.Clear();
                pfrmMScatterResult.pChart.ChartAreas[0].AxisX.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.None;
                //pfrmMScatterResult.pChart.ChartAreas[0].AxisX.MajorTickMark.Interval = 1;
                //pfrmMScatterResult.pChart.ChartAreas[0].AxisX.MajorTickMark.IntervalOffset = -2;

                int intMin = Convert.ToInt32(Math.Floor(adblVar1.Min()));
                int intMax = Convert.ToInt32(Math.Ceiling(adblVar1.Max()));
                for (int n = intMin; n < intMax; n++)
                {
                    System.Windows.Forms.DataVisualization.Charting.CustomLabel pcutsomLabel = new System.Windows.Forms.DataVisualization.Charting.CustomLabel();
                    pcutsomLabel.FromPosition = n - 0.5;
                    pcutsomLabel.ToPosition   = n + 0.5;
                    pcutsomLabel.Text         = n.ToString();
                    pfrmMScatterResult.pChart.ChartAreas[0].AxisX.CustomLabels.Add(pcutsomLabel);
                }

                pfrmMScatterResult.Show();
            }
            pfrmProgress.Close();
        }
Exemplo n.º 13
0
        private void EvalRobustness(double[] cb)
        {
            int    intLIndex = m_pSnippet.GetIndexNumberFromLayerName(m_pActiveView, cboSourceLayer.Text);
            ILayer pLayer    = mForm.axMapControl1.get_Layer(intLIndex);

            m_pFLayer = pLayer as IFeatureLayer;
            IFeatureClass pFClass      = m_pFLayer.FeatureClass;
            string        strValueFld  = m_pRenderedLayer.strValueFldName;
            string        strUncernfld = string.Empty;

            if (m_pRenderedLayer.strUncernFldName == string.Empty)
            {
                strUncernfld = cboUncernFld.Text;
            }
            else
            {
                strUncernfld = m_pRenderedLayer.strUncernFldName;
            }
            if (strUncernfld == string.Empty)
            {
                return;
            }

            int intValueIdx   = pFClass.FindField(strValueFld);
            int intUncernIdx  = pFClass.FindField(strUncernfld);
            int intClassCount = cb.Length - 1;

            string strSavefldnm = txtFldName.Text;

            //strTempfldName = "MinSepfave";


            if (pFClass.FindField(strSavefldnm) == -1)
            {
                m_pSnippet.AddField(pFClass, strSavefldnm, esriFieldType.esriFieldTypeDouble);
            }

            int intSavefldIdx = pFClass.FindField(strSavefldnm);

            int   intFCounts = pFClass.FeatureCount(null);
            Chart pChart     = new Chart();

            IFeature pFeat = null;

            IFeatureCursor pFCursor = null;

            pFCursor = pFClass.Update(null, false);

            pFeat = pFCursor.NextFeature();
            Robustness[] pRobustness = new Robustness[intFCounts];
            double[]     arrValue    = new double[intFCounts];

            int i = 0;

            while (pFeat != null)
            {
                pRobustness[i] = new Robustness();
                pRobustness[i].Robustnesses = new double[intClassCount];

                double dblValue = Convert.ToDouble(pFeat.get_Value(intValueIdx));
                double dblStd   = Convert.ToDouble(pFeat.get_Value(intUncernIdx));

                double dblEntropy = 0;
                for (int j = 0; j < intClassCount; j++)
                {
                    double dblUpperZvalue  = (cb[j + 1] - dblValue) / dblStd;
                    double dblUpperConfLev = pChart.DataManipulator.Statistics.NormalDistribution(dblUpperZvalue);
                    double dblLowerZvalue  = (cb[j] - dblValue) / dblStd;
                    double dblLowerConfLev = pChart.DataManipulator.Statistics.NormalDistribution(dblLowerZvalue);
                    double dblProb         = dblUpperConfLev - dblLowerConfLev;
                    pRobustness[i].Robustnesses[j] = dblProb; //Probability of an observation to each class

                    if (dblProb != 0)
                    {
                        dblEntropy += dblProb * Math.Log(dblProb, 2);
                    }

                    if (j == 0)
                    {
                        if (dblValue >= cb[j] && dblValue <= cb[j + 1])
                        {
                            pRobustness[i].TargetClass = j;
                        }
                    }
                    else
                    {
                        if (dblValue > cb[j] && dblValue <= cb[j + 1])
                        {
                            pRobustness[i].TargetClass = j;
                        }
                    }
                }



                pRobustness[i].Entropy = ((double)(-1) * dblEntropy) / (Math.Log(intClassCount, 2));

                if (cboMeasure.Text == "Entropy")
                {
                    arrValue[i] = pRobustness[i].Entropy;
                    pFeat.set_Value(intSavefldIdx, pRobustness[i].Entropy);
                }
                else
                {
                    pFeat.set_Value(intSavefldIdx, pRobustness[i].Robustnesses[pRobustness[i].TargetClass]);
                    arrValue[i] = pRobustness[i].Robustnesses[pRobustness[i].TargetClass];
                }


                pFCursor.UpdateFeature(pFeat);
                pFeat = pFCursor.NextFeature();
                i++;
            }

            //Visualization
            //dblClsMean = new double[intClassCount, 3];
            //double dblSumRobustness = 0;
            //for (int j = 0; j < intFCounts; j++)
            //{
            //    dblSumRobustness = dblSumRobustness + arrRobustness[j, 0];
            //    for (int k = 0; k < intClassCount; k++)
            //    {
            //        if (arrRobustness[j, 1] == k)
            //        {
            //            dblClsMean[k, 0] = arrRobustness[j, 0] + dblClsMean[k, 0];
            //            dblClsMean[k, 1] = dblClsMean[k, 1] + 1;
            //        }
            //    }
            //}
            //for (int k = 0; k < intClassCount; k++)
            //{
            //    dblClsMean[k, 2] = dblClsMean[k, 0] / dblClsMean[k, 1];
            //}
            //dblMeanRobustness = dblSumRobustness / intFCounts;


            //switch (cboGCClassify.Text)
            //{
            //    case "Equal Interval":
            //        pClassifyGEN = new EqualIntervalClass();
            //        break;
            //    case "Geometrical Interval":
            //        pClassifyGEN = new GeometricalInterval();
            //        break;
            //    case "Natural Breaks":
            //        pClassifyGEN = new NaturalBreaksClass();
            //        break;
            //    case "Quantile":
            //        pClassifyGEN = new QuantileClass();
            //        break;
            //    case "StandardDeviation":
            //        pClassifyGEN = new StandardDeviationClass();
            //        break;
            //    default:
            //        pClassifyGEN = new NaturalBreaksClass();
            //        break;
            //}
            if (chkAddMap.Checked)
            {
                IClassifyGEN pClassifyGEN = new NaturalBreaksClass();

                IFeatureLayer pflUncern = new FeatureLayerClass();
                pflUncern.FeatureClass = pFClass;
                pflUncern.Name         = cboSourceLayer.Text + " " + cboMeasure.Text;
                pflUncern.Visible      = true;

                IGeoFeatureLayer pGeofeatureLayer = (IGeoFeatureLayer)pflUncern;

                ITableHistogram pTableHistogram2 = new BasicTableHistogramClass();
                ITable          pTable           = (ITable)pFClass;
                pTableHistogram2.Field = strSavefldnm;
                pTableHistogram2.Table = pTable;
                //IHistogram pHistogram = (IHistogram)pTableHistogram2;
                IBasicHistogram pHistogram = (IBasicHistogram)pTableHistogram2;

                object xVals, frqs;
                pHistogram.GetHistogram(out xVals, out frqs);
                pClassifyGEN.Classify(xVals, frqs, 4); //Fixed Class count
                double[] cb_uncern = (double[])pClassifyGEN.ClassBreaks;

                if (cboMeasure.Text == "Entropy")
                {
                    cb_uncern[1] = 0.4; cb_uncern[2] = 0.6; cb_uncern[3] = 0.75;
                }
                else
                {
                    cb_uncern[1] = 0.4; cb_uncern[2] = 0.6; cb_uncern[3] = 0.75;
                }


                ISpacingBreaksRenderer pSpacingBrksRenderers = new SpacingBreaksRendererClass();
                pSpacingBrksRenderers.arrClassBrks = cb_uncern;
                pSpacingBrksRenderers.arrValue     = arrValue;

                if (cboMeasure.Text == "Entropy")
                {
                    pSpacingBrksRenderers.dblFromSep = Convert.ToDouble(1);
                    pSpacingBrksRenderers.dblToSep   = Convert.ToDouble(20);
                }
                else
                {
                    pSpacingBrksRenderers.dblFromSep = Convert.ToDouble(20);
                    pSpacingBrksRenderers.dblToSep   = Convert.ToDouble(1);
                }

                pSpacingBrksRenderers.dblLineAngle = Convert.ToDouble(45);
                pSpacingBrksRenderers.dblLineWidth = Convert.ToDouble(0.1);
                pSpacingBrksRenderers.m_pLineRgb   = m_pSnippet.getRGB(0, 0, 0);
                if (pSpacingBrksRenderers.m_pLineRgb == null)
                {
                    return;
                }

                pSpacingBrksRenderers.strHeading        = cboMeasure.Text;
                pSpacingBrksRenderers.intRoundingDigits = 2;
                pSpacingBrksRenderers.CreateLegend();

                pGeofeatureLayer.Renderer = (IFeatureRenderer)pSpacingBrksRenderers;

                m_pActiveView.FocusMap.AddLayer(pGeofeatureLayer);
                m_pActiveView.Refresh();
                mForm.axTOCControl1.Update();
            }
        }
Exemplo n.º 14
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            try
            {
                if (cboFldnm1.Text == "" || cboFldnm2.Text == "")
                {
                    MessageBox.Show("Please select target field");
                    return;
                }

                frmProgress pfrmProgress = new frmProgress();
                pfrmProgress.lblStatus.Text    = "Processing:";
                pfrmProgress.pgbProgress.Style = ProgressBarStyle.Marquee;
                pfrmProgress.Show();

                REngine pEngine = m_pForm.pEngine;
                // Creates the input and output matrices from the shapefile//
                string strLayerName = cboTargetLayer.Text;

                int    intLIndex = m_pSnippet.GetIndexNumberFromLayerName(m_pActiveView, strLayerName);
                ILayer pLayer    = m_pForm.axMapControl1.get_Layer(intLIndex);

                IFeatureLayer pFLayer  = pLayer as IFeatureLayer;
                IFeatureClass pFClass  = pFLayer.FeatureClass;
                int           nFeature = pFClass.FeatureCount(null);

                IFeatureCursor pFCursor = pFLayer.Search(null, true);
                IFeature       pFeature = pFCursor.NextFeature();

                //Get index for independent and dependent variables
                //Get variable index
                string strVarNM1  = (string)cboFldnm1.SelectedItem;
                string strVarNM2  = (string)cboFldnm2.SelectedItem;
                int    intVarIdx1 = pFClass.FindField(strVarNM1);
                int    intVarIdx2 = pFClass.FindField(strVarNM2);

                //Store Variable at Array
                double[] arrVar1 = new double[nFeature];
                double[] arrVar2 = new double[nFeature];

                int i = 0;

                while (pFeature != null)
                {
                    arrVar1[i] = Convert.ToDouble(pFeature.get_Value(intVarIdx1));
                    arrVar2[i] = Convert.ToDouble(pFeature.get_Value(intVarIdx2));
                    i++;
                    pFeature = pFCursor.NextFeature();
                }

                //Plot command for R
                StringBuilder plotCommmand = new StringBuilder();

                string strStartPath = m_pForm.strPath;
                string pathr        = strStartPath.Replace(@"\", @"/");
                pEngine.Evaluate("source('" + pathr + "/AllFunctions_LeeL.R')");

                //Get the file path and name to create spatial weight matrix
                string strNameR = m_pSnippet.FilePathinRfromLayer(pFLayer);

                if (strNameR == null)
                {
                    return;
                }

                //Create spatial weight matrix in R
                pEngine.Evaluate("library(spdep); library(maptools)");
                pEngine.Evaluate("sample.shp <- readShapePoly('" + strNameR + "')");

                if (txtSWM.Text == "Default")
                {
                    pEngine.Evaluate("sample.nb <- poly2nb(sample.shp)");
                }
                else
                {
                    int intResult = m_pSnippet.SWMusingGAL(pEngine, pFClass, txtSWM.Text);
                    if (intResult == -1)
                    {
                        return;
                    }
                }

                NumericVector vecVar1 = pEngine.CreateNumericVector(arrVar1);
                pEngine.SetSymbol("sample.v1", vecVar1);
                NumericVector vecVar2 = pEngine.CreateNumericVector(arrVar2);
                pEngine.SetSymbol("sample.v2", vecVar2);

                string strSigLv     = nudSigLv.Value.ToString();
                string strSigMethod = cboSigMethod.Text;

                if (cboSAM.Text == "Lee's L")
                {
                    #region Li
                    pEngine.Evaluate("sample.l <- L.local.test(sample.v1, sample.v2, 1:length(sample.nb), sample.nb, style='W', sig.levels=c(" + strSigLv + "), method='" + strSigMethod + "', alternative='two.sided', diag.zero=FALSE)");

                    double[] dblLValues = pEngine.Evaluate("sample.l$local.L").AsNumeric().ToArray();
                    double[] dblPvalues = pEngine.Evaluate("sample.l$pvalue").AsNumeric().ToArray();
                    string[] strFlgs    = pEngine.Evaluate("as.character(sample.l$sig)").AsCharacter().ToArray();

                    //Save Output on SHP
                    //Add Target fields to store results in the shapefile
                    for (int j = 0; j < 3; j++)
                    {
                        IField     newField  = new FieldClass();
                        IFieldEdit fieldEdit = (IFieldEdit)newField;
                        fieldEdit.Name_2 = lvFields.Items[j].SubItems[1].Text;
                        if (j == 2)
                        {
                            fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                        }
                        else
                        {
                            fieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
                        }
                        pFClass.AddField(newField);
                    }

                    //Update Field
                    pFCursor = pFClass.Update(null, false);
                    pFeature = pFCursor.NextFeature();

                    string strFlgFldNam  = lvFields.Items[2].SubItems[1].Text;
                    int    intStatFldIdx = pFClass.FindField(lvFields.Items[0].SubItems[1].Text);
                    int    intPrFldIdx   = pFClass.FindField(lvFields.Items[1].SubItems[1].Text);
                    int    intFlgFldIdx  = pFClass.FindField(strFlgFldNam);

                    int featureIdx = 0;
                    while (pFeature != null)
                    {
                        pFeature.set_Value(intStatFldIdx, dblLValues[featureIdx]);
                        pFeature.set_Value(intPrFldIdx, dblPvalues[featureIdx]);
                        pFeature.set_Value(intFlgFldIdx, strFlgs[featureIdx]);

                        pFCursor.UpdateFeature(pFeature);

                        pFeature = pFCursor.NextFeature();
                        featureIdx++;
                    }
                    pFCursor.Flush();

                    pfrmProgress.Close();

                    if (chkMap.Checked)
                    {
                        double[,] adblMinMaxForLabel = new double[2, 4];
                        ITable pTable = (ITable)pFClass;

                        IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass();
                        pUniqueValueRenderer.FieldCount = 1;
                        pUniqueValueRenderer.set_Field(0, strFlgFldNam);
                        IDataStatistics    pDataStat;
                        IStatisticsResults pStatResults;
                        ISimpleFillSymbol  pSymbol;
                        ICursor            pCursor;

                        IQueryFilter pQFilter = new QueryFilterClass();
                        pQFilter.WhereClause = strFlgFldNam + " = 'HH'";

                        int intCnt = pTable.RowCount(pQFilter);

                        pCursor                  = pTable.Search(pQFilter, true);
                        pDataStat                = new DataStatisticsClass();
                        pDataStat.Field          = lvFields.Items[1].SubItems[1].Text;
                        pDataStat.Cursor         = pCursor;
                        pStatResults             = pDataStat.Statistics;
                        adblMinMaxForLabel[0, 0] = pStatResults.Minimum;
                        adblMinMaxForLabel[1, 0] = pStatResults.Maximum;
                        pCursor.Flush();

                        pSymbol       = new SimpleFillSymbolClass();
                        pSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
                        pSymbol.Color = m_pSnippet.getRGB(255, 80, 80);
                        pUniqueValueRenderer.AddValue("HH", null, (ISymbol)pSymbol);
                        if (intCnt == 1)
                        {
                            pUniqueValueRenderer.set_Label("HH", "HH (" + adblMinMaxForLabel[0, 0].ToString("N1") + ")");
                        }
                        else if (intCnt == 0)
                        {
                            pUniqueValueRenderer.set_Label("HH", "HH (no obs)");
                        }
                        else
                        {
                            pUniqueValueRenderer.set_Label("HH", "HH (" + adblMinMaxForLabel[0, 0].ToString("N1") + "-" + adblMinMaxForLabel[1, 0].ToString("N1") + ")");
                        }


                        pQFilter.WhereClause = strFlgFldNam + " = 'LL'";
                        intCnt = pTable.RowCount(pQFilter);


                        pCursor                  = pTable.Search(pQFilter, true);
                        pDataStat                = new DataStatisticsClass();
                        pDataStat.Field          = lvFields.Items[1].SubItems[1].Text;
                        pDataStat.Cursor         = pCursor;
                        pStatResults             = pDataStat.Statistics;
                        adblMinMaxForLabel[0, 1] = pStatResults.Minimum;
                        adblMinMaxForLabel[1, 1] = pStatResults.Maximum;
                        pCursor.Flush();

                        pSymbol       = new SimpleFillSymbolClass();
                        pSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
                        pSymbol.Color = m_pSnippet.getRGB(50, 157, 194);
                        pUniqueValueRenderer.AddValue("LL", null, (ISymbol)pSymbol);

                        if (intCnt == 1)
                        {
                            pUniqueValueRenderer.set_Label("LL", "LL (" + adblMinMaxForLabel[0, 1].ToString("N1") + ")");
                        }
                        else if (intCnt == 0)
                        {
                            pUniqueValueRenderer.set_Label("LL", "LL (no obs)");
                        }
                        else
                        {
                            pUniqueValueRenderer.set_Label("LL", "LL (" + adblMinMaxForLabel[0, 1].ToString("N1") + "-" + adblMinMaxForLabel[1, 1].ToString("N1") + ")");
                        }


                        pQFilter.WhereClause = strFlgFldNam + " = 'HL'";
                        intCnt = pTable.RowCount(pQFilter);


                        pCursor                  = pTable.Search(pQFilter, true);
                        pDataStat                = new DataStatisticsClass();
                        pDataStat.Field          = lvFields.Items[1].SubItems[1].Text;
                        pDataStat.Cursor         = pCursor;
                        pStatResults             = pDataStat.Statistics;
                        adblMinMaxForLabel[0, 2] = pStatResults.Minimum;
                        adblMinMaxForLabel[1, 2] = pStatResults.Maximum;
                        pCursor.Flush();

                        pSymbol       = new SimpleFillSymbolClass();
                        pSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
                        pSymbol.Color = m_pSnippet.getRGB(244, 199, 0);
                        pUniqueValueRenderer.AddValue("HL", null, (ISymbol)pSymbol);

                        if (intCnt == 1)
                        {
                            pUniqueValueRenderer.set_Label("HL", "HL (" + adblMinMaxForLabel[0, 2].ToString("N1") + ")");
                        }
                        else if (intCnt == 0)
                        {
                            pUniqueValueRenderer.set_Label("HL", "HL (no obs)");
                        }
                        else
                        {
                            pUniqueValueRenderer.set_Label("HL", "HL (" + adblMinMaxForLabel[0, 2].ToString("N1") + "-" + adblMinMaxForLabel[1, 2].ToString("N1") + ")");
                        }


                        pQFilter.WhereClause = strFlgFldNam + " = 'LH'";
                        intCnt = pTable.RowCount(pQFilter);

                        pCursor                  = pTable.Search(pQFilter, true);
                        pDataStat                = new DataStatisticsClass();
                        pDataStat.Field          = lvFields.Items[1].SubItems[1].Text;
                        pDataStat.Cursor         = pCursor;
                        pStatResults             = pDataStat.Statistics;
                        adblMinMaxForLabel[0, 3] = pStatResults.Minimum;
                        adblMinMaxForLabel[1, 3] = pStatResults.Maximum;
                        pCursor.Flush();

                        pSymbol       = new SimpleFillSymbolClass();
                        pSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
                        pSymbol.Color = m_pSnippet.getRGB(173, 255, 179);
                        pUniqueValueRenderer.AddValue("LH", null, (ISymbol)pSymbol);

                        if (intCnt == 1)
                        {
                            pUniqueValueRenderer.set_Label("LH", "LH (" + adblMinMaxForLabel[0, 3].ToString("N1") + ")");
                        }
                        else if (intCnt == 0)
                        {
                            pUniqueValueRenderer.set_Label("LH", "LH (no obs)");
                        }
                        else
                        {
                            pUniqueValueRenderer.set_Label("LH", "LH (" + adblMinMaxForLabel[0, 3].ToString("N1") + "-" + adblMinMaxForLabel[1, 3].ToString("N1") + ")");
                        }



                        pSymbol       = new SimpleFillSymbolClass();
                        pSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
                        pSymbol.Color = m_pSnippet.getRGB(200, 200, 200);
                        //pUniqueValueRenderer.AddValue("", strFlgFldNam, (ISymbol)pSymbol);
                        //pUniqueValueRenderer.set_Label("", "Not significant");
                        pUniqueValueRenderer.DefaultSymbol = (ISymbol)pSymbol;
                        pUniqueValueRenderer.DefaultLabel  = "Not significant";

                        pUniqueValueRenderer.UseDefaultSymbol = true;

                        IFeatureLayer pNewFLayer = new FeatureLayerClass();
                        pNewFLayer.FeatureClass = pFClass;
                        pNewFLayer.Name         = cboSAM.Text + " of " + pFLayer.Name;
                        IGeoFeatureLayer pGFLayer = (IGeoFeatureLayer)pNewFLayer;
                        pGFLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer;
                        m_pActiveView.FocusMap.AddLayer(pGFLayer);
                        m_pActiveView.Refresh();
                        m_pForm.axTOCControl1.Update();
                    }
                    else
                    {
                        MessageBox.Show("Complete. The results are stored in the shape file");
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog();
                return;
            }
        }
Exemplo n.º 15
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            try
            {
                //Checking
                if (cboFieldName.Text == "")
                {
                    MessageBox.Show("Please select target field");
                    return;
                }

                frmProgress pfrmProgress = new frmProgress();
                pfrmProgress.lblStatus.Text    = "Processing:";
                pfrmProgress.pgbProgress.Style = ProgressBarStyle.Marquee;
                pfrmProgress.Show();

                int nFeature = m_pFClass.FeatureCount(null);

                IFeatureCursor pFCursor = m_pFLayer.Search(null, true);
                IFeature       pFeature = pFCursor.NextFeature();

                //Get index for independent and dependent variables
                //Get variable index
                string strVarNM  = (string)cboFieldName.SelectedItem;
                int    intVarIdx = m_pFClass.FindField(strVarNM);

                //Store Variable at Array
                double[] arrVar = new double[nFeature];

                int i = 0;

                while (pFeature != null)
                {
                    arrVar[i] = Convert.ToDouble(pFeature.get_Value(intVarIdx));
                    i++;
                    pFeature = pFCursor.NextFeature();
                }

                //Plot command for R
                StringBuilder plotCommmand = new StringBuilder();

                if (!m_blnCreateSWM)
                {
                    //Get the file path and name to create spatial weight matrix
                    string strNameR = m_pSnippet.FilePathinRfromLayer(m_pFLayer);

                    if (strNameR == null)
                    {
                        return;
                    }

                    //Create spatial weight matrix in R
                    if (m_pFClass.ShapeType == esriGeometryType.esriGeometryPolygon)
                    {
                        m_pEngine.Evaluate("sample.shp <- readShapePoly('" + strNameR + "')");
                    }
                    else if (m_pFClass.ShapeType == esriGeometryType.esriGeometryPoint)
                    {
                        m_pEngine.Evaluate("sample.shp <- readShapePoints('" + strNameR + "')");
                    }
                    else
                    {
                        MessageBox.Show("This geometry type is not supported");
                        pfrmProgress.Close();
                        this.Close();
                    }


                    int intSuccess = m_pSnippet.CreateSpatialWeightMatrix(m_pEngine, m_pFClass, txtSWM.Text, pfrmProgress);
                    if (intSuccess == 0)
                    {
                        return;
                    }
                }

                NumericVector vecVar = m_pEngine.CreateNumericVector(arrVar);
                m_pEngine.SetSymbol(strVarNM, vecVar);

                if (cboSAM.Text == "Local Moran")
                {
                    #region Local Moran
                    plotCommmand.Append("localmoran(" + strVarNM + ", sample.listw, alternative = 'two.sided', ");

                    //select multiple correction method (only Bonferroni.. 100915 HK)
                    if (cboAdjustment.Text == "None")
                    {
                        plotCommmand.Append(", zero.policy=TRUE)");
                    }
                    else if (cboAdjustment.Text == "Bonferroni correction")
                    {
                        plotCommmand.Append("p.adjust.method='bonferroni', zero.policy=TRUE)");
                    }

                    NumericMatrix nmResults = m_pEngine.Evaluate(plotCommmand.ToString()).AsNumericMatrix();

                    string strFlgFldNam = lvFields.Items[3].SubItems[1].Text;
                    //Save Output on SHP
                    //Add Target fields to store results in the shapefile
                    for (int j = 0; j < 4; j++)
                    {
                        IField     newField  = new FieldClass();
                        IFieldEdit fieldEdit = (IFieldEdit)newField;
                        fieldEdit.Name_2 = lvFields.Items[j].SubItems[1].Text;
                        if (j == 3)
                        {
                            fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                        }
                        else
                        {
                            fieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
                        }
                        m_pFClass.AddField(newField);
                    }


                    //Update Field
                    pFCursor = m_pFClass.Update(null, false);
                    pFeature = pFCursor.NextFeature();

                    int intStatFldIdx = m_pFClass.FindField(lvFields.Items[0].SubItems[1].Text);
                    int intZFldIdx    = m_pFClass.FindField(lvFields.Items[1].SubItems[1].Text);
                    int intPrFldIdx   = m_pFClass.FindField(lvFields.Items[2].SubItems[1].Text);
                    int intFlgFldIdx  = m_pFClass.FindField(strFlgFldNam);

                    double dblValue = 0, dblPvalue = 0, dblZvalue = 0;
                    double dblValueMean = arrVar.Average();
                    double dblPrCri     = Convert.ToDouble(nudConfLevel.Value);

                    int featureIdx = 0;
                    while (pFeature != null)
                    {
                        dblValue  = arrVar[featureIdx] - dblValueMean;
                        dblZvalue = nmResults[featureIdx, 3];
                        dblPvalue = nmResults[featureIdx, 4];
                        pFeature.set_Value(intStatFldIdx, (object)nmResults[featureIdx, 0]);
                        pFeature.set_Value(intZFldIdx, dblZvalue);
                        pFeature.set_Value(intPrFldIdx, dblPvalue);

                        if (dblPvalue < dblPrCri)
                        {
                            if (dblZvalue > 0)
                            {
                                if (dblValue > 0)
                                {
                                    pFeature.set_Value(intFlgFldIdx, "HH");
                                }
                                else
                                {
                                    pFeature.set_Value(intFlgFldIdx, "LL");
                                }
                            }
                            else
                            {
                                if (dblValue > 0)
                                {
                                    pFeature.set_Value(intFlgFldIdx, "HL");
                                }
                                else
                                {
                                    pFeature.set_Value(intFlgFldIdx, "LH");
                                }
                            }
                        }
                        //else
                        //    pFeature.set_Value(intFlgFldIdx, "");
                        pFCursor.UpdateFeature(pFeature);

                        pFeature = pFCursor.NextFeature();
                        featureIdx++;
                    }

                    pfrmProgress.Close();
                    if (chkMap.Checked)
                    {
                        double[,] adblMinMaxForLabel = new double[2, 4];
                        ITable pTable = (ITable)m_pFClass;

                        IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass();
                        pUniqueValueRenderer.FieldCount = 1;
                        pUniqueValueRenderer.set_Field(0, strFlgFldNam);
                        IDataStatistics    pDataStat;
                        IStatisticsResults pStatResults;

                        ICursor pCursor;

                        if (m_pFClass.ShapeType == esriGeometryType.esriGeometryPolygon)
                        {
                            ISimpleFillSymbol pSymbol;
                            IQueryFilter      pQFilter = new QueryFilterClass();
                            pQFilter.WhereClause = strFlgFldNam + " = 'HH'";

                            int intCnt = pTable.RowCount(pQFilter);

                            pCursor                  = pTable.Search(pQFilter, true);
                            pDataStat                = new DataStatisticsClass();
                            pDataStat.Field          = lvFields.Items[1].SubItems[1].Text;
                            pDataStat.Cursor         = pCursor;
                            pStatResults             = pDataStat.Statistics;
                            adblMinMaxForLabel[0, 0] = pStatResults.Minimum;
                            adblMinMaxForLabel[1, 0] = pStatResults.Maximum;
                            pCursor.Flush();

                            pSymbol       = new SimpleFillSymbolClass();
                            pSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
                            pSymbol.Color = m_pSnippet.getRGB(255, 80, 80);
                            pUniqueValueRenderer.AddValue("HH", null, (ISymbol)pSymbol);
                            if (intCnt == 1)
                            {
                                pUniqueValueRenderer.set_Label("HH", "HH (" + adblMinMaxForLabel[0, 0].ToString("N1") + ")");
                            }
                            else if (intCnt == 0)
                            {
                                pUniqueValueRenderer.set_Label("HH", "HH (no obs)");
                            }
                            else
                            {
                                pUniqueValueRenderer.set_Label("HH", "HH (" + adblMinMaxForLabel[0, 0].ToString("N1") + "-" + adblMinMaxForLabel[1, 0].ToString("N1") + ")");
                            }



                            pQFilter.WhereClause = strFlgFldNam + " = 'LL'";
                            intCnt = pTable.RowCount(pQFilter);


                            pCursor                  = pTable.Search(pQFilter, true);
                            pDataStat                = new DataStatisticsClass();
                            pDataStat.Field          = lvFields.Items[1].SubItems[1].Text;
                            pDataStat.Cursor         = pCursor;
                            pStatResults             = pDataStat.Statistics;
                            adblMinMaxForLabel[0, 1] = pStatResults.Minimum;
                            adblMinMaxForLabel[1, 1] = pStatResults.Maximum;
                            pCursor.Flush();

                            pSymbol       = new SimpleFillSymbolClass();
                            pSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
                            pSymbol.Color = m_pSnippet.getRGB(50, 157, 194);
                            pUniqueValueRenderer.AddValue("LL", null, (ISymbol)pSymbol);

                            if (intCnt == 1)
                            {
                                pUniqueValueRenderer.set_Label("LL", "LL (" + adblMinMaxForLabel[0, 1].ToString("N1") + ")");
                            }
                            else if (intCnt == 0)
                            {
                                pUniqueValueRenderer.set_Label("LL", "LL (no obs)");
                            }
                            else
                            {
                                pUniqueValueRenderer.set_Label("LL", "LL (" + adblMinMaxForLabel[0, 1].ToString("N1") + "-" + adblMinMaxForLabel[1, 1].ToString("N1") + ")");
                            }


                            pQFilter.WhereClause = strFlgFldNam + " = 'HL'";
                            intCnt = pTable.RowCount(pQFilter);


                            pCursor                  = pTable.Search(pQFilter, true);
                            pDataStat                = new DataStatisticsClass();
                            pDataStat.Field          = lvFields.Items[1].SubItems[1].Text;
                            pDataStat.Cursor         = pCursor;
                            pStatResults             = pDataStat.Statistics;
                            adblMinMaxForLabel[0, 2] = pStatResults.Minimum;
                            adblMinMaxForLabel[1, 2] = pStatResults.Maximum;
                            pCursor.Flush();

                            pSymbol       = new SimpleFillSymbolClass();
                            pSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
                            pSymbol.Color = m_pSnippet.getRGB(244, 199, 0);
                            pUniqueValueRenderer.AddValue("HL", null, (ISymbol)pSymbol);

                            if (intCnt == 1)
                            {
                                pUniqueValueRenderer.set_Label("HL", "HL (" + adblMinMaxForLabel[0, 2].ToString("N1") + ")");
                            }
                            else if (intCnt == 0)
                            {
                                pUniqueValueRenderer.set_Label("HL", "HL (no obs)");
                            }
                            else
                            {
                                pUniqueValueRenderer.set_Label("HL", "HL (" + adblMinMaxForLabel[0, 2].ToString("N1") + "-" + adblMinMaxForLabel[1, 2].ToString("N1") + ")");
                            }


                            pQFilter.WhereClause = strFlgFldNam + " = 'LH'";
                            intCnt = pTable.RowCount(pQFilter);

                            pCursor                  = pTable.Search(pQFilter, true);
                            pDataStat                = new DataStatisticsClass();
                            pDataStat.Field          = lvFields.Items[1].SubItems[1].Text;
                            pDataStat.Cursor         = pCursor;
                            pStatResults             = pDataStat.Statistics;
                            adblMinMaxForLabel[0, 3] = pStatResults.Minimum;
                            adblMinMaxForLabel[1, 3] = pStatResults.Maximum;
                            pCursor.Flush();

                            pSymbol       = new SimpleFillSymbolClass();
                            pSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
                            pSymbol.Color = m_pSnippet.getRGB(173, 255, 179);
                            pUniqueValueRenderer.AddValue("LH", null, (ISymbol)pSymbol);

                            if (intCnt == 1)
                            {
                                pUniqueValueRenderer.set_Label("LH", "LH (" + adblMinMaxForLabel[0, 3].ToString("N1") + ")");
                            }
                            else if (intCnt == 0)
                            {
                                pUniqueValueRenderer.set_Label("LH", "LH (no obs)");
                            }
                            else
                            {
                                pUniqueValueRenderer.set_Label("LH", "LH (" + adblMinMaxForLabel[0, 3].ToString("N1") + "-" + adblMinMaxForLabel[1, 3].ToString("N1") + ")");
                            }



                            pSymbol       = new SimpleFillSymbolClass();
                            pSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
                            pSymbol.Color = m_pSnippet.getRGB(200, 200, 200);
                            //pUniqueValueRenderer.AddValue("", strFlgFldNam, (ISymbol)pSymbol);
                            //pUniqueValueRenderer.set_Label("", "Not significant");
                            pUniqueValueRenderer.DefaultSymbol = (ISymbol)pSymbol;
                            pUniqueValueRenderer.DefaultLabel  = "Not significant";

                            pUniqueValueRenderer.UseDefaultSymbol = true;
                        }
                        else if (m_pFClass.ShapeType == esriGeometryType.esriGeometryPoint)
                        {
                            ISimpleMarkerSymbol pSymbol;
                            IQueryFilter        pQFilter = new QueryFilterClass();
                            pQFilter.WhereClause = strFlgFldNam + " = 'HH'";

                            int intCnt = pTable.RowCount(pQFilter);

                            pCursor                  = pTable.Search(pQFilter, true);
                            pDataStat                = new DataStatisticsClass();
                            pDataStat.Field          = lvFields.Items[1].SubItems[1].Text;
                            pDataStat.Cursor         = pCursor;
                            pStatResults             = pDataStat.Statistics;
                            adblMinMaxForLabel[0, 0] = pStatResults.Minimum;
                            adblMinMaxForLabel[1, 0] = pStatResults.Maximum;
                            pCursor.Flush();

                            pSymbol       = new SimpleMarkerSymbolClass();
                            pSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;
                            pSymbol.Color = m_pSnippet.getRGB(255, 80, 80);
                            pUniqueValueRenderer.AddValue("HH", null, (ISymbol)pSymbol);
                            if (intCnt == 1)
                            {
                                pUniqueValueRenderer.set_Label("HH", "HH (" + adblMinMaxForLabel[0, 0].ToString("N1") + ")");
                            }
                            else if (intCnt == 0)
                            {
                                pUniqueValueRenderer.set_Label("HH", "HH (no obs)");
                            }
                            else
                            {
                                pUniqueValueRenderer.set_Label("HH", "HH (" + adblMinMaxForLabel[0, 0].ToString("N1") + "-" + adblMinMaxForLabel[1, 0].ToString("N1") + ")");
                            }



                            pQFilter.WhereClause = strFlgFldNam + " = 'LL'";
                            intCnt = pTable.RowCount(pQFilter);


                            pCursor                  = pTable.Search(pQFilter, true);
                            pDataStat                = new DataStatisticsClass();
                            pDataStat.Field          = lvFields.Items[1].SubItems[1].Text;
                            pDataStat.Cursor         = pCursor;
                            pStatResults             = pDataStat.Statistics;
                            adblMinMaxForLabel[0, 1] = pStatResults.Minimum;
                            adblMinMaxForLabel[1, 1] = pStatResults.Maximum;
                            pCursor.Flush();

                            pSymbol       = new SimpleMarkerSymbolClass();
                            pSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;
                            pSymbol.Color = m_pSnippet.getRGB(50, 157, 194);
                            pUniqueValueRenderer.AddValue("LL", null, (ISymbol)pSymbol);

                            if (intCnt == 1)
                            {
                                pUniqueValueRenderer.set_Label("LL", "LL (" + adblMinMaxForLabel[0, 1].ToString("N1") + ")");
                            }
                            else if (intCnt == 0)
                            {
                                pUniqueValueRenderer.set_Label("LL", "LL (no obs)");
                            }
                            else
                            {
                                pUniqueValueRenderer.set_Label("LL", "LL (" + adblMinMaxForLabel[0, 1].ToString("N1") + "-" + adblMinMaxForLabel[1, 1].ToString("N1") + ")");
                            }


                            pQFilter.WhereClause = strFlgFldNam + " = 'HL'";
                            intCnt = pTable.RowCount(pQFilter);


                            pCursor                  = pTable.Search(pQFilter, true);
                            pDataStat                = new DataStatisticsClass();
                            pDataStat.Field          = lvFields.Items[1].SubItems[1].Text;
                            pDataStat.Cursor         = pCursor;
                            pStatResults             = pDataStat.Statistics;
                            adblMinMaxForLabel[0, 2] = pStatResults.Minimum;
                            adblMinMaxForLabel[1, 2] = pStatResults.Maximum;
                            pCursor.Flush();

                            pSymbol       = new SimpleMarkerSymbolClass();
                            pSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;
                            pSymbol.Color = m_pSnippet.getRGB(244, 199, 0);
                            pUniqueValueRenderer.AddValue("HL", null, (ISymbol)pSymbol);

                            if (intCnt == 1)
                            {
                                pUniqueValueRenderer.set_Label("HL", "HL (" + adblMinMaxForLabel[0, 2].ToString("N1") + ")");
                            }
                            else if (intCnt == 0)
                            {
                                pUniqueValueRenderer.set_Label("HL", "HL (no obs)");
                            }
                            else
                            {
                                pUniqueValueRenderer.set_Label("HL", "HL (" + adblMinMaxForLabel[0, 2].ToString("N1") + "-" + adblMinMaxForLabel[1, 2].ToString("N1") + ")");
                            }


                            pQFilter.WhereClause = strFlgFldNam + " = 'LH'";
                            intCnt = pTable.RowCount(pQFilter);

                            pCursor                  = pTable.Search(pQFilter, true);
                            pDataStat                = new DataStatisticsClass();
                            pDataStat.Field          = lvFields.Items[1].SubItems[1].Text;
                            pDataStat.Cursor         = pCursor;
                            pStatResults             = pDataStat.Statistics;
                            adblMinMaxForLabel[0, 3] = pStatResults.Minimum;
                            adblMinMaxForLabel[1, 3] = pStatResults.Maximum;
                            pCursor.Flush();

                            pSymbol       = new SimpleMarkerSymbolClass();
                            pSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;
                            pSymbol.Color = m_pSnippet.getRGB(173, 255, 179);
                            pUniqueValueRenderer.AddValue("LH", null, (ISymbol)pSymbol);

                            if (intCnt == 1)
                            {
                                pUniqueValueRenderer.set_Label("LH", "LH (" + adblMinMaxForLabel[0, 3].ToString("N1") + ")");
                            }
                            else if (intCnt == 0)
                            {
                                pUniqueValueRenderer.set_Label("LH", "LH (no obs)");
                            }
                            else
                            {
                                pUniqueValueRenderer.set_Label("LH", "LH (" + adblMinMaxForLabel[0, 3].ToString("N1") + "-" + adblMinMaxForLabel[1, 3].ToString("N1") + ")");
                            }



                            pSymbol       = new SimpleMarkerSymbolClass();
                            pSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;
                            pSymbol.Color = m_pSnippet.getRGB(200, 200, 200);
                            //pUniqueValueRenderer.AddValue("", strFlgFldNam, (ISymbol)pSymbol);
                            //pUniqueValueRenderer.set_Label("", "Not significant");
                            pUniqueValueRenderer.DefaultSymbol = (ISymbol)pSymbol;
                            pUniqueValueRenderer.DefaultLabel  = "Not significant";

                            pUniqueValueRenderer.UseDefaultSymbol = true;
                        }



                        IFeatureLayer pNewFLayer = new FeatureLayerClass();
                        pNewFLayer.FeatureClass = m_pFClass;
                        pNewFLayer.Name         = cboSAM.Text + " of " + m_pFLayer.Name;
                        IGeoFeatureLayer pGFLayer = (IGeoFeatureLayer)pNewFLayer;
                        pGFLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer;
                        m_pActiveView.FocusMap.AddLayer(pGFLayer);
                        m_pActiveView.Refresh();
                        m_pForm.axTOCControl1.Update();
                    }
                    else
                    {
                        MessageBox.Show("Complete. The results are stored in the shape file");
                    }
                    #endregion
                }
                else if (cboSAM.Text == "Gi*")
                {
                    #region Gi*
                    m_pEngine.Evaluate("sample.lg <- localG(" + strVarNM + ", sample.listw, zero.policy=TRUE)");
                    m_pEngine.Evaluate("sample.p <- 2*pnorm(-abs(sample.lg))");

                    if (cboAdjustment.Text == "Bonferroni correction")
                    {
                        m_pEngine.Evaluate("sample.p <- p.adjust(sample.p, method = 'bonferroni', n = length(sample.p))");
                    }

                    double[] dblGValues = m_pEngine.Evaluate("sample.lg").AsNumeric().ToArray();
                    double[] dblPvalues = m_pEngine.Evaluate("sample.p").AsNumeric().ToArray();

                    //Save Output on SHP
                    //Add Target fields to store results in the shapefile
                    for (int j = 0; j < 2; j++)
                    {
                        IField     newField  = new FieldClass();
                        IFieldEdit fieldEdit = (IFieldEdit)newField;
                        fieldEdit.Name_2 = lvFields.Items[j].SubItems[1].Text;
                        fieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
                        m_pFClass.AddField(newField);
                    }

                    //Update Field
                    pFCursor = m_pFClass.Update(null, false);
                    pFeature = pFCursor.NextFeature();

                    int intStatFldIdx = m_pFClass.FindField(lvFields.Items[0].SubItems[1].Text);
                    int intPrFldIdx   = m_pFClass.FindField(lvFields.Items[1].SubItems[1].Text);

                    int featureIdx = 0;
                    while (pFeature != null)
                    {
                        pFeature.set_Value(intStatFldIdx, dblGValues[featureIdx]);
                        pFeature.set_Value(intPrFldIdx, dblPvalues[featureIdx]);

                        pFCursor.UpdateFeature(pFeature);

                        pFeature = pFCursor.NextFeature();
                        featureIdx++;
                    }
                    pFCursor.Flush();

                    pfrmProgress.Close();

                    if (chkMap.Checked)
                    {
                        string strStaticFldName = lvFields.Items[0].SubItems[1].Text;

                        m_pEngine.Evaluate("p.vals <- c(0.1, 0.05, 0.01)");
                        if (cboAdjustment.Text == "Bonferroni correction")
                        {
                            m_pEngine.Evaluate("sample.n <- length(sample.p)");
                            m_pEngine.Evaluate("p.vals <- p.vals/sample.n");
                        }
                        m_pEngine.Evaluate("zc <- qnorm(1 - (p.vals/2))");
                        double[] dblZBrks = m_pEngine.Evaluate("sort(cbind(zc, -zc))").AsNumeric().ToArray();

                        pFCursor = m_pFClass.Search(null, false);
                        IDataStatistics pDataStat = new DataStatisticsClass();
                        pDataStat.Field  = strStaticFldName;
                        pDataStat.Cursor = (ICursor)pFCursor;
                        IStatisticsResults pStatResults = pDataStat.Statistics;
                        double             dblMax       = pStatResults.Maximum;
                        double             dblMin       = pStatResults.Minimum;
                        int      intBreaksCount         = dblZBrks.Length + 2;
                        double[] cb = new double[intBreaksCount];

                        //Assign Min and Max values for class breaks
                        if (dblMin < dblZBrks[0])
                        {
                            cb[0] = dblMin;
                        }
                        else
                        {
                            cb[0] = dblZBrks[0] - 1; //Manually Assigned minimum value
                        }
                        if (dblMax > dblZBrks[dblZBrks.Length - 1])
                        {
                            cb[intBreaksCount - 1] = dblMax;
                        }
                        else
                        {
                            cb[intBreaksCount - 1] = dblZBrks[dblZBrks.Length - 1] + 1;//Manually Assigned minimum value
                        }
                        for (int k = 0; k < intBreaksCount - 2; k++)
                        {
                            cb[k + 1] = dblZBrks[k];
                        }

                        IClassBreaksRenderer pCBRenderer = new ClassBreaksRenderer();
                        pCBRenderer.Field        = strStaticFldName;
                        pCBRenderer.BreakCount   = intBreaksCount - 1;
                        pCBRenderer.MinimumBreak = cb[0];

                        //' use this interface to set dialog properties
                        IClassBreaksUIProperties pUIProperties = (IClassBreaksUIProperties)pCBRenderer;
                        pUIProperties.ColorRamp = "Custom";
                        if (m_pFClass.ShapeType == esriGeometryType.esriGeometryPolygon)
                        {
                            ISimpleFillSymbol pSimpleFillSym;

                            int[,] arrColors = CreateColorRamp();

                            //Add Probability Value Manually
                            string[] strsProbLabels = new string[] { "(0.01)", "(0.05)", "(0.1)", "(0.1)", "(0.05)", "(0.01)" };
                            //' be careful, indices are different for the diff lists
                            for (int j = 0; j < intBreaksCount - 1; j++)
                            {
                                pCBRenderer.Break[j] = cb[j + 1];
                                if (j == 0)
                                {
                                    pCBRenderer.Label[j] = " <= " + Math.Round(cb[j + 1], 2).ToString() + strsProbLabels[j];
                                }
                                else if (j == intBreaksCount - 2)
                                {
                                    pCBRenderer.Label[j] = " > " + Math.Round(cb[j], 2).ToString() + strsProbLabels[j - 1];
                                }
                                else
                                {
                                    pCBRenderer.Label[j] = Math.Round(cb[j], 2).ToString() + strsProbLabels[j - 1] + " ~ " + Math.Round(cb[j + 1], 2).ToString() + strsProbLabels[j];
                                }
                                pUIProperties.LowBreak[j] = cb[j];
                                pSimpleFillSym            = new SimpleFillSymbolClass();
                                IRgbColor pRGBColor = m_pSnippet.getRGB(arrColors[j, 0], arrColors[j, 1], arrColors[j, 2]);
                                pSimpleFillSym.Color  = (IColor)pRGBColor;
                                pCBRenderer.Symbol[j] = (ISymbol)pSimpleFillSym;
                            }
                        }
                        else if (m_pFClass.ShapeType == esriGeometryType.esriGeometryPoint)
                        {
                            ISimpleMarkerSymbol pSimpleMarkerSym;

                            int[,] arrColors = CreateColorRamp();

                            //Add Probability Value Manually
                            string[] strsProbLabels = new string[] { "(0.01)", "(0.05)", "(0.1)", "(0.1)", "(0.05)", "(0.01)" };
                            //' be careful, indices are different for the diff lists
                            for (int j = 0; j < intBreaksCount - 1; j++)
                            {
                                pCBRenderer.Break[j] = cb[j + 1];
                                if (j == 0)
                                {
                                    pCBRenderer.Label[j] = " <= " + Math.Round(cb[j + 1], 2).ToString() + strsProbLabels[j];
                                }
                                else if (j == intBreaksCount - 2)
                                {
                                    pCBRenderer.Label[j] = " > " + Math.Round(cb[j], 2).ToString() + strsProbLabels[j - 1];
                                }
                                else
                                {
                                    pCBRenderer.Label[j] = Math.Round(cb[j], 2).ToString() + strsProbLabels[j - 1] + " ~ " + Math.Round(cb[j + 1], 2).ToString() + strsProbLabels[j];
                                }
                                pUIProperties.LowBreak[j] = cb[j];
                                pSimpleMarkerSym          = new SimpleMarkerSymbolClass();
                                IRgbColor pRGBColor = m_pSnippet.getRGB(arrColors[j, 0], arrColors[j, 1], arrColors[j, 2]);
                                pSimpleMarkerSym.Color = (IColor)pRGBColor;
                                pCBRenderer.Symbol[j]  = (ISymbol)pSimpleMarkerSym;
                            }
                        }


                        IFeatureLayer pNewFLayer = new FeatureLayerClass();
                        pNewFLayer.FeatureClass = m_pFClass;
                        pNewFLayer.Name         = cboSAM.Text + " of " + m_pFLayer.Name;
                        IGeoFeatureLayer pGFLayer = (IGeoFeatureLayer)pNewFLayer;
                        pGFLayer.Renderer = (IFeatureRenderer)pCBRenderer;
                        m_pActiveView.FocusMap.AddLayer(pGFLayer);
                        m_pActiveView.Refresh();
                        m_pForm.axTOCControl1.Update();
                    }
                    else
                    {
                        MessageBox.Show("Complete. The results are stored in the shape file");
                    }
                    #endregion
                }

                this.Close();
            }
            catch (Exception ex)
            {
                frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog();
                return;
            }
        }
Exemplo n.º 16
0
        //Create Legend
        public void CreateLegend()
        {
            clsSnippet pSnippet = new clsSnippet();

            //Create Legend Group
            m_pLegendGroup          = new LegendGroup();
            m_pLegendGroup.Heading  = m_strOriRenderField;
            m_pLegendGroup.Editable = true;
            m_pLegendGroup.Visible  = true;

            ILegendClass legendClass = new LegendClass();

            legendClass.Label = Math.Round(dblMaxValue, 0).ToString();

            IStackedChartSymbol stackedChartSymbol = new StackedChartSymbolClass();

            //IBarChartSymbol barChartSymbol = new BarChartSymbolClass();
            stackedChartSymbol.Width = 10;
            if (bln3Dfeature)
            {
                I3DChartSymbol p3DChartSymbol = stackedChartSymbol as I3DChartSymbol;
                p3DChartSymbol.Display3D = true;
                p3DChartSymbol.Thickness = 3;
            }
            //IMarkerSymbol markerSymbol = stackedChartSymbol as IMarkerSymbol;
            //markerSymbol.Size = 50;
            IChartSymbol chartSymbol = stackedChartSymbol as IChartSymbol;

            chartSymbol.MaxValue = dblMaxValue;

            ISymbolArray symbolArray = stackedChartSymbol as ISymbolArray;
            //Stacked Symbol
            IFillSymbol fillSymbol = new SimpleFillSymbolClass();

            fillSymbol.Color         = pSnippet.getRGB(255, 0, 0);
            fillSymbol.Outline.Color = pSnippet.getRGB(0, 0, 0);
            symbolArray.AddSymbol(fillSymbol as ISymbol);
            chartSymbol.set_Value(0, dblMaxUncern);

            //fillSymbol = new SimpleFillSymbolClass();
            //fillSymbol.Color = pSnippet.getRGB(255, 0, 0);
            //fillSymbol.Outline.Color = pSnippet.getRGB(0, 0, 0);
            //symbolArray.AddSymbol(fillSymbol as ISymbol);
            //chartSymbol.set_Value(1, dblMaxUncern);

            fillSymbol               = new SimpleFillSymbolClass();
            fillSymbol.Color         = pSnippet.getRGB(255, 255, 255);
            fillSymbol.Outline.Color = pSnippet.getRGB(0, 0, 0);
            symbolArray.AddSymbol(fillSymbol as ISymbol);
            chartSymbol.set_Value(1, dblMaxEstimate - dblMaxUncern);

            legendClass.Symbol = (ISymbol)chartSymbol;
            m_pLegendGroup.AddClass(legendClass);

            //Bounds
            legendClass       = new LegendClass();
            legendClass.Label = "Upper Bound";
            ISimpleFillSymbol pLegendUncerSymbol = new SimpleFillSymbol();

            pLegendUncerSymbol.Color         = pSnippet.getRGB(0, 0, 255);
            pLegendUncerSymbol.Outline.Color = pSnippet.getRGB(0, 0, 0);

            legendClass.Symbol = (ISymbol)pLegendUncerSymbol;
            m_pLegendGroup.AddClass(legendClass);

            legendClass                      = new LegendClass();
            legendClass.Label                = "Lower Bound";
            pLegendUncerSymbol               = new SimpleFillSymbol();
            pLegendUncerSymbol.Color         = pSnippet.getRGB(255, 0, 0);
            pLegendUncerSymbol.Outline.Color = pSnippet.getRGB(0, 0, 0);

            legendClass.Symbol = (ISymbol)pLegendUncerSymbol;
            m_pLegendGroup.AddClass(legendClass);
        }
Exemplo n.º 17
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            if (cboFldnm1.Text == "" || cboFldnm2.Text == "")
            {
                MessageBox.Show("Please select target field");
                return;
            }

            frmProgress pfrmProgress = new frmProgress();

            pfrmProgress.lblStatus.Text    = "Processing:";
            pfrmProgress.pgbProgress.Style = ProgressBarStyle.Marquee;
            pfrmProgress.Show();

            REngine pEngine = m_pForm.pEngine;

            int nFeature = m_pFClass.FeatureCount(null);

            IFeatureCursor pFCursor = m_pFClass.Search(null, true);
            IFeature       pFeature = pFCursor.NextFeature();

            //Get index for independent and dependent variables
            //Get variable index
            string strVarNM1  = (string)cboFldnm1.SelectedItem;
            string strVarNM2  = (string)cboFldnm2.SelectedItem;
            int    intVarIdx1 = m_pFClass.FindField(strVarNM1);
            int    intVarIdx2 = m_pFClass.FindField(strVarNM2);

            //Store Variable at Array
            double[] arrVar1 = new double[nFeature];
            double[] arrVar2 = new double[nFeature];

            int i = 0;

            while (pFeature != null)
            {
                arrVar1[i] = Convert.ToDouble(pFeature.get_Value(intVarIdx1));
                arrVar2[i] = Convert.ToDouble(pFeature.get_Value(intVarIdx2));
                i++;
                pFeature = pFCursor.NextFeature();
            }

            pFCursor.Flush();

            //Plot command for R
            StringBuilder plotCommmand = new StringBuilder();

            string strStartPath = m_pForm.strPath;
            string pathr        = strStartPath.Replace(@"\", @"/");

            pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_LARRY.R')");
            pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_neighbor.R')");
            pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_SASbi.R')");

            //Get the file path and name to create spatial weight matrix
            string strNameR = m_pSnippet.FilePathinRfromLayer(m_pFLayer);

            if (strNameR == null)
            {
                return;
            }

            //Create spatial weight matrix in R
            pEngine.Evaluate("library(spdep); library(maptools)");
            pEngine.Evaluate("sample.shp <- readShapePoly('" + strNameR + "')");
            //pEngine.Evaluate("sample.nb <- poly2nb(sample.shp, queen=FALSE)");
            pEngine.Evaluate("sample.nb <- poly2nb(sample.shp)");

            NumericVector vecVar1 = pEngine.CreateNumericVector(arrVar1);

            pEngine.SetSymbol("sample.v1", vecVar1);
            NumericVector vecVar2 = pEngine.CreateNumericVector(arrVar2);

            pEngine.SetSymbol("sample.v2", vecVar2);

            //string strRSigLv = nudRsigLv.Value.ToString();
            //string strLSigLv = nudLsigLv.Value.ToString();
            //string strLSig = cboLocalL.Text;
            //string strRsig = cboLocalPearson.Text;
            //string strRowStd = cboRowStandardization.Text;
            //string strMaxRanges = nudMaxRange.Value.ToString();
            //string strHigherOrder = cboHigherOrder.Text;
            string strNonZero = null;

            if (chkDiagZero.Checked)
            {
                strNonZero = "FALSE";
            }
            else
            {
                strNonZero = "TRUE";
            }

            double[] dblLoclLisa = null;

            if (cboMeasure.Text == "Lee's L")
            {
                pEngine.Evaluate("sample.result <- LARRY.bivariate.LISA.lee(sample.v1, sample.v2, 1:length(sample.nb), sample.nb, style = 'W', diag.zero = " + strNonZero + ")");
                dblLoclLisa = pEngine.Evaluate("as.numeric(sample.result$local.L)").AsNumeric().ToArray();
            }
            else if (cboMeasure.Text == "Local Pearson")
            {
                pEngine.Evaluate("sample.result <- LARRY.bivariate.LISA.pearson(sample.v1, sample.v2, 1:length(sample.nb))");

                if (cboMapOption.Text == "Local Pearson")
                {
                    dblLoclLisa = pEngine.Evaluate("as.numeric(sample.result$local.pearson)").AsNumeric().ToArray();
                }
                else if (cboMapOption.Text == "z-score of variable 1")
                {
                    dblLoclLisa = pEngine.Evaluate("as.numeric(sample.result$z.x)").AsNumeric().ToArray();
                }
                else if (cboMapOption.Text == "z-score of variable 2")
                {
                    dblLoclLisa = pEngine.Evaluate("as.numeric(sample.result$z.y)").AsNumeric().ToArray();
                }
            }

            //Save Output on SHP
            //Add Target fields to store results in the shapefile // Keep loop
            for (int j = 0; j < 1; j++)
            {
                string strfldName = lvFields.Items[j].SubItems[1].Text;
                if (m_pFClass.FindField(strfldName) == -1)
                {
                    IField     newField  = new FieldClass();
                    IFieldEdit fieldEdit = (IFieldEdit)newField;
                    fieldEdit.Name_2 = strfldName;
                    fieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
                    m_pFClass.AddField(newField);
                }
            }

            //Update Field
            pFCursor = m_pFClass.Update(null, false);
            pFeature = pFCursor.NextFeature();

            string strLocalLISAFldName = lvFields.Items[0].SubItems[1].Text;
            int    intSpQuadFldIdx     = m_pFClass.FindField(strLocalLISAFldName);

            int featureIdx = 0;

            while (pFeature != null)
            {
                pFeature.set_Value(intSpQuadFldIdx, dblLoclLisa[featureIdx]);

                pFCursor.UpdateFeature(pFeature);

                pFeature = pFCursor.NextFeature();
                featureIdx++;
            }
            pFCursor.Flush();

            if (chkMap.Checked)
            {
                ITable pTable = (ITable)m_pFClass;

                pFCursor = m_pFClass.Search(null, false);
                IDataStatistics pDataStat = new DataStatisticsClass();
                pDataStat.Field  = strLocalLISAFldName;
                pDataStat.Cursor = (ICursor)pFCursor;

                IStatisticsResults pStatResults = pDataStat.Statistics;
                double             dblMax       = pStatResults.Maximum;
                double             dblMin       = pStatResults.Minimum;

                int      intBreaksCount = m_pBiLISASym.Length + 1;
                double[] cb             = new double[intBreaksCount];

                //Assign Min and Max values for class breaks
                cb[0] = dblMin;
                cb[intBreaksCount - 1] = dblMax;

                for (int k = 0; k < intBreaksCount - 2; k++)
                {
                    cb[k + 1] = m_pBiLISASym[k].UValue;
                }

                IClassBreaksRenderer pCBRenderer = new ClassBreaksRenderer();
                pCBRenderer.Field        = strLocalLISAFldName;
                pCBRenderer.BreakCount   = intBreaksCount - 1;
                pCBRenderer.MinimumBreak = cb[0];

                //' use this interface to set dialog properties
                IClassBreaksUIProperties pUIProperties = (IClassBreaksUIProperties)pCBRenderer;
                pUIProperties.ColorRamp = "Custom";
                ISimpleFillSymbol pSimpleFillSym;

                //int[,] arrColors = CreateColorRamp();

                ////Add Probability Value Manually
                //string[] strsProbLabels = new string[] { "(0.01)", "(0.05)", "(0.1)", "(0.1)", "(0.05)", "(0.01)" };

                //' be careful, indices are different for the diff lists
                for (int j = 0; j < intBreaksCount - 1; j++)
                {
                    pCBRenderer.Break[j] = cb[j + 1];
                    pCBRenderer.Label[j] = m_pBiLISASym[j].Label;

                    pUIProperties.LowBreak[j] = cb[j];
                    pSimpleFillSym            = new SimpleFillSymbolClass();
                    IRgbColor pRGBColor = m_pSnippet.getRGB(m_pBiLISASym[j].R, m_pBiLISASym[j].G, m_pBiLISASym[j].B);
                    pSimpleFillSym.Color  = (IColor)pRGBColor;
                    pCBRenderer.Symbol[j] = (ISymbol)pSimpleFillSym;
                }

                IFeatureLayer pNewFLayer = new FeatureLayerClass();
                pNewFLayer.FeatureClass = m_pFClass;
                pNewFLayer.Name         = lvFields.Items[0].SubItems[0].Text + " of " + m_pFLayer.Name;
                IGeoFeatureLayer pGFLayer = (IGeoFeatureLayer)pNewFLayer;
                pGFLayer.Renderer = (IFeatureRenderer)pCBRenderer;
                m_pActiveView.FocusMap.AddLayer(pGFLayer);
                m_pActiveView.Refresh();
                m_pForm.axTOCControl1.Update();

                pfrmProgress.Close();
            }
            else
            {
                MessageBox.Show("Complete. The results are stored in the shape file");
            }
        }
Exemplo n.º 18
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            if (cboFldnm1.Text == "" || cboFldnm2.Text == "")
            {
                MessageBox.Show("Please select target field");
                return;
            }

            frmProgress pfrmProgress = new frmProgress();

            pfrmProgress.lblStatus.Text    = "Processing:";
            pfrmProgress.pgbProgress.Style = ProgressBarStyle.Marquee;
            pfrmProgress.Show();

            REngine pEngine = m_pForm.pEngine;

            int nFeature = m_pFClass.FeatureCount(null);

            IFeatureCursor pFCursor = m_pFClass.Search(null, true);
            IFeature       pFeature = pFCursor.NextFeature();

            //Get index for independent and dependent variables
            //Get variable index
            string strVarNM1  = (string)cboFldnm1.SelectedItem;
            string strVarNM2  = (string)cboFldnm2.SelectedItem;
            int    intVarIdx1 = m_pFClass.FindField(strVarNM1);
            int    intVarIdx2 = m_pFClass.FindField(strVarNM2);
            int    intFIDIdx  = m_pFClass.FindField(m_pFClass.OIDFieldName);

            //Store Variable at Array
            double[] arrVar1 = new double[nFeature];
            double[] arrVar2 = new double[nFeature];

            int[] arrFID = new int[nFeature];

            int i = 0;

            while (pFeature != null)
            {
                arrVar1[i] = Convert.ToDouble(pFeature.get_Value(intVarIdx1));
                arrVar2[i] = Convert.ToDouble(pFeature.get_Value(intVarIdx2));
                arrFID[i]  = Convert.ToInt32(pFeature.get_Value(intFIDIdx));
                i++;
                pFeature = pFCursor.NextFeature();
            }

            pFCursor.Flush();

            //Plot command for R
            StringBuilder plotCommmand = new StringBuilder();

            string strStartPath = m_pForm.strPath;
            string pathr        = strStartPath.Replace(@"\", @"/");

            pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_LARRY.R')");
            pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_neighbor.R')");
            pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_SASbi.R')");

            //Get the file path and name to create spatial weight matrix
            string strNameR = m_pSnippet.FilePathinRfromLayer(m_pFLayer);

            if (strNameR == null)
            {
                return;
            }

            //Create spatial weight matrix in R
            pEngine.Evaluate("library(spdep); library(maptools)");
            pEngine.Evaluate("sample.shp <- readShapePoly('" + strNameR + "')");
            //pEngine.Evaluate("sample.nb <- poly2nb(sample.shp, queen=FALSE)");
            pEngine.Evaluate("sample.nb <- poly2nb(sample.shp)");

            NumericVector vecVar1 = pEngine.CreateNumericVector(arrVar1);

            pEngine.SetSymbol("sample.v1", vecVar1);
            NumericVector vecVar2 = pEngine.CreateNumericVector(arrVar2);

            pEngine.SetSymbol("sample.v2", vecVar2);

            string strNonZero = null;

            if (chkDiagZero.Checked)
            {
                strNonZero = "FALSE";
            }
            else
            {
                strNonZero = "TRUE";
            }
            string strSigLv = nudSigLv.Value.ToString();

            string[] strSPQuadrants = null;

            //double[] adblVar1 = null;
            //double[] adblVar2 = null;
            //NumericVector vecCoeff = null;
            if (cboMeasure.Text == "Lee's L")
            {
                pEngine.Evaluate("sample.result <- LARRY.bivariate.sig.quad.lee(sample.v1, sample.v2, 1:length(sample.nb), sample.nb, style = 'W', sig.level=c(" + strSigLv + "), method='" + cboMethod.Text + "', alternative='" + txtAlternative.Text + "', diag.zero = " + strNonZero + ")");

                //pEngine.Evaluate("sample.result <- LARRY.bivariate.sig.quad.lee(sample.v1, sample.v2, 1:length(sample.nb), sample.nb, style = 'W', sig.level=c(" + strSigLv + "), method='total', alternative='two.sided', diag.zero = " + strNonZero + ")");
                strSPQuadrants = pEngine.Evaluate("as.character(sample.result[[6]])").AsCharacter().ToArray();
            }
            else if (cboMeasure.Text == "Local Pearson")
            {
                pEngine.Evaluate("sample.result <- LARRY.bivariate.sig.quad.pearson(sample.v1, sample.v2, 1:length(sample.nb), sig.level=c(" + strSigLv + ", 0.01), method='" + cboMethod.Text + "', alternative='" + txtAlternative.Text + "')");

                //pEngine.Evaluate("sample.result <- LARRY.bivariate.sig.quad.pearson(sample.v1, sample.v2, 1:length(sample.nb), sig.level=c(" + strSigLv + "), method='total', alternative='two.sided')");
                strSPQuadrants = pEngine.Evaluate("as.character(sample.result[[6]])").AsCharacter().ToArray();
            }

            //Save Output on SHP
            //Add Target fields to store results in the shapefile // Keep loop
            for (int j = 0; j < 1; j++)
            {
                string strfldName = lvFields.Items[j].SubItems[1].Text;
                if (m_pFClass.FindField(strfldName) == -1)
                {
                    IField     newField  = new FieldClass();
                    IFieldEdit fieldEdit = (IFieldEdit)newField;
                    fieldEdit.Name_2 = strfldName;
                    fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                    m_pFClass.AddField(newField);
                }
            }

            //Update Field
            pFCursor = m_pFClass.Update(null, false);
            pFeature = pFCursor.NextFeature();

            string strSpQuadFldName = lvFields.Items[0].SubItems[1].Text;
            int    intSpQuadFldIdx  = m_pFClass.FindField(strSpQuadFldName);

            int featureIdx = 0;

            while (pFeature != null)
            {
                pFeature.set_Value(intSpQuadFldIdx, strSPQuadrants[featureIdx]);

                pFCursor.UpdateFeature(pFeature);

                pFeature = pFCursor.NextFeature();
                featureIdx++;
            }
            pFCursor.Flush();

            if (chkMap.Checked)
            {
                ITable pTable = (ITable)m_pFClass;

                IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass();
                pUniqueValueRenderer.FieldCount = 1;
                pUniqueValueRenderer.set_Field(0, strSpQuadFldName);

                if (cboMaptype.Text == "choropleth map")
                {
                    ISimpleFillSymbol pSymbol;
                    IQueryFilter      pQFilter = new QueryFilterClass();
                    int    intTotalCount       = 0;
                    string strLabel            = null;

                    for (int j = 0; j < 5; j++)
                    {
                        pSymbol       = new SimpleFillSymbolClass();
                        pSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
                        pSymbol.Color = m_pSnippet.getRGB(m_pQuadrantSymbols[j].R, m_pQuadrantSymbols[j].G, m_pQuadrantSymbols[j].B);

                        pQFilter.WhereClause = strSpQuadFldName + " = '" + m_pQuadrantSymbols[j].Value + "'";

                        intTotalCount = pTable.RowCount(pQFilter);

                        strLabel = m_pQuadrantSymbols[j].Label + " (" + intTotalCount.ToString() + ")";
                        pUniqueValueRenderer.AddValue(m_pQuadrantSymbols[j].Value, null, (ISymbol)pSymbol);
                        pUniqueValueRenderer.set_Label(m_pQuadrantSymbols[j].Value, strLabel);
                    }
                    pUniqueValueRenderer.UseDefaultSymbol = false;
                }
                else if (cboMaptype.Text == "point map")
                {
                    ICharacterMarkerSymbol pSymbol;
                    stdole.IFontDisp       stdFontCls = ((stdole.IFontDisp)(new stdole.StdFont()));
                    stdFontCls.Name = "ESRI NIMA VMAP1&2 PT";
                    stdFontCls.Size = 10;

                    IQueryFilter pQFilter      = new QueryFilterClass();
                    int          intTotalCount = 0;
                    string       strLabel      = null;

                    for (int j = 0; j < 4; j++)
                    {
                        ////Without hallo
                        //pSymbol = new CharacterMarkerSymbolClass();
                        //pSymbol.CharacterIndex = 248;
                        ////pSymbol.Color = m_pSnippet.getRGB(m_pQuadrantSymbols[j].R, m_pQuadrantSymbols[j].G, m_pQuadrantSymbols[j].B);
                        //pSymbol.Size = 10;
                        //pSymbol.Font = stdFontCls;

                        //pSymbol.Angle = m_pQuadrantSymbols[j].Angle;

                        //With hallo
                        pSymbol = new CharacterMarkerSymbolClass();
                        pSymbol.CharacterIndex = 248;
                        //pSymbol.Color = m_pSnippet.getRGB(m_pQuadrantSymbols[j].R, m_pQuadrantSymbols[j].G, m_pQuadrantSymbols[j].B);
                        pSymbol.Size = 10;
                        pSymbol.Font = stdFontCls;

                        pSymbol.Angle = m_pQuadrantSymbols[j].Angle;

                        //Create a Fill Symbol for the Mask
                        ISimpleFillSymbol smpFill = new SimpleFillSymbol();
                        smpFill.Color = m_pSnippet.getRGB(0, 0, 0);
                        smpFill.Style = esriSimpleFillStyle.esriSFSSolid;
                        //Create a MultiLayerMarkerSymbol
                        IMultiLayerMarkerSymbol multiLyrMrk = new MultiLayerMarkerSymbol();
                        //Add the simple marker to the MultiLayer
                        multiLyrMrk.AddLayer(pSymbol);
                        //Create a Mask for the MultiLayerMarkerSymbol
                        IMask mrkMask = (IMask)multiLyrMrk;
                        mrkMask.MaskSymbol = smpFill;
                        mrkMask.MaskStyle  = esriMaskStyle.esriMSHalo;
                        mrkMask.MaskSize   = 0.5;

///to here
                        pQFilter.WhereClause = strSpQuadFldName + " = '" + m_pQuadrantSymbols[j].Value + "'";

                        intTotalCount = pTable.RowCount(pQFilter);

                        strLabel = m_pQuadrantSymbols[j].Label + " (" + intTotalCount.ToString() + ")";
                        pUniqueValueRenderer.AddValue(m_pQuadrantSymbols[j].Value, null, (ISymbol)pSymbol);
                        pUniqueValueRenderer.set_Label(m_pQuadrantSymbols[j].Value, strLabel);
                    }
                    pUniqueValueRenderer.UseDefaultSymbol = false;
                }
                IFeatureLayer pNewFLayer = new FeatureLayerClass();
                pNewFLayer.FeatureClass = m_pFClass;
                pNewFLayer.Name         = "Bivariate Spatial Significant Quadrant";
                IGeoFeatureLayer pGFLayer = (IGeoFeatureLayer)pNewFLayer;
                pGFLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer;
                m_pActiveView.FocusMap.AddLayer(pGFLayer);
                m_pActiveView.Refresh();
                m_pForm.axTOCControl1.Update();
            }
            pfrmProgress.Close();
        }
Exemplo n.º 19
0
        private void DrawPointsOnActiveView(int colindex, int rowindex, IRasterProps pRasterProps, IActiveView ActiveView)
        {
            IGraphicsContainer pGraphicContainer = ActiveView.GraphicsContainer;

            IRgbColor pRgbColor = m_pSnippet.getRGB(0, 255, 255);

            //ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass();
            //pSimpleLineSymbol.Width = 2;
            //pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
            //pSimpleLineSymbol.Color = pRgbColor;

            ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass();

            pSimpleMarkerSymbol.Size  = 8;
            pSimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle;
            pSimpleMarkerSymbol.Color = pRgbColor;

            double dblX = 0, dblY = 0;
            double dblCellSize = Convert.ToDouble(pRasterProps.MeanCellSize().X);

            dblX = pRasterProps.Extent.XMin + (dblCellSize / 2) + dblCellSize * colindex;
            dblY = pRasterProps.Extent.YMax - (dblCellSize / 2) - dblCellSize * rowindex;

            IPoint pPoint = new PointClass();

            pPoint.X = dblX;
            pPoint.Y = dblY;

            IElement pElement = new MarkerElementClass();

            IMarkerElement pMarkerElement = (IMarkerElement)pElement;

            pMarkerElement.Symbol = pSimpleMarkerSymbol;
            pElement.Geometry     = pPoint;

            pGraphicContainer.AddElement(pElement, 0);

            ActiveView.Refresh();
            //for (int i = 0; i < intLstCnt; i++)
            //{
            //    int intIdx = lstIndices[i];
            //    double[] arrSelValue = arrValue[intIdx];
            //    //drawing a polyline
            //    IPoint FromP = new PointClass();
            //    FromP.X = arrSelValue[0]; FromP.Y = arrSelValue[1];

            //    IPoint ToP = new PointClass();
            //    ToP.X = arrSelValue[2]; ToP.Y = arrSelValue[3];

            //    IPolyline polyline = new PolylineClass();
            //    IPointCollection pointColl = polyline as IPointCollection;
            //    pointColl.AddPoint(FromP);
            //    pointColl.AddPoint(ToP);

            //    IElement pElement = new LineElementClass();

            //    ILineElement pLineElement = (ILineElement)pElement;
            //    pLineElement.Symbol = pSimpleLineSymbol;
            //    pElement.Geometry = polyline;

            //    pGraphicContainer.AddElement(pElement, 0);
            //}

            //pActiveView.Refresh();
        }
Exemplo n.º 20
0
        private void axTOCControl1_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e)
        {
            try
            {
                esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone;
                IBasicMap          map = null; ILayer layer = null;
                object             other = null; object index = null;

                //Determine what kind of item is selected
                m_tocControl.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);

                if (item == esriTOCControlItem.esriTOCControlItemNone)
                {
                    return;
                }

                // Load TOC context menu
                if (e.button == 2)
                {
                    if (item == esriTOCControlItem.esriTOCControlItemMap)
                    {
                        m_tocControl.SelectItem(map, null);
                    }
                    else
                    {
                        m_tocControl.SelectItem(layer, null);
                    }

                    //Set the layer into the CustomProperty (this is used by the custom layer commands)
                    m_mapControl.CustomProperty = layer;

                    //Popup the correct context menu
                    if (item == esriTOCControlItem.esriTOCControlItemMap)
                    {
                        return;
                    }
                    if (item == esriTOCControlItem.esriTOCControlItemLayer)
                    {
                        m_menuLayer.PopupMenu(e.x, e.y, m_tocControl.hWnd);
                    }
                }
                //Ensure the item gets selected

                //Load Simple Color pallette 071017 HK
                if (e.button == 1 && item == esriTOCControlItem.esriTOCControlItemLegendClass)
                {
                    IFeatureLayer    featureLayer    = layer as IFeatureLayer;
                    IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)featureLayer;

                    DialogResult DR;
                    if (geoFeatureLayer.Renderer is ISimpleRenderer) // Only apply this function to simple Renderer
                    {
                        DR = cdColor.ShowDialog();
                    }
                    else
                    {
                        return;
                    }

                    IRgbColor pRGBcolor = new RgbColorClass();
                    if (DR == DialogResult.OK)
                    {
                        pRGBcolor = m_pSnippet.getRGB(cdColor.Color.R, cdColor.Color.G, cdColor.Color.B);
                    }

                    ISimpleRenderer simpleRenderer = (ISimpleRenderer)geoFeatureLayer.Renderer;

                    ISymbol pSymbol = simpleRenderer.Symbol;

                    //Update only color
                    switch (featureLayer.FeatureClass.ShapeType)
                    {
                    case esriGeometryType.esriGeometryPoint:
                        ISimpleMarkerSymbol pSimpleMarkerSymobl = (ISimpleMarkerSymbol)pSymbol;
                        pSimpleMarkerSymobl.Color = (IColor)pRGBcolor;
                        pSymbol = (ISymbol)pSimpleMarkerSymobl;
                        break;

                    case esriGeometryType.esriGeometryPolyline:
                        ISimpleLineSymbol pSimpleLineSymobl = (ISimpleLineSymbol)pSymbol;
                        pSimpleLineSymobl.Color = (IColor)pRGBcolor;
                        pSymbol = (ISymbol)pSimpleLineSymobl;
                        break;

                    case esriGeometryType.esriGeometryPolygon:
                        ISimpleFillSymbol pSimpleFillSymobl = (ISimpleFillSymbol)pSymbol;
                        pSimpleFillSymobl.Color = (IColor)pRGBcolor;
                        pSymbol = (ISymbol)pSimpleFillSymobl;

                        break;
                    }
                    simpleRenderer.Symbol    = pSymbol;
                    geoFeatureLayer.Renderer = (IFeatureRenderer)simpleRenderer;
                    m_tocControl.ActiveView.ContentsChanged();
                    m_mapControl.Refresh(esriViewDrawPhase.esriViewGeography, null, null);
                }
            }
            catch (Exception ex)
            {
                frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog();
                return;
            }
        }
Exemplo n.º 21
0
        private void CreateAlgorimcColorRamps(string strAlgorithm, int intDefault)
        {
            try
            {
                IAlgorithmicColorRamp pColorRamp = new AlgorithmicColorRampClass();

                switch (strAlgorithm)
                {
                case "HSV":
                    pColorRamp.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm;
                    break;

                case "CIE Lab":
                    pColorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
                    break;

                case "Lab LCh":
                    pColorRamp.Algorithm = esriColorRampAlgorithm.esriLabLChAlgorithm;
                    break;

                default:
                    pColorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
                    break;
                }

                IRgbColor pColor1 = new RgbColorClass();
                IRgbColor pColor2 = new RgbColorClass();

                //Can Change the color in here!
                pColor1 = pSnippet.getRGB(arrTotalColors[intRampsCounts, 0], arrTotalColors[intRampsCounts, 1], arrTotalColors[intRampsCounts, 2]);
                pColor2 = pSnippet.getRGB(arrTotalColors[intRampsCounts, 3], arrTotalColors[intRampsCounts, 4], arrTotalColors[intRampsCounts, 5]);

                if (pColor1 == null || pColor2 == null)
                {
                    return;
                }

                Boolean blnOK = true;

                pColorRamp.FromColor = pColor1;
                pColorRamp.ToColor   = pColor2;
                pColorRamp.Size      = intDefault;
                pColorRamp.CreateRamp(out blnOK);

                arrListviewColors = new int[intDefault, 3];
                pEnumColors       = pColorRamp.Colors;
                pEnumColors.Reset();

                for (int k = 0; k < intDefault; k++)
                {
                    IColor    pColor    = pEnumColors.Next();
                    IRgbColor pRGBColor = new RgbColorClass();
                    pRGBColor.RGB = pColor.RGB;

                    arrListviewColors[k, 0] = pRGBColor.Red;
                    arrListviewColors[k, 1] = pRGBColor.Green;
                    arrListviewColors[k, 2] = pRGBColor.Blue;
                }

                pEnumColors.Reset();
            }
            catch (Exception ex)
            {
                frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog();
                return;
            }
        }
Exemplo n.º 22
0
        private void btnApply_Click(object sender, EventArgs e)
        {
            try
            {
                //Declare variables
                clsSnippet pSnippet     = new clsSnippet();
                string     strLayerName = cboSourceLayer.Text;

                int    intLIndex = pSnippet.GetIndexNumberFromLayerName(pActiveView, strLayerName);
                ILayer pLayer    = mForm.axMapControl1.get_Layer(intLIndex);

                IFeatureLayer pFLayer = pLayer as IFeatureLayer;
                IFeatureClass pFClass = pFLayer.FeatureClass;

                string strOriRenderField    = cboValueField.Text;
                string strUncernRenderField = CboUField.Text;
                string strConLevelField     = nudConfidenceLevel.Value.ToString();

                if (strOriRenderField == "" || strUncernRenderField == "")
                {
                    MessageBox.Show("Plese choose field names");
                    return;
                }

                //Find Fields
                ITable pTable       = (ITable)pFClass;
                int    intOriIdx    = pTable.FindField(strOriRenderField);
                int    intUncernIdx = pTable.FindField(strUncernRenderField);

                //Create Geofeature Layer
                IGeoFeatureLayer pGeofeatureLayer = null;
                if (chkNewLayer.Checked == true)
                {
                    IFeatureLayer pflOutput = new FeatureLayerClass();
                    pflOutput.FeatureClass = pFClass;
                    pflOutput.Name         = txtNewLayer.Text;
                    pflOutput.Visible      = true;
                    pGeofeatureLayer       = (IGeoFeatureLayer)pflOutput;
                }
                else
                {
                    pGeofeatureLayer = (IGeoFeatureLayer)pFLayer;
                }

                //Calculate confidence levels
                Chart  pChart         = new Chart();
                double dblConInstance = pChart.DataManipulator.Statistics.InverseNormalDistribution(Convert.ToDouble(nudConfidenceLevel.Value) / 100);


                if (tcUncer.SelectedIndex == 0) //Proportional symbol composite layers
                {
                    double dblMinPtSize = Convert.ToDouble(nudSymbolSize.Value);

                    //Find max value at attribute to set to initial value for finding Min value at composite symbols
                    IField          pOriField = pTable.Fields.get_Field(intOriIdx);
                    ICursor         pCursor   = pTable.Search(null, false);
                    IDataStatistics pDataStat = new DataStatisticsClass();
                    pDataStat.Field  = pOriField.Name;
                    pDataStat.Cursor = pCursor;
                    IStatisticsResults pStatResults = pDataStat.Statistics;

                    double dblMinValue = pStatResults.Maximum;
                    pCursor.Flush();

                    pCursor = pTable.Search(null, false);
                    IRow   pRow     = pCursor.NextRow();
                    double dblValue = 0;

                    //Cacluate Min and Max value based on the confidence intervals
                    //Min
                    while (pRow != null)
                    {
                        dblValue = Convert.ToDouble(pRow.get_Value(intOriIdx)) - (Convert.ToDouble(pRow.get_Value(intUncernIdx)) * dblConInstance);
                        if (dblValue < dblMinValue)
                        {
                            dblMinValue = dblValue;
                        }
                        pRow = pCursor.NextRow();
                    }

                    //Max
                    pCursor.Flush();

                    double dblMaxValue = 0;
                    pCursor  = pTable.Search(null, false);
                    pRow     = pCursor.NextRow();
                    dblValue = 0;

                    //Cacluate Min and Max value based on the confidence intervals
                    while (pRow != null)
                    {
                        dblValue = Convert.ToDouble(pRow.get_Value(intOriIdx)) + (Convert.ToDouble(pRow.get_Value(intUncernIdx)) * dblConInstance);
                        if (dblValue > dblMaxValue)
                        {
                            dblMaxValue = dblValue;
                        }
                        pRow = pCursor.NextRow();
                    }


                    //To adjust min value to 1, if the min value is zero
                    double dbladjuctMinvalue = 0;
                    if (dblMinValue <= 0)
                    {
                        dbladjuctMinvalue = (0 - dblMinValue) + 1;
                        dblMinValue       = dblMinValue + dbladjuctMinvalue;
                    }


                    //Loading uncertainty proportional symbol renderer
                    IDisplay pDisplay = pActiveView.ScreenDisplay;

                    UncernVis.BivariateRenderer.IPropCompositeRenderer pUnProprotional = new UncernVis.BivariateRenderer.PropCompositeRenderer();

                    pUnProprotional.m_dblMinPtSize = dblMinPtSize;
                    pUnProprotional.m_dblMinValue  = dblMinValue;
                    pUnProprotional.m_dblMaxValue  = dblMaxValue;

                    pUnProprotional.m_dblOutlineSize      = Convert.ToDouble(nudLinewidth.Value);
                    pUnProprotional.m_dblAdjustedMinValue = dbladjuctMinvalue;

                    IRgbColor pSymbolRgb = new RgbColorClass();
                    pSymbolRgb.Red   = picSymbolColor.BackColor.R;
                    pSymbolRgb.Green = picSymbolColor.BackColor.G;
                    pSymbolRgb.Blue  = picSymbolColor.BackColor.B;

                    IRgbColor pLineRgb = new RgbColorClass();
                    pLineRgb.Red   = picLineColor.BackColor.R;
                    pLineRgb.Green = picLineColor.BackColor.G;
                    pLineRgb.Blue  = picLineColor.BackColor.B;

                    pUnProprotional.m_pLineRgb   = pLineRgb;
                    pUnProprotional.m_pSymbolRgb = pSymbolRgb;

                    pUnProprotional.m_strUncernRenderField = strUncernRenderField;
                    pUnProprotional.m_strOriRenderField    = strOriRenderField;

                    pUnProprotional.m_dblConInstance = dblConInstance;
                    pUnProprotional.m_pGeometryTypes = pFClass.ShapeType;

                    //Create Legend
                    pUnProprotional.CreateLegend();

                    pGeofeatureLayer.Renderer = (IFeatureRenderer)pUnProprotional;


                    if (chkNewLayer.Checked == true)
                    {
                        mForm.axMapControl1.ActiveView.FocusMap.AddLayer(pGeofeatureLayer);
                    }
                    else
                    {
                        pFLayer = (IFeatureLayer)pGeofeatureLayer;
                    }
                }
                else if (tcUncer.SelectedIndex == 1) // Chart composite symbols
                {
                    double dblChartWidth = Convert.ToDouble(nudChartWidth.Value);
                    double dblChartSize  = Convert.ToDouble(nudChartSize.Value);
                    double dblThickness  = Convert.ToDouble(nudThickness.Value);

                    //Cacluate Max value based on the confidence intervals
                    ICursor pCursor = (ICursor)pFClass.Search(null, false);

                    IRow   pRow            = pCursor.NextRow();
                    double dblMaxValue     = 0;
                    double dblTempValue    = 0;
                    double dblMaxEstimate  = 0;
                    double dblMaxUncern    = 0;
                    double dblTempEstimate = 0;
                    double dblTempUncern   = 0;

                    while (pRow != null)
                    {
                        dblTempEstimate = Convert.ToDouble(pRow.get_Value(intOriIdx));
                        dblTempUncern   = Convert.ToDouble(pRow.get_Value(intUncernIdx)) * dblConInstance;
                        dblTempValue    = dblTempEstimate + dblTempUncern;

                        if (dblTempValue > dblMaxValue)
                        {
                            dblMaxValue    = dblTempValue;
                            dblMaxEstimate = dblTempEstimate;
                            dblMaxUncern   = dblTempUncern;
                        }
                        pRow = pCursor.NextRow();
                    }
                    pCursor.Flush();


                    //IFeatureCursor pFCursor = pGeofeatureLayer.Search(null, true);

                    IChartCompositeRenderer pChartCompositeRenderer = new ChartCompositeRenderer();

                    pChartCompositeRenderer.m_dblConInstance = dblConInstance;

                    pChartCompositeRenderer.m_dblMaxValue          = dblMaxValue;
                    pChartCompositeRenderer.m_bln3Dfeature         = chk3D.Checked;
                    pChartCompositeRenderer.m_strOriRenderField    = strOriRenderField;
                    pChartCompositeRenderer.m_strUncernRenderField = strUncernRenderField;

                    pChartCompositeRenderer.m_dblMaxEstimate = dblMaxEstimate;
                    pChartCompositeRenderer.m_dblMaxUncern   = dblMaxUncern;

                    pChartCompositeRenderer.m_dblBarWidth  = dblChartWidth;
                    pChartCompositeRenderer.m_dblBarSize   = dblChartSize;
                    pChartCompositeRenderer.m_dblThickness = dblThickness;

                    pChartCompositeRenderer.CreateLegend();
                    pGeofeatureLayer.Renderer = pChartCompositeRenderer as IFeatureRenderer;
                    if (chkNewLayer.Checked == true)
                    {
                        mForm.axMapControl1.ActiveView.FocusMap.AddLayer(pGeofeatureLayer);
                    }
                    else
                    {
                        pFLayer = (IFeatureLayer)pGeofeatureLayer;
                    }
                }
                else if (tcUncer.SelectedIndex == 2) //For Line Symbol
                {
                    double dblMinPtSize = Convert.ToDouble(nudMinWidth.Value);

                    //Find max value at attribute to set to initial value for finding Min value at composite symbols
                    IField          pOriField = pTable.Fields.get_Field(intOriIdx);
                    ICursor         pCursor   = pTable.Search(null, false);
                    IDataStatistics pDataStat = new DataStatisticsClass();
                    pDataStat.Field  = pOriField.Name;
                    pDataStat.Cursor = pCursor;
                    IStatisticsResults pStatResults = pDataStat.Statistics;

                    double dblMinValue = pStatResults.Maximum;
                    pCursor.Flush();

                    pCursor = pTable.Search(null, false);
                    IRow   pRow     = pCursor.NextRow();
                    double dblValue = 0;

                    //Cacluate Min and Max value based on the confidence intervals
                    //Min
                    while (pRow != null)
                    {
                        dblValue = Convert.ToDouble(pRow.get_Value(intOriIdx)) - (Convert.ToDouble(pRow.get_Value(intUncernIdx)) * dblConInstance);
                        if (dblValue < dblMinValue)
                        {
                            dblMinValue = dblValue;
                        }
                        pRow = pCursor.NextRow();
                    }

                    //Max
                    pCursor.Flush();

                    double dblMaxValue = 0;
                    pCursor  = pTable.Search(null, false);
                    pRow     = pCursor.NextRow();
                    dblValue = 0;

                    //Cacluate Min and Max value based on the confidence intervals
                    while (pRow != null)
                    {
                        dblValue = Convert.ToDouble(pRow.get_Value(intOriIdx)) + (Convert.ToDouble(pRow.get_Value(intUncernIdx)) * dblConInstance);
                        if (dblValue > dblMaxValue)
                        {
                            dblMaxValue = dblValue;
                        }
                        pRow = pCursor.NextRow();
                    }


                    //To adjust min value to 1, if the min value is zero
                    double dbladjuctMinvalue = 0;
                    if (dblMinValue <= 0)
                    {
                        dbladjuctMinvalue = (0 - dblMinValue) + 1;
                        dblMinValue       = dblMinValue + dbladjuctMinvalue;
                    }


                    //Loading uncertainty proportional symbol renderer
                    IDisplay pDisplay = pActiveView.ScreenDisplay;

                    UncernVis.BivariateRenderer.IPropCompositeRenderer pUnProprotional = new UncernVis.BivariateRenderer.PropCompositeRenderer();

                    pUnProprotional.m_dblMinPtSize = dblMinPtSize;
                    pUnProprotional.m_dblMinValue  = dblMinValue;
                    pUnProprotional.m_dblMaxValue  = dblMaxValue;

                    pUnProprotional.m_dblOutlineSize      = 0;
                    pUnProprotional.m_dblAdjustedMinValue = dbladjuctMinvalue;

                    IRgbColor pSymbolRgb = pSnippet.getRGB(picLineConColor.BackColor.R, picLineConColor.BackColor.G, picLineConColor.BackColor.B);
                    //pSymbolRgb.Red = picSymbolColor.BackColor.R;
                    //pSymbolRgb.Green = picSymbolColor.BackColor.G;
                    //pSymbolRgb.Blue = picSymbolColor.BackColor.B;

                    IRgbColor pLineRgb = pSnippet.getRGB(picLineCntColor.BackColor.R, picLineCntColor.BackColor.G, picLineCntColor.BackColor.B);
                    //pLineRgb.Red = picLineColor.BackColor.R;
                    //pLineRgb.Green = picLineColor.BackColor.G;
                    //pLineRgb.Blue = picLineColor.BackColor.B;

                    pUnProprotional.m_pLineRgb   = pLineRgb;
                    pUnProprotional.m_pSymbolRgb = pSymbolRgb;

                    pUnProprotional.m_strUncernRenderField = strUncernRenderField;
                    pUnProprotional.m_strOriRenderField    = strOriRenderField;

                    pUnProprotional.m_dblConInstance = dblConInstance;
                    pUnProprotional.m_pGeometryTypes = pFClass.ShapeType;

                    //Create Legend
                    pUnProprotional.CreateLegend();

                    pGeofeatureLayer.Renderer = (IFeatureRenderer)pUnProprotional;


                    if (chkNewLayer.Checked == true)
                    {
                        mForm.axMapControl1.ActiveView.FocusMap.AddLayer(pGeofeatureLayer);
                    }
                    else
                    {
                        pFLayer = (IFeatureLayer)pGeofeatureLayer;
                    }
                }

                mForm.axMapControl1.ActiveView.Refresh();
                mForm.axTOCControl1.Update();
            }
            catch (Exception ex)
            {
                frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog();
                return;
            }
        }
Exemplo n.º 23
0
        private void btnApply_Click(object sender, EventArgs e)
        {
            //Choropleth mapping : Exactly same with the function in frmChoroplethwithOverlay HK102915
            string strLayerName = cboSourceLayer.Text;

            if (cboSourceLayer.Text == "" || cboValueField.Text == "" || cboUField.Text == "")
            {
                MessageBox.Show("Assign proper layer and field");
                return;
            }

            int    intLIndex = pSnippet.GetIndexNumberFromLayerName(pActiveView, strLayerName);
            ILayer pLayer    = mForm.axMapControl1.get_Layer(intLIndex);

            IFeatureLayer pFLayer = pLayer as IFeatureLayer;
            IFeatureClass pFClass = pFLayer.FeatureClass;

            //Create Rendering of Mean Value at Target Layer
            int    intGCBreakeCount = Convert.ToInt32(nudGCNClasses.Value);
            string strGCRenderField = cboValueField.Text;

            IGeoFeatureLayer pGeofeatureLayer;

            pGeofeatureLayer = (IGeoFeatureLayer)pFLayer;

            ITable       pTable = (ITable)pFClass;
            IClassifyGEN pClassifyGEN;

            switch (cboGCClassify.Text)
            {
            case "Equal Interval":
                pClassifyGEN = new EqualIntervalClass();
                break;

            case "Geometrical Interval":
                pClassifyGEN = new GeometricalInterval();
                break;

            case "Natural Breaks":
                pClassifyGEN = new NaturalBreaksClass();
                break;

            case "Quantile":
                pClassifyGEN = new QuantileClass();
                break;

            case "StandardDeviation":
                pClassifyGEN = new StandardDeviationClass();
                break;

            default:
                pClassifyGEN = new NaturalBreaksClass();
                break;
            }

            //Need to be changed 1/29/15
            ITableHistogram pTableHistogram = new TableHistogramClass();

            pTableHistogram.Field = strGCRenderField;
            pTableHistogram.Table = pTable;
            IHistogram pHistogram = (IHistogram)pTableHistogram;

            object xVals, frqs;

            pHistogram.GetHistogram(out xVals, out frqs);
            pClassifyGEN.Classify(xVals, frqs, intGCBreakeCount);

            ClassBreaksRenderer pRender = new ClassBreaksRenderer();

            double[] cb = (double[])pClassifyGEN.ClassBreaks;
            pRender.Field        = strGCRenderField;
            pRender.BreakCount   = intGCBreakeCount;
            pRender.MinimumBreak = cb[0];

            //' create our color ramp
            IAlgorithmicColorRamp pColorRamp = new AlgorithmicColorRampClass();

            pColorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
            IRgbColor pColor1 = new RgbColor();
            IRgbColor pColor2 = new RgbColor();

            //Can Change the color in here!
            pColor1.Red   = picSymolfrom.BackColor.R;
            pColor1.Green = picSymolfrom.BackColor.G;
            pColor1.Blue  = picSymolfrom.BackColor.B;

            Boolean blnOK = true;

            pColor2.Red          = picSymbolTo.BackColor.R;
            pColor2.Green        = picSymbolTo.BackColor.G;
            pColor2.Blue         = picSymbolTo.BackColor.B;
            pColorRamp.FromColor = pColor1;
            pColorRamp.ToColor   = pColor2;
            pColorRamp.Size      = intGCBreakeCount;
            pColorRamp.CreateRamp(out blnOK);

            IEnumColors pEnumColors = pColorRamp.Colors;

            pEnumColors.Reset();

            IRgbColor pColorOutline = new RgbColor();

            //Can Change the color in here!
            pColorOutline.Red   = picGCLineColor.BackColor.R;
            pColorOutline.Green = picGCLineColor.BackColor.G;
            pColorOutline.Blue  = picGCLineColor.BackColor.B;
            double dblGCOutlineSize = Convert.ToDouble(nudGCLinewidth.Value);

            ICartographicLineSymbol pOutLines = new CartographicLineSymbol();

            pOutLines.Width = dblGCOutlineSize;
            pOutLines.Color = (IColor)pColorOutline;

            //' use this interface to set dialog properties
            IClassBreaksUIProperties pUIProperties = (IClassBreaksUIProperties)pRender;

            pUIProperties.ColorRamp = "Custom";

            ISimpleFillSymbol pSimpleFillSym;

            //' be careful, indices are different for the diff lists
            for (int j = 0; j < intGCBreakeCount; j++)
            {
                pRender.Break[j]          = cb[j + 1];
                pRender.Label[j]          = Math.Round(cb[j], 2).ToString() + " - " + Math.Round(cb[j + 1], 2).ToString();
                pUIProperties.LowBreak[j] = cb[j];
                pSimpleFillSym            = new SimpleFillSymbolClass();
                pSimpleFillSym.Color      = pEnumColors.Next();
                pSimpleFillSym.Outline    = pOutLines;
                pRender.Symbol[j]         = (ISymbol)pSimpleFillSym;
            }
            pGeofeatureLayer.Renderer = (IFeatureRenderer)pRender;


            //////////////////The Robustness
            int    intRoundingDigits   = 2;
            int    intUncernBreakCount = Convert.ToInt32(nudTeNClasses.Value);
            string strUncerFieldName   = cboUField.Text;

            int intUncernIdx = pFClass.FindField(strUncerFieldName);
            int intValueIdx  = pFClass.FindField(strGCRenderField);

            //Calculate Robustness
            //Add fld
            int    intTempfldIdx  = 0;
            string strTempfldName = txtFldName.Text;

            if (chkRobustness.Checked)
            {
                if (pFClass.FindField(strTempfldName) == -1)
                {
                    AddField(pFClass, strTempfldName);
                }
                intTempfldIdx = pFClass.FindField(strTempfldName);
            }

            Chart pChart = new Chart();

            IFeature pFeat = null;
            //IFeatureCursor pFCursor = pFClass.Search(null, false);
            IFeatureCursor pFCursor = null;

            if (chkRobustness.Checked)
            {
                pFCursor = pFClass.Update(null, false);
            }
            else
            {
                pFCursor = pFClass.Search(null, false);
            }

            pFeat = pFCursor.NextFeature();
            double[] arrRobustness = new double[pFClass.FeatureCount(null)];

            int i = 0;

            while (pFeat != null)
            {
                for (int j = 0; j < (cb.Length - 1); j++)
                {
                    double dblValue = Convert.ToDouble(pFeat.get_Value(intValueIdx));
                    double dblStd   = Convert.ToDouble(pFeat.get_Value(intUncernIdx));
                    if (j == 0)
                    {
                        if (dblValue >= cb[j] && dblValue <= cb[j + 1])
                        {
                            double dblUpperZvalue  = (cb[j + 1] - dblValue) / dblStd;
                            double dblUpperConfLev = pChart.DataManipulator.Statistics.NormalDistribution(dblUpperZvalue);
                            double dblLowerZvalue  = (cb[j] - dblValue) / dblStd;
                            double dblLowerConfLev = pChart.DataManipulator.Statistics.NormalDistribution(dblLowerZvalue);
                            arrRobustness[i] = dblUpperConfLev - dblLowerConfLev;
                            if (chkRobustness.Checked)
                            {
                                pFeat.set_Value(intTempfldIdx, arrRobustness[i]);
                            }
                        }
                    }
                    else
                    {
                        if (dblValue > cb[j] && dblValue <= cb[j + 1])
                        {
                            double dblUpperZvalue  = (cb[j + 1] - dblValue) / dblStd;
                            double dblUpperConfLev = pChart.DataManipulator.Statistics.NormalDistribution(dblUpperZvalue);
                            double dblLowerZvalue  = (cb[j] - dblValue) / dblStd;
                            double dblLowerConfLev = pChart.DataManipulator.Statistics.NormalDistribution(dblLowerZvalue);
                            arrRobustness[i] = dblUpperConfLev - dblLowerConfLev;
                            if (chkRobustness.Checked)
                            {
                                pFeat.set_Value(intTempfldIdx, arrRobustness[i]);
                            }
                        }
                    }
                }
                if (chkRobustness.Checked)
                {
                    pFCursor.UpdateFeature(pFeat);
                }

                i++;
                pFeat = pFCursor.NextFeature();
            }

            //Define the intervals (the last class is fixed to 1)
            if (intUncernBreakCount == 1)
            {
                return;
            }

            double[] arrRobustBrks     = new double[intUncernBreakCount + 1];
            double   dblRBrksIntervals = Math.Round(1 / Convert.ToDouble(intUncernBreakCount - 1), intRoundingDigits);

            arrRobustBrks[0] = 0;
            for (int j = 1; j < intUncernBreakCount; j++)
            {
                arrRobustBrks[j] = dblRBrksIntervals * j;
            }
            arrRobustBrks[intUncernBreakCount] = 1;



            IFeatureLayer pflUncern = new FeatureLayerClass();

            pflUncern.FeatureClass = pFClass;
            pflUncern.Name         = "Robustness";
            pflUncern.Visible      = true;

            IGeoFeatureLayer pGFLUncern = (IGeoFeatureLayer)pflUncern;

            pFCursor = pGFLUncern.Search(null, true);
            RobustnessRenderer pRobustnessRenderer = new RobustnessRenderer();

            pRobustnessRenderer.arrRobustBrks       = arrRobustBrks;
            pRobustnessRenderer.arrRobustness       = arrRobustness;
            pRobustnessRenderer.dblAngle            = Convert.ToDouble(nudAngleFrom.Value);
            pRobustnessRenderer.dblFromSep          = Convert.ToDouble(nudSeperationFrom.Value);
            pRobustnessRenderer.dblLinewidth        = Convert.ToDouble(nudTeLinewidth.Value);
            pRobustnessRenderer.dblToSep            = Convert.ToDouble(nudSeperationTo.Value);
            pRobustnessRenderer.intUncernBreakCount = intUncernBreakCount;
            pRobustnessRenderer.pLineColor          = pSnippet.getRGB(picTeLineColor.BackColor.R, picTeLineColor.BackColor.G, picTeLineColor.BackColor.B);
            IQueryFilter pQFilter = new QueryFilterClass();


            pRobustnessRenderer.PrepareFilter(pFClass, pQFilter);
            pRobustnessRenderer.Draw(pFCursor, esriDrawPhase.esriDPSelection, pActiveView.ScreenDisplay, null);
            pRobustnessRenderer.CreateLegend();
            pGFLUncern.Renderer = pRobustnessRenderer;

            pActiveView.FocusMap.AddLayer(pGFLUncern as ILayer);

            mForm.axMapControl1.ActiveView.Refresh();
            mForm.axTOCControl1.Update();
        }
Exemplo n.º 24
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            if (cboFldnm1.Text == "" || cboFldnm2.Text == "")
            {
                MessageBox.Show("Please select target field");
                return;
            }

            frmProgress pfrmProgress = new frmProgress();

            pfrmProgress.lblStatus.Text    = "Processing:";
            pfrmProgress.pgbProgress.Style = ProgressBarStyle.Marquee;
            pfrmProgress.Show();

            REngine pEngine = m_pForm.pEngine;
            // Creates the input and output matrices from the shapefile//
            string strLayerName = cboTargetLayer.Text;

            int    intLIndex = m_pSnippet.GetIndexNumberFromLayerName(m_pActiveView, strLayerName);
            ILayer pLayer    = m_pForm.axMapControl1.get_Layer(intLIndex);

            IFeatureLayer pFLayer  = pLayer as IFeatureLayer;
            IFeatureClass pFClass  = pFLayer.FeatureClass;
            int           nFeature = pFClass.FeatureCount(null);

            IFeatureCursor pFCursor = pFLayer.Search(null, true);
            IFeature       pFeature = pFCursor.NextFeature();

            //Get index for independent and dependent variables
            //Get variable index
            string strVarNM1  = (string)cboFldnm1.SelectedItem;
            string strVarNM2  = (string)cboFldnm2.SelectedItem;
            int    intVarIdx1 = pFClass.FindField(strVarNM1);
            int    intVarIdx2 = pFClass.FindField(strVarNM2);

            //Store Variable at Array
            double[] arrVar1 = new double[nFeature];
            double[] arrVar2 = new double[nFeature];

            int i = 0;

            while (pFeature != null)
            {
                arrVar1[i] = Convert.ToDouble(pFeature.get_Value(intVarIdx1));
                arrVar2[i] = Convert.ToDouble(pFeature.get_Value(intVarIdx2));
                i++;
                pFeature = pFCursor.NextFeature();
            }

            pFCursor.Flush();

            //Plot command for R
            StringBuilder plotCommmand = new StringBuilder();

            string strStartPath = m_pForm.strPath;
            string pathr        = strStartPath.Replace(@"\", @"/");

            pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_LARRY.R')");
            pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_neighbor.R')");
            pEngine.Evaluate("source('" + pathr + "/ESDA_LEE/AllFunctions_SASbi.R')");

            //Get the file path and name to create spatial weight matrix
            string strNameR = m_pSnippet.FilePathinRfromLayer(pFLayer);

            if (strNameR == null)
            {
                return;
            }

            //Create spatial weight matrix in R
            pEngine.Evaluate("library(spdep); library(maptools)");
            pEngine.Evaluate("sample.shp <- readShapePoly('" + strNameR + "')");
            pEngine.Evaluate("sample.nb <- poly2nb(sample.shp)");

            NumericVector vecVar1 = pEngine.CreateNumericVector(arrVar1);

            pEngine.SetSymbol("sample.v1", vecVar1);
            NumericVector vecVar2 = pEngine.CreateNumericVector(arrVar2);

            pEngine.SetSymbol("sample.v2", vecVar2);

            string strRSigLv  = nudRsigLv.Value.ToString();
            string strLSigLv  = nudLsigLv.Value.ToString();
            string strLSig    = cboLocalL.Text;
            string strRsig    = cboLocalPearson.Text;
            string strRowStd  = cboRowStandardization.Text;
            string strNonZero = null;

            if (chkDiagZero.Checked)
            {
                strNonZero = "FALSE";
            }
            else
            {
                strNonZero = "TRUE";
            }

            pEngine.Evaluate("sample.result <- LARRY.bivariate.spatial.outlier(sample.v1, sample.v2, 1:length(sample.nb), sample.nb, pearson.sig = " +
                             strRSigLv + ", lee.sig = " + strLSigLv + ", method.pearson = '" + strRsig + "', method.lee = '" +
                             strLSig + "', type.row.stand = '" + strRowStd + "', alternative = 'two', diag.zero = "
                             + strNonZero + ")");

            string[] strSPOutliers = pEngine.Evaluate("as.character(sample.result$sp.outlier)").AsCharacter().ToArray();

            //Save Output on SHP
            //Add Target fields to store results in the shapefile // Keep loop
            for (int j = 0; j < 1; j++)
            {
                string strfldName = lvFields.Items[j].SubItems[1].Text;
                if (pFClass.FindField(strfldName) == -1)
                {
                    IField     newField  = new FieldClass();
                    IFieldEdit fieldEdit = (IFieldEdit)newField;
                    fieldEdit.Name_2 = strfldName;
                    fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                    pFClass.AddField(newField);
                }
            }

            //Update Field
            pFCursor = pFClass.Update(null, false);
            pFeature = pFCursor.NextFeature();

            string strSpOutlierFldName = lvFields.Items[0].SubItems[1].Text;
            int    intSpOutlierFldIdx  = pFClass.FindField(strSpOutlierFldName);

            int featureIdx = 0;

            while (pFeature != null)
            {
                pFeature.set_Value(intSpOutlierFldIdx, strSPOutliers[featureIdx]);

                pFCursor.UpdateFeature(pFeature);

                pFeature = pFCursor.NextFeature();
                featureIdx++;
            }
            pFCursor.Flush();

            if (chkMap.Checked)
            {
                ITable pTable = (ITable)pFClass;

                IUniqueValueRenderer pUniqueValueRenderer = new UniqueValueRendererClass();
                pUniqueValueRenderer.FieldCount = 1;
                pUniqueValueRenderer.set_Field(0, strSpOutlierFldName);
                if (cboMaptype.Text == "choropleth map")
                {
                    ISimpleFillSymbol pSymbol;
                    IQueryFilter      pQFilter = new QueryFilterClass();
                    int    intTotalCount       = 0;
                    string strLabel            = null;

                    for (int j = 0; j < 4; j++)
                    {
                        pSymbol       = new SimpleFillSymbolClass();
                        pSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
                        pSymbol.Color = m_pSnippet.getRGB(m_pOutlierSymbols[j].R, m_pOutlierSymbols[j].G, m_pOutlierSymbols[j].B);

                        pQFilter.WhereClause = strSpOutlierFldName + " = '" + m_pOutlierSymbols[j].Value + "'";

                        intTotalCount = pTable.RowCount(pQFilter);

                        strLabel = m_pOutlierSymbols[j].Label + " (" + intTotalCount.ToString() + ")";
                        pUniqueValueRenderer.AddValue(m_pOutlierSymbols[j].Value, null, (ISymbol)pSymbol);
                        pUniqueValueRenderer.set_Label(m_pOutlierSymbols[j].Value, strLabel);
                    }
                    pUniqueValueRenderer.UseDefaultSymbol = false;
                }
                else if (cboMaptype.Text == "point map")
                {
                    ICharacterMarkerSymbol pSymbol;
                    stdole.IFontDisp       stdFontCls = ((stdole.IFontDisp)(new stdole.StdFont()));
                    stdFontCls.Name = "ESRI NIMA VMAP1&2 PT";
                    stdFontCls.Size = 10;

                    IQueryFilter pQFilter      = new QueryFilterClass();
                    int          intTotalCount = 0;
                    string       strLabel      = null;

                    for (int j = 0; j < 4; j++)
                    {
                        pSymbol = new CharacterMarkerSymbolClass();
                        pSymbol.CharacterIndex = 248;
                        //pSymbol.Color = m_pSnippet.getRGB(m_pQuadrantSymbols[j].R, m_pQuadrantSymbols[j].G, m_pQuadrantSymbols[j].B);
                        pSymbol.Size = 10;
                        pSymbol.Font = stdFontCls;

                        pSymbol.Angle = m_pOutlierSymbols[j].Angle;

                        pQFilter.WhereClause = strSpOutlierFldName + " = '" + m_pOutlierSymbols[j].Value + "'";

                        intTotalCount = pTable.RowCount(pQFilter);

                        strLabel = m_pOutlierSymbols[j].Label + " (" + intTotalCount.ToString() + ")";
                        pUniqueValueRenderer.AddValue(m_pOutlierSymbols[j].Value, null, (ISymbol)pSymbol);
                        pUniqueValueRenderer.set_Label(m_pOutlierSymbols[j].Value, strLabel);
                    }
                    pUniqueValueRenderer.UseDefaultSymbol = false;
                }
                IFeatureLayer pNewFLayer = new FeatureLayerClass();
                pNewFLayer.FeatureClass = pFClass;
                pNewFLayer.Name         = "Bivariate Spatial Quadrants";
                IGeoFeatureLayer pGFLayer = (IGeoFeatureLayer)pNewFLayer;
                pGFLayer.Renderer = (IFeatureRenderer)pUniqueValueRenderer;
                m_pActiveView.FocusMap.AddLayer(pGFLayer);
                m_pActiveView.Refresh();
                m_pForm.axTOCControl1.Update();

                pfrmProgress.Close();
            }
            else
            {
                MessageBox.Show("Complete. The results are stored in the shape file");
            }
        }
Exemplo n.º 25
0
        private void DrawCCMaps()
        {
            m_intClassNumber = Convert.ToInt32(nudGCNClasses.Value);
            IFeatureClass pFClass = pFLayer.FeatureClass;

            //Determine Class Breaks for variable
            int intValueFldIdx = pFClass.FindField(strVarFldName);

            ITable       pTable       = (ITable)pFClass;
            IClassifyGEN pClassifyGEN = null;

            switch (cboGCClassify.Text)
            {
            case "Equal Interval":
                pClassifyGEN = new EqualIntervalClass();
                break;

            case "Geometrical Interval":
                pClassifyGEN = new GeometricalInterval();
                break;

            case "Natural Breaks":
                pClassifyGEN = new NaturalBreaksClass();
                break;

            case "Quantile":
                pClassifyGEN = new QuantileClass();
                break;

            case "StandardDeviation":
                pClassifyGEN = new StandardDeviationClass();
                break;

            default:
                pClassifyGEN = new NaturalBreaksClass();
                break;
            }


            ITableHistogram pTableHistogram = new BasicTableHistogramClass();

            pTableHistogram.Field = strVarFldName;
            pTableHistogram.Table = pTable;
            //IHistogram pHistogram = (IHistogram)pTableHistogram2;
            IBasicHistogram pHistogram = (IBasicHistogram)pTableHistogram;

            ////Not working in ArcGIS 10.5 022417 HK
            //ITableHistogram pTableHistogram = new TableHistogramClass();
            //pTableHistogram.Field = strVarFldName;
            //pTableHistogram.Table = pTable;
            //IHistogram pHistogram = (IHistogram)pTableHistogram;

            object xVals, frqs;

            pHistogram.GetHistogram(out xVals, out frqs);
            pClassifyGEN.Classify(xVals, frqs, m_intClassNumber);
            double[] cb = (double[])pClassifyGEN.ClassBreaks;

            //Class Determinations for vertical and horizontal axis

            if (m_VerticalBreaks == null)
            {
                pClassifyGEN          = new QuantileClass(); //Using Quatile
                pTableHistogram       = new BasicTableHistogramClass();
                pTableHistogram.Field = strVerConFldName;
                pTableHistogram.Table = pTable;
                pHistogram            = (IBasicHistogram)pTableHistogram;

                pHistogram.GetHistogram(out xVals, out frqs);
                pClassifyGEN.Classify(xVals, frqs, intVerCnt);
                m_VerticalBreaks = (double[])pClassifyGEN.ClassBreaks;
            }

            if (m_HorizontalBreaks == null)
            {
                pClassifyGEN          = new QuantileClass(); //Using Quatile
                pTableHistogram       = new BasicTableHistogramClass();
                pTableHistogram.Field = strHorConFldName;
                pTableHistogram.Table = pTable;
                pHistogram            = (IBasicHistogram)pTableHistogram;

                pHistogram.GetHistogram(out xVals, out frqs);
                pClassifyGEN.Classify(xVals, frqs, intHorCnt);
                m_HorizontalBreaks = (double[])pClassifyGEN.ClassBreaks;
            }

            //Create Renderer
            IClassBreaksRenderer pRender = new ClassBreaksRenderer();

            pRender.Field        = strVarFldName;
            pRender.BreakCount   = m_intClassNumber;
            pRender.MinimumBreak = cb[0];

            string strColorRamp = cboColorRamp.Text;

            IEnumColors pEnumColors = MultiPartColorRamp(strColorRamp, "CIE Lab", m_intClassNumber);

            pEnumColors.Reset();

            int[,] arrColors = new int[m_intClassNumber, 3];

            for (int k = 0; k < m_intClassNumber; k++)
            {
                IColor    pColor    = pEnumColors.Next();
                IRgbColor pRGBColor = new RgbColorClass();
                pRGBColor.RGB = pColor.RGB;

                arrColors[k, 0] = pRGBColor.Red;
                arrColors[k, 1] = pRGBColor.Green;
                arrColors[k, 2] = pRGBColor.Blue;
            }

            pEnumColors.Reset();
            IRgbColor pColorOutline = new RgbColor();

            //Can Change the color in here!
            pColorOutline = m_pSnippet.getRGB(picOutlineColor.BackColor.R, picOutlineColor.BackColor.G, picOutlineColor.BackColor.B);

            double dblGCOutlineSize = Convert.ToDouble(nudOutlinewidth.Value);

            ICartographicLineSymbol pOutLines = new CartographicLineSymbol();

            pOutLines.Width = dblGCOutlineSize;
            pOutLines.Color = (IColor)pColorOutline;

            //' use this interface to set dialog properties
            IClassBreaksUIProperties pUIProperties = (IClassBreaksUIProperties)pRender;

            pUIProperties.ColorRamp = "Custom";
            ISimpleFillSymbol pSimpleFillSym;

            pEnumColors.Reset();

            double dblAdding = Math.Pow(0.1, m_intRounding);

            for (int j = 0; j < m_intClassNumber; j++)
            {
                pRender.Break[j] = cb[j + 1];

                if (j == 0)
                {
                    pRender.Label[j] = Math.Round(cb[j], m_intRounding).ToString("N" + m_intRounding.ToString()) + " - " + Math.Round(cb[j + 1], 2).ToString("N" + m_intRounding.ToString());
                }
                else
                {
                    pRender.Label[j] = Math.Round(cb[j] + dblAdding, m_intRounding).ToString("N" + m_intRounding.ToString()) + " - " + Math.Round(cb[j + 1], 2).ToString("N" + m_intRounding.ToString());
                }

                pUIProperties.LowBreak[j] = cb[j];

                pSimpleFillSym = new SimpleFillSymbolClass();
                IRgbColor pRGBColor = m_pSnippet.getRGB(arrColors[j, 0], arrColors[j, 1], arrColors[j, 2]);
                pSimpleFillSym.Color   = (IColor)pRGBColor;
                pSimpleFillSym.Outline = pOutLines;
                pRender.Symbol[j]      = (ISymbol)pSimpleFillSym;
            }

            //Background Layer
            ISimpleRenderer   pSimpleRender = new SimpleRendererClass();
            ISimpleFillSymbol pBGSymbol     = new SimpleFillSymbolClass();

            pBGSymbol.Color = (IColor)m_pSnippet.getRGB(picBGColor.BackColor.R, picBGColor.BackColor.G, picBGColor.BackColor.B);

            ICartographicLineSymbol pBGOutLines = new CartographicLineSymbol();

            pBGOutLines.Width = 0;
            pBGOutLines.Color = m_pSnippet.getRGB(255, 255, 255);
            pBGSymbol.Outline = pBGOutLines;

            pSimpleRender.Symbol = (ISymbol)pBGSymbol;

            IFeatureLayer pflBG = new FeatureLayerClass();

            pflBG.FeatureClass = pFClass;

            IGeoFeatureLayer pGeoBG = (IGeoFeatureLayer)pflBG;

            pGeoBG.Renderer   = (IFeatureRenderer)pSimpleRender;
            pGeoBG.Selectable = false;

            //Feature Count for each map
            m_intsFeatureCnts = new int[intVerCnt * intHorCnt];

            int l = 0;

            for (int i = 0; i < intVerCnt; i++)
            {
                for (int j = 0; j < intHorCnt; j++)
                {
                    IFeatureLayer pflOutput = new FeatureLayerClass();
                    pflOutput.FeatureClass = pFClass;

                    IGeoFeatureLayer pGeofeatureLayer = (IGeoFeatureLayer)pflOutput;

                    pGeofeatureLayer.Renderer = (IFeatureRenderer)pRender;

                    IFeatureLayerDefinition2 pFDefinition = (IFeatureLayerDefinition2)pGeofeatureLayer;
                    string strWhereClause = null;

                    if (i == 0 && j == 0)
                    {
                        strWhereClause = strVerConFldName + " >= " + m_VerticalBreaks[i].ToString() + " AND " +
                                         strVerConFldName + " <= " + m_VerticalBreaks[i + 1].ToString() + " AND " +
                                         strHorConFldName + " >= " + m_HorizontalBreaks[j].ToString() + " AND " +
                                         strHorConFldName + " <= " + m_HorizontalBreaks[j + 1].ToString();
                    }
                    else if (i != 0 && j == 0)
                    {
                        strWhereClause = strVerConFldName + " > " + m_VerticalBreaks[i].ToString() + " AND " +
                                         strVerConFldName + " <= " + m_VerticalBreaks[i + 1].ToString() + " AND " +
                                         strHorConFldName + " >= " + m_HorizontalBreaks[j].ToString() + " AND " +
                                         strHorConFldName + " <= " + m_HorizontalBreaks[j + 1].ToString();
                    }
                    else if (i == 0 && j != 0)
                    {
                        strWhereClause = strVerConFldName + " >= " + m_VerticalBreaks[i].ToString() + " AND " +
                                         strVerConFldName + " <= " + m_VerticalBreaks[i + 1].ToString() + " AND " +
                                         strHorConFldName + " > " + m_HorizontalBreaks[j].ToString() + " AND " +
                                         strHorConFldName + " <= " + m_HorizontalBreaks[j + 1].ToString();
                    }
                    else
                    {
                        strWhereClause = strVerConFldName + " > " + m_VerticalBreaks[i].ToString() + " AND " +
                                         strVerConFldName + " <= " + m_VerticalBreaks[i + 1].ToString() + " AND " +
                                         strHorConFldName + " > " + m_HorizontalBreaks[j].ToString() + " AND " +
                                         strHorConFldName + " <= " + m_HorizontalBreaks[j + 1].ToString();
                    }

                    pFDefinition.DefinitionExpression = strWhereClause;

                    IQueryFilter pQfilter = new QueryFilterClass();
                    pQfilter.WhereClause = strWhereClause;

                    m_intsFeatureCnts[l] = pGeofeatureLayer.FeatureClass.FeatureCount(pQfilter);
                    m_axMapControls[l].ActiveView.FocusMap.ClearLayers();
                    m_axMapControls[l].ActiveView.FocusMap.AddLayer(pGeoBG);
                    m_axMapControls[l].ActiveView.FocusMap.AddLayer(pGeofeatureLayer);
                    m_axMapControls[l].ActiveView.Extent = m_axMapControls[l].ActiveView.FullExtent;
                    m_axMapControls[l].ActiveView.Refresh();
                    l++;
                }
            }

            lblVariable.Text = "Selected Variable: " + strVarFldName;
            UpdateRange(lvSymbol, m_intClassNumber, cb, arrColors, m_intRounding);

            if (m_blnAddBoxes)
            {
                UpdateTextBoxes();
            }
            else
            {
                AddTextBoxes();
            }

            UpdateLabels();
            UpdateHorVerLabels();
        }
Exemplo n.º 26
0
        private IEnumColors MultiPartColorRamp(string strColorRamp, string strAlgorithm, int intGCBreakeCount)
        {
            try
            {
                IEnumColors pEnumColors = null;

                if (strColorRamp == "Blue Light to Dark" || strColorRamp == "Green Light to Dark" || strColorRamp == "Orange Light to Dark" || strColorRamp == "Red Light to Dark")
                {
                    IAlgorithmicColorRamp pColorRamp = new AlgorithmicColorRampClass();
                    switch (strAlgorithm)
                    {
                    case "HSV":
                        pColorRamp.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm;
                        break;

                    case "CIE Lab":
                        pColorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
                        break;

                    case "Lab LCh":
                        pColorRamp.Algorithm = esriColorRampAlgorithm.esriLabLChAlgorithm;
                        break;

                    default:
                        pColorRamp.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
                        break;
                    }

                    IRgbColor pColor1 = new RgbColor();
                    IRgbColor pColor2 = new RgbColor();

                    switch (strColorRamp)
                    {
                    case "Blue Light to Dark":
                        pColor1 = pSnippet.getRGB(239, 243, 255);
                        pColor2 = pSnippet.getRGB(8, 81, 156);
                        break;

                    case "Green Light to Dark":
                        pColor1 = pSnippet.getRGB(237, 248, 233);
                        pColor2 = pSnippet.getRGB(0, 109, 44);
                        break;

                    case "Orange Light to Dark":
                        pColor1 = pSnippet.getRGB(254, 237, 222);
                        pColor2 = pSnippet.getRGB(166, 54, 3);
                        break;

                    case "Red Light to Dark":
                        pColor1 = pSnippet.getRGB(254, 229, 217);
                        pColor2 = pSnippet.getRGB(165, 15, 21);
                        break;

                    default:
                        pColor1 = pSnippet.getRGB(254, 229, 217);
                        pColor2 = pSnippet.getRGB(165, 15, 21);
                        break;
                    }

                    Boolean blnOK = true;

                    pColorRamp.FromColor = pColor1;
                    pColorRamp.ToColor   = pColor2;
                    pColorRamp.Size      = intGCBreakeCount;
                    pColorRamp.CreateRamp(out blnOK);


                    //arrColors = new int [intGCBreakeCount,3];
                    pEnumColors = pColorRamp.Colors;
                }
                else if (strColorRamp == "Custom")
                {
                    Boolean             blnOK           = true;
                    frmColorRamps       m_pColorRamps   = System.Windows.Forms.Application.OpenForms["frmColorRamps"] as frmColorRamps;
                    IMultiPartColorRamp pMultiColorRamp = m_pColorRamps.pMulitColorRampsResults;

                    pMultiColorRamp.Size = intGCBreakeCount;
                    pMultiColorRamp.CreateRamp(out blnOK);


                    pEnumColors = pMultiColorRamp.Colors;
                }
                else
                {
                    IAlgorithmicColorRamp pColorRamp1 = new AlgorithmicColorRampClass();
                    IAlgorithmicColorRamp pColorRamp2 = new AlgorithmicColorRampClass();


                    switch (strAlgorithm)
                    {
                    case "HSV":
                        pColorRamp1.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm;
                        pColorRamp2.Algorithm = esriColorRampAlgorithm.esriHSVAlgorithm;
                        break;

                    case "CIE Lab":
                        pColorRamp1.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
                        pColorRamp2.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
                        break;

                    case "Lab LCh":
                        pColorRamp1.Algorithm = esriColorRampAlgorithm.esriLabLChAlgorithm;
                        pColorRamp2.Algorithm = esriColorRampAlgorithm.esriLabLChAlgorithm;
                        break;

                    default:
                        pColorRamp1.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
                        pColorRamp2.Algorithm = esriColorRampAlgorithm.esriCIELabAlgorithm;
                        break;
                    }

                    IRgbColor pColor1 = new RgbColor();
                    IRgbColor pColor2 = new RgbColor();
                    IRgbColor pColor3 = new RgbColor();

                    switch (strColorRamp)
                    {
                    case "Blue to Red":
                        pColor1 = pSnippet.getRGB(49, 54, 149);
                        pColor2 = pSnippet.getRGB(255, 255, 191);
                        pColor3 = pSnippet.getRGB(165, 0, 38);
                        break;

                    case "Green to Purple":
                        pColor1 = pSnippet.getRGB(0, 68, 27);
                        pColor2 = pSnippet.getRGB(247, 247, 247);
                        pColor3 = pSnippet.getRGB(64, 0, 75);
                        break;

                    case "Green to Red":
                        pColor1 = pSnippet.getRGB(0, 104, 55);
                        pColor2 = pSnippet.getRGB(255, 255, 191);
                        pColor3 = pSnippet.getRGB(165, 0, 38);
                        break;

                    case "Purple to Brown":
                        pColor1 = pSnippet.getRGB(45, 0, 75);
                        pColor2 = pSnippet.getRGB(247, 247, 247);
                        pColor3 = pSnippet.getRGB(127, 59, 8);
                        break;

                    default:
                        pColor1 = pSnippet.getRGB(49, 54, 149);
                        pColor2 = pSnippet.getRGB(255, 255, 191);
                        pColor3 = pSnippet.getRGB(165, 0, 38);
                        break;
                    }


                    pColorRamp1.FromColor = pColor1;
                    pColorRamp1.ToColor   = pColor2;
                    pColorRamp2.FromColor = pColor2;
                    pColorRamp2.ToColor   = pColor3;

                    Boolean blnOK = true;

                    IMultiPartColorRamp pMultiColorRamp = new MultiPartColorRampClass();
                    pMultiColorRamp.Ramp[0] = pColorRamp1;
                    pMultiColorRamp.Ramp[1] = pColorRamp2;
                    pMultiColorRamp.Size    = intGCBreakeCount;
                    pMultiColorRamp.CreateRamp(out blnOK);


                    pEnumColors = pMultiColorRamp.Colors;
                }
                pEnumColors.Reset();
                return(pEnumColors);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this.Handle.ToString() + " Error:" + ex.Message);
                return(null);
            }
        }
Exemplo n.º 27
0
        //int[,] IClassSeparabilityRenderer.arrColors
        //{
        //    get { return this.arrColors; }
        //    set { this.arrColors = value; }
        //}

        //int[,] IClassSeparabilityRenderer.arrSepLineColors
        //{
        //    get { return this.arrSepLineColors; }
        //    set { this.arrSepLineColors = value; }
        //}
        void IClassSeparabilityRenderer.CreateLegend()
        {
            double     dblLinewidth = 2;
            clsSnippet pSnippet     = new clsSnippet();

            m_pTwoLegendGroup = new LegendGroupsClass();
            //Create Legend Group
            ILegendGroup pLegendGroup = new LegendGroup();

            pLegendGroup.Heading  = null;
            pLegendGroup.Editable = true;
            pLegendGroup.Visible  = true;

            //intBrksCount = (arrClassBrks.Length * 2) - 3;
            intBrksCount = (pCSMembers.ClassBrks.Length * 2) - 3;

            //For Values
            ILegendClass legendClass = new LegendClass();

            ISimpleFillSymbol pSimpleFillSym = new SimpleFillSymbolClass();
            ISimpleLineSymbol pLineSym       = new SimpleLineSymbolClass();
            int intValueIdx   = 0;
            int intSepLineIdx = 0;

            int intLastIdx = pCSMembers.ClassBrks.Length - 2;

            legendClass          = new LegendClass();
            legendClass.Label    = "Estimates";
            pSimpleFillSym       = new SimpleFillSymbolClass();
            pSimpleFillSym.Color = (IColor)pSnippet.getRGB(pCSMembers.Colors[intLastIdx, 0], pCSMembers.Colors[intLastIdx, 1], pCSMembers.Colors[intLastIdx, 2]);
            legendClass.Symbol   = pSimpleFillSym as ISymbol;
            pLegendGroup.AddClass(legendClass);

            legendClass = new LegendClass();
            //legendClass.Label = "Separability Value";
            legendClass.Label = "-- Separability Value";
            pLineSym          = new SimpleLineSymbolClass();
            //pLineSym.Color = (IColor)pSnippet.getRGB(0, 0, 0);
            pLineSym.Color     = (IColor)pSnippet.getRGB(255, 255, 255);
            pLineSym.Width     = dblLinewidth;
            legendClass.Symbol = (ISymbol)pLineSym;
            pLegendGroup.AddClass(legendClass);
            m_pTwoLegendGroup.Add(pLegendGroup);

            //Create Legend Group
            pLegendGroup = new LegendGroup();
            //pLegendGroup.Heading = "-----------------";
            pLegendGroup.Heading  = "_____________";
            pLegendGroup.Editable = true;
            pLegendGroup.Visible  = true;

            for (int i = 0; i < intBrksCount; i++)
            {
                legendClass = new LegendClass();
                if (i % 2 == 0)
                {
                    intValueIdx = i / 2;
                    if (i == 0)
                    {
                        legendClass.Label = Math.Round(pCSMembers.ClassBrks[intValueIdx], intRoundingDigits).ToString() + " - " + (Math.Round(pCSMembers.ClassBrks[intValueIdx + 1], intRoundingDigits)).ToString();
                    }
                    else
                    {
                        legendClass.Label = (Math.Round(pCSMembers.ClassBrks[intValueIdx], intRoundingDigits) + (1 * Math.Pow(0.1, intRoundingDigits))).ToString() + " - " + (Math.Round(pCSMembers.ClassBrks[intValueIdx + 1], intRoundingDigits)).ToString();
                    }


                    pSimpleFillSym       = new SimpleFillSymbolClass();
                    pSimpleFillSym.Color = (IColor)pSnippet.getRGB(pCSMembers.Colors[intValueIdx, 0], pCSMembers.Colors[intValueIdx, 1], pCSMembers.Colors[intValueIdx, 2]);
                    legendClass.Symbol   = pSimpleFillSym as ISymbol;
                }
                else
                {
                    intValueIdx       = (i - 1) / 2;
                    legendClass.Label = "-- " + Math.Round(pCSMembers.Serabability[intValueIdx], intRoundingDigits).ToString();

                    intSepLineIdx = Convert.ToInt32(Math.Floor(pCSMembers.Serabability[intValueIdx] * 10));
                    pLineSym      = new SimpleLineSymbolClass();
                    //pLineSym.Color = (IColor)pSnippet.getRGB(arrSepLineColors[intSepLineIdx, 0], arrSepLineColors[intSepLineIdx, 1], arrSepLineColors[intSepLineIdx, 2]);
                    pLineSym.Color = (IColor)pSnippet.getRGB(255, 255, 255);
                    pLineSym.Width = dblLinewidth;

                    //ITextSymbol
                    //ITextSymbol textSymbol = new TextSymbol();


                    //legendClass.Format.LabelSymbol = textSymbol;


                    legendClass.Symbol = (ISymbol)pLineSym;
                }

                pLegendGroup.AddClass(legendClass);
            }
            m_pTwoLegendGroup.Add(pLegendGroup);
        }