/// <summary>
        /// Displaying the visualiztion options according to the chosen classification
        /// </summary>
        private void RefreshControlsState(object sender, EventArgs e)
        {
            bool uniqueValues = ((tkClassificationType)cboClassificationType.SelectedIndex == tkClassificationType.ctUniqueValues);

            cboCategoriesCount.Enabled = !uniqueValues;

            // fields; graduated color schemes doesn't accept string fields, therefore we need to build new list in this case
            string fieldName = "";

            if (cboField.SelectedItem != null)
            {
                fieldName = cboField.SelectedItem.ToString();
            }

            cboField.Items.Clear();
            if (m_shapefile != null)
            {
                for (int i = 0; i < m_shapefile.NumFields; i++)
                {
                    if ((!uniqueValues) && m_shapefile.get_Field(i).Type == FieldType.STRING_FIELD)
                    {
                        continue;
                    }
                    cboField.Items.Add(m_shapefile.get_Field(i).Name);
                }

                if (cboField.Items.Count > 0)
                {
                    if (fieldName != "")
                    {
                        for (int i = 0; i < cboField.Items.Count; i++)
                        {
                            if (cboField.Items[i].ToString() == fieldName)
                            {
                                cboField.SelectedIndex = i;
                                break;
                            }
                        }
                        if (cboField.SelectedIndex == -1)
                        {
                            cboField.SelectedIndex = 0;
                        }
                    }
                    else
                    {
                        cboField.SelectedIndex = 0;
                    }
                }
            }

            udMinSize.Enabled       = chkUseVariableSize.Checked;
            udMaxSize.Enabled       = chkUseVariableSize.Checked;
            icbFrame.Enabled        = chkGraduatedFrame.Checked;
            btnFrameScheme.Enabled  = chkGraduatedFrame.Checked;
            groupColors.Text        = m_shapefile.Labels.FrameVisible ? "Frame colors" : "Font colors";
            chkRandomColors.Enabled = chkGraduatedFrame.Checked;
        }
        private void PopulateForm(bool ShowAfterward, MapWinGIS.Shapefile shapeFile, int shpIndex, bool calledBySelf)
        {
            if (!calledBySelf)
            {
                m_HavePanel = !ShowAfterward;
            }

            try
            {
                System.Windows.Forms.ListViewItem item;
                int numFields;
                m_ShapeFile = shapeFile;

                //clear the list view items
                lv.Items.Clear();

                numFields = shapeFile.NumFields;
                for (int i = 0; i < numFields; i++)
                {
                    string s = shapeFile.get_CellValue(i, shpIndex).ToString();
                    item = lv.Items.Add(shapeFile.get_Field(i).Name);
                    item.SubItems.Add(s);

                    item.ForeColor = Color.Black;
                    if (s.ToLower().StartsWith("http") || s.ToLower().StartsWith("file://"))
                    {
                        item.ForeColor = Color.Blue;
                    }
                }

                //color the current shape red
                if (m_SelShape != -1)
                {
                    m_parent.m_MapWin.View.SelectedShapes.AddByIndex(m_SelShape, YELLOW);
                }
                m_SelShape = shpIndex;
                m_parent.m_MapWin.View.SelectedShapes.AddByIndex(shpIndex, RED);

                if (ShowAfterward)
                {
                    this.Show();
                }
            }
            catch (System.Exception ex)
            {
                ShowErrorBox("PopulateForm()", ex.Message);
            }
        }
        /// <summary>
        /// Fills the fields tab
        /// </summary>
        private void InitFields()
        {
            // building list of fields
            listLeft.Items.Clear();
            listRight.Items.Clear();
            for (int i = 0; i < _shapefile.NumFields; i++)
            {
                if (_shapefile.get_Field(i).Type != FieldType.STRING_FIELD)
                {
                    listLeft.Items.Add(_shapefile.get_Field(i).Name);
                }
            }

            // in case some fields have been chosen we must show them
            if (_shapefile.Charts.NumFields > 0)
            {
                for (int i = 0; i < _shapefile.Charts.NumFields; i++)
                {
                    string name = _shapefile.Charts.get_Field(i).Name.ToLower();
                    for (int j = 0; j < listLeft.Items.Count; j++)
                    {
                        if (listLeft.Items[j].ToString().ToLower() == name)
                        {
                            listRight.Items.Add(listLeft.Items[j]);
                            listLeft.Items.Remove(listLeft.Items[j]);
                            break;
                        }
                    }
                }
            }

            if (listLeft.Items.Count > 0)
            {
                listLeft.SelectedIndex = 0;
            }

            if (listRight.Items.Count > 0)
            {
                listRight.SelectedIndex = 0;
            }

            // Filling size and normalization fields
            cboChartSizeField.Items.Clear();
            cboChartNormalizationField.Items.Clear();

            cboChartSizeField.Items.Add("<None>");          // default
            cboChartNormalizationField.Items.Add("<None>");

            for (int i = 0; i < _shapefile.NumFields; i++)
            {
                MapWinGIS.Field fld = _shapefile.get_Field(i);
                if (fld.Type != FieldType.STRING_FIELD)
                {
                    cboChartSizeField.Items.Add(fld.Name);
                    cboChartNormalizationField.Items.Add(fld.Name);
                }
            }

            if (cboChartSizeField.Items.Count >= 0)
            {
                cboChartSizeField.SelectedIndex = 0;
            }

            if (cboChartNormalizationField.Items.Count >= 0)
            {
                cboChartNormalizationField.SelectedIndex = 0;
            }

            // size field
            MapWinGIS.Charts charts = _shapefile.Charts;
            if (charts.SizeField >= 0 && charts.SizeField < cboChartSizeField.Items.Count - 1)  // first item is <none>
            {
                Field fld = _shapefile.get_Field(charts.SizeField);
                if (fld != null)
                {
                    for (int i = 2; i < cboChartSizeField.Items.Count; i++)     // 2 = <none> and <sum of fields>
                    {
                        if (fld.Name == cboChartSizeField.Items[i].ToString())
                        {
                            cboChartSizeField.SelectedIndex = i;
                            break;
                        }
                    }
                }
            }
            else
            {
                cboChartSizeField.SelectedIndex = 0;
            }

            // normalization field
            if (charts.NormalizationField >= 0 && charts.NormalizationField < cboChartNormalizationField.Items.Count - 1)  // first item is <none>
            {
                Field fld = _shapefile.get_Field(charts.NormalizationField);
                if (fld != null)
                {
                    for (int i = 2; i < cboChartNormalizationField.Items.Count; i++)     // 2 = <none> and <sum of fields>
                    {
                        if (fld.Name == cboChartNormalizationField.Items[i].ToString())
                        {
                            cboChartNormalizationField.SelectedIndex = i;
                            break;
                        }
                    }
                }
            }
            else
            {
                cboChartNormalizationField.SelectedIndex = 0;
            }
        }
        /// <summary>
        /// Generates shapefile categories according to specified options
        /// </summary>
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (cboField.SelectedIndex < 0)
            {
                Globals.MessageBoxInformation("No field for generation was selected.");
                this.DialogResult = DialogResult.None;
                return;
            }

            int count;

            if (!Int32.TryParse(cboCategoriesCount.Text, out count))
            {
                Globals.MessageBoxError("Number of categories isn't a valid interger.");
                return;
            }

            MapWinGIS.ShapefileCategories categories = _shapefile.Categories;
            int index = ((ComboItem)cboField.SelectedItem).RealIndex;

            categories.Generate(index, (MapWinGIS.tkClassificationType)cboClassificationType.SelectedIndex, count);

            categories.Caption = "Categories: " + _shapefile.get_Field(index).Name;

            if (chkUseVariableSize.Checked)
            {
                if (_shapefile.ShapefileType == ShpfileType.SHP_POINT || _shapefile.ShapefileType == ShpfileType.SHP_MULTIPOINT)
                {
                    double step = (double)(udMaxSize.Value - udMinSize.Value) / ((double)categories.Count - 1);
                    for (int i = 0; i < categories.Count; i++)
                    {
                        categories.get_Item(i).DrawingOptions.PointSize = (int)udMinSize.Value + Convert.ToInt32(i * step);
                    }
                }
                else if (_shapefile.ShapefileType == ShpfileType.SHP_POLYLINE)
                {
                    double step = (double)(udMaxSize.Value + udMinSize.Value) / (double)categories.Count;
                    for (int i = 0; i < categories.Count; i++)
                    {
                        categories.get_Item(i).DrawingOptions.LineWidth = (int)udMinSize.Value + Convert.ToInt32(i * step);
                    }
                }
            }

            MapWinGIS.ColorScheme scheme = null;
            if (icbColorScheme.SelectedIndex >= 0)
            {
                ColorBlend blend = (ColorBlend)icbColorScheme.ColorSchemes.List[icbColorScheme.SelectedIndex];
                scheme = ColorSchemes.ColorBlend2ColorScheme(blend);
            }

            tkColorSchemeType type = chkRandomColors.Checked ? tkColorSchemeType.ctSchemeRandom : tkColorSchemeType.ctSchemeGraduated;

            _shapefile.Categories.ApplyColorScheme(type, scheme);

            if (chkSetGradient.Checked)
            {
                for (int i = 0; i < categories.Count; i++)
                {
                    ShapeDrawingOptions options = categories.get_Item(i).DrawingOptions;
                    options.SetGradientFill(options.FillColor, 75);
                    options.FillType = tkFillType.ftGradient;
                }
            }

            _shapefile.Categories.ApplyExpressions();

            SaveSettings();
        }
