Пример #1
0
        private void SelectionOverlay_FeatureSelected(object sender, EventArgs e)
        {
            Dictionary <string, string> columnValues = new Dictionary <string, string>();

            foreach (var feature in GisEditor.SelectionManager.GetSelectedFeatures())
            {
                if (!feature.ColumnValues.ContainsKey(FeatureIdColumnName))
                {
                    string featureId = feature.Id;

                    var    selectLayer     = GisEditor.SelectionManager.GetSelectedFeaturesLayer(feature);
                    string featureIdColumn = LayerPluginHelper.GetFeatureIdColumn(selectLayer);

                    if (feature.ColumnValues.ContainsKey(featureIdColumn))
                    {
                        featureId = feature.ColumnValues[featureIdColumn];
                    }
                    //else if (feature.LinkColumnValues.ContainsKey(featureIdColumn))
                    //{
                    //    featureId = string.Join(Environment.NewLine, feature.LinkColumnValues[featureIdColumn].Select(f => f.Value));
                    //}

                    if (featureId.Contains(SelectionTrackInteractiveOverlay.FeatureIdSeparator))
                    {
                        featureId = featureId.Split(new string[] { SelectionTrackInteractiveOverlay.FeatureIdSeparator }, StringSplitOptions.RemoveEmptyEntries)[0];
                    }

                    feature.ColumnValues.Add(SelectionUIPlugin.FeatureIdColumnName, featureId);
                }
            }

            GisEditor.UIManager.BeginRefreshPlugins(new RefreshArgs(this, RefreshArgsDescription.SelectionOverlayFeatureSelectedDescription));
            GisEditor.LoggerManager.Log(LoggerLevel.Debug, "Feature Selected, Count: " + GisEditor.ActiveMap.SelectionOverlay.HighlightFeatureLayer.InternalFeatures.Count.ToString(), "Selection");
        }
        protected override UserControl GetPropertiesUICore(Layer layer)
        {
            UserControl propertiesUserControl = base.GetPropertiesUICore(layer);

            LayerPluginHelper.SaveFeatureIDColumns((FeatureLayer)layer, propertiesUserControl);

            return(propertiesUserControl);
        }
        protected override UserControl GetPropertiesUICore(Layer layer)
        {
            ShapefileFeatureLayerPropertiesUserControl metadataUserControl = new ShapefileFeatureLayerPropertiesUserControl((ShapeFileFeatureLayer)layer);

            LayerPluginHelper.SaveFeatureIDColumns((FeatureLayer)layer, metadataUserControl);

            return(metadataUserControl);
        }
