/// <summary>
        /// Creates the output featureclass, either fgdb featureclass or a shapefile
        /// </summary>
        /// <param name="outputPath">location of featureclass</param>
        /// <param name="saveAsType">Type of output selected, either fgdb featureclass or shapefile</param>
        /// <param name="graphicsList">List of graphics for selected tab</param>
        /// <param name="ipSpatialRef">Spatial Reference being used</param>
        /// <returns>Output featureclass</returns>
        public IFeatureClass CreateFCOutput(string outputPath, SaveAsType saveAsType, List <Graphic> graphicsList, ISpatialReference ipSpatialRef)
        {
            string        fcName     = System.IO.Path.GetFileName(outputPath);
            string        folderName = System.IO.Path.GetDirectoryName(outputPath);
            IFeatureClass fc         = null;

            try
            {
                bool isGraphicLineOrRangeRing = graphicsList[0].GraphicType == GraphicTypes.Line || graphicsList[0].GraphicType == GraphicTypes.RangeRing;
                if (saveAsType == SaveAsType.FileGDB)
                {
                    IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactory();
                    IWorkspace        workspace        = workspaceFactory.OpenFromFile(folderName, 0);
                    IFeatureWorkspace fWorkspace       = (IFeatureWorkspace)workspace;

                    if (DoesFeatureClassExist(folderName, fcName))
                    {
                        DeleteFeatureClass(fWorkspace, fcName);
                    }

                    fc = CreateFeatureClass(fWorkspace, fcName, isGraphicLineOrRangeRing);

                    foreach (Graphic graphic in graphicsList)
                    {
                        IFeature feature = fc.CreateFeature();

                        if (graphic.GraphicType != GraphicTypes.Line && graphic.GraphicType != GraphicTypes.RangeRing)
                        {
                            feature.Shape = PolylineToPolygon(graphic.Geometry);
                        }
                        else
                        {
                            feature.Shape = graphic.Geometry;
                        }

                        feature.Store();
                    }
                }
                else if (saveAsType == SaveAsType.Shapefile)
                {
                    // already asked them for confirmation to overwrite file
                    if (File.Exists(outputPath))
                    {
                        DeleteShapeFile(outputPath);
                    }

                    fc = ExportToShapefile(outputPath, graphicsList, ipSpatialRef, isGraphicLineOrRangeRing);
                }
                return(fc);
            }
            catch (Exception ex)
            {
                return(fc);
            }
        }
Пример #2
0
 public async Task <bool> ExportLayer(string layerName, string outputPath, SaveAsType saveAsType)
 {
     if (saveAsType == SaveAsType.KML)
     {
         return(await ExportKMLLayer(layerName, outputPath));
     }
     else
     {
         return(await ExportFeatureLayer(layerName, outputPath));
     }
 }
        /// <summary>
        /// Creates the output featureclass, either fgdb featureclass or shapefile
        /// </summary>
        /// <param name="outputPath">location of featureclass</param>
        /// <param name="saveAsType">Type of output selected, either fgdb featureclass or shapefile</param>
        /// <param name="graphicsList">List of graphics for selected tab</param>
        /// <param name="ipSpatialRef">Spatial Reference being used</param>
        /// <returns>Output featureclass</returns>
        public async Task CreateFCOutput(string outputPath, SaveAsType saveAsType, List <Graphic> graphicsList, SpatialReference spatialRef, MapView mapview, GeomType geomType, bool isKML = false)
        {
            string dataset    = System.IO.Path.GetFileName(outputPath);
            string connection = System.IO.Path.GetDirectoryName(outputPath);

            try
            {
                await QueuedTask.Run(async() =>
                {
                    await CreateFeatureClass(dataset, geomType, connection, spatialRef, graphicsList, mapview, isKML);
                });
            }
            catch (Exception ex)
            {
            }
        }
