static void Main(string[] args) { //arg 0 = source layer string file gdb string with feature class name //arg 1 = target layer path for fabric layer //arg 2 = control point tolerance (in projection units) to match with existing fabric points, -1 means don't do it //arg 3 = merge tolerance. Merge with existing control points if within tolerance, -1 means turn off merging //arg 4 = control merging choices for attributes [KeepExistingAttributes | UpdateExistingAttributes] //arg 5 = must have same name to merge if within the tolerance? [NamesMustMatchToMerge | IgnoreNames] //arg 6 = if control is merged keep existing names or update with incoming names? [KeepExistingNames | UpdateExistingNames] //.....(arg 6 is ignored if arg 5 = NamesMustMatchToMerge) //arg 7 = control merging choices for coordinates [UpdateXY | UpdateXYZ | UpdateZ | KeepExistingXYZ] //arg 8 = create a log file at the same location as the executable? [LoggingOn | LoggingOff] //.....(a log file is always generated unless LoggingOff is explcitly used) //ESRI License Initializer generated code. m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeStandard, esriLicenseProductCode.esriLicenseProductCodeAdvanced }, new esriLicenseExtensionCode[] { }); //ESRI License Initializer generated code. //Do not make any call to ArcObjects after ShutDownApplication() int iLen = args.Length; if (iLen < 2) { UsageMessage(); m_AOLicenseInitializer.ShutdownApplication(); return; } ITrackCancel pTrkCan = new CancelTrackerClass(); // Create and display the Progress Dialog IProgressDialogFactory pProDlgFact = new ProgressDialogFactoryClass(); IProgressDialog2 pProDlg = pProDlgFact.Create(pTrkCan, 0) as IProgressDialog2; try { ICadastralControlImporter pControlPointCadastralImp = new CadastralControlImporterClass(); // args[0] ============================================ string PathToFileGDBandFeatureClass = args[0]; if (args[0].Contains(":") && args[0].Contains("\\")) { PathToFileGDBandFeatureClass = args[0]; } else { string[] sExecPathArr = System.Reflection.Assembly.GetEntryAssembly().Location.Split('\\'); string x = ""; for (int i = 0; i < (sExecPathArr.Length - 1); i++) { x += sExecPathArr[i] + "\\"; } PathToFileGDBandFeatureClass = x + PathToFileGDBandFeatureClass; } string[] PathToFileGDBArray = PathToFileGDBandFeatureClass.Split('\\'); string NameOfSourceFeatureClass = PathToFileGDBArray[PathToFileGDBArray.Length - 1]; string PathToFileGDB = ""; for (int i = 0; i < (PathToFileGDBArray.Length - 1); i++) { PathToFileGDB += PathToFileGDBArray[i] + "\\"; } PathToFileGDB = PathToFileGDB.TrimEnd('\\'); if (!System.IO.Directory.Exists(PathToFileGDB)) { throw new Exception("File does not exist. [" + PathToFileGDB + "]"); } // args[1] ============================================ string layerFilePathToFabric = args[1]; if (!(layerFilePathToFabric.Contains(":") && layerFilePathToFabric.Contains("\\"))) { string[] sExecPathArr = System.Reflection.Assembly.GetEntryAssembly().Location.Split('\\'); string x = ""; for (int i = 0; i < (sExecPathArr.Length - 1); i++) { x += sExecPathArr[i] + "\\"; } layerFilePathToFabric = x + layerFilePathToFabric; } if (!System.IO.File.Exists(layerFilePathToFabric)) { throw new Exception("File does not exist. [" + layerFilePathToFabric + "]"); } ILayerFile layerFileToTargetFabric = new LayerFileClass(); layerFileToTargetFabric.Open(layerFilePathToFabric); ILayer pLayer = layerFileToTargetFabric.Layer; ICadastralFabricLayer pParcelFabLyr = pLayer as ICadastralFabricLayer; ICadastralFabric pParcelFabric = pParcelFabLyr.CadastralFabric; IDataset pDS = pParcelFabric as IDataset; IName pDSName = pDS.FullName; ICadastralFabricName pCadastralFabricName = pDSName as ICadastralFabricName; IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactory(); IFeatureWorkspace pFWS = (IFeatureWorkspace)workspaceFactory.OpenFromFile(PathToFileGDB, 0); pDS = (IDataset)pFWS.OpenFeatureClass(NameOfSourceFeatureClass); IName pSourceFeatClassName = pDS.FullName; // args[2] ============================================ bool bHasControlTolerance = iLen > 2; double dControlToFabricPointMatchTolerance = -1; if (bHasControlTolerance) { if (!Double.TryParse(args[2], out dControlToFabricPointMatchTolerance)) { throw new Exception("The third parameter should be a numeric value. [" + args[2] + "]"); } } pControlPointCadastralImp.ControlPointTolerance = dControlToFabricPointMatchTolerance; //'***** performance, -1 means that matching to existing fabric points is turned off pControlPointCadastralImp.UseShapeField = true; //============= Arguments for merging control points =============== // args[3] [4] [5] [6] [7] ============================================ bool bIsMergingControlPoints = (iLen == 7); if (bIsMergingControlPoints) { //arg 3 = merge tolerance. Merge with existing control points if within tolerance, -1 means turn off merging //arg 4 = control merging choices for attributes [KeepExistingAttributes | UpdateExistingAttributes] //arg 5 = must have same name to merge if within the tolerance? [NamesMustMatchToMerge | IgnoreNames] //arg 6 = if control is merged keep existing names or update with incoming names? [KeepExistingNames | UpdateExistingNames] //.....(arg 6 is ignored if arg 5 = NamesMustMatchToMerge) //arg 7 = control merging choices for coordinates [UpdateXY | UpdateXYZ | UpdateZ | KeepExistingXYZ] double dControlPointMergingTolerance = -1; if (!Double.TryParse(args[3], out dControlPointMergingTolerance)) { { throw new Exception("The fourth parameter should be a numeric value. [" + args[3] + "]"); } } ICadastralControlImporterMerging pImpMerge = pControlPointCadastralImp as ICadastralControlImporterMerging; pImpMerge.MergeCloseControl = dControlPointMergingTolerance > 0; pImpMerge.CloseControlTolerance = dControlPointMergingTolerance; if (args[4].ToLower().Contains("updateexistingattributes")) { pImpMerge.MergeAttributesOption = esriCFControlMergingAttributes.esriCFControlMergingUpdateAttributes; } else { pImpMerge.MergeAttributesOption = esriCFControlMergingAttributes.esriCFControlMergingKeepAttributes; } pImpMerge.MergeControlNameCaseSensitive = false; pImpMerge.MergeControlSameName = args[5].ToLower().Contains("namesmustmatchtomerge"); if (args[6].ToLower().Contains("updateexistingnames") && !args[5].ToLower().Contains("namesmustmatchtomerge")) { pImpMerge.MergeNameOption = esriCFControlMergingName.esriCFControlMergingUpdateExistingNames; } else { pImpMerge.MergeNameOption = esriCFControlMergingName.esriCFControlMergingKeepExistingNames; } if (args[7].ToLower() == "updatexy") { pImpMerge.MergeCoordinateOption = esriCFControlMergingCoordinate.esriCFControlMergingUpdateXY; } else if (args[7].ToLower() == "updatexyz") { pImpMerge.MergeCoordinateOption = esriCFControlMergingCoordinate.esriCFControlMergingUpdateXYZ; } else if (args[7].ToLower() == "updatez") { pImpMerge.MergeCoordinateOption = esriCFControlMergingCoordinate.esriCFControlMergingUpdateZ; } else if (args[7].ToLower() == "keepexistingxyz") { pImpMerge.MergeCoordinateOption = esriCFControlMergingCoordinate.esriCFControlMergingKeepExistingCoordinates; } } ICadastralImporter pControlImporter = (ICadastralImporter)pControlPointCadastralImp; bool bHasExplicitLogFileParameter = (iLen > 8); bool bExplicitTurnLoggingOff = false; /// Argument for logging importer results //arg 8 = create a log file at the same location as the executable? [LoggingOn | LoggingOff | <path to logfile>] //.....(a log file is always generated unless LoggingOff is explcitly used) string sLogFilePath = "LogControlImport"; if (bHasExplicitLogFileParameter) { if (args[8].ToLower() == "loggingoff") { bExplicitTurnLoggingOff = true; } if (args[8].ToLower() != "loggingon" && !bExplicitTurnLoggingOff) { if (args[8].Contains(":") && args[8].Contains("\\")) //if (args[8].ToLower() != "loggingon") { sLogFilePath = args[8]; } else { string[] sExecPathArr = System.Reflection.Assembly.GetEntryAssembly().Location.Split('\\'); string x = ""; for (int i = 0; i < (sExecPathArr.Length - 1); i++) { x += sExecPathArr[i] + "\\"; } sLogFilePath = x + args[8]; } } } else { string[] sExecPathArr = System.Reflection.Assembly.GetEntryAssembly().Location.Split('\\'); string x = ""; for (int i = 0; i < (sExecPathArr.Length - 1); i++) { x += sExecPathArr[i] + "\\"; } sLogFilePath = x + sLogFilePath; } sLogFilePath += ".log"; if (!bExplicitTurnLoggingOff) { pControlImporter.OutputLogfile = sLogFilePath; //default location is same as executable } //Set the properties of the Progress Dialog pProDlg.CancelEnabled = false; pProDlg.Description = "Importing Control Point data ..."; pProDlg.Title = "Importing Control Points"; pProDlg.Animation = esriProgressAnimationTypes.esriProgressGlobe; Console.WriteLine("Starting data load..."); pControlImporter.Import(pSourceFeatClassName, pCadastralFabricName, pTrkCan); //BUG fails if the TrackCancel is null Console.WriteLine("Finished data load..."); } catch (Exception ex) { Console.WriteLine(ex.Message); //UsageMessage(); } finally { if (pProDlg != null) { pProDlg.HideDialog(); } m_AOLicenseInitializer.ShutdownApplication(); } }
protected override void OnClick() { IApplication pApp; ICadastralFabric m_pCadaFab; #region Get Fabric pApp = (IApplication)ArcMap.Application; if (pApp == null) { //if the app is null then could be running from ArcCatalog pApp = (IApplication)ArcCatalog.Application; } if (pApp == null) { MessageBox.Show("Could not access the application.", "No Application found"); return; } IGxApplication pGXApp = (IGxApplication)pApp; stdole.IUnknown pUnk = null; try { pUnk = (stdole.IUnknown)pGXApp.SelectedObject.InternalObjectName.Open(); } catch (COMException ex) { if (ex.ErrorCode == (int)fdoError.FDO_E_DATASET_TYPE_NOT_SUPPORTED_IN_RELEASE || ex.ErrorCode == -2147220944) { MessageBox.Show("The dataset is not supported in this release.", "Could not open the dataset"); } else { MessageBox.Show(ex.ErrorCode.ToString(), "Could not open the dataset"); } return; } if (pUnk is ICadastralFabric) { m_pCadaFab = (ICadastralFabric)pUnk; } else { MessageBox.Show("Please select a parcel fabric and try again.", "Not a parcel fabric"); return; } #endregion IName pName = pGXApp.SelectedObject.InternalObjectName as IName; ICadastralFabricName pCFName = pName as ICadastralFabricName; IFabricImporterUI pFabImporterUI = new FabricCogoImporterUIClass(); pFabImporterUI.CadastralFabric = pCFName; pFabImporterUI.DoModal(pApp.hWnd); //ArcMap.Application.CurrentTool = null; }