示例#5
0
        /// <summary>
        /// 'Copyright (C) 2008  Enrico Antonio Chiaradia, UNIMI
        ///'This program is free software; you can redistribute it and/or
        ///'modify it under the terms of the GNU General Public License 
        ///'version 2, 1991 as published by the Free Software Foundation.
        ///'This program is distributed in the hope that it will be useful,
        ///'but WITHOUT ANY WARRANTY; without even the implied warranty of
        ///'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        ///'GNU General Public License for more details.
        ///'A copy of the full GNU General Public License is available at:
        ///'http://www.gnu.org/copyleft/gpl.html
        ///'or from:
        ///'The Free Software Foundation, Inc., 59 Temple Place - Suite 330, 
        ///'Boston, MA  02111-1307, USA.
        ///'If you wish to use or incorporate this program (or parts of it) into 
        ///'other software that does not meet the GNU General Public License 
        ///'conditions contact the author to request permission.
        ///'If you have any question or suggestion, please contact the author.
        ///'Enrico A. Chiaradia
        ///'University of Milan
        ///'Ist. di Idraulica Agraria
        ///'via Celoria 2
        ///'20133, Milan, Italy
        ///'email:  [email protected]
        /// </summary>
        /// <param name="sfPath">the name of the shapefile</param>
        /// <param name="resultGridPath">the name of the new grid</param>
        /// <param name="gridFileType">file type of the new grid</param>
        /// <param name="gridDataType">data format of the new grid</param>
        /// <param name="sfValueField">the name of the field that contains data</param>
        /// <param name="resultGridHeader">contains information about dimension of the new grid</param>
        /// <param name="callback">(optional) reports progress and error messages</param>
        /// <returns></returns>
        public bool ShapefileToGrid2(string SfNm, string GrdName,
            MapWinGIS.GridFileType GrdFileType, MapWinGIS.GridDataType GrdDataType,
            string Fldname, MapWinGIS.GridHeader GrdHd,
            MapWinGIS.ICallback cback)
        {
            int i;
            bool flg;
            string projStr;

            //open the shapefile
            MapWinGIS.Shapefile MySf = new MapWinGIS.Shapefile();
            flg = MySf.Open(SfNm, cback);
            if (flg == false)
            {
                reportError("ERROR in opening shapefile: " + SfNm, cback);
                MySf.Close();
                return false;
            }

            //get the handle for the field
            MapWinGIS.Field field;
            int FldId = -1;
            int LayFldNum = MySf.NumFields;

            i = 0;
            for (i = 0; i < LayFldNum; ++i)
            {
                field = MySf.get_Field(i);
                if (field.Name.ToLower() == Fldname.ToLower())
                {
                    FldId = i;
                    break;
                }
            }
            if (FldId < 0)
            {
                reportError("The shapefile " + SfNm + " doesn't have a field " + Fldname, cback);
                MySf.Close();
                return false;
            }

            //copy shapefile projection
            projStr = MySf.Projection;
            if (!MapWinUtility.Strings.IsEmpty(projStr))
            {
                GrdHd.Projection = projStr;
            }

            //create a new grid and a new gridheader
            MapWinGIS.Grid NewGrd = new MapWinGIS.Grid();
            flg = NewGrd.CreateNew(GrdName, GrdHd, GrdDataType, GrdHd.NodataValue, false, GrdFileType, cback);
            if (flg == false)
            {
                reportError("ERROR in grid initialization: " + GrdName, cback);
                NewGrd.Close();
                MySf.Close();
            }

            //verify the type of shapefile and call rasterization function
            MapWinGIS.ShpfileType SfType = new MapWinGIS.ShpfileType();
            SfType = MySf.ShapefileType;
            switch (SfType)
            {
                case ShpfileType.SHP_POLYGON:
                case ShpfileType.SHP_POLYGONM:
                case ShpfileType.SHP_POLYGONZ:
                    flg = Poly2Grid(MySf, FldId, NewGrd, GrdHd, GrdDataType, cback);
                    break;
                case ShpfileType.SHP_POLYLINE:
                case ShpfileType.SHP_POLYLINEM:
                case ShpfileType.SHP_POLYLINEZ:
                    flg = Line2Grid(MySf, FldId, NewGrd, GrdHd, GrdDataType, cback);
                    break;
                case ShpfileType.SHP_POINT:
                case ShpfileType.SHP_POINTM:
                case ShpfileType.SHP_POINTZ:
                    flg = Point2Grid(MySf, FldId, NewGrd, GrdHd, GrdDataType, cback);
                    break;
                case ShpfileType.SHP_MULTIPOINT:
                case ShpfileType.SHP_MULTIPOINTM:
                case ShpfileType.SHP_MULTIPOINTZ:
                    flg = Multipoint2Grid(MySf, FldId, NewGrd, GrdHd, GrdDataType, cback);
                    break;
                default:
                    reportError("The shapefile type " + SfType.ToString() + "is not supported.", cback);
                    NewGrd.Close();
                    MySf.Close();
                    flg = false;
                    break;
            }

            //save and close the grid, close shapefile
            NewGrd.Save(GrdName, GrdFileType, cback);
            NewGrd.Close();
            MySf.Close();
            return flg;
        }
