Esempio n. 1
0
        private void SetupCustomRenderSettings(string fieldName, int layerIndex, TooltipHeaderFieldNamePair[] tooltipFields)
        {            
            //get the required layer
            EGIS.ShapeFileLib.RenderSettings renderSettings = SFMap1.GetLayer(layerIndex).RenderSettings;
            int numRecords = SFMap1.GetLayer(layerIndex).RecordCount;
            EGIS.ShapeFileLib.DbfReader dbfReader = renderSettings.DbfReader;
            int fieldIndex = dbfReader.IndexOfFieldName(fieldName);

            double[] samples = new double[numRecords];
            //find the range of population values and obtain the quintile quantiles
            for (int n = 0; n < numRecords; n++)
            {
                double d = double.Parse(dbfReader.GetField(n, fieldIndex), System.Globalization.CultureInfo.InvariantCulture);
                samples[n] = d;
            }            
            double[] ranges = GetQuintiles(samples);
            
            //create the quintile colors - there will be 1 more color than the number of elements in quantiles
            Color[] cols = new Color[] { 
                Color.FromArgb(80, 0, 20), 
                Color.FromArgb(120, 0, 20), 
                Color.FromArgb(180, 0, 20), 
                Color.FromArgb(220, 0, 20),
                Color.FromArgb(250,0,20)};

            //setup the list of tooltip fields
            System.Collections.Generic.List<TooltipHeaderFieldNamePair> tooltipPairList = null;
            if(tooltipFields != null)
            {
                tooltipPairList = new System.Collections.Generic.List<TooltipHeaderFieldNamePair>();
                tooltipPairList.AddRange(tooltipFields);
            }

            //create a new QuantileCustomRenderSettings and add it to the SFMap
            QuantileCustomRenderSettings rcrs = new QuantileCustomRenderSettings(renderSettings, cols, ranges, fieldName, tooltipPairList);
            SFMap1.SetCustomRenderSettings(layerIndex, rcrs);

        }
        private void SetupCustomRenderSettings(string fieldName, int layerIndex, TooltipHeaderFieldNamePair[] tooltipFields)
        {
            //get the required layer
            EGIS.ShapeFileLib.RenderSettings renderSettings = SFMap1.GetLayer(layerIndex).RenderSettings;
            int numRecords = SFMap1.GetLayer(layerIndex).RecordCount;
            EGIS.ShapeFileLib.DbfReader dbfReader = renderSettings.DbfReader;
            int fieldIndex = dbfReader.IndexOfFieldName(fieldName);

            double[] samples = new double[numRecords];
            //find the range of population values and obtain the quintile quantiles
            //for (int n = 0; n < numRecords; n++)
            //{

            //    if (String.IsNullOrEmpty(dbfReader.GetField(n, fieldIndex)) == false)
            //    {
            //        string tmp = dbfReader.GetField(n, fieldIndex);
            //        int value;
            //        if (int.TryParse(tmp, out value))
            //        {
            //            double d = double.Parse(dbfReader.GetField(n, fieldIndex), System.Globalization.CultureInfo.InvariantCulture);
            //            samples[n] = d;
            //        }
            //    }
            //}

            for (int n = 0; n < numRecords; n++)
            {

                if (String.IsNullOrEmpty(dbfReader.GetField(n, fieldIndex)) == false)
                {
                    string tmp = dbfReader.GetField(n, fieldIndex);
                    int value;
                    if (int.TryParse(tmp, out value))
                    {
                        double d = double.Parse(dbfReader.GetField(n, fieldIndex), System.Globalization.CultureInfo.InvariantCulture);
                        samples[n] = d;
                    }
                }
            }

            double[] ranges = GetQuintiles(samples);

            //create the quintile colors - there will be 1 more color than the number of elements in quantiles
            Color[] cols = new Color[] {
                Color.FromArgb(96,169, 108),
                Color.FromArgb(201, 200, 123),
                Color.FromArgb(157, 135, 151),
                Color.FromArgb(112, 155, 235),
                Color.FromArgb(192,94,113)};

            //setup the list of tooltip fields
            System.Collections.Generic.List<TooltipHeaderFieldNamePair> tooltipPairList = null;
            if (tooltipFields != null)
            {
                tooltipPairList = new System.Collections.Generic.List<TooltipHeaderFieldNamePair>();
                tooltipPairList.AddRange(tooltipFields);
            }

            //create a new QuantileCustomRenderSettings and add it to the SFMap
            QuantileCustomRenderSettings rcrs = new QuantileCustomRenderSettings(renderSettings, cols, ranges, fieldName, tooltipPairList);
            SFMap1.SetCustomRenderSettings(layerIndex, rcrs);
        }