Пример #4
0
        public async Task CreateFCOutput(string outputPath, SaveAsType saveAsType, List <CCProGraphic> mapPointList, SpatialReference spatialRef, MapView mapview, GeomType geomType, bool isKML = false)
        {
            string dataset    = System.IO.Path.GetFileName(outputPath);
            string connection = System.IO.Path.GetDirectoryName(outputPath);

            try
            {
                await QueuedTask.Run(async() =>
                {
                    await CreateFeatureClass(dataset, connection, spatialRef, mapPointList, mapview, isKML);
                });
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
        /// <summary>
        /// 另存元数据(报表或视图)
        /// </summary>
        /// <param name="login">包装的login信息</param>
        /// <param name="sourceId">另存的源Id(报表id或视图Id)</param>
        /// <param name="savaAsName">另存的新名称</param>
        /// <param name="saveAsType">另存类型</param>
        /// <returns>另存成功,返回true;已存在要另存的名称,返回false</returns>
        public bool SaveAs(
            U8LoginInfor login,
            string sourceId,
            string savaAsName,
            string reportSubId,
            SaveAsType saveAsType,
            string runtimeForamtXml,
            string colorstyleid,
            string currentViewId)
        {
            SqlCommand cmd = new SqlCommand("UAP_Report_RuntimeSaveAs");

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(SqlHelper.GetParameter("@SourceId", SqlDbType.NVarChar, 100, sourceId));
            cmd.Parameters.Add(SqlHelper.GetParameter("@SaveAsName", SqlDbType.NVarChar, 256, savaAsName));
            cmd.Parameters.Add(SqlHelper.GetParameter("@SaveAsType", SqlDbType.NVarChar, 100, saveAsType.ToString()));
            cmd.Parameters.Add(SqlHelper.GetParameter("@cAccId", SqlDbType.NVarChar, 100, login.cAccId));
            cmd.Parameters.Add(SqlHelper.GetParameter("@cYear", SqlDbType.NVarChar, 100, login.cYear));
            cmd.Parameters.Add(SqlHelper.GetParameter("@cUserId", SqlDbType.NVarChar, 100, login.UserID));
            cmd.Parameters.Add(SqlHelper.GetParameter("@IsExistedName", SqlDbType.Bit));
            cmd.Parameters.Add(SqlHelper.GetParameter("@ReportSubId", SqlDbType.NVarChar, 100, reportSubId));
            cmd.Parameters.Add(SqlHelper.GetParameter("@NewAuthIds", SqlDbType.NVarChar, 2000));
            cmd.Parameters.Add(SqlHelper.GetParameter("@RuntimeFormat", SqlDbType.NText, runtimeForamtXml));
            cmd.Parameters.Add(SqlHelper.GetParameter("@colorstyleid", SqlDbType.NVarChar, 100, colorstyleid));
            cmd.Parameters.Add(SqlHelper.GetParameter("@CurrentViewId", SqlDbType.NVarChar, 100, currentViewId));

            bool isNameExisted = false;

            this.ExcuteStoreProc(login.UfMetaCnnString, cmd, ref isNameExisted);
            if (isNameExisted)
            {
                return(false);
            }
            if (saveAsType == SaveAsType.SaveAsReport)
            {
                this.AddAuth2Cache(cmd, login);
            }
            return(true);
        }
        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);
                }
            }
        }
Пример #7
0
        private void HandleMessage(Message rdomail, string exportdir)
        {
            if (this.ProcessedMsgs.Contains(rdomail.Node))
            {
                return;
            }

            this.ProcessedMsgs.Add(rdomail.Node);

            string msgdir = exportdir;

            if (this.SaveAsTypes != SaveAsType.None || this.SaveAttachments == true)
            {
                msgdir = msgdir + @"\" + rdomail.Node.ToString();
            }

            if (!Directory.Exists(msgdir))
            {
                Directory.CreateDirectory(msgdir);
            }
            if (Directory.Exists(msgdir))
            {
                if ((this.SaveAsTypes & SaveAsType.Xml) == SaveAsType.Xml)
                {
                    this.OutputFiles.Add(rdomail.Write(this.Pst2MsgCompatible ? exportdir + @"\XML" : msgdir, Message.SaveAsMessageType.Xml, true), "Xml");
                }
                if ((this.SaveAsTypes & SaveAsType.Eml) == SaveAsType.Eml)
                {
                    this.OutputFiles.Add(rdomail.Write(msgdir, Message.SaveAsMessageType.Eml, true));
                }
                if ((this.SaveAsTypes & SaveAsType.Msg) == SaveAsType.Msg)
                {
                    this.OutputFiles.Add(rdomail.Write(this.Pst2MsgCompatible ? exportdir + @"\MSG" : msgdir, Message.SaveAsMessageType.Msg, true), "Msg");
                }
                if ((this.SaveAsTypes & SaveAsType.Html) == SaveAsType.Html)
                {
                    this.OutputFiles.Add(rdomail.Write(msgdir, Message.SaveAsMessageType.Html, true), "Html");
                }
                if (rdomail.HasBody && ((this.SaveAsTypes & SaveAsType.Text) == SaveAsType.Text))
                {
                    this.OutputFiles.Add(rdomail.Write(msgdir, Message.SaveAsMessageType.Text, true), "Text");
                }
                if (rdomail.HasRtfBody && ((this.SaveAsTypes & SaveAsType.Rtf) == SaveAsType.Rtf))
                {
                    this.OutputFiles.Add(rdomail.Write(msgdir, Message.SaveAsMessageType.Rtf, true));
                }
                foreach (pstsdk.definition.pst.message.IAttachment rdoattachment in rdomail.Attachments)
                {
                    if (rdoattachment.IsMessage)
                    {
                        Message attachmsg = null;
                        try
                        {
                            attachmsg     = (Message)rdoattachment.OpenAsMessage();
                            attachmsg.Pst = rdomail.Pst;
                        }
                        catch (Exception ex)
                        {
                            WFLogger.NLogger.ErrorException(string.Format("PSTFile={0}  NodeID={1}", this.PSTFile, this.FileToProcess), ex);
                        }
                        finally
                        {
                            if (attachmsg != null)
                            {
                                if (this.SaveEmbeddedMsgs == true && attachmsg.Node == Convert.ToUInt32(this.FileToProcess))
                                {
                                    SaveAsType origsaveastype = this.SaveAsTypes;
                                    this.SaveAsTypes = SaveAsType.Msg | SaveAsType.Xml | SaveAsType.Html;
                                    HandleMessage(attachmsg, exportdir);
                                    this.SaveAsTypes = origsaveastype;
                                }
                                else
                                {
                                    this.OutputFiles.Add(attachmsg.Node.Value.ToString(), "EmbeddedMsg");
                                }
                            }
                        }
                    }
                    else if (this.SaveAttachments)
                    {
                        string filedir = string.Format("{0}\\{1}", msgdir, WFUtilities.GetNextDirectoryNumber(msgdir));
                        if (!Directory.Exists(filedir))
                        {
                            Directory.CreateDirectory(filedir);
                        }
                        if (Directory.Exists(filedir))
                        {
                            string filename = filedir + @"\" + rdoattachment.Filename;
                            using (var bw = new BinaryWriter(File.OpenWrite(filename)))
                            {
                                bw.Write(rdoattachment.Bytes);
                                this.OutputFiles.Add(filename, "Attachment");
                            }
                        }
                    }
                    rdoattachment.Dispose();
                }
            }
        }
        /// <summary>
        /// Creates the output featureclass, either fgdb featureclass or a shapefile
        /// </summary>
        /// <param name="outputPath">location of featureclass</param>
        /// <param name="saveAsType">Type of output selected, either fgdb featureclass or shapefile</param>
        /// <param name="graphicsList">List of graphics for selected tab</param>
        /// <param name="ipSpatialRef">Spatial Reference being used</param>
        /// <returns>Output featureclass</returns>
        public IFeatureClass CreateFCOutput(string outputPath, SaveAsType saveAsType, List<Graphic> graphicsList, ISpatialReference ipSpatialRef)
        {
            string fcName = System.IO.Path.GetFileName(outputPath);
            string folderName = System.IO.Path.GetDirectoryName(outputPath);
            IFeatureClass fc = null;

            try
            {
                if (saveAsType == SaveAsType.FileGDB)
                {
                    IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactory();
                    IWorkspace workspace = workspaceFactory.OpenFromFile(folderName, 0);
                    IFeatureWorkspace fWorkspace = (IFeatureWorkspace)workspace;

                    if (DoesFeatureClassExist(folderName, fcName))
                    {
                        DeleteFeatureClass(fWorkspace, fcName);
                    }

                    fc = CreatePolylineFeatureClass(fWorkspace, fcName);

                    foreach (Graphic graphic in graphicsList)
                    {
                        IFeature feature = fc.CreateFeature();

                        feature.Shape = graphic.Geometry;
                        feature.Store();
                    }

                }
                else if (saveAsType == SaveAsType.Shapefile)
                {
                    // already asked them for confirmation to overwrite file
                    if (File.Exists(outputPath))
                    {
                        DeleteShapeFile(outputPath);
                    }            

                    fc = ExportToShapefile(outputPath, graphicsList, ipSpatialRef);
                }
                return fc;
            }
            catch (Exception ex)
            {
                return 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);
                }
            }
        }
