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); } } }
/// <summary> /// Method to use when you need to move a feedback line to a point /// This forces a new point to be used, sometimes this method projects the point to a different spatial reference /// </summary> /// <param name="point"></param> //internal void FeedbackMoveTo(IPoint point) //{ // if (feedback == null || point == null) // return; // feedback.MoveTo(new Point() { X = point.X, Y = point.Y, SpatialReference = point.SpatialReference }); //} /// <summary> /// Saves graphics to file gdb or shp file /// </summary> /// <param name="obj"></param> private async void OnSaveAs() { var dlg = new ProSaveAsFormatView(); dlg.DataContext = new ProSaveAsFormatViewModel(); var vm = dlg.DataContext as ProSaveAsFormatViewModel; GeomType geomType = GeomType.Polygon; if (dlg.ShowDialog() == true) { // Get the graphics list for the selected tab List <Graphic> typeGraphicsList = new List <Graphic>(); if (this is ProLinesViewModel) { typeGraphicsList = GraphicsList.Where(g => g.GraphicType == GraphicTypes.Line).ToList(); geomType = GeomType.PolyLine; } else if (this is ProCircleViewModel) { typeGraphicsList = GraphicsList.Where(g => g.GraphicType == GraphicTypes.Circle).ToList(); } else if (this is ProEllipseViewModel) { typeGraphicsList = GraphicsList.Where(g => g.GraphicType == GraphicTypes.Ellipse).ToList(); } else if (this is ProRangeViewModel) { typeGraphicsList = GraphicsList.Where(g => g.GraphicType == GraphicTypes.RangeRing).ToList(); geomType = GeomType.PolyLine; } string path = fcUtils.PromptUserWithSaveDialog(vm.FeatureIsChecked, vm.ShapeIsChecked, vm.KmlIsChecked); if (path != null) { try { string folderName = System.IO.Path.GetDirectoryName(path); if (vm.FeatureIsChecked) { await fcUtils.CreateFCOutput(path, SaveAsType.FileGDB, typeGraphicsList, MapView.Active.Map.SpatialReference, MapView.Active, geomType); } else if (vm.ShapeIsChecked || vm.KmlIsChecked) { await fcUtils.CreateFCOutput(path, SaveAsType.Shapefile, typeGraphicsList, MapView.Active.Map.SpatialReference, MapView.Active, geomType, vm.KmlIsChecked); } } catch (Exception ex) { } } } }
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); } } }
/// <summary> /// Saves graphics to file gdb or shp file /// </summary> /// <param name="obj"></param> private void OnSaveAs(object obj) { var dlg = new GRSaveAsFormatView(); dlg.DataContext = new SaveAsFormatViewModel(); var vm = dlg.DataContext as SaveAsFormatViewModel; if (dlg.ShowDialog() == true) { IFeatureClass fc = null; // Get the graphics list for the selected tab List <Graphic> typeGraphicsList = new List <Graphic>(); if (this is LinesViewModel) { typeGraphicsList = GraphicsList.Where(g => g.GraphicType == GraphicTypes.Line).ToList(); } else if (this is CircleViewModel) { typeGraphicsList = GraphicsList.Where(g => g.GraphicType == GraphicTypes.Circle).ToList(); } else if (this is EllipseViewModel) { typeGraphicsList = GraphicsList.Where(g => g.GraphicType == GraphicTypes.Ellipse).ToList(); } else if (this is RangeViewModel) { typeGraphicsList = GraphicsList.Where(g => g.GraphicType == GraphicTypes.RangeRing).ToList(); } string path = null; 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, typeGraphicsList, ArcMap.Document.FocusMap.SpatialReference); } else { fc = fcUtils.CreateFCOutput(path, SaveAsType.FileGDB, typeGraphicsList, 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, typeGraphicsList, ArcMap.Document.FocusMap.SpatialReference); if (tempFc != null) { kmlUtils.ConvertLayerToKML(path, tempShapeFile, ArcMap.Document.FocusMap); // delete the temporary shapefile fcUtils.DeleteShapeFile(tempShapeFile); } } } if (fc != null) { IFeatureLayer outputFeatureLayer = new FeatureLayerClass(); outputFeatureLayer.FeatureClass = fc; IGeoFeatureLayer geoLayer = outputFeatureLayer as IGeoFeatureLayer; geoLayer.Name = fc.AliasName; ESRI.ArcGIS.Carto.IMap map = ArcMap.Document.FocusMap; map.AddLayer((ILayer)outputFeatureLayer); } } }
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; } } }