Exemplo n.º 1
0
        public void GetSupportedGDalDataType()
        {
            Driver gdalDriverForBilFile = Gdal.GetDriverByName("EHdr");
            var    type = GdalHelper.GetGdalDataType(gdalDriverForBilFile, typeof(double));

            Assert.AreEqual(DataType.GDT_Float32, type);
        }
        private void btnRun_Click(object sender, EventArgs e)
        {
            if (dataGridView1.Rows.Count < 1)
            {
                return;
            }

            ChangedView(true);
            try
            {
                _stopRunning = false;
                var rows = dataGridView1.Rows;
                progressBar1.Maximum = rows.Count;
                foreach (DataGridViewRow row in rows)
                {
                    row.Cells["colResult"].Value = string.Empty;
                }
                Application.DoEvents();

                var layerName      = cmbLayers.SelectedItem.ToString();
                var layer          = dataSourceSelector1.GetLayerByName(layerName);
                var idFieldName    = cmbIdField.SelectedItem.ToString();
                var txtFileDir     = txtTextFileDir.Text.Trim();
                var featureDefn    = layer.GetLayerDefn();
                var idField        = featureDefn.GetFieldDefn(featureDefn.GetFieldIndex(idFieldName));
                var sqlFormat      = idField.GetFieldType() == FieldType.OFTString ? "{0} = '{1}'" : "{0} = {1}";
                var fileNameFormat = cmbNameField.SelectedIndex > 0 ? "{0}_{1}.txt" : "{0}.txt";

                foreach (DataGridViewRow row in rows)
                {
                    if (Convert.ToBoolean(row.Cells["colCheck"].Value) == true)
                    {
                        try
                        {
                            var id       = row.Cells["colID"].Value.ToString();
                            var name     = row.Cells["colName"].Value.ToString();
                            var filePath = Path.Combine(txtFileDir, string.Format(fileNameFormat, id, name));
                            var features = GdalHelper.GetFeatures(layer, string.Format(sqlFormat, idFieldName, id));
                            var txtInfo  = RedLineManager.GetProjInfoFromFeatures(features.ToArray());
                            RedLineManager.ToTxtFile(filePath, txtInfo);

                            row.Cells["colResultPath"].Value = filePath;
                            row.Cells["colResult"].Value     = "成功";
                        }
                        catch (Exception ex)
                        {
                            row.Cells["colResult"].Value = "失败:" + ex.Message;
                        }
                    }
                    progressBar1.Value++;
                    Application.DoEvents();
                    if (_stopRunning)
                    {
                        break;
                    }
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); }
            ChangedView(false);
        }
Exemplo n.º 3
0
        public void GetSupportedGdalDriverForBIL()
        {
            string path       = TestHelper.GetDataDir() + @"\RasterData\Bodem.bil";
            var    driverName = GdalHelper.GetDriverName(path);

            Assert.AreEqual("EHdr", driverName);
        }
Exemplo n.º 4
0
        private void InitData(Layer polygonLayer)
        {
            this.cmbJD.SelectedIndex   = 2;
            this.cmbDKBH.SelectedIndex = 0;
            this.cmbDKMC.SelectedIndex = 0;
            this.cmbDKMJ.SelectedIndex = 0;
            this.cmbTFH.SelectedIndex  = 0;
            this.cmbTDYT.SelectedIndex = 0;
            this.cmbDLBM.SelectedIndex = 0;

            if (polygonLayer != null)
            {
                this.PolygonLayer = polygonLayer;

                var fieldNames = GdalHelper.GetFieldNames(polygonLayer).ToArray();
                this.cmbDKBH.Items.AddRange(fieldNames);
                this.cmbDKMC.Items.AddRange(fieldNames);
                this.cmbDKMJ.Items.AddRange(fieldNames);
                this.cmbTFH.Items.AddRange(fieldNames);
                this.cmbTDYT.Items.AddRange(fieldNames);
                this.cmbDLBM.Items.AddRange(fieldNames);

                this.cmbJD.SelectedItem   = CfgRedlineTxt.AttrFields[8].DefaultValue;
                this.cmbDKBH.SelectedItem = CfgRedlineTxt.BlockFields[2].FieldName;
                this.cmbDKMC.SelectedItem = CfgRedlineTxt.BlockFields[3].FieldName;
                this.cmbDKMJ.SelectedItem = CfgRedlineTxt.BlockFields[1].FieldName;
                this.cmbTFH.SelectedItem  = CfgRedlineTxt.BlockFields[5].FieldName;
                this.cmbTDYT.SelectedItem = CfgRedlineTxt.BlockFields[6].FieldName;
                this.cmbDLBM.SelectedItem = CfgRedlineTxt.BlockFields[7].FieldName;
            }
        }
