public GottenLayersLayerPluginEventArgs(IEnumerable <Layer> layers, GetLayersParameters parameters)
 {
     this.parameters = parameters;
     this.layers     = new Collection <Layer>();
     foreach (var layer in layers)
     {
         this.layers.Add(layer);
     }
 }
        protected virtual Collection <T> GetLayersCore <T>(GetLayersParameters getLayersParameters) where T : Layer
        {
            Collection <T> resultLayers = new Collection <T>();
            LayerPlugin    layerPlugin  = GetLayerPlugins(typeof(T)).FirstOrDefault();

            if (layerPlugin != null && layerPlugin.IsActive)
            {
                IEnumerable <T> layers = layerPlugin.GetLayers(getLayersParameters).OfType <T>();
                foreach (T layer in layers)
                {
                    resultLayers.Add(layer);
                }
            }

            return(resultLayers);
        }
Esempio n. 3
0
        public Collection <Layer> GetLayers(GetLayersParameters getLayersParameters)
        {
            if (getLayersParameters == null)
            {
                getLayersParameters = new GetLayersParameters();
            }

            GettingLayersLayerPluginEventArgs gettingLayersEventArgs = new GettingLayersLayerPluginEventArgs(getLayersParameters);

            OnGettingLayers(gettingLayersEventArgs);
            getLayersParameters = gettingLayersEventArgs.Parameters;

            Collection <Layer> layers = GetLayersCore(getLayersParameters);

            GottenLayersLayerPluginEventArgs gotLayersEventArgs = new GottenLayersLayerPluginEventArgs(layers, getLayersParameters);

            OnGottenLayers(gotLayersEventArgs);
            return(gotLayersEventArgs.Layers);
        }
