Beispiel #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)
                    {
                    }
                }
            }
        }
        public override void OnDisplayCoordinateTypeChanged(CoordinateConversionLibrary.Models.CoordinateConversionLibraryConfig obj)
        {
            base.OnDisplayCoordinateTypeChanged(obj);

            // update list box coordinates
            var list = CoordinateAddInPoints.ToList();

            CoordinateAddInPoints.Clear();
            foreach (var item in list)
            {
                CoordinateAddInPoints.Add(item);
            }
        }
 private void OnClearGraphicsCommand(object obj)
 {
     /* KG - Use DeletePoints() to Clrea All button
      * var mxdoc = ArcMap.Application.Document as IMxDocument;
      * if (mxdoc == null)
      *  return;
      * var av = mxdoc.FocusMap as IActiveView;
      * if (av == null)
      *  return;
      * var gc = av as IGraphicsContainer;
      * if (gc == null)
      *  return;
      * //TODO need to clarify what clear graphics button does
      * // seems to be different than the other Military Tools when doing batch collection
      * RemoveGraphics(gc, GraphicsList.Where(g => g.IsTemp == false).ToList());
      *
      * //av.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
      * av.Refresh(); // sometimes a partial refresh is not working
      */
     DeletePoints(CoordinateAddInPoints.ToList());
 }
        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);
                }
            }
        }
 // Call CopyAllCoordinateOutputs event
 private void OnCopyAllCommand(object obj)
 {
     OnCopyAllCoordinateOutputs(CoordinateAddInPoints.ToList());
 }
 private void OnDeleteAllPointsCommand(object obj)
 {
     DeletePoints(CoordinateAddInPoints.ToList());
 }
        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);
                }
            }
        }
Beispiel #8
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;
                }
            }
        }
Beispiel #9
0
 private void OnClearGraphicsCommand(object obj)
 {
     DeletePoints(CoordinateAddInPoints.ToList());
 }