Exemplo n.º 5
0
        public void GetSupportedGdalDriverForASC()
        {
            string path       = TestHelper.GetDataDir() + @"\RasterData\test.ASC";
            var    driverName = GdalHelper.GetDriverName(path);

            Assert.AreEqual("AAIGrid", driverName);
        }
        private void Output(IEnumerable <Feature> bufferedFeatures, string path, string projection)
        {
            ShpFileExporter exporter        = new ShpFileExporter();
            string          projectionInWKT = GdalHelper.Proj4ToWkt(projection);
            FileExportInfo  info            = new FileExportInfo(bufferedFeatures, columns, path, projectionInWKT);

            exporter.ExportToFile(info);
        }
Exemplo n.º 7
0
        private void Output(IEnumerable <Feature> bufferedFeatures)
        {
            string         projectionInWKT = GdalHelper.Proj4ToWkt(displayProjectionParameters);
            FileExportInfo info            = new FileExportInfo(bufferedFeatures, GetColumns(), outputPath, projectionInWKT);

            ShpFileExporter exporter = new ShpFileExporter();

            exporter.ExportToFile(info);
        }
Exemplo n.º 8
0
        public void GetSupportedGDalDataTypeSet()
        {
            var gdalDriverForMapFile = Gdal.GetDriverByName("PCRaster");
            var targetTypes          = GdalHelper.GetSupportedValueTypes(gdalDriverForMapFile);

            targetTypes.Should().Contain(DataType.GDT_Byte);
            targetTypes.Should().Contain(DataType.GDT_Int32);
            targetTypes.Should().Contain(DataType.GDT_Float32);
            targetTypes.Should().Have.Count.EqualTo(3);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Configures the specified context.
        /// </summary>
        protected override void Configure(IAppContext context, ToolConfiguration configuration)
        {
            base.Configure(context, configuration);

            var resolutions = new[] { "", "highest", "lowest", "average", "user" };

            configuration.Get <BuildVrtTool>()
            .AddComboList(t => t.Resolution, resolutions)
            .AddComboList(t => t.Resampling, GdalHelper.GetRasterResampling());
        }
Exemplo n.º 10
0
        public void GetSupportedGdalTargetTypeByDriverAndComponentTypeForBIL()
        {
            const string path       = @"..\..\..\..\data\RasterData\Bodem.bil";
            var          driverName = GdalHelper.GetDriverName(path);

            var valueType  = typeof(double);
            var gdalDriver = Gdal.GetDriverByName(driverName);
            var dataType   = GdalHelper.GetGdalDataType(gdalDriver, valueType);

            Assert.AreEqual(DataType.GDT_Float32, dataType);
        }
Exemplo n.º 11
0
 /// <summary>
 /// Initialize Ogr, if it hadn't been initialized yet.
 /// </summary>
 // ReSharper disable once UnusedMember.Local
 private static void ConfigureOgr()
 {
     if (!GdalHelper.Usable)
     {
         GdalHelper.Initialize();
     }
     if (GdalHelper.IsOgrConfigured)
     {
         return;
     }
     GdalHelper.ConfigureOgr();
 }
        private void btnGeo2Prj_Click(object sender, EventArgs e)
        {
            bool   isSaveToSource = this.cbSaveToSourceShpDir.Checked;
            string txtDir         = null;

            if (!isSaveToSource)
            {
                if (!Directory.Exists(txtDir = this.txtTextFileDir.Text.Trim()))
                {
                    MessageBox.Show(@"TXT保存目录不存在,请选择正确的TXT保存目录!", @"坐标文件转换", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            ChangedView(true);
            var rows = this.dataGridView1.Rows;

            this.progressBar1.Maximum = rows.Count;

            foreach (DataGridViewRow row in rows)
            {
                row.Cells["colResult"].Value = "";
            }

            for (int i = 0; i < rows.Count; i++)
            {
                try
                {
                    var path = rows[i].Cells["colFilePath"].Value.ToString();
                    var name = rows[i].Cells["colFileName"].Value.ToString();
                    if (isSaveToSource)
                    {
                        txtDir = Path.GetDirectoryName(path);
                    }

                    var resultPath = Path.Combine(txtDir, name + "_Prj2Geo.shp");
                    if (File.Exists(path))
                    {
                        GdalHelper.ConvertSpatialRef(path, resultPath, null, false);
                    }

                    rows[i].Cells["colResultPath"].Value = resultPath;
                    rows[i].Cells["colResult"].Value     = "成功";
                }
                catch (Exception ex)
                {
                    rows[i].Cells["colResult"].Value = "失败:" + ex.Message;
                }
                this.progressBar1.Value++;
                Application.DoEvents();
            }
            ChangedView(false);
        }
Exemplo n.º 13
0
        protected override void Configure(IAppContext context, ToolConfiguration configuration)
        {
            base.Configure(context, configuration);

            var dataTypes = GdalHelper.GetRasterDataTypes().ToList();

            dataTypes.Insert(0, "<autodetect>");

            configuration.Get <WarpRasterTool>()
            .AddComboList(t => t.DstResampling, GdalHelper.GetRasterResampling())
            .AddComboList(t => t.WorkingPixelsType, dataTypes);
        }
Exemplo n.º 14
0
        public void FixDelft1D2DOutputFile()
        {
            string dir  = TestHelper.GetTestDataPath(TestDataPath.DeltaShell.DeltaShellDeltaShellPluginsSharpMapGisTests);
            string path = dir + @"\RasterData\dm1d0079.asc";

            File.Copy(path, Path.GetFileName(path), true);
            path = Path.GetFileName(path);
            GdalHelper.CheckAndFixAscHeader(path);

            using (TextReader reader = new StreamReader(path))
            {
                string firstLine = reader.ReadLine();
                Assert.IsTrue(firstLine.StartsWith(
                                  "ncols", StringComparison.OrdinalIgnoreCase));
                Assert.IsTrue(File.Exists(path + ".bak"));
            }
        }
Exemplo n.º 15
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //若出现【无法加载 DLL“ogr_wrap”: 找不到指定的模块】,
            //请将附带的DLL.rar中的全部文件解压复制到生成目录bin\x86\Debug(或bin\x86\Debug\DLL),同时安装附带的VC++包(Vcredist_x86.exe)
            //Exception: Unable to load DLL "ogr_wrap": Cannot find the specified module.
            //Solution: ① Please unzip all the files in the attached DLL.rar to the build directory bin\x86\Debug(or bin\x86\Debug\DLL)
            //          ② Install VC++ package (Vcredist_x86.exe)
            //Exception: Unable to open EPSG support file gcs.csv.
            //Solution: Please unzip all the files in the attached Data.rar to the build directory bin\x86\Debug\Data
            GdalHelper.GdalInit();
            Gdal.SetConfigOption("SHAPE_RESTORE_SHX", "YES"); //尝试还原/生成缺少的.shx文件

            Application.Run(new ConverterForm());
        }
Exemplo n.º 16
0
        /// <summary>
        /// Gets list of data types supported by driver according to metadata.
        /// </summary>
        public static IEnumerable<string> GetCreationDataTypes(this DatasourceDriver driver)
        {
            string s = driver.get_Metadata(GdalDriverMetadata.CreationDataTypes);

            IList<string> result;

            if (string.IsNullOrWhiteSpace(s))
            {
                result = GdalHelper.GetRasterDataTypes();
            }
            else
            {
                result = s.Split(new[] { ' ' }).ToList();
            }

            result.Insert(0, SameAsInputDataType);

            return result;
        }
Exemplo n.º 17
0
 /// <summary>
 /// Initialize Gdal, if it hadn't been initialized yet.
 /// </summary>
 private static void ConfigureGdal() => GdalHelper.ConfigureAll();
Exemplo n.º 18
0
        public ShpToTxtSettingsForm(string shpPath)
        {
            InitializeComponent();

            GdalHelper.OpenSource(shpPath, dataSource => InitData(dataSource.GetLayerByIndex(0)));
        }