Esempio n. 4
0
        /// <summary>
        /// This method creates layers instance.
        /// In this method, it might popup a dialog to configuration.
        /// For example, a ShapeFileFeatureLayer is based on a shapefile, we need popup an OpenFileDialog to choose a file.
        /// Or MSSql layer needs a connection string to connect to the server, etc.
        /// </summary>
        /// <returns>A set of specific layers that created by this plugin.</returns>
        protected virtual Collection <Layer> GetLayersCore(GetLayersParameters getLayersParameters)
        {
            if (!String.IsNullOrEmpty(ExtensionFilter) && (getLayersParameters == null || getLayersParameters.LayerUris.Count == 0))
            {
                if (openFileDialog == null)
                {
                    openFileDialog             = new OpenFileDialog();
                    openFileDialog.Multiselect = true;
                    openFileDialog.Filter      = ExtensionFilter;
                }

                if (openFileDialog.ShowDialog().GetValueOrDefault())
                {
                    foreach (string fileName in openFileDialog.FileNames)
                    {
                        getLayersParameters.LayerUris.Add(new Uri(fileName));
                    }
                }
            }

            return(new Collection <Layer>());
        }
        private void ExportToShapeFile(Collection <Feature> resultFeatures, Collection <FeatureSourceColumn> columns, FeatureLayerPlugin sourceLayerPlugin, WellKnownType type)
        {
            int count = resultFeatures.Count;

            if (count > 0)
            {
                FeatureLayerPlugin targetLayerPlugin = (FeatureLayerPlugin)GisEditor.LayerManager.GetLayerPlugins(typeof(ShapeFileFeatureLayer)).FirstOrDefault();
                FeatureLayer       resultLayer       = null;

                if (targetLayerPlugin != null)
                {
                    GetLayersParameters             getLayerParameters = new GetLayersParameters();
                    ConfigureFeatureLayerParameters parameters         = targetLayerPlugin.GetCreateFeatureLayerParameters(columns);
                    if (parameters != null && sourceLayerPlugin != null)
                    {
                        bool needColumns = false;
                        Collection <string> tempColumns = new Collection <string>();
                        if (parameters.CustomData.ContainsKey("Columns"))
                        {
                            tempColumns = parameters.CustomData["Columns"] as Collection <string>;
                        }
                        else
                        {
                            needColumns = true;
                        }

                        var featureColumns = columns.Where(c => needColumns || tempColumns.Contains(c.ColumnName));
                        if (targetLayerPlugin.CanCreateFeatureLayerWithSourceColumns(sourceLayerPlugin))
                        {
                            foreach (var item in featureColumns)
                            {
                                FeatureSourceColumn column = new FeatureSourceColumn(item.ColumnName, item.TypeName, item.MaxLength);
                                if (column.TypeName.Equals("c", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    column.TypeName = "Character";
                                }
                                parameters.AddedColumns.Add(column);
                            }
                        }
                        else
                        {
                            var geoColumns = sourceLayerPlugin.GetIntermediateColumns(featureColumns);
                            foreach (var item in geoColumns)
                            {
                                if (item.TypeName.Equals("c", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    item.TypeName = "Character";
                                }
                                parameters.AddedColumns.Add(item);
                            }
                        }


                        parameters.WellKnownType = type;
                        //parameters.CustomData["SourceLayer"] = featureLayer;

                        getLayerParameters.LayerUris.Add(parameters.LayerUri);
                        foreach (var item in parameters.CustomData)
                        {
                            getLayerParameters.CustomData[item.Key] = item.Value;
                        }

                        Proj4Projection proj4 = new Proj4Projection();
                        proj4.InternalProjectionParametersString = parameters.Proj4ProjectionParametersString;
                        proj4.ExternalProjectionParametersString = GisEditor.ActiveMap.DisplayProjectionParameters;
                        proj4.SyncProjectionParametersString();
                        proj4.Open();

                        foreach (var item in resultFeatures)
                        {
                            Feature feature = proj4.ConvertToInternalProjection(item);
                            parameters.AddedFeatures.Add(feature);
                        }

                        if (parameters.MemoColumnConvertMode == MemoColumnConvertMode.ToCharacter)
                        {
                            foreach (var item in parameters.AddedColumns.Where(c => c.TypeName.Equals("Memo", StringComparison.InvariantCultureIgnoreCase)).ToList())
                            {
                                item.TypeName  = "Character";
                                item.MaxLength = 254;
                                DbfColumn tmpDbfColumn = item as DbfColumn;
                                if (tmpDbfColumn != null)
                                {
                                    tmpDbfColumn.ColumnType = DbfColumnType.Character;
                                    tmpDbfColumn.Length     = 254;
                                }
                            }
                        }

                        resultLayer = targetLayerPlugin.CreateFeatureLayer(parameters);
                        resultLayer.FeatureSource.Projection = proj4;
                        resultLayer = targetLayerPlugin.GetLayers(getLayerParameters).FirstOrDefault() as FeatureLayer;
                    }
                }

                if (resultLayer != null)
                {
                    GisEditorMessageBox messageBox = new GisEditorMessageBox(MessageBoxButton.YesNo);
                    messageBox.Owner = Application.Current.MainWindow;
                    messageBox.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                    messageBox.Title        = GisEditor.LanguageManager.GetStringResource("NavigatePluginAddToMap");
                    messageBox.Message      = GisEditor.LanguageManager.GetStringResource("DoYouWantToAddToMap");
                    messageBox.ErrorMessage = string.Empty;
                    if (messageBox.ShowDialog().Value)
                    {
                        GisEditor.ActiveMap.AddLayerToActiveOverlay(resultLayer);
                        GisEditor.ActiveMap.RefreshActiveOverlay();
                        RefreshArgs refreshArgs = new RefreshArgs(this, "LoadToMapCore");
                        InvokeRefreshPlugins(GisEditor.UIManager, refreshArgs);
                        GisEditor.ActiveMap.Refresh();
                    }
                }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("There is no features to export.", "Export");
            }
        }
        /// <summary>
        /// Gets the layers core.
        /// </summary>
        /// <returns></returns>
        protected virtual Collection <Layer> GetLayersCore()
        {
            Collection <Layer> resultsLayers = new Collection <Layer>();
            var supportedLayerProviders      = GetLayerPlugins()
                                               .Where(p => p.IsActive && !string.IsNullOrEmpty(p.ExtensionFilter)).ToList();

            int count = supportedLayerProviders.Count();

            if (count > 0)
            {
                StringBuilder filterStringBuilder         = new StringBuilder();
                StringBuilder allFilesFilterStringBuilder = new StringBuilder();

                foreach (var fileLayerPlugin in supportedLayerProviders)
                {
                    string[] array = fileLayerPlugin.ExtensionFilter.Split('|');
                    if (array != null && array.Length >= 2)
                    {
                        allFilesFilterStringBuilder.Append(array[1] + ";");
                    }
                }

                filterStringBuilder.Append("All Supported Formats|" + allFilesFilterStringBuilder.ToString());

                foreach (var fileLayerPlugin in supportedLayerProviders)
                {
                    filterStringBuilder.Append("|" + fileLayerPlugin.ExtensionFilter);
                }

                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Multiselect = true;
                openFileDialog.Filter      = filterStringBuilder.ToString();
                if (openFileDialog.ShowDialog().GetValueOrDefault())
                {
                    var groupedFileDataItems = openFileDialog.FileNames.GroupBy(item => Path.GetExtension(item));
                    foreach (var fileDataItems in groupedFileDataItems)
                    {
                        var extension           = fileDataItems.Key.ToUpperInvariant();
                        var matchingLayerPlugin = GetActiveLayerPlugins()
                                                  .FirstOrDefault(tmpPlugin => tmpPlugin.ExtensionFilter.ToUpperInvariant()
                                                                  .Contains(extension));

                        if (matchingLayerPlugin != null)
                        {
                            var getLayersParameters = new GetLayersParameters();
                            foreach (var item in fileDataItems)
                            {
                                getLayersParameters.LayerUris.Add(new Uri(item));
                            }
                            var layers = matchingLayerPlugin.GetLayers(getLayersParameters);
                            foreach (var layer in layers)
                            {
                                resultsLayers.Add(layer);
                            }
                        }
                        else
                        {
                            System.Windows.Forms.MessageBox.Show(GisEditor.LanguageManager.GetStringResource("DataRepositoryCannotFindLayerProviderWarningLabel"), GisEditor.LanguageManager.GetStringResource("MessageBoxWarningTitle"), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                        }
                    }
                }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show(GisEditor.LanguageManager.GetStringResource("LayerPluginManagerNotFoundText"), GisEditor.LanguageManager.GetStringResource("LayerPluginManagerNotFoundCaption"), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
            }

            return(resultsLayers);
        }
 public Collection <T> GetLayers <T>(GetLayersParameters getLayersParameters) where T : Layer
 {
     return(GetLayersCore <T>(getLayersParameters));
 }
 public GettingLayersLayerPluginEventArgs(GetLayersParameters parameters)
 {
     this.parameters = parameters;
 }