Exemple #1
0
        private async void OnSaveAsCommand(object obj)
        {
            var saveAsDialog = new ProSaveAsFormatView();
            var vm           = new ProSaveAsFormatViewModel();

            saveAsDialog.DataContext = vm;

            if (saveAsDialog.ShowDialog() == true)
            {
                var fcUtils = new FeatureClassUtils();

                string path = fcUtils.PromptUserWithSaveDialog(vm.FeatureIsChecked, vm.ShapeIsChecked, vm.KmlIsChecked, vm.CSVIsChecked);
                if (path != null)
                {
                    try
                    {
                        string folderName   = System.IO.Path.GetDirectoryName(path);
                        var    mapPointList = CoordinateAddInPoints.Select(i => i.Point).ToList();
                        if (vm.FeatureIsChecked)
                        {
                            await fcUtils.CreateFCOutput(path,
                                                         SaveAsType.FileGDB,
                                                         mapPointList,
                                                         MapView.Active.Map.SpatialReference,
                                                         MapView.Active,
                                                         CoordinateConversionLibrary.GeomType.Point);
                        }
                        else if (vm.ShapeIsChecked || vm.KmlIsChecked)
                        {
                            await fcUtils.CreateFCOutput(path, SaveAsType.Shapefile, mapPointList, MapView.Active.Map.SpatialReference, MapView.Active, CoordinateConversionLibrary.GeomType.Point, vm.KmlIsChecked);
                        }
                        else if (vm.CSVIsChecked)
                        {
                            var aiPoints = CoordinateAddInPoints.ToList();

                            if (aiPoints == null || !aiPoints.Any())
                            {
                                return;
                            }

                            var csvExport = new CsvExport();
                            foreach (var point in aiPoints)
                            {
                                csvExport.AddRow();
                                csvExport["Coordinate"] = point.Text;
                            }
                            csvExport.ExportToFile(path);

                            System.Windows.Forms.MessageBox.Show(CoordinateConversionLibrary.Properties.Resources.CSVExportSuccessfulMessage + path,
                                                                 CoordinateConversionLibrary.Properties.Resources.CSVExportSuccessfulCaption);
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
        }
        private void OnSaveAsCommand(object obj)
        {
            var saveAsDialog = new AMSaveAsFormatView();
            var vm           = new SaveAsFormatViewModel();

            saveAsDialog.DataContext = vm;

            if (saveAsDialog.ShowDialog() == true)
            {
                IFeatureClass fc      = null;
                string        path    = null;
                var           fcUtils = new FeatureClassUtils();
                if (vm.FeatureShapeIsChecked)
                {
                    path = fcUtils.PromptUserWithGxDialog(ArcMap.Application.hWnd);
                    if (path != null)
                    {
                        if (System.IO.Path.GetExtension(path).Equals(".shp"))
                        {
                            fc = fcUtils.CreateFCOutput(path, SaveAsType.Shapefile, GraphicsList, ArcMap.Document.FocusMap.SpatialReference);
                        }
                        else
                        {
                            fc = fcUtils.CreateFCOutput(path, SaveAsType.FileGDB, GraphicsList, ArcMap.Document.FocusMap.SpatialReference);
                        }
                    }
                }
                else
                {
                    path = PromptSaveFileDialog();
                    if (path != null)
                    {
                        string        kmlName       = System.IO.Path.GetFileName(path);
                        string        folderName    = System.IO.Path.GetDirectoryName(path);
                        string        tempShapeFile = folderName + "\\tmpShapefile.shp";
                        IFeatureClass tempFc        = fcUtils.CreateFCOutput(tempShapeFile, SaveAsType.Shapefile, GraphicsList, ArcMap.Document.FocusMap.SpatialReference);

                        if (tempFc != null)
                        {
                            var kmlUtils = new KMLUtils();
                            kmlUtils.ConvertLayerToKML(path, tempShapeFile, ArcMap.Document.FocusMap);

                            // delete the temporary shapefile
                            fcUtils.DeleteShapeFile(tempShapeFile);
                        }
                    }
                }

                if (fc != null)
                {
                    AddFeatureLayerToMap(fc);
                }
            }
        }
        private async void OnSaveAsCommand(object obj)
        {
            var saveAsDialog = new ProSaveAsFormatView();
            var vm           = new ProSaveAsFormatViewModel();

            saveAsDialog.DataContext = vm;

            if (saveAsDialog.ShowDialog() == true)
            {
                var fcUtils = new FeatureClassUtils();

                string path = fcUtils.PromptUserWithSaveDialog(vm.FeatureIsChecked, vm.ShapeIsChecked, vm.KmlIsChecked);
                if (path != null)
                {
                    try
                    {
                        string folderName   = System.IO.Path.GetDirectoryName(path);
                        var    mapPointList = CoordinateAddInPoints.Select(i => i.Point).ToList();
                        if (vm.FeatureIsChecked)
                        {
                            await fcUtils.CreateFCOutput(path,
                                                         SaveAsType.FileGDB,
                                                         mapPointList,
                                                         MapView.Active.Map.SpatialReference,
                                                         MapView.Active,
                                                         CoordinateConversionLibrary.GeomType.Point);
                        }
                        else if (vm.ShapeIsChecked || vm.KmlIsChecked)
                        {
                            await fcUtils.CreateFCOutput(path, SaveAsType.Shapefile, mapPointList, MapView.Active.Map.SpatialReference, MapView.Active, CoordinateConversionLibrary.GeomType.Point, vm.KmlIsChecked);
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
        }
        private void OnSaveAsCommand(object obj)
        {
            var saveAsDialog = new AMSaveAsFormatView();
            var vm           = new SaveAsFormatViewModel();

            saveAsDialog.DataContext = vm;

            if (saveAsDialog.ShowDialog() == true)
            {
                IFeatureClass fc      = null;
                string        path    = null;
                var           fcUtils = new FeatureClassUtils();
                if (vm.FeatureShapeIsChecked)
                {
                    path = fcUtils.PromptUserWithGxDialog(ArcMap.Application.hWnd);
                    if (path != null)
                    {
                        SaveAsType saveType = System.IO.Path.GetExtension(path).Equals(".shp") ? SaveAsType.Shapefile : SaveAsType.FileGDB;
                        fc = fcUtils.CreateFCOutput(path, saveType, GraphicsList, ArcMap.Document.FocusMap.SpatialReference);
                    }
                }
                else if (vm.KmlIsChecked)
                {
                    path = PromptSaveFileDialog("kmz", "KMZ File (*.kmz)|*.kmz", CoordinateConversionLibrary.Properties.Resources.KMLLocationMessage);
                    if (path != null)
                    {
                        string        kmlName       = System.IO.Path.GetFileName(path);
                        string        folderName    = System.IO.Path.GetDirectoryName(path);
                        string        tempShapeFile = folderName + "\\tmpShapefile.shp";
                        IFeatureClass tempFc        = fcUtils.CreateFCOutput(tempShapeFile, SaveAsType.Shapefile, GraphicsList, ArcMap.Document.FocusMap.SpatialReference);

                        if (tempFc != null)
                        {
                            var kmlUtils = new KMLUtils();
                            kmlUtils.ConvertLayerToKML(path, tempShapeFile, ArcMap.Document.FocusMap);

                            // delete the temporary shapefile
                            fcUtils.DeleteShapeFile(tempShapeFile);
                        }
                    }
                }
                else
                {
                    //Export to CSV
                    path = PromptSaveFileDialog("csv", "CSV File (*.csv)|*.csv", CoordinateConversionLibrary.Properties.Resources.CSVLocationMessage);
                    if (path != null)
                    {
                        string csvName    = System.IO.Path.GetFileName(path);
                        string folderName = System.IO.Path.GetDirectoryName(path);
                        string tempFile   = System.IO.Path.Combine(folderName, csvName);

                        var aiPoints = CoordinateAddInPoints.ToList();

                        if (aiPoints == null || !aiPoints.Any())
                        {
                            return;
                        }

                        var csvExport = new CsvExport();
                        foreach (var point in aiPoints)
                        {
                            csvExport.AddRow();
                            csvExport["Coordinates"] = point.Text;
                        }
                        csvExport.ExportToFile(tempFile);

                        System.Windows.Forms.MessageBox.Show(CoordinateConversionLibrary.Properties.Resources.CSVExportSuccessfulMessage + tempFile,
                                                             CoordinateConversionLibrary.Properties.Resources.CSVExportSuccessfulCaption);
                    }
                }

                if (fc != null)
                {
                    AddFeatureLayerToMap(fc);
                }
            }
        }
        private void OnSaveAsCommand(object obj)
        {
            var saveAsDialog = new AMSaveAsFormatView();
            var vm           = new SaveAsFormatViewModel();

            saveAsDialog.DataContext = vm;

            if (saveAsDialog.ShowDialog() == true)
            {
                IFeatureClass fc      = null;
                string        path    = null;
                var           fcUtils = new FeatureClassUtils();
                if (vm.FeatureShapeIsChecked)
                {
                    path = fcUtils.PromptUserWithGxDialog(ArcMap.Application.hWnd);
                    if (path != null)
                    {
                        var        grpList  = GetMapPointExportFormat(GraphicsList);
                        SaveAsType saveType = System.IO.Path.GetExtension(path).Equals(".shp") ? SaveAsType.Shapefile : SaveAsType.FileGDB;
                        fc = fcUtils.CreateFCOutput(path, saveType, grpList, ArcMap.Document.FocusMap.SpatialReference);
                    }
                }
                else if (vm.KmlIsChecked)
                {
                    path = PromptSaveFileDialog("kmz", "KMZ File (*.kmz)|*.kmz", CoordinateConversionLibrary.Properties.Resources.KMLLocationMessage);
                    if (path != null)
                    {
                        string        kmlName            = System.IO.Path.GetFileName(path);
                        string        folderName         = System.IO.Path.GetDirectoryName(path);
                        var           grpList            = GetMapPointExportFormat(GraphicsList);
                        var           fileNameWithoutExt = System.IO.Path.GetFileNameWithoutExtension(kmlName);
                        IFeatureClass tempFc             = fcUtils.CreateFCOutput(fileNameWithoutExt, SaveAsType.KML, grpList, ArcMap.Document.FocusMap.SpatialReference);

                        if (tempFc != null)
                        {
                            var kmlUtils = new KMLUtils();
                            kmlUtils.ConvertLayerToKML(tempFc, path, fileNameWithoutExt, ArcMap.Document.FocusMap);
                        }
                    }
                }
                else
                {
                    //Export to CSV
                    path = PromptSaveFileDialog("csv", "CSV File (*.csv)|*.csv", CoordinateConversionLibrary.Properties.Resources.CSVLocationMessage);
                    if (path != null)
                    {
                        string csvName    = System.IO.Path.GetFileName(path);
                        string folderName = System.IO.Path.GetDirectoryName(path);
                        string tempFile   = System.IO.Path.Combine(folderName, csvName);
                        var    aiPoints   = CoordinateAddInPoints.ToList();
                        if (!aiPoints.Any())
                        {
                            return;
                        }
                        var csvExport  = new CsvExport();
                        var displayAmb = CoordinateConversionLibraryConfig.AddInConfig.DisplayAmbiguousCoordsDlg;
                        foreach (var point in aiPoints)
                        {
                            var results = GetOutputFormats(point);
                            csvExport.AddRow();
                            foreach (var item in results)
                            {
                                csvExport[item.Key] = item.Value;
                            }
                            if (point.FieldsDictionary != null)
                            {
                                foreach (KeyValuePair <string, Tuple <object, bool> > item in point.FieldsDictionary)
                                {
                                    if (item.Key != PointFieldName && item.Key != OutputFieldName)
                                    {
                                        csvExport[item.Key] = item.Value.Item1;
                                    }
                                }
                            }
                            CoordinateConversionLibraryConfig.AddInConfig.DisplayAmbiguousCoordsDlg = false;
                        }
                        CoordinateConversionLibraryConfig.AddInConfig.DisplayAmbiguousCoordsDlg = displayAmb;
                        csvExport.ExportToFile(tempFile);
                        System.Windows.Forms.MessageBox.Show(CoordinateConversionLibrary.Properties.Resources.CSVExportSuccessfulMessage + tempFile,
                                                             CoordinateConversionLibrary.Properties.Resources.CSVExportSuccessfulCaption);
                    }
                }

                if (fc != null)
                {
                    AddFeatureLayerToMap(fc);
                }
            }
        }
Exemple #6
0
        public override List <Dictionary <string, Tuple <object, bool> > > ReadExcelInput(string fileName)
        {
            var tableName     = Guid.NewGuid().ToString().Replace("-", "");
            var lstDictionary = new List <Dictionary <string, Tuple <object, bool> > >();

            using (ComReleaser oComReleaser = new ComReleaser())
            {
                IFeatureWorkspace workspace = FeatureClassUtils.CreateFeatureWorkspace("tempWorkspace");
                if (workspace == null)
                {
                }
                // Cast the workspace to the IWorkspaceEdit interface.
                IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace;

                // Start an edit session. An undo/redo stack isn't necessary in this case.
                workspaceEdit.StartEditing(false);

                // Start an edit operation.
                workspaceEdit.StartEditOperation();

                IGeoProcessor2 gp = new GeoProcessorClass();
                gp.AddOutputsToMap = false;

                IVariantArray rasterToPolyParams = new VarArrayClass();
                rasterToPolyParams.Add(fileName);
                rasterToPolyParams.Add(((IWorkspace)workspace).PathName + System.IO.Path.DirectorySeparatorChar + tableName);
                object oResult = gp.Execute("ExcelToTable_conversion", rasterToPolyParams, null);
                IGeoProcessorResult ipResult = (IGeoProcessorResult)oResult;

                // Save the edit operation. To cancel an edit operation, the AbortEditOperation
                // method can be used.
                workspaceEdit.StopEditOperation();

                // Stop the edit session. The saveEdits parameter indioates the edit session
                // will be committed.
                workspaceEdit.StopEditing(true);

                if (ipResult.Status == esriJobStatus.esriJobSucceeded)
                {
                    var workspacePath = System.IO.Path.GetDirectoryName(Convert.ToString(ipResult.ReturnValue));

                    var    workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(typeof(FileGDBWorkspaceFactoryClass));
                    var    featureWorkspace = workspaceFactory.OpenFromFile(workspacePath, 0);
                    ITable table            = GetTables(featureWorkspace, tableName);
                    if (table != null)
                    {
                        for (int i = 1; i <= table.RowCount(null); i++)
                        {
                            var  dictionary = new Dictionary <string, Tuple <object, bool> >();
                            IRow row        = table.GetRow(i);
                            for (int j = 0; j < row.Fields.FieldCount; j++)
                            {
                                dictionary.Add(row.Fields.get_Field(j).Name, Tuple.Create(row.get_Value(j), false));
                            }
                            lstDictionary.Add(dictionary);
                        }
                    }
                    var ds = table as IDataset;
                    ds.Delete();
                }
            }
            return(lstDictionary);
        }
Exemple #7
0
        private async void OnSaveAsCommand(object obj)
        {
            var saveAsDialog = new ProSaveAsFormatView();
            var vm           = new ProSaveAsFormatViewModel();

            saveAsDialog.DataContext = vm;
            if (saveAsDialog.ShowDialog() == true)
            {
                IsToolActive = false;
                var    fcUtils = new FeatureClassUtils();
                string path    = fcUtils.PromptUserWithSaveDialog(vm.FeatureIsChecked, vm.ShapeIsChecked, vm.KmlIsChecked, vm.CSVIsChecked);
                if (path != null)
                {
                    var displayAmb = CoordinateConversionLibraryConfig.AddInConfig.DisplayAmbiguousCoordsDlg;
                    CoordinateConversionLibraryConfig.AddInConfig.DisplayAmbiguousCoordsDlg = false;
                    try
                    {
                        string folderName   = System.IO.Path.GetDirectoryName(path);
                        var    mapPointList = CoordinateAddInPoints.Select(i => i.Point).ToList();
                        if (vm.FeatureIsChecked)
                        {
                            var ccMapPointList = GetMapPointExportFormat(CoordinateAddInPoints);
                            await fcUtils.CreateFCOutput(path,
                                                         SaveAsType.FileGDB,
                                                         ccMapPointList,
                                                         MapView.Active.Map.SpatialReference,
                                                         MapView.Active,
                                                         CoordinateConversionLibrary.GeomType.Point);
                        }
                        else if (vm.ShapeIsChecked || vm.KmlIsChecked)
                        {
                            var ccMapPointList = GetMapPointExportFormat(CoordinateAddInPoints);
                            await fcUtils.CreateFCOutput(path, SaveAsType.Shapefile, ccMapPointList, MapView.Active.Map.SpatialReference, MapView.Active, CoordinateConversionLibrary.GeomType.Point, vm.KmlIsChecked);
                        }
                        else if (vm.CSVIsChecked)
                        {
                            var aiPoints = CoordinateAddInPoints.ToList();
                            if (!aiPoints.Any())
                            {
                                return;
                            }
                            var csvExport = new CsvExport();

                            foreach (var point in aiPoints)
                            {
                                var results = GetOutputFormats(point);
                                csvExport.AddRow();
                                foreach (var item in results)
                                {
                                    csvExport[item.Key] = item.Value;
                                }
                                if (point.FieldsDictionary != null)
                                {
                                    foreach (KeyValuePair <string, Tuple <object, bool> > item in point.FieldsDictionary)
                                    {
                                        if (item.Key != PointFieldName && item.Key != OutputFieldName)
                                        {
                                            csvExport[item.Key] = item.Value.Item1;
                                        }
                                    }
                                }
                            }
                            csvExport.ExportToFile(path);

                            System.Windows.Forms.MessageBox.Show(CoordinateConversionLibrary.Properties.Resources.CSVExportSuccessfulMessage + path,
                                                                 CoordinateConversionLibrary.Properties.Resources.CSVExportSuccessfulCaption);
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.Message);
                    }
                    CoordinateConversionLibraryConfig.AddInConfig.DisplayAmbiguousCoordsDlg = displayAmb;
                }
            }
        }