Esempio n. 1
0
        private void polyshp_Click(object sender, EventArgs e)
        {
            DataOperator  dataOperator = new DataOperator(axMapControl1.Map);
            IFeatureClass featureClass = dataOperator.CreateShapefile("E:\\", "ShapefileWorespace", "ShapefileSample", "Polygon");

            if (featureClass == null)
            {
                MessageBox.Show("创建shapefile文件失败!");
                return;
            }
            //将要素类添加到地图中,图层名为"Observation Stations"
            //如果创建成功,将"创建shapefile"按钮禁用
            //如果创建失败,弹出消息框提示
            bool bRes = dataOperator.AddFeatureClassToMap(featureClass, "Observation Stations");

            if (bRes)
            {
                polyshp.Enabled = false;
                return;
            }
            else
            {
                MessageBox.Show("将新建shapefile文件加入地图失败!");
                return;
            }
        }
Esempio n. 2
0
        private void btnAdmit_Click(object sender, EventArgs e)
        {
            IFields     fields     = new FieldsClass();
            IFieldsEdit fieldsEdit = fields as IFieldsEdit;

            //add fields
            for (int i = 3; i < listBoxFieldName.Items.Count; i++)
            {
                AddNewField(fields, listBoxFieldName.Items[i].ToString(), listBoxAliasName.Items[i].ToString(),
                            listBoxFieldType.Items[i].ToString());
            }

            //Show message box when the input is not complete
            if (tbFilePath.Text == "")
            {
                MessageBox.Show("Please input file path!");
            }
            else if (tbShapefileName.Text == "")
            {
                MessageBox.Show("Please input file name!");
            }
            else if (System.IO.File.Exists(tbFilePath.Text + "\\" + tbShapefileName.Text + ".shp"))
            {
                MessageBox.Show("The shapefile already exists!");
            }
            else
            {
                //Get parent directory and workspace names
                String        sParentDirectory = tbFilePath.Text.Substring(0, fbd.SelectedPath.LastIndexOf("\\"));
                String        sWorkspace       = tbFilePath.Text.Substring(fbd.SelectedPath.LastIndexOf("\\") + 1);
                DataOperator  dataOperator     = new DataOperator(m_map);
                IFeatureClass featureClass     = dataOperator.CreateShapefile(fields, sParentDirectory, sWorkspace, tbShapefileName.Text, cbGeometryType.SelectedItem.ToString());
                if (featureClass == null)
                {
                    MessageBox.Show("Failed to create shapefile!");
                }
                //add shapefile to the map
                if (MessageBox.Show("Do you want to add the shapefile to the map?", "", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    dataOperator.AddFeatureClassToMap(featureClass, tbShapefileName.Text);
                }
                this.Close();
            }
        }