Пример #10
0
        /// <summary>
        /// Creates the output featureclass, either fgdb featureclass or a shapefile
        /// </summary>
        /// <param name="outputPath">location of featureclass</param>
        /// <param name="saveAsType">Type of output selected, either fgdb featureclass or shapefile</param>
        /// <param name="graphicsList">List of graphics for selected tab</param>
        /// <param name="ipSpatialRef">Spatial Reference being used</param>
        /// <returns>Output featureclass</returns>
        public IFeatureClass CreateFCOutput(string outputPath, SaveAsType saveAsType, List <Graphic> graphicsList, ISpatialReference ipSpatialRef)
        {
            string        fcName     = System.IO.Path.GetFileName(outputPath);
            string        folderName = System.IO.Path.GetDirectoryName(outputPath);
            IFeatureClass fc         = null;

            try
            {
                bool isGraphicLineOrRangeRing = graphicsList[0].GraphicType == GraphicTypes.Line || graphicsList[0].GraphicType == GraphicTypes.RangeRing;
                if (saveAsType == SaveAsType.FileGDB)
                {
                    IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactory();
                    IWorkspace        workspace        = workspaceFactory.OpenFromFile(folderName, 0);
                    IFeatureWorkspace fWorkspace       = (IFeatureWorkspace)workspace;

                    if (DoesFeatureClassExist(folderName, fcName))
                    {
                        DeleteFeatureClass(fWorkspace, fcName);
                    }

                    fc = CreateFeatureClass(fWorkspace, fcName, graphicsList, isGraphicLineOrRangeRing);

                    foreach (Graphic graphic in graphicsList)
                    {
                        if (graphic.Attributes == null)
                        {
                            continue;
                        }
                        IFeature feature = fc.CreateFeature();

                        if (graphic.GraphicType != GraphicTypes.Line && graphic.GraphicType != GraphicTypes.RangeRing)
                        {
                            feature.Shape = PolylineToPolygon(graphic.Geometry);
                        }
                        else
                        {
                            feature.Shape = graphic.Geometry;
                        }

                        switch (graphic.GraphicType.ToString())
                        {
                        case "Line":
                        {
                            System.Object dist;
                            System.Object angle;
                            System.Object angleunit;
                            System.Object ox;
                            System.Object oy;
                            System.Object dx;
                            System.Object dy;
                            System.Object distunit;

                            graphic.Attributes.TryGetValue("distance", out dist);
                            graphic.Attributes.TryGetValue("distanceunit", out distunit);
                            graphic.Attributes.TryGetValue("startx", out ox);
                            graphic.Attributes.TryGetValue("starty", out oy);
                            graphic.Attributes.TryGetValue("endx", out dx);
                            graphic.Attributes.TryGetValue("endy", out dy);
                            graphic.Attributes.TryGetValue("angle", out angle);
                            graphic.Attributes.TryGetValue("angleunit", out angleunit);
                            feature.set_Value(feature.Fields.FindField("Distance"), dist);
                            feature.set_Value(feature.Fields.FindField("DistanceUnit"), distunit);
                            feature.set_Value(feature.Fields.FindField("OriginX"), ox);
                            feature.set_Value(feature.Fields.FindField("OriginY"), oy);
                            feature.set_Value(feature.Fields.FindField("DestinationX"), dx);
                            feature.set_Value(feature.Fields.FindField("DestinationY"), dy);
                            feature.set_Value(feature.Fields.FindField("Angle"), angle);
                            feature.set_Value(feature.Fields.FindField("AngleUnit"), angleunit);
                            feature.Store();
                            break;
                        }

                        case "Circle":
                        {
                            System.Object radius;
                            System.Object disttype;
                            System.Object distunit;
                            System.Object centerx;
                            System.Object centery;

                            graphic.Attributes.TryGetValue("radius", out radius);
                            graphic.Attributes.TryGetValue("distanceunit", out distunit);
                            graphic.Attributes.TryGetValue("disttype", out disttype);
                            graphic.Attributes.TryGetValue("centerx", out centerx);
                            graphic.Attributes.TryGetValue("centery", out centery);

                            feature.set_Value(feature.Fields.FindField("Distance"), radius);
                            feature.set_Value(feature.Fields.FindField("DistanceUnit"), distunit);
                            feature.set_Value(feature.Fields.FindField("DistanceType"), disttype);
                            feature.set_Value(feature.Fields.FindField("CenterX"), centerx);
                            feature.set_Value(feature.Fields.FindField("CenterY"), centery);

                            feature.Store();
                            break;
                        }

                        case "Ellipse":
                        {
                            System.Object majoraxis;
                            System.Object minoraxis;
                            System.Object angle;
                            System.Object distunit;
                            System.Object centerx;
                            System.Object centery;
                            System.Object angleunit;

                            graphic.Attributes.TryGetValue("majoraxis", out majoraxis);
                            graphic.Attributes.TryGetValue("minoraxis", out minoraxis);
                            graphic.Attributes.TryGetValue("azimuth", out angle);
                            graphic.Attributes.TryGetValue("distanceunit", out distunit);
                            graphic.Attributes.TryGetValue("centerx", out centerx);
                            graphic.Attributes.TryGetValue("centery", out centery);
                            graphic.Attributes.TryGetValue("angleunit", out angleunit);

                            feature.set_Value(feature.Fields.FindField("MajorAxis"), majoraxis);
                            feature.set_Value(feature.Fields.FindField("MinorAxis"), minoraxis);
                            feature.set_Value(feature.Fields.FindField("DistanceUnit"), distunit);
                            feature.set_Value(feature.Fields.FindField("Angle"), angle);
                            feature.set_Value(feature.Fields.FindField("CenterX"), centerx);
                            feature.set_Value(feature.Fields.FindField("CenterY"), centery);
                            feature.set_Value(feature.Fields.FindField("AngleUnit"), angleunit);

                            feature.Store();
                            break;
                        }

                        case "RangeRing":
                        {
                            System.Object rings;
                            System.Object distance;
                            System.Object distunit;
                            System.Object centerx;
                            System.Object centery;

                            graphic.Attributes.TryGetValue("rings", out rings);
                            graphic.Attributes.TryGetValue("distance", out distance);
                            graphic.Attributes.TryGetValue("distanceunit", out distunit);
                            graphic.Attributes.TryGetValue("centerx", out centerx);
                            graphic.Attributes.TryGetValue("centery", out centery);

                            feature.set_Value(feature.Fields.FindField("Rings"), rings);
                            feature.set_Value(feature.Fields.FindField("Distance"), distance);
                            feature.set_Value(feature.Fields.FindField("DistanceUnit"), distunit);
                            feature.set_Value(feature.Fields.FindField("CenterX"), centerx);
                            feature.set_Value(feature.Fields.FindField("CenterY"), centery);
                            feature.Store();
                            break;
                        }
                        }
                    }
                }
                else if (saveAsType == SaveAsType.Shapefile)
                {
                    // already asked them for confirmation to overwrite file
                    if (File.Exists(outputPath))
                    {
                        DeleteShapeFile(outputPath);
                    }

                    fc = ExportToShapefile(outputPath, graphicsList, ipSpatialRef, isGraphicLineOrRangeRing);
                }
                return(fc);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(fc);
            }
        }
        /// <summary>
        /// Creates the output featureclass, either fgdb featureclass or shapefile
        /// </summary>
        /// <param name="outputPath">location of featureclass</param>
        /// <param name="saveAsType">Type of output selected, either fgdb featureclass or shapefile</param>
        /// <param name="graphicsList">List of graphics for selected tab</param>
        /// <param name="ipSpatialRef">Spatial Reference being used</param>
        /// <returns>Output featureclass</returns>
        public async Task CreateFCOutput(string outputPath, SaveAsType saveAsType, List<Graphic> graphicsList, SpatialReference spatialRef, MapView mapview, GeomType geomType, bool isKML = false)
        {
            string dataset = System.IO.Path.GetFileName(outputPath);
            string connection = System.IO.Path.GetDirectoryName(outputPath);
            
            try
            {
                await QueuedTask.Run(async () =>
                {
                    await CreateFeatureClass(dataset, geomType, connection, spatialRef, graphicsList, mapview, isKML);
                });  
            }
            catch (Exception ex)
            {

            }
        }
