Exemple #1
0
        private void ImportShapeFile(bool safeMode)
        {
            try
            {
                // txtCoordSys.Text, txtConString.Text, chkDrop.Checked, radGeog.Checked, chkSRID.Checked ? txtSrid.Text : null
                _importer = new ShapeFileImporter(txtSHP.Text);
                _importer.ProgressChanged += new EventHandler <ProgressChangedEventArgs>(_importer_ProgressChanged);
                _importer.Done            += new EventHandler(importer_Done);
                _importer.Error           += new EventHandler <ShapeImportExceptionEventArgs>(importer_Error);

                toolStripProgressBar1.Value   = 0;
                toolStripProgressBar1.Maximum = 100;

                List <string> selectedFields = new List <string>();
                foreach (var item in lstColumns.CheckedItems)
                {
                    selectedFields.Add(((ShapeField)item).Name);
                }


                if (safeMode)
                {
                    _importer.ImportShapeFile(txtConString.Text,
                                              chkReproject.Checked ? txtCoordSys.Text : null,
                                              chkDrop.Checked,
                                              radGeog.Checked ? enSpatialType.geography : radGeom.Checked ? enSpatialType.geometry : enSpatialType.both,
                                              chkSRID.Checked ? int.Parse(txtSrid.Text) : 0,
                                              txtTableName.Text, txtSchema.Text,
                                              txtIDCol.Text,
                                              txtGeomCol.Text,
                                              selectedFields);
                }
                else
                {
                    _importer.ImportShapeFile_Direct(txtConString.Text,
                                                     chkReproject.Checked ? txtCoordSys.Text : null,
                                                     chkDrop.Checked,
                                                     radGeog.Checked ? enSpatialType.geography : radGeom.Checked ? enSpatialType.geometry : enSpatialType.both,
                                                     chkSRID.Checked ? int.Parse(txtSrid.Text) : 0,
                                                     txtTableName.Text, txtSchema.Text,
                                                     txtIDCol.Text,
                                                     txtGeomCol.Text,
                                                     selectedFields);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
            }
        }
Exemple #2
0
        private void InitIHM_ShapeFile(string shapeFile)
        {
            try
            {
                if (!File.Exists(shapeFile))
                {
                    return;
                }

                ShapeFileImporter importer = new ShapeFileImporter(shapeFile);

                txtSHP.Text                   = shapeFile;
                lblShapeHeader.Text           = string.Format("{0} {1} in shapefile\n{2}", importer.RecordCount, importer.ShapeType, importer.Bounds, importer.CoordinateSystem);
                lblShapeHeader.Tag            = importer.CoordinateSystem;
                txtTableName.Text             = importer.SqlTableName;
                txtIDCol.Text                 = importer.SqlIDFIeld;
                txtGeomCol.Text               = importer.SqlGeomField;
                toolStripProgressBar1.Minimum = 0;
                toolStripProgressBar1.Maximum = importer.RecordCount;
                toolStripProgressBar1.Value   = 0;
                toolStripProgressBar1.Step    = 1;

                //ICoordinateSystem csSource = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(importer.CoordinateSystem) as ICoordinateSystem;
                //ICoordinateSystem csTarget = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(txtCoordSys.Text) as ICoordinateSystem;

                //bool testEq = csSource.EqualParams(csTarget);


                BindingList <ShapeField> bindList = new BindingList <ShapeField>();
                foreach (var kv in importer.Fields)
                {
                    bindList.Add(new ShapeField()
                    {
                        Name = kv.Key, Type = kv.Value.Name.ToString()
                    });
                }
                lstColumns.DataSource    = bindList;
                lstColumns.DisplayMember = "FullName";
                lstColumns.ValueMember   = "Name";

                for (int i = 0; i < lstColumns.Items.Count; i++)
                {
                    lstColumns.SetItemChecked(i, true);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error with shape file: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }