| Numéro d’ID de bogue |
BUG-000112264 |
| Envoi | March 8, 2018 |
| Dernière modification | June 5, 2024 |
| S’applique à | ArcObjects SDK |
| Version trouvée | 10.5.1 |
| Système d’exploitation | Windows OS |
| Version du système d’exploitation | 10.0 64 Bit |
| Statut | Will Not Be Addressed
L’équipe de développement a examiné le problème ou la demande et a décidé qu’ils ne seraient pas traités. Pour d’autres explications, reportez-vous à la section Informations supplémentaires correspondant au problème.
|
Informations supplémentaires
The goal is to use a Cadastral XML file as source information to update the attributes of a pre-existing parcel stored in the parcel fabric dataset. This task can be done via SDK without any fixes required from Esri development. The sample add-in source code below includes the steps required to achieve this specific goal.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.CadastralUI;
using ESRI.ArcGIS.GeoSurvey;
using ESRI.ArcGIS.Editor;
using System.Windows.Forms;
using ESRI.ArcGIS.GeoDatabaseExtensions;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.esriSystem;
using System.Reflection;
namespace TestXML
{
public class LoadXML : ESRI.ArcGIS.Desktop.AddIns.Button
{
public LoadXML()
{
}
protected override void OnClick()
{
IEditor pEd = null;
try
{
ICadastralEditor pCadEd = (ICadastralEditor)ArcMap.Application.FindExtensionByName("esriCadastralUI.CadastralEditorExtension");
pEd = (IEditor)ArcMap.Application.FindExtensionByName("esri object editor");
if (pEd.EditState == esriEditState.esriStateNotEditing)
{
MessageBox.Show("Please start editing and try again.");
return;
}
IFIDSet pFIDSetParcels = new FIDSetClass();
ICadastralSelection pSelection = (ICadastralSelection)pCadEd;
IEnumGSParcels pGSParcels = pSelection.SelectedParcels;
//IEnumCEParcels pCEParcels = (IEnumCEParcels)pGSParcels;
pGSParcels.Reset();
IGSParcel pGSParcel = pGSParcels.Next();
while (pGSParcel != null)
{
pFIDSetParcels.Add(pGSParcel.DatabaseId);
pGSParcel = pGSParcels.Next();
}
if (pFIDSetParcels.Count() == 0)
{
MessageBox.Show("No selection. Please select parcels to be updated and try again.");
return;
}
ICadastralFabric pCadaFab = pCadEd.CadastralFabric;
ICadastralJob job = new CadastralJob
{
Name = Convert.ToString(DateTime.Now),
Owner = "Test",
Description = "Test"
};
pCadaFab.CreateJob(job);
#region Test for Edit Locks
ICadastralFabricLocks pFabLocks = (ICadastralFabricLocks)pCadaFab;
int[] pParcelIds = new int[pFIDSetParcels.Count()];
ILongArray pParcelsToLock = new LongArrayClass();
FIDsetToLongArray(pFIDSetParcels, ref pParcelsToLock, ref pParcelIds);
pFabLocks.LockingJob = job.Name;
ILongArray pLocksInConflict = null;
ILongArray pSoftLcksInConflict = null;
try
{
pFabLocks.AcquireLocks(pParcelsToLock, true, ref pLocksInConflict, ref pSoftLcksInConflict);
}
catch (COMException pCOMEx)
{
if (pCOMEx.ErrorCode == (int)fdoError.FDO_E_CADASTRAL_FABRIC_JOB_LOCK_ALREADY_EXISTS ||
pCOMEx.ErrorCode == (int)fdoError.FDO_E_CADASTRAL_FABRIC_JOB_CURRENTLY_EDITED)
{
MessageBox.Show("Edit Locks could not be acquired on all selected parcels.");
// since the operation is being aborted, release any locks that were acquired
pFabLocks.UndoLastAcquiredLocks();
}
else
MessageBox.Show(pCOMEx.Message + Environment.NewLine + Convert.ToString(pCOMEx.ErrorCode));
return;
}
#endregion
#region Get Cadastral XML File, add locked tag
OpenFileDialog pFileBrowser = new OpenFileDialog();
pFileBrowser.Multiselect = false;
pFileBrowser.InitialDirectory = Application.ExecutablePath;
pFileBrowser.Filter = "Cadastral XML|*.xml";
pFileBrowser.Title = "Browse and Open the Cadastral XML";
DialogResult result = pFileBrowser.ShowDialog(); // Show the dialog.
if (result != DialogResult.OK)
{
ArcMap.Application.CurrentTool = null;
return;
}
string sourceCadasatrlXMLPath = pFileBrowser.FileName;
string sTempPath = System.IO.Path.GetTempPath();
string sCopiedCadastralXMLFile = System.IO.Path.Combine(sTempPath, job.Name.Replace('/','_').Replace(':','_') + ".xml");
ReplaceInFile(sourceCadasatrlXMLPath, sCopiedCadastralXMLFile, "", "true");
#endregion
//do an extract to set the spatial reference
((ICadastralFabric3)pCadaFab).ExtractCadastralPacket(job.Name, pEd.Map.SpatialReference as IProjectedCoordinateSystem, null, true);
IXMLStream pStream = new XMLStream();
pStream.LoadFromFile(sCopiedCadastralXMLFile);
IFIDSet pSet = new FIDSet();
pEd.StartOperation();
((ICadastralFabric3)pCadaFab).PostCadastralPacket(pStream, null, esriCadastralPacketSetting.esriCadastralPacketNoSetting, ref pSet);
int setCnt = pSet.Count();
pEd.StopOperation("Update by Cadastral XML");
}
catch (Exception ex)
{
pEd.AbortOperation();
MessageBox.Show(ex.Message);
}
ArcMap.Application.CurrentTool = null;
}
protected override void OnUpdate()
{
Enabled = ArcMap.Application != null;
}
static public void FIDsetToLongArray(IFIDSet InFIDSet, ref ILongArray OutLongArray, ref int[] OutIntArray)
{
Int32 pfID = -1;
InFIDSet.Reset();
double dMax = InFIDSet.Count();
int iMax = (int)(dMax);
for (Int32 pCnt = 0; pCnt <= (InFIDSet.Count() - 1); pCnt++)
{
InFIDSet.Next(out pfID);
OutLongArray.Add(pfID);
OutIntArray[pCnt] = pfID;
}
return;
}
static public void ReplaceInFile(string inFilePath, string outFilePath, string searchText, string replaceText)
{
StreamReader reader = new StreamReader(inFilePath);
string content = reader.ReadToEnd();
reader.Close();
content = Regex.Replace(content, searchText, replaceText);
StreamWriter writer = new StreamWriter(outFilePath);
writer.Write(content);
writer.Close();
}
}
}
Étapes pour reproduire
ID de bogue: BUG-000112264
Logiciel: