private void InitSelectableFeatureLayers()
        {
            featureLayers = new ObservableCollection <FeatureLayer>();

            if (GisEditor.ActiveMap != null)
            {
                var allFeatureLayers = GisEditor.ActiveMap.GetFeatureLayers(true).Where(layer =>
                {
                    if (layer is ShapeFileFeatureLayer)
                    {
                        ShapeFileFeatureLayerPlugin layerPlugin = new ShapeFileFeatureLayerPlugin();
                        var shapeType = layerPlugin.GetFeatureSimpleShapeType(layer);
                        if (shapeType == SimpleShapeType.Point)
                        {
                            return(false);
                        }
                    }

                    return(true);
                });

                foreach (var featureLayer in allFeatureLayers)
                {
                    FeatureLayers.Add(featureLayer);
                }
            }
        }
示例#2
0
 public ConfigLayerStructureViewModel(FeatureLayer featureLayer)
     : base()
 {
     shpFileType          = GeneralShapeFileType.Area;
     columnListItemSource = new ObservableCollection <FeatureSourceColumnItem>();
     FeatureLayer         = featureLayer;
     LayerPlugin          = new ShapeFileFeatureLayerPlugin();
     isAliasEnabled       = true;
     layerUri             = new Uri(ConfigShapeFileViewModel.GetDefaultOutputPath());
 }
        private static void ExportToShapeFile(Collection <Feature> resultFeatures, Collection <FeatureSourceColumn> columns, FeatureLayerPlugin sourceLayerPlugin, WellKnownType type)
        {
            int count = resultFeatures.Count;

            if (count > 0)
            {
                ShapeFileFeatureLayerPlugin targetLayerPlugin = GisEditor.LayerManager.GetActiveLayerPlugins <ShapeFileFeatureLayerPlugin>().FirstOrDefault();
                FeatureLayer        resultLayer        = null;
                GetLayersParameters getLayerParameters = new GetLayersParameters();

                if (targetLayerPlugin != null)
                {
                    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())
                            {
                                //parameters.AddedColumns.Remove(item);
                                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(null, "LoadToMapCore");
                        InvokeRefreshPlugins(GisEditor.UIManager, refreshArgs);
                        GisEditor.ActiveMap.Refresh();
                    }
                }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("There's no features in this layer.", "Export File");
            }
        }