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 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); } } }