示例#6
0
        /// <summary>
        /// 'Copyright (C) 2008  Enrico Antonio Chiaradia, UNIMI
        ///'This program is free software; you can redistribute it and/or
        ///'modify it under the terms of the GNU General Public License
        ///'version 2, 1991 as published by the Free Software Foundation.

        ///'This program is distributed in the hope that it will be useful,
        ///'but WITHOUT ANY WARRANTY; without even the implied warranty of
        ///'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        ///'GNU General Public License for more details.

        ///'A copy of the full GNU General Public License is available at:
        ///'http://www.gnu.org/copyleft/gpl.html
        ///'or from:
        ///'The Free Software Foundation, Inc., 59 Temple Place - Suite 330,
        ///'Boston, MA  02111-1307, USA.

        ///'If you wish to use or incorporate this program (or parts of it) into
        ///'other software that does not meet the GNU General Public License
        ///'conditions contact the author to request permission.

        ///'If you have any question or suggestion, please contact the author.

        ///'Enrico A. Chiaradia
        ///'University of Milan
        ///'Ist. di Idraulica Agraria
        ///'via Celoria 2
        ///'20133, Milan, Italy
        ///'email:  [email protected]
        /// </summary>
        /// <param name="sfPath">the name of the shapefile</param>
        /// <param name="resultGridPath">the name of the new grid</param>
        /// <param name="gridFileType">file type of the new grid</param>
        /// <param name="gridDataType">data format of the new grid</param>
        /// <param name="sfValueField">the name of the field that contains data</param>
        /// <param name="resultGridHeader">contains information about dimension of the new grid</param>
        /// <param name="callback">(optional) reports progress and error messages</param>
        /// <returns></returns>
        public bool ShapefileToGrid2(string SfNm, string GrdName,
                                     MapWinGIS.GridFileType GrdFileType, MapWinGIS.GridDataType GrdDataType,
                                     string Fldname, MapWinGIS.GridHeader GrdHd,
                                     MapWinGIS.ICallback cback)
        {
            int    i;
            bool   flg;
            string projStr;

            //open the shapefile
            MapWinGIS.Shapefile MySf = new MapWinGIS.Shapefile();
            flg = MySf.Open(SfNm, cback);
            if (flg == false)
            {
                reportError("ERROR in opening shapefile: " + SfNm, cback);
                MySf.Close();
                return(false);
            }

            //get the handle for the field
            MapWinGIS.Field field;
            int             FldId     = -1;
            int             LayFldNum = MySf.NumFields;

            i = 0;
            for (i = 0; i < LayFldNum; ++i)
            {
                field = MySf.get_Field(i);
                if (field.Name.ToLower() == Fldname.ToLower())
                {
                    FldId = i;
                    break;
                }
            }
            if (FldId < 0)
            {
                reportError("The shapefile " + SfNm + " doesn't have a field " + Fldname, cback);
                MySf.Close();
                return(false);
            }

            //copy shapefile projection
            projStr = MySf.Projection;
            if (!MapWinUtility.Strings.IsEmpty(projStr))
            {
                GrdHd.Projection = projStr;
            }

            //create a new grid and a new gridheader
            MapWinGIS.Grid NewGrd = new MapWinGIS.Grid();
            flg = NewGrd.CreateNew(GrdName, GrdHd, GrdDataType, GrdHd.NodataValue, false, GrdFileType, cback);
            if (flg == false)
            {
                reportError("ERROR in grid initialization: " + GrdName, cback);
                NewGrd.Close();
                MySf.Close();
            }

            //verify the type of shapefile and call rasterization function
            MapWinGIS.ShpfileType SfType = new MapWinGIS.ShpfileType();
            SfType = MySf.ShapefileType;
            switch (SfType)
            {
            case ShpfileType.SHP_POLYGON:
            case ShpfileType.SHP_POLYGONM:
            case ShpfileType.SHP_POLYGONZ:
                flg = Poly2Grid(MySf, FldId, NewGrd, GrdHd, GrdDataType, cback);
                break;

            case ShpfileType.SHP_POLYLINE:
            case ShpfileType.SHP_POLYLINEM:
            case ShpfileType.SHP_POLYLINEZ:
                flg = Line2Grid(MySf, FldId, NewGrd, GrdHd, GrdDataType, cback);
                break;

            case ShpfileType.SHP_POINT:
            case ShpfileType.SHP_POINTM:
            case ShpfileType.SHP_POINTZ:
                flg = Point2Grid(MySf, FldId, NewGrd, GrdHd, GrdDataType, cback);
                break;

            case ShpfileType.SHP_MULTIPOINT:
            case ShpfileType.SHP_MULTIPOINTM:
            case ShpfileType.SHP_MULTIPOINTZ:
                flg = Multipoint2Grid(MySf, FldId, NewGrd, GrdHd, GrdDataType, cback);
                break;

            default:
                reportError("The shapefile type " + SfType.ToString() + "is not supported.", cback);
                NewGrd.Close();
                MySf.Close();
                flg = false;
                break;
            }

            //save and close the grid, close shapefile
            NewGrd.Save(GrdName, GrdFileType, cback);
            NewGrd.Close();
            MySf.Close();
            return(flg);
        }
        public void PopulateForm(bool ShowAfterward, MapWinGIS.Shapefile shapeFile, string layerName, bool calledBySelf)
        {
            if (!calledBySelf)
            {
                m_HavePanel = !ShowAfterward;
            }

            try
            {
                int    numFields;
                string fieldName;
                m_ShapeFile = shapeFile;
                m_shpIndex  = null;

                m_LayerName = layerName;
                SetTitle();

                //new selected shapes
                m_SelShape = -1;

                //clear the selected box
                m_parent.m_MapWin.View.Draw.ClearDrawing(m_parent.m_hDraw);

                //clear the list view items
                lv.Items.Clear();
                cb.Items.Clear();
                cb.Text = "";

                //clear the combo Box field Name
                cbFieldName.Items.Clear();
                cbFieldName.Items.Add("Shape Index");
                cb.Text = "";

                numFields = shapeFile.NumFields;
                for (int i = 0; i < numFields; i++)
                {
                    fieldName = shapeFile.get_Field(i).Name;
                    lv.Items.Add(fieldName);

                    //add all the field name to the combo box
                    cbFieldName.Items.Add(fieldName);
                }

                //select the first field
                if (cbFieldName.Items.IndexOf(m_FieldName) == -1)
                {
                    cbFieldName.SelectedIndex = 0;
                }
                else
                {
                    cbFieldName.SelectedItem = m_FieldName;
                }

                if (ShowAfterward)
                {
                    this.Show();
                }
            }
            catch (System.Exception ex)
            {
                ShowErrorBox("PopulateForm()", ex.Message);
            }
        }
        public void PopulateForm(bool ShowAfterward, MapWinGIS.Shapefile shapeFile, int[] shpIndex, string layerName, bool calledBySelf)
        {
            if (!calledBySelf)
            {
                m_HavePanel = !ShowAfterward;
            }

            try
            {
                System.Windows.Forms.ListViewItem item;
                int numFields;
                m_shpIndex  = shpIndex;
                m_LayerName = layerName;
                m_ShapeFile = shapeFile;
                SetTitle();

                //new selected shapes
                m_SelShape = -1;

                //clear the list view items
                lv.Items.Clear();

                //clear the combo Box field Name
                cb.Items.Clear();
                cb.Text = "";
                cbFieldName.Items.Clear();
                cbFieldName.Items.Add("Shape Index");

                //clear the selected box
                m_parent.m_MapWin.View.Draw.ClearDrawing(m_parent.m_hDraw);

                numFields = shapeFile.NumFields;
                for (int i = 0; i < numFields; i++)
                {
                    item = lv.Items.Add(shapeFile.get_Field(i).Name);
                    item.SubItems.Add(shapeFile.get_CellValue(i, shpIndex[0]).ToString());

                    //add all the field name to the combo box
                    cbFieldName.Items.Add(shapeFile.get_Field(i).Name);
                }

                //color the current shape red
                if (m_SelShape != -1)
                {
                    m_parent.m_MapWin.View.SelectedShapes.AddByIndex(m_SelShape, YELLOW);
                }
                m_SelShape = shpIndex[0];

                m_parent.m_MapWin.View.SelectedShapes.AddByIndex(shpIndex[0], RED);

                //select the first field
                if (cbFieldName.Items.IndexOf(m_FieldName) == -1)
                {
                    cbFieldName.SelectedIndex = 0;
                }
                else
                {
                    cbFieldName.SelectedItem = m_FieldName;
                }

                if (ShowAfterward)
                {
                    this.Show();
                }
            }
            catch (System.Exception ex)
            {
                ShowErrorBox("PopulateForm()", ex.Message);
            }
        }