コード例 #1
0
 public static void LoadLayerFromStream(ILayer paramLayer, byte[] paramLayerContent)
 {
     if (((paramLayer != null) && (paramLayerContent != null)) && (paramLayerContent.Length != 0))
     {
         IPersistStream stream = paramLayer as IPersistStream;
         XMLStream      class2 = new XMLStream();
         class2.LoadFromBytes(ref paramLayerContent);
         stream.Load((IStream)class2);
     }
 }
コード例 #2
0
 public static byte[] SaveLayerToStream(ILayer paramLayer)
 {
     byte[] buffer = null;
     if (paramLayer is IPersistStream)
     {
         IPersistStream stream = paramLayer as IPersistStream;
         XMLStream      class2 = new XMLStream();
         stream.Save((IStream)class2, 0);
         buffer = class2.SaveToBytes();
     }
     return(buffer);
 }
コード例 #3
0
        public IFIDSet AppendCadastralXML(ICadastralFabric Fabric, ICadastralJob CadastralJob, IProjectedCoordinateSystem TargetProjectedCoordinateSystem, string CadastralXMLPath)
        {
            try
            {
                string sTempPath = System.IO.Path.GetTempPath();
                string sCopiedCadastralXMLFile = System.IO.Path.Combine(sTempPath, CadastralJob.Name.Replace('/', '_').Replace(':', '_') + ".xml");

                //rename ALL oID tags so that they're ignored
                ReplaceInFile(CadastralXMLPath, sCopiedCadastralXMLFile, "oID>", "old_xxX>");

                //Possible TODO for merge-point workaround: analyze coordinates of incoming file and if any are identical to existing fabric coordinates, then make the oID tag match
                //the oID of the existing point in the target fabric. This will trigger point merging of identical points

                ITrackCancel pTrkCan = new CancelTracker();
                // Create and display the Progress Dialog
                IProgressDialogFactory pProDlgFact = new ProgressDialogFactory();
                IProgressDialog2       pProDlg     = pProDlgFact.Create(pTrkCan, 0) as IProgressDialog2;
                //Set the properties of the Progress Dialog
                pProDlg.CancelEnabled = false;
                pProDlg.Description   = "    ";
                pProDlg.Title         = "Append";
                pProDlg.Animation     = esriProgressAnimationTypes.esriProgressGlobe;

                //        do an extract to set the spatial reference
                ((ICadastralFabric3)Fabric).ExtractCadastralPacket(CadastralJob.Name, TargetProjectedCoordinateSystem, null, true);



                IXMLStream pStream = new XMLStream();
                pStream.LoadFromFile(sCopiedCadastralXMLFile);
                IFIDSet pFIDSet = null;//new FIDSet();

                (Fabric as ICadastralFabric3).PostCadastralPacket(pStream, pTrkCan, esriCadastralPacketSetting.esriCadastralPacketNoSetting, ref pFIDSet);
                //(Fabric as ICadastralFabric3).InsertCadastralPacket(CadastralJob, pStream, pTrkCan, esriCadastralPacketSetting.esriCadastralPacketNoSetting, ref pFIDSet);
                int setCnt = pFIDSet.Count();

                RefreshFabricLayers(ArcMap.Document.ActiveView.FocusMap, Fabric);
                File.Delete(sCopiedCadastralXMLFile);

                if (pProDlg != null)
                {
                    pProDlg.HideDialog();
                }

                return(pFIDSet);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(null);
            }
        }
コード例 #4
0
ファイル: CommandManager.cs プロジェクト: zj8487/HyDM
        public bool SaveToFile(string cmdfile)
        {
            //Create a MemoryBlobStream
            //IBlobStream blobStream = new MemoryBlobStreamClass();
            IXMLStream xmlstream = new XMLStream();
            //Get the IStream interface
            IStream stream = (IStream)xmlstream;
            //Get the IToolbarControl2 interface
            IToolbarControl2 toolbarControl = (IToolbarControl2)axToolbarControl1.Object;

            //Save the ToolbarControl into the stream
            toolbarControl.SaveItems(stream);
            //Save the stream to a file
            xmlstream.SaveToFile(cmdfile);
            return(true);
        }
