Example #1
0
        private bool RunGdalImport(string inputFilename, string newTableName = null, string tablename = null)
        {
            DBConnectionTool db             = new DBConnectionTool(this.AxMap, this.MapControlTools);
            string           outputFilename = db.GetGdalConnectionString();

            var gdalUtils = new GdalUtils();
            var options   = new[] { "-append" };

            if ((newTableName != null))
            {
                options = new[]
                { "-nln", newTableName, "-overwrite", tablename }
            }
            ;


            ExportImportCallback callback = new ExportImportCallback(MapControlTools);

            callback.GdalFinished   += Callback_GdalFinished;
            gdalUtils.GlobalCallback = callback;
            openTasks++;
            if (!gdalUtils.GdalVectorTranslate(inputFilename, outputFilename, options, true))
            {
                Events.MapControl_Error export_error = new Events.MapControl_Error()
                {
                    ErrorCode = Events.ErrorCodes.ImportExportError, InMethod = "ImportProject", AxMapError = gdalUtils.ErrorMsg[gdalUtils.LastErrorCode] + " Detailed error: " + gdalUtils.DetailedErrorMsg
                };
                On_Error(export_error);
                return(false);
            }
            return(true);
        }
Example #2
0
        private bool RunGdalTranslate(string inputFilename, string outputFilename, string outputType, string sql, bool append = false, string newTableName = null)
        {
            var gdalUtils = new GdalUtils();
            var options   = new[]
            {
                "-f", outputType,
                "-sql", sql, "-overwrite"
            };

            if (append)
            {
                List <string> newOptions = options.ToList();
                newOptions.Add("-append");
                options = newOptions.ToArray();
            }
            if (newTableName != null)
            {
                List <string> newOptions = options.ToList();
                newOptions.Add("-nln");
                newOptions.Add(newTableName);
                options = newOptions.ToArray();
            }

            ExportImportCallback callback = new ExportImportCallback(MapControlTools);

            callback.GdalFinished   += Callback_GdalFinished;
            gdalUtils.GlobalCallback = callback;
            openTasks++;
            if (!gdalUtils.GdalVectorTranslate(inputFilename, outputFilename, options, true))
            {
                Events.MapControl_Error export_error = new Events.MapControl_Error()
                {
                    ErrorCode = Events.ErrorCodes.ImportExportError, InMethod = "ExportProject", AxMapError = gdalUtils.ErrorMsg[gdalUtils.LastErrorCode] + " Detailed error: " + gdalUtils.DetailedErrorMsg
                };
                On_Error(export_error);

                return(false);
            }
            return(true);
        }