Пример #4
0
        protected override Collection <Layer> GetLayersCore(GetLayersParameters getLayersParameters)
        {
            Collection <Layer> layers = base.GetLayersCore(getLayersParameters);

            foreach (var uri in getLayersParameters.LayerUris)
            {
                WorldFileInfo wInfo = GetWorldFileInfo(uri);
                RasterLayer   layer = GetRasterLayer(uri, wInfo);

                if (layer != null)
                {
                    layer.UpperThreshold = double.MaxValue;
                    layer.LowerThreshold = 0d;
                    layer.Name           = Path.GetFileNameWithoutExtension(uri.LocalPath);

                    layer.Open();
                    if (!layer.HasProjectionText)
                    {
                        string proj4PathFileName = Path.ChangeExtension(uri.LocalPath, "prj");
                        string proj4Parameter    = LayerPluginHelper.GetProj4ProjectionParameter(proj4PathFileName);
                        if (!string.IsNullOrEmpty(proj4Parameter))
                        {
                            layer.InitializeProj4Projection(proj4Parameter);
                        }
                    }
                    else
                    {
                        string proj = layer.GetProjectionText().Trim();
                        if (!string.IsNullOrEmpty(proj))
                        {
                            layer.InitializeProj4Projection(proj);
                        }
                    }

                    layer.Close();

                    layers.Add(layer);
                }
            }

            return(layers);
        }
        private void SetInternalProjection()
        {
            string prjPath      = Path.ChangeExtension(shpLayer.ShapePathFilename, ".prj");
            var    requireIndex = shpLayer.RequireIndex;

            shpLayer.RequireIndex = false;
            bool isDecimalDegree = LayerPluginHelper.IsDecimalDegree(shpLayer);

            shpLayer.RequireIndex             = requireIndex;
            shpLayer.FeatureSource.Projection = new Proj4Projection();
            if (File.Exists(prjPath))
            {
                string wkt = File.ReadAllText(prjPath);
                try
                {
                    string          proj4      = Proj4Projection.ConvertPrjToProj4(wkt);
                    Proj4Projection projection = (Proj4Projection)ShpLayer.FeatureSource.Projection;
                    projection.InternalProjectionParametersString = proj4;
                    projection.SyncProjectionParametersString();
                    IsInternalProjectionDetermined = true;
                }
                catch (Exception ex)
                {
                    GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex));
                    IsInternalProjectionDetermined = false;
                }
            }
            else if (isDecimalDegree)
            {
                Proj4Projection projection = (Proj4Projection)ShpLayer.FeatureSource.Projection;
                projection.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
                projection.SyncProjectionParametersString();
                IsInternalProjectionDetermined = true;
            }
            else
            {
                IsInternalProjectionDetermined = false;
            }
        }
        protected override FeatureLayer CreateFeatureLayerCore(ConfigureFeatureLayerParameters featureLayerStructureParameters)
        {
            string layerPath = LayerPluginHelper.GetLayerUriToSave(featureLayerStructureParameters.LayerUri, ExtensionFilter);

            if (string.IsNullOrEmpty(layerPath))
            {
                return(null);
            }
            featureLayerStructureParameters.LayerUri = new Uri(layerPath);

            Collection <TabDbfColumn> tabDbfColumns = new Collection <TabDbfColumn>();

            foreach (var column in featureLayerStructureParameters.AddedColumns)
            {
                var           columnLenght  = column.MaxLength;
                var           decimalLength = 0;
                DbfColumnType columnType    = DbfColumnType.Character;

                switch (column.TypeName.ToUpperInvariant())
                {
                case "DOUBLE":
                    columnLenght  = columnLenght == 0 ? 10 : columnLenght;
                    decimalLength = 4;
                    columnType    = DbfColumnType.Float;
                    break;

                case "DATE":
                case "DATETIME":
                    columnLenght  = columnLenght == 0 ? 10 : columnLenght;
                    decimalLength = 0;
                    columnType    = DbfColumnType.Date;
                    break;

                case "INTEGER":
                case "INT":
                    columnLenght  = columnLenght == 0 ? 10 : columnLenght;
                    decimalLength = 0;
                    columnType    = DbfColumnType.Numeric;
                    break;

                case "STRING":
                case "CHARACTER":
                    columnLenght  = columnLenght == 0 ? 255 : columnLenght;
                    decimalLength = 0;
                    columnType    = DbfColumnType.Character;
                    break;

                default:
                    break;
                }

                tabDbfColumns.Add(new TabDbfColumn(column.ColumnName, columnType, columnLenght, decimalLength, false, false));
            }

            if (featureLayerStructureParameters.CustomData.ContainsKey("SourceLayer"))
            {
                FeatureLayer sourcefeatureLayer = featureLayerStructureParameters.CustomData["SourceLayer"] as FeatureLayer;
                double       precisionInMeter   = TinyGeoFeatureLayer.GetOptimalPrecision(sourcefeatureLayer, GisEditor.ActiveMap.MapUnit, DistanceUnit.Meter, TinyGeoPrecisionMode.PreventSplitting);

                TinyGeoFeatureLayer.CreateTinyGeoFile(featureLayerStructureParameters.LayerUri.OriginalString, sourcefeatureLayer, GisEditor.ActiveMap.MapUnit, featureLayerStructureParameters.AddedColumns.Select(f => f.ColumnName).ToList(), "", precisionInMeter, Encoding.Default, featureLayerStructureParameters.WellKnownType);

                string prjPath = Path.ChangeExtension(featureLayerStructureParameters.LayerUri.OriginalString, "prj");
                File.WriteAllText(prjPath, Proj4Projection.ConvertProj4ToPrj(featureLayerStructureParameters.Proj4ProjectionParametersString));
            }

            var resultLayer = new TinyGeoFeatureLayer(featureLayerStructureParameters.LayerUri.OriginalString);

            return(resultLayer);
        }
Пример #7
0
        protected override FeatureLayer CreateFeatureLayerCore(ConfigureFeatureLayerParameters featureLayerStructureParameters)
        {
            string layerPath = LayerPluginHelper.GetLayerUriToSave(featureLayerStructureParameters.LayerUri, ExtensionFilter);
            string fileName  = Path.GetFileNameWithoutExtension(layerPath);

            if (string.IsNullOrEmpty(layerPath))
            {
                return(null);
            }
            if (fileName.FirstOrDefault() != null && Char.IsNumber(fileName.FirstOrDefault()))
            {
                MessageBox.Show("Table name can not start with number.");
                return(null);
            }
            featureLayerStructureParameters.LayerUri = new Uri(layerPath);

            Collection <FeatureSourceColumn> columns = new Collection <FeatureSourceColumn>();

            System.Text.RegularExpressions.Regex regx = new System.Text.RegularExpressions.Regex(@"\W");
            foreach (var column in featureLayerStructureParameters.AddedColumns)
            {
                FeatureSourceColumn newColumn = column;
                if (newColumn.ColumnName.Equals("Null", StringComparison.Ordinal))
                {
                    newColumn.ColumnName = "Null_";
                }
                newColumn.ColumnName = regx.Replace(newColumn.ColumnName, string.Empty);
                columns.Add(newColumn);
            }

            string tableName = string.Empty;

            if (featureLayerStructureParameters.CustomData.ContainsKey("TableName"))
            {
                //if (createFeatureLayerParameters.Tag != null)
                //tableName = createFeatureLayerParameters.Tag.ToString().Split('|').First();
                tableName = featureLayerStructureParameters.CustomData["TableName"] as string;
            }
            else
            {
                tableName = Path.GetFileNameWithoutExtension(featureLayerStructureParameters.LayerUri.OriginalString);
            }

            FileGeoDatabaseFeatureLayer.CreateFileGeoDatabase(featureLayerStructureParameters.LayerUri.OriginalString);
            FileGeoDatabaseFeatureLayer.CreateTable(featureLayerStructureParameters.LayerUri.OriginalString, tableName, featureLayerStructureParameters.WellKnownType, columns);

            string prjPath = Path.ChangeExtension(featureLayerStructureParameters.LayerUri.OriginalString, "prj");

            File.WriteAllText(prjPath, Proj4Projection.ConvertProj4ToPrj(featureLayerStructureParameters.Proj4ProjectionParametersString));

            FileGeoDatabaseFeatureLayer fileGeoDatabaseFeatureLayer = new FileGeoDatabaseFeatureLayer(featureLayerStructureParameters.LayerUri.LocalPath, tableName);

            if (featureLayerStructureParameters.AddedFeatures.Count > 0)
            {
                fileGeoDatabaseFeatureLayer.Open();
                fileGeoDatabaseFeatureLayer.EditTools.BeginTransaction();
                foreach (var feature in featureLayerStructureParameters.AddedFeatures)
                {
                    fileGeoDatabaseFeatureLayer.EditTools.Add(feature);
                }
                fileGeoDatabaseFeatureLayer.EditTools.CommitTransaction();
                fileGeoDatabaseFeatureLayer.Close();
            }

            return(fileGeoDatabaseFeatureLayer);
        }
        protected override FeatureLayer CreateFeatureLayerCore(ConfigureFeatureLayerParameters featureLayerStructureParameters)
        {
            string layerPath = LayerPluginHelper.GetLayerUriToSave(featureLayerStructureParameters.LayerUri, ExtensionFilterCore);

            if (string.IsNullOrEmpty(layerPath))
            {
                return(null);
            }
            featureLayerStructureParameters.LayerUri = new Uri(layerPath);

            ShapeFileType shapeFileType = ShapeFileType.Null;

            switch (featureLayerStructureParameters.WellKnownType)
            {
            case WellKnownType.Multipoint:
                shapeFileType = ShapeFileType.Multipoint;
                break;

            case WellKnownType.Point:
                shapeFileType = ShapeFileType.Point;
                break;

            case WellKnownType.Line:
            case WellKnownType.Multiline:
                shapeFileType = ShapeFileType.Polyline;
                break;

            case WellKnownType.Polygon:
            case WellKnownType.Multipolygon:
                shapeFileType = ShapeFileType.Polygon;
                break;
            }

            Dictionary <string, DbfColumn>   dbfColumns    = new Dictionary <string, DbfColumn>();
            Collection <FeatureSourceColumn> addedColumns  = featureLayerStructureParameters.AddedColumns;
            Dictionary <string, string>      oldNewNames   = new Dictionary <string, string>();
            Collection <Feature>             addedFeatures = featureLayerStructureParameters.AddedFeatures;

            bool truncateLongColumn = featureLayerStructureParameters.LongColumnTruncateMode == LongColumnTruncateMode.Truncate;

            if (truncateLongColumn)
            {
                Dictionary <string, string> editColumns = new Dictionary <string, string>();
                if (featureLayerStructureParameters.CustomData.ContainsKey("EditedColumns"))
                {
                    editColumns = featureLayerStructureParameters.CustomData["EditedColumns"] as Dictionary <string, string>;
                }
                addedColumns = TruncateLongColumnNames(featureLayerStructureParameters.AddedColumns, oldNewNames, editColumns);
            }

            foreach (var column in addedColumns)
            {
                if (!string.IsNullOrEmpty(column.ColumnName))
                {
                    DbfColumn dbfColumn = column as DbfColumn;
                    if (dbfColumn != null)
                    {
                        if (dbfColumn.ColumnType == DbfColumnType.DoubleInBinary || dbfColumn.ColumnType == DbfColumnType.DateTime)
                        {
                            dbfColumn.Length        = 8;
                            dbfColumn.DecimalLength = 0;
                        }
                        else if (dbfColumn.ColumnType == DbfColumnType.IntegerInBinary)
                        {
                            dbfColumn.Length        = 4;
                            dbfColumn.DecimalLength = 0;
                        }
                    }
                    else
                    {
                        int columnLenght  = column.MaxLength;
                        int decimalLength = 0;

                        switch (column.TypeName.ToUpperInvariant())
                        {
                        case "DOUBLE":
                        case "NUMERIC":
                            columnLenght = columnLenght == 0 ? 10 : columnLenght;
                            if (columnLenght < 4)
                            {
                                columnLenght = 10;
                            }
                            decimalLength = 4;
                            break;

                        case "DATE":
                        case "DATETIME":
                            columnLenght  = columnLenght == 0 ? 10 : columnLenght;
                            decimalLength = 0;
                            break;

                        case "INTEGER":
                        case "INT":
                            columnLenght  = columnLenght == 0 ? 10 : columnLenght;
                            decimalLength = 0;
                            break;

                        case "STRING":
                        case "CHARACTER":
                            columnLenght  = columnLenght == 0 ? characterTypeLength : columnLenght;
                            decimalLength = 0;
                            break;

                        case "LOGICAL":
                            columnLenght  = 5;
                            decimalLength = 0;
                            break;
                        }

                        DbfColumnType type = DbfColumnType.Character;
                        if (column.TypeName.Equals("DOUBLE", StringComparison.InvariantCultureIgnoreCase))
                        {
                            column.TypeName = DbfColumnType.Float.ToString();
                        }
                        if (column.TypeName.Equals("INT", StringComparison.InvariantCultureIgnoreCase))
                        {
                            column.TypeName = DbfColumnType.Numeric.ToString();
                        }
                        bool isSuccess = Enum.TryParse <DbfColumnType>(column.TypeName, true, out type);
                        if (!isSuccess)
                        {
                            type = DbfColumnType.Character;
                        }

                        dbfColumn           = new DbfColumn(column.ColumnName, type, columnLenght, decimalLength);
                        dbfColumn.TypeName  = column.TypeName;
                        dbfColumn.MaxLength = column.MaxLength;
                    }
                    //Feature firstFeature = featureLayerStructureParameters.AddedFeatures.FirstOrDefault();

                    ////This is to fix that fox pro columns cannot write to dbf, convert all linked columns to character column type.
                    //string tempColumnName = column.ColumnName;
                    //if (oldNewNames.ContainsValue(column.ColumnName))
                    //{
                    //    tempColumnName = oldNewNames.FirstOrDefault(f => f.Value == column.ColumnName).Key;
                    //}
                    //if (tempColumnName.Contains(".") && firstFeature != null && firstFeature.LinkColumnValues.ContainsKey(tempColumnName))
                    //{
                    //    if (dbfColumn.ColumnType != DbfColumnType.Memo)
                    //    {
                    //        dbfColumn.ColumnType = DbfColumnType.Character;
                    //        dbfColumn.Length = characterTypeLength;
                    //        dbfColumn.DecimalLength = 0;
                    //    }
                    //}

                    dbfColumns[dbfColumn.ColumnName] = dbfColumn;
                }
            }

            bool convertMemoToCharacter = featureLayerStructureParameters.MemoColumnConvertMode == MemoColumnConvertMode.ToCharacter;

            Dictionary <string, int> columnLength = new Dictionary <string, int>();

            foreach (var feature in addedFeatures)
            {
                //foreach (var linkColumnValue in feature.LinkColumnValues)
                //{
                //    if (!feature.ColumnValues.ContainsKey(linkColumnValue.Key))
                //    {
                //        string[] values = linkColumnValue.Value.Select(v =>
                //        {
                //            if (v.Value == null)
                //            {
                //                return string.Empty;
                //            }
                //            if (v.Value is DateTime)
                //            {
                //                return ((DateTime)v.Value).ToShortDateString();
                //            }
                //            return v.Value.ToString();
                //        }).ToArray();
                //        if (values.All(v => string.IsNullOrEmpty(v) || string.IsNullOrWhiteSpace(v)))
                //        {
                //            if (oldNewNames.ContainsKey(linkColumnValue.Key))
                //                feature.ColumnValues[oldNewNames[linkColumnValue.Key]] = string.Empty;
                //            else
                //                feature.ColumnValues[linkColumnValue.Key] = string.Empty;
                //        }
                //        else
                //        {
                //            string tempColumName = linkColumnValue.Key;
                //            if (oldNewNames.ContainsKey(linkColumnValue.Key))
                //            {
                //                tempColumName = oldNewNames[linkColumnValue.Key];
                //            }
                //            string linkValue = string.Join(",", values);
                //            feature.ColumnValues[tempColumName] = linkValue;

                //            //Choose the max length
                //            if (columnLength.ContainsKey(tempColumName))
                //            {
                //                if (columnLength[tempColumName] < linkValue.Length)
                //                {
                //                    columnLength[tempColumName] = linkValue.Length;
                //                }
                //            }
                //            else
                //            {
                //                columnLength[tempColumName] = linkValue.Length > 254 ? 254 : linkValue.Length;
                //            }
                //        }
                //    }
                //}
                foreach (var item in oldNewNames)
                {
                    if (feature.ColumnValues.ContainsKey(item.Key))
                    {
                        feature.ColumnValues[oldNewNames[item.Key]] = feature.ColumnValues[item.Key];
                        feature.ColumnValues.Remove(item.Key);
                    }
                }
                if (!convertMemoToCharacter)
                {
                    foreach (var item in feature.ColumnValues)
                    {
                        if (item.Value.Length > characterTypeLength && dbfColumns[item.Key].ColumnType != DbfColumnType.Memo)
                        {
                            dbfColumns[item.Key].ColumnType    = DbfColumnType.Memo;
                            dbfColumns[item.Key].Length        = 4;
                            dbfColumns[item.Key].DecimalLength = 0;
                        }
                    }
                }
            }

            foreach (var column in dbfColumns)
            {
                Feature firstFeature = featureLayerStructureParameters.AddedFeatures.FirstOrDefault();
                //This is to fix that fox pro columns cannot write to dbf, convert all linked columns to character column type.
                string tempColumnName = column.Key;
                if (oldNewNames.ContainsValue(column.Key))
                {
                    tempColumnName = oldNewNames.FirstOrDefault(f => f.Value == column.Key).Key;
                }
                //if (tempColumnName.Contains(".") && firstFeature != null && firstFeature.LinkColumnValues.ContainsKey(tempColumnName))
                //{
                //    if (column.Value.ColumnType != DbfColumnType.Memo)
                //    {
                //        column.Value.ColumnType = DbfColumnType.Character;
                //        //column.Value.Length = characterTypeLength;
                //        column.Value.DecimalLength = 0;

                //        if (columnLength.ContainsKey(tempColumnName) && column.Value.Length < columnLength[tempColumnName])
                //        {
                //            column.Value.Length = columnLength[tempColumnName];
                //        }
                //    }
                //}
            }

            ShapeFileFeatureLayer.CreateShapeFile(shapeFileType,
                                                  featureLayerStructureParameters.LayerUri.OriginalString,
                                                  dbfColumns.Values,
                                                  DefaultEncoding,
                                                  OverwriteMode.Overwrite);

            string encodingPathFileName = Path.ChangeExtension(featureLayerStructureParameters.LayerUri.OriginalString, ".cpg");

            if (File.Exists(encodingPathFileName))
            {
                File.Delete(encodingPathFileName);
            }
            File.WriteAllText(encodingPathFileName, DefaultEncoding.CodePage.ToString(CultureInfo.InvariantCulture));

            string prjPath = Path.ChangeExtension(featureLayerStructureParameters.LayerUri.OriginalString, "prj");

            File.WriteAllText(prjPath, Proj4Projection.ConvertProj4ToPrj(featureLayerStructureParameters.Proj4ProjectionParametersString));

            ShapeFileFeatureLayer resultLayer = new ShapeFileFeatureLayer(featureLayerStructureParameters.LayerUri.LocalPath, GeoFileReadWriteMode.ReadWrite);

            if (addedFeatures.Count > 0)
            {
                resultLayer.Open();
                resultLayer.EditTools.BeginTransaction();
                foreach (var feature in addedFeatures)
                {
                    if (convertMemoToCharacter)
                    {
                        foreach (var item in dbfColumns)
                        {
                            if (feature.ColumnValues.ContainsKey(item.Key) && feature.ColumnValues[item.Key].Length > 254)
                            {
                                feature.ColumnValues[item.Key] = feature.ColumnValues[item.Key].Substring(0, 254);
                            }
                            if (feature.ColumnValues.ContainsKey(item.Key) && feature.ColumnValues[item.Key].Length > item.Value.MaxLength)
                            {
                                feature.ColumnValues[item.Key] = feature.ColumnValues[item.Key].Substring(0, item.Value.MaxLength);
                            }
                        }
                    }

                    resultLayer.EditTools.Add(feature);
                }
                resultLayer.EditTools.CommitTransaction();
                resultLayer.Close();
            }

            return(resultLayer);
        }