コード例 #5
0
ファイル: ModuleSysSetting.cs プロジェクト: radtek/geosufan
        public static bool CopySelectedMap(IWorkspace pWorkspace, string strCondition, out IMap pMap)
        {
            pMap = null;
            if (pWorkspace != null)
            {
                try
                {
                    //读取数据库表内容
                    Fan.Common.Gis.SysGisTable sysTable = new Fan.Common.Gis.SysGisTable(pWorkspace);
                    Exception err = null;
                    Dictionary <string, object> pDic = sysTable.GetRow(_MxdListTable, strCondition, out err);
                    if (pDic != null)
                    {
                        if (pDic.ContainsKey(_MxdListTable_MapField))
                        {
                            if (pDic[_MxdListTable_MapField] != null)  //这里仅能成功导出当初以文件类型导入的BLOB字段
                            {
                                object tempObj = pDic[_MxdListTable_MapField];
                                IMemoryBlobStreamVariant pMemoryValue;
                                pMemoryValue = (IMemoryBlobStreamVariant)tempObj;
                                object objValue;
                                pMemoryValue.ExportToVariant(out objValue);
                                byte[]     pbyte      = objValue as byte[];
                                IXMLStream pXMLStream = new XMLStream();
                                pXMLStream.LoadFromBytes(ref pbyte);
                                IStream        pStream        = pXMLStream as IStream;
                                IPersistStream pPersistStream = new MapClass();
                                pPersistStream.Load(pStream);
                                pMap = pPersistStream as IMap;

                                sysTable = null;
                                return(true);
                            }
                        }
                    }
                    sysTable = null;
                }
                catch (Exception err)
                { }
            }
            return(false);
        }
コード例 #6
0
        private void ProcessFile(string fileName)
        {
            string FN = fileName.ToLower();
            int    szip = 0, sxml = 0;

            szip = FN.IndexOf(".sbm");
            sxml = FN.IndexOf(".sbc");
            Stream XMLStream;

            if (szip > 0)
            {
                FileStream zipToOpen = new FileStream(fileName, FileMode.Open);
                ZipArchive archive   = new ZipArchive(zipToOpen, ZipArchiveMode.Read);
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    if (entry.FullName.ToLower().IndexOf("cubeblocks") > 0)
                    {
                        XMLStream = entry.Open();
                        GetThtusterInfo(entry.Open());
                        XMLStream.Close();
                        //MessageBox.Show(entry.FullName);
                    }
                }
                archive.Dispose();
                zipToOpen.Close();
            }
            if (sxml > 0 && fileName.ToLower().IndexOf("cubeblocks") > 0)
            {
                XMLStream = File.OpenRead(fileName);
                if (XMLStream != null)
                {
                    GetThtusterInfo(XMLStream);
                }
                XMLStream.Close();
            }
            //throw new NotImplementedException();
        }
コード例 #7
0
        public static IXMLStream WriteFeatureClassToXMLStream(IFeatureClass featureClass, IQueryFilter queryFilter)
        {
            string       ss       = "http://www.esri.com/schemas/ArcGIS/9.2 ";
            IPropertySet pPropset = new PropertySet();

            pPropset.SetProperty("Namespaceuri", "http://schemas.esri.com/ArcGis/Server/ ");
            IPropertySet pCpropset = new PropertySet();

            pCpropset.SetProperty("http://schemas.esri.com/ArcGis/Server/", "xmlns");
            pPropset.SetProperty("Namespaceprefixes", pCpropset);

            IRecordSetInit pRecinit = new RecordSetClass();

            pRecinit.SetSourceTable(featureClass as ITable, queryFilter);
            IRecordSet pRec       = pRecinit as IRecordSet;
            IXMLStream pXmlStream = new XMLStream();
            IXMLWriter pXmlWriter = new XMLWriter();

            pXmlWriter.WriteTo(pXmlStream as IStream);
            IXMLSerializer pXmlSerial = new XMLSerializer();

            pXmlSerial.WriteObject(pXmlWriter, pPropset, null, "Record", ss, pRec);
            return(pXmlStream);
        }
