protected override void RunCore()
        {
            //if (FeatureLayer != null && FeatureLayer.FeatureSource.LinkSources.Count > 0)
            //{
            //    hasLinkSource = true;
            //}

            if (FeaturesForExporting.Count == 0 && FeatureIdsForExporting.Count > 0 && FeatureLayer != null)
            {
                FeatureLayer.CloseAll();
                FeatureLayer.SafeProcess(() =>
                {
                    //if (FeatureLayer.FeatureSource.LinkSources.Count > 0)
                    //{
                    //    featuresForExporting = FeatureLayer.FeatureSource.GetFeaturesByIds(FeatureIdsForExporting, FeatureLayer.GetDistinctColumnNames());
                    //    hasLinkSource = true;
                    //}
                    //else
                    //{
                    //    featuresForExporting = FeatureLayer.QueryTools.GetFeaturesByIds(FeatureIdsForExporting, FeatureLayer.GetDistinctColumnNames());
                    //    hasLinkSource = false;
                    //}

                    featuresForExporting = FeatureLayer.QueryTools.GetFeaturesByIds(FeatureIdsForExporting, FeatureLayer.GetDistinctColumnNames());
                    hasLinkSource        = false;
                });
            }

            Proj4Projection proj4 = new Proj4Projection();

            proj4.InternalProjectionParametersString = InternalPrj4Projection;
            proj4.ExternalProjectionParametersString = Proj4Projection.ConvertPrjToProj4(ProjectionWkt);
            proj4.SyncProjectionParametersString();
            proj4.Open();

            Collection <Feature> exportFeatures = FeaturesForExporting;

            if (proj4.CanProject())
            {
                exportFeatures = new Collection <Feature>();
                foreach (var item in FeaturesForExporting)
                {
                    Feature newFeature = item;
                    newFeature = proj4.ConvertToExternalProjection(item);
                    exportFeatures.Add(newFeature);
                }
            }
            proj4.Close();

            #region This is a trick to fix that fox pro columns cannot write to dbf, convert all fox pro columns to character column type.

            if (hasLinkSource)
            {
                Collection <string> dateTimeColumns = new Collection <string>();
                Collection <string> dateColumns     = new Collection <string>();

                foreach (var item in FeatureSourceColumns)
                {
                    string doubleInBinary  = DbfColumnType.DoubleInBinary.ToString();
                    string integerInBinary = DbfColumnType.IntegerInBinary.ToString();
                    string dateTime        = DbfColumnType.DateTime.ToString();
                    string date            = DbfColumnType.Date.ToString();
                    string logical         = DbfColumnType.Logical.ToString();

                    if (item.TypeName.Equals(doubleInBinary, StringComparison.OrdinalIgnoreCase) ||
                        item.TypeName.Equals(integerInBinary, StringComparison.OrdinalIgnoreCase) ||
                        item.TypeName.Equals(dateTime, StringComparison.OrdinalIgnoreCase) ||
                        item.TypeName.Equals(date, StringComparison.OrdinalIgnoreCase) ||
                        item.TypeName.Equals(logical, StringComparison.OrdinalIgnoreCase))
                    {
                        item.TypeName = DbfColumnType.Character.ToString();
                    }
                }

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

                //foreach (var feature in exportFeatures)
                //{
                //    // Fill link column values into column values.
                //    foreach (var item in feature.LinkColumnValues)
                //    {
                //        string key = item.Key;
                //        string value = string.Join("\r\n", item.Value.Select(v => v.Value));
                //        feature.ColumnValues[key] = value;
                //        longLengthColumnNames[key] = value.Length;
                //    }
                //}

                // fix too long column value
                foreach (var key in longLengthColumnNames.Keys)
                {
                    FeatureSourceColumn column = FeatureSourceColumns.FirstOrDefault(f => f.ColumnName.Equals(key, StringComparison.OrdinalIgnoreCase));
                    if (column != null)
                    {
                        int length = longLengthColumnNames[key];
                        if (length > column.MaxLength)
                        {
                            column.MaxLength = length;
                        }
                    }
                }
            }

            #endregion This is a trick to fix that fox pro columns cannot write to dbf.

            if (NeedConvertMemoToCharacter)
            {
                foreach (var feature in exportFeatures)
                {
                    foreach (var item in FeatureSourceColumns)
                    {
                        if (item.TypeName.Equals(DbfColumnType.Memo.ToString(), StringComparison.OrdinalIgnoreCase))
                        {
                            item.TypeName  = DbfColumnType.Character.ToString();
                            item.MaxLength = 254;
                        }
                        else if (item.TypeName.Equals(DbfColumnType.Character.ToString(), StringComparison.OrdinalIgnoreCase) &&
                                 item.MaxLength > 254)
                        {
                            item.MaxLength = 254;
                        }
                        //if (feature.ColumnValues.ContainsKey(item.ColumnName) && feature.ColumnValues[item.ColumnName].Length > 254)
                        //{
                        //    feature.ColumnValues[item.ColumnName] = feature.ColumnValues[item.ColumnName].Substring(0, 254);
                        //}
                    }
                }
            }

            var info = new FileExportInfo(exportFeatures, FeatureSourceColumns, OutputPathFileName, ProjectionWkt);
            foreach (var item in CostomizedColumnNames)
            {
                info.CostomizedColumnNames.Add(item.Key, item.Value);
            }
            Export(info);
        }