Пример #12
0
        /// <summary>
        /// Saves selected data
        /// </summary>
        private void SaveData()
        {
            // If the required objects are missing, return
            if (_mainForm == null || _mainForm.RomData == null || cbSave.SelectedItem == null || cbSaveAs.SelectedItem == null)
            {
                return;
            }

            // Set up objects
            ObjectID   objectID   = null;
            Bitmap     bmp        = null;
            SaveType   saveType   = (SaveType)(cbSave.SelectedItem as ObjectID).ID;
            SaveAsType saveAsType = (SaveAsType)(cbSaveAs.SelectedItem as ObjectID).ID;
            string     save       = EnumMethods.GetDescription(typeof(SaveType), saveType);
            string     saveAs     = EnumMethods.GetDescription(typeof(SaveAsType), saveAsType);

            switch (saveType)
            {
            case SaveType.PaletteGroup: objectID = GetSelectedPaletteGroup(); bmp = objectID != null?GetSelectedPaletteGroup().GetPaletteGroupImage() : null; break;

            case SaveType.Sprite: objectID = GetSelectedSprite(); bmp = pnlSprite.Image; break;

            case SaveType.SpriteTileset: objectID = GetSelectedTileset(cbSpriteTilesets); bmp = pnlSpriteTilesets.Image; break;

            case SaveType.SpriteTileMap: objectID = GetSelectedTileMap(cbSpriteTileMaps); bmp = pnlSpriteTileMaps.Image; break;

            case SaveType.Tileset: objectID = GetSelectedTileset(cbTilesets); bmp = pnlTilesets.Image; break;

            case SaveType.TileMap: objectID = GetSelectedTileMap(cbTileMaps); bmp = pnlTileMaps.Image; break;
            }

            // If no object was selected, return
            if (objectID == null)
            {
                ShowMessage("Please select a " + EnumMethods.GetDescription(typeof(SaveType), saveType).ToLower() + " to save.");
                return;
            }

            // Create open file dialog
            using (SaveFileDialog dialog = new SaveFileDialog())
            {
                // Set up the open file dialog
                dialog.Filter   = saveAsType == SaveAsType.Binary ? "Uncompressed Binary|*.bin" : saveAsType == SaveAsType.CompressedBinary ? "Compressed Binary|*.bin" : "Image|*.png";
                dialog.Title    = "Save " + save + " " + saveAs + " File";
                dialog.FileName = objectID.Name + saveType.ToString() + saveAsType.ToString();

                // Show dialog, if the user clicks OK
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    // Write data to disk, based on save as type
                    switch (saveAsType)
                    {
                    case SaveAsType.Binary: using (BinaryWriter bw = new BinaryWriter(File.Create(dialog.FileName))) { bw.Write(MainForm.RomData.Decompress(objectID.Compression, objectID.DataStart, objectID.Length)); break; }

                    case SaveAsType.CompressedBinary: using (BinaryWriter bw = new BinaryWriter(File.Create(dialog.FileName))) { bw.Write(MainForm.RomData.GetBytes(objectID.DataStart, objectID.Length)); } break;

                    case SaveAsType.Image: if (bmp != null)
                        {
                            bmp.Save(dialog.FileName, ImageFormat.Png);
                        }
                        break;
                    }
                }
            }
        }