Пример #9
0
        public FeatureViewModel(Feature newFeature, FeatureLayer ownerFeatureLayer)
        {
            header = String.Format(CultureInfo.InvariantCulture, "{0}", newFeature.Id);
            //.Length > 5 ? feature.Feature.Id.Substring(0, 5) + "..." : feature.Feature.Id);

            string featureIdColumn = LayerPluginHelper.GetFeatureIdColumn(ownerFeatureLayer);

            if (newFeature.ColumnValues.ContainsKey(featureIdColumn))
            {
                header = String.Format(CultureInfo.InvariantCulture, "{0}", newFeature.ColumnValues[featureIdColumn]);
            }
            //if (newFeature.LinkColumnValues.ContainsKey(featureIdColumn))
            //{
            //    Collection<LinkColumnValue> linkColumnValues = newFeature.LinkColumnValues[featureIdColumn];
            //    header = String.Format(CultureInfo.InvariantCulture, "{0}", string.Join("|||", linkColumnValues.Select(lcv => lcv.Value.ToString())));
            //}

            if (string.IsNullOrEmpty(header) || string.IsNullOrWhiteSpace(header))
            {
                header = "[NONE]";
            }

            featureId = newFeature.Id;
            wkt       = newFeature.GetWellKnownText();
            this.ownerFeatureLayer = ownerFeatureLayer;
            feature = newFeature.CloneDeep(ReturningColumnsType.AllColumns);

            table = new DataTable();
            table.Columns.Add("Column", typeof(string));
            table.Columns.Add("Value", typeof(string));
            table.Columns.Add("RealValue", typeof(string));
            Collection <FeatureSourceColumn> featureColumns = new Collection <FeatureSourceColumn>();
            FeatureLayer columnSourceLayer = newFeature.Tag as FeatureLayer;

            if (columnSourceLayer == null)
            {
                columnSourceLayer = ownerFeatureLayer;
            }

            columnSourceLayer.SafeProcess(() =>
            {
                var tempFeatureColumns = columnSourceLayer.QueryTools.GetColumns();
                foreach (var item in tempFeatureColumns)
                {
                    featureColumns.Add(item);
                }
            });

            if (CalculatedDbfColumn.CalculatedColumns.ContainsKey(columnSourceLayer.FeatureSource.Id))
            {
                foreach (var item in CalculatedDbfColumn.CalculatedColumns[columnSourceLayer.FeatureSource.Id])
                {
                    featureColumns.Add(item);
                }
            }

            foreach (var column in featureColumns)
            {
                if (!string.IsNullOrEmpty(column.ColumnName) && newFeature.ColumnValues.ContainsKey(column.ColumnName))
                {
                    string realValue   = newFeature.ColumnValues[column.ColumnName];
                    string value       = realValue;
                    object valueResult = null;
                    if (column.TypeName.Equals("Double", StringComparison.InvariantCultureIgnoreCase) ||
                        column.TypeName.Equals("Float", StringComparison.InvariantCultureIgnoreCase))
                    {
                        double doubleValue;
                        if (double.TryParse(value, out doubleValue))
                        {
                            value = doubleValue.ToString(CultureInfo.InvariantCulture);
                            DbfColumn dbfColumn = column as DbfColumn;
                            if (dbfColumn != null)
                            {
                                value = doubleValue.ToString("N" + dbfColumn.DecimalLength);
                            }
                        }
                    }
                    else if (column.TypeName.Equals("Integer", StringComparison.InvariantCultureIgnoreCase) ||
                             column.TypeName.Equals("Numeric", StringComparison.InvariantCultureIgnoreCase))
                    {
                        int intValue;
                        value = int.TryParse(value, out intValue) ? intValue.ToString(CultureInfo.InvariantCulture) : string.Empty;
                    }
                    else
                    {
                        valueResult = value;
                        //valueResult = new Uri(value, UriKind.RelativeOrAbsolute);
                    }

                    if (valueResult == null)
                    {
                        valueResult = value;
                    }
                    //if (valueResult == null) valueResult = new Uri(value, UriKind.RelativeOrAbsolute);

                    string alias = ownerFeatureLayer.FeatureSource.GetColumnAlias(column.ColumnName);
                    table.Rows.Add(alias, valueResult, realValue);
                }
            }

            //foreach (KeyValuePair<string, Collection<LinkColumnValue>> item in newFeature.LinkColumnValues.Where(i => !newFeature.ColumnValues.ContainsKey(i.Key)))
            //{
            //    string alias = ownerFeatureLayer.FeatureSource.GetColumnAlias(item.Key);
            //    Collection<LinkColumnValue> linkColumnValues = item.Value;
            //    if (linkColumnValues != null)
            //    {
            //        IEnumerable<string> filteredColumnValues = linkColumnValues
            //            .Select(v =>
            //            {
            //                if (v.Value != null)
            //                {
            //                    if (v.Value is DateTime)
            //                    {
            //                        DateTime dateTime = (DateTime)v.Value;
            //                        if (dateTime != DateTime.MinValue)
            //                        {
            //                            return dateTime.ToString("MM/dd/yyyy");
            //                        }
            //                        return string.Empty;
            //                    }
            //                    return v.Value.ToString();
            //                }
            //                return null;
            //            })
            //            .Where(v => v != null);

            //        string value = string.Join(Environment.NewLine, filteredColumnValues);
            //        string realValue = string.Join(Environment.NewLine, linkColumnValues.Where(c => c != null).Where(v => !string.IsNullOrEmpty(v.ToString())).Select(l => l.Value));
            //        if (Uri.IsWellFormedUriString(value, UriKind.RelativeOrAbsolute))
            //        {
            //            table.Rows.Add(alias, new Uri(value, UriKind.RelativeOrAbsolute), realValue);
            //        }
            //        else
            //        {
            //            table.Rows.Add(alias, value, realValue);
            //        }
            //    }
            //    else
            //    {
            //        table.Rows.Add(alias, new Uri("", UriKind.RelativeOrAbsolute), null);
            //    }
            //}
        }
        protected override FeatureLayer CreateFeatureLayerCore(ConfigureFeatureLayerParameters featureLayerStructureParameters)
        {
            bool hasFeatures = featureLayerStructureParameters.AddedFeatures.Count > 0;

            if (hasFeatures)
            {
                List <string> columns = featureLayerStructureParameters.AddedFeatures[0].ColumnValues.Keys.ToList();
                WKTColumn       = GetUniqueColumn(WKTColumn, columns, 0);
                LongitudeColumn = GetUniqueColumn(LongitudeColumn, columns, 0);
                LatitudeColumn  = GetUniqueColumn(LatitudeColumn, columns, 0);

                foreach (var feature in featureLayerStructureParameters.AddedFeatures)
                {
                    PointShape pointBaseShape = feature.GetShape() as PointShape;
                    if (pointBaseShape != null)
                    {
                        feature.ColumnValues[WKTColumn] = pointBaseShape.GetWellKnownText();
                    }
                    else
                    {
                        feature.ColumnValues[LongitudeColumn] = "";
                        feature.ColumnValues[LatitudeColumn]  = "";
                    }
                }
            }

            string layerPath = LayerPluginHelper.GetLayerUriToSave(featureLayerStructureParameters.LayerUri, ExtensionFilter);

            if (string.IsNullOrEmpty(layerPath))
            {
                return(null);
            }
            featureLayerStructureParameters.LayerUri = new Uri(layerPath);

            Collection <string> csvColumns = new Collection <string>();

            foreach (var column in featureLayerStructureParameters.AddedColumns)
            {
                csvColumns.Add(column.ColumnName);
            }

            string delimiter = ",";

            if (featureLayerStructureParameters.CustomData.ContainsKey("Delimiter"))
            {
                delimiter = featureLayerStructureParameters.CustomData["Delimiter"].ToString();
            }
            else if (featureLayerStructureParameters.WellKnownType != WellKnownType.Point && featureLayerStructureParameters.WellKnownType != WellKnownType.Multipoint)
            {
                delimiter = "\t";
            }

            DelimitedSpatialColumnsType csvMappingType = DelimitedSpatialColumnsType.WellKnownText;

            if (featureLayerStructureParameters.CustomData.ContainsKey("MappingType"))
            {
                csvMappingType = (DelimitedSpatialColumnsType)featureLayerStructureParameters.CustomData["MappingType"];
            }
            else
            {
                if (featureLayerStructureParameters.WellKnownType == WellKnownType.Point || featureLayerStructureParameters.WellKnownType == WellKnownType.Multipoint)
                {
                    csvMappingType = DelimitedSpatialColumnsType.XAndY;
                    featureLayerStructureParameters.CustomData["X"] = LongitudeColumn;
                    featureLayerStructureParameters.CustomData["Y"] = LatitudeColumn;
                    csvColumns.Add(LongitudeColumn);
                    csvColumns.Add(LatitudeColumn);
                    if (hasFeatures)
                    {
                        csvColumns.Add(WKTColumn);
                    }
                }
                else
                {
                    csvMappingType = DelimitedSpatialColumnsType.WellKnownText;
                    featureLayerStructureParameters.CustomData["WKT"] = WKTColumn;
                    if (hasFeatures)
                    {
                        csvColumns.Add(LongitudeColumn);
                        csvColumns.Add(LatitudeColumn);
                    }
                    csvColumns.Add(WKTColumn);
                }
            }

            CsvFeatureLayer.CreateDelimitedFile(featureLayerStructureParameters.LayerUri.OriginalString, csvColumns, delimiter, OverwriteMode.Overwrite);

            string prjPath = Path.ChangeExtension(featureLayerStructureParameters.LayerUri.OriginalString, "prj");

            File.WriteAllText(prjPath, Proj4Projection.ConvertProj4ToPrj(featureLayerStructureParameters.Proj4ProjectionParametersString));

            var resultLayer = new CsvFeatureLayer();

            resultLayer.DelimitedPathFilename = featureLayerStructureParameters.LayerUri.LocalPath;
            resultLayer.Delimiter             = delimiter;
            resultLayer.SpatialColumnType     = csvMappingType;
            resultLayer.RequireIndex          = false;

            if (featureLayerStructureParameters.CustomData.ContainsKey("X"))
            {
                resultLayer.XColumnName = featureLayerStructureParameters.CustomData["X"].ToString();
            }
            if (featureLayerStructureParameters.CustomData.ContainsKey("Y"))
            {
                resultLayer.YColumnName = featureLayerStructureParameters.CustomData["Y"].ToString();
            }
            if (featureLayerStructureParameters.CustomData.ContainsKey("WKT"))
            {
                resultLayer.WellKnownTextColumnName = featureLayerStructureParameters.CustomData["WKT"].ToString();
            }
            resultLayer.Open();
            if (featureLayerStructureParameters.AddedFeatures.Count > 0)
            {
                resultLayer.EditTools.BeginTransaction();
                foreach (var feature in featureLayerStructureParameters.AddedFeatures)
                {
                    resultLayer.EditTools.Add(feature);
                }
                resultLayer.EditTools.CommitTransaction();
            }
            CSVModel.BuildDelimitedConfigurationFile(resultLayer);
            resultLayer.Close();

            return(resultLayer);
        }
        protected override FeatureLayer CreateFeatureLayerCore(ConfigureFeatureLayerParameters featureLayerStructureParameters)
        {
            string layerPath = LayerPluginHelper.GetLayerUriToSave(featureLayerStructureParameters.LayerUri, ExtensionFilter);

            if (string.IsNullOrEmpty(layerPath))
            {
                return(null);
            }
            featureLayerStructureParameters.LayerUri = new Uri(layerPath);

            Collection <TabDbfColumn> tabDbfColumns = new Collection <TabDbfColumn>();

            foreach (var column in featureLayerStructureParameters.AddedColumns)
            {
                var columnLenght  = column.MaxLength;
                var decimalLength = 0;

                switch (column.TypeName.ToUpperInvariant())
                {
                case "DOUBLE":
                    columnLenght  = columnLenght == 0 ? 10 : columnLenght;
                    decimalLength = 4;
                    break;

                case "DATE":
                case "DATETIME":
                    columnLenght  = columnLenght == 0 ? 10 : columnLenght;
                    decimalLength = 0;
                    break;

                case "INTEGER":
                case "INT":
                    columnLenght  = columnLenght == 0 ? 10 : columnLenght;
                    decimalLength = 0;
                    break;

                case "STRING":
                    columnLenght  = columnLenght == 0 ? 255 : columnLenght;
                    decimalLength = 0;
                    break;
                }

                tabDbfColumns.Add(new TabDbfColumn(column.ColumnName, (DbfColumnType)Enum.Parse(typeof(DbfColumnType), column.TypeName, true), columnLenght, decimalLength, false, false));
            }

            TabFeatureLayer.CreateTabFile(featureLayerStructureParameters.LayerUri.OriginalString, tabDbfColumns, new Collection <Feature>(), OverwriteMode.Overwrite);
            TabFeatureLayer.BuildIndexFile(featureLayerStructureParameters.LayerUri.OriginalString);

            string prjPath = Path.ChangeExtension(featureLayerStructureParameters.LayerUri.OriginalString, "prj");

            File.WriteAllText(prjPath, Proj4Projection.ConvertProj4ToPrj(featureLayerStructureParameters.Proj4ProjectionParametersString));

            var resultLayer = new TabFeatureLayer(featureLayerStructureParameters.LayerUri.LocalPath, GeoFileReadWriteMode.ReadWrite);

            if (featureLayerStructureParameters.AddedFeatures.Count > 0)
            {
                resultLayer.Open();
                resultLayer.EditTools.BeginTransaction();
                foreach (var feature in featureLayerStructureParameters.AddedFeatures)
                {
                    resultLayer.EditTools.Add(feature);
                }
                resultLayer.EditTools.CommitTransaction();
                resultLayer.Close();
            }

            return(resultLayer);
        }