コード例 #8
0
        protected override void OnClick()
        {
            //go get a traverse file
            // Display .Net dialog for File selection.
            OpenFileDialog openFileDialog = new OpenFileDialog();

            // Set File Filter
            openFileDialog.Filter = "Cadastral XML file (*.xml)|*.xml";
            // Enable multi-select
            openFileDialog.Multiselect = true;
            // Don't need to Show Help
            openFileDialog.ShowHelp = false;
            // Set Dialog Title
            openFileDialog.Title       = "Append Cadastral XML files";
            openFileDialog.FilterIndex = 2;
            // Display Open File Dialog
            if (openFileDialog.ShowDialog() != DialogResult.OK)
            {
                openFileDialog = null;
                return;
            }

            //Get the cadastral editor
            ICadastralEditor pCadEd     = (ICadastralEditor)ArcMap.Application.FindExtensionByName("esriCadastralUI.CadastralEditorExtension");
            ICadastralFabric pCadFabric = pCadEd.CadastralFabric;
            IEditor          pEd        = ArcMap.Editor;

            ITrackCancel pTrkCan = new CancelTracker();
            // Create and display the Progress Dialog
            IProgressDialogFactory pProDlgFact = new ProgressDialogFactory();
            IProgressDialog2       pProDlg     = pProDlgFact.Create(pTrkCan, 0) as IProgressDialog2;

            //Set the properties of the Progress Dialog
            pProDlg.CancelEnabled = true;
            pProDlg.Description   = "    ";
            pProDlg.Title         = "Append";
            pProDlg.Animation     = esriProgressAnimationTypes.esriProgressGlobe;
            string sCopiedCadastralXMLFile = "";

            try
            {
                ICadastralJob CadaJob;
                bool          bJobExists = false; //used to trap for the special error message condition of existing job
                pEd.StartOperation();

                #region workaround for setting Projection
                ICadastralJob CadaJobTemp;
                bJobExists = false;
                if (!CreateCadastralJob(pCadFabric, "TEMPJOB", out CadaJobTemp, true, ref bJobExists))
                {
                    if (!bJobExists) // if the create job failed for some other reason than it already exists, then bail out.
                    {
                        MessageBox.Show("Job could not be created.");
                        return;
                    }
                }
                //do an extract to set the spatial reference: bug workaround
                ((ICadastralFabric3)pCadFabric).ExtractCadastralPacket(CadaJobTemp.Name, ArcMap.Document.ActiveView.FocusMap.SpatialReference as IProjectedCoordinateSystem, null, true);
                #endregion

                //make a temporary file for the edited cadastral XML that is used for the fabric update
                string sTempPath = System.IO.Path.GetTempPath();
                sCopiedCadastralXMLFile = System.IO.Path.Combine(sTempPath, "LastUpdatedCadastralXMLAppendedFromBatch.xml");
                int iFileCount  = 0;
                int iTotalFiles = openFileDialog.FileNames.GetLength(0);

                List <string> lstPlans = new List <string>();
                #region get all plan names for all files
                foreach (String CadastralXMLPath in openFileDialog.FileNames)
                {
                    TextReader tr = null;
                    try
                    {
                        tr = new StreamReader(CadastralXMLPath);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        return;
                    }

                    //          string[] sFileLine = new string[0]; //define as dynamic array
                    string sLine       = "";
                    int    iCount      = 0;
                    bool   bInPlanData = false;
                    bool   bInParcel   = false;

                    //fill the array with the lines from the file
                    while (sLine != null)
                    {
                        sLine = tr.ReadLine();
                        try
                        {
                            if (sLine.Trim().Length >= 1) //test for empty lines
                            {
                                if (!bInParcel && !bInPlanData)
                                {
                                    bInPlanData = sLine.Contains("<plan>");
                                }

                                if (bInPlanData && sLine.Contains("<name>") && sLine.Contains("</name>"))
                                {
                                    string sPlanName = sLine.Replace("<name>", "").Replace("</name>", "").Replace("\t", "").Trim();
                                    if (!lstPlans.Contains(sPlanName))
                                    {
                                        lstPlans.Add(sPlanName);
                                    }
                                    bInPlanData = false;
                                }
                            }
                            iCount++;
                        }
                        catch { }
                    }
                    tr.Close(); //close the file and release resources
                }
                string sInClause = "";
                foreach (string sPlan in lstPlans)
                {
                    sInClause += "'" + sPlan + "'" + ",";
                }

                sInClause = sInClause.Remove(sInClause.LastIndexOf(","), 1);

                ITable       pPlansTable = pCadFabric.get_CadastralTable(esriCadastralFabricTable.esriCFTPlans);
                int          iNameFld    = pPlansTable.FindField("Name");
                IQueryFilter pQuFilter   = new QueryFilterClass();
                pQuFilter.WhereClause = "NAME IN (" + sInClause + ")";
                ICursor       pCur           = pPlansTable.Search(pQuFilter, false);
                List <string> lstPlanReplace = new List <string>();

                IRow pPlan = pCur.NextRow();
                while (pPlan != null)
                {
                    lstPlanReplace.Add("<name>" + (string)pPlan.Value[iNameFld] + "</name>\n\t\t<oID>" + pPlan.OID.ToString() + "</oID>");
                    Marshal.ReleaseComObject(pPlan);
                    pPlan = pCur.NextRow();
                }
                Marshal.ReleaseComObject(pCur);

                #endregion

                foreach (String CadastralXMLPath in openFileDialog.FileNames)
                {
                    if (!pTrkCan.Continue())
                    {
                        pEd.AbortOperation();
                        return;
                    }

                    //rename ALL oID tags so that they're ignored. This indicates that these are to be treated as NEW parcels coming in.
                    ReplaceInFile(CadastralXMLPath, sCopiedCadastralXMLFile, "oID>", "old_xxX>");

                    foreach (string sPlanTag in lstPlanReplace)
                    {
                        string sFirstPart = sPlanTag.Substring(0, sPlanTag.IndexOf("\n"));
                        ReplaceInFile(sCopiedCadastralXMLFile, sCopiedCadastralXMLFile, sFirstPart, sPlanTag);
                    }

                    //TEST ONLY
                    //ReplaceInFile(CadastralXMLPath, sCopiedCadastralXMLFile, "oID>", "oID>");

                    //IF using PostCadastralPacket the points are not all merged. If using PostCadastralPacket, then a merge-point workaround would be to analyze coordinates
                    //of incoming file and if any are identical to existing fabric coordinates, then make the oID tag match
                    //the oID of the existing point in the target fabric. This will trigger point merging of identical points when using PostCadastralPacket.
                    //code below uses InsertCadastralPacket and so point merging is handled.

                    IXMLStream pStream = new XMLStream();
                    pStream.LoadFromFile(sCopiedCadastralXMLFile);
                    IFIDSet pFIDSet = null;//new FIDSet();

                    DateTime localNow = DateTime.Now;
                    string   sJobName = Convert.ToString(localNow) + "_" + (iFileCount++).ToString();
                    // note the create option is to NOT write job to fabric and is in-memory only initially, and then the InsertCadastralPacket will create and store the job in the fabric
                    // IF using PostCadastralPacket, then this option should be set to true, so that the job already exists in the fabric.
                    // Also, when using PostCadastralPacket, you can continue to use the same Target job, and a new one is not needed for each iteration.
                    // With InsertCadastralPacket a job is created for each call when new parcels are being created.
                    if (!CreateCadastralJob(pCadFabric, sJobName, out CadaJob, false, ref bJobExists))
                    {
                        pEd.AbortOperation();
                        return;
                    }

                    pProDlg.Description = "File: " + System.IO.Path.GetFileName(CadastralXMLPath) + " (" + iFileCount.ToString() + " of " + iTotalFiles.ToString() + ")";
                    //(pCadFabric as ICadastralFabric3).PostCadastralPacket(pStream, pTrkCan, esriCadastralPacketSetting.esriCadastralPacketNoSetting, ref pFIDSet);
                    (pCadFabric as ICadastralFabric3).InsertCadastralPacket(CadaJob, pStream, pTrkCan, esriCadastralPacketSetting.esriCadastralPacketNoSetting, ref pFIDSet);
                    //int setCnt = pFIDSet.Count();
                }
                RefreshFabricLayers(ArcMap.Document.ActiveView.FocusMap, pCadFabric);
                pEd.StopOperation("Append " + iFileCount.ToString() + " cadastral XML files");
            }
            catch (Exception ex)
            {
                pEd.AbortOperation();
                COMException c_Ex;
                int          errorCode = 0;
                if (ex is COMException)
                {
                    c_Ex      = (COMException)ex;
                    errorCode = c_Ex.ErrorCode;
                }
                if (errorCodeDict.ContainsKey(errorCode))
                {
                    MessageBox.Show(errorCodeDict[errorCode], "Append files");
                }
                else
                {
                    MessageBox.Show("Error: " + ex.Message + Environment.NewLine + ex.HResult.ToString(), "Append files");
                }
            }
            finally
            {
                if (sCopiedCadastralXMLFile != string.Empty)
                {
                    File.Delete(sCopiedCadastralXMLFile);
                }
                if (pProDlg != null)
                {
                    pProDlg.HideDialog();
                }
            }
        }
コード例 #9
0
ファイル: CommandManager.cs プロジェクト: hy1314200/HyDM
        public bool SaveToFile(string cmdfile)
        {
            //Create a MemoryBlobStream
            //IBlobStream blobStream = new MemoryBlobStreamClass();
            IXMLStream xmlstream = new XMLStream();
            //Get the IStream interface
            IStream stream = (IStream) xmlstream;
            //Get the IToolbarControl2 interface
            IToolbarControl2 toolbarControl = (IToolbarControl2) axToolbarControl1.Object;

            //Save the ToolbarControl into the stream
            toolbarControl.SaveItems(stream);
            //Save the stream to a file
            xmlstream.SaveToFile(cmdfile);
            return true;
        }