Ejemplo n.º 1
0
        protected override TaskPlugin GetTaskPluginCore()
        {
            List <FeatureSource> featureSources = null;

            if (OnlyMergeSelectedFeatures)
            {
                SaveSelectedFeaturesToTempFile();
                featureSources = new List <FeatureSource> {
                    new ShapeFileFeatureSource(tempFilePath)
                };
            }
            else
            {
                featureSources = SelectedLayers.Select(featureLayer => featureLayer.FeatureSource).ToList();
                foreach (var featureSource in featureSources)
                {
                    featureSource.Close();
                    if (featureSource.Projection != null)
                    {
                        featureSource.Projection.Close();
                    }
                }
            }

            var columns = IncludedColumns.Select(c => c.ToFeatureSourceColumn()).ToArray();
            var plugin  = GisEditor.TaskManager.GetActiveTaskPlugins <MergeTaskPlugin>().FirstOrDefault();

            if (plugin != null)
            {
                InitializePlugin(plugin, featureSources, columns);
            }

            return(plugin);
        }
Ejemplo n.º 2
0
        public string GetDetailInfo()
        {
            var sb   = new StringBuilder();
            var name = $"[{SchemaName}].[{TableName}].[{IndexName}]";

            sb.AppendLine($"Name: {name} (Reads:{NotAvailableIfNull(UserReads)} Writes:{NotAvailableIfNull(UserWrites)} Size:{IndexSizeMB.ToString("N2")} MB)");
            sb.AppendLine($"Indexed Columns: {string.Join(", ", IndexedColumns.Select(c => c.ColumnName + (c.IsDescendingKey ? " (desc)" : "")))}");
            sb.AppendLine($"Included Columns: {string.Join(", ", IncludedColumns.Select(c => c.ColumnName))}");

            List <string> attribs = GetAttributes();

            sb.AppendLine($"Attributes: {string.Join(", ", attribs)}");

            sb.AppendLine($"Filter: {FilterDefinition}");

            return(sb.ToString());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the column names
        /// </summary>
        /// <remarks>Because DbfExporter is forward-reading, calling this method multiple times or calling it after <see cref="GetRowFields"/> will throw an exception.</remarks>
        /// <returns>Returns the columns of a Dbf as a <see cref="IEnumerable{T}"/> where T is a <see cref="string"/></returns>
        public IEnumerable <string> GetColumns()
        {
            if (FieldCount == 0)
            {
                ReadHeader();
            }
            if (Columns.Count > 0)
            {
                throw new Exception("Column names have already been read");
            }
            ColumnRenames   = ColumnRenames.ToDictionary(d => d.Key.ToUpper(), d => d.Value);
            IncludedColumns = IncludedColumns.Select(s => s.ToUpper()).ToList();
            bool          addColumn   = IncludedColumns.Count == 0;
            List <string> columnNames = new List <string>();

            byte[] columnHeader = new byte[FieldArraySize];
            DbfFile.Read(columnHeader, 0, FieldArraySize);
            int    baseOffset;
            int    numericDecimal;
            int    columnOffset = 0;
            string pgColumnType;

            for (int i = 0; i < FieldCount; ++i)
            {
                baseOffset = i * FieldDefinitionSize;
                byte[] nameBytes = new byte[FieldNameLength];
                Array.Copy(columnHeader, baseOffset, nameBytes, 0, FieldNameLength);
                string columnName = Encoding.ASCII.GetString(nameBytes).Replace("\0", string.Empty);
                if (ColumnRenames.ContainsKey(columnName))
                {
                    columnName = ColumnRenames[columnName];
                }
                if (ReservedWords.Contains(columnName))
                {
                    int increment = 0;
                    while (IncludedColumns.Contains($"{columnName}_{++increment}"))
                    {
                        ;
                    }
                    columnName = $"{columnName}_{increment}";
                }
                if (addColumn)
                {
                    IncludedColumns.Add(columnName);
                }
                var       dbfColumnType = Convert.ToChar(columnHeader[baseOffset + FieldTypeOffset]);
                DbfColumn column        = dbfColumnType == 'M' ? new MemoColumn() : new DbfColumn();
                column.Export = IncludedColumns.Contains(columnName) || addColumn;
                column.Type   = dbfColumnType;
                column.Length = columnHeader[baseOffset + FieldLengthOffset];
                column.Offset = columnOffset;
                columnOffset += column.Length;
                Columns.Add(column);
                if (CreateTable)
                {
                    pgColumnType = "TEXT";
                    if (column.Type == 'N' || column.Type == 'F')
                    {
                        if (ConvertNumericToText)
                        {
                            pgColumnType = "TEXT";
                        }
                        else
                        {
                            numericDecimal = columnHeader[baseOffset + FieldDecimalsOffset];
                            pgColumnType   = numericDecimal == 0 ?
                                             $"NUMERIC({column.Length})" :
                                             $"NUMERIC({column.Length},{numericDecimal})";
                        }
                    }
                    else if (column.Type == 'L')
                    {
                        if (ConvertBoolToVarChar)
                        {
                            column.Type  = 'C';
                            pgColumnType = "VARCHAR(1)";
                        }
                        else
                        {
                            pgColumnType = "BOOLEAN";
                        }
                    }
                    else if (column.Type == 'M')
                    {
                        pgColumnType = "TEXT";
                    }
                    else
                    {
                        pgColumnType = $"VARCHAR({column.Length})";
                    }
                    if (column.Export)
                    {
                        columnNames.Add(columnName + " " + pgColumnType);
                    }
                }
                else if (column.Export)
                {
                    columnNames.Add(columnName);
                }
            }
            InitMemoFile();
            DbfFile.Seek(SkipBytes + 1, SeekOrigin.Current);
            return(columnNames);
        }
Ejemplo n.º 4
0
 public override string ToString()
 {
     return($"{IndexName} Cols:{string.Join(", ", IndexedColumns.Select(c => c.ColumnName))} Includes:{string.Join(", ", IncludedColumns.Select(c => c.ColumnName))}");
 }