Beispiel #2
0
        private static void SetExtent(GisEditorWpfMap map)
        {
            if (map.Overlays.Count == 1)
            {
                RectangleShape extent = map.Overlays[0].GetBoundingBox();
                if (map.Overlays[0] is WorldMapKitMapOverlay)
                {
                    extent = new RectangleShape(-152.941811131969, 73.3011270968869, -63.395569383504, 4.88674180823698);
                }
                if (extent == null)
                {
                    extent = new RectangleShape(-130, 90, 130, -90);
                    var proj = new Proj4Projection();
                    proj.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
                    proj.ExternalProjectionParametersString = map.DisplayProjectionParameters;
                    proj.SyncProjectionParametersString();
                    proj.Open();
                    extent = proj.ConvertToExternalProjection(extent);
                }
                map.CurrentExtent = extent;
            }

            if (map.Overlays.Count <= 1 &&
                System.Windows.Application.Current != null &&
                System.Windows.Application.Current.MainWindow.Tag is Dictionary <string, string> )
            {
                var tmpSettings          = System.Windows.Application.Current.MainWindow.Tag as Dictionary <string, string>;
                var currentExtentStrings = tmpSettings["CurrentExtent"].Split(',');

                if (currentExtentStrings.Length > 3)
                {
                    double minX = double.NaN;
                    double maxY = double.NaN;
                    double maxX = double.NaN;
                    double minY = double.NaN;

                    if (double.TryParse(currentExtentStrings[0], out minX) &&
                        double.TryParse(currentExtentStrings[1], out maxY) &&
                        double.TryParse(currentExtentStrings[2], out maxX) &&
                        double.TryParse(currentExtentStrings[3], out minY))
                    {
                        RectangleShape  extent     = new RectangleShape(minX, maxY, maxX, minY);
                        Proj4Projection projection = new Proj4Projection(Proj4Projection.GetWgs84ParametersString(), map.DisplayProjectionParameters);
                        projection.SyncProjectionParametersString();
                        if (projection.CanProject())
                        {
                            try
                            {
                                projection.Open();
                                extent = projection.ConvertToExternalProjection(extent);
                            }
                            catch (Exception ex)
                            {
                                GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex));
                            }
                            finally
                            {
                                projection.Close();
                            }
                        }

                        map.CurrentExtent = extent;
                    }
                }
            }
        }