Example #1
0
        public static void CloseInOverlay(this FeatureLayer featureLayer)
        {
            featureLayer.CloseAll();

            LayerPlugin currentFeatureLayerPlugin = GisEditor.LayerManager.GetLayerPlugins(featureLayer.GetType()).FirstOrDefault();

            if (currentFeatureLayerPlugin != null)
            {
                Uri currentFeatureLayerUri = currentFeatureLayerPlugin.GetUri(featureLayer);
                IEnumerable <LayerOverlay> layerOverlays = GisEditor.GetMaps().
                                                           SelectMany(map => map.Overlays).
                                                           OfType <LayerOverlay>().
                                                           Where(layerOverlay =>
                {
                    FeatureLayer matchingShpLayer = layerOverlay.Layers.OfType <FeatureLayer>().Where(tempLayer =>
                    {
                        LayerPlugin tempFeatureLayerPlugin = GisEditor.LayerManager.GetLayerPlugins(tempLayer.GetType()).FirstOrDefault();
                        return(tempFeatureLayerPlugin.GetUri(tempLayer) == currentFeatureLayerUri);
                    }).FirstOrDefault();

                    if (matchingShpLayer != null)
                    {
                        matchingShpLayer.CloseAll();
                        return(true);
                    }
                    return(false);
                });

                foreach (var layerOverlay in layerOverlays)
                {
                    layerOverlay.Close();
                }
            }
            else
            {
                LayerOverlay layerOverlay = GisEditor.ActiveMap.Overlays.OfType <LayerOverlay>().Where(lo => lo.Layers.Contains(featureLayer)).FirstOrDefault();
                if (layerOverlay != null)
                {
                    layerOverlay.Close();
                }
            }
        }
Example #2
0
        public static void ReOpen(this FeatureLayer featureLayer, Action reOpenAction = null)
        {
            bool isOpened = false;

            if (featureLayer.IsOpen)
            {
                isOpened = true;
                featureLayer.CloseAll();
            }

            if (reOpenAction != null)
            {
                reOpenAction();
            }

            if (isOpened)
            {
                featureLayer.Open();
            }